All Classes Functions Variables Typedefs Enumerations Groups
SDL_gpu_OpenGL_2.h
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;
98  GPU_bool last_use_texturing;
99  unsigned int last_shape;
100  GPU_bool last_use_blending;
101  GPU_BlendMode last_blend_mode;
102  GPU_Rect last_viewport;
103  GPU_Camera last_camera;
104  GPU_bool last_camera_inverted;
105 
106  GPU_Image* last_image;
107  GPU_Target* last_target;
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;
110  unsigned short blit_buffer_max_num_vertices;
111  unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
112  unsigned int index_buffer_num_vertices;
113  unsigned int index_buffer_max_num_vertices;
114 
115 
116  unsigned int blit_VBO[2]; // For double-buffering
117  unsigned int blit_IBO;
118  GPU_bool blit_VBO_flop;
119 
120  GPU_AttributeSource shader_attributes[16];
121  unsigned int attribute_VBO[16];
123 
124 typedef struct ImageData_OpenGL_2
125 {
126  int refcount;
127  GPU_bool owns_handle;
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
Definition: SDL_gpu.h:578
Definition: SDL_gpu.h:300
Definition: SDL_gpu_OpenGL_2.h:95
Definition: SDL_gpu_OpenGL_2.h:132
Definition: SDL_gpu.h:159
Definition: SDL_gpu.h:398
Definition: SDL_gpu.h:263
Definition: SDL_gpu.h:89
Definition: SDL_gpu_OpenGL_2.h:124