[Bf-blender-cvs] [396dd82] blender2.8: OpenGL: add simple shaders for 2D drawing
Mike Erwin
noreply at git.blender.org
Thu Aug 4 22:06:31 CEST 2016
Commit: 396dd824285d7fb524fcc8ad8ca4cddddf2efb6d
Author: Mike Erwin
Date: Thu Aug 4 15:59:38 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB396dd824285d7fb524fcc8ad8ca4cddddf2efb6d
OpenGL: add simple shaders for 2D drawing
The first two of several new simple built-in shaders (will test these
before adding more). These are intended for the new immediate mode API,
but you can use them just like any built-in GPUShader.
Due to limitations on different platforms, shaders need to work with
GLSL versions 120, 130 and 150. Final Blender 2.8 will be pure #version
150.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_shader.h
M source/blender/gpu/intern/gpu_shader.c
A source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
A source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
A source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl
A source/blender/gpu/shaders/gpu_shader_2D_uniform_color_vert.glsl
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 5708352..6bdac68 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -100,6 +100,11 @@ set(SRC
intern/gpu_private.h
)
+data_to_c_simple(shaders/gpu_shader_2D_uniform_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_uniform_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
+
data_to_c_simple(shaders/gpu_shader_geometry.glsl SRC)
data_to_c_simple(shaders/gpu_shader_smoke_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_smoke_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 762329e..3950152 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -89,6 +89,10 @@ typedef enum GPUBuiltinShader {
GPU_SHADER_SEP_GAUSSIAN_BLUR = 1,
GPU_SHADER_SMOKE = 2,
GPU_SHADER_SMOKE_FIRE = 3,
+
+ /* for simple drawing */
+ GPU_SHADER_2D_UNIFORM_COLOR,
+ GPU_SHADER_2D_SMOOTH_COLOR,
} GPUBuiltinShader;
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index df1213b..c3663f2 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -45,6 +45,11 @@
#define MAX_EXT_DEFINE_LENGTH 1024
/* Non-generated shaders */
+extern char datatoc_gpu_shader_2D_uniform_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
+
extern char datatoc_gpu_shader_smoke_vert_glsl[];
extern char datatoc_gpu_shader_smoke_frag_glsl[];
extern char datatoc_gpu_shader_vsm_store_vert_glsl[];
@@ -69,6 +74,9 @@ static struct GPUShadersGlobal {
GPUShader *smoke_fire;
/* cache for shader fx. Those can exist in combinations so store them here */
GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
+ /* for simple drawing */
+ GPUShader *uniform_color_2D;
+ GPUShader *smooth_color_2D;
} shaders;
} GG = {{NULL}};
@@ -622,6 +630,22 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
NULL, NULL, "#define USE_FIRE;\n", 0, 0, 0);
retval = GG.shaders.smoke_fire;
break;
+ case GPU_SHADER_2D_UNIFORM_COLOR:
+ if (!GG.shaders.uniform_color_2D)
+ GG.shaders.uniform_color_2D = GPU_shader_create(
+ datatoc_gpu_shader_2D_uniform_color_vert_glsl,
+ datatoc_gpu_shader_2D_uniform_color_frag_glsl,
+ NULL, NULL, NULL, 0, 0, 0);
+ retval = GG.shaders.uniform_color_2D;
+ break;
+ case GPU_SHADER_2D_SMOOTH_COLOR:
+ if (!GG.shaders.smooth_color_2D)
+ GG.shaders.smooth_color_2D = GPU_shader_create(
+ datatoc_gpu_shader_2D_smooth_color_vert_glsl,
+ datatoc_gpu_shader_2D_smooth_color_frag_glsl,
+ NULL, NULL, NULL, 0, 0, 0);
+ retval = GG.shaders.smooth_color_2D;
+ break;
}
if (retval == NULL)
@@ -733,6 +757,16 @@ void GPU_shader_free_builtin_shaders(void)
GG.shaders.smoke_fire = NULL;
}
+ if (GG.shaders.uniform_color_2D) {
+ GPU_shader_free(GG.shaders.uniform_color_2D);
+ GG.shaders.uniform_color_2D = NULL;
+ }
+
+ if (GG.shaders.smooth_color_2D) {
+ GPU_shader_free(GG.shaders.smooth_color_2D);
+ GG.shaders.smooth_color_2D = 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_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
new file mode 100644
index 0000000..89d23e2
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
@@ -0,0 +1,13 @@
+
+#if __VERSION__ == 120
+ varying vec4 finalColor;
+ #define fragColor gl_FragColor
+#else
+ noperspective in vec4 finalColor;
+ out vec4 fragColor;
+#endif
+
+void main()
+{
+ fragColor = finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
new file mode 100644
index 0000000..e74485b
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
@@ -0,0 +1,18 @@
+
+#if __VERSION__ == 120
+ attribute vec2 pos;
+ attribute vec4 color;
+
+ varying vec4 finalColor;
+#else
+ in vec2 pos;
+ in vec4 color;
+
+ noperspective out vec4 finalColor;
+#endif
+
+void main()
+{
+ gl_Position = gl_ModelViewMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl
new file mode 100644
index 0000000..af200bf
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl
@@ -0,0 +1,13 @@
+
+uniform vec4 color;
+
+#if __VERSION__ == 120
+ #define fragColor gl_FragColor
+#else
+ out vec4 fragColor;
+#endif
+
+void main()
+{
+ fragColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_vert.glsl
new file mode 100644
index 0000000..68d9941
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_vert.glsl
@@ -0,0 +1,11 @@
+
+#if __VERSION__ == 120
+ attribute vec2 pos;
+#else
+ in vec2 pos;
+#endif
+
+void main()
+{
+ gl_Position = gl_ModelViewMatrix * vec4(pos, 0.0, 1.0);
+}
More information about the Bf-blender-cvs
mailing list