Mercurial > sdl-ios-xcode
annotate src/render/opengl/SDL_shaders_gl.c @ 5236:e82908c86c9c
Made the shaders easier to debug when they don't compile
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 08 Feb 2011 20:31:39 -0800 |
parents | 8efa43b915be |
children | 55b31686f82b |
rev | line source |
---|---|
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2010 Sam Lantinga |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 #include "SDL_stdinc.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #include "SDL_log.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "SDL_opengl.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "SDL_video.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "SDL_shaders_gl.h" |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 /* OpenGL shader implementation */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
34 /*#define DEBUG_SHADERS*/ |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
35 |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 typedef struct |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 GLenum program; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 GLenum vert_shader; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 GLenum frag_shader; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 } GL_ShaderData; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 struct GL_ShaderContext |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 GLenum (*glGetError)(void); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 PFNGLATTACHOBJECTARBPROC glAttachObjectARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 PFNGLCOMPILESHADERARBPROC glCompileShaderARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 PFNGLGETINFOLOGARBPROC glGetInfoLogARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 PFNGLLINKPROGRAMARBPROC glLinkProgramARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 PFNGLSHADERSOURCEARBPROC glShaderSourceARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 PFNGLUNIFORM1IARBPROC glUniform1iARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 PFNGLUNIFORM1FARBPROC glUniform1fARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
61 SDL_bool GL_ARB_texture_rectangle_supported; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
62 |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 GL_Shader current_shader; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 GL_ShaderData shaders[NUM_SHADERS]; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 }; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
67 /* |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
68 * NOTE: Always use sampler2D, etc here. We'll #define them to the |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
69 * texture_rectangle versions if we choose to use that extension. |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
70 */ |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 static const char *shader_source[NUM_SHADERS][2] = |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 /* SHADER_NONE */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 { NULL, NULL }, |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 /* SHADER_SOLID */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 /* vertex shader */ |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
79 "varying vec4 v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
80 "\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
81 "void main()\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
82 "{\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
83 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
84 " v_color = gl_Color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
85 "}", |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 /* fragment shader */ |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
87 "varying vec4 v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
88 "\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
89 "void main()\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
90 "{\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
91 " gl_FragColor = v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
92 "}" |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 }, |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 /* SHADER_RGB */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 /* vertex shader */ |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
98 "varying vec4 v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
99 "varying vec2 v_texCoord;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
100 "\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
101 "void main()\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
102 "{\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
103 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
104 " v_color = gl_Color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
105 " v_texCoord = vec2(gl_MultiTexCoord0);\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
106 "}", |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 /* fragment shader */ |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
108 "varying vec4 v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
109 "varying vec2 v_texCoord;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
110 "uniform sampler2D tex0;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
111 "\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
112 "void main()\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
113 "{\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
114 " gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n" |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
115 "}" |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 }, |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 }; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 static SDL_bool |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
120 CompileShader(GL_ShaderContext *ctx, GLenum shader, const char *defines, const char *source) |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 GLint status; |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
123 const char *sources[2]; |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
125 sources[0] = defines; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
126 sources[1] = source; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
127 |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
128 ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL); |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 ctx->glCompileShaderARB(shader); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 if (status == 0) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 GLint length; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 char *info; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 info = SDL_stack_alloc(char, length+1); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 ctx->glGetInfoLogARB(shader, length, NULL, info); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 SDL_LogError(SDL_LOG_CATEGORY_RENDER, |
5236
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
139 "Failed to compile shader:\n%s%s\n%s", defines, source, info); |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
140 #ifdef DEBUG_SHADERS |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
141 fprintf(stderr, |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
142 "Failed to compile shader:\n%s%s\n%s", defines, source, info); |
e82908c86c9c
Made the shaders easier to debug when they don't compile
Sam Lantinga <slouken@libsdl.org>
parents:
5235
diff
changeset
|
143 #endif |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 SDL_stack_free(info); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 return SDL_FALSE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 } else { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 return SDL_TRUE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 static SDL_bool |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data) |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 const int num_tmus_bound = 4; |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
156 const char *vert_defines = ""; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
157 const char *frag_defines = ""; |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 int i; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 GLint location; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 if (index == SHADER_NONE) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 return SDL_TRUE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 ctx->glGetError(); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
167 /* Make sure we use the correct sampler type for our texture type */ |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
168 if (ctx->GL_ARB_texture_rectangle_supported) { |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
169 frag_defines = |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
170 "#define sampler2D sampler2DRect\n" |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
171 "#define texture2D texture2DRect\n"; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
172 } |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
173 |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 /* Create one program object to rule them all */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 data->program = ctx->glCreateProgramObjectARB(); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 /* Create the vertex shader */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
179 if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) { |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 return SDL_FALSE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 /* Create the fragment shader */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
185 if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) { |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 return SDL_FALSE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 /* ... and in the darkness bind them */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 ctx->glAttachObjectARB(data->program, data->vert_shader); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 ctx->glAttachObjectARB(data->program, data->frag_shader); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 ctx->glLinkProgramARB(data->program); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 /* Set up some uniform variables */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 ctx->glUseProgramObjectARB(data->program); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 for (i = 0; i < num_tmus_bound; ++i) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 char tex_name[5]; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 location = ctx->glGetUniformLocationARB(data->program, tex_name); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 if (location >= 0) { |
5234
c015d3e63631
Fixed setting the texture unit, still doesn't work.
Sam Lantinga <slouken@libsdl.org>
parents:
5233
diff
changeset
|
201 ctx->glUniform1iARB(location, i); |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 ctx->glUseProgramObjectARB(0); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 return (ctx->glGetError() == GL_NO_ERROR); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 static void |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data) |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 if (index == SHADER_NONE) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 return; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 ctx->glDeleteObjectARB(data->vert_shader); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 ctx->glDeleteObjectARB(data->frag_shader); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 ctx->glDeleteObjectARB(data->program); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 GL_ShaderContext * |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 GL_CreateShaderContext() |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 GL_ShaderContext *ctx; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 SDL_bool shaders_supported; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 int i; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx)); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 if (!ctx) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 return NULL; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
5235
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
233 if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
234 || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
235 ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE; |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
236 } |
8efa43b915be
Fixed the shaders (needed to use texture2DRect) - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
5234
diff
changeset
|
237 |
5233
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 /* Check for shader support */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 shaders_supported = SDL_FALSE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 ctx->glGetError = (GLenum (*)(void)) SDL_GL_GetProcAddress("glGetError"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC) SDL_GL_GetProcAddress("glUniform1fARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 if (ctx->glGetError && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 ctx->glAttachObjectARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 ctx->glCompileShaderARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 ctx->glCreateProgramObjectARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 ctx->glCreateShaderObjectARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 ctx->glDeleteObjectARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 ctx->glGetInfoLogARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 ctx->glGetObjectParameterivARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 ctx->glGetUniformLocationARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 ctx->glLinkProgramARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 ctx->glShaderSourceARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 ctx->glUniform1iARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 ctx->glUniform1fARB && |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 ctx->glUseProgramObjectARB) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 shaders_supported = SDL_TRUE; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 if (!shaders_supported) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 GL_DestroyShaderContext(ctx); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 return NULL; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 /* Compile all the shaders */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 for (i = 0; i < NUM_SHADERS; ++i) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 fprintf(stderr, "Unable to compile shader!\n"); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 GL_DestroyShaderContext(ctx); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 return NULL; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 /* We're done! */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 return ctx; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 void |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader) |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 /* Nothing to do if there's no shader support */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 if (!ctx) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 return; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 /* Nothing to do if there's no shader change */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 if (shader == ctx->current_shader) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 return; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 ctx->glUseProgramObjectARB(ctx->shaders[shader].program); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 ctx->current_shader = shader; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 void |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 GL_DestroyShaderContext(GL_ShaderContext *ctx) |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 int i; |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 for (i = 0; i < NUM_SHADERS; ++i) { |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 DestroyShaderProgram(ctx, &ctx->shaders[i]); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 SDL_free(ctx); |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 } |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 #endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */ |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
811beeb698f9
Beginning of a framework for OpenGL shaders
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 /* vi: set ts=4 sw=4 expandtab: */ |