All Classes Functions Variables Typedefs Enumerations Groups
SDL_gpu_OpenGL_1.h
1 #ifndef _SDL_GPU_OPENGL_1_H__
2 #define _SDL_GPU_OPENGL_1_H__
3 
4 #include "SDL_gpu.h"
5 
6 #if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_1)
7 
8  // Hacks to fix compile errors due to polluted namespace
9  #ifdef _WIN32
10  #define _WINUSER_H
11  #define _WINGDI_H
12  #endif
13 
14  #include "glew.h"
15 
16  #if defined(GL_EXT_bgr) && !defined(GL_BGR)
17  #define GL_BGR GL_BGR_EXT
18  #endif
19  #if defined(GL_EXT_bgra) && !defined(GL_BGRA)
20  #define GL_BGRA GL_BGRA_EXT
21  #endif
22  #if defined(GL_EXT_abgr) && !defined(GL_ABGR)
23  #define GL_ABGR GL_ABGR_EXT
24  #endif
25 
26  #undef glBlendFuncSeparate
27  #define glBlendFuncSeparate glBlendFuncSeparateEXT
28  #undef glBlendEquation
29  #define glBlendEquation glBlendEquationEXT
30  #undef glBlendEquationSeparate
31  #define glBlendEquationSeparate glBlendEquationSeparateEXT
32 
33  #undef GL_MIRRORED_REPEAT
34  #define GL_MIRRORED_REPEAT GL_MIRRORED_REPEAT_ARB
35 
36  #undef glCreateShader
37  #undef GL_VERTEX_SHADER
38  #undef GL_FRAGMENT_SHADER
39  #undef glShaderSource
40  #undef glCompileShader
41  #undef glGetShaderiv
42  #undef GL_COMPILE_STATUS
43  #undef glGetShaderInfoLog
44  #undef glDeleteShader
45  #undef glActiveTexture
46  #undef GL_TEXTURE0
47  #define glCreateShader glCreateShaderObjectARB
48  #define GL_VERTEX_SHADER GL_VERTEX_SHADER_ARB
49  #define GL_FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB
50  #define glShaderSource glShaderSourceARB
51  #define glCompileShader glCompileShaderARB
52  #define glGetShaderiv glGetObjectParameterivARB
53  #define GL_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB
54  #define glGetShaderInfoLog glGetInfoLogARB
55  #define glDeleteShader glDeleteObjectARB
56  #define glActiveTexture glActiveTextureARB
57  #define GL_TEXTURE0 GL_TEXTURE0_ARB
58 
59  #undef glCreateProgram
60  #undef glAttachShader
61  #undef glLinkProgram
62  #undef GL_LINK_STATUS
63  #undef glGetProgramiv
64  #undef glGetProgramInfoLog
65  #undef glUseProgram
66  #undef glDeleteProgram
67  #define glCreateProgram glCreateProgramObjectARB
68  #define glAttachShader glAttachObjectARB
69  #define glLinkProgram glLinkProgramARB
70  #define GL_LINK_STATUS GL_OBJECT_LINK_STATUS_ARB
71  #define glGetProgramiv glGetObjectParameterivARB
72  #define glGetProgramInfoLog glGetInfoLogARB
73  #define glUseProgram glUseProgramObjectARB
74  #define glDeleteProgram glDeleteObjectARB
75 
76  #undef glGetUniformLocation
77  #undef glGetUniformiv
78  #undef glUniform1i
79  #undef glUniform1iv
80  #undef glUniform2iv
81  #undef glUniform3iv
82  #undef glUniform4iv
83  #undef glUniform1f
84  #undef glUniform1fv
85  #undef glUniform2fv
86  #undef glUniform3fv
87  #undef glUniform4fv
88  #undef glUniformMatrix4fv
89  #define glGetUniformLocation glGetUniformLocationARB
90  #define glGetUniformiv glGetUniformivARB
91  #define glUniform1i glUniform1iARB
92  #define glUniform1iv glUniform1ivARB
93  #define glUniform2iv glUniform2ivARB
94  #define glUniform3iv glUniform3ivARB
95  #define glUniform4iv glUniform4ivARB
96  #define glUniform1f glUniform1fARB
97  #define glUniform1fv glUniform1fvARB
98  #define glUniform2fv glUniform2fvARB
99  #define glUniform3fv glUniform3fvARB
100  #define glUniform4fv glUniform4fvARB
101  #define glUniformMatrix4fv glUniformMatrix4fvARB
102 
103  #undef glGetAttribLocation
104  #undef glVertexAttrib1f
105  #undef glVertexAttrib2f
106  #undef glVertexAttrib3f
107  #undef glVertexAttrib4f
108  #undef glVertexAttribI1i
109  #undef glVertexAttribI2i
110  #undef glVertexAttribI3i
111  #undef glVertexAttribI4i
112  #undef glVertexAttribI1ui
113  #undef glVertexAttribI2ui
114  #undef glVertexAttribI3ui
115  #undef glVertexAttribI4ui
116  #define glGetAttribLocation glGetAttribLocationARB
117  #define glVertexAttrib1f glVertexAttrib1fARB
118  #define glVertexAttrib2f glVertexAttrib2fARB
119  #define glVertexAttrib3f glVertexAttrib3fARB
120  #define glVertexAttrib4f glVertexAttrib4fARB
121  #define glVertexAttribI1i glVertexAttrib1sARB
122  #define glVertexAttribI2i glVertexAttrib2sARB
123  #define glVertexAttribI3i glVertexAttrib3sARB
124  #define glVertexAttribI4i glVertexAttrib4sARB
125  #define glVertexAttribI1ui glVertexAttrib1sARB
126  #define glVertexAttribI2ui glVertexAttrib2sARB
127  #define glVertexAttribI3ui glVertexAttrib3sARB
128  #define glVertexAttribI4ui glVertexAttrib4sARB
129 
130  #undef glGenBuffers
131  #undef glDeleteBuffers
132  #undef glBindBuffer
133  #undef glBufferData
134  #undef glBufferSubData
135  #undef GL_ARRAY_BUFFER
136  #define glGenBuffers glGenBuffersARB
137  #define glDeleteBuffers glDeleteBuffersARB
138  #define glBindBuffer glBindBufferARB
139  #define glBufferData glBufferDataARB
140  #define glBufferSubData glBufferSubDataARB
141  #define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
142 
143 
144  #undef glEnableVertexAttribArray
145  #undef glDisableVertexAttribArray
146  #undef glVertexAttribPointer
147  #define glEnableVertexAttribArray glEnableVertexAttribArrayARB
148  #define glDisableVertexAttribArray glDisableVertexAttribArrayARB
149  #define glVertexAttribPointer glVertexAttribPointerARB
150 
151 #endif
152 
153 
154 
155 #define GPU_CONTEXT_DATA ContextData_OpenGL_1
156 #define GPU_IMAGE_DATA ImageData_OpenGL_1
157 #define GPU_TARGET_DATA TargetData_OpenGL_1
158 
159 
160 
161 
162 #define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
163 "#version 110\n\
164 \
165 attribute vec2 gpu_Vertex;\n\
166 attribute vec2 gpu_TexCoord;\n\
167 attribute vec4 gpu_Color;\n\
168 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
169 \
170 varying vec4 color;\n\
171 varying vec2 texCoord;\n\
172 \
173 void main(void)\n\
174 {\n\
175  color = gpu_Color;\n\
176  texCoord = vec2(gpu_TexCoord);\n\
177  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
178 }"
179 
180 // Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
181 #define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
182 "#version 110\n\
183 \
184 attribute vec2 gpu_Vertex;\n\
185 attribute vec4 gpu_Color;\n\
186 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
187 \
188 varying vec4 color;\n\
189 \
190 void main(void)\n\
191 {\n\
192  color = gpu_Color;\n\
193  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
194 }"
195 
196 
197 #define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
198 "#version 110\n\
199 \
200 varying vec4 color;\n\
201 varying vec2 texCoord;\n\
202 \
203 uniform sampler2D tex;\n\
204 \
205 void main(void)\n\
206 {\n\
207  gl_FragColor = texture2D(tex, texCoord) * color;\n\
208 }"
209 
210 #define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
211 "#version 110\n\
212 \
213 varying vec4 color;\n\
214 \
215 void main(void)\n\
216 {\n\
217  gl_FragColor = color;\n\
218 }"
219 
220 
221 
222 
223 
224 typedef struct ContextData_OpenGL_1
225 {
226  SDL_Color last_color;
227  GPU_bool last_use_texturing;
228  unsigned int last_shape;
229  GPU_bool last_use_blending;
230  GPU_BlendMode last_blend_mode;
231  GPU_Rect last_viewport;
232  GPU_Camera last_camera;
233  GPU_bool last_camera_inverted;
234 
235  GPU_Image* last_image;
236  GPU_Target* last_target;
237  float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
238  unsigned short blit_buffer_num_vertices;
239  unsigned short blit_buffer_max_num_vertices;
240  unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
241  unsigned int index_buffer_num_vertices;
242  unsigned int index_buffer_max_num_vertices;
243 
244 
245  unsigned int blit_VBO[2]; // For double-buffering
246  unsigned int blit_IBO;
247  GPU_bool blit_VBO_flop;
248 
249  GPU_AttributeSource shader_attributes[16];
250  unsigned int attribute_VBO[16];
252 
253 typedef struct ImageData_OpenGL_1
254 {
255  int refcount;
256  GPU_bool owns_handle;
257  Uint32 handle;
258  Uint32 format;
260 
261 typedef struct TargetData_OpenGL_1
262 {
263  int refcount;
264  Uint32 handle;
265  Uint32 format;
267 
268 
269 
270 #endif
Definition: SDL_gpu.h:578
Definition: SDL_gpu.h:300
Definition: SDL_gpu_OpenGL_1.h:253
Definition: SDL_gpu_OpenGL_1.h:224
Definition: SDL_gpu_OpenGL_1.h:261
Definition: SDL_gpu.h:159
Definition: SDL_gpu.h:398
Definition: SDL_gpu.h:263
Definition: SDL_gpu.h:89