The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SDL_gpu_OpenGL_2.h
Go to the documentation of this file.
1 #ifndef _SDL_GPU_OPENGL_2_H__
2 #define _SDL_GPU_OPENGL_2_H__
3 
4 #include "SDL_gpu.h"
5 
6 #if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_2)
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 #endif
27 
28 
29 #define GPU_CONTEXT_DATA ContextData_OpenGL_2
30 #define GPU_IMAGE_DATA ImageData_OpenGL_2
31 #define GPU_TARGET_DATA TargetData_OpenGL_2
32 
33 
34 
35 #define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
36 "#version 120\n\
37 \
38 attribute vec2 gpu_Vertex;\n\
39 attribute vec2 gpu_TexCoord;\n\
40 attribute vec4 gpu_Color;\n\
41 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
42 \
43 varying vec4 color;\n\
44 varying vec2 texCoord;\n\
45 \
46 void main(void)\n\
47 {\n\
48  color = gpu_Color;\n\
49  texCoord = vec2(gpu_TexCoord);\n\
50  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
51 }"
52 
53 // Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
54 #define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
55 "#version 120\n\
56 \
57 attribute vec2 gpu_Vertex;\n\
58 attribute vec4 gpu_Color;\n\
59 uniform mat4 gpu_ModelViewProjectionMatrix;\n\
60 \
61 varying vec4 color;\n\
62 \
63 void main(void)\n\
64 {\n\
65  color = gpu_Color;\n\
66  gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
67 }"
68 
69 
70 #define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
71 "#version 120\n\
72 \
73 varying vec4 color;\n\
74 varying vec2 texCoord;\n\
75 \
76 uniform sampler2D tex;\n\
77 \
78 void main(void)\n\
79 {\n\
80  gl_FragColor = texture2D(tex, texCoord) * color;\n\
81 }"
82 
83 #define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
84 "#version 120\n\
85 \
86 varying vec4 color;\n\
87 \
88 void main(void)\n\
89 {\n\
90  gl_FragColor = color;\n\
91 }"
92 
93 
94 
95 typedef struct ContextData_OpenGL_2
96 {
97  SDL_Color last_color;
99  unsigned int last_shape;
105 
108  float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
109  unsigned short blit_buffer_num_vertices;
111  unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
114 
115 
116  unsigned int blit_VBO[2]; // For double-buffering
120 
122  unsigned int attribute_VBO[16];
124 
125 typedef struct ImageData_OpenGL_2
126 {
127  int refcount;
128  Uint32 handle;
129  Uint32 format;
131 
132 typedef struct TargetData_OpenGL_2
133 {
134  int refcount;
135  Uint32 handle;
136  Uint32 format;
138 
139 
140 
141 #endif
struct TargetData_OpenGL_2 TargetData_OpenGL_2
struct ImageData_OpenGL_2 ImageData_OpenGL_2
unsigned short blit_buffer_max_num_vertices
GPU_AttributeSource shader_attributes[16]
unsigned int index_buffer_max_num_vertices
GPU_BlendMode last_blend_mode
unsigned int blit_VBO[2]
unsigned short * index_buffer
GPU_ShaderBlock shader_block[2]
unsigned short blit_buffer_num_vertices
unsigned int attribute_VBO[16]
unsigned int index_buffer_num_vertices
GPU_ShaderBlock current_shader_block
struct ContextData_OpenGL_2 ContextData_OpenGL_2