Fixed compiling on Windows
authorSam Lantinga
Wed, 09 Feb 2011 10:31:12 -0800
changeset 5238c0e9d3897a85
parent 5237 55b31686f82b
child 5239 0a154d1e9aa9
Fixed compiling on Windows
Added an untested shader for YV12 textures
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
src/render/opengl/SDL_shaders_gl.c
src/render/opengl/SDL_shaders_gl.h
     1.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Wed Feb 09 10:13:26 2011 -0800
     1.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Wed Feb 09 10:31:12 2011 -0800
     1.3 @@ -1055,6 +1055,14 @@
     1.4  			>
     1.5  		</File>
     1.6  		<File
     1.7 +			RelativePath="..\..\src\render\opengl\SDL_shaders_gl.c"
     1.8 +			>
     1.9 +		</File>
    1.10 +		<File
    1.11 +			RelativePath="..\..\src\render\opengl\SDL_shaders_gl.h"
    1.12 +			>
    1.13 +		</File>
    1.14 +		<File
    1.15  			RelativePath="..\..\src\video\SDL_shape.c"
    1.16  			>
    1.17  		</File>
     2.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Wed Feb 09 10:13:26 2011 -0800
     2.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Wed Feb 09 10:31:12 2011 -0800
     2.3 @@ -285,6 +285,7 @@
     2.4      <ClInclude Include="..\..\src\libm\math.h" />
     2.5      <ClInclude Include="..\..\src\libm\math_private.h" />
     2.6      <ClInclude Include="..\..\src\render\mmx.h" />
     2.7 +    <ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" />
     2.8      <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
     2.9      <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
    2.10      <ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
    2.11 @@ -373,6 +374,7 @@
    2.12      <ClCompile Include="..\..\src\libm\s_sin.c" />
    2.13      <ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
    2.14      <ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" />
    2.15 +    <ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" />
    2.16      <ClCompile Include="..\..\src\render\SDL_render.c" />
    2.17      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
    2.18      <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
     3.1 --- a/src/render/opengl/SDL_shaders_gl.c	Wed Feb 09 10:13:26 2011 -0800
     3.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Wed Feb 09 10:31:12 2011 -0800
     3.3 @@ -114,6 +114,58 @@
     3.4  "    gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
     3.5  "}"
     3.6      },
     3.7 +
     3.8 +    /* SHADER_YV12 */
     3.9 +    {
    3.10 +        /* vertex shader */
    3.11 +"varying vec4 v_color;\n"
    3.12 +"varying vec2 v_texCoord;\n"
    3.13 +"\n"
    3.14 +"void main()\n"
    3.15 +"{\n"
    3.16 +"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
    3.17 +"    v_color = gl_Color;\n"
    3.18 +"    v_texCoord = vec2(gl_MultiTexCoord0);\n"
    3.19 +"}",
    3.20 +        /* fragment shader */
    3.21 +"varying vec4 v_color;\n"
    3.22 +"varying vec2 v_texCoord;\n"
    3.23 +"uniform sampler2D tex0; // Y \n"
    3.24 +"uniform sampler2D tex1; // U \n"
    3.25 +"uniform sampler2D tex2; // V \n"
    3.26 +"\n"
    3.27 +"// YUV offset \n"
    3.28 +"const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n"
    3.29 +"\n"
    3.30 +"// RGB coefficients \n"
    3.31 +"const vec3 Rcoeff = vec3(1.164,  0.000,  1.596);\n"
    3.32 +"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n"
    3.33 +"const vec3 Bcoeff = vec3(1.164,  2.018,  0.000);\n"
    3.34 +"\n"
    3.35 +"void main()\n"
    3.36 +"{\n"
    3.37 +"    vec2 tcoord;\n"
    3.38 +"    vec3 yuv, rgb;\n"
    3.39 +"\n"
    3.40 +"    // Get the Y value \n"
    3.41 +"    tcoord = v_texCoord;\n"
    3.42 +"    yuv.x = texture2D(tex0, tcoord).r;\n"
    3.43 +"\n"
    3.44 +"    // Get the U and V values \n"
    3.45 +"    tcoord *= 0.5;\n"
    3.46 +"    yuv.y = texture2D(tex1, tcoord).r;\n"
    3.47 +"    yuv.z = texture2D(tex2, tcoord).r;\n"
    3.48 +"\n"
    3.49 +"    // Do the color transform \n"
    3.50 +"    yuv += offset;\n"
    3.51 +"    rgb.r = dot(yuv, Rcoeff);\n"
    3.52 +"    rgb.g = dot(yuv, Gcoeff);\n"
    3.53 +"    rgb.b = dot(yuv, Bcoeff);\n"
    3.54 +"\n"
    3.55 +"    // That was easy. :) \n"
    3.56 +"    gl_FragColor = vec4(rgb, 1.0) * v_color;\n"
    3.57 +"}"
    3.58 +    },
    3.59  };
    3.60  
    3.61  static SDL_bool
    3.62 @@ -209,10 +261,6 @@
    3.63  static void
    3.64  DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
    3.65  {
    3.66 -    if (index == SHADER_NONE) {
    3.67 -        return;
    3.68 -    }
    3.69 -
    3.70      ctx->glDeleteObjectARB(data->vert_shader);
    3.71      ctx->glDeleteObjectARB(data->frag_shader);
    3.72      ctx->glDeleteObjectARB(data->program);
    3.73 @@ -281,7 +329,6 @@
    3.74      /* Compile all the shaders */
    3.75      for (i = 0; i < NUM_SHADERS; ++i) {
    3.76          if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) {
    3.77 -fprintf(stderr, "Unable to compile shader!\n");
    3.78              GL_DestroyShaderContext(ctx);
    3.79              return NULL;
    3.80          }
     4.1 --- a/src/render/opengl/SDL_shaders_gl.h	Wed Feb 09 10:13:26 2011 -0800
     4.2 +++ b/src/render/opengl/SDL_shaders_gl.h	Wed Feb 09 10:31:12 2011 -0800
     4.3 @@ -27,7 +27,7 @@
     4.4      SHADER_NONE,
     4.5      SHADER_SOLID,
     4.6      SHADER_RGB,
     4.7 -    //SHADER_YV12,
     4.8 +    SHADER_YV12,
     4.9      NUM_SHADERS
    4.10  } GL_Shader;
    4.11