From 385175ca656802abe0b744ce3974ab2541a3c1b5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 28 Jan 2014 13:10:56 +0900 Subject: [PATCH] Use the new shader system for 2d drawing. --- libs/video/renderer/glsl/Makefile.am | 6 ++-- libs/video/renderer/glsl/glsl_draw.c | 26 ++++++++++----- libs/video/renderer/glsl/quake2d.frag | 16 --------- libs/video/renderer/glsl/quakeforge.glsl | 42 ++++++++++++++++++++++++ libs/video/renderer/glsl/quakeico.vert | 21 ------------ 5 files changed, 62 insertions(+), 49 deletions(-) delete mode 100644 libs/video/renderer/glsl/quake2d.frag delete mode 100644 libs/video/renderer/glsl/quakeico.vert diff --git a/libs/video/renderer/glsl/Makefile.am b/libs/video/renderer/glsl/Makefile.am index 1daa73c78..933108b6b 100644 --- a/libs/video/renderer/glsl/Makefile.am +++ b/libs/video/renderer/glsl/Makefile.am @@ -4,11 +4,9 @@ AM_CFLAGS= @PREFER_PIC@ AM_CPPFLAGS= -I$(top_srcdir)/include $(GLX_CFLAGS) shader_src= quakeforge.glsl \ - iqm.frag iqm.vert \ - quake2d.frag quakeico.vert + iqm.frag iqm.vert shader_gen= quakeforge.slc \ - iqm.fc iqm.vc \ - quake2d.fc quakeico.vc + iqm.fc iqm.vc glsl_src = \ glsl_alias.c glsl_bsp.c glsl_draw.c glsl_fog.c glsl_iqm.c glsl_lightmap.c \ diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index a42bc9370..528dc60da 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -72,13 +72,18 @@ typedef struct { float color[4]; } drawvert_t; -static const char quakeicon_vert[] = -#include "quakeico.vc" -; +static const char *twod_vert_effects[] = +{ + "QuakeForge.Vertex.2d", + 0 +}; -static const char quake2d_frag[] = -#include "quake2d.fc" -; +static const char *twod_frag_effects[] = +{ + "QuakeForge.Fragment.palette", + "QuakeForge.Fragment.2d", + 0 +}; static float proj_matrix[16]; @@ -364,6 +369,7 @@ Draw_ClearCache (int phase) void glsl_Draw_Init (void) { + shader_t *vert_shader, *frag_shader; int i; int frag, vert; qpic_t *pic; @@ -377,9 +383,11 @@ glsl_Draw_Init (void) draw_queue = dstring_new (); - vert = GLSL_CompileShaderS ("quakeico.vert", quakeicon_vert, + vert_shader = GLSL_BuildShader (twod_vert_effects); + frag_shader = GLSL_BuildShader (twod_frag_effects); + vert = GLSL_CompileShader ("quakeico.vert", vert_shader, GL_VERTEX_SHADER); - frag = GLSL_CompileShaderS ("quake2d.frag", quake2d_frag, + frag = GLSL_CompileShader ("quake2d.frag", frag_shader, GL_FRAGMENT_SHADER); quake_2d.program = GLSL_LinkProgram ("quake2d", vert, frag); GLSL_ResolveShaderParam (quake_2d.program, &quake_2d.texture); @@ -387,6 +395,8 @@ glsl_Draw_Init (void) GLSL_ResolveShaderParam (quake_2d.program, &quake_2d.matrix); GLSL_ResolveShaderParam (quake_2d.program, &quake_2d.vertex); GLSL_ResolveShaderParam (quake_2d.program, &quake_2d.color); + GLSL_FreeShader (vert_shader); + GLSL_FreeShader (frag_shader); draw_scrap = GLSL_CreateScrap (2048, GL_LUMINANCE, 0); diff --git a/libs/video/renderer/glsl/quake2d.frag b/libs/video/renderer/glsl/quake2d.frag deleted file mode 100644 index 730b48e22..000000000 --- a/libs/video/renderer/glsl/quake2d.frag +++ /dev/null @@ -1,16 +0,0 @@ -//precision mediump float; -uniform sampler2D texture; -uniform sampler2D palette; -varying vec4 color; -varying vec2 st; - -void -main (void) -{ - float pix; - - pix = texture2D (texture, st).r; - if (pix == 1.0) - discard; - gl_FragColor = texture2D (palette, vec2 (pix, 0.0)) * color; -} diff --git a/libs/video/renderer/glsl/quakeforge.glsl b/libs/video/renderer/glsl/quakeforge.glsl index 66371483e..ff1fd57a2 100644 --- a/libs/video/renderer/glsl/quakeforge.glsl +++ b/libs/video/renderer/glsl/quakeforge.glsl @@ -389,3 +389,45 @@ main (void) discard; gl_FragColor = fogBlend (col); } + +-- Vertex.2d + +uniform mat4 mvp_mat; +attribute vec4 vcolor; +/** Vertex position. + + x, y, s, t + + \a vertex provides the onscreen location at which to draw the icon + (\a x, \a y) and texture coordinate for the icon (\a s=z, \a t=w). +*/ +attribute vec4 vertex; + +varying vec4 color; +varying vec2 st; + +void +main (void) +{ + gl_Position = mvp_mat * vec4 (vertex.xy, 0.0, 1.0); + st = vertex.zw; + color = vcolor; +} + +-- Fragment.2d + +//precision mediump float; +uniform sampler2D texture; +varying vec4 color; +varying vec2 st; + +void +main (void) +{ + float pix; + + pix = texture2D (texture, st).r; + if (pix == 1.0) + discard; + gl_FragColor = palettedColor (pix) * color; +} diff --git a/libs/video/renderer/glsl/quakeico.vert b/libs/video/renderer/glsl/quakeico.vert deleted file mode 100644 index 9f0399c75..000000000 --- a/libs/video/renderer/glsl/quakeico.vert +++ /dev/null @@ -1,21 +0,0 @@ -uniform mat4 mvp_mat; -attribute vec4 vcolor; -/** Vertex position. - - x, y, s, t - - \a vertex provides the onscreen location at which to draw the icon - (\a x, \a y) and texture coordinate for the icon (\a s=z, \a t=w). -*/ -attribute vec4 vertex; - -varying vec4 color; -varying vec2 st; - -void -main (void) -{ - gl_Position = mvp_mat * vec4 (vertex.xy, 0.0, 1.0); - st = vertex.zw; - color = vcolor; -}