SDL_gpu  0.11.0
A hardware-accelerated, cross-platform 2D graphics API
SDL_gpu_OpenGL_3.h
Go to the documentation of this file.
1 #ifndef _SDL_GPU_OPENGL_3_H__
2 #define _SDL_GPU_OPENGL_3_H__
3 
4 #include "SDL_gpu.h"
5 
6 #if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_3)
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 #endif
26 
27 
28 #define GPU_CONTEXT_DATA ContextData_OpenGL_3
29 #define GPU_IMAGE_DATA ImageData_OpenGL_3
30 #define GPU_TARGET_DATA TargetData_OpenGL_3
31 
32 
33 #define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
34 "#version 130\n\
35 \
36 in vec2 gpu_Vertex;\n\
37 in vec2 gpu_TexCoord;\n\
38 in vec4 gpu_Color;\n\
39 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
40 \
41 out vec4 color;\n\
42 out vec2 texCoord;\n\
43 \
44 void main(void)\n\
45 {\n\
46  color = gpu_Color;\n\
47  texCoord = vec2(gpu_TexCoord);\n\
48  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
49 }"
50 
51 // Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
52 #define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
53 "#version 130\n\
54 \
55 in vec2 gpu_Vertex;\n\
56 in vec4 gpu_Color;\n\
57 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
58 \
59 out vec4 color;\n\
60 \
61 void main(void)\n\
62 {\n\
63  color = gpu_Color;\n\
64  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
65 }"
66 
67 
68 #define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
69 "#version 130\n\
70 \
71 in vec4 color;\n\
72 in vec2 texCoord;\n\
73 \
74 uniform sampler2D tex;\n\
75 \
76 void main(void)\n\
77 {\n\
78  gl_FragColor = texture2D(tex, texCoord) * color;\n\
79 }"
80 
81 #define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
82 "#version 130\n\
83 \
84 in vec4 color;\n\
85 \
86 void main(void)\n\
87 {\n\
88  gl_FragColor = color;\n\
89 }"
90 
91 
92 
93 
94 // OpenGL 3.2 and 3.3 need newer shaders in case a core profile is used
95 
96 #define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE_CORE \
97 "#version 150\n\
98 \
99 in vec2 gpu_Vertex;\n\
100 in vec2 gpu_TexCoord;\n\
101 in vec4 gpu_Color;\n\
102 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
103 \
104 out vec4 color;\n\
105 out vec2 texCoord;\n\
106 \
107 void main(void)\n\
108 {\n\
109  color = gpu_Color;\n\
110  texCoord = vec2(gpu_TexCoord);\n\
111  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
112 }"
113 
114 #define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE_CORE \
115 "#version 150\n\
116 \
117 in vec2 gpu_Vertex;\n\
118 in vec4 gpu_Color;\n\
119 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
120 \
121 out vec4 color;\n\
122 \
123 void main(void)\n\
124 {\n\
125  color = gpu_Color;\n\
126  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
127 }"
128 
129 
130 #define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE_CORE \
131 "#version 150\n\
132 \
133 in vec4 color;\n\
134 in vec2 texCoord;\n\
135 \
136 uniform sampler2D tex;\n\
137 \
138 out vec4 fragColor;\n\
139 \
140 void main(void)\n\
141 {\n\
142  fragColor = texture(tex, texCoord) * color;\n\
143 }"
144 
145 #define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE_CORE \
146 "#version 150\n\
147 \
148 in vec4 color;\n\
149 \
150 out vec4 fragColor;\n\
151 \
152 void main(void)\n\
153 {\n\
154  fragColor = color;\n\
155 }"
156 
157 
158 typedef struct ContextData_OpenGL_3
159 {
160  SDL_Color last_color;
162  unsigned int last_shape;
168 
171  float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]).
172  unsigned short blit_buffer_num_vertices;
174  unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
177 
178  // Tier 3 rendering
179  unsigned int blit_VAO;
180  unsigned int blit_VBO[2]; // For double-buffering
181  unsigned int blit_IBO;
183 
185  unsigned int attribute_VBO[16];
187 
188 typedef struct ImageData_OpenGL_3
189 {
190  int refcount;
192  Uint32 handle;
193  Uint32 format;
195 
196 typedef struct TargetData_OpenGL_3
197 {
198  int refcount;
199  Uint32 handle;
200  Uint32 format;
202 
203 
204 
205 #endif
unsigned int blit_VBO[2]
unsigned short blit_buffer_max_num_vertices
GPU_AttributeSource shader_attributes[16]
unsigned int index_buffer_num_vertices
unsigned short * index_buffer
GPU_BlendMode last_blend_mode
unsigned int index_buffer_max_num_vertices
unsigned int attribute_VBO[16]
unsigned short blit_buffer_num_vertices
#define GPU_bool
Definition: SDL_gpu.h:59