Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 9, 2011
1 parent e6897a7 commit e3650ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/render/opengl/SDL_render_gl.c
Expand Up @@ -297,11 +297,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
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;
Expand Down
37 changes: 30 additions & 7 deletions src/render/opengl/SDL_shaders_gl.c
Expand Up @@ -56,10 +56,16 @@ struct GL_ShaderContext
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 */
Expand All @@ -73,7 +79,7 @@ varying vec4 v_color; \
\
void main() \
{ \
gl_Position = ftransform(); \
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
v_color = gl_Color; \
} \
",
Expand All @@ -97,7 +103,7 @@ varying vec2 v_texCoord; \
\
void main() \
{ \
gl_Position = ftransform(); \
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
v_color = gl_Color; \
v_texCoord = vec2(gl_MultiTexCoord0); \
} \
Expand All @@ -117,11 +123,15 @@ void main() \
};

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) {
Expand All @@ -146,7 +156,8 @@ static SDL_bool
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;

Expand All @@ -156,18 +167,25 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)

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;
}

Expand Down Expand Up @@ -215,6 +233,11 @@ GL_CreateShaderContext()
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") &&
Expand Down

0 comments on commit e3650ba

Please sign in to comment.