comparison src/render/opengl/SDL_shaders_gl.c @ 5243:c0e9d3897a85

Fixed compiling on Windows Added an untested shader for YV12 textures
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Feb 2011 10:31:12 -0800
parents 55b31686f82b
children b530ef003506
comparison
equal deleted inserted replaced
5242:55b31686f82b 5243:c0e9d3897a85
112 "void main()\n" 112 "void main()\n"
113 "{\n" 113 "{\n"
114 " gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n" 114 " gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
115 "}" 115 "}"
116 }, 116 },
117
118 /* SHADER_YV12 */
119 {
120 /* vertex shader */
121 "varying vec4 v_color;\n"
122 "varying vec2 v_texCoord;\n"
123 "\n"
124 "void main()\n"
125 "{\n"
126 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
127 " v_color = gl_Color;\n"
128 " v_texCoord = vec2(gl_MultiTexCoord0);\n"
129 "}",
130 /* fragment shader */
131 "varying vec4 v_color;\n"
132 "varying vec2 v_texCoord;\n"
133 "uniform sampler2D tex0; // Y \n"
134 "uniform sampler2D tex1; // U \n"
135 "uniform sampler2D tex2; // V \n"
136 "\n"
137 "// YUV offset \n"
138 "const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n"
139 "\n"
140 "// RGB coefficients \n"
141 "const vec3 Rcoeff = vec3(1.164, 0.000, 1.596);\n"
142 "const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n"
143 "const vec3 Bcoeff = vec3(1.164, 2.018, 0.000);\n"
144 "\n"
145 "void main()\n"
146 "{\n"
147 " vec2 tcoord;\n"
148 " vec3 yuv, rgb;\n"
149 "\n"
150 " // Get the Y value \n"
151 " tcoord = v_texCoord;\n"
152 " yuv.x = texture2D(tex0, tcoord).r;\n"
153 "\n"
154 " // Get the U and V values \n"
155 " tcoord *= 0.5;\n"
156 " yuv.y = texture2D(tex1, tcoord).r;\n"
157 " yuv.z = texture2D(tex2, tcoord).r;\n"
158 "\n"
159 " // Do the color transform \n"
160 " yuv += offset;\n"
161 " rgb.r = dot(yuv, Rcoeff);\n"
162 " rgb.g = dot(yuv, Gcoeff);\n"
163 " rgb.b = dot(yuv, Bcoeff);\n"
164 "\n"
165 " // That was easy. :) \n"
166 " gl_FragColor = vec4(rgb, 1.0) * v_color;\n"
167 "}"
168 },
117 }; 169 };
118 170
119 static SDL_bool 171 static SDL_bool
120 CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source) 172 CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source)
121 { 173 {
207 } 259 }
208 260
209 static void 261 static void
210 DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data) 262 DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
211 { 263 {
212 if (index == SHADER_NONE) {
213 return;
214 }
215
216 ctx->glDeleteObjectARB(data->vert_shader); 264 ctx->glDeleteObjectARB(data->vert_shader);
217 ctx->glDeleteObjectARB(data->frag_shader); 265 ctx->glDeleteObjectARB(data->frag_shader);
218 ctx->glDeleteObjectARB(data->program); 266 ctx->glDeleteObjectARB(data->program);
219 } 267 }
220 268
279 } 327 }
280 328
281 /* Compile all the shaders */ 329 /* Compile all the shaders */
282 for (i = 0; i < NUM_SHADERS; ++i) { 330 for (i = 0; i < NUM_SHADERS; ++i) {
283 if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) { 331 if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) {
284 fprintf(stderr, "Unable to compile shader!\n");
285 GL_DestroyShaderContext(ctx); 332 GL_DestroyShaderContext(ctx);
286 return NULL; 333 return NULL;
287 } 334 }
288 } 335 }
289 336