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