src/render/opengl/SDL_shaders_gl.c
changeset 5230 8efa43b915be
parent 5229 c015d3e63631
child 5231 e82908c86c9c
     1.1 --- a/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 16:50:51 2011 -0800
     1.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 20:23:52 2011 -0800
     1.3 @@ -56,10 +56,16 @@
     1.4      PFNGLUNIFORM1FARBPROC glUniform1fARB;
     1.5      PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
     1.6  
     1.7 +    SDL_bool GL_ARB_texture_rectangle_supported;
     1.8 +
     1.9      GL_Shader current_shader;
    1.10      GL_ShaderData shaders[NUM_SHADERS];
    1.11  };
    1.12  
    1.13 +/*
    1.14 + * NOTE: Always use sampler2D, etc here. We'll #define them to the
    1.15 + *  texture_rectangle versions if we choose to use that extension.
    1.16 + */
    1.17  static const char *shader_source[NUM_SHADERS][2] =
    1.18  {
    1.19      /* SHADER_NONE */
    1.20 @@ -73,7 +79,7 @@
    1.21   \
    1.22  void main() \
    1.23  { \
    1.24 -    gl_Position = ftransform(); \
    1.25 +    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
    1.26      v_color = gl_Color; \
    1.27  } \
    1.28  ",
    1.29 @@ -97,7 +103,7 @@
    1.30   \
    1.31  void main() \
    1.32  { \
    1.33 -    gl_Position = ftransform(); \
    1.34 +    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
    1.35      v_color = gl_Color; \
    1.36      v_texCoord = vec2(gl_MultiTexCoord0); \
    1.37  } \
    1.38 @@ -117,11 +123,15 @@
    1.39  };
    1.40  
    1.41  static SDL_bool
    1.42 -CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *source)
    1.43 +CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source)
    1.44  {
    1.45      GLint status;
    1.46 +    const char *sources[2];
    1.47  
    1.48 -    ctx->glShaderSourceARB(shader, 1, &source, NULL);
    1.49 +    sources[0] = defines;
    1.50 +    sources[1] = source;
    1.51 +
    1.52 +    ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL);
    1.53      ctx->glCompileShaderARB(shader);
    1.54      ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
    1.55      if (status == 0) {
    1.56 @@ -146,7 +156,8 @@
    1.57  CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
    1.58  {
    1.59      const int num_tmus_bound = 4;
    1.60 -    GLint status;
    1.61 +    const char *vert_defines = "";
    1.62 +    const char *frag_defines = "";
    1.63      int i;
    1.64      GLint location;
    1.65  
    1.66 @@ -156,18 +167,25 @@
    1.67  
    1.68      ctx->glGetError();
    1.69  
    1.70 +    /* Make sure we use the correct sampler type for our texture type */
    1.71 +    if (ctx->GL_ARB_texture_rectangle_supported) {
    1.72 +        frag_defines = 
    1.73 +"#define sampler2D sampler2DRect\n"
    1.74 +"#define texture2D texture2DRect\n";
    1.75 +    }
    1.76 +
    1.77      /* Create one program object to rule them all */
    1.78      data->program = ctx->glCreateProgramObjectARB();
    1.79  
    1.80      /* Create the vertex shader */
    1.81      data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    1.82 -    if (!CompileShader(ctx, data->vert_shader, shader_source[index][0])) {
    1.83 +    if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) {
    1.84          return SDL_FALSE;
    1.85      }
    1.86  
    1.87      /* Create the fragment shader */
    1.88      data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    1.89 -    if (!CompileShader(ctx, data->frag_shader, shader_source[index][1])) {
    1.90 +    if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) {
    1.91          return SDL_FALSE;
    1.92      }
    1.93  
    1.94 @@ -215,6 +233,11 @@
    1.95          return NULL;
    1.96      }
    1.97  
    1.98 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
    1.99 +        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   1.100 +        ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE;
   1.101 +    }
   1.102 +
   1.103      /* Check for shader support */
   1.104      shaders_supported = SDL_FALSE;
   1.105      if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&