mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
gdk: Move GLSL shaders into GResource
Having the shaders inlined as C strings makes them harder to edit and maintain.
This commit is contained in:
parent
d7b5ea89eb
commit
55537cccbd
@ -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
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
112
gdk/gdkgl.c
112
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_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 *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 *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_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 *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 *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)
|
||||
{
|
||||
|
9
gdk/resources/glsl/gl2-texture-2d.fs.glsl
Normal file
9
gdk/resources/glsl/gl2-texture-2d.fs.glsl
Normal file
@ -0,0 +1,9 @@
|
||||
#version 130
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
uniform sampler2D map;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D (map, vUv);
|
||||
}
|
13
gdk/resources/glsl/gl2-texture-2d.vs.glsl
Normal file
13
gdk/resources/glsl/gl2-texture-2d.vs.glsl
Normal file
@ -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;
|
||||
}
|
9
gdk/resources/glsl/gl2-texture-rect.fs.glsl
Normal file
9
gdk/resources/glsl/gl2-texture-rect.fs.glsl
Normal file
@ -0,0 +1,9 @@
|
||||
#version 130
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
uniform sampler2DRect map;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2DRect (map, vUv);
|
||||
}
|
13
gdk/resources/glsl/gl2-texture-rect.vs.glsl
Normal file
13
gdk/resources/glsl/gl2-texture-rect.vs.glsl
Normal file
@ -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;
|
||||
}
|
11
gdk/resources/glsl/gl3-texture-2d.fs.glsl
Normal file
11
gdk/resources/glsl/gl3-texture-2d.fs.glsl
Normal file
@ -0,0 +1,11 @@
|
||||
#version 150
|
||||
|
||||
in vec2 vUv;
|
||||
|
||||
out vec4 vertexColor;
|
||||
|
||||
uniform sampler2D map;
|
||||
|
||||
void main() {
|
||||
vertexColor = texture2D (map, vUv);
|
||||
}
|
13
gdk/resources/glsl/gl3-texture-2d.vs.glsl
Normal file
13
gdk/resources/glsl/gl3-texture-2d.vs.glsl
Normal file
@ -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;
|
||||
}
|
9
gdk/resources/glsl/gl3-texture-rect.fs.glsl
Normal file
9
gdk/resources/glsl/gl3-texture-rect.fs.glsl
Normal file
@ -0,0 +1,9 @@
|
||||
#version 150
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
uniform sampler2DRect map;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2DRect (map, vUv);
|
||||
}
|
13
gdk/resources/glsl/gl3-texture-rect.vs.glsl
Normal file
13
gdk/resources/glsl/gl3-texture-rect.vs.glsl
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user