1 module rlgl;
2 
3 /**********************************************************************************************
4 *
5 *   rlgl v4.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
6 *
7 *   An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
8 *   that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...)
9 *
10 *   When chosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
11 *   initialized on rlglInit() to accumulate vertex data.
12 *
13 *   When an internal state change is required all the stored vertex data is renderer in batch,
14 *   additioanlly, rlDrawRenderBatchActive() could be called to force flushing of the batch.
15 *
16 *   Some additional resources are also loaded for convenience, here the complete list:
17 *      - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data
18 *      - Default texture (RLGL.defaultTextureId): 1x1 white pixel R8G8B8A8
19 *      - Default shader (RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs)
20 *
21 *   Internal buffer (and additional resources) must be manually unloaded calling rlglClose().
22 *
23 *
24 *   CONFIGURATION:
25 *
26 *   #define GRAPHICS_API_OPENGL_11
27 *   #define GRAPHICS_API_OPENGL_21
28 *   #define GRAPHICS_API_OPENGL_33
29 *   #define GRAPHICS_API_OPENGL_43
30 *   #define GRAPHICS_API_OPENGL_ES2
31 *       Use selected OpenGL graphics backend, should be supported by platform
32 *       Those preprocessor defines are only used on rlgl module, if OpenGL version is
33 *       required by any other module, use rlGetVersion() to check it
34 *
35 *   #define RLGL_IMPLEMENTATION
36 *       Generates the implementation of the library into the included file.
37 *       If not defined, the library is in header only mode and can be included in other headers
38 *       or source files without problems. But only ONE file should hold the implementation.
39 *
40 *   #define RLGL_RENDER_TEXTURES_HINT
41 *       Enable framebuffer objects (fbo) support (enabled by default)
42 *       Some GPUs could not support them despite the OpenGL version
43 *
44 *   #define RLGL_SHOW_GL_DETAILS_INFO
45 *       Show OpenGL extensions and capabilities detailed logs on init
46 *
47 *   #define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
48 *       Enable debug context (only available on OpenGL 4.3)
49 *
50 *   rlgl capabilities could be customized just defining some internal
51 *   values before library inclusion (default values listed):
52 *
53 *   #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS   8192    // Default internal render batch elements limits
54 *   #define RL_DEFAULT_BATCH_BUFFERS              1    // Default number of batch buffers (multi-buffering)
55 *   #define RL_DEFAULT_BATCH_DRAWCALLS          256    // Default number of batch draw calls (by state changes: mode, texture)
56 *   #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS    4    // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
57 *
58 *   #define RL_MAX_MATRIX_STACK_SIZE             32    // Maximum size of internal Matrix stack
59 *   #define RL_MAX_SHADER_LOCATIONS              32    // Maximum number of shader locations supported
60 *   #define RL_CULL_DISTANCE_NEAR              0.01    // Default projection matrix near cull distance
61 *   #define RL_CULL_DISTANCE_FAR             1000.0    // Default projection matrix far cull distance
62 *
63 *   When loading a shader, the following vertex attribute and uniform
64 *   location names are tried to be set automatically:
65 *
66 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION     "vertexPosition"    // Binded by default to shader location: 0
67 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD     "vertexTexCoord"    // Binded by default to shader location: 1
68 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL       "vertexNormal"      // Binded by default to shader location: 2
69 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR        "vertexColor"       // Binded by default to shader location: 3
70 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT      "vertexTangent"     // Binded by default to shader location: 4
71 *   #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2    "vertexTexCoord2"   // Binded by default to shader location: 5
72 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP         "mvp"               // model-view-projection matrix
73 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW        "matView"           // view matrix
74 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION  "matProjection"     // projection matrix
75 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL       "matModel"          // model matrix
76 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL      "matNormal"         // normal matrix (transpose(inverse(matModelView))
77 *   #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR       "colDiffuse"        // color diffuse (base tint color, multiplied by texture color)
78 *   #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0  "texture0"          // texture0 (texture slot active 0)
79 *   #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1  "texture1"          // texture1 (texture slot active 1)
80 *   #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2  "texture2"          // texture2 (texture slot active 2)
81 *
82 *   DEPENDENCIES:
83 *
84 *      - OpenGL libraries (depending on platform and OpenGL version selected)
85 *      - GLAD OpenGL extensions loading library (only for OpenGL 3.3 Core, 4.3 Core)
86 *
87 *
88 *   LICENSE: zlib/libpng
89 *
90 *   Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
91 *
92 *   This software is provided "as-is", without any express or implied warranty. In no event
93 *   will the authors be held liable for any damages arising from the use of this software.
94 *
95 *   Permission is granted to anyone to use this software for any purpose, including commercial
96 *   applications, and to alter it and redistribute it freely, subject to the following restrictions:
97 *
98 *     1. The origin of this software must not be misrepresented; you must not claim that you
99 *     wrote the original software. If you use this software in a product, an acknowledgment
100 *     in the product documentation would be appreciated but is not required.
101 *
102 *     2. Altered source versions must be plainly marked as such, and must not be misrepresented
103 *     as being the original software.
104 *
105 *     3. This notice may not be removed or altered from any source distribution.
106 *
107 **********************************************************************************************/
108 
109 import core.stdc.config;
110 import core.stdc.stdarg;
111 import core.stdc.stdlib;
112 
113 extern (C) @nogc nothrow:
114 
115 enum RLGL_VERSION = "4.0";
116 
117 // Function specifiers in case library is build/used as a shared library (Windows)
118 // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
119 
120 // We are building the library as a Win32 shared library (.dll)
121 
122 // We are using the library as a Win32 shared library (.dll)
123 
124 // Function specifiers definition // Functions defined as 'extern' by default (implicit specifiers)
125 
126 // Support TRACELOG macros
127 
128 // Security check in case no GRAPHICS_API_OPENGL_* defined
129 
130 // Security check in case multiple GRAPHICS_API_OPENGL_* defined
131 
132 // OpenGL 2.1 uses most of OpenGL 3.3 Core functionality
133 // WARNING: Specific parts are checked with #if defines
134 
135 // OpenGL 4.3 uses OpenGL 3.3 Core functionality
136 
137 // Support framebuffer objects by default
138 // NOTE: Some driver implementation do not support it, despite they should
139 
140 //----------------------------------------------------------------------------------
141 // Defines and Macros
142 //----------------------------------------------------------------------------------
143 
144 // Default internal render batch elements limits
145 
146 // This is the maximum amount of elements (quads) per batch
147 // NOTE: Be careful with text, every letter maps to a quad
148 enum RL_DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
149 
150 // We reduce memory sizes for embedded systems (RPI and HTML5)
151 // NOTE: On HTML5 (emscripten) this is allocated on heap,
152 // by default it's only 16MB!...just take care...
153 
154 enum RL_DEFAULT_BATCH_BUFFERS = 1; // Default number of batch buffers (multi-buffering)
155 
156 enum RL_DEFAULT_BATCH_DRAWCALLS = 256; // Default number of batch draw calls (by state changes: mode, texture)
157 
158 enum RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS = 4; // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
159 
160 // Internal Matrix stack
161 
162 enum RL_MAX_MATRIX_STACK_SIZE = 32; // Maximum size of Matrix stack
163 
164 // Shader limits
165 
166 enum RL_MAX_SHADER_LOCATIONS = 32; // Maximum number of shader locations supported
167 
168 // Projection matrix culling
169 
170 enum RL_CULL_DISTANCE_NEAR = 0.01; // Default near cull distance
171 
172 enum RL_CULL_DISTANCE_FAR = 1000.0; // Default far cull distance
173 
174 // Texture parameters (equivalent to OpenGL defines)
175 enum RL_TEXTURE_WRAP_S = 0x2802; // GL_TEXTURE_WRAP_S
176 enum RL_TEXTURE_WRAP_T = 0x2803; // GL_TEXTURE_WRAP_T
177 enum RL_TEXTURE_MAG_FILTER = 0x2800; // GL_TEXTURE_MAG_FILTER
178 enum RL_TEXTURE_MIN_FILTER = 0x2801; // GL_TEXTURE_MIN_FILTER
179 
180 enum RL_TEXTURE_FILTER_NEAREST = 0x2600; // GL_NEAREST
181 enum RL_TEXTURE_FILTER_LINEAR = 0x2601; // GL_LINEAR
182 enum RL_TEXTURE_FILTER_MIP_NEAREST = 0x2700; // GL_NEAREST_MIPMAP_NEAREST
183 enum RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702; // GL_NEAREST_MIPMAP_LINEAR
184 enum RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701; // GL_LINEAR_MIPMAP_NEAREST
185 enum RL_TEXTURE_FILTER_MIP_LINEAR = 0x2703; // GL_LINEAR_MIPMAP_LINEAR
186 enum RL_TEXTURE_FILTER_ANISOTROPIC = 0x3000; // Anisotropic filter (custom identifier)
187 
188 enum RL_TEXTURE_WRAP_REPEAT = 0x2901; // GL_REPEAT
189 enum RL_TEXTURE_WRAP_CLAMP = 0x812F; // GL_CLAMP_TO_EDGE
190 enum RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370; // GL_MIRRORED_REPEAT
191 enum RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742; // GL_MIRROR_CLAMP_EXT
192 
193 // Matrix modes (equivalent to OpenGL)
194 enum RL_MODELVIEW = 0x1700; // GL_MODELVIEW
195 enum RL_PROJECTION = 0x1701; // GL_PROJECTION
196 enum RL_TEXTURE = 0x1702; // GL_TEXTURE
197 
198 // Primitive assembly draw modes
199 enum RL_LINES = 0x0001; // GL_LINES
200 enum RL_TRIANGLES = 0x0004; // GL_TRIANGLES
201 enum RL_QUADS = 0x0007; // GL_QUADS
202 
203 // GL equivalent data types
204 enum RL_UNSIGNED_BYTE = 0x1401; // GL_UNSIGNED_BYTE
205 enum RL_FLOAT = 0x1406; // GL_FLOAT
206 
207 // Buffer usage hint
208 enum RL_STREAM_DRAW = 0x88E0; // GL_STREAM_DRAW
209 enum RL_STREAM_READ = 0x88E1; // GL_STREAM_READ
210 enum RL_STREAM_COPY = 0x88E2; // GL_STREAM_COPY
211 enum RL_STATIC_DRAW = 0x88E4; // GL_STATIC_DRAW
212 enum RL_STATIC_READ = 0x88E5; // GL_STATIC_READ
213 enum RL_STATIC_COPY = 0x88E6; // GL_STATIC_COPY
214 enum RL_DYNAMIC_DRAW = 0x88E8; // GL_DYNAMIC_DRAW
215 enum RL_DYNAMIC_READ = 0x88E9; // GL_DYNAMIC_READ
216 enum RL_DYNAMIC_COPY = 0x88EA; // GL_DYNAMIC_COPY
217 
218 // GL Shader type
219 enum RL_FRAGMENT_SHADER = 0x8B30; // GL_FRAGMENT_SHADER
220 enum RL_VERTEX_SHADER = 0x8B31; // GL_VERTEX_SHADER
221 enum RL_COMPUTE_SHADER = 0x91B9; // GL_COMPUTE_SHADER
222 
223 //----------------------------------------------------------------------------------
224 // Types and Structures Definition
225 //----------------------------------------------------------------------------------
226 enum rlGlVersion
227 {
228     OPENGL_11 = 1,
229     OPENGL_21 = 2,
230     OPENGL_33 = 3,
231     OPENGL_43 = 4,
232     OPENGL_ES_20 = 5
233 }
234 
235 enum rlFramebufferAttachType
236 {
237     RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
238     RL_ATTACHMENT_COLOR_CHANNEL1 = 1,
239     RL_ATTACHMENT_COLOR_CHANNEL2 = 2,
240     RL_ATTACHMENT_COLOR_CHANNEL3 = 3,
241     RL_ATTACHMENT_COLOR_CHANNEL4 = 4,
242     RL_ATTACHMENT_COLOR_CHANNEL5 = 5,
243     RL_ATTACHMENT_COLOR_CHANNEL6 = 6,
244     RL_ATTACHMENT_COLOR_CHANNEL7 = 7,
245     RL_ATTACHMENT_DEPTH = 100,
246     RL_ATTACHMENT_STENCIL = 200
247 }
248 
249 enum rlFramebufferAttachTextureType
250 {
251     RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
252     RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1,
253     RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2,
254     RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3,
255     RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4,
256     RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5,
257     RL_ATTACHMENT_TEXTURE2D = 100,
258     RL_ATTACHMENT_RENDERBUFFER = 200
259 }
260 
261 // Dynamic vertex buffers (position + texcoords + colors + indices arrays)
262 struct rlVertexBuffer
263 {
264     int elementCount; // Number of elements in the buffer (QUADS)
265 
266     float* vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
267     float* texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
268     ubyte* colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
269 
270     uint* indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
271 
272     // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
273 
274     uint vaoId; // OpenGL Vertex Array Object id
275     uint[4] vboId; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
276 }
277 
278 // Draw call type
279 // NOTE: Only texture changes register a new draw, other state-change-related elements are not
280 // used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any
281 // of those state-change happens (this is done in core module)
282 struct rlDrawCall
283 {
284     int mode; // Drawing mode: LINES, TRIANGLES, QUADS
285     int vertexCount; // Number of vertex of the draw
286     int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)
287     //unsigned int vaoId;       // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId
288     //unsigned int shaderId;    // Shader id to be used on the draw -> Using RLGL.currentShaderId
289     uint textureId; // Texture id to be used on the draw -> Use to create new draw call if changes
290 
291     //Matrix projection;      // Projection matrix for this draw -> Using RLGL.projection by default
292     //Matrix modelview;       // Modelview matrix for this draw -> Using RLGL.modelview by default
293 }
294 
295 // rlRenderBatch type
296 struct rlRenderBatch
297 {
298     int bufferCount; // Number of vertex buffers (multi-buffering support)
299     int currentBuffer; // Current buffer tracking in case of multi-buffering
300     rlVertexBuffer* vertexBuffer; // Dynamic buffer(s) for vertex data
301 
302     rlDrawCall* draws; // Draw calls array, depends on textureId
303     int drawCounter; // Draw calls counter
304     float currentDepth; // Current depth value for next draw
305 }
306 
307 // Boolean type
308 
309 // Matrix, 4x4 components, column major, OpenGL style, right handed
310 struct Matrix
311 {
312     float m0;
313     float m4;
314     float m8;
315     float m12; // Matrix first row (4 components)
316     float m1;
317     float m5;
318     float m9;
319     float m13; // Matrix second row (4 components)
320     float m2;
321     float m6;
322     float m10;
323     float m14; // Matrix third row (4 components)
324     float m3;
325     float m7;
326     float m11;
327     float m15; // Matrix fourth row (4 components)
328 }
329 
330 // Trace log level
331 // NOTE: Organized by priority level
332 enum rlTraceLogLevel
333 {
334     RL_LOG_ALL = 0, // Display all logs
335     RL_LOG_TRACE = 1, // Trace logging, intended for internal use only
336     RL_LOG_DEBUG = 2, // Debug logging, used for internal debugging, it should be disabled on release builds
337     RL_LOG_INFO = 3, // Info logging, used for program execution info
338     RL_LOG_WARNING = 4, // Warning logging, used on recoverable failures
339     RL_LOG_ERROR = 5, // Error logging, used on unrecoverable failures
340     RL_LOG_FATAL = 6, // Fatal logging, used to abort program: exit(EXIT_FAILURE)
341     RL_LOG_NONE = 7 // Disable logging
342 }
343 
344 // Texture formats (support depends on OpenGL version)
345 enum rlPixelFormat
346 {
347     RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
348     RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA = 2, // 8*2 bpp (2 channels)
349     RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5 = 3, // 16 bpp
350     RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8 = 4, // 24 bpp
351     RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1 = 5, // 16 bpp (1 bit alpha)
352     RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4 = 6, // 16 bpp (4 bit alpha)
353     RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = 7, // 32 bpp
354     RL_PIXELFORMAT_UNCOMPRESSED_R32 = 8, // 32 bpp (1 channel - float)
355     RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32 = 9, // 32*3 bpp (3 channels - float)
356     RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 = 10, // 32*4 bpp (4 channels - float)
357     RL_PIXELFORMAT_COMPRESSED_DXT1_RGB = 11, // 4 bpp (no alpha)
358     RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA = 12, // 4 bpp (1 bit alpha)
359     RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA = 13, // 8 bpp
360     RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA = 14, // 8 bpp
361     RL_PIXELFORMAT_COMPRESSED_ETC1_RGB = 15, // 4 bpp
362     RL_PIXELFORMAT_COMPRESSED_ETC2_RGB = 16, // 4 bpp
363     RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA = 17, // 8 bpp
364     RL_PIXELFORMAT_COMPRESSED_PVRT_RGB = 18, // 4 bpp
365     RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA = 19, // 4 bpp
366     RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA = 20, // 8 bpp
367     RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA = 21 // 2 bpp
368 }
369 
370 // Texture parameters: filter mode
371 // NOTE 1: Filtering considers mipmaps if available in the texture
372 // NOTE 2: Filter is accordingly set for minification and magnification
373 enum rlTextureFilter
374 {
375     RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel aproximation
376     RL_TEXTURE_FILTER_BILINEAR = 1, // Linear filtering
377     RL_TEXTURE_FILTER_TRILINEAR = 2, // Trilinear filtering (linear with mipmaps)
378     RL_TEXTURE_FILTER_ANISOTROPIC_4X = 3, // Anisotropic filtering 4x
379     RL_TEXTURE_FILTER_ANISOTROPIC_8X = 4, // Anisotropic filtering 8x
380     RL_TEXTURE_FILTER_ANISOTROPIC_16X = 5 // Anisotropic filtering 16x
381 }
382 
383 // Color blending modes (pre-defined)
384 enum rlBlendMode
385 {
386     RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)
387     RL_BLEND_ADDITIVE = 1, // Blend textures adding colors
388     RL_BLEND_MULTIPLIED = 2, // Blend textures multiplying colors
389     RL_BLEND_ADD_COLORS = 3, // Blend textures adding colors (alternative)
390     RL_BLEND_SUBTRACT_COLORS = 4, // Blend textures subtracting colors (alternative)
391     RL_BLEND_CUSTOM = 5 // Belnd textures using custom src/dst factors (use SetBlendModeCustom())
392 }
393 
394 // Shader location point type
395 enum rlShaderLocationIndex
396 {
397     RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
398     RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01
399     RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02
400     RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal
401     RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent
402     RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color
403     RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection
404     RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform)
405     RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection
406     RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform)
407     RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal
408     RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view
409     RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color
410     RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color
411     RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color
412     RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
413     RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
414     RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal
415     RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness
416     RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion
417     RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission
418     RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height
419     RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap
420     RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance
421     RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter
422     RL_SHADER_LOC_MAP_BRDF = 25 // Shader location: sampler2d texture: brdf
423 }
424 
425 enum RL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO;
426 enum RL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS;
427 
428 // Shader uniform data type
429 enum rlShaderUniformDataType
430 {
431     RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
432     RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float)
433     RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float)
434     RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float)
435     RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int
436     RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int)
437     RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int)
438     RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int)
439     RL_SHADER_UNIFORM_SAMPLER2D = 8 // Shader uniform type: sampler2d
440 }
441 
442 // Shader attribute data types
443 enum rlShaderAttributeDataType
444 {
445     RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
446     RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float)
447     RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float)
448     RL_SHADER_ATTRIB_VEC4 = 3 // Shader attribute type: vec4 (4 float)
449 }
450 
451 //------------------------------------------------------------------------------------
452 // Functions Declaration - Matrix operations
453 //------------------------------------------------------------------------------------
454 
455 // Prevents name mangling of functions
456 
457 void rlMatrixMode (int mode); // Choose the current matrix to be transformed
458 void rlPushMatrix (); // Push the current matrix to stack
459 void rlPopMatrix (); // Pop lattest inserted matrix from stack
460 void rlLoadIdentity (); // Reset current matrix to identity matrix
461 void rlTranslatef (float x, float y, float z); // Multiply the current matrix by a translation matrix
462 void rlRotatef (float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
463 void rlScalef (float x, float y, float z); // Multiply the current matrix by a scaling matrix
464 void rlMultMatrixf (float* matf); // Multiply the current matrix by another matrix
465 void rlFrustum (double left, double right, double bottom, double top, double znear, double zfar);
466 void rlOrtho (double left, double right, double bottom, double top, double znear, double zfar);
467 void rlViewport (int x, int y, int width, int height); // Set the viewport area
468 
469 //------------------------------------------------------------------------------------
470 // Functions Declaration - Vertex level operations
471 //------------------------------------------------------------------------------------
472 void rlBegin (int mode); // Initialize drawing mode (how to organize vertex)
473 void rlEnd (); // Finish vertex providing
474 void rlVertex2i (int x, int y); // Define one vertex (position) - 2 int
475 void rlVertex2f (float x, float y); // Define one vertex (position) - 2 float
476 void rlVertex3f (float x, float y, float z); // Define one vertex (position) - 3 float
477 void rlTexCoord2f (float x, float y); // Define one vertex (texture coordinate) - 2 float
478 void rlNormal3f (float x, float y, float z); // Define one vertex (normal) - 3 float
479 void rlColor4ub (ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte
480 void rlColor3f (float x, float y, float z); // Define one vertex (color) - 3 float
481 void rlColor4f (float x, float y, float z, float w); // Define one vertex (color) - 4 float
482 
483 //------------------------------------------------------------------------------------
484 // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
485 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
486 // some of them are direct wrappers over OpenGL calls, some others are custom
487 //------------------------------------------------------------------------------------
488 
489 // Vertex buffers state
490 bool rlEnableVertexArray (uint vaoId); // Enable vertex array (VAO, if supported)
491 void rlDisableVertexArray (); // Disable vertex array (VAO, if supported)
492 void rlEnableVertexBuffer (uint id); // Enable vertex buffer (VBO)
493 void rlDisableVertexBuffer (); // Disable vertex buffer (VBO)
494 void rlEnableVertexBufferElement (uint id); // Enable vertex buffer element (VBO element)
495 void rlDisableVertexBufferElement (); // Disable vertex buffer element (VBO element)
496 void rlEnableVertexAttribute (uint index); // Enable vertex attribute index
497 void rlDisableVertexAttribute (uint index); // Disable vertex attribute index
498 
499 // Enable attribute state pointer
500 // Disable attribute state pointer
501 
502 // Textures state
503 void rlActiveTextureSlot (int slot); // Select and active a texture slot
504 void rlEnableTexture (uint id); // Enable texture
505 void rlDisableTexture (); // Disable texture
506 void rlEnableTextureCubemap (uint id); // Enable texture cubemap
507 void rlDisableTextureCubemap (); // Disable texture cubemap
508 void rlTextureParameters (uint id, int param, int value); // Set texture parameters (filter, wrap)
509 
510 // Shader state
511 void rlEnableShader (uint id); // Enable shader program
512 void rlDisableShader (); // Disable shader program
513 
514 // Framebuffer state
515 void rlEnableFramebuffer (uint id); // Enable render texture (fbo)
516 void rlDisableFramebuffer (); // Disable render texture (fbo), return to default framebuffer
517 void rlActiveDrawBuffers (int count); // Activate multiple draw color buffers
518 
519 // General render state
520 void rlEnableColorBlend (); // Enable color blending
521 void rlDisableColorBlend (); // Disable color blending
522 void rlEnableDepthTest (); // Enable depth test
523 void rlDisableDepthTest (); // Disable depth test
524 void rlEnableDepthMask (); // Enable depth write
525 void rlDisableDepthMask (); // Disable depth write
526 void rlEnableBackfaceCulling (); // Enable backface culling
527 void rlDisableBackfaceCulling (); // Disable backface culling
528 void rlEnableScissorTest (); // Enable scissor test
529 void rlDisableScissorTest (); // Disable scissor test
530 void rlScissor (int x, int y, int width, int height); // Scissor test
531 void rlEnableWireMode (); // Enable wire mode
532 void rlDisableWireMode (); // Disable wire mode
533 void rlSetLineWidth (float width); // Set the line drawing width
534 float rlGetLineWidth (); // Get the line drawing width
535 void rlEnableSmoothLines (); // Enable line aliasing
536 void rlDisableSmoothLines (); // Disable line aliasing
537 void rlEnableStereoRender (); // Enable stereo rendering
538 void rlDisableStereoRender (); // Disable stereo rendering
539 bool rlIsStereoRenderEnabled (); // Check if stereo render is enabled
540 
541 void rlClearColor (ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color
542 void rlClearScreenBuffers (); // Clear used screen buffers (color and depth)
543 void rlCheckErrors (); // Check and log OpenGL error codes
544 void rlSetBlendMode (int mode); // Set blending mode
545 void rlSetBlendFactors (int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
546 
547 //------------------------------------------------------------------------------------
548 // Functions Declaration - rlgl functionality
549 //------------------------------------------------------------------------------------
550 // rlgl initialization functions
551 void rlglInit (int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
552 void rlglClose (); // De-inititialize rlgl (buffers, shaders, textures)
553 void rlLoadExtensions (void* loader); // Load OpenGL extensions (loader function required)
554 int rlGetVersion (); // Get current OpenGL version
555 int rlGetFramebufferWidth (); // Get default framebuffer width
556 int rlGetFramebufferHeight (); // Get default framebuffer height
557 
558 uint rlGetTextureIdDefault (); // Get default texture id
559 uint rlGetShaderIdDefault (); // Get default shader id
560 int* rlGetShaderLocsDefault (); // Get default shader locations
561 
562 // Render batch management
563 // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
564 // but this render batch API is exposed in case of custom batches are required
565 rlRenderBatch rlLoadRenderBatch (int numBuffers, int bufferElements); // Load a render batch system
566 void rlUnloadRenderBatch (rlRenderBatch batch); // Unload render batch system
567 void rlDrawRenderBatch (rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset)
568 void rlSetRenderBatchActive (rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)
569 void rlDrawRenderBatchActive (); // Update and draw internal render batch
570 bool rlCheckRenderBatchLimit (int vCount); // Check internal buffer overflow for a given number of vertex
571 void rlSetTexture (uint id); // Set current texture for render batch and check buffers limits
572 
573 //------------------------------------------------------------------------------------------------------------------------
574 
575 // Vertex buffers management
576 uint rlLoadVertexArray (); // Load vertex array (vao) if supported
577 uint rlLoadVertexBuffer (void* buffer, int size, bool dynamic); // Load a vertex buffer attribute
578 uint rlLoadVertexBufferElement (void* buffer, int size, bool dynamic); // Load a new attributes element buffer
579 void rlUpdateVertexBuffer (uint bufferId, void* data, int dataSize, int offset); // Update GPU buffer with new data
580 void rlUnloadVertexArray (uint vaoId);
581 void rlUnloadVertexBuffer (uint vboId);
582 void rlSetVertexAttribute (uint index, int compSize, int type, bool normalized, int stride, void* pointer);
583 void rlSetVertexAttributeDivisor (uint index, int divisor);
584 void rlSetVertexAttributeDefault (int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value
585 void rlDrawVertexArray (int offset, int count);
586 void rlDrawVertexArrayElements (int offset, int count, void* buffer);
587 void rlDrawVertexArrayInstanced (int offset, int count, int instances);
588 void rlDrawVertexArrayElementsInstanced (int offset, int count, void* buffer, int instances);
589 
590 // Textures management
591 uint rlLoadTexture (void* data, int width, int height, int format, int mipmapCount); // Load texture in GPU
592 uint rlLoadTextureDepth (int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
593 uint rlLoadTextureCubemap (void* data, int size, int format); // Load texture cubemap
594 void rlUpdateTexture (uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data
595 void rlGetGlTextureFormats (int format, int* glInternalFormat, int* glFormat, int* glType); // Get OpenGL internal formats
596 const(char)* rlGetPixelFormatName (uint format); // Get name string for pixel format
597 void rlUnloadTexture (uint id); // Unload texture from GPU memory
598 void rlGenTextureMipmaps (uint id, int width, int height, int format, int* mipmaps); // Generate mipmap data for selected texture
599 void* rlReadTexturePixels (uint id, int width, int height, int format); // Read texture pixel data
600 ubyte* rlReadScreenPixels (int width, int height); // Read screen pixel data (color buffer)
601 
602 // Framebuffer management (fbo)
603 uint rlLoadFramebuffer (int width, int height); // Load an empty framebuffer
604 void rlFramebufferAttach (uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
605 bool rlFramebufferComplete (uint id); // Verify framebuffer is complete
606 void rlUnloadFramebuffer (uint id); // Delete framebuffer from GPU
607 
608 // Shaders management
609 uint rlLoadShaderCode (const(char)* vsCode, const(char)* fsCode); // Load shader from code strings
610 uint rlCompileShader (const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
611 uint rlLoadShaderProgram (uint vShaderId, uint fShaderId); // Load custom shader program
612 void rlUnloadShaderProgram (uint id); // Unload shader program
613 int rlGetLocationUniform (uint shaderId, const(char)* uniformName); // Get shader location uniform
614 int rlGetLocationAttrib (uint shaderId, const(char)* attribName); // Get shader location attribute
615 void rlSetUniform (int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform
616 void rlSetUniformMatrix (int locIndex, Matrix mat); // Set shader value matrix
617 void rlSetUniformSampler (int locIndex, uint textureId); // Set shader value sampler
618 void rlSetShader (uint id, int* locs); // Set shader currently active (id and locations)
619 
620 // Compute shader management
621 uint rlLoadComputeShaderProgram (uint shaderId); // Load compute shader program
622 void rlComputeShaderDispatch (uint groupX, uint groupY, uint groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
623 
624 // Shader buffer storage object management (ssbo)
625 uint rlLoadShaderBuffer (ulong size, const(void)* data, int usageHint); // Load shader storage buffer object (SSBO)
626 void rlUnloadShaderBuffer (uint ssboId); // Unload shader storage buffer object (SSBO)
627 void rlUpdateShaderBufferElements (uint id, const(void)* data, ulong dataSize, ulong offset); // Update SSBO buffer data
628 ulong rlGetShaderBufferSize (uint id); // Get SSBO buffer size
629 void rlReadShaderBufferElements (uint id, void* dest, ulong count, ulong offset); // Bind SSBO buffer
630 void rlBindShaderBuffer (uint id, uint index); // Copy SSBO buffer data
631 
632 // Buffer management
633 void rlCopyBuffersElements (uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); // Copy SSBO buffer data
634 void rlBindImageTexture (uint id, uint index, uint format, int readonly); // Bind image texture
635 
636 // Matrix state management
637 Matrix rlGetMatrixModelview (); // Get internal modelview matrix
638 Matrix rlGetMatrixProjection (); // Get internal projection matrix
639 Matrix rlGetMatrixTransform (); // Get internal accumulated transform matrix
640 Matrix rlGetMatrixProjectionStereo (int eye); // Get internal projection matrix for stereo render (selected eye)
641 Matrix rlGetMatrixViewOffsetStereo (int eye); // Get internal view offset matrix for stereo render (selected eye)
642 void rlSetMatrixProjection (Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
643 void rlSetMatrixModelview (Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
644 void rlSetMatrixProjectionStereo (Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
645 void rlSetMatrixViewOffsetStereo (Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
646 
647 // Quick and dirty cube/quad buffers load->draw->unload
648 void rlLoadDrawCube (); // Load and draw a cube
649 void rlLoadDrawQuad (); // Load and draw a quad
650 
651 // RLGL_H
652 
653 /***********************************************************************************
654 *
655 *   RLGL IMPLEMENTATION
656 *
657 ************************************************************************************/
658 
659 // OpenGL 1.1 library for OSX
660 // OpenGL extensions library
661 
662 // APIENTRY for OpenGL function pointer declarations is required
663 
664 // WINGDIAPI definition. Some Windows OpenGL headers need it
665 
666 // OpenGL 1.1 library
667 
668 // OpenGL 3 library for OSX
669 // OpenGL 3 extensions library for OSX
670 
671 // GLAD extensions loading library, includes OpenGL headers
672 
673 //#include <EGL/egl.h>              // EGL library -> not required, platform layer
674 // OpenGL ES 2.0 library
675 // OpenGL ES 2.0 extensions library
676 
677 // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
678 // provided headers (despite being defined in official Khronos GLES2 headers)
679 
680 // Required for: malloc(), free()
681 // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
682 // Required for: sqrtf(), sinf(), cosf(), floor(), log()
683 
684 //----------------------------------------------------------------------------------
685 // Defines and Macros
686 //----------------------------------------------------------------------------------
687 
688 // Default shader vertex attribute names to set location points
689 
690 // Binded by default to shader location: 0
691 
692 // Binded by default to shader location: 1
693 
694 // Binded by default to shader location: 2
695 
696 // Binded by default to shader location: 3
697 
698 // Binded by default to shader location: 4
699 
700 // Binded by default to shader location: 5
701 
702 // model-view-projection matrix
703 
704 // view matrix
705 
706 // projection matrix
707 
708 // model matrix
709 
710 // normal matrix (transpose(inverse(matModelView))
711 
712 // color diffuse (base tint color, multiplied by texture color)
713 
714 // texture0 (texture slot active 0)
715 
716 // texture1 (texture slot active 1)
717 
718 // texture2 (texture slot active 2)
719 
720 //----------------------------------------------------------------------------------
721 // Types and Structures Definition
722 //----------------------------------------------------------------------------------
723 
724 // Current render batch
725 // Default internal render batch
726 
727 // Current active render batch vertex counter (generic, used for all batches)
728 // Current active texture coordinate (added on glVertex*())
729 // Current active normal (added on glVertex*())
730 // Current active color (added on glVertex*())
731 
732 // Current matrix mode
733 // Current matrix pointer
734 // Default modelview matrix
735 // Default projection matrix
736 // Transform matrix to be used with rlTranslate, rlRotate, rlScale
737 // Require transform matrix application to current draw-call vertex (if required)
738 // Matrix stack for push/pop
739 // Matrix stack counter
740 
741 // Default texture used on shapes/poly drawing (required by shader)
742 // Active texture ids to be enabled on batch drawing (0 active by default)
743 // Default vertex shader id (used by default shader program)
744 // Default fragment shader id (used by default shader program)
745 // Default shader program id, supports vertex color and diffuse texture
746 // Default shader locations pointer to be used on rendering
747 // Current shader id to be used on rendering (by default, defaultShaderId)
748 // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)
749 
750 // Stereo rendering flag
751 // VR stereo rendering eyes projection matrices
752 // VR stereo rendering eyes view offset matrices
753 
754 // Blending mode active
755 // Blending source factor
756 // Blending destination factor
757 // Blending equation
758 
759 // Default framebuffer width
760 // Default framebuffer height
761 
762 // Renderer state
763 
764 // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
765 // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
766 // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
767 // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
768 // float textures support (32 bit per channel) (GL_OES_texture_float)
769 // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
770 // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
771 // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
772 // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
773 // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
774 // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
775 // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
776 // Compute shaders support (GL_ARB_compute_shader)
777 // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)
778 
779 // Maximum anisotropy level supported (minimum is 2.0f)
780 // Maximum bits for depth component
781 
782 // Extensions supported flags
783 
784 // OpenGL extension functions loader signature (same as GLADloadproc)
785 
786 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
787 
788 //----------------------------------------------------------------------------------
789 // Global Variables Definition
790 //----------------------------------------------------------------------------------
791 
792 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
793 
794 // NOTE: VAO functionality is exposed through extensions (OES)
795 
796 // NOTE: Instancing functionality could also be available through extension
797 
798 //----------------------------------------------------------------------------------
799 // Module specific Functions Declaration
800 //----------------------------------------------------------------------------------
801 
802 // Load default shader
803 // Unload default shader
804 
805 // Get compressed format official GL identifier name
806 // RLGL_SHOW_GL_DETAILS_INFO
807 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
808 
809 // Generate mipmaps data on CPU side
810 // Generate next mipmap level on CPU side
811 
812 // Get pixel data size in bytes (image or texture)
813 // Auxiliar matrix math functions
814 // Get identity matrix
815 // Multiply two matrices
816 
817 //----------------------------------------------------------------------------------
818 // Module Functions Definition - Matrix operations
819 //----------------------------------------------------------------------------------
820 
821 // Fallback to OpenGL 1.1 function calls
822 //---------------------------------------
823 
824 // Choose the current matrix to be transformed
825 
826 //else if (mode == RL_TEXTURE) // Not supported
827 
828 // Push the current matrix into RLGL.State.stack
829 
830 // Pop lattest inserted matrix from RLGL.State.stack
831 
832 // Reset current matrix to identity matrix
833 
834 // Multiply the current matrix by a translation matrix
835 
836 // NOTE: We transpose matrix with multiplication order
837 
838 // Multiply the current matrix by a rotation matrix
839 // NOTE: The provided angle must be in degrees
840 
841 // Axis vector (x, y, z) normalization
842 
843 // Rotation matrix generation
844 
845 // NOTE: We transpose matrix with multiplication order
846 
847 // Multiply the current matrix by a scaling matrix
848 
849 // NOTE: We transpose matrix with multiplication order
850 
851 // Multiply the current matrix by another matrix
852 
853 // Matrix creation from array
854 
855 // Multiply the current matrix by a perspective matrix generated by parameters
856 
857 // Multiply the current matrix by an orthographic matrix generated by parameters
858 
859 // NOTE: If left-right and top-botton values are equal it could create a division by zero,
860 // response to it is platform/compiler dependant
861 
862 // Set the viewport area (transformation from normalized device coordinates to window coordinates)
863 
864 //----------------------------------------------------------------------------------
865 // Module Functions Definition - Vertex level operations
866 //----------------------------------------------------------------------------------
867 
868 // Fallback to OpenGL 1.1 function calls
869 //---------------------------------------
870 
871 // Initialize drawing mode (how to organize vertex)
872 
873 // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
874 // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
875 
876 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
877 // that way, following QUADS drawing will keep aligned with index processing
878 // It implies adding some extra alignment vertex at the end of the draw,
879 // those vertex are not processed but they are considered as an additional offset
880 // for the next set of vertex to be drawn
881 
882 // Finish vertex providing
883 
884 // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
885 // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
886 // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
887 
888 // Verify internal buffers limits
889 // NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
890 
891 // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
892 // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
893 // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
894 
895 // Define one vertex (position)
896 // NOTE: Vertex position data is the basic information required for drawing
897 
898 // Transform provided vector if required
899 
900 // Verify that current vertex buffer elements limit has not been reached
901 
902 // Add vertices
903 
904 // Add current texcoord
905 
906 // TODO: Add current normal
907 // By default rlVertexBuffer type does not store normals
908 
909 // Add current color
910 
911 // Define one vertex (position)
912 
913 // Define one vertex (position)
914 
915 // Define one vertex (texture coordinate)
916 // NOTE: Texture coordinates are limited to QUADS only
917 
918 // Define one vertex (normal)
919 // NOTE: Normals limited to TRIANGLES only?
920 
921 // Define one vertex (color)
922 
923 // Define one vertex (color)
924 
925 // Define one vertex (color)
926 
927 //--------------------------------------------------------------------------------------
928 // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
929 //--------------------------------------------------------------------------------------
930 
931 // Set current texture to use
932 
933 // NOTE: If quads batch limit is reached, we force a draw call and next batch starts
934 
935 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
936 // that way, following QUADS drawing will keep aligned with index processing
937 // It implies adding some extra alignment vertex at the end of the draw,
938 // those vertex are not processed but they are considered as an additional offset
939 // for the next set of vertex to be drawn
940 
941 // Select and active a texture slot
942 
943 // Enable texture
944 
945 // Disable texture
946 
947 // Enable texture cubemap
948 
949 // Disable texture cubemap
950 
951 // Set texture parameters (wrap mode/filter mode)
952 
953 // Enable shader program
954 
955 // Disable shader program
956 
957 // Enable rendering to texture (fbo)
958 
959 // Disable rendering to texture
960 
961 // Activate multiple draw color buffers
962 // NOTE: One color buffer is always active by default
963 
964 // NOTE: Maximum number of draw buffers supported is implementation dependant,
965 // it can be queried with glGet*() but it must be at least 8
966 //GLint maxDrawBuffers = 0;
967 //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
968 
969 //----------------------------------------------------------------------------------
970 // General render state configuration
971 //----------------------------------------------------------------------------------
972 
973 // Enable color blending
974 
975 // Disable color blending
976 
977 // Enable depth test
978 
979 // Disable depth test
980 
981 // Enable depth write
982 
983 // Disable depth write
984 
985 // Enable backface culling
986 
987 // Disable backface culling
988 
989 // Enable scissor test
990 
991 // Disable scissor test
992 
993 // Scissor test
994 
995 // Enable wire mode
996 
997 // NOTE: glPolygonMode() not available on OpenGL ES
998 
999 // Disable wire mode
1000 
1001 // NOTE: glPolygonMode() not available on OpenGL ES
1002 
1003 // Set the line drawing width
1004 
1005 // Get the line drawing width
1006 
1007 // Enable line aliasing
1008 
1009 // Disable line aliasing
1010 
1011 // Enable stereo rendering
1012 
1013 // Disable stereo rendering
1014 
1015 // Check if stereo render is enabled
1016 
1017 // Clear color buffer with color
1018 
1019 // Color values clamp to 0.0f(0) and 1.0f(255)
1020 
1021 // Clear used screen buffers (color and depth)
1022 
1023 // Clear used buffers: Color and Depth (Depth is used for 3D)
1024 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);     // Stencil buffer not used...
1025 
1026 // Check and log OpenGL error codes
1027 
1028 // Set blend mode
1029 
1030 // Set blending mode factor and equation
1031 
1032 //----------------------------------------------------------------------------------
1033 // Module Functions Definition - OpenGL Debug
1034 //----------------------------------------------------------------------------------
1035 
1036 // Ignore non-significant error/warning codes (NVidia drivers)
1037 // NOTE: Here there are the details with a sample output:
1038 // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
1039 // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
1040 //             will use VIDEO memory as the source for buffer object operations. (severity: low)
1041 // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)
1042 // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have
1043 //             a defined base level and cannot be used for texture mapping. (severity: low)
1044 
1045 //----------------------------------------------------------------------------------
1046 // Module Functions Definition - rlgl functionality
1047 //----------------------------------------------------------------------------------
1048 
1049 // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
1050 
1051 // Enable OpenGL debug context if required
1052 
1053 // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message
1054 
1055 // Debug context options:
1056 //  - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
1057 //  - GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint can be placed on the callback in order to get a stacktrace for the GL error
1058 
1059 // Init default white texture
1060 // 1 pixel RGBA (4 bytes)
1061 
1062 // Init default Shader (customized for GL 3.3 and ES2)
1063 // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs
1064 
1065 // Init default vertex arrays buffers
1066 
1067 // Init stack matrices (emulating OpenGL 1.1)
1068 
1069 // Init internal matrices
1070 
1071 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1072 
1073 // Initialize OpenGL default states
1074 //----------------------------------------------------------
1075 // Init state: Depth test
1076 // Type of depth testing to apply
1077 // Disable depth testing for 2D (only used for 3D)
1078 
1079 // Init state: Blending mode
1080 // Color blending function (how colors are mixed)
1081 // Enable color blending (required to work with transparencies)
1082 
1083 // Init state: Culling
1084 // NOTE: All shapes/models triangles are drawn CCW
1085 // Cull the back face (default)
1086 // Front face are defined counter clockwise (default)
1087 // Enable backface culling
1088 
1089 // Init state: Cubemap seamless
1090 
1091 // Seamless cubemaps (not supported on OpenGL ES 2.0)
1092 
1093 // Init state: Color hints (deprecated in OpenGL 3.0+)
1094 // Improve quality of color and texture coordinate interpolation
1095 // Smooth shading between vertex (vertex colors interpolation)
1096 
1097 // Store screen size into global variables
1098 
1099 //----------------------------------------------------------
1100 
1101 // Init state: Color/Depth buffers clear
1102 // Set clear color (black)
1103 // Set clear depth value (default)
1104 // Clear color and depth buffers (depth buffer required for 3D)
1105 
1106 // Vertex Buffer Object deinitialization (memory free)
1107 
1108 // Unload default shader
1109 
1110 // Unload default texture
1111 
1112 // Load OpenGL extensions
1113 // NOTE: External loader function must be provided
1114 
1115 // Also defined for GRAPHICS_API_OPENGL_21
1116 // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
1117 
1118 // Get number of supported extensions
1119 
1120 // Get supported extensions list
1121 // WARNING: glGetStringi() not available on OpenGL 2.1
1122 
1123 // Register supported extensions flags
1124 // OpenGL 3.3 extensions supported by default (core)
1125 
1126 // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
1127 // Texture compression: DXT
1128 // Texture compression: ETC2/EAC
1129 
1130 // GRAPHICS_API_OPENGL_33
1131 
1132 // Get supported extensions list
1133 
1134 // Allocate 512 strings pointers (2 KB)
1135 // One big const string
1136 
1137 // NOTE: We have to duplicate string because glGetString() returns a const string
1138 // Get extensions string size in bytes
1139 
1140 // Check required extensions
1141 
1142 // Check VAO support
1143 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
1144 
1145 // The extension is supported by our hardware and driver, try to get related functions pointers
1146 // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
1147 
1148 //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES");     // NOTE: Fails in WebGL, omitted
1149 
1150 // Check instanced rendering support
1151 // Web ANGLE
1152 
1153 // Standard EXT
1154 
1155 // Check NPOT textures support
1156 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
1157 
1158 // Check texture float support
1159 
1160 // Check depth texture support
1161 
1162 // Check texture compression support: DXT
1163 
1164 // Check texture compression support: ETC1
1165 
1166 // Check texture compression support: ETC2/EAC
1167 
1168 // Check texture compression support: PVR
1169 
1170 // Check texture compression support: ASTC
1171 
1172 // Check anisotropic texture filter support
1173 
1174 // Check clamp mirror wrap mode support
1175 
1176 // Free extensions pointers
1177 
1178 // Duplicated string must be deallocated
1179 // GRAPHICS_API_OPENGL_ES2
1180 
1181 // Check OpenGL information and capabilities
1182 //------------------------------------------------------------------------------
1183 // Show current OpenGL and GLSL version
1184 
1185 // NOTE: Anisotropy levels capability is an extension
1186 
1187 // Show some OpenGL GPU capabilities
1188 
1189 /*
1190 // Following capabilities are only supported by OpenGL 4.3 or greater
1191 glGetIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &capability);
1192 TRACELOG(RL_LOG_INFO, "    GL_MAX_VERTEX_ATTRIB_BINDINGS: %i", capability);
1193 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &capability);
1194 TRACELOG(RL_LOG_INFO, "    GL_MAX_UNIFORM_LOCATIONS: %i", capability);
1195 */
1196 // RLGL_SHOW_GL_DETAILS_INFO
1197 
1198 // Show some basic info about GL supported features
1199 
1200 // RLGL_SHOW_GL_DETAILS_INFO
1201 
1202 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1203 
1204 // Get current OpenGL version
1205 
1206 // NOTE: Force OpenGL 3.3 on OSX
1207 
1208 // Get default framebuffer width
1209 
1210 // Get default framebuffer height
1211 
1212 // Get default internal texture (white texture)
1213 // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
1214 
1215 // Get default shader id
1216 
1217 // Get default shader locs
1218 
1219 // Render batch management
1220 //------------------------------------------------------------------------------------------------
1221 // Load render batch
1222 
1223 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
1224 //--------------------------------------------------------------------------------------------
1225 
1226 // 3 float by vertex, 4 vertex by quad
1227 // 2 float by texcoord, 4 texcoord by quad
1228 // 4 float by color, 4 colors by quad
1229 
1230 // 6 int by quad (indices)
1231 
1232 // 6 int by quad (indices)
1233 
1234 // Indices can be initialized right now
1235 
1236 //--------------------------------------------------------------------------------------------
1237 
1238 // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
1239 //--------------------------------------------------------------------------------------------
1240 
1241 // Initialize Quads VAO
1242 
1243 // Quads - Vertex buffers binding and attributes enable
1244 // Vertex position buffer (shader-location = 0)
1245 
1246 // Vertex texcoord buffer (shader-location = 1)
1247 
1248 // Vertex color buffer (shader-location = 3)
1249 
1250 // Fill index buffer
1251 
1252 // Unbind the current VAO
1253 
1254 //--------------------------------------------------------------------------------------------
1255 
1256 // Init draw calls tracking system
1257 //--------------------------------------------------------------------------------------------
1258 
1259 //batch.draws[i].vaoId = 0;
1260 //batch.draws[i].shaderId = 0;
1261 
1262 //batch.draws[i].RLGL.State.projection = rlMatrixIdentity();
1263 //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();
1264 
1265 // Record buffer count
1266 // Reset draws counter
1267 // Reset depth value
1268 //--------------------------------------------------------------------------------------------
1269 
1270 // Unload default internal buffers vertex data from CPU and GPU
1271 
1272 // Unbind everything
1273 
1274 // Unload all vertex buffers data
1275 
1276 // Unbind VAO attribs data
1277 
1278 // Delete VBOs from GPU (VRAM)
1279 
1280 // Delete VAOs from GPU (VRAM)
1281 
1282 // Free vertex arrays memory from CPU (RAM)
1283 
1284 // Unload arrays
1285 
1286 // Draw render batch
1287 // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
1288 
1289 // Update batch vertex buffers
1290 //------------------------------------------------------------------------------------------------------------
1291 // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
1292 // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
1293 
1294 // Activate elements VAO
1295 
1296 // Vertex positions buffer
1297 
1298 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW);  // Update all buffer
1299 
1300 // Texture coordinates buffer
1301 
1302 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
1303 
1304 // Colors buffer
1305 
1306 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW);    // Update all buffer
1307 
1308 // NOTE: glMapBuffer() causes sync issue.
1309 // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
1310 // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
1311 // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
1312 // allocated pointer immediately even if GPU is still working with the previous data.
1313 
1314 // Another option: map the buffer object into client's memory
1315 // Probably this code could be moved somewhere else...
1316 // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
1317 // if (batch->vertexBuffer[batch->currentBuffer].vertices)
1318 // {
1319 // Update vertex data
1320 // }
1321 // glUnmapBuffer(GL_ARRAY_BUFFER);
1322 
1323 // Unbind the current VAO
1324 
1325 //------------------------------------------------------------------------------------------------------------
1326 
1327 // Draw batch vertex buffers (considering VR stereo if required)
1328 //------------------------------------------------------------------------------------------------------------
1329 
1330 // Setup current eye viewport (half screen width)
1331 
1332 // Set current eye view offset to modelview matrix
1333 
1334 // Set current eye projection matrix
1335 
1336 // Draw buffers
1337 
1338 // Set current shader and upload current MVP matrix
1339 
1340 // Create modelview-projection matrix and upload to shader
1341 
1342 // Bind vertex attrib: position (shader-location = 0)
1343 
1344 // Bind vertex attrib: texcoord (shader-location = 1)
1345 
1346 // Bind vertex attrib: color (shader-location = 3)
1347 
1348 // Setup some default shader values
1349 
1350 // Active default sampler2D: texture0
1351 
1352 // Activate additional sampler textures
1353 // Those additional textures will be common for all draw calls of the batch
1354 
1355 // Activate default sampler2D texture0 (one texture is always active for default batch shader)
1356 // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
1357 
1358 // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
1359 
1360 // We need to define the number of indices to be processed: elementCount*6
1361 // NOTE: The final parameter tells the GPU the offset in bytes from the
1362 // start of the index buffer to the location of the first index to process
1363 
1364 // Unbind textures
1365 
1366 // Unbind VAO
1367 
1368 // Unbind shader program
1369 
1370 //------------------------------------------------------------------------------------------------------------
1371 
1372 // Reset batch buffers
1373 //------------------------------------------------------------------------------------------------------------
1374 // Reset vertex counter for next frame
1375 
1376 // Reset depth for next draw
1377 
1378 // Restore projection/modelview matrices
1379 
1380 // Reset RLGL.currentBatch->draws array
1381 
1382 // Reset active texture units for next batch
1383 
1384 // Reset draws counter to one draw for the batch
1385 
1386 //------------------------------------------------------------------------------------------------------------
1387 
1388 // Change to next buffer in the list (in case of multi-buffering)
1389 
1390 // Set the active render batch for rlgl
1391 
1392 // Update and draw internal render batch
1393 
1394 // NOTE: Stereo rendering is checked inside
1395 
1396 // Check internal buffer overflow for a given number of vertex
1397 // and force a rlRenderBatch draw call if required
1398 
1399 // NOTE: Stereo rendering is checked inside
1400 
1401 // Restore state of last batch so we can continue adding vertices
1402 
1403 // Textures data management
1404 //-----------------------------------------------------------------------------------------
1405 // Convert image data to OpenGL texture (returns OpenGL valid Id)
1406 
1407 // Free any old binding
1408 
1409 // Check texture format support by OpenGL 1.1 (compressed textures not supported)
1410 
1411 // GRAPHICS_API_OPENGL_11
1412 
1413 // Generate texture id
1414 
1415 // Mipmap data offset
1416 
1417 // Load the different mipmap levels
1418 
1419 // Security check for NPOT textures
1420 
1421 // Texture parameters configuration
1422 // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
1423 
1424 // NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
1425 
1426 // Set texture to repeat on x-axis
1427 // Set texture to repeat on y-axis
1428 
1429 // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
1430 // Set texture to clamp on x-axis
1431 // Set texture to clamp on y-axis
1432 
1433 // Set texture to repeat on x-axis
1434 // Set texture to repeat on y-axis
1435 
1436 // Magnification and minification filters
1437 // Alternative: GL_LINEAR
1438 // Alternative: GL_LINEAR
1439 
1440 // Activate Trilinear filtering if mipmaps are available
1441 
1442 // At this point we have the texture loaded in GPU and texture parameters configured
1443 
1444 // NOTE: If mipmaps were not in data, they are not generated automatically
1445 
1446 // Unbind current texture
1447 
1448 // Load depth texture/renderbuffer (to be attached to fbo)
1449 // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
1450 
1451 // In case depth textures not supported, we force renderbuffer usage
1452 
1453 // NOTE: We let the implementation to choose the best bit-depth
1454 // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
1455 
1456 // Create the renderbuffer that will serve as the depth attachment for the framebuffer
1457 // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
1458 
1459 // Load texture cubemap
1460 // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
1461 // expected the following convention: +X, -X, +Y, -Y, +Z, -Z
1462 
1463 // Load cubemap faces
1464 
1465 // Instead of using a sized internal texture format (GL_RGB16F, GL_RGB32F), we let the driver to choose the better format for us (GL_RGB)
1466 
1467 // Set cubemap texture sampling parameters
1468 
1469 // Flag not supported on OpenGL ES 2.0
1470 
1471 // Update already loaded texture in GPU with new data
1472 // NOTE: We don't know safely if internal texture format is the expected one...
1473 
1474 // Get OpenGL internal formats and data type from raylib PixelFormat
1475 
1476 // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
1477 
1478 // NOTE: Requires extension OES_texture_float
1479 // NOTE: Requires extension OES_texture_float
1480 // NOTE: Requires extension OES_texture_float
1481 
1482 // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
1483 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1484 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1485 // NOTE: Requires PowerVR GPU
1486 // NOTE: Requires PowerVR GPU
1487 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1488 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1489 
1490 // Unload texture from GPU memory
1491 
1492 // Generate mipmap data for selected texture
1493 
1494 // Check if texture is power-of-two (POT)
1495 
1496 // WARNING: Manual mipmap generation only works for RGBA 32bit textures!
1497 
1498 // Retrieve texture data from VRAM
1499 
1500 // NOTE: Texture data size is reallocated to fit mipmaps data
1501 // NOTE: CPU mipmap generation only supports RGBA 32bit data
1502 
1503 // Load the mipmaps
1504 
1505 // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
1506 
1507 //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);   // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
1508 // Generate mipmaps automatically
1509 
1510 // Activate Trilinear filtering for mipmaps
1511 
1512 // Read texture pixel data
1513 
1514 // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)
1515 // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
1516 //int width, height, format;
1517 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
1518 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
1519 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
1520 
1521 // NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.
1522 // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
1523 // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
1524 // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
1525 
1526 // glGetTexImage() is not available on OpenGL ES 2.0
1527 // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
1528 // Two possible Options:
1529 // 1 - Bind texture to color fbo attachment and glReadPixels()
1530 // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
1531 // We are using Option 1, just need to care for texture format on retrieval
1532 // NOTE: This behaviour could be conditioned by graphic driver...
1533 
1534 // Attach our texture to FBO
1535 
1536 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
1537 
1538 // Clean up temporal fbo
1539 
1540 // Read screen pixel data (color buffer)
1541 
1542 // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
1543 // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
1544 
1545 // Flip image vertically!
1546 
1547 // Flip line
1548 
1549 // Set alpha component value to 255 (no trasparent image retrieval)
1550 // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
1551 
1552 // NOTE: image data should be freed
1553 
1554 // Framebuffer management (fbo)
1555 //-----------------------------------------------------------------------------------------
1556 // Load a framebuffer to be used for rendering
1557 // NOTE: No textures attached
1558 
1559 // Create the framebuffer object
1560 // Unbind any framebuffer
1561 
1562 // Attach color buffer texture to an fbo (unloads previous attachment)
1563 // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
1564 
1565 // Verify render texture is complete
1566 
1567 // Unload framebuffer from GPU memory
1568 // NOTE: All attached textures/cubemaps/renderbuffers are also deleted
1569 
1570 // Query depth attachment to automatically delete texture/renderbuffer
1571 
1572 // Bind framebuffer to query depth texture type
1573 
1574 // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
1575 // the texture image is automatically detached from the currently bound framebuffer.
1576 
1577 // Vertex data management
1578 //-----------------------------------------------------------------------------------------
1579 // Load a new attributes buffer
1580 
1581 // Load a new attributes element buffer
1582 
1583 // Enable vertex buffer (VBO)
1584 
1585 // Disable vertex buffer (VBO)
1586 
1587 // Enable vertex buffer element (VBO element)
1588 
1589 // Disable vertex buffer element (VBO element)
1590 
1591 // Update vertex buffer with new data
1592 // NOTE: dataSize and offset must be provided in bytes
1593 
1594 // Update vertex buffer elements with new data
1595 // NOTE: dataSize and offset must be provided in bytes
1596 
1597 // Enable vertex array object (VAO)
1598 
1599 // Disable vertex array object (VAO)
1600 
1601 // Enable vertex attribute index
1602 
1603 // Disable vertex attribute index
1604 
1605 // Draw vertex array
1606 
1607 // Draw vertex array elements
1608 
1609 // Draw vertex array instanced
1610 
1611 // Draw vertex array elements instanced
1612 
1613 // Enable vertex state pointer
1614 
1615 //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
1616 
1617 // Disable vertex state pointer
1618 
1619 // Load vertex array object (VAO)
1620 
1621 // Set vertex attribute
1622 
1623 // Set vertex attribute divisor
1624 
1625 // Unload vertex array object (VAO)
1626 
1627 // Unload vertex buffer (VBO)
1628 
1629 //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
1630 
1631 // Shaders management
1632 //-----------------------------------------------------------------------------------------------
1633 // Load shader from code strings
1634 // NOTE: If shader string is NULL, using default vertex/fragment shaders
1635 
1636 // Detach shader before deletion to make sure memory is freed
1637 
1638 // Detach shader before deletion to make sure memory is freed
1639 
1640 // Get available shader uniforms
1641 // NOTE: This information is useful for debug...
1642 
1643 // Assume no variable names longer than 256
1644 
1645 // Get the name of the uniforms
1646 
1647 // Compile custom shader and return shader id
1648 
1649 //case GL_GEOMETRY_SHADER:
1650 
1651 //case GL_GEOMETRY_SHADER:
1652 
1653 // Load custom shader strings and return program id
1654 
1655 // NOTE: Default attribute shader locations must be binded before linking
1656 
1657 // NOTE: If some attrib name is no found on the shader, it locations becomes -1
1658 
1659 // NOTE: All uniform variables are intitialised to 0 when a program links
1660 
1661 // Get the size of compiled shader program (not available on OpenGL ES 2.0)
1662 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
1663 //GLint binarySize = 0;
1664 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
1665 
1666 // Unload shader program
1667 
1668 // Get shader location uniform
1669 
1670 // Get shader location attribute
1671 
1672 // Set shader value uniform
1673 
1674 // Set shader value attribute
1675 
1676 // Set shader value uniform matrix
1677 
1678 // Set shader value uniform sampler
1679 
1680 // Check if texture is already active
1681 
1682 // Register a new active texture for the internal batch system
1683 // NOTE: Default texture is always activated as GL_TEXTURE0
1684 
1685 // Activate new texture unit
1686 // Save texture id for binding on drawing
1687 
1688 // Set shader currently active (id and locations)
1689 
1690 // Load compute shader program
1691 
1692 // NOTE: All uniform variables are intitialised to 0 when a program links
1693 
1694 // Get the size of compiled shader program (not available on OpenGL ES 2.0)
1695 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
1696 //GLint binarySize = 0;
1697 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
1698 
1699 // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
1700 
1701 // Load shader storage buffer object (SSBO)
1702 
1703 // Unload shader storage buffer object (SSBO)
1704 
1705 // Update SSBO buffer data
1706 
1707 // Get SSBO buffer size
1708 
1709 // Read SSBO buffer data
1710 
1711 // Bind SSBO buffer
1712 
1713 // Copy SSBO buffer data
1714 
1715 // Bind image texture
1716 
1717 // Matrix state management
1718 //-----------------------------------------------------------------------------------------
1719 // Get internal modelview matrix
1720 
1721 // Get internal projection matrix
1722 
1723 // Get internal accumulated transform matrix
1724 
1725 // TODO: Consider possible transform matrices in the RLGL.State.stack
1726 // Is this the right order? or should we start with the first stored matrix instead of the last one?
1727 //Matrix matStackTransform = rlMatrixIdentity();
1728 //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);
1729 
1730 // Get internal projection matrix for stereo render (selected eye)
1731 
1732 // Get internal view offset matrix for stereo render (selected eye)
1733 
1734 // Set a custom modelview matrix (replaces internal modelview matrix)
1735 
1736 // Set a custom projection matrix (replaces internal projection matrix)
1737 
1738 // Set eyes projection matrices for stereo rendering
1739 
1740 // Set eyes view offsets matrices for stereo rendering
1741 
1742 // Load and draw a quad in NDC
1743 
1744 // Positions         Texcoords
1745 
1746 // Gen VAO to contain VBO
1747 
1748 // Gen and fill vertex buffer (VBO)
1749 
1750 // Bind vertex attributes (position, texcoords)
1751 
1752 // Positions
1753 
1754 // Texcoords
1755 
1756 // Draw quad
1757 
1758 // Delete buffers (VBO and VAO)
1759 
1760 // Load and draw a cube in NDC
1761 
1762 // Positions          Normals               Texcoords
1763 
1764 // Gen VAO to contain VBO
1765 
1766 // Gen and fill vertex buffer (VBO)
1767 
1768 // Bind vertex attributes (position, normals, texcoords)
1769 
1770 // Positions
1771 
1772 // Normals
1773 
1774 // Texcoords
1775 
1776 // Draw cube
1777 
1778 // Delete VBO and VAO
1779 
1780 // Get name string for pixel format
1781 
1782 // 8 bit per pixel (no alpha)
1783 // 8*2 bpp (2 channels)
1784 // 16 bpp
1785 // 24 bpp
1786 // 16 bpp (1 bit alpha)
1787 // 16 bpp (4 bit alpha)
1788 // 32 bpp
1789 // 32 bpp (1 channel - float)
1790 // 32*3 bpp (3 channels - float)
1791 // 32*4 bpp (4 channels - float)
1792 // 4 bpp (no alpha)
1793 // 4 bpp (1 bit alpha)
1794 // 8 bpp
1795 // 8 bpp
1796 // 4 bpp
1797 // 4 bpp
1798 // 8 bpp
1799 // 4 bpp
1800 // 4 bpp
1801 // 8 bpp
1802 // 2 bpp
1803 
1804 //----------------------------------------------------------------------------------
1805 // Module specific Functions Definition
1806 //----------------------------------------------------------------------------------
1807 
1808 // Load default shader (just vertex positioning and texture coloring)
1809 // NOTE: This shader program is used for internal buffers
1810 // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
1811 
1812 // NOTE: All locations must be reseted to -1 (no location)
1813 
1814 // Vertex shader directly defined, no external file required
1815 
1816 // Fragment shader directly defined, no external file required
1817 
1818 // Precision required for OpenGL ES2 (WebGL)
1819 
1820 // NOTE: Compiled vertex/fragment shaders are kept for re-use
1821 // Compile default vertex shader
1822 // Compile default fragment shader
1823 
1824 // Set default shader locations: attributes locations
1825 
1826 // Set default shader locations: uniform locations
1827 
1828 // Unload default shader
1829 // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
1830 
1831 // Get compressed format official GL identifier name
1832 
1833 // GL_EXT_texture_compression_s3tc
1834 
1835 // GL_3DFX_texture_compression_FXT1
1836 
1837 // GL_IMG_texture_compression_pvrtc
1838 
1839 // GL_OES_compressed_ETC1_RGB8_texture
1840 
1841 // GL_ARB_texture_compression_rgtc
1842 
1843 // GL_ARB_texture_compression_bptc
1844 
1845 // GL_ARB_ES3_compatibility
1846 
1847 // GL_KHR_texture_compression_astc_hdr
1848 
1849 // RLGL_SHOW_GL_DETAILS_INFO
1850 
1851 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1852 
1853 // Mipmaps data is generated after image data
1854 // NOTE: Only works with RGBA (4 bytes) data!
1855 
1856 // Required mipmap levels count (including base level)
1857 
1858 // Size in bytes (will include mipmaps...), RGBA only
1859 
1860 // Count mipmap levels required
1861 
1862 // Add mipmap size (in bytes)
1863 
1864 // RGBA: 4 bytes
1865 
1866 // Generate mipmaps
1867 // NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)
1868 
1869 // Size of last mipmap
1870 
1871 // Mipmap size to store after offset
1872 
1873 // Add mipmap to data
1874 
1875 // free mipmap data
1876 
1877 // Manual mipmap generation (basic scaling algorithm)
1878 
1879 // Scaling algorithm works perfectly (box-filter)
1880 
1881 // GRAPHICS_API_OPENGL_11
1882 
1883 // Get pixel data size in bytes (image or texture)
1884 // NOTE: Size depends on pixel format
1885 
1886 // Size in bytes
1887 // Bits per pixel
1888 
1889 // Total data size in bytes
1890 
1891 // Most compressed formats works on 4x4 blocks,
1892 // if texture is smaller, minimum dataSize is 8 or 16
1893 
1894 // Auxiliar math functions
1895 
1896 // Get identity matrix
1897 
1898 // Get two matrix multiplication
1899 // NOTE: When multiplying matrices... the order matters!
1900 
1901 // RLGL_IMPLEMENTATION