forked from AuroraMiddleware/gtk
demo: Add GLES support to the GtkGLArea demo
We need new shaders, and we need to select the correct shader when building the program we use to render the triangle.
This commit is contained in:
parent
b993c7db63
commit
872b5115ea
@ -199,8 +199,10 @@
|
||||
<file>popover.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/glarea">
|
||||
<file>glarea-fragment.glsl</file>
|
||||
<file>glarea-vertex.glsl</file>
|
||||
<file>glarea-gl.fs.glsl</file>
|
||||
<file>glarea-gl.vs.glsl</file>
|
||||
<file>glarea-gles.fs.glsl</file>
|
||||
<file>glarea-gles.vs.glsl</file>
|
||||
</gresource>
|
||||
<gresource prefix="/font_features">
|
||||
<file>font-features.ui</file>
|
||||
|
7
demos/gtk-demo/glarea-gles.fs.glsl
Normal file
7
demos/gtk-demo/glarea-gles.fs.glsl
Normal file
@ -0,0 +1,7 @@
|
||||
precision highp float;
|
||||
|
||||
void main() {
|
||||
float lerpVal = gl_FragCoord.y / 500.0f;
|
||||
|
||||
gl_FragColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpVal);
|
||||
}
|
7
demos/gtk-demo/glarea-gles.vs.glsl
Normal file
7
demos/gtk-demo/glarea-gles.vs.glsl
Normal file
@ -0,0 +1,7 @@
|
||||
attribute vec4 position;
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp * position;
|
||||
}
|
@ -93,7 +93,9 @@ create_shader (int type,
|
||||
|
||||
/* Initialize the shaders and link them into a program */
|
||||
static void
|
||||
init_shaders (GLuint *program_out,
|
||||
init_shaders (const char *vertex_path,
|
||||
const char *fragment_path,
|
||||
GLuint *program_out,
|
||||
GLuint *mvp_out)
|
||||
{
|
||||
GLuint vertex, fragment;
|
||||
@ -102,7 +104,7 @@ init_shaders (GLuint *program_out,
|
||||
int status;
|
||||
GBytes *source;
|
||||
|
||||
source = g_resources_lookup_data ("/glarea/glarea-vertex.glsl", 0, NULL);
|
||||
source = g_resources_lookup_data (vertex_path, 0, NULL);
|
||||
vertex = create_shader (GL_VERTEX_SHADER, g_bytes_get_data (source, NULL));
|
||||
g_bytes_unref (source);
|
||||
|
||||
@ -112,7 +114,7 @@ init_shaders (GLuint *program_out,
|
||||
return;
|
||||
}
|
||||
|
||||
source = g_resources_lookup_data ("/glarea/glarea-fragment.glsl", 0, NULL);
|
||||
source = g_resources_lookup_data (fragment_path, 0, NULL);
|
||||
fragment = create_shader (GL_FRAGMENT_SHADER, g_bytes_get_data (source, NULL));
|
||||
g_bytes_unref (source);
|
||||
|
||||
@ -218,13 +220,29 @@ static GLuint mvp_location;
|
||||
static void
|
||||
realize (GtkWidget *widget)
|
||||
{
|
||||
const char *vertex_path, *fragment_path;
|
||||
GdkGLContext *context;
|
||||
|
||||
gtk_gl_area_make_current (GTK_GL_AREA (widget));
|
||||
|
||||
if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
|
||||
return;
|
||||
|
||||
context = gtk_gl_area_get_context (GTK_GL_AREA (widget));
|
||||
|
||||
if (gdk_gl_context_get_use_es (context))
|
||||
{
|
||||
vertex_path = "/glarea/glarea-gles.vs.glsl";
|
||||
fragment_path = "/glarea/glarea-gles.fs.glsl";
|
||||
}
|
||||
else
|
||||
{
|
||||
vertex_path = "/glarea/glarea-gl.vs.glsl";
|
||||
fragment_path = "/glarea/glarea-gl.fs.glsl";
|
||||
}
|
||||
|
||||
init_buffers (&position_buffer, NULL);
|
||||
init_shaders (&program, &mvp_location);
|
||||
init_shaders (vertex_path, fragment_path, &program, &mvp_location);
|
||||
}
|
||||
|
||||
/* We should tear down the state when unrealizing */
|
||||
|
Loading…
Reference in New Issue
Block a user