My Project
Loading...
Searching...
No Matches
SDL_gpu_OpenGL_3.h
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\
36in vec2 gpu_Vertex;\n\
37in vec2 gpu_TexCoord;\n\
38in vec4 gpu_Color;\n\
39uniform mat4 gpu_ModelViewProjectionMatrix;\n\
40\
41out vec4 color;\n\
42out vec2 texCoord;\n\
43\
44void 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\
55in vec2 gpu_Vertex;\n\
56in vec4 gpu_Color;\n\
57uniform mat4 gpu_ModelViewProjectionMatrix;\n\
58\
59out vec4 color;\n\
60\
61void 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\
71in vec4 color;\n\
72in vec2 texCoord;\n\
73\
74uniform sampler2D tex;\n\
75\
76void 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\
84in vec4 color;\n\
85\
86void 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\
99in vec2 gpu_Vertex;\n\
100in vec2 gpu_TexCoord;\n\
101in vec4 gpu_Color;\n\
102uniform mat4 gpu_ModelViewProjectionMatrix;\n\
103\
104out vec4 color;\n\
105out vec2 texCoord;\n\
106\
107void 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\
117in vec2 gpu_Vertex;\n\
118in vec4 gpu_Color;\n\
119uniform mat4 gpu_ModelViewProjectionMatrix;\n\
120\
121out vec4 color;\n\
122\
123void 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\
133in vec4 color;\n\
134in vec2 texCoord;\n\
135\
136uniform sampler2D tex;\n\
137\
138out vec4 fragColor;\n\
139\
140void 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\
148in vec4 color;\n\
149\
150out vec4 fragColor;\n\
151\
152void main(void)\n\
153{\n\
154 fragColor = color;\n\
155}"
156
157
159{
160 SDL_Color last_color;
161 GPU_bool last_use_texturing;
162 unsigned int last_shape;
163 GPU_bool last_use_blending;
164 GPU_BlendMode last_blend_mode;
165 GPU_Rect last_viewport;
166 GPU_Camera last_camera;
167 GPU_bool last_camera_inverted;
168
169 GPU_bool last_depth_test;
170 GPU_bool last_depth_write;
171 GPU_ComparisonEnum last_depth_function;
172
173 GPU_Image* last_image;
174 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, ...]).
175 unsigned short blit_buffer_num_vertices;
176 unsigned short blit_buffer_max_num_vertices;
177 unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
178 unsigned int index_buffer_num_vertices;
179 unsigned int index_buffer_max_num_vertices;
180
181 // Tier 3 rendering
182 unsigned int blit_VAO;
183 unsigned int blit_VBO[2]; // For double-buffering
184 unsigned int blit_IBO;
185 GPU_bool blit_VBO_flop;
186
187 GPU_AttributeSource shader_attributes[16];
188 unsigned int attribute_VBO[16];
190
191typedef struct ImageData_OpenGL_3
192{
193 int refcount;
194 GPU_bool owns_handle;
195 Uint32 handle;
196 Uint32 format;
198
200{
201 int refcount;
202 Uint32 handle;
203 Uint32 format;
205
206
207
208#endif
GPU_ComparisonEnum
Definition: SDL_gpu.h:183
Definition: SDL_gpu_OpenGL_3.h:159
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_3.h:192
Definition: SDL_gpu_OpenGL_3.h:200