src/render/opengl/SDL_shaders_gl.c
changeset 5238 c0e9d3897a85
parent 5237 55b31686f82b
child 5262 b530ef003506
     1.1 --- a/src/render/opengl/SDL_shaders_gl.c	Wed Feb 09 10:13:26 2011 -0800
     1.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Wed Feb 09 10:31:12 2011 -0800
     1.3 @@ -114,6 +114,58 @@
     1.4  "    gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
     1.5  "}"
     1.6      },
     1.7 +
     1.8 +    /* SHADER_YV12 */
     1.9 +    {
    1.10 +        /* vertex shader */
    1.11 +"varying vec4 v_color;\n"
    1.12 +"varying vec2 v_texCoord;\n"
    1.13 +"\n"
    1.14 +"void main()\n"
    1.15 +"{\n"
    1.16 +"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
    1.17 +"    v_color = gl_Color;\n"
    1.18 +"    v_texCoord = vec2(gl_MultiTexCoord0);\n"
    1.19 +"}",
    1.20 +        /* fragment shader */
    1.21 +"varying vec4 v_color;\n"
    1.22 +"varying vec2 v_texCoord;\n"
    1.23 +"uniform sampler2D tex0; // Y \n"
    1.24 +"uniform sampler2D tex1; // U \n"
    1.25 +"uniform sampler2D tex2; // V \n"
    1.26 +"\n"
    1.27 +"// YUV offset \n"
    1.28 +"const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n"
    1.29 +"\n"
    1.30 +"// RGB coefficients \n"
    1.31 +"const vec3 Rcoeff = vec3(1.164,  0.000,  1.596);\n"
    1.32 +"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n"
    1.33 +"const vec3 Bcoeff = vec3(1.164,  2.018,  0.000);\n"
    1.34 +"\n"
    1.35 +"void main()\n"
    1.36 +"{\n"
    1.37 +"    vec2 tcoord;\n"
    1.38 +"    vec3 yuv, rgb;\n"
    1.39 +"\n"
    1.40 +"    // Get the Y value \n"
    1.41 +"    tcoord = v_texCoord;\n"
    1.42 +"    yuv.x = texture2D(tex0, tcoord).r;\n"
    1.43 +"\n"
    1.44 +"    // Get the U and V values \n"
    1.45 +"    tcoord *= 0.5;\n"
    1.46 +"    yuv.y = texture2D(tex1, tcoord).r;\n"
    1.47 +"    yuv.z = texture2D(tex2, tcoord).r;\n"
    1.48 +"\n"
    1.49 +"    // Do the color transform \n"
    1.50 +"    yuv += offset;\n"
    1.51 +"    rgb.r = dot(yuv, Rcoeff);\n"
    1.52 +"    rgb.g = dot(yuv, Gcoeff);\n"
    1.53 +"    rgb.b = dot(yuv, Bcoeff);\n"
    1.54 +"\n"
    1.55 +"    // That was easy. :) \n"
    1.56 +"    gl_FragColor = vec4(rgb, 1.0) * v_color;\n"
    1.57 +"}"
    1.58 +    },
    1.59  };
    1.60  
    1.61  static SDL_bool
    1.62 @@ -209,10 +261,6 @@
    1.63  static void
    1.64  DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
    1.65  {
    1.66 -    if (index == SHADER_NONE) {
    1.67 -        return;
    1.68 -    }
    1.69 -
    1.70      ctx->glDeleteObjectARB(data->vert_shader);
    1.71      ctx->glDeleteObjectARB(data->frag_shader);
    1.72      ctx->glDeleteObjectARB(data->program);
    1.73 @@ -281,7 +329,6 @@
    1.74      /* Compile all the shaders */
    1.75      for (i = 0; i < NUM_SHADERS; ++i) {
    1.76          if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) {
    1.77 -fprintf(stderr, "Unable to compile shader!\n");
    1.78              GL_DestroyShaderContext(ctx);
    1.79              return NULL;
    1.80          }