Mercurial > sdl-ios-xcode
changeset 5235:8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 08 Feb 2011 20:23:52 -0800 |
parents | c015d3e63631 |
children | e82908c86c9c |
files | src/render/opengl/SDL_render_gl.c src/render/opengl/SDL_shaders_gl.c |
diffstat | 2 files changed, 30 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/render/opengl/SDL_render_gl.c Tue Feb 08 16:50:51 2011 -0800 +++ b/src/render/opengl/SDL_render_gl.c Tue Feb 08 20:23:52 2011 -0800 @@ -297,11 +297,6 @@ data->glDisable(GL_CULL_FACE); /* This ended up causing video discrepancies between OpenGL and Direct3D */ /*data->glEnable(GL_LINE_SMOOTH);*/ - if (data->GL_ARB_texture_rectangle_supported) { - data->glEnable(GL_TEXTURE_RECTANGLE_ARB); - } else { - data->glEnable(GL_TEXTURE_2D); - } data->updateSize = SDL_TRUE; return renderer;
--- a/src/render/opengl/SDL_shaders_gl.c Tue Feb 08 16:50:51 2011 -0800 +++ b/src/render/opengl/SDL_shaders_gl.c Tue Feb 08 20:23:52 2011 -0800 @@ -56,10 +56,16 @@ PFNGLUNIFORM1FARBPROC glUniform1fARB; PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; + SDL_bool GL_ARB_texture_rectangle_supported; + GL_Shader current_shader; GL_ShaderData shaders[NUM_SHADERS]; }; +/* + * NOTE: Always use sampler2D, etc here. We'll #define them to the + * texture_rectangle versions if we choose to use that extension. + */ static const char *shader_source[NUM_SHADERS][2] = { /* SHADER_NONE */ @@ -73,7 +79,7 @@ \ void main() \ { \ - gl_Position = ftransform(); \ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \ v_color = gl_Color; \ } \ ", @@ -97,7 +103,7 @@ \ void main() \ { \ - gl_Position = ftransform(); \ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \ v_color = gl_Color; \ v_texCoord = vec2(gl_MultiTexCoord0); \ } \ @@ -117,11 +123,15 @@ }; static SDL_bool -CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *source) +CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source) { GLint status; + const char *sources[2]; - ctx->glShaderSourceARB(shader, 1, &source, NULL); + sources[0] = defines; + sources[1] = source; + + ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL); ctx->glCompileShaderARB(shader); ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); if (status == 0) { @@ -146,7 +156,8 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data) { const int num_tmus_bound = 4; - GLint status; + const char *vert_defines = ""; + const char *frag_defines = ""; int i; GLint location; @@ -156,18 +167,25 @@ ctx->glGetError(); + /* Make sure we use the correct sampler type for our texture type */ + if (ctx->GL_ARB_texture_rectangle_supported) { + frag_defines = +"#define sampler2D sampler2DRect\n" +"#define texture2D texture2DRect\n"; + } + /* Create one program object to rule them all */ data->program = ctx->glCreateProgramObjectARB(); /* Create the vertex shader */ data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); - if (!CompileShader(ctx, data->vert_shader, shader_source[index][0])) { + if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) { return SDL_FALSE; } /* Create the fragment shader */ data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); - if (!CompileShader(ctx, data->frag_shader, shader_source[index][1])) { + if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) { return SDL_FALSE; } @@ -215,6 +233,11 @@ return NULL; } + if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") + || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { + ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE; + } + /* Check for shader support */ shaders_supported = SDL_FALSE; if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&