The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 typedef struct ContextData_OpenGL_3
93 {
94  SDL_Color last_color;
96  unsigned int last_shape;
102 
105  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, ...]).
106  unsigned short blit_buffer_num_vertices;
108  unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
111 
112  // Tier 3 rendering
113  unsigned int blit_VAO;
114  unsigned int blit_VBO[2]; // For double-buffering
118 
120  unsigned int attribute_VBO[16];
122 
123 typedef struct ImageData_OpenGL_3
124 {
125  int refcount;
126  Uint32 handle;
127  Uint32 format;
129 
130 typedef struct TargetData_OpenGL_3
131 {
132  int refcount;
133  Uint32 handle;
134  Uint32 format;
136 
137 
138 
139 #endif
unsigned short blit_buffer_num_vertices
unsigned short * index_buffer
struct ImageData_OpenGL_3 ImageData_OpenGL_3
struct ContextData_OpenGL_3 ContextData_OpenGL_3
struct TargetData_OpenGL_3 TargetData_OpenGL_3
GPU_BlendMode last_blend_mode
unsigned short blit_buffer_max_num_vertices
unsigned int blit_VBO[2]
unsigned int index_buffer_num_vertices
GPU_ShaderBlock shader_block[2]
unsigned int index_buffer_max_num_vertices
unsigned int attribute_VBO[16]
GPU_AttributeSource shader_attributes[16]
GPU_ShaderBlock current_shader_block