1 module rlgl;
2 
3 import raylib;
4 /**********************************************************************************************
5 *
6 *   rlgl v3.7 - raylib OpenGL abstraction layer
7 *
8 *   rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to
9 *   pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...).
10 *
11 *   When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
12 *   VBO buffers (and VAOs if available). It requires calling 3 functions:
13 *       rlglInit()  - Initialize internal buffers and auxiliary resources
14 *       rlglClose() - De-initialize internal buffers data and other auxiliar resources
15 *
16 *   CONFIGURATION:
17 *
18 *   #define GRAPHICS_API_OPENGL_11
19 *   #define GRAPHICS_API_OPENGL_21
20 *   #define GRAPHICS_API_OPENGL_33
21 *   #define GRAPHICS_API_OPENGL_ES2
22 *       Use selected OpenGL graphics backend, should be supported by platform
23 *       Those preprocessor defines are only used on rlgl module, if OpenGL version is
24 *       required by any other module, use rlGetVersion() to check it
25 *
26 *   #define RLGL_IMPLEMENTATION
27 *       Generates the implementation of the library into the included file.
28 *       If not defined, the library is in header only mode and can be included in other headers
29 *       or source files without problems. But only ONE file should hold the implementation.
30 *
31 *   #define RLGL_STANDALONE
32 *       Use rlgl as standalone library (no raylib dependency)
33 *
34 *   #define SUPPORT_GL_DETAILS_INFO
35 *       Show OpenGL extensions and capabilities detailed logs on init
36 *
37 *   DEPENDENCIES:
38 *       raymath     - 3D math functionality (Vector3, Matrix, Quaternion)
39 *       GLAD        - OpenGL extensions loading (OpenGL 3.3 Core only)
40 *
41 *
42 *   LICENSE: zlib/libpng
43 *
44 *   Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
45 *
46 *   This software is provided "as-is", without any express or implied warranty. In no event
47 *   will the authors be held liable for any damages arising from the use of this software.
48 *
49 *   Permission is granted to anyone to use this software for any purpose, including commercial
50 *   applications, and to alter it and redistribute it freely, subject to the following restrictions:
51 *
52 *     1. The origin of this software must not be misrepresented; you must not claim that you
53 *     wrote the original software. If you use this software in a product, an acknowledgment
54 *     in the product documentation would be appreciated but is not required.
55 *
56 *     2. Altered source versions must be plainly marked as such, and must not be misrepresented
57 *     as being the original software.
58 *
59 *     3. This notice may not be removed or altered from any source distribution.
60 *
61 **********************************************************************************************/
62 
63 extern (C) @nogc nothrow:
64 
65 // We are building or using rlgl as a static library (or Linux shared library)
66 
67 // We are building raylib as a Win32 shared library (.dll)
68 
69 // We are using raylib as a Win32 shared library (.dll)
70 
71 // Support TRACELOG macros
72 
73 // Allow custom memory allocators
74 
75 // Required for: Shader, Texture2D
76 
77 // Required for: Vector3, Matrix
78 
79 // Security check in case no GRAPHICS_API_OPENGL_* defined
80 
81 // Security check in case multiple GRAPHICS_API_OPENGL_* defined
82 
83 // OpenGL 2.1 uses most of OpenGL 3.3 Core functionality
84 // WARNING: Specific parts are checked with #if defines
85 
86 //----------------------------------------------------------------------------------
87 // Defines and Macros
88 //----------------------------------------------------------------------------------
89 // Default internal render batch limits
90 
91 // This is the maximum amount of elements (quads) per batch
92 // NOTE: Be careful with text, every letter maps to a quad
93 enum DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
94 
95 // We reduce memory sizes for embedded systems (RPI and HTML5)
96 // NOTE: On HTML5 (emscripten) this is allocated on heap,
97 // by default it's only 16MB!...just take care...
98 
99 enum DEFAULT_BATCH_BUFFERS = 1; // Default number of batch buffers (multi-buffering)
100 
101 enum DEFAULT_BATCH_DRAWCALLS = 256; // Default number of batch draw calls (by state changes: mode, texture)
102 
103 enum MAX_BATCH_ACTIVE_TEXTURES = 4; // Maximum number of additional textures that can be activated on batch drawing (SetShaderValueTexture())
104 
105 // Internal Matrix stack
106 
107 enum MAX_MATRIX_STACK_SIZE = 32; // Maximum size of Matrix stack
108 
109 // Vertex buffers id limit
110 
111 enum MAX_MESH_VERTEX_BUFFERS = 7; // Maximum vertex buffers (VBO) per mesh
112 
113 // Shader and material limits
114 
115 enum MAX_SHADER_LOCATIONS = 32; // Maximum number of shader locations supported
116 
117 enum MAX_MATERIAL_MAPS = 12; // Maximum number of shader maps supported
118 
119 // Projection matrix culling
120 
121 enum RL_CULL_DISTANCE_NEAR = 0.01; // Default near cull distance
122 
123 enum RL_CULL_DISTANCE_FAR = 1000.0; // Default far cull distance
124 
125 // Texture parameters (equivalent to OpenGL defines)
126 enum RL_TEXTURE_WRAP_S = 0x2802; // GL_TEXTURE_WRAP_S
127 enum RL_TEXTURE_WRAP_T = 0x2803; // GL_TEXTURE_WRAP_T
128 enum RL_TEXTURE_MAG_FILTER = 0x2800; // GL_TEXTURE_MAG_FILTER
129 enum RL_TEXTURE_MIN_FILTER = 0x2801; // GL_TEXTURE_MIN_FILTER
130 
131 enum RL_TEXTURE_FILTER_NEAREST = 0x2600; // GL_NEAREST
132 enum RL_TEXTURE_FILTER_LINEAR = 0x2601; // GL_LINEAR
133 enum RL_TEXTURE_FILTER_MIP_NEAREST = 0x2700; // GL_NEAREST_MIPMAP_NEAREST
134 enum RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702; // GL_NEAREST_MIPMAP_LINEAR
135 enum RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701; // GL_LINEAR_MIPMAP_NEAREST
136 enum RL_TEXTURE_FILTER_MIP_LINEAR = 0x2703; // GL_LINEAR_MIPMAP_LINEAR
137 enum RL_TEXTURE_FILTER_ANISOTROPIC = 0x3000; // Anisotropic filter (custom identifier)
138 
139 enum RL_TEXTURE_WRAP_REPEAT = 0x2901; // GL_REPEAT
140 enum RL_TEXTURE_WRAP_CLAMP = 0x812F; // GL_CLAMP_TO_EDGE
141 enum RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370; // GL_MIRRORED_REPEAT
142 enum RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742; // GL_MIRROR_CLAMP_EXT
143 
144 // Matrix modes (equivalent to OpenGL)
145 enum RL_MODELVIEW = 0x1700; // GL_MODELVIEW
146 enum RL_PROJECTION = 0x1701; // GL_PROJECTION
147 enum RL_TEXTURE = 0x1702; // GL_TEXTURE
148 
149 // Primitive assembly draw modes
150 enum RL_LINES = 0x0001; // GL_LINES
151 enum RL_TRIANGLES = 0x0004; // GL_TRIANGLES
152 enum RL_QUADS = 0x0007; // GL_QUADS
153 
154 // GL equivalent data types
155 enum RL_UNSIGNED_BYTE = 0x1401; // GL_UNSIGNED_BYTE
156 enum RL_FLOAT = 0x1406; // GL_FLOAT
157 
158 //----------------------------------------------------------------------------------
159 // Types and Structures Definition
160 //----------------------------------------------------------------------------------
161 enum GlVersion
162 {
163     OPENGL_11 = 1,
164     OPENGL_21 = 2,
165     OPENGL_33 = 3,
166     OPENGL_ES_20 = 4
167 }
168 
169 enum FramebufferAttachType
170 {
171     RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
172     RL_ATTACHMENT_COLOR_CHANNEL1 = 1,
173     RL_ATTACHMENT_COLOR_CHANNEL2 = 2,
174     RL_ATTACHMENT_COLOR_CHANNEL3 = 3,
175     RL_ATTACHMENT_COLOR_CHANNEL4 = 4,
176     RL_ATTACHMENT_COLOR_CHANNEL5 = 5,
177     RL_ATTACHMENT_COLOR_CHANNEL6 = 6,
178     RL_ATTACHMENT_COLOR_CHANNEL7 = 7,
179     RL_ATTACHMENT_DEPTH = 100,
180     RL_ATTACHMENT_STENCIL = 200
181 }
182 
183 enum FramebufferAttachTextureType
184 {
185     RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
186     RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1,
187     RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2,
188     RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3,
189     RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4,
190     RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5,
191     RL_ATTACHMENT_TEXTURE2D = 100,
192     RL_ATTACHMENT_RENDERBUFFER = 200
193 }
194 
195 // Dynamic vertex buffers (position + texcoords + colors + indices arrays)
196 struct VertexBuffer
197 {
198     int elementsCount; // Number of elements in the buffer (QUADS)
199 
200     int vCounter; // Vertex position counter to process (and draw) from full buffer
201     int tcCounter; // Vertex texcoord counter to process (and draw) from full buffer
202     int cCounter; // Vertex color counter to process (and draw) from full buffer
203 
204     float* vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
205     float* texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
206     ubyte* colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
207 
208     uint* indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
209 
210     // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
211 
212     uint vaoId; // OpenGL Vertex Array Object id
213     uint[4] vboId; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
214 }
215 
216 // Draw call type
217 // NOTE: Only texture changes register a new draw, other state-change-related elements are not
218 // used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any
219 // of those state-change happens (this is done in core module)
220 struct DrawCall
221 {
222     int mode; // Drawing mode: LINES, TRIANGLES, QUADS
223     int vertexCount; // Number of vertex of the draw
224     int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)
225     //unsigned int vaoId;       // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId
226     //unsigned int shaderId;    // Shader id to be used on the draw -> Using RLGL.currentShader.id
227     uint textureId; // Texture id to be used on the draw -> Use to create new draw call if changes
228 
229     //Matrix projection;        // Projection matrix for this draw -> Using RLGL.projection by default
230     //Matrix modelview;         // Modelview matrix for this draw -> Using RLGL.modelview by default
231 }
232 
233 // RenderBatch type
234 struct RenderBatch
235 {
236     int buffersCount; // Number of vertex buffers (multi-buffering support)
237     int currentBuffer; // Current buffer tracking in case of multi-buffering
238     VertexBuffer* vertexBuffer; // Dynamic buffer(s) for vertex data
239 
240     DrawCall* draws; // Draw calls array, depends on textureId
241     int drawsCounter; // Draw calls counter
242     float currentDepth; // Current depth value for next draw
243 }
244 
245 // Shader attribute data types
246 enum ShaderAttributeDataType
247 {
248     SHADER_ATTRIB_FLOAT = 0,
249     SHADER_ATTRIB_VEC2 = 1,
250     SHADER_ATTRIB_VEC3 = 2,
251     SHADER_ATTRIB_VEC4 = 3
252 }
253 
254 // Boolean type
255 
256 // Color type, RGBA (32bit)
257 
258 // Texture type
259 // NOTE: Data stored in GPU memory
260 
261 // OpenGL texture id
262 // Texture base width
263 // Texture base height
264 // Mipmap levels, 1 by default
265 // Data format (PixelFormat)
266 
267 // Shader type (generic)
268 
269 // Shader program id
270 // Shader locations array (MAX_SHADER_LOCATIONS)
271 
272 // TraceLog message types
273 
274 // Texture formats (support depends on OpenGL version)
275 
276 // 8 bit per pixel (no alpha)
277 
278 // 16 bpp
279 // 24 bpp
280 // 16 bpp (1 bit alpha)
281 // 16 bpp (4 bit alpha)
282 // 32 bpp
283 // 32 bpp (1 channel - float)
284 // 32*3 bpp (3 channels - float)
285 // 32*4 bpp (4 channels - float)
286 // 4 bpp (no alpha)
287 // 4 bpp (1 bit alpha)
288 // 8 bpp
289 // 8 bpp
290 // 4 bpp
291 // 4 bpp
292 // 8 bpp
293 // 4 bpp
294 // 4 bpp
295 // 8 bpp
296 // 2 bpp
297 
298 // Texture parameters: filter mode
299 // NOTE 1: Filtering considers mipmaps if available in the texture
300 // NOTE 2: Filter is accordingly set for minification and magnification
301 
302 // No filter, just pixel aproximation
303 // Linear filtering
304 // Trilinear filtering (linear with mipmaps)
305 // Anisotropic filtering 4x
306 // Anisotropic filtering 8x
307 // Anisotropic filtering 16x
308 
309 // Texture parameters: wrap mode
310 
311 // Repeats texture in tiled mode
312 // Clamps texture to edge pixel in tiled mode
313 // Mirrors and repeats the texture in tiled mode
314 // Mirrors and clamps to border the texture in tiled mode
315 
316 // Color blending modes (pre-defined)
317 
318 // Blend textures considering alpha (default)
319 // Blend textures adding colors
320 // Blend textures multiplying colors
321 // Blend textures adding colors (alternative)
322 // Blend textures subtracting colors (alternative)
323 // Belnd textures using custom src/dst factors (use SetBlendModeCustom())
324 
325 // Shader location point type
326 
327 // SHADER_LOC_MAP_DIFFUSE
328 // SHADER_LOC_MAP_SPECULAR
329 
330 // Shader uniform data types
331 
332 // Prevents name mangling of functions
333 
334 //------------------------------------------------------------------------------------
335 // Functions Declaration - Matrix operations
336 //------------------------------------------------------------------------------------
337 void rlMatrixMode(int mode); // Choose the current matrix to be transformed
338 void rlPushMatrix(); // Push the current matrix to stack
339 void rlPopMatrix(); // Pop lattest inserted matrix from stack
340 void rlLoadIdentity(); // Reset current matrix to identity matrix
341 void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
342 void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix
343 void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
344 void rlMultMatrixf(float* matf); // Multiply the current matrix by another matrix
345 void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
346 void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
347 void rlViewport(int x, int y, int width, int height); // Set the viewport area
348 
349 //------------------------------------------------------------------------------------
350 // Functions Declaration - Vertex level operations
351 //------------------------------------------------------------------------------------
352 void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
353 void rlEnd(); // Finish vertex providing
354 void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
355 void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
356 void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
357 void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
358 void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
359 void rlColor4ub(ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte
360 void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
361 void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
362 
363 //------------------------------------------------------------------------------------
364 // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
365 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
366 // some of them are direct wrappers over OpenGL calls, some others are custom
367 //------------------------------------------------------------------------------------
368 
369 // Vertex buffers state
370 bool rlEnableVertexArray(uint vaoId); // Enable vertex array (VAO, if supported)
371 void rlDisableVertexArray(); // Disable vertex array (VAO, if supported)
372 void rlEnableVertexBuffer(uint id); // Enable vertex buffer (VBO)
373 void rlDisableVertexBuffer(); // Disable vertex buffer (VBO)
374 void rlEnableVertexBufferElement(uint id); // Enable vertex buffer element (VBO element)
375 void rlDisableVertexBufferElement(); // Disable vertex buffer element (VBO element)
376 void rlEnableVertexAttribute(uint index); // Enable vertex attribute index
377 void rlDisableVertexAttribute(uint index); // Disable vertex attribute index
378 
379 // Textures state
380 void rlActiveTextureSlot(int slot); // Select and active a texture slot
381 void rlEnableTexture(uint id); // Enable texture
382 void rlDisableTexture(); // Disable texture
383 void rlEnableTextureCubemap(uint id); // Enable texture cubemap
384 void rlDisableTextureCubemap(); // Disable texture cubemap
385 void rlTextureParameters(uint id, int param, int value); // Set texture parameters (filter, wrap)
386 
387 // Shader state
388 void rlEnableShader(uint id); // Enable shader program
389 void rlDisableShader(); // Disable shader program
390 
391 // Framebuffer state
392 void rlEnableFramebuffer(uint id); // Enable render texture (fbo)
393 void rlDisableFramebuffer(); // Disable render texture (fbo), return to default framebuffer
394 
395 // General render state
396 void rlEnableDepthTest(); // Enable depth test
397 void rlDisableDepthTest(); // Disable depth test
398 void rlEnableDepthMask(); // Enable depth write
399 void rlDisableDepthMask(); // Disable depth write
400 void rlEnableBackfaceCulling(); // Enable backface culling
401 void rlDisableBackfaceCulling(); // Disable backface culling
402 void rlEnableScissorTest(); // Enable scissor test
403 void rlDisableScissorTest(); // Disable scissor test
404 void rlScissor(int x, int y, int width, int height); // Scissor test
405 void rlEnableWireMode(); // Enable wire mode
406 void rlDisableWireMode(); // Disable wire mode
407 void rlSetLineWidth(float width); // Set the line drawing width
408 float rlGetLineWidth(); // Get the line drawing width
409 void rlEnableSmoothLines(); // Enable line aliasing
410 void rlDisableSmoothLines(); // Disable line aliasing
411 void rlEnableStereoRender(); // Enable stereo rendering
412 void rlDisableStereoRender(); // Disable stereo rendering
413 bool rlIsStereoRenderEnabled(); // Check if stereo render is enabled
414 
415 void rlClearColor(ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color
416 void rlClearScreenBuffers(); // Clear used screen buffers (color and depth)
417 void rlCheckErrors(); // Check and log OpenGL error codes
418 void rlSetBlendMode(int mode); // Set blending mode
419 void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
420 
421 //------------------------------------------------------------------------------------
422 // Functions Declaration - rlgl functionality
423 //------------------------------------------------------------------------------------
424 // rlgl initialization functions
425 void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
426 void rlglClose(); // De-inititialize rlgl (buffers, shaders, textures)
427 void rlLoadExtensions(void* loader); // Load OpenGL extensions (loader function pointer required)
428 int rlGetVersion(); // Returns current OpenGL version
429 int rlGetFramebufferWidth(); // Get default framebuffer width
430 int rlGetFramebufferHeight(); // Get default framebuffer height
431 
432 Shader rlGetShaderDefault(); // Get default shader
433 Texture2D rlGetTextureDefault(); // Get default texture
434 
435 // Render batch management
436 // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
437 // but this render batch API is exposed in case of custom batches are required
438 RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
439 void rlUnloadRenderBatch(RenderBatch batch); // Unload render batch system
440 void rlDrawRenderBatch(RenderBatch* batch); // Draw render batch data (Update->Draw->Reset)
441 void rlSetRenderBatchActive(RenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)
442 void rlDrawRenderBatchActive(); // Update and draw internal render batch
443 bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
444 void rlSetTexture(uint id); // Set current texture for render batch and check buffers limits
445 
446 //------------------------------------------------------------------------------------------------------------------------
447 
448 // Vertex buffers management
449 uint rlLoadVertexArray(); // Load vertex array (vao) if supported
450 uint rlLoadVertexBuffer(void* buffer, int size, bool dynamic); // Load a vertex buffer attribute
451 uint rlLoadVertexBufferElement(void* buffer, int size, bool dynamic); // Load a new attributes element buffer
452 void rlUpdateVertexBuffer(int bufferId, void* data, int dataSize, int offset); // Update GPU buffer with new data
453 void rlUnloadVertexArray(uint vaoId);
454 void rlUnloadVertexBuffer(uint vboId);
455 void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, void* pointer);
456 void rlSetVertexAttributeDivisor(uint index, int divisor);
457 void rlSetVertexAttributeDefault(int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value
458 void rlDrawVertexArray(int offset, int count);
459 void rlDrawVertexArrayElements(int offset, int count, void* buffer);
460 void rlDrawVertexArrayInstanced(int offset, int count, int instances);
461 void rlDrawVertexArrayElementsInstanced(int offset, int count, void* buffer, int instances);
462 
463 // Textures management
464 uint rlLoadTexture(void* data, int width, int height, int format, int mipmapCount); // Load texture in GPU
465 uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
466 uint rlLoadTextureCubemap(void* data, int size, int format); // Load texture cubemap
467 void rlUpdateTexture(uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data
468 void rlGetGlTextureFormats(int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats
469 void rlUnloadTexture(uint id); // Unload texture from GPU memory
470 void rlGenerateMipmaps(Texture2D* texture); // Generate mipmap data for selected texture
471 void* rlReadTexturePixels(Texture2D texture); // Read texture pixel data
472 ubyte* rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
473 
474 // Framebuffer management (fbo)
475 uint rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
476 void rlFramebufferAttach(uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
477 bool rlFramebufferComplete(uint id); // Verify framebuffer is complete
478 void rlUnloadFramebuffer(uint id); // Delete framebuffer from GPU
479 
480 // Shaders management
481 uint rlLoadShaderCode(const(char)* vsCode, const(char)* fsCode); // Load shader from code strings
482 uint rlCompileShader(const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER)
483 uint rlLoadShaderProgram(uint vShaderId, uint fShaderId); // Load custom shader program
484 void rlUnloadShaderProgram(uint id); // Unload shader program
485 int rlGetLocationUniform(uint shaderId, const(char)* uniformName); // Get shader location uniform
486 int rlGetLocationAttrib(uint shaderId, const(char)* attribName); // Get shader location attribute
487 void rlSetUniform(int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform
488 void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
489 void rlSetUniformSampler(int locIndex, uint textureId); // Set shader value sampler
490 void rlSetShader(Shader shader); // Set shader currently active
491 
492 // Matrix state management
493 Matrix rlGetMatrixModelview(); // Get internal modelview matrix
494 Matrix rlGetMatrixProjection(); // Get internal projection matrix
495 Matrix rlGetMatrixTransform(); // Get internal accumulated transform matrix
496 Matrix rlGetMatrixProjectionStereo(int eye); // Get internal projection matrix for stereo render (selected eye)
497 Matrix rlGetMatrixViewOffsetStereo(int eye); // Get internal view offset matrix for stereo render (selected eye)
498 void rlSetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
499 void rlSetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
500 void rlSetMatrixProjectionStereo(Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
501 void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
502 
503 // Quick and dirty cube/quad buffers load->draw->unload
504 void rlLoadDrawCube(); // Load and draw a cube
505 void rlLoadDrawQuad(); // Load and draw a quad
506 
507 // RLGL_H
508 
509 /***********************************************************************************
510 *
511 *   RLGL IMPLEMENTATION
512 *
513 ************************************************************************************/
514 
515 // Check if config flags have been externally provided on compilation line
516 
517 // Defines module configuration flags
518 
519 // Required for: Vector3 and Matrix functions
520 
521 // Required for: malloc(), free()
522 // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
523 
524 // OpenGL 1.1 library for OSX
525 
526 // APIENTRY for OpenGL function pointer declarations is required
527 
528 // WINGDIAPI definition. Some Windows OpenGL headers need it
529 
530 // OpenGL 1.1 library
531 
532 // OpenGL 3 library for OSX
533 // OpenGL 3 extensions library for OSX
534 
535 // GLAD extensions loading library, includes OpenGL headers
536 
537 // GLAD extensions loading library, includes OpenGL headers
538 
539 // EGL library
540 // OpenGL ES 2.0 library
541 // OpenGL ES 2.0 extensions library
542 
543 // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
544 // provided headers (despite being defined in official Khronos GLES2 headers)
545 
546 //----------------------------------------------------------------------------------
547 // Defines and Macros
548 //----------------------------------------------------------------------------------
549 
550 // Default shader vertex attribute names to set location points
551 
552 // Binded by default to shader location: 0
553 
554 // Binded by default to shader location: 1
555 
556 // Binded by default to shader location: 2
557 
558 // Binded by default to shader location: 3
559 
560 // Binded by default to shader location: 4
561 
562 // Binded by default to shader location: 5
563 
564 //----------------------------------------------------------------------------------
565 // Types and Structures Definition
566 //----------------------------------------------------------------------------------
567 
568 // Current render batch
569 // Default internal render batch
570 
571 // Current matrix mode
572 // Current matrix pointer
573 // Default modelview matrix
574 // Default projection matrix
575 // Transform matrix to be used with rlTranslate, rlRotate, rlScale
576 // Require transform matrix application to current draw-call vertex (if required)
577 // Matrix stack for push/pop
578 // Matrix stack counter
579 
580 // Default texture used on shapes/poly drawing (required by shader)
581 // Active texture ids to be enabled on batch drawing (0 active by default)
582 // Default vertex shader id (used by default shader program)
583 // Default fragment shader Id (used by default shader program)
584 // Basic shader, support vertex color and diffuse texture
585 // Shader to be used on rendering (by default, defaultShader)
586 
587 // Stereo rendering flag
588 // VR stereo rendering eyes projection matrices
589 // VR stereo rendering eyes view offset matrices
590 
591 // Blending mode active
592 // Blending source factor
593 // Blending destination factor
594 // Blending equation
595 
596 // Default framebuffer width
597 // Default framebuffer height
598 
599 // Renderer state
600 
601 // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
602 // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
603 // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
604 // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
605 // float textures support (32 bit per channel) (GL_OES_texture_float)
606 // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
607 // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
608 // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
609 // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
610 // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
611 // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
612 // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
613 
614 // Maximum anisotropy level supported (minimum is 2.0f)
615 // Maximum bits for depth component
616 
617 // Extensions supported flags
618 
619 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
620 
621 //----------------------------------------------------------------------------------
622 // Global Variables Definition
623 //----------------------------------------------------------------------------------
624 
625 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
626 
627 // NOTE: VAO functionality is exposed through extensions (OES)
628 
629 // NOTE: Instancing functionality could also be available through extension
630 
631 //----------------------------------------------------------------------------------
632 // Module specific Functions Declaration
633 //----------------------------------------------------------------------------------
634 
635 // Load default shader (RLGL.State.defaultShader)
636 // Unload default shader (RLGL.State.defaultShader)
637 
638 // Get compressed format official GL identifier name
639 // SUPPORT_GL_DETAILS_INFO
640 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
641 
642 // Generate mipmaps data on CPU side
643 // Generate next mipmap level on CPU side
644 
645 // Get pixel data size in bytes (image or texture)
646 
647 //----------------------------------------------------------------------------------
648 // Module Functions Definition - Matrix operations
649 //----------------------------------------------------------------------------------
650 
651 // Fallback to OpenGL 1.1 function calls
652 //---------------------------------------
653 
654 // Choose the current matrix to be transformed
655 
656 //else if (mode == RL_TEXTURE) // Not supported
657 
658 // Push the current matrix into RLGL.State.stack
659 
660 // Pop lattest inserted matrix from RLGL.State.stack
661 
662 // Reset current matrix to identity matrix
663 
664 // Multiply the current matrix by a translation matrix
665 
666 // NOTE: We transpose matrix with multiplication order
667 
668 // Multiply the current matrix by a rotation matrix
669 
670 // NOTE: We transpose matrix with multiplication order
671 
672 // Multiply the current matrix by a scaling matrix
673 
674 // NOTE: We transpose matrix with multiplication order
675 
676 // Multiply the current matrix by another matrix
677 
678 // Matrix creation from array
679 
680 // Multiply the current matrix by a perspective matrix generated by parameters
681 
682 // Multiply the current matrix by an orthographic matrix generated by parameters
683 
684 // NOTE: If left-right and top-botton values are equal it could create
685 // a division by zero on MatrixOrtho(), response to it is platform/compiler dependant
686 
687 // Set the viewport area (transformation from normalized device coordinates to window coordinates)
688 
689 //----------------------------------------------------------------------------------
690 // Module Functions Definition - Vertex level operations
691 //----------------------------------------------------------------------------------
692 
693 // Fallback to OpenGL 1.1 function calls
694 //---------------------------------------
695 
696 // Initialize drawing mode (how to organize vertex)
697 
698 // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
699 // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
700 
701 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
702 // that way, following QUADS drawing will keep aligned with index processing
703 // It implies adding some extra alignment vertex at the end of the draw,
704 // those vertex are not processed but they are considered as an additional offset
705 // for the next set of vertex to be drawn
706 
707 // Finish vertex providing
708 
709 // Make sure vertexCount is the same for vertices, texcoords, colors and normals
710 // NOTE: In OpenGL 1.1, one glColor call can be made for all the subsequent glVertex calls
711 
712 // Make sure colors count match vertex count
713 
714 // Make sure texcoords count match vertex count
715 
716 // TODO: Make sure normals count match vertex count... if normals support is added in a future... :P
717 
718 // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
719 // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
720 // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
721 
722 // Verify internal buffers limits
723 // NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
724 
725 // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
726 // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
727 // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
728 
729 // Define one vertex (position)
730 // NOTE: Vertex position data is the basic information required for drawing
731 
732 // Transform provided vector if required
733 
734 // Verify that current vertex buffer elements limit has not been reached
735 
736 // Define one vertex (position)
737 
738 // Define one vertex (position)
739 
740 // Define one vertex (texture coordinate)
741 // NOTE: Texture coordinates are limited to QUADS only
742 
743 // Define one vertex (normal)
744 // NOTE: Normals limited to TRIANGLES only?
745 
746 // TODO: Normals usage...
747 
748 // Define one vertex (color)
749 
750 // Define one vertex (color)
751 
752 // Define one vertex (color)
753 
754 //--------------------------------------------------------------------------------------
755 // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
756 //--------------------------------------------------------------------------------------
757 
758 // Set current texture to use
759 
760 // NOTE: If quads batch limit is reached, we force a draw call and next batch starts
761 
762 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
763 // that way, following QUADS drawing will keep aligned with index processing
764 // It implies adding some extra alignment vertex at the end of the draw,
765 // those vertex are not processed but they are considered as an additional offset
766 // for the next set of vertex to be drawn
767 
768 // Select and active a texture slot
769 
770 // Enable texture
771 
772 // Disable texture
773 
774 // Enable texture cubemap
775 
776 // Core in OpenGL 1.4
777 
778 // Disable texture cubemap
779 
780 // Set texture parameters (wrap mode/filter mode)
781 
782 // Enable shader program
783 
784 // Disable shader program
785 
786 // Enable rendering to texture (fbo)
787 
788 // Disable rendering to texture
789 
790 // Enable depth test
791 
792 // Disable depth test
793 
794 // Enable depth write
795 
796 // Disable depth write
797 
798 // Enable backface culling
799 
800 // Disable backface culling
801 
802 // Enable scissor test
803 
804 // Disable scissor test
805 
806 // Scissor test
807 
808 // Enable wire mode
809 
810 // NOTE: glPolygonMode() not available on OpenGL ES
811 
812 // Disable wire mode
813 
814 // NOTE: glPolygonMode() not available on OpenGL ES
815 
816 // Set the line drawing width
817 
818 // Get the line drawing width
819 
820 // Enable line aliasing
821 
822 // Disable line aliasing
823 
824 // Enable stereo rendering
825 
826 // Disable stereo rendering
827 
828 // Check if stereo render is enabled
829 
830 // Clear color buffer with color
831 
832 // Color values clamp to 0.0f(0) and 1.0f(255)
833 
834 // Clear used screen buffers (color and depth)
835 
836 // Clear used buffers: Color and Depth (Depth is used for 3D)
837 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);     // Stencil buffer not used...
838 
839 // Check and log OpenGL error codes
840 
841 // Set blend mode
842 
843 // Set blending mode factor and equation
844 
845 //----------------------------------------------------------------------------------
846 // Module Functions Definition - rlgl functionality
847 //----------------------------------------------------------------------------------
848 
849 // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
850 
851 // Init default white texture
852 // 1 pixel RGBA (4 bytes)
853 
854 // Init default Shader (customized for GL 3.3 and ES2)
855 // RLGL.State.defaultShader
856 
857 // Init default vertex arrays buffers
858 
859 // Init stack matrices (emulating OpenGL 1.1)
860 
861 // Init internal matrices
862 
863 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
864 
865 // Initialize OpenGL default states
866 //----------------------------------------------------------
867 // Init state: Depth test
868 // Type of depth testing to apply
869 // Disable depth testing for 2D (only used for 3D)
870 
871 // Init state: Blending mode
872 // Color blending function (how colors are mixed)
873 // Enable color blending (required to work with transparencies)
874 
875 // Init state: Culling
876 // NOTE: All shapes/models triangles are drawn CCW
877 // Cull the back face (default)
878 // Front face are defined counter clockwise (default)
879 // Enable backface culling
880 
881 // Init state: Cubemap seamless
882 
883 // Seamless cubemaps (not supported on OpenGL ES 2.0)
884 
885 // Init state: Color hints (deprecated in OpenGL 3.0+)
886 // Improve quality of color and texture coordinate interpolation
887 // Smooth shading between vertex (vertex colors interpolation)
888 
889 // Store screen size into global variables
890 
891 //----------------------------------------------------------
892 
893 // Init state: Color/Depth buffers clear
894 // Set clear color (black)
895 // Set clear depth value (default)
896 // Clear color and depth buffers (depth buffer required for 3D)
897 
898 // Vertex Buffer Object deinitialization (memory free)
899 
900 // Unload default shader
901 
902 // Unload default texture
903 
904 // Load OpenGL extensions
905 // NOTE: External loader function could be passed as a pointer
906 
907 // Also defined for GRAPHICS_API_OPENGL_21
908 // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
909 
910 // Get number of supported extensions
911 
912 // Get supported extensions list
913 // WARNING: glGetStringi() not available on OpenGL 2.1
914 
915 // Free extensions pointers
916 
917 // Register supported extensions flags
918 // OpenGL 3.3 extensions supported by default (core)
919 
920 // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
921 // Texture compression: DXT
922 // Texture compression: ETC2/EAC
923 
924 // GRAPHICS_API_OPENGL_33
925 
926 // Get supported extensions list
927 
928 // Allocate 512 strings pointers (2 KB)
929 // One big const string
930 
931 // NOTE: We have to duplicate string because glGetString() returns a const string
932 
933 // Check required extensions
934 
935 // Check VAO support
936 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
937 
938 // The extension is supported by our hardware and driver, try to get related functions pointers
939 // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
940 
941 //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");     // NOTE: Fails in WebGL, omitted
942 
943 // Check instanced rendering support
944 // Web ANGLE
945 
946 // Standard EXT
947 
948 // Check NPOT textures support
949 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
950 
951 // Check texture float support
952 
953 // Check depth texture support
954 
955 // Check texture compression support: DXT
956 
957 // Check texture compression support: ETC1
958 
959 // Check texture compression support: ETC2/EAC
960 
961 // Check texture compression support: PVR
962 
963 // Check texture compression support: ASTC
964 
965 // Check anisotropic texture filter support
966 
967 // Check clamp mirror wrap mode support
968 
969 // Free extensions pointers
970 
971 // Duplicated string must be deallocated
972 // GRAPHICS_API_OPENGL_ES2
973 
974 // Check OpenGL information and capabilities
975 //------------------------------------------------------------------------------
976 // Show current OpenGL and GLSL version
977 
978 // NOTE: Anisotropy levels capability is an extension
979 
980 // Show some OpenGL GPU capabilities
981 
982 /*
983 // Following capabilities are only supported by OpenGL 4.3 or greater
984 glGetIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &capability);
985 TRACELOG(LOG_INFO, "    GL_MAX_VERTEX_ATTRIB_BINDINGS: %i", capability);
986 glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &capability);
987 TRACELOG(LOG_INFO, "    GL_MAX_UNIFORM_LOCATIONS: %i", capability);
988 */
989 // SUPPORT_GL_DETAILS_INFO
990 
991 // Show some basic info about GL supported features
992 
993 // SUPPORT_GL_DETAILS_INFO
994 
995 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
996 
997 // Returns current OpenGL version
998 
999 // NOTE: Force OpenGL 3.3 on OSX
1000 
1001 // Get default framebuffer width
1002 
1003 // Get default framebuffer height
1004 
1005 // Get default internal shader (simple texture + tint color)
1006 
1007 // Get default internal texture (white texture)
1008 
1009 // Render batch management
1010 //------------------------------------------------------------------------------------------------
1011 // Load render batch
1012 
1013 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
1014 //--------------------------------------------------------------------------------------------
1015 
1016 // 3 float by vertex, 4 vertex by quad
1017 // 2 float by texcoord, 4 texcoord by quad
1018 // 4 float by color, 4 colors by quad
1019 
1020 // 6 int by quad (indices)
1021 
1022 // 6 int by quad (indices)
1023 
1024 // Indices can be initialized right now
1025 
1026 //--------------------------------------------------------------------------------------------
1027 
1028 // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
1029 //--------------------------------------------------------------------------------------------
1030 
1031 // Initialize Quads VAO
1032 
1033 // Quads - Vertex buffers binding and attributes enable
1034 // Vertex position buffer (shader-location = 0)
1035 
1036 // Vertex texcoord buffer (shader-location = 1)
1037 
1038 // Vertex color buffer (shader-location = 3)
1039 
1040 // Fill index buffer
1041 
1042 // Unbind the current VAO
1043 
1044 //--------------------------------------------------------------------------------------------
1045 
1046 // Init draw calls tracking system
1047 //--------------------------------------------------------------------------------------------
1048 
1049 //batch.draws[i].vaoId = 0;
1050 //batch.draws[i].shaderId = 0;
1051 
1052 //batch.draws[i].RLGL.State.projection = MatrixIdentity();
1053 //batch.draws[i].RLGL.State.modelview = MatrixIdentity();
1054 
1055 // Record buffer count
1056 // Reset draws counter
1057 // Reset depth value
1058 //--------------------------------------------------------------------------------------------
1059 
1060 // Unload default internal buffers vertex data from CPU and GPU
1061 
1062 // Unbind everything
1063 
1064 // Unload all vertex buffers data
1065 
1066 // Delete VBOs from GPU (VRAM)
1067 
1068 // Delete VAOs from GPU (VRAM)
1069 
1070 // Free vertex arrays memory from CPU (RAM)
1071 
1072 // Unload arrays
1073 
1074 // Draw render batch
1075 // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
1076 
1077 // Update batch vertex buffers
1078 //------------------------------------------------------------------------------------------------------------
1079 // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
1080 // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
1081 
1082 // Activate elements VAO
1083 
1084 // Vertex positions buffer
1085 
1086 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW);  // Update all buffer
1087 
1088 // Texture coordinates buffer
1089 
1090 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
1091 
1092 // Colors buffer
1093 
1094 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW);    // Update all buffer
1095 
1096 // NOTE: glMapBuffer() causes sync issue.
1097 // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
1098 // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
1099 // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
1100 // allocated pointer immediately even if GPU is still working with the previous data.
1101 
1102 // Another option: map the buffer object into client's memory
1103 // Probably this code could be moved somewhere else...
1104 // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
1105 // if (batch->vertexBuffer[batch->currentBuffer].vertices)
1106 // {
1107 // Update vertex data
1108 // }
1109 // glUnmapBuffer(GL_ARRAY_BUFFER);
1110 
1111 // Unbind the current VAO
1112 
1113 //------------------------------------------------------------------------------------------------------------
1114 
1115 // Draw batch vertex buffers (considering VR stereo if required)
1116 //------------------------------------------------------------------------------------------------------------
1117 
1118 // Setup current eye viewport (half screen width)
1119 
1120 // Set current eye view offset to modelview matrix
1121 
1122 // Set current eye projection matrix
1123 
1124 // Draw buffers
1125 
1126 // Set current shader and upload current MVP matrix
1127 
1128 // Create modelview-projection matrix and upload to shader
1129 
1130 // Bind vertex attrib: position (shader-location = 0)
1131 
1132 // Bind vertex attrib: texcoord (shader-location = 1)
1133 
1134 // Bind vertex attrib: color (shader-location = 3)
1135 
1136 // Setup some default shader values
1137 
1138 // Active default sampler2D: texture0
1139 
1140 // Activate additional sampler textures
1141 // Those additional textures will be common for all draw calls of the batch
1142 
1143 // Activate default sampler2D texture0 (one texture is always active for default batch shader)
1144 // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
1145 
1146 // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
1147 
1148 // We need to define the number of indices to be processed: quadsCount*6
1149 // NOTE: The final parameter tells the GPU the offset in bytes from the
1150 // start of the index buffer to the location of the first index to process
1151 
1152 // Unbind textures
1153 
1154 // Unbind VAO
1155 
1156 // Unbind shader program
1157 
1158 //------------------------------------------------------------------------------------------------------------
1159 
1160 // Reset batch buffers
1161 //------------------------------------------------------------------------------------------------------------
1162 // Reset vertex counters for next frame
1163 
1164 // Reset depth for next draw
1165 
1166 // Restore projection/modelview matrices
1167 
1168 // Reset RLGL.currentBatch->draws array
1169 
1170 // Reset active texture units for next batch
1171 
1172 // Reset draws counter to one draw for the batch
1173 
1174 //------------------------------------------------------------------------------------------------------------
1175 
1176 // Change to next buffer in the list (in case of multi-buffering)
1177 
1178 // Set the active render batch for rlgl
1179 
1180 // Update and draw internal render batch
1181 
1182 // NOTE: Stereo rendering is checked inside
1183 
1184 // Check internal buffer overflow for a given number of vertex
1185 // and force a RenderBatch draw call if required
1186 
1187 // NOTE: Stereo rendering is checked inside
1188 
1189 // Textures data management
1190 //-----------------------------------------------------------------------------------------
1191 // Convert image data to OpenGL texture (returns OpenGL valid Id)
1192 
1193 // Free any old binding
1194 
1195 // Check texture format support by OpenGL 1.1 (compressed textures not supported)
1196 
1197 // GRAPHICS_API_OPENGL_11
1198 
1199 // Generate texture id
1200 
1201 // Mipmap data offset
1202 
1203 // Load the different mipmap levels
1204 
1205 // Security check for NPOT textures
1206 
1207 // Texture parameters configuration
1208 // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
1209 
1210 // 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
1211 
1212 // Set texture to repeat on x-axis
1213 // Set texture to repeat on y-axis
1214 
1215 // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
1216 // Set texture to clamp on x-axis
1217 // Set texture to clamp on y-axis
1218 
1219 // Set texture to repeat on x-axis
1220 // Set texture to repeat on y-axis
1221 
1222 // Magnification and minification filters
1223 // Alternative: GL_LINEAR
1224 // Alternative: GL_LINEAR
1225 
1226 // Activate Trilinear filtering if mipmaps are available
1227 
1228 // At this point we have the texture loaded in GPU and texture parameters configured
1229 
1230 // NOTE: If mipmaps were not in data, they are not generated automatically
1231 
1232 // Unbind current texture
1233 
1234 // Load depth texture/renderbuffer (to be attached to fbo)
1235 // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
1236 
1237 // In case depth textures not supported, we force renderbuffer usage
1238 
1239 // NOTE: We let the implementation to choose the best bit-depth
1240 // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
1241 
1242 // Create the renderbuffer that will serve as the depth attachment for the framebuffer
1243 // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
1244 
1245 // Load texture cubemap
1246 // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
1247 // expected the following convention: +X, -X, +Y, -Y, +Z, -Z
1248 
1249 // Load cubemap faces
1250 
1251 // 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)
1252 
1253 // Set cubemap texture sampling parameters
1254 
1255 // Flag not supported on OpenGL ES 2.0
1256 
1257 // Update already loaded texture in GPU with new data
1258 // NOTE: We don't know safely if internal texture format is the expected one...
1259 
1260 // Get OpenGL internal formats and data type from raylib PixelFormat
1261 
1262 // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
1263 
1264 // NOTE: Requires extension OES_texture_float
1265 // NOTE: Requires extension OES_texture_float
1266 // NOTE: Requires extension OES_texture_float
1267 
1268 // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
1269 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1270 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
1271 // NOTE: Requires PowerVR GPU
1272 // NOTE: Requires PowerVR GPU
1273 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1274 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
1275 
1276 // Unload texture from GPU memory
1277 
1278 // Generate mipmap data for selected texture
1279 
1280 // Check if texture is power-of-two (POT)
1281 
1282 // WARNING: Manual mipmap generation only works for RGBA 32bit textures!
1283 
1284 // Retrieve texture data from VRAM
1285 
1286 // NOTE: Texture data size is reallocated to fit mipmaps data
1287 // NOTE: CPU mipmap generation only supports RGBA 32bit data
1288 
1289 // Load the mipmaps
1290 
1291 // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
1292 
1293 //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);   // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
1294 // Generate mipmaps automatically
1295 
1296 // Activate Trilinear filtering for mipmaps
1297 
1298 // Read texture pixel data
1299 
1300 // NOTE: Using texture.id, we can retrieve some texture info (but not on OpenGL ES 2.0)
1301 // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
1302 //int width, height, format;
1303 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
1304 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
1305 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
1306 
1307 // 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.
1308 // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
1309 // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
1310 // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
1311 
1312 // glGetTexImage() is not available on OpenGL ES 2.0
1313 // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
1314 // Two possible Options:
1315 // 1 - Bind texture to color fbo attachment and glReadPixels()
1316 // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
1317 // We are using Option 1, just need to care for texture format on retrieval
1318 // NOTE: This behaviour could be conditioned by graphic driver...
1319 
1320 // TODO: Create depth texture/renderbuffer for fbo?
1321 
1322 // Attach our texture to FBO
1323 
1324 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
1325 
1326 // Clean up temporal fbo
1327 
1328 // Read screen pixel data (color buffer)
1329 
1330 // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
1331 // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
1332 
1333 // Flip image vertically!
1334 
1335 // Flip line
1336 
1337 // Set alpha component value to 255 (no trasparent image retrieval)
1338 // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
1339 
1340 // NOTE: image data should be freed
1341 
1342 // Framebuffer management (fbo)
1343 //-----------------------------------------------------------------------------------------
1344 // Load a framebuffer to be used for rendering
1345 // NOTE: No textures attached
1346 
1347 // Create the framebuffer object
1348 // Unbind any framebuffer
1349 
1350 // Attach color buffer texture to an fbo (unloads previous attachment)
1351 // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
1352 
1353 // Verify render texture is complete
1354 
1355 // Unload framebuffer from GPU memory
1356 // NOTE: All attached textures/cubemaps/renderbuffers are also deleted
1357 
1358 // Query depth attachment to automatically delete texture/renderbuffer
1359 
1360 // Bind framebuffer to query depth texture type
1361 
1362 // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
1363 // the texture image is automatically detached from the currently bound framebuffer.
1364 
1365 // Vertex data management
1366 //-----------------------------------------------------------------------------------------
1367 // Load a new attributes buffer
1368 
1369 // Load a new attributes element buffer
1370 
1371 // Update GPU buffer with new data
1372 // NOTE: dataSize and offset must be provided in bytes
1373 
1374 //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
1375 
1376 //TRACELOG(LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
1377 
1378 // Shaders management
1379 //-----------------------------------------------------------------------------------------------
1380 // Load shader from code strings
1381 // NOTE: If shader string is NULL, using default vertex/fragment shaders
1382 
1383 // Detach shader before deletion to make sure memory is freed
1384 
1385 // Detach shader before deletion to make sure memory is freed
1386 
1387 // Get available shader uniforms
1388 // NOTE: This information is useful for debug...
1389 
1390 // Assume no variable names longer than 256
1391 
1392 // Get the name of the uniforms
1393 
1394 // Compile custom shader and return shader id
1395 
1396 //case GL_GEOMETRY_SHADER:
1397 //case GL_COMPUTE_SHADER:
1398 
1399 //case GL_GEOMETRY_SHADER:
1400 //case GL_COMPUTE_SHADER:
1401 
1402 // Load custom shader strings and return program id
1403 
1404 // NOTE: Default attribute shader locations must be binded before linking
1405 
1406 // NOTE: If some attrib name is no found on the shader, it locations becomes -1
1407 
1408 // NOTE: All uniform variables are intitialised to 0 when a program links
1409 
1410 // Unload shader program
1411 
1412 // Get shader location uniform
1413 
1414 // Get shader location attribute
1415 
1416 // Set shader value uniform
1417 
1418 // Set shader value attribute
1419 
1420 // Set shader value uniform matrix
1421 
1422 // Set shader value uniform sampler
1423 
1424 // Check if texture is already active
1425 
1426 // Register a new active texture for the internal batch system
1427 // NOTE: Default texture is always activated as GL_TEXTURE0
1428 
1429 // Activate new texture unit
1430 // Save texture id for binding on drawing
1431 
1432 // Set shader currently active
1433 
1434 // Matrix state management
1435 //-----------------------------------------------------------------------------------------
1436 // Return internal modelview matrix
1437 
1438 // Return internal projection matrix
1439 
1440 // Get internal accumulated transform matrix
1441 
1442 // TODO: Consider possible transform matrices in the RLGL.State.stack
1443 // Is this the right order? or should we start with the first stored matrix instead of the last one?
1444 //Matrix matStackTransform = MatrixIdentity();
1445 //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = MatrixMultiply(RLGL.State.stack[i], matStackTransform);
1446 
1447 // Get internal projection matrix for stereo render (selected eye)
1448 
1449 // Get internal view offset matrix for stereo render (selected eye)
1450 
1451 // Set a custom modelview matrix (replaces internal modelview matrix)
1452 
1453 // Set a custom projection matrix (replaces internal projection matrix)
1454 
1455 // Set eyes projection matrices for stereo rendering
1456 
1457 // Set eyes view offsets matrices for stereo rendering
1458 
1459 // Load and draw a 1x1 XY quad in NDC
1460 
1461 // Positions         Texcoords
1462 
1463 // Gen VAO to contain VBO
1464 
1465 // Gen and fill vertex buffer (VBO)
1466 
1467 // Bind vertex attributes (position, texcoords)
1468 
1469 // Positions
1470 
1471 // Texcoords
1472 
1473 // Draw quad
1474 
1475 // Delete buffers (VBO and VAO)
1476 
1477 // Load and draw a 1x1 3D cube in NDC
1478 
1479 // Positions          Normals               Texcoords
1480 
1481 // Gen VAO to contain VBO
1482 
1483 // Gen and fill vertex buffer (VBO)
1484 
1485 // Bind vertex attributes (position, normals, texcoords)
1486 
1487 // Positions
1488 
1489 // Normals
1490 
1491 // Texcoords
1492 
1493 // Draw cube
1494 
1495 // Delete VBO and VAO
1496 
1497 //----------------------------------------------------------------------------------
1498 // Module specific Functions Definition
1499 //----------------------------------------------------------------------------------
1500 
1501 // Load default shader (just vertex positioning and texture coloring)
1502 // NOTE: This shader program is used for internal buffers
1503 // NOTE: It uses global variable: RLGL.State.defaultShader
1504 
1505 // NOTE: All locations must be reseted to -1 (no location)
1506 
1507 // Vertex shader directly defined, no external file required
1508 
1509 // Fragment shader directly defined, no external file required
1510 
1511 // Precision required for OpenGL ES2 (WebGL)
1512 
1513 // NOTE: Compiled vertex/fragment shaders are kept for re-use
1514 // Compile default vertex shader
1515 // Compile default fragment shader
1516 
1517 // Set default shader locations: attributes locations
1518 
1519 // Set default shader locations: uniform locations
1520 
1521 // Unload default shader
1522 // NOTE: It uses global variable: RLGL.State.defaultShader
1523 
1524 // Get compressed format official GL identifier name
1525 
1526 // GL_EXT_texture_compression_s3tc
1527 
1528 // GL_3DFX_texture_compression_FXT1
1529 
1530 // GL_IMG_texture_compression_pvrtc
1531 
1532 // GL_OES_compressed_ETC1_RGB8_texture
1533 
1534 // GL_ARB_texture_compression_rgtc
1535 
1536 // GL_ARB_texture_compression_bptc
1537 
1538 // GL_ARB_ES3_compatibility
1539 
1540 // GL_KHR_texture_compression_astc_hdr
1541 
1542 // SUPPORT_GL_DETAILS_INFO
1543 
1544 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
1545 
1546 // Mipmaps data is generated after image data
1547 // NOTE: Only works with RGBA (4 bytes) data!
1548 
1549 // Required mipmap levels count (including base level)
1550 
1551 // Size in bytes (will include mipmaps...), RGBA only
1552 
1553 // Count mipmap levels required
1554 
1555 // Add mipmap size (in bytes)
1556 
1557 // Generate mipmaps
1558 // NOTE: Every mipmap data is stored after data
1559 
1560 // Size of last mipmap
1561 
1562 // Mipmap size to store after offset
1563 
1564 // Add mipmap to data
1565 
1566 // free mipmap data
1567 
1568 // Manual mipmap generation (basic scaling algorithm)
1569 
1570 // Scaling algorithm works perfectly (box-filter)
1571 
1572 // GRAPHICS_API_OPENGL_11
1573 
1574 // Get pixel data size in bytes (image or texture)
1575 // NOTE: Size depends on pixel format
1576 
1577 // Size in bytes
1578 // Bits per pixel
1579 
1580 // Total data size in bytes
1581 
1582 // Most compressed formats works on 4x4 blocks,
1583 // if texture is smaller, minimum dataSize is 8 or 16
1584 
1585 // RLGL_IMPLEMENTATION