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