Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
authorSam Lantinga <slouken@libsdl.org>
Tue, 08 Feb 2011 20:23:52 -0800
changeset 52308efa43b915be
parent 5229 c015d3e63631
child 5231 e82908c86c9c
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
src/render/opengl/SDL_render_gl.c
src/render/opengl/SDL_shaders_gl.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Tue Feb 08 16:50:51 2011 -0800
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Tue Feb 08 20:23:52 2011 -0800
     1.3 @@ -297,11 +297,6 @@
     1.4      data->glDisable(GL_CULL_FACE);
     1.5      /* This ended up causing video discrepancies between OpenGL and Direct3D */
     1.6      /*data->glEnable(GL_LINE_SMOOTH);*/
     1.7 -    if (data->GL_ARB_texture_rectangle_supported) {
     1.8 -        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
     1.9 -    } else {
    1.10 -        data->glEnable(GL_TEXTURE_2D);
    1.11 -    }
    1.12      data->updateSize = SDL_TRUE;
    1.13  
    1.14      return renderer;
     2.1 --- a/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 16:50:51 2011 -0800
     2.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 20:23:52 2011 -0800
     2.3 @@ -56,10 +56,16 @@
     2.4      PFNGLUNIFORM1FARBPROC glUniform1fARB;
     2.5      PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
     2.6  
     2.7 +    SDL_bool GL_ARB_texture_rectangle_supported;
     2.8 +
     2.9      GL_Shader current_shader;
    2.10      GL_ShaderData shaders[NUM_SHADERS];
    2.11  };
    2.12  
    2.13 +/*
    2.14 + * NOTE: Always use sampler2D, etc here. We'll #define them to the
    2.15 + *  texture_rectangle versions if we choose to use that extension.
    2.16 + */
    2.17  static const char *shader_source[NUM_SHADERS][2] =
    2.18  {
    2.19      /* SHADER_NONE */
    2.20 @@ -73,7 +79,7 @@
    2.21   \
    2.22  void main() \
    2.23  { \
    2.24 -    gl_Position = ftransform(); \
    2.25 +    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
    2.26      v_color = gl_Color; \
    2.27  } \
    2.28  ",
    2.29 @@ -97,7 +103,7 @@
    2.30   \
    2.31  void main() \
    2.32  { \
    2.33 -    gl_Position = ftransform(); \
    2.34 +    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
    2.35      v_color = gl_Color; \
    2.36      v_texCoord = vec2(gl_MultiTexCoord0); \
    2.37  } \
    2.38 @@ -117,11 +123,15 @@
    2.39  };
    2.40  
    2.41  static SDL_bool
    2.42 -CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *source)
    2.43 +CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source)
    2.44  {
    2.45      GLint status;
    2.46 +    const char *sources[2];
    2.47  
    2.48 -    ctx->glShaderSourceARB(shader, 1, &source, NULL);
    2.49 +    sources[0] = defines;
    2.50 +    sources[1] = source;
    2.51 +
    2.52 +    ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL);
    2.53      ctx->glCompileShaderARB(shader);
    2.54      ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
    2.55      if (status == 0) {
    2.56 @@ -146,7 +156,8 @@
    2.57  CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
    2.58  {
    2.59      const int num_tmus_bound = 4;
    2.60 -    GLint status;
    2.61 +    const char *vert_defines = "";
    2.62 +    const char *frag_defines = "";
    2.63      int i;
    2.64      GLint location;
    2.65  
    2.66 @@ -156,18 +167,25 @@
    2.67  
    2.68      ctx->glGetError();
    2.69  
    2.70 +    /* Make sure we use the correct sampler type for our texture type */
    2.71 +    if (ctx->GL_ARB_texture_rectangle_supported) {
    2.72 +        frag_defines = 
    2.73 +"#define sampler2D sampler2DRect\n"
    2.74 +"#define texture2D texture2DRect\n";
    2.75 +    }
    2.76 +
    2.77      /* Create one program object to rule them all */
    2.78      data->program = ctx->glCreateProgramObjectARB();
    2.79  
    2.80      /* Create the vertex shader */
    2.81      data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    2.82 -    if (!CompileShader(ctx, data->vert_shader, shader_source[index][0])) {
    2.83 +    if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) {
    2.84          return SDL_FALSE;
    2.85      }
    2.86  
    2.87      /* Create the fragment shader */
    2.88      data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    2.89 -    if (!CompileShader(ctx, data->frag_shader, shader_source[index][1])) {
    2.90 +    if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) {
    2.91          return SDL_FALSE;
    2.92      }
    2.93  
    2.94 @@ -215,6 +233,11 @@
    2.95          return NULL;
    2.96      }
    2.97  
    2.98 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
    2.99 +        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   2.100 +        ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE;
   2.101 +    }
   2.102 +
   2.103      /* Check for shader support */
   2.104      shaders_supported = SDL_FALSE;
   2.105      if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&