diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-03-27 08:16:18 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-03-27 08:16:18 +0300 |
commit | b95ee78ed3f1851443aea871ffd1b1fd36e5ab1b (patch) | |
tree | 9a22b58d2323040d89c49a1ac49318cb0aca2fd3 /source/blender | |
parent | 159f56f4abf30ed1f4b81645a325d051e880cb16 (diff) |
OpenGL: prepare GLSL for version 3.3
- use in/out instead of attribute/varying
- use named output instead of gl_FragColor
- use texture() instead of the multitude of older texture sampling functions
The #if __VERSION__ == 120 paths (needed on Mac) will be removed after we switch to 3.3 core profile.
Part of T49165 (general OpenGL upgrade)
Diffstat (limited to 'source/blender')
9 files changed, 63 insertions, 14 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index fed928b53ba..df3b6f962e5 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -653,7 +653,7 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final BLI_dynstr_append(ds, ");\n"); } - BLI_dynstr_append(ds, "\n\tgl_FragColor = "); + BLI_dynstr_append(ds, "\n\tfragColor = "); codegen_convert_datatype(ds, finaloutput->type, GPU_VEC4, "tmp", finaloutput->id); BLI_dynstr_append(ds, ";\n"); } diff --git a/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl index 3819203bcd9..45f86e036a1 100644 --- a/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl @@ -1,5 +1,13 @@ -varying vec3 coords; +#if __VERSION__ == 120 + varying vec3 coords; + #define fragColor gl_FragColor +#else + in vec3 coords; + out vec4 fragColor; + #define texture1D texture + #define texture3D texture +#endif uniform sampler3D flame_texture; uniform sampler1D spectrum_texture; @@ -13,5 +21,5 @@ void main() color.rgb = emission.a * emission.rgb; color.a = emission.a; - gl_FragColor = color; + fragColor = color; } diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 6fb70c98330..ef30f8ae6c5 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -5,6 +5,14 @@ uniform mat4 ModelViewMatrixInverse; uniform mat4 ProjectionMatrixInverse; uniform mat3 NormalMatrix; +#if __VERSION__ == 120 + #define fragColor gl_FragColor +#else + out vec4 fragColor; + #define texture2D texture + #define textureCube texture +#endif + /* Converters */ float convert_rgba_to_float(vec4 color) diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl index 6ded453225e..fcb385ed30a 100644 --- a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl @@ -1,5 +1,13 @@ -varying vec3 coords; +#if __VERSION__ == 120 + varying vec3 coords; + #define fragColor gl_FragColor +#else + in vec3 coords; + out vec4 fragColor; + #define texture1D texture + #define texture3D texture +#endif uniform vec3 active_color; uniform float step_size; @@ -44,5 +52,5 @@ void main() vec4 color = transfer_function * density_scale; #endif - gl_FragColor = color; + fragColor = color; } diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl index 5548ac28839..f49272d0913 100644 --- a/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl @@ -1,7 +1,11 @@ uniform mat4 ModelViewProjectionMatrix; -varying vec3 coords; +#if __VERSION__ == 120 + varying vec3 coords; +#else + out vec3 coords; +#endif uniform vec3 min_location; uniform vec3 invsize; diff --git a/source/blender/gpu/shaders/gpu_shader_vertex.glsl b/source/blender/gpu/shaders/gpu_shader_vertex.glsl index 7f23a43689a..5a6b237b3be 100644 --- a/source/blender/gpu/shaders/gpu_shader_vertex.glsl +++ b/source/blender/gpu/shaders/gpu_shader_vertex.glsl @@ -12,8 +12,13 @@ out block { } outpt; #endif -varying vec3 varposition; -varying vec3 varnormal; +#if __VERSION__ == 120 + varying vec3 varposition; + varying vec3 varnormal; +#else + out vec3 varposition; + out vec3 varnormal; +#endif #ifdef CLIP_WORKAROUND varying float gl_ClipDistance[6]; diff --git a/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl b/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl index d45a4b316a8..7a39c3fc674 100644 --- a/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl +++ b/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl @@ -1,7 +1,11 @@ -varying vec3 varposition; -varying vec3 varnormal; - +#if __VERSION__ == 120 + varying vec3 varposition; + varying vec3 varnormal; +#else + out vec3 varposition; + out vec3 varnormal; +#endif /* Color, keep in sync with: gpu_shader_vertex.glsl */ diff --git a/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl b/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl index 3761bf350eb..9035a311ecb 100644 --- a/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl @@ -2,7 +2,13 @@ * This fragment shader was initially found at http://fabiensanglard.net/shadowmappingVSM/index.php */ -varying vec4 v_position; +#if __VERSION__ == 120 + varying vec4 v_position; + #define fragColor gl_FragColor +#else + in vec4 v_position; + out vec4 fragColor; +#endif void main() { @@ -17,5 +23,6 @@ void main() float dy = dFdy(depth); moment2 += 0.25 * (dx * dx + dy * dy); - gl_FragColor = vec4(moment1, moment2, 0.0, 0.0); + fragColor = vec4(moment1, moment2, 0.0, 0.0); + // TODO: write to a 2-component target --^ } diff --git a/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl b/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl index 32befccdc86..96ea22b3483 100644 --- a/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl @@ -1,6 +1,11 @@ uniform mat4 ModelViewProjectionMatrix; -varying vec4 v_position; + +#if __VERSION__ == 120 + varying vec4 v_position; +#else + out vec4 v_position; +#endif void main() { |