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-2022 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 approximation
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_ALPHA_PREMULTIPLY = 5, // Blend premultiplied textures considering alpha
392     RL_BLEND_CUSTOM = 6 // Blend textures using custom src/dst factors (use rlSetBlendFactors())
393 }
394 
395 // Shader location point type
396 enum rlShaderLocationIndex
397 {
398     RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
399     RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01
400     RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02
401     RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal
402     RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent
403     RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color
404     RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection
405     RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform)
406     RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection
407     RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform)
408     RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal
409     RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view
410     RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color
411     RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color
412     RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color
413     RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
414     RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
415     RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal
416     RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness
417     RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion
418     RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission
419     RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height
420     RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap
421     RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance
422     RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter
423     RL_SHADER_LOC_MAP_BRDF = 25 // Shader location: sampler2d texture: brdf
424 }
425 
426 enum RL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO;
427 enum RL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS;
428 
429 // Shader uniform data type
430 enum rlShaderUniformDataType
431 {
432     RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
433     RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float)
434     RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float)
435     RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float)
436     RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int
437     RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int)
438     RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int)
439     RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int)
440     RL_SHADER_UNIFORM_SAMPLER2D = 8 // Shader uniform type: sampler2d
441 }
442 
443 // Shader attribute data types
444 enum rlShaderAttributeDataType
445 {
446     RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
447     RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float)
448     RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float)
449     RL_SHADER_ATTRIB_VEC4 = 3 // Shader attribute type: vec4 (4 float)
450 }
451 
452 //------------------------------------------------------------------------------------
453 // Functions Declaration - Matrix operations
454 //------------------------------------------------------------------------------------
455 
456 // Prevents name mangling of functions
457 
458 void rlMatrixMode (int mode); // Choose the current matrix to be transformed
459 void rlPushMatrix (); // Push the current matrix to stack
460 void rlPopMatrix (); // Pop lattest inserted matrix from stack
461 void rlLoadIdentity (); // Reset current matrix to identity matrix
462 void rlTranslatef (float x, float y, float z); // Multiply the current matrix by a translation matrix
463 void rlRotatef (float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
464 void rlScalef (float x, float y, float z); // Multiply the current matrix by a scaling matrix
465 void rlMultMatrixf (float* matf); // Multiply the current matrix by another matrix
466 void rlFrustum (double left, double right, double bottom, double top, double znear, double zfar);
467 void rlOrtho (double left, double right, double bottom, double top, double znear, double zfar);
468 void rlViewport (int x, int y, int width, int height); // Set the viewport area
469 
470 //------------------------------------------------------------------------------------
471 // Functions Declaration - Vertex level operations
472 //------------------------------------------------------------------------------------
473 void rlBegin (int mode); // Initialize drawing mode (how to organize vertex)
474 void rlEnd (); // Finish vertex providing
475 void rlVertex2i (int x, int y); // Define one vertex (position) - 2 int
476 void rlVertex2f (float x, float y); // Define one vertex (position) - 2 float
477 void rlVertex3f (float x, float y, float z); // Define one vertex (position) - 3 float
478 void rlTexCoord2f (float x, float y); // Define one vertex (texture coordinate) - 2 float
479 void rlNormal3f (float x, float y, float z); // Define one vertex (normal) - 3 float
480 void rlColor4ub (ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte
481 void rlColor3f (float x, float y, float z); // Define one vertex (color) - 3 float
482 void rlColor4f (float x, float y, float z, float w); // Define one vertex (color) - 4 float
483 
484 //------------------------------------------------------------------------------------
485 // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
486 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
487 // some of them are direct wrappers over OpenGL calls, some others are custom
488 //------------------------------------------------------------------------------------
489 
490 // Vertex buffers state
491 bool rlEnableVertexArray (uint vaoId); // Enable vertex array (VAO, if supported)
492 void rlDisableVertexArray (); // Disable vertex array (VAO, if supported)
493 void rlEnableVertexBuffer (uint id); // Enable vertex buffer (VBO)
494 void rlDisableVertexBuffer (); // Disable vertex buffer (VBO)
495 void rlEnableVertexBufferElement (uint id); // Enable vertex buffer element (VBO element)
496 void rlDisableVertexBufferElement (); // Disable vertex buffer element (VBO element)
497 void rlEnableVertexAttribute (uint index); // Enable vertex attribute index
498 void rlDisableVertexAttribute (uint index); // Disable vertex attribute index
499 
500 // Enable attribute state pointer
501 // Disable attribute state pointer
502 
503 // Textures state
504 void rlActiveTextureSlot (int slot); // Select and active a texture slot
505 void rlEnableTexture (uint id); // Enable texture
506 void rlDisableTexture (); // Disable texture
507 void rlEnableTextureCubemap (uint id); // Enable texture cubemap
508 void rlDisableTextureCubemap (); // Disable texture cubemap
509 void rlTextureParameters (uint id, int param, int value); // Set texture parameters (filter, wrap)
510 
511 // Shader state
512 void rlEnableShader (uint id); // Enable shader program
513 void rlDisableShader (); // Disable shader program
514 
515 // Framebuffer state
516 void rlEnableFramebuffer (uint id); // Enable render texture (fbo)
517 void rlDisableFramebuffer (); // Disable render texture (fbo), return to default framebuffer
518 void rlActiveDrawBuffers (int count); // Activate multiple draw color buffers
519 
520 // General render state
521 void rlEnableColorBlend (); // Enable color blending
522 void rlDisableColorBlend (); // Disable color blending
523 void rlEnableDepthTest (); // Enable depth test
524 void rlDisableDepthTest (); // Disable depth test
525 void rlEnableDepthMask (); // Enable depth write
526 void rlDisableDepthMask (); // Disable depth write
527 void rlEnableBackfaceCulling (); // Enable backface culling
528 void rlDisableBackfaceCulling (); // Disable backface culling
529 void rlEnableScissorTest (); // Enable scissor test
530 void rlDisableScissorTest (); // Disable scissor test
531 void rlScissor (int x, int y, int width, int height); // Scissor test
532 void rlEnableWireMode (); // Enable wire mode
533 void rlDisableWireMode (); // Disable wire mode
534 void rlSetLineWidth (float width); // Set the line drawing width
535 float rlGetLineWidth (); // Get the line drawing width
536 void rlEnableSmoothLines (); // Enable line aliasing
537 void rlDisableSmoothLines (); // Disable line aliasing
538 void rlEnableStereoRender (); // Enable stereo rendering
539 void rlDisableStereoRender (); // Disable stereo rendering
540 bool rlIsStereoRenderEnabled (); // Check if stereo render is enabled
541 
542 void rlClearColor (ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color
543 void rlClearScreenBuffers (); // Clear used screen buffers (color and depth)
544 void rlCheckErrors (); // Check and log OpenGL error codes
545 void rlSetBlendMode (int mode); // Set blending mode
546 void rlSetBlendFactors (int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
547 
548 //------------------------------------------------------------------------------------
549 // Functions Declaration - rlgl functionality
550 //------------------------------------------------------------------------------------
551 // rlgl initialization functions
552 void rlglInit (int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
553 void rlglClose (); // De-inititialize rlgl (buffers, shaders, textures)
554 void rlLoadExtensions (void* loader); // Load OpenGL extensions (loader function required)
555 int rlGetVersion (); // Get current OpenGL version
556 void rlSetFramebufferWidth (int width); // Set current framebuffer width
557 int rlGetFramebufferWidth (); // Get default framebuffer width
558 void rlSetFramebufferHeight (int height); // Set current framebuffer height
559 int rlGetFramebufferHeight (); // Get default framebuffer height
560 
561 uint rlGetTextureIdDefault (); // Get default texture id
562 uint rlGetShaderIdDefault (); // Get default shader id
563 int* rlGetShaderLocsDefault (); // Get default shader locations
564 
565 // Render batch management
566 // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
567 // but this render batch API is exposed in case of custom batches are required
568 rlRenderBatch rlLoadRenderBatch (int numBuffers, int bufferElements); // Load a render batch system
569 void rlUnloadRenderBatch (rlRenderBatch batch); // Unload render batch system
570 void rlDrawRenderBatch (rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset)
571 void rlSetRenderBatchActive (rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)
572 void rlDrawRenderBatchActive (); // Update and draw internal render batch
573 bool rlCheckRenderBatchLimit (int vCount); // Check internal buffer overflow for a given number of vertex
574 void rlSetTexture (uint id); // Set current texture for render batch and check buffers limits
575 
576 //------------------------------------------------------------------------------------------------------------------------
577 
578 // Vertex buffers management
579 uint rlLoadVertexArray (); // Load vertex array (vao) if supported
580 uint rlLoadVertexBuffer (const(void)* buffer, int size, bool dynamic); // Load a vertex buffer attribute
581 uint rlLoadVertexBufferElement (const(void)* buffer, int size, bool dynamic); // Load a new attributes element buffer
582 void rlUpdateVertexBuffer (uint bufferId, const(void)* data, int dataSize, int offset); // Update GPU buffer with new data
583 void rlUpdateVertexBufferElements (uint id, const(void)* data, int dataSize, int offset); // Update vertex buffer elements with new data
584 void rlUnloadVertexArray (uint vaoId);
585 void rlUnloadVertexBuffer (uint vboId);
586 void rlSetVertexAttribute (uint index, int compSize, int type, bool normalized, int stride, const(void)* pointer);
587 void rlSetVertexAttributeDivisor (uint index, int divisor);
588 void rlSetVertexAttributeDefault (int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value
589 void rlDrawVertexArray (int offset, int count);
590 void rlDrawVertexArrayElements (int offset, int count, const(void)* buffer);
591 void rlDrawVertexArrayInstanced (int offset, int count, int instances);
592 void rlDrawVertexArrayElementsInstanced (int offset, int count, const(void)* buffer, int instances);
593 
594 // Textures management
595 uint rlLoadTexture (const(void)* data, int width, int height, int format, int mipmapCount); // Load texture in GPU
596 uint rlLoadTextureDepth (int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
597 uint rlLoadTextureCubemap (const(void)* data, int size, int format); // Load texture cubemap
598 void rlUpdateTexture (uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data
599 void rlGetGlTextureFormats (int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats
600 const(char)* rlGetPixelFormatName (uint format); // Get name string for pixel format
601 void rlUnloadTexture (uint id); // Unload texture from GPU memory
602 void rlGenTextureMipmaps (uint id, int width, int height, int format, int* mipmaps); // Generate mipmap data for selected texture
603 void* rlReadTexturePixels (uint id, int width, int height, int format); // Read texture pixel data
604 ubyte* rlReadScreenPixels (int width, int height); // Read screen pixel data (color buffer)
605 
606 // Framebuffer management (fbo)
607 uint rlLoadFramebuffer (int width, int height); // Load an empty framebuffer
608 void rlFramebufferAttach (uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
609 bool rlFramebufferComplete (uint id); // Verify framebuffer is complete
610 void rlUnloadFramebuffer (uint id); // Delete framebuffer from GPU
611 
612 // Shaders management
613 uint rlLoadShaderCode (const(char)* vsCode, const(char)* fsCode); // Load shader from code strings
614 uint rlCompileShader (const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
615 uint rlLoadShaderProgram (uint vShaderId, uint fShaderId); // Load custom shader program
616 void rlUnloadShaderProgram (uint id); // Unload shader program
617 int rlGetLocationUniform (uint shaderId, const(char)* uniformName); // Get shader location uniform
618 int rlGetLocationAttrib (uint shaderId, const(char)* attribName); // Get shader location attribute
619 void rlSetUniform (int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform
620 void rlSetUniformMatrix (int locIndex, Matrix mat); // Set shader value matrix
621 void rlSetUniformSampler (int locIndex, uint textureId); // Set shader value sampler
622 void rlSetShader (uint id, int* locs); // Set shader currently active (id and locations)
623 
624 // Compute shader management
625 uint rlLoadComputeShaderProgram (uint shaderId); // Load compute shader program
626 void rlComputeShaderDispatch (uint groupX, uint groupY, uint groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
627 
628 // Shader buffer storage object management (ssbo)
629 uint rlLoadShaderBuffer (ulong size, const(void)* data, int usageHint); // Load shader storage buffer object (SSBO)
630 void rlUnloadShaderBuffer (uint ssboId); // Unload shader storage buffer object (SSBO)
631 void rlUpdateShaderBufferElements (uint id, const(void)* data, ulong dataSize, ulong offset); // Update SSBO buffer data
632 ulong rlGetShaderBufferSize (uint id); // Get SSBO buffer size
633 void rlReadShaderBufferElements (uint id, void* dest, ulong count, ulong offset); // Bind SSBO buffer
634 void rlBindShaderBuffer (uint id, uint index); // Copy SSBO buffer data
635 
636 // Buffer management
637 void rlCopyBuffersElements (uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); // Copy SSBO buffer data
638 void rlBindImageTexture (uint id, uint index, uint format, int readonly); // Bind image texture
639 
640 // Matrix state management
641 Matrix rlGetMatrixModelview (); // Get internal modelview matrix
642 Matrix rlGetMatrixProjection (); // Get internal projection matrix
643 Matrix rlGetMatrixTransform (); // Get internal accumulated transform matrix
644 Matrix rlGetMatrixProjectionStereo (int eye); // Get internal projection matrix for stereo render (selected eye)
645 Matrix rlGetMatrixViewOffsetStereo (int eye); // Get internal view offset matrix for stereo render (selected eye)
646 void rlSetMatrixProjection (Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
647 void rlSetMatrixModelview (Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
648 void rlSetMatrixProjectionStereo (Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
649 void rlSetMatrixViewOffsetStereo (Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
650 
651 // Quick and dirty cube/quad buffers load->draw->unload
652 void rlLoadDrawCube (); // Load and draw a cube
653 void rlLoadDrawQuad (); // Load and draw a quad
654 
655 // RLGL_H
656 
657 /***********************************************************************************
658 *
659 *   RLGL IMPLEMENTATION
660 *
661 ************************************************************************************/
662 
663 // OpenGL 1.1 library for OSX
664 // OpenGL extensions library
665 
666 // APIENTRY for OpenGL function pointer declarations is required
667 
668 // WINGDIAPI definition. Some Windows OpenGL headers need it
669 
670 // OpenGL 1.1 library
671 
672 // OpenGL 3 library for OSX
673 // OpenGL 3 extensions library for OSX
674 
675 // GLAD extensions loading library, includes OpenGL headers
676 
677 //#include <EGL/egl.h>              // EGL library -> not required, platform layer
678 // OpenGL ES 2.0 library
679 // OpenGL ES 2.0 extensions library
680 
681 // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
682 // provided headers (despite being defined in official Khronos GLES2 headers)
683 
684 // Required for: malloc(), free()
685 // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
686 // Required for: sqrtf(), sinf(), cosf(), floor(), log()
687 
688 //----------------------------------------------------------------------------------
689 // Defines and Macros
690 //----------------------------------------------------------------------------------
691 
692 // Default shader vertex attribute names to set location points
693 
694 // Binded by default to shader location: 0
695 
696 // Binded by default to shader location: 1
697 
698 // Binded by default to shader location: 2
699 
700 // Binded by default to shader location: 3
701 
702 // Binded by default to shader location: 4
703 
704 // Binded by default to shader location: 5
705 
706 // model-view-projection matrix
707 
708 // view matrix
709 
710 // projection matrix
711 
712 // model matrix
713 
714 // normal matrix (transpose(inverse(matModelView))
715 
716 // color diffuse (base tint color, multiplied by texture color)
717 
718 // texture0 (texture slot active 0)
719 
720 // texture1 (texture slot active 1)
721 
722 // texture2 (texture slot active 2)
723 
724 //----------------------------------------------------------------------------------
725 // Types and Structures Definition
726 //----------------------------------------------------------------------------------
727 
728 // Current render batch
729 // Default internal render batch
730 
731 // Current active render batch vertex counter (generic, used for all batches)
732 // Current active texture coordinate (added on glVertex*())
733 // Current active normal (added on glVertex*())
734 // Current active color (added on glVertex*())
735 
736 // Current matrix mode
737 // Current matrix pointer
738 // Default modelview matrix
739 // Default projection matrix
740 // Transform matrix to be used with rlTranslate, rlRotate, rlScale
741 // Require transform matrix application to current draw-call vertex (if required)
742 // Matrix stack for push/pop
743 // Matrix stack counter
744 
745 // Default texture used on shapes/poly drawing (required by shader)
746 // Active texture ids to be enabled on batch drawing (0 active by default)
747 // Default vertex shader id (used by default shader program)
748 // Default fragment shader id (used by default shader program)
749 // Default shader program id, supports vertex color and diffuse texture
750 // Default shader locations pointer to be used on rendering
751 // Current shader id to be used on rendering (by default, defaultShaderId)
752 // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)
753 
754 // Stereo rendering flag
755 // VR stereo rendering eyes projection matrices
756 // VR stereo rendering eyes view offset matrices
757 
758 // Blending mode active
759 // Blending source factor
760 // Blending destination factor
761 // Blending equation
762 
763 // Current framebuffer width
764 // Current framebuffer height
765 
766 // Renderer state
767 
768 // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
769 // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
770 // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
771 // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
772 // float textures support (32 bit per channel) (GL_OES_texture_float)
773 // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
774 // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
775 // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
776 // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
777 // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
778 // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
779 // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
780 // Compute shaders support (GL_ARB_compute_shader)
781 // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)
782 
783 // Maximum anisotropy level supported (minimum is 2.0f)
784 // Maximum bits for depth component
785 
786 // Extensions supported flags
787 
788 // OpenGL extension functions loader signature (same as GLADloadproc)
789 
790 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
791 
792 //----------------------------------------------------------------------------------
793 // Global Variables Definition
794 //----------------------------------------------------------------------------------
795 
796 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
797 
798 // NOTE: VAO functionality is exposed through extensions (OES)
799 
800 // NOTE: Instancing functionality could also be available through extension
801 
802 //----------------------------------------------------------------------------------
803 // Module specific Functions Declaration
804 //----------------------------------------------------------------------------------
805 
806 // Load default shader
807 // Unload default shader
808 
809 // Get compressed format official GL identifier name
810 // RLGL_SHOW_GL_DETAILS_INFO
811 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
812 
813 // Generate mipmaps data on CPU side
814 // Generate next mipmap level on CPU side
815 
816 // Get pixel data size in bytes (image or texture)
817 // Auxiliar matrix math functions
818 // Get identity matrix
819 // Multiply two matrices
820 
821 //----------------------------------------------------------------------------------
822 // Module Functions Definition - Matrix operations
823 //----------------------------------------------------------------------------------
824 
825 // Fallback to OpenGL 1.1 function calls
826 //---------------------------------------
827 
828 // Choose the current matrix to be transformed
829 
830 //else if (mode == RL_TEXTURE) // Not supported
831 
832 // Push the current matrix into RLGL.State.stack
833 
834 // Pop lattest inserted matrix from RLGL.State.stack
835 
836 // Reset current matrix to identity matrix
837 
838 // Multiply the current matrix by a translation matrix
839 
840 // NOTE: We transpose matrix with multiplication order
841 
842 // Multiply the current matrix by a rotation matrix
843 // NOTE: The provided angle must be in degrees
844 
845 // Axis vector (x, y, z) normalization
846 
847 // Rotation matrix generation
848 
849 // NOTE: We transpose matrix with multiplication order
850 
851 // Multiply the current matrix by a scaling matrix
852 
853 // NOTE: We transpose matrix with multiplication order
854 
855 // Multiply the current matrix by another matrix
856 
857 // Matrix creation from array
858 
859 // Multiply the current matrix by a perspective matrix generated by parameters
860 
861 // Multiply the current matrix by an orthographic matrix generated by parameters
862 
863 // NOTE: If left-right and top-botton values are equal it could create a division by zero,
864 // response to it is platform/compiler dependant
865 
866 // Set the viewport area (transformation from normalized device coordinates to window coordinates)
867 // NOTE: We store current viewport dimensions
868 
869 //----------------------------------------------------------------------------------
870 // Module Functions Definition - Vertex level operations
871 //----------------------------------------------------------------------------------
872 
873 // Fallback to OpenGL 1.1 function calls
874 //---------------------------------------
875 
876 // Initialize drawing mode (how to organize vertex)
877 
878 // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
879 // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
880 
881 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
882 // that way, following QUADS drawing will keep aligned with index processing
883 // It implies adding some extra alignment vertex at the end of the draw,
884 // those vertex are not processed but they are considered as an additional offset
885 // for the next set of vertex to be drawn
886 
887 // Finish vertex providing
888 
889 // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
890 // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
891 // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
892 
893 // Verify internal buffers limits
894 // NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
895 
896 // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
897 // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
898 // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
899 
900 // Define one vertex (position)
901 // NOTE: Vertex position data is the basic information required for drawing
902 
903 // Transform provided vector if required
904 
905 // Verify that current vertex buffer elements limit has not been reached
906 
907 // Add vertices
908 
909 // Add current texcoord
910 
911 // TODO: Add current normal
912 // By default rlVertexBuffer type does not store normals
913 
914 // Add current color
915 
916 // Define one vertex (position)
917 
918 // Define one vertex (position)
919 
920 // Define one vertex (texture coordinate)
921 // NOTE: Texture coordinates are limited to QUADS only
922 
923 // Define one vertex (normal)
924 // NOTE: Normals limited to TRIANGLES only?
925 
926 // Define one vertex (color)
927 
928 // Define one vertex (color)
929 
930 // Define one vertex (color)
931 
932 //--------------------------------------------------------------------------------------
933 // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
934 //--------------------------------------------------------------------------------------
935 
936 // Set current texture to use
937 
938 // NOTE: If quads batch limit is reached, we force a draw call and next batch starts
939 
940 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
941 // that way, following QUADS drawing will keep aligned with index processing
942 // It implies adding some extra alignment vertex at the end of the draw,
943 // those vertex are not processed but they are considered as an additional offset
944 // for the next set of vertex to be drawn
945 
946 // Select and active a texture slot
947 
948 // Enable texture
949 
950 // Disable texture
951 
952 // Enable texture cubemap
953 
954 // Disable texture cubemap
955 
956 // Set texture parameters (wrap mode/filter mode)
957 
958 // Reset anisotropy filter, in case it was set
959 
960 // Enable shader program
961 
962 // Disable shader program
963 
964 // Enable rendering to texture (fbo)
965 
966 // Disable rendering to texture
967 
968 // Activate multiple draw color buffers
969 // NOTE: One color buffer is always active by default
970 
971 // NOTE: Maximum number of draw buffers supported is implementation dependant,
972 // it can be queried with glGet*() but it must be at least 8
973 //GLint maxDrawBuffers = 0;
974 //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
975 
976 //----------------------------------------------------------------------------------
977 // General render state configuration
978 //----------------------------------------------------------------------------------
979 
980 // Enable color blending
981 
982 // Disable color blending
983 
984 // Enable depth test
985 
986 // Disable depth test
987 
988 // Enable depth write
989 
990 // Disable depth write
991 
992 // Enable backface culling
993 
994 // Disable backface culling
995 
996 // Enable scissor test
997 
998 // Disable scissor test
999 
1000 // Scissor test
1001 
1002 // Enable wire mode
1003 
1004 // NOTE: glPolygonMode() not available on OpenGL ES
1005 
1006 // Disable wire mode
1007 
1008 // NOTE: glPolygonMode() not available on OpenGL ES
1009 
1010 // Set the line drawing width
1011 
1012 // Get the line drawing width
1013 
1014 // Enable line aliasing
1015 
1016 // Disable line aliasing
1017 
1018 // Enable stereo rendering
1019 
1020 // Disable stereo rendering
1021 
1022 // Check if stereo render is enabled
1023 
1024 // Clear color buffer with color
1025 
1026 // Color values clamp to 0.0f(0) and 1.0f(255)
1027 
1028 // Clear used screen buffers (color and depth)
1029 
1030 // Clear used buffers: Color and Depth (Depth is used for 3D)
1031 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);     // Stencil buffer not used...
1032 
1033 // Check and log OpenGL error codes
1034 
1035 // Set blend mode
1036 
1037 // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
1038 
1039 // Set blending mode factor and equation
1040 
1041 //----------------------------------------------------------------------------------
1042 // Module Functions Definition - OpenGL Debug
1043 //----------------------------------------------------------------------------------
1044 
1045 // Ignore non-significant error/warning codes (NVidia drivers)
1046 // NOTE: Here there are the details with a sample output:
1047 // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
1048 // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
1049 //             will use VIDEO memory as the source for buffer object operations. (severity: low)
1050 // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)
1051 // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have
1052 //             a defined base level and cannot be used for texture mapping. (severity: low)
1053 
1054 //----------------------------------------------------------------------------------
1055 // Module Functions Definition - rlgl functionality
1056 //----------------------------------------------------------------------------------
1057 
1058 // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
1059 
1060 // Enable OpenGL debug context if required
1061 
1062 // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message
1063 
1064 // Debug context options:
1065 //  - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
1066 //  - 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
1067 
1068 // Init default white texture
1069 // 1 pixel RGBA (4 bytes)
1070 
1071 // Init default Shader (customized for GL 3.3 and ES2)
1072 // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs
1073 
1074 // Init default vertex arrays buffers
1075 
1076 // Init stack matrices (emulating OpenGL 1.1)
1077 
1078 // Init internal matrices
1079 
1080 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1081 
1082 // Initialize OpenGL default states
1083 //----------------------------------------------------------
1084 // Init state: Depth test
1085 // Type of depth testing to apply
1086 // Disable depth testing for 2D (only used for 3D)
1087 
1088 // Init state: Blending mode
1089 // Color blending function (how colors are mixed)
1090 // Enable color blending (required to work with transparencies)
1091 
1092 // Init state: Culling
1093 // NOTE: All shapes/models triangles are drawn CCW
1094 // Cull the back face (default)
1095 // Front face are defined counter clockwise (default)
1096 // Enable backface culling
1097 
1098 // Init state: Cubemap seamless
1099 
1100 // Seamless cubemaps (not supported on OpenGL ES 2.0)
1101 
1102 // Init state: Color hints (deprecated in OpenGL 3.0+)
1103 // Improve quality of color and texture coordinate interpolation
1104 // Smooth shading between vertex (vertex colors interpolation)
1105 
1106 // Store screen size into global variables
1107 
1108 //----------------------------------------------------------
1109 
1110 // Init state: Color/Depth buffers clear
1111 // Set clear color (black)
1112 // Set clear depth value (default)
1113 // Clear color and depth buffers (depth buffer required for 3D)
1114 
1115 // Vertex Buffer Object deinitialization (memory free)
1116 
1117 // Unload default shader
1118 
1119 // Unload default texture
1120 
1121 // Load OpenGL extensions
1122 // NOTE: External loader function must be provided
1123 
1124 // Also defined for GRAPHICS_API_OPENGL_21
1125 // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
1126 
1127 // Get number of supported extensions
1128 
1129 // Get supported extensions list
1130 // WARNING: glGetStringi() not available on OpenGL 2.1
1131 
1132 // Register supported extensions flags
1133 // OpenGL 3.3 extensions supported by default (core)
1134 
1135 // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
1136 // Texture compression: DXT
1137 // Texture compression: ETC2/EAC
1138 
1139 // GRAPHICS_API_OPENGL_33
1140 
1141 // Get supported extensions list
1142 
1143 // Allocate 512 strings pointers (2 KB)
1144 // One big const string
1145 
1146 // NOTE: We have to duplicate string because glGetString() returns a const string
1147 // Get extensions string size in bytes
1148 
1149 // Check required extensions
1150 
1151 // Check VAO support
1152 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
1153 
1154 // The extension is supported by our hardware and driver, try to get related functions pointers
1155 // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
1156 
1157 //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES");     // NOTE: Fails in WebGL, omitted
1158 
1159 // Check instanced rendering support
1160 // Web ANGLE
1161 
1162 // Standard EXT
1163 
1164 // Check NPOT textures support
1165 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
1166 
1167 // Check texture float support
1168 
1169 // Check depth texture support
1170 
1171 // Check texture compression support: DXT
1172 
1173 // Check texture compression support: ETC1
1174 
1175 // Check texture compression support: ETC2/EAC
1176 
1177 // Check texture compression support: PVR
1178 
1179 // Check texture compression support: ASTC
1180 
1181 // Check anisotropic texture filter support
1182 
1183 // Check clamp mirror wrap mode support
1184 
1185 // Free extensions pointers
1186 
1187 // Duplicated string must be deallocated
1188 // GRAPHICS_API_OPENGL_ES2
1189 
1190 // Check OpenGL information and capabilities
1191 //------------------------------------------------------------------------------
1192 // Show current OpenGL and GLSL version
1193 
1194 // NOTE: Anisotropy levels capability is an extension
1195 
1196 // Show some OpenGL GPU capabilities
1197 
1198 // GRAPHICS_API_OPENGL_43
1199 // RLGL_SHOW_GL_DETAILS_INFO
1200 
1201 // Show some basic info about GL supported features
1202 
1203 // RLGL_SHOW_GL_DETAILS_INFO
1204 
1205 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1206 
1207 // Get current OpenGL version
1208 
1209 // NOTE: Force OpenGL 3.3 on OSX
1210 
1211 // Set current framebuffer width
1212 
1213 // Set current framebuffer height
1214 
1215 // Get default framebuffer width
1216 
1217 // Get default framebuffer height
1218 
1219 // Get default internal texture (white texture)
1220 // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
1221 
1222 // Get default shader id
1223 
1224 // Get default shader locs
1225 
1226 // Render batch management
1227 //------------------------------------------------------------------------------------------------
1228 // Load render batch
1229 
1230 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
1231 //--------------------------------------------------------------------------------------------
1232 
1233 // 3 float by vertex, 4 vertex by quad
1234 // 2 float by texcoord, 4 texcoord by quad
1235 // 4 float by color, 4 colors by quad
1236 
1237 // 6 int by quad (indices)
1238 
1239 // 6 int by quad (indices)
1240 
1241 // Indices can be initialized right now
1242 
1243 //--------------------------------------------------------------------------------------------
1244 
1245 // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
1246 //--------------------------------------------------------------------------------------------
1247 
1248 // Initialize Quads VAO
1249 
1250 // Quads - Vertex buffers binding and attributes enable
1251 // Vertex position buffer (shader-location = 0)
1252 
1253 // Vertex texcoord buffer (shader-location = 1)
1254 
1255 // Vertex color buffer (shader-location = 3)
1256 
1257 // Fill index buffer
1258 
1259 // Unbind the current VAO
1260 
1261 //--------------------------------------------------------------------------------------------
1262 
1263 // Init draw calls tracking system
1264 //--------------------------------------------------------------------------------------------
1265 
1266 //batch.draws[i].vaoId = 0;
1267 //batch.draws[i].shaderId = 0;
1268 
1269 //batch.draws[i].RLGL.State.projection = rlMatrixIdentity();
1270 //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();
1271 
1272 // Record buffer count
1273 // Reset draws counter
1274 // Reset depth value
1275 //--------------------------------------------------------------------------------------------
1276 
1277 // Unload default internal buffers vertex data from CPU and GPU
1278 
1279 // Unbind everything
1280 
1281 // Unload all vertex buffers data
1282 
1283 // Unbind VAO attribs data
1284 
1285 // Delete VBOs from GPU (VRAM)
1286 
1287 // Delete VAOs from GPU (VRAM)
1288 
1289 // Free vertex arrays memory from CPU (RAM)
1290 
1291 // Unload arrays
1292 
1293 // Draw render batch
1294 // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
1295 
1296 // Update batch vertex buffers
1297 //------------------------------------------------------------------------------------------------------------
1298 // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
1299 // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
1300 
1301 // Activate elements VAO
1302 
1303 // Vertex positions buffer
1304 
1305 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW);  // Update all buffer
1306 
1307 // Texture coordinates buffer
1308 
1309 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
1310 
1311 // Colors buffer
1312 
1313 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW);    // Update all buffer
1314 
1315 // NOTE: glMapBuffer() causes sync issue.
1316 // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
1317 // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
1318 // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
1319 // allocated pointer immediately even if GPU is still working with the previous data.
1320 
1321 // Another option: map the buffer object into client's memory
1322 // Probably this code could be moved somewhere else...
1323 // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
1324 // if (batch->vertexBuffer[batch->currentBuffer].vertices)
1325 // {
1326 // Update vertex data
1327 // }
1328 // glUnmapBuffer(GL_ARRAY_BUFFER);
1329 
1330 // Unbind the current VAO
1331 
1332 //------------------------------------------------------------------------------------------------------------
1333 
1334 // Draw batch vertex buffers (considering VR stereo if required)
1335 //------------------------------------------------------------------------------------------------------------
1336 
1337 // Setup current eye viewport (half screen width)
1338 
1339 // Set current eye view offset to modelview matrix
1340 
1341 // Set current eye projection matrix
1342 
1343 // Draw buffers
1344 
1345 // Set current shader and upload current MVP matrix
1346 
1347 // Create modelview-projection matrix and upload to shader
1348 
1349 // Bind vertex attrib: position (shader-location = 0)
1350 
1351 // Bind vertex attrib: texcoord (shader-location = 1)
1352 
1353 // Bind vertex attrib: color (shader-location = 3)
1354 
1355 // Setup some default shader values
1356 
1357 // Active default sampler2D: texture0
1358 
1359 // Activate additional sampler textures
1360 // Those additional textures will be common for all draw calls of the batch
1361 
1362 // Activate default sampler2D texture0 (one texture is always active for default batch shader)
1363 // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
1364 
1365 // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
1366 
1367 // We need to define the number of indices to be processed: elementCount*6
1368 // NOTE: The final parameter tells the GPU the offset in bytes from the
1369 // start of the index buffer to the location of the first index to process
1370 
1371 // Unbind textures
1372 
1373 // Unbind VAO
1374 
1375 // Unbind shader program
1376 
1377 // Restore viewport to default measures
1378 
1379 //------------------------------------------------------------------------------------------------------------
1380 
1381 // Reset batch buffers
1382 //------------------------------------------------------------------------------------------------------------
1383 // Reset vertex counter for next frame
1384 
1385 // Reset depth for next draw
1386 
1387 // Restore projection/modelview matrices
1388 
1389 // Reset RLGL.currentBatch->draws array
1390 
1391 // Reset active texture units for next batch
1392 
1393 // Reset draws counter to one draw for the batch
1394 
1395 //------------------------------------------------------------------------------------------------------------
1396 
1397 // Change to next buffer in the list (in case of multi-buffering)
1398 
1399 // Set the active render batch for rlgl
1400 
1401 // Update and draw internal render batch
1402 
1403 // NOTE: Stereo rendering is checked inside
1404 
1405 // Check internal buffer overflow for a given number of vertex
1406 // and force a rlRenderBatch draw call if required
1407 
1408 // NOTE: Stereo rendering is checked inside
1409 
1410 // Restore state of last batch so we can continue adding vertices
1411 
1412 // Textures data management
1413 //-----------------------------------------------------------------------------------------
1414 // Convert image data to OpenGL texture (returns OpenGL valid Id)
1415 
1416 // Free any old binding
1417 
1418 // Check texture format support by OpenGL 1.1 (compressed textures not supported)
1419 
1420 // GRAPHICS_API_OPENGL_11
1421 
1422 // Generate texture id
1423 
1424 // Mipmap data offset
1425 
1426 // Load the different mipmap levels
1427 
1428 // Security check for NPOT textures
1429 
1430 // Texture parameters configuration
1431 // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
1432 
1433 // 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
1434 
1435 // Set texture to repeat on x-axis
1436 // Set texture to repeat on y-axis
1437 
1438 // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
1439 // Set texture to clamp on x-axis
1440 // Set texture to clamp on y-axis
1441 
1442 // Set texture to repeat on x-axis
1443 // Set texture to repeat on y-axis
1444 
1445 // Magnification and minification filters
1446 // Alternative: GL_LINEAR
1447 // Alternative: GL_LINEAR
1448 
1449 // Activate Trilinear filtering if mipmaps are available
1450 
1451 // At this point we have the texture loaded in GPU and texture parameters configured
1452 
1453 // NOTE: If mipmaps were not in data, they are not generated automatically
1454 
1455 // Unbind current texture
1456 
1457 // Load depth texture/renderbuffer (to be attached to fbo)
1458 // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
1459 
1460 // In case depth textures not supported, we force renderbuffer usage
1461 
1462 // NOTE: We let the implementation to choose the best bit-depth
1463 // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
1464 
1465 // Create the renderbuffer that will serve as the depth attachment for the framebuffer
1466 // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
1467 
1468 // Load texture cubemap
1469 // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
1470 // expected the following convention: +X, -X, +Y, -Y, +Z, -Z
1471 
1472 // Load cubemap faces
1473 
1474 // 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)
1475 
1476 // Set cubemap texture sampling parameters
1477 
1478 // Flag not supported on OpenGL ES 2.0
1479 
1480 // Update already loaded texture in GPU with new data
1481 // NOTE: We don't know safely if internal texture format is the expected one...
1482 
1483 // Get OpenGL internal formats and data type from raylib PixelFormat
1484 
1485 // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
1486 
1487 // NOTE: Requires extension OES_texture_float
1488 // NOTE: Requires extension OES_texture_float
1489 // NOTE: Requires extension OES_texture_float
1490 
1491 // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
1492 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1493 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1494 // NOTE: Requires PowerVR GPU
1495 // NOTE: Requires PowerVR GPU
1496 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1497 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1498 
1499 // Unload texture from GPU memory
1500 
1501 // Generate mipmap data for selected texture
1502 
1503 // Check if texture is power-of-two (POT)
1504 
1505 // WARNING: Manual mipmap generation only works for RGBA 32bit textures!
1506 
1507 // Retrieve texture data from VRAM
1508 
1509 // NOTE: Texture data size is reallocated to fit mipmaps data
1510 // NOTE: CPU mipmap generation only supports RGBA 32bit data
1511 
1512 // Load the mipmaps
1513 
1514 // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
1515 
1516 //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);   // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
1517 // Generate mipmaps automatically
1518 
1519 // Read texture pixel data
1520 
1521 // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)
1522 // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
1523 //int width, height, format;
1524 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
1525 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
1526 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
1527 
1528 // 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.
1529 // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
1530 // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
1531 // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
1532 
1533 // glGetTexImage() is not available on OpenGL ES 2.0
1534 // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
1535 // Two possible Options:
1536 // 1 - Bind texture to color fbo attachment and glReadPixels()
1537 // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
1538 // We are using Option 1, just need to care for texture format on retrieval
1539 // NOTE: This behaviour could be conditioned by graphic driver...
1540 
1541 // Attach our texture to FBO
1542 
1543 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
1544 
1545 // Clean up temporal fbo
1546 
1547 // Read screen pixel data (color buffer)
1548 
1549 // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
1550 // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
1551 
1552 // Flip image vertically!
1553 
1554 // Flip line
1555 
1556 // Set alpha component value to 255 (no trasparent image retrieval)
1557 // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
1558 
1559 // NOTE: image data should be freed
1560 
1561 // Framebuffer management (fbo)
1562 //-----------------------------------------------------------------------------------------
1563 // Load a framebuffer to be used for rendering
1564 // NOTE: No textures attached
1565 
1566 // Create the framebuffer object
1567 // Unbind any framebuffer
1568 
1569 // Attach color buffer texture to an fbo (unloads previous attachment)
1570 // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
1571 
1572 // Verify render texture is complete
1573 
1574 // Unload framebuffer from GPU memory
1575 // NOTE: All attached textures/cubemaps/renderbuffers are also deleted
1576 
1577 // Query depth attachment to automatically delete texture/renderbuffer
1578 
1579 // Bind framebuffer to query depth texture type
1580 
1581 // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
1582 // the texture image is automatically detached from the currently bound framebuffer.
1583 
1584 // Vertex data management
1585 //-----------------------------------------------------------------------------------------
1586 // Load a new attributes buffer
1587 
1588 // Load a new attributes element buffer
1589 
1590 // Enable vertex buffer (VBO)
1591 
1592 // Disable vertex buffer (VBO)
1593 
1594 // Enable vertex buffer element (VBO element)
1595 
1596 // Disable vertex buffer element (VBO element)
1597 
1598 // Update vertex buffer with new data
1599 // NOTE: dataSize and offset must be provided in bytes
1600 
1601 // Update vertex buffer elements with new data
1602 // NOTE: dataSize and offset must be provided in bytes
1603 
1604 // Enable vertex array object (VAO)
1605 
1606 // Disable vertex array object (VAO)
1607 
1608 // Enable vertex attribute index
1609 
1610 // Disable vertex attribute index
1611 
1612 // Draw vertex array
1613 
1614 // Draw vertex array elements
1615 
1616 // Draw vertex array instanced
1617 
1618 // Draw vertex array elements instanced
1619 
1620 // Enable vertex state pointer
1621 
1622 //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
1623 
1624 // Disable vertex state pointer
1625 
1626 // Load vertex array object (VAO)
1627 
1628 // Set vertex attribute
1629 
1630 // Set vertex attribute divisor
1631 
1632 // Unload vertex array object (VAO)
1633 
1634 // Unload vertex buffer (VBO)
1635 
1636 //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
1637 
1638 // Shaders management
1639 //-----------------------------------------------------------------------------------------------
1640 // Load shader from code strings
1641 // NOTE: If shader string is NULL, using default vertex/fragment shaders
1642 
1643 // Compile vertex shader (if provided)
1644 
1645 // In case no vertex shader was provided or compilation failed, we use default vertex shader
1646 
1647 // Compile fragment shader (if provided)
1648 
1649 // In case no fragment shader was provided or compilation failed, we use default fragment shader
1650 
1651 // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id
1652 
1653 // One of or both shader are new, we need to compile a new shader program
1654 
1655 // We can detach and delete vertex/fragment shaders (if not default ones)
1656 // NOTE: We detach shader before deletion to make sure memory is freed
1657 
1658 // In case shader program loading failed, we assign default shader
1659 
1660 // In case shader loading fails, we return the default shader
1661 
1662 /*
1663 else
1664 {
1665     // Get available shader uniforms
1666     // NOTE: This information is useful for debug...
1667     int uniformCount = -1;
1668     glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
1669 
1670     for (int i = 0; i < uniformCount; i++)
1671     {
1672         int namelen = -1;
1673         int num = -1;
1674         char name[256] = { 0 };     // Assume no variable names longer than 256
1675         GLenum type = GL_ZERO;
1676 
1677         // Get the name of the uniforms
1678         glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
1679 
1680         name[namelen] = 0;
1681         TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
1682     }
1683 }
1684 */
1685 
1686 // Compile custom shader and return shader id
1687 
1688 //case GL_GEOMETRY_SHADER:
1689 
1690 //case GL_GEOMETRY_SHADER:
1691 
1692 // Load custom shader strings and return program id
1693 
1694 // NOTE: Default attribute shader locations must be binded before linking
1695 
1696 // NOTE: If some attrib name is no found on the shader, it locations becomes -1
1697 
1698 // NOTE: All uniform variables are intitialised to 0 when a program links
1699 
1700 // Get the size of compiled shader program (not available on OpenGL ES 2.0)
1701 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
1702 //GLint binarySize = 0;
1703 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
1704 
1705 // Unload shader program
1706 
1707 // Get shader location uniform
1708 
1709 // Get shader location attribute
1710 
1711 // Set shader value uniform
1712 
1713 // Set shader value attribute
1714 
1715 // Set shader value uniform matrix
1716 
1717 // Set shader value uniform sampler
1718 
1719 // Check if texture is already active
1720 
1721 // Register a new active texture for the internal batch system
1722 // NOTE: Default texture is always activated as GL_TEXTURE0
1723 
1724 // Activate new texture unit
1725 // Save texture id for binding on drawing
1726 
1727 // Set shader currently active (id and locations)
1728 
1729 // Load compute shader program
1730 
1731 // NOTE: All uniform variables are intitialised to 0 when a program links
1732 
1733 // Get the size of compiled shader program (not available on OpenGL ES 2.0)
1734 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
1735 //GLint binarySize = 0;
1736 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
1737 
1738 // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
1739 
1740 // Load shader storage buffer object (SSBO)
1741 
1742 // Unload shader storage buffer object (SSBO)
1743 
1744 // Update SSBO buffer data
1745 
1746 // Get SSBO buffer size
1747 
1748 // Read SSBO buffer data
1749 
1750 // Bind SSBO buffer
1751 
1752 // Copy SSBO buffer data
1753 
1754 // Bind image texture
1755 
1756 // Matrix state management
1757 //-----------------------------------------------------------------------------------------
1758 // Get internal modelview matrix
1759 
1760 // Get internal projection matrix
1761 
1762 // Get internal accumulated transform matrix
1763 
1764 // TODO: Consider possible transform matrices in the RLGL.State.stack
1765 // Is this the right order? or should we start with the first stored matrix instead of the last one?
1766 //Matrix matStackTransform = rlMatrixIdentity();
1767 //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);
1768 
1769 // Get internal projection matrix for stereo render (selected eye)
1770 
1771 // Get internal view offset matrix for stereo render (selected eye)
1772 
1773 // Set a custom modelview matrix (replaces internal modelview matrix)
1774 
1775 // Set a custom projection matrix (replaces internal projection matrix)
1776 
1777 // Set eyes projection matrices for stereo rendering
1778 
1779 // Set eyes view offsets matrices for stereo rendering
1780 
1781 // Load and draw a quad in NDC
1782 
1783 // Positions         Texcoords
1784 
1785 // Gen VAO to contain VBO
1786 
1787 // Gen and fill vertex buffer (VBO)
1788 
1789 // Bind vertex attributes (position, texcoords)
1790 
1791 // Positions
1792 
1793 // Texcoords
1794 
1795 // Draw quad
1796 
1797 // Delete buffers (VBO and VAO)
1798 
1799 // Load and draw a cube in NDC
1800 
1801 // Positions          Normals               Texcoords
1802 
1803 // Gen VAO to contain VBO
1804 
1805 // Gen and fill vertex buffer (VBO)
1806 
1807 // Bind vertex attributes (position, normals, texcoords)
1808 
1809 // Positions
1810 
1811 // Normals
1812 
1813 // Texcoords
1814 
1815 // Draw cube
1816 
1817 // Delete VBO and VAO
1818 
1819 // Get name string for pixel format
1820 
1821 // 8 bit per pixel (no alpha)
1822 // 8*2 bpp (2 channels)
1823 // 16 bpp
1824 // 24 bpp
1825 // 16 bpp (1 bit alpha)
1826 // 16 bpp (4 bit alpha)
1827 // 32 bpp
1828 // 32 bpp (1 channel - float)
1829 // 32*3 bpp (3 channels - float)
1830 // 32*4 bpp (4 channels - float)
1831 // 4 bpp (no alpha)
1832 // 4 bpp (1 bit alpha)
1833 // 8 bpp
1834 // 8 bpp
1835 // 4 bpp
1836 // 4 bpp
1837 // 8 bpp
1838 // 4 bpp
1839 // 4 bpp
1840 // 8 bpp
1841 // 2 bpp
1842 
1843 //----------------------------------------------------------------------------------
1844 // Module specific Functions Definition
1845 //----------------------------------------------------------------------------------
1846 
1847 // Load default shader (just vertex positioning and texture coloring)
1848 // NOTE: This shader program is used for internal buffers
1849 // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
1850 
1851 // NOTE: All locations must be reseted to -1 (no location)
1852 
1853 // Vertex shader directly defined, no external file required
1854 
1855 // Fragment shader directly defined, no external file required
1856 
1857 // Precision required for OpenGL ES2 (WebGL)
1858 
1859 // NOTE: Compiled vertex/fragment shaders are not deleted,
1860 // they are kept for re-use as default shaders in case some shader loading fails
1861 // Compile default vertex shader
1862 // Compile default fragment shader
1863 
1864 // Set default shader locations: attributes locations
1865 
1866 // Set default shader locations: uniform locations
1867 
1868 // Unload default shader
1869 // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
1870 
1871 // Get compressed format official GL identifier name
1872 
1873 // GL_EXT_texture_compression_s3tc
1874 
1875 // GL_3DFX_texture_compression_FXT1
1876 
1877 // GL_IMG_texture_compression_pvrtc
1878 
1879 // GL_OES_compressed_ETC1_RGB8_texture
1880 
1881 // GL_ARB_texture_compression_rgtc
1882 
1883 // GL_ARB_texture_compression_bptc
1884 
1885 // GL_ARB_ES3_compatibility
1886 
1887 // GL_KHR_texture_compression_astc_hdr
1888 
1889 // RLGL_SHOW_GL_DETAILS_INFO
1890 
1891 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1892 
1893 // Mipmaps data is generated after image data
1894 // NOTE: Only works with RGBA (4 bytes) data!
1895 
1896 // Required mipmap levels count (including base level)
1897 
1898 // Size in bytes (will include mipmaps...), RGBA only
1899 
1900 // Count mipmap levels required
1901 
1902 // Add mipmap size (in bytes)
1903 
1904 // RGBA: 4 bytes
1905 
1906 // Generate mipmaps
1907 // NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)
1908 
1909 // Size of last mipmap
1910 
1911 // Mipmap size to store after offset
1912 
1913 // Add mipmap to data
1914 
1915 // free mipmap data
1916 
1917 // Manual mipmap generation (basic scaling algorithm)
1918 
1919 // Scaling algorithm works perfectly (box-filter)
1920 
1921 // GRAPHICS_API_OPENGL_11
1922 
1923 // Get pixel data size in bytes (image or texture)
1924 // NOTE: Size depends on pixel format
1925 
1926 // Size in bytes
1927 // Bits per pixel
1928 
1929 // Total data size in bytes
1930 
1931 // Most compressed formats works on 4x4 blocks,
1932 // if texture is smaller, minimum dataSize is 8 or 16
1933 
1934 // Auxiliar math functions
1935 
1936 // Get identity matrix
1937 
1938 // Get two matrix multiplication
1939 // NOTE: When multiplying matrices... the order matters!
1940 
1941 // RLGL_IMPLEMENTATION