OpenGL: one more point shader
authorMike Erwin <significant.bit@gmail.com>
Sat, 1 Oct 2016 21:32:29 +0000 (17:32 -0400)
committerMike Erwin <significant.bit@gmail.com>
Sat, 1 Oct 2016 21:32:29 +0000 (17:32 -0400)
Added a built-in shader for points that vary both size and color.

source/blender/gpu/CMakeLists.txt
source/blender/gpu/GPU_shader.h
source/blender/gpu/intern/gpu_shader.c
source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl [new file with mode: 0644]

index ff826f40344b285f363c579877cfef8dda19b331..50d587c22fcda191c8ab585353d04bc2ce080744 100644 (file)
@@ -139,6 +139,7 @@ data_to_c_simple(shaders/gpu_shader_point_uniform_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_point_varying_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_no_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl SRC)
 
 data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC)
index 0845178cab89f68690dc7304e6e2ed1d4172a51e..f303697cbfa04c6ad095048cee58134bc9f43835 100644 (file)
@@ -107,6 +107,7 @@ typedef enum GPUBuiltinShader {
        /* points */
        GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
        GPU_SHADER_3D_POINT_VARYING_SIZE_UNIFORM_COLOR,
+       GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
 } GPUBuiltinShader;
 
 GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
index 98c2f23ae753e5f9b57c18822a34368842599a78..26dea79132c5f5decc32e054ba4256464c6243cb 100644 (file)
@@ -65,6 +65,7 @@ extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[];
 extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
 extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[];
 extern char datatoc_gpu_shader_3D_point_varying_size_no_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[];
 
 extern char datatoc_gpu_shader_text_vert_glsl[];
 extern char datatoc_gpu_shader_text_frag_glsl[];
@@ -111,6 +112,7 @@ static struct GPUShadersGlobal {
                /* points */
                GPUShader *point_fixed_size_varying_color_3D;
                GPUShader *point_varying_size_uniform_color_3D;
+               GPUShader *point_varying_size_varying_color_3D;
        } shaders;
 } GG = {{NULL}};
 
@@ -733,6 +735,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
                                        NULL, NULL, NULL, 0, 0, 0);
                        retval = GG.shaders.point_varying_size_uniform_color_3D;
                        break;
+               case GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR:
+                       if (!GG.shaders.point_varying_size_varying_color_3D)
+                               GG.shaders.point_varying_size_varying_color_3D = GPU_shader_create(
+                                       datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl,
+                                       datatoc_gpu_shader_point_varying_color_frag_glsl,
+                                       NULL, NULL, NULL, 0, 0, 0);
+                       retval = GG.shaders.point_varying_size_varying_color_3D;
+                       break;
        }
 
        if (retval == NULL)
@@ -899,6 +909,11 @@ void GPU_shader_free_builtin_shaders(void)
                GG.shaders.point_varying_size_uniform_color_3D = NULL;
        }
 
+       if (GG.shaders.point_varying_size_varying_color_3D) {
+               GPU_shader_free(GG.shaders.point_varying_size_varying_color_3D);
+               GG.shaders.point_varying_size_varying_color_3D = NULL;
+       }
+
        for (i = 0; i < 2 * MAX_FX_SHADERS; ++i) {
                if (GG.shaders.fx_shaders[i]) {
                        GPU_shader_free(GG.shaders.fx_shaders[i]);
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
new file mode 100644 (file)
index 0000000..529b46d
--- /dev/null
@@ -0,0 +1,19 @@
+
+#if __VERSION__ == 120
+  attribute vec3 pos;
+  attribute float size;
+  attribute vec4 color;
+  varying vec4 finalColor;
+#else
+  in vec3 pos;
+  in float size;
+  in vec4 color;
+  out vec4 finalColor;
+#endif
+
+void main()
+{
+       gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
+       gl_PointSize = size;
+       finalColor = color;
+}