[gtk+/wip/ebassi/gles: 4/24] gdk: Move GLSL shaders into GResource
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/ebassi/gles: 4/24] gdk: Move GLSL shaders into GResource
- Date: Mon, 25 Apr 2016 11:34:42 +0000 (UTC)
commit 55537cccbd8129ed9fd3d00e8af07c05719516ac
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Apr 22 12:34:33 2016 +0100
gdk: Move GLSL shaders into GResource
Having the shaders inlined as C strings makes them harder to edit and
maintain.
gdk/Makefile.am | 46 ++++++++++-
gdk/gdk.c | 4 +
gdk/gdkgl.c | 116 ++++++--------------------
gdk/resources/glsl/gl2-texture-2d.fs.glsl | 9 ++
gdk/resources/glsl/gl2-texture-2d.vs.glsl | 13 +++
gdk/resources/glsl/gl2-texture-rect.fs.glsl | 9 ++
gdk/resources/glsl/gl2-texture-rect.vs.glsl | 13 +++
gdk/resources/glsl/gl3-texture-2d.fs.glsl | 11 +++
gdk/resources/glsl/gl3-texture-2d.vs.glsl | 13 +++
gdk/resources/glsl/gl3-texture-rect.fs.glsl | 9 ++
gdk/resources/glsl/gl3-texture-rect.vs.glsl | 13 +++
11 files changed, 164 insertions(+), 92 deletions(-)
---
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index 74e321f..f33c8ae 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -172,6 +172,8 @@ gdk_built_sources = \
gdkenumtypes.c \
gdkmarshalers.h \
gdkmarshalers.c \
+ gdkresources.h \
+ gdkresources.c \
gdkversionmacros.h
#
@@ -179,8 +181,8 @@ gdk_built_sources = \
#
gdkincludedir = $(includedir)/gtk-3.0/gdk
-gdkinclude_HEADERS = $(gdk_public_h_sources) gdkenumtypes.h gdkversionmacros.h
-nodist_gdkinclude_HEADERS = gdkconfig.h
+gdkinclude_HEADERS = $(gdk_public_h_sources)
+nodist_gdkinclude_HEADERS = gdkconfig.h gdkenumtypes.h gdkversionmacros.h
deprecatedincludedir = $(includedir)/gtk-3.0/gdk/deprecated
deprecatedinclude_HEADERS = $(deprecated_h_sources)
@@ -190,7 +192,9 @@ common_sources = \
$(gdk_c_sources) \
gdkenumtypes.c \
gdkmarshalers.c \
- gdkmarshalers.h
+ gdkmarshalers.h \
+ gdkresources.h \
+ gdkresources.c
libgdk_3_la_SOURCES = $(common_sources)
libgdk_3_la_CFLAGS = $(AM_CFLAGS) $(GDK_HIDDEN_VISIBILITY_CFLAGS)
@@ -442,6 +446,42 @@ stamp-gc-h: $(top_builddir)/config.status
$(AM_V_at) cd $(top_builddir) && $(SHELL) ./config.status gdk/gdkconfig.h \
&& echo timestamp > gdk/$(@F)
+#
+# Resources
+#
+gdk.gresource.xml: Makefile.am
+ $(AM_V_GEN) echo "<?xml version='1.0' encoding='UTF-8'?>" > $@; \
+ echo "<gresources>" >> $@; \
+ echo " <gresource prefix='/org/gtk/libgdk'>" >> $@; \
+ for f in $(srcdir)/resources/glsl/*.glsl; do \
+ n=`basename $$f`; \
+ echo " <file alias='glsl/$$n'>resources/glsl/$$n</file>" >> $@; \
+ done; \
+ echo " </gresource>" >> $@; \
+ echo "</gresources>" >> $@;
+
+glsl_sources = \
+ resources/glsl/gl3-texture-2d.fs.glsl \
+ resources/glsl/gl3-texture-2d.vs.glsl \
+ resources/glsl/gl3-texture-rect.fs.glsl \
+ resources/glsl/gl3-texture-rect.vs.glsl \
+ resources/glsl/gl2-texture-2d.fs.glsl \
+ resources/glsl/gl2-texture-2d.fs.glsl \
+ resources/glsl/gl2-texture-rect.vs.glsl \
+ resources/glsl/gl2-texture-rect.vs.glsl
+
+EXTRA_DIST += $(glsl_sources)
+CLEANFILES += gdk.gresource.xml
+
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies
$(builddir)/gdk.gresource.xml)
+
+gdkresources.h: gdk.gresource.xml
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \
+ --sourcedir=$(srcdir) --c-name _gdk --generate-header --manual-register
+gdkresources.c: gdk.gresource.xml $(resource_files)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \
+ --sourcedir=$(srcdir) --c-name _gdk --generate-source --manual-register
+
# ------------------- MSVC Build Items ----------------
MSVCPROJS = gdk-3
diff --git a/gdk/gdk.c b/gdk/gdk.c
index c9c3536..d57502a 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -30,6 +30,8 @@
#include "gdkinternals.h"
#include "gdkintl.h"
+#include "gdkresources.h"
+
#include "gdk-private.h"
#ifndef HAVE_XCONVERTCASE
@@ -274,6 +276,8 @@ gdk_pre_parse (void)
gdk_initialized = TRUE;
+ _gdk_register_resource ();
+
/* We set the fallback program class here, rather than lazily in
* gdk_get_program_class, since we don't want -name to override it.
*/
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index e8ba770..155e8cd 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -86,17 +86,24 @@ create_shader (int type,
static void
make_program (GdkGLContextProgram *program,
- const char *vertex_shader_code,
- const char *fragment_shader_code)
+ const char *vertex_shader_path,
+ const char *fragment_shader_path)
{
guint vertex_shader, fragment_shader;
+ GBytes *source;
int status;
- vertex_shader = create_shader (GL_VERTEX_SHADER, vertex_shader_code);
+ source = g_resources_lookup_data (vertex_shader_path, 0, NULL);
+ g_assert (source != NULL);
+ vertex_shader = create_shader (GL_VERTEX_SHADER, g_bytes_get_data (source, NULL));
+ g_bytes_unref (source);
if (vertex_shader == 0)
return;
- fragment_shader = create_shader (GL_FRAGMENT_SHADER, fragment_shader_code);
+ source = g_resources_lookup_data (fragment_shader_path, 0, NULL);
+ g_assert (source != NULL);
+ fragment_shader = create_shader (GL_FRAGMENT_SHADER, g_bytes_get_data (source, NULL));
+ g_bytes_unref (source);
if (fragment_shader == 0)
{
glDeleteShader (vertex_shader);
@@ -147,51 +154,16 @@ bind_vao (GdkGLContextPaintData *paint_data)
static void
use_texture_2d_program (GdkGLContextPaintData *paint_data)
{
- static const char *vertex_shader_code_150 =
- "#version 150\n"
- "uniform sampler2D map;"
- "in vec2 position;\n"
- "in vec2 uv;\n"
- "out vec2 vUv;\n"
- "void main() {\n"
- " gl_Position = vec4(position, 0, 1);\n"
- " vUv = uv;\n"
- "}\n";
- static const char *fragment_shader_code_150 =
- "#version 150\n"
- "in vec2 vUv;\n"
- "out vec4 vertexColor;\n"
- "uniform sampler2D map;\n"
- "void main() {\n"
- " vertexColor = texture2D (map, vUv);\n"
- "}\n";
- static const char *vertex_shader_code_130 =
- "#version 130\n"
- "uniform sampler2D map;"
- "attribute vec2 position;\n"
- "attribute vec2 uv;\n"
- "varying vec2 vUv;\n"
- "void main() {\n"
- " gl_Position = vec4(position, 0, 1);\n"
- " vUv = uv;\n"
- "}\n";
- static const char *fragment_shader_code_130 =
- "#version 130\n"
- "varying vec2 vUv;\n"
- "uniform sampler2D map;\n"
- "void main() {\n"
- " gl_FragColor = texture2D (map, vUv);\n"
- "}\n";
-
- const char *vertex_shader_code = paint_data->is_legacy
- ? vertex_shader_code_130
- : vertex_shader_code_150;
- const char *fragment_shader_code = paint_data->is_legacy
- ? fragment_shader_code_130
- : fragment_shader_code_150;
+ const char *vertex_shader_path = paint_data->is_legacy
+ ? "/org/gtk/libgdk/glsl/gl2-texture-2d.vs.glsl"
+ : "/org/gtk/libgdk/glsl/gl3-texture-2d.vs.glsl";
+
+ const char *fragment_shader_path = paint_data->is_legacy
+ ? "/org/gtk/libgdk/glsl/gl2-texture-2d.fs.glsl"
+ : "/org/gtk/libgdk/glsl/gl3-texture-2d.fs.glsl";
if (paint_data->texture_2d_quad_program.program == 0)
- make_program (&paint_data->texture_2d_quad_program, vertex_shader_code, fragment_shader_code);
+ make_program (&paint_data->texture_2d_quad_program, vertex_shader_path, fragment_shader_path);
if (paint_data->current_program != &paint_data->texture_2d_quad_program)
{
@@ -203,50 +175,16 @@ use_texture_2d_program (GdkGLContextPaintData *paint_data)
static void
use_texture_rect_program (GdkGLContextPaintData *paint_data)
{
- static const char *vertex_shader_code_150 =
- "#version 150\n"
- "uniform sampler2DRect map;\n"
- "attribute vec2 position;\n"
- "attribute vec2 uv;\n"
- "varying vec2 vUv;\n"
- "void main() {\n"
- " gl_Position = vec4(position, 0, 1);\n"
- " vUv = uv;\n"
- "}\n";
- static const char *fragment_shader_code_150 =
- "#version 150\n"
- "varying vec2 vUv;\n"
- "uniform sampler2DRect map;\n"
- "void main() {\n"
- " gl_FragColor = texture2DRect (map, vUv);\n"
- "}\n";
- static const char *vertex_shader_code_130 =
- "#version 130\n"
- "uniform sampler2DRect map;\n"
- "attribute vec2 position;\n"
- "attribute vec2 uv;\n"
- "varying vec2 vUv;\n"
- "void main() {\n"
- " gl_Position = vec4(position, 0, 1);\n"
- " vUv = uv;\n"
- "}\n";
- static const char *fragment_shader_code_130 =
- "#version 130\n"
- "varying vec2 vUv;\n"
- "uniform sampler2DRect map;\n"
- "void main() {\n"
- " gl_FragColor = texture2DRect (map, vUv);\n"
- "}\n";
-
- const char *vertex_shader_code = paint_data->is_legacy
- ? vertex_shader_code_130
- : vertex_shader_code_150;
- const char *fragment_shader_code = paint_data->is_legacy
- ? fragment_shader_code_130
- : fragment_shader_code_150;
+ const char *vertex_shader_path = paint_data->is_legacy
+ ? "/org/gtk/libgdk/glsl/gl2-texture-rect.vs.glsl"
+ : "/org/gtk/libgdk/glsl/gl3-texture-rect.vs.glsl";
+
+ const char *fragment_shader_path = paint_data->is_legacy
+ ? "/org/gtk/libgdk/glsl/gl2-texture-rect.fs.glsl"
+ : "/org/gtk/libgdk/glsl/gl3-texture-rect.vs.glsl";
if (paint_data->texture_rect_quad_program.program == 0)
- make_program (&paint_data->texture_rect_quad_program, vertex_shader_code, fragment_shader_code);
+ make_program (&paint_data->texture_rect_quad_program, vertex_shader_path, fragment_shader_path);
if (paint_data->current_program != &paint_data->texture_rect_quad_program)
{
diff --git a/gdk/resources/glsl/gl2-texture-2d.fs.glsl b/gdk/resources/glsl/gl2-texture-2d.fs.glsl
new file mode 100644
index 0000000..d0bacfb
--- /dev/null
+++ b/gdk/resources/glsl/gl2-texture-2d.fs.glsl
@@ -0,0 +1,9 @@
+#version 130
+
+varying vec2 vUv;
+
+uniform sampler2D map;
+
+void main() {
+ gl_FragColor = texture2D (map, vUv);
+}
diff --git a/gdk/resources/glsl/gl2-texture-2d.vs.glsl b/gdk/resources/glsl/gl2-texture-2d.vs.glsl
new file mode 100644
index 0000000..bf9fdbb
--- /dev/null
+++ b/gdk/resources/glsl/gl2-texture-2d.vs.glsl
@@ -0,0 +1,13 @@
+#version 130
+
+uniform sampler2D map;
+
+attribute vec2 position;
+attribute vec2 uv;
+
+varying vec2 vUv;
+
+void main() {
+ gl_Position = vec4(position, 0, 1);
+ vUv = uv;
+}
diff --git a/gdk/resources/glsl/gl2-texture-rect.fs.glsl b/gdk/resources/glsl/gl2-texture-rect.fs.glsl
new file mode 100644
index 0000000..fe0b870
--- /dev/null
+++ b/gdk/resources/glsl/gl2-texture-rect.fs.glsl
@@ -0,0 +1,9 @@
+#version 130
+
+varying vec2 vUv;
+
+uniform sampler2DRect map;
+
+void main() {
+ gl_FragColor = texture2DRect (map, vUv);
+}
diff --git a/gdk/resources/glsl/gl2-texture-rect.vs.glsl b/gdk/resources/glsl/gl2-texture-rect.vs.glsl
new file mode 100644
index 0000000..834d31d
--- /dev/null
+++ b/gdk/resources/glsl/gl2-texture-rect.vs.glsl
@@ -0,0 +1,13 @@
+#version 130
+
+uniform sampler2DRect map;
+
+attribute vec2 position;
+attribute vec2 uv;
+
+varying vec2 vUv;
+
+void main() {
+ gl_Position = vec4(position, 0, 1);
+ vUv = uv;
+}
diff --git a/gdk/resources/glsl/gl3-texture-2d.fs.glsl b/gdk/resources/glsl/gl3-texture-2d.fs.glsl
new file mode 100644
index 0000000..fe353a6
--- /dev/null
+++ b/gdk/resources/glsl/gl3-texture-2d.fs.glsl
@@ -0,0 +1,11 @@
+#version 150
+
+in vec2 vUv;
+
+out vec4 vertexColor;
+
+uniform sampler2D map;
+
+void main() {
+ vertexColor = texture2D (map, vUv);
+}
diff --git a/gdk/resources/glsl/gl3-texture-2d.vs.glsl b/gdk/resources/glsl/gl3-texture-2d.vs.glsl
new file mode 100644
index 0000000..2c61f05
--- /dev/null
+++ b/gdk/resources/glsl/gl3-texture-2d.vs.glsl
@@ -0,0 +1,13 @@
+#version 150
+
+uniform sampler2D map;
+
+in vec2 position;
+in vec2 uv;
+
+out vec2 vUv;
+
+void main() {
+ gl_Position = vec4(position, 0, 1);
+ vUv = uv;
+}
diff --git a/gdk/resources/glsl/gl3-texture-rect.fs.glsl b/gdk/resources/glsl/gl3-texture-rect.fs.glsl
new file mode 100644
index 0000000..bf6884e
--- /dev/null
+++ b/gdk/resources/glsl/gl3-texture-rect.fs.glsl
@@ -0,0 +1,9 @@
+#version 150
+
+varying vec2 vUv;
+
+uniform sampler2DRect map;
+
+void main() {
+ gl_FragColor = texture2DRect (map, vUv);
+}
diff --git a/gdk/resources/glsl/gl3-texture-rect.vs.glsl b/gdk/resources/glsl/gl3-texture-rect.vs.glsl
new file mode 100644
index 0000000..874ef6c
--- /dev/null
+++ b/gdk/resources/glsl/gl3-texture-rect.vs.glsl
@@ -0,0 +1,13 @@
+#version 150
+
+uniform sampler2DRect map;
+
+attribute vec2 position;
+attribute vec2 uv;
+
+varying vec2 vUv;
+
+void main() {
+ gl_Position = vec4(position, 0, 1);
+ vUv = uv;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]