My Project
Loading...
Searching...
No Matches
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\
165attribute vec2 gpu_Vertex;\n\
166attribute vec2 gpu_TexCoord;\n\
167attribute vec4 gpu_Color;\n\
168uniform mat4 gpu_ModelViewProjectionMatrix;\n\
169\
170varying vec4 color;\n\
171varying vec2 texCoord;\n\
172\
173void 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\
184attribute vec2 gpu_Vertex;\n\
185attribute vec4 gpu_Color;\n\
186uniform mat4 gpu_ModelViewProjectionMatrix;\n\
187\
188varying vec4 color;\n\
189\
190void 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\
200varying vec4 color;\n\
201varying vec2 texCoord;\n\
202\
203uniform sampler2D tex;\n\
204\
205void 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\
213varying vec4 color;\n\
214\
215void main(void)\n\
216{\n\
217 gl_FragColor = color;\n\
218}"
219
220
221
222
223
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_bool last_depth_test;
236 GPU_bool last_depth_write;
237 GPU_ComparisonEnum last_depth_function;
238
239 GPU_Image* last_image;
240 float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
241 unsigned short blit_buffer_num_vertices;
242 unsigned short blit_buffer_max_num_vertices;
243 unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
244 unsigned int index_buffer_num_vertices;
245 unsigned int index_buffer_max_num_vertices;
246
247
248 unsigned int blit_VBO[2]; // For double-buffering
249 unsigned int blit_IBO;
250 GPU_bool blit_VBO_flop;
251
252 GPU_AttributeSource shader_attributes[16];
253 unsigned int attribute_VBO[16];
255
256typedef struct ImageData_OpenGL_1
257{
258 int refcount;
259 GPU_bool owns_handle;
260 Uint32 handle;
261 Uint32 format;
263
265{
266 int refcount;
267 Uint32 handle;
268 Uint32 format;
270
271
272
273#endif
GPU_ComparisonEnum
Definition: SDL_gpu.h:183
Definition: SDL_gpu_OpenGL_1.h:225
Definition: SDL_gpu.h:710
Definition: SDL_gpu.h:227
Definition: SDL_gpu.h:380
Definition: SDL_gpu.h:334
Definition: SDL_gpu.h:138
Definition: SDL_gpu_OpenGL_1.h:257
Definition: SDL_gpu_OpenGL_1.h:265