1 modulerlgl;
2 3 /**********************************************************************************************
4 *
5 * rlgl v4.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
6 *
7 * An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
8 * that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...)
9 *
10 * When chosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
11 * initialized on rlglInit() to accumulate vertex data.
12 *
13 * When an internal state change is required all the stored vertex data is renderer in batch,
14 * additioanlly, rlDrawRenderBatchActive() could be called to force flushing of the batch.
15 *
16 * Some additional resources are also loaded for convenience, here the complete list:
17 * - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data
18 * - Default texture (RLGL.defaultTextureId): 1x1 white pixel R8G8B8A8
19 * - Default shader (RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs)
20 *
21 * Internal buffer (and additional resources) must be manually unloaded calling rlglClose().
22 *
23 *
24 * CONFIGURATION:
25 *
26 * #define GRAPHICS_API_OPENGL_11
27 * #define GRAPHICS_API_OPENGL_21
28 * #define GRAPHICS_API_OPENGL_33
29 * #define GRAPHICS_API_OPENGL_43
30 * #define GRAPHICS_API_OPENGL_ES2
31 * Use selected OpenGL graphics backend, should be supported by platform
32 * Those preprocessor defines are only used on rlgl module, if OpenGL version is
33 * required by any other module, use rlGetVersion() to check it
34 *
35 * #define RLGL_IMPLEMENTATION
36 * Generates the implementation of the library into the included file.
37 * If not defined, the library is in header only mode and can be included in other headers
38 * or source files without problems. But only ONE file should hold the implementation.
39 *
40 * #define RLGL_RENDER_TEXTURES_HINT
41 * Enable framebuffer objects (fbo) support (enabled by default)
42 * Some GPUs could not support them despite the OpenGL version
43 *
44 * #define RLGL_SHOW_GL_DETAILS_INFO
45 * Show OpenGL extensions and capabilities detailed logs on init
46 *
47 * #define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
48 * Enable debug context (only available on OpenGL 4.3)
49 *
50 * rlgl capabilities could be customized just defining some internal
51 * values before library inclusion (default values listed):
52 *
53 * #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch elements limits
54 * #define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
55 * #define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
56 * #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
57 *
58 * #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
59 * #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
60 * #define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
61 * #define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
62 *
63 * When loading a shader, the following vertex attribute and uniform
64 * location names are tried to be set automatically:
65 *
66 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
67 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
68 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
69 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
70 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
71 * #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
72 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
73 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
74 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
75 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
76 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
77 * #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
78 * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
79 * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
80 * #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
81 *
82 * DEPENDENCIES:
83 *
84 * - OpenGL libraries (depending on platform and OpenGL version selected)
85 * - GLAD OpenGL extensions loading library (only for OpenGL 3.3 Core, 4.3 Core)
86 *
87 *
88 * LICENSE: zlib/libpng
89 *
90 * Copyright (c) 2014-2022 Ramon Santamaria (@raysan5)
91 *
92 * This software is provided "as-is", without any express or implied warranty. In no event
93 * will the authors be held liable for any damages arising from the use of this software.
94 *
95 * Permission is granted to anyone to use this software for any purpose, including commercial
96 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
97 *
98 * 1. The origin of this software must not be misrepresented; you must not claim that you
99 * wrote the original software. If you use this software in a product, an acknowledgment
100 * in the product documentation would be appreciated but is not required.
101 *
102 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
103 * as being the original software.
104 *
105 * 3. This notice may not be removed or altered from any source distribution.
106 *
107 **********************************************************************************************/108 109 importcore.stdc.config;
110 importcore.stdc.stdarg;
111 importcore.stdc.stdlib;
112 113 extern (C) @nogcnothrow:
114 115 enumRLGL_VERSION = "4.0";
116 117 // Function specifiers in case library is build/used as a shared library (Windows)118 // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll119 120 // We are building the library as a Win32 shared library (.dll)121 122 // We are using the library as a Win32 shared library (.dll)123 124 // Function specifiers definition // Functions defined as 'extern' by default (implicit specifiers)125 126 // Support TRACELOG macros127 128 // Security check in case no GRAPHICS_API_OPENGL_* defined129 130 // Security check in case multiple GRAPHICS_API_OPENGL_* defined131 132 // OpenGL 2.1 uses most of OpenGL 3.3 Core functionality133 // WARNING: Specific parts are checked with #if defines134 135 // OpenGL 4.3 uses OpenGL 3.3 Core functionality136 137 // Support framebuffer objects by default138 // NOTE: Some driver implementation do not support it, despite they should139 140 //----------------------------------------------------------------------------------141 // Defines and Macros142 //----------------------------------------------------------------------------------143 144 // Default internal render batch elements limits145 146 // This is the maximum amount of elements (quads) per batch147 // NOTE: Be careful with text, every letter maps to a quad148 enumRL_DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
149 150 // We reduce memory sizes for embedded systems (RPI and HTML5)151 // NOTE: On HTML5 (emscripten) this is allocated on heap,152 // by default it's only 16MB!...just take care...153 154 enumRL_DEFAULT_BATCH_BUFFERS = 1; // Default number of batch buffers (multi-buffering)155 156 enumRL_DEFAULT_BATCH_DRAWCALLS = 256; // Default number of batch draw calls (by state changes: mode, texture)157 158 enumRL_DEFAULT_BATCH_MAX_TEXTURE_UNITS = 4; // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())159 160 // Internal Matrix stack161 162 enumRL_MAX_MATRIX_STACK_SIZE = 32; // Maximum size of Matrix stack163 164 // Shader limits165 166 enumRL_MAX_SHADER_LOCATIONS = 32; // Maximum number of shader locations supported167 168 // Projection matrix culling169 170 enumRL_CULL_DISTANCE_NEAR = 0.01; // Default near cull distance171 172 enumRL_CULL_DISTANCE_FAR = 1000.0; // Default far cull distance173 174 // Texture parameters (equivalent to OpenGL defines)175 enumRL_TEXTURE_WRAP_S = 0x2802; // GL_TEXTURE_WRAP_S176 enumRL_TEXTURE_WRAP_T = 0x2803; // GL_TEXTURE_WRAP_T177 enumRL_TEXTURE_MAG_FILTER = 0x2800; // GL_TEXTURE_MAG_FILTER178 enumRL_TEXTURE_MIN_FILTER = 0x2801; // GL_TEXTURE_MIN_FILTER179 180 enumRL_TEXTURE_FILTER_NEAREST = 0x2600; // GL_NEAREST181 enumRL_TEXTURE_FILTER_LINEAR = 0x2601; // GL_LINEAR182 enumRL_TEXTURE_FILTER_MIP_NEAREST = 0x2700; // GL_NEAREST_MIPMAP_NEAREST183 enumRL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702; // GL_NEAREST_MIPMAP_LINEAR184 enumRL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701; // GL_LINEAR_MIPMAP_NEAREST185 enumRL_TEXTURE_FILTER_MIP_LINEAR = 0x2703; // GL_LINEAR_MIPMAP_LINEAR186 enumRL_TEXTURE_FILTER_ANISOTROPIC = 0x3000; // Anisotropic filter (custom identifier)187 188 enumRL_TEXTURE_WRAP_REPEAT = 0x2901; // GL_REPEAT189 enumRL_TEXTURE_WRAP_CLAMP = 0x812F; // GL_CLAMP_TO_EDGE190 enumRL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370; // GL_MIRRORED_REPEAT191 enumRL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742; // GL_MIRROR_CLAMP_EXT192 193 // Matrix modes (equivalent to OpenGL)194 enumRL_MODELVIEW = 0x1700; // GL_MODELVIEW195 enumRL_PROJECTION = 0x1701; // GL_PROJECTION196 enumRL_TEXTURE = 0x1702; // GL_TEXTURE197 198 // Primitive assembly draw modes199 enumRL_LINES = 0x0001; // GL_LINES200 enumRL_TRIANGLES = 0x0004; // GL_TRIANGLES201 enumRL_QUADS = 0x0007; // GL_QUADS202 203 // GL equivalent data types204 enumRL_UNSIGNED_BYTE = 0x1401; // GL_UNSIGNED_BYTE205 enumRL_FLOAT = 0x1406; // GL_FLOAT206 207 // Buffer usage hint208 enumRL_STREAM_DRAW = 0x88E0; // GL_STREAM_DRAW209 enumRL_STREAM_READ = 0x88E1; // GL_STREAM_READ210 enumRL_STREAM_COPY = 0x88E2; // GL_STREAM_COPY211 enumRL_STATIC_DRAW = 0x88E4; // GL_STATIC_DRAW212 enumRL_STATIC_READ = 0x88E5; // GL_STATIC_READ213 enumRL_STATIC_COPY = 0x88E6; // GL_STATIC_COPY214 enumRL_DYNAMIC_DRAW = 0x88E8; // GL_DYNAMIC_DRAW215 enumRL_DYNAMIC_READ = 0x88E9; // GL_DYNAMIC_READ216 enumRL_DYNAMIC_COPY = 0x88EA; // GL_DYNAMIC_COPY217 218 // GL Shader type219 enumRL_FRAGMENT_SHADER = 0x8B30; // GL_FRAGMENT_SHADER220 enumRL_VERTEX_SHADER = 0x8B31; // GL_VERTEX_SHADER221 enumRL_COMPUTE_SHADER = 0x91B9; // GL_COMPUTE_SHADER222 223 //----------------------------------------------------------------------------------224 // Types and Structures Definition225 //----------------------------------------------------------------------------------226 enumrlGlVersion227 {
228 OPENGL_11 = 1,
229 OPENGL_21 = 2,
230 OPENGL_33 = 3,
231 OPENGL_43 = 4,
232 OPENGL_ES_20 = 5233 }
234 235 enumrlFramebufferAttachType236 {
237 RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
238 RL_ATTACHMENT_COLOR_CHANNEL1 = 1,
239 RL_ATTACHMENT_COLOR_CHANNEL2 = 2,
240 RL_ATTACHMENT_COLOR_CHANNEL3 = 3,
241 RL_ATTACHMENT_COLOR_CHANNEL4 = 4,
242 RL_ATTACHMENT_COLOR_CHANNEL5 = 5,
243 RL_ATTACHMENT_COLOR_CHANNEL6 = 6,
244 RL_ATTACHMENT_COLOR_CHANNEL7 = 7,
245 RL_ATTACHMENT_DEPTH = 100,
246 RL_ATTACHMENT_STENCIL = 200247 }
248 249 enumrlFramebufferAttachTextureType250 {
251 RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
252 RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1,
253 RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2,
254 RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3,
255 RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4,
256 RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5,
257 RL_ATTACHMENT_TEXTURE2D = 100,
258 RL_ATTACHMENT_RENDERBUFFER = 200259 }
260 261 // Dynamic vertex buffers (position + texcoords + colors + indices arrays)262 structrlVertexBuffer263 {
264 intelementCount; // Number of elements in the buffer (QUADS)265 266 float* vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)267 float* texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)268 ubyte* colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)269 270 uint* indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)271 272 // Vertex indices (in case vertex data comes indexed) (6 indices per quad)273 274 uintvaoId; // OpenGL Vertex Array Object id275 uint[4] vboId; // OpenGL Vertex Buffer Objects id (4 types of vertex data)276 }
277 278 // Draw call type279 // NOTE: Only texture changes register a new draw, other state-change-related elements are not280 // used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any281 // of those state-change happens (this is done in core module)282 structrlDrawCall283 {
284 intmode; // Drawing mode: LINES, TRIANGLES, QUADS285 intvertexCount; // Number of vertex of the draw286 intvertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)287 //unsigned int vaoId; // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId288 //unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShaderId289 uinttextureId; // Texture id to be used on the draw -> Use to create new draw call if changes290 291 //Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default292 //Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default293 }
294 295 // rlRenderBatch type296 structrlRenderBatch297 {
298 intbufferCount; // Number of vertex buffers (multi-buffering support)299 intcurrentBuffer; // Current buffer tracking in case of multi-buffering300 rlVertexBuffer* vertexBuffer; // Dynamic buffer(s) for vertex data301 302 rlDrawCall* draws; // Draw calls array, depends on textureId303 intdrawCounter; // Draw calls counter304 floatcurrentDepth; // Current depth value for next draw305 }
306 307 // Boolean type308 309 // Matrix, 4x4 components, column major, OpenGL style, right handed310 structMatrix311 {
312 floatm0;
313 floatm4;
314 floatm8;
315 floatm12; // Matrix first row (4 components)316 floatm1;
317 floatm5;
318 floatm9;
319 floatm13; // Matrix second row (4 components)320 floatm2;
321 floatm6;
322 floatm10;
323 floatm14; // Matrix third row (4 components)324 floatm3;
325 floatm7;
326 floatm11;
327 floatm15; // Matrix fourth row (4 components)328 }
329 330 // Trace log level331 // NOTE: Organized by priority level332 enumrlTraceLogLevel333 {
334 RL_LOG_ALL = 0, // Display all logs335 RL_LOG_TRACE = 1, // Trace logging, intended for internal use only336 RL_LOG_DEBUG = 2, // Debug logging, used for internal debugging, it should be disabled on release builds337 RL_LOG_INFO = 3, // Info logging, used for program execution info338 RL_LOG_WARNING = 4, // Warning logging, used on recoverable failures339 RL_LOG_ERROR = 5, // Error logging, used on unrecoverable failures340 RL_LOG_FATAL = 6, // Fatal logging, used to abort program: exit(EXIT_FAILURE)341 RL_LOG_NONE = 7// Disable logging342 }
343 344 // Texture formats (support depends on OpenGL version)345 enumrlPixelFormat346 {
347 RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)348 RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA = 2, // 8*2 bpp (2 channels)349 RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5 = 3, // 16 bpp350 RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8 = 4, // 24 bpp351 RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1 = 5, // 16 bpp (1 bit alpha)352 RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4 = 6, // 16 bpp (4 bit alpha)353 RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = 7, // 32 bpp354 RL_PIXELFORMAT_UNCOMPRESSED_R32 = 8, // 32 bpp (1 channel - float)355 RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32 = 9, // 32*3 bpp (3 channels - float)356 RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 = 10, // 32*4 bpp (4 channels - float)357 RL_PIXELFORMAT_COMPRESSED_DXT1_RGB = 11, // 4 bpp (no alpha)358 RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA = 12, // 4 bpp (1 bit alpha)359 RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA = 13, // 8 bpp360 RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA = 14, // 8 bpp361 RL_PIXELFORMAT_COMPRESSED_ETC1_RGB = 15, // 4 bpp362 RL_PIXELFORMAT_COMPRESSED_ETC2_RGB = 16, // 4 bpp363 RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA = 17, // 8 bpp364 RL_PIXELFORMAT_COMPRESSED_PVRT_RGB = 18, // 4 bpp365 RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA = 19, // 4 bpp366 RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA = 20, // 8 bpp367 RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA = 21// 2 bpp368 }
369 370 // Texture parameters: filter mode371 // NOTE 1: Filtering considers mipmaps if available in the texture372 // NOTE 2: Filter is accordingly set for minification and magnification373 enumrlTextureFilter374 {
375 RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation376 RL_TEXTURE_FILTER_BILINEAR = 1, // Linear filtering377 RL_TEXTURE_FILTER_TRILINEAR = 2, // Trilinear filtering (linear with mipmaps)378 RL_TEXTURE_FILTER_ANISOTROPIC_4X = 3, // Anisotropic filtering 4x379 RL_TEXTURE_FILTER_ANISOTROPIC_8X = 4, // Anisotropic filtering 8x380 RL_TEXTURE_FILTER_ANISOTROPIC_16X = 5// Anisotropic filtering 16x381 }
382 383 // Color blending modes (pre-defined)384 enumrlBlendMode385 {
386 RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)387 RL_BLEND_ADDITIVE = 1, // Blend textures adding colors388 RL_BLEND_MULTIPLIED = 2, // Blend textures multiplying colors389 RL_BLEND_ADD_COLORS = 3, // Blend textures adding colors (alternative)390 RL_BLEND_SUBTRACT_COLORS = 4, // Blend textures subtracting colors (alternative)391 RL_BLEND_ALPHA_PREMULTIPLY = 5, // Blend premultiplied textures considering alpha392 RL_BLEND_CUSTOM = 6// Blend textures using custom src/dst factors (use rlSetBlendFactors())393 }
394 395 // Shader location point type396 enumrlShaderLocationIndex397 {
398 RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position399 RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01400 RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02401 RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal402 RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent403 RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color404 RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection405 RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform)406 RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection407 RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform)408 RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal409 RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view410 RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color411 RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color412 RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color413 RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)414 RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)415 RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal416 RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness417 RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion418 RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission419 RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height420 RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap421 RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance422 RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter423 RL_SHADER_LOC_MAP_BRDF = 25// Shader location: sampler2d texture: brdf424 }
425 426 enumRL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO;
427 enumRL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS;
428 429 // Shader uniform data type430 enumrlShaderUniformDataType431 {
432 RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float433 RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float)434 RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float)435 RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float)436 RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int437 RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int)438 RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int)439 RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int)440 RL_SHADER_UNIFORM_SAMPLER2D = 8// Shader uniform type: sampler2d441 }
442 443 // Shader attribute data types444 enumrlShaderAttributeDataType445 {
446 RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float447 RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float)448 RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float)449 RL_SHADER_ATTRIB_VEC4 = 3// Shader attribute type: vec4 (4 float)450 }
451 452 //------------------------------------------------------------------------------------453 // Functions Declaration - Matrix operations454 //------------------------------------------------------------------------------------455 456 // Prevents name mangling of functions457 458 voidrlMatrixMode (intmode); // Choose the current matrix to be transformed459 voidrlPushMatrix (); // Push the current matrix to stack460 voidrlPopMatrix (); // Pop lattest inserted matrix from stack461 voidrlLoadIdentity (); // Reset current matrix to identity matrix462 voidrlTranslatef (floatx, floaty, floatz); // Multiply the current matrix by a translation matrix463 voidrlRotatef (floatangle, floatx, floaty, floatz); // Multiply the current matrix by a rotation matrix464 voidrlScalef (floatx, floaty, floatz); // Multiply the current matrix by a scaling matrix465 voidrlMultMatrixf (float* matf); // Multiply the current matrix by another matrix466 voidrlFrustum (doubleleft, doubleright, doublebottom, doubletop, doubleznear, doublezfar);
467 voidrlOrtho (doubleleft, doubleright, doublebottom, doubletop, doubleznear, doublezfar);
468 voidrlViewport (intx, inty, intwidth, intheight); // Set the viewport area469 470 //------------------------------------------------------------------------------------471 // Functions Declaration - Vertex level operations472 //------------------------------------------------------------------------------------473 voidrlBegin (intmode); // Initialize drawing mode (how to organize vertex)474 voidrlEnd (); // Finish vertex providing475 voidrlVertex2i (intx, inty); // Define one vertex (position) - 2 int476 voidrlVertex2f (floatx, floaty); // Define one vertex (position) - 2 float477 voidrlVertex3f (floatx, floaty, floatz); // Define one vertex (position) - 3 float478 voidrlTexCoord2f (floatx, floaty); // Define one vertex (texture coordinate) - 2 float479 voidrlNormal3f (floatx, floaty, floatz); // Define one vertex (normal) - 3 float480 voidrlColor4ub (ubyter, ubyteg, ubyteb, ubytea); // Define one vertex (color) - 4 byte481 voidrlColor3f (floatx, floaty, floatz); // Define one vertex (color) - 3 float482 voidrlColor4f (floatx, floaty, floatz, floatw); // Define one vertex (color) - 4 float483 484 //------------------------------------------------------------------------------------485 // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)486 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer,487 // some of them are direct wrappers over OpenGL calls, some others are custom488 //------------------------------------------------------------------------------------489 490 // Vertex buffers state491 boolrlEnableVertexArray (uintvaoId); // Enable vertex array (VAO, if supported)492 voidrlDisableVertexArray (); // Disable vertex array (VAO, if supported)493 voidrlEnableVertexBuffer (uintid); // Enable vertex buffer (VBO)494 voidrlDisableVertexBuffer (); // Disable vertex buffer (VBO)495 voidrlEnableVertexBufferElement (uintid); // Enable vertex buffer element (VBO element)496 voidrlDisableVertexBufferElement (); // Disable vertex buffer element (VBO element)497 voidrlEnableVertexAttribute (uintindex); // Enable vertex attribute index498 voidrlDisableVertexAttribute (uintindex); // Disable vertex attribute index499 500 // Enable attribute state pointer501 // Disable attribute state pointer502 503 // Textures state504 voidrlActiveTextureSlot (intslot); // Select and active a texture slot505 voidrlEnableTexture (uintid); // Enable texture506 voidrlDisableTexture (); // Disable texture507 voidrlEnableTextureCubemap (uintid); // Enable texture cubemap508 voidrlDisableTextureCubemap (); // Disable texture cubemap509 voidrlTextureParameters (uintid, intparam, intvalue); // Set texture parameters (filter, wrap)510 511 // Shader state512 voidrlEnableShader (uintid); // Enable shader program513 voidrlDisableShader (); // Disable shader program514 515 // Framebuffer state516 voidrlEnableFramebuffer (uintid); // Enable render texture (fbo)517 voidrlDisableFramebuffer (); // Disable render texture (fbo), return to default framebuffer518 voidrlActiveDrawBuffers (intcount); // Activate multiple draw color buffers519 520 // General render state521 voidrlEnableColorBlend (); // Enable color blending522 voidrlDisableColorBlend (); // Disable color blending523 voidrlEnableDepthTest (); // Enable depth test524 voidrlDisableDepthTest (); // Disable depth test525 voidrlEnableDepthMask (); // Enable depth write526 voidrlDisableDepthMask (); // Disable depth write527 voidrlEnableBackfaceCulling (); // Enable backface culling528 voidrlDisableBackfaceCulling (); // Disable backface culling529 voidrlEnableScissorTest (); // Enable scissor test530 voidrlDisableScissorTest (); // Disable scissor test531 voidrlScissor (intx, inty, intwidth, intheight); // Scissor test532 voidrlEnableWireMode (); // Enable wire mode533 voidrlDisableWireMode (); // Disable wire mode534 voidrlSetLineWidth (floatwidth); // Set the line drawing width535 floatrlGetLineWidth (); // Get the line drawing width536 voidrlEnableSmoothLines (); // Enable line aliasing537 voidrlDisableSmoothLines (); // Disable line aliasing538 voidrlEnableStereoRender (); // Enable stereo rendering539 voidrlDisableStereoRender (); // Disable stereo rendering540 boolrlIsStereoRenderEnabled (); // Check if stereo render is enabled541 542 voidrlClearColor (ubyter, ubyteg, ubyteb, ubytea); // Clear color buffer with color543 voidrlClearScreenBuffers (); // Clear used screen buffers (color and depth)544 voidrlCheckErrors (); // Check and log OpenGL error codes545 voidrlSetBlendMode (intmode); // Set blending mode546 voidrlSetBlendFactors (intglSrcFactor, intglDstFactor, intglEquation); // Set blending mode factor and equation (using OpenGL factors)547 548 //------------------------------------------------------------------------------------549 // Functions Declaration - rlgl functionality550 //------------------------------------------------------------------------------------551 // rlgl initialization functions552 voidrlglInit (intwidth, intheight); // Initialize rlgl (buffers, shaders, textures, states)553 voidrlglClose (); // De-inititialize rlgl (buffers, shaders, textures)554 voidrlLoadExtensions (void* loader); // Load OpenGL extensions (loader function required)555 intrlGetVersion (); // Get current OpenGL version556 voidrlSetFramebufferWidth (intwidth); // Set current framebuffer width557 intrlGetFramebufferWidth (); // Get default framebuffer width558 voidrlSetFramebufferHeight (intheight); // Set current framebuffer height559 intrlGetFramebufferHeight (); // Get default framebuffer height560 561 uintrlGetTextureIdDefault (); // Get default texture id562 uintrlGetShaderIdDefault (); // Get default shader id563 int* rlGetShaderLocsDefault (); // Get default shader locations564 565 // Render batch management566 // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode567 // but this render batch API is exposed in case of custom batches are required568 rlRenderBatchrlLoadRenderBatch (intnumBuffers, intbufferElements); // Load a render batch system569 voidrlUnloadRenderBatch (rlRenderBatchbatch); // Unload render batch system570 voidrlDrawRenderBatch (rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset)571 voidrlSetRenderBatchActive (rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal)572 voidrlDrawRenderBatchActive (); // Update and draw internal render batch573 boolrlCheckRenderBatchLimit (intvCount); // Check internal buffer overflow for a given number of vertex574 voidrlSetTexture (uintid); // Set current texture for render batch and check buffers limits575 576 //------------------------------------------------------------------------------------------------------------------------577 578 // Vertex buffers management579 uintrlLoadVertexArray (); // Load vertex array (vao) if supported580 uintrlLoadVertexBuffer (const(void)* buffer, intsize, booldynamic); // Load a vertex buffer attribute581 uintrlLoadVertexBufferElement (const(void)* buffer, intsize, booldynamic); // Load a new attributes element buffer582 voidrlUpdateVertexBuffer (uintbufferId, const(void)* data, intdataSize, intoffset); // Update GPU buffer with new data583 voidrlUpdateVertexBufferElements (uintid, const(void)* data, intdataSize, intoffset); // Update vertex buffer elements with new data584 voidrlUnloadVertexArray (uintvaoId);
585 voidrlUnloadVertexBuffer (uintvboId);
586 voidrlSetVertexAttribute (uintindex, intcompSize, inttype, boolnormalized, intstride, const(void)* pointer);
587 voidrlSetVertexAttributeDivisor (uintindex, intdivisor);
588 voidrlSetVertexAttributeDefault (intlocIndex, const(void)* value, intattribType, intcount); // Set vertex attribute default value589 voidrlDrawVertexArray (intoffset, intcount);
590 voidrlDrawVertexArrayElements (intoffset, intcount, const(void)* buffer);
591 voidrlDrawVertexArrayInstanced (intoffset, intcount, intinstances);
592 voidrlDrawVertexArrayElementsInstanced (intoffset, intcount, const(void)* buffer, intinstances);
593 594 // Textures management595 uintrlLoadTexture (const(void)* data, intwidth, intheight, intformat, intmipmapCount); // Load texture in GPU596 uintrlLoadTextureDepth (intwidth, intheight, booluseRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)597 uintrlLoadTextureCubemap (const(void)* data, intsize, intformat); // Load texture cubemap598 voidrlUpdateTexture (uintid, intoffsetX, intoffsetY, intwidth, intheight, intformat, const(void)* data); // Update GPU texture with new data599 voidrlGetGlTextureFormats (intformat, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats600 const(char)* rlGetPixelFormatName (uintformat); // Get name string for pixel format601 voidrlUnloadTexture (uintid); // Unload texture from GPU memory602 voidrlGenTextureMipmaps (uintid, intwidth, intheight, intformat, int* mipmaps); // Generate mipmap data for selected texture603 void* rlReadTexturePixels (uintid, intwidth, intheight, intformat); // Read texture pixel data604 ubyte* rlReadScreenPixels (intwidth, intheight); // Read screen pixel data (color buffer)605 606 // Framebuffer management (fbo)607 uintrlLoadFramebuffer (intwidth, intheight); // Load an empty framebuffer608 voidrlFramebufferAttach (uintfboId, uinttexId, intattachType, inttexType, intmipLevel); // Attach texture/renderbuffer to a framebuffer609 boolrlFramebufferComplete (uintid); // Verify framebuffer is complete610 voidrlUnloadFramebuffer (uintid); // Delete framebuffer from GPU611 612 // Shaders management613 uintrlLoadShaderCode (const(char)* vsCode, const(char)* fsCode); // Load shader from code strings614 uintrlCompileShader (const(char)* shaderCode, inttype); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)615 uintrlLoadShaderProgram (uintvShaderId, uintfShaderId); // Load custom shader program616 voidrlUnloadShaderProgram (uintid); // Unload shader program617 intrlGetLocationUniform (uintshaderId, const(char)* uniformName); // Get shader location uniform618 intrlGetLocationAttrib (uintshaderId, const(char)* attribName); // Get shader location attribute619 voidrlSetUniform (intlocIndex, const(void)* value, intuniformType, intcount); // Set shader value uniform620 voidrlSetUniformMatrix (intlocIndex, Matrixmat); // Set shader value matrix621 voidrlSetUniformSampler (intlocIndex, uinttextureId); // Set shader value sampler622 voidrlSetShader (uintid, int* locs); // Set shader currently active (id and locations)623 624 // Compute shader management625 uintrlLoadComputeShaderProgram (uintshaderId); // Load compute shader program626 voidrlComputeShaderDispatch (uintgroupX, uintgroupY, uintgroupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)627 628 // Shader buffer storage object management (ssbo)629 uintrlLoadShaderBuffer (ulongsize, const(void)* data, intusageHint); // Load shader storage buffer object (SSBO)630 voidrlUnloadShaderBuffer (uintssboId); // Unload shader storage buffer object (SSBO)631 voidrlUpdateShaderBufferElements (uintid, const(void)* data, ulongdataSize, ulongoffset); // Update SSBO buffer data632 ulongrlGetShaderBufferSize (uintid); // Get SSBO buffer size633 voidrlReadShaderBufferElements (uintid, void* dest, ulongcount, ulongoffset); // Bind SSBO buffer634 voidrlBindShaderBuffer (uintid, uintindex); // Copy SSBO buffer data635 636 // Buffer management637 voidrlCopyBuffersElements (uintdestId, uintsrcId, ulongdestOffset, ulongsrcOffset, ulongcount); // Copy SSBO buffer data638 voidrlBindImageTexture (uintid, uintindex, uintformat, intreadonly); // Bind image texture639 640 // Matrix state management641 MatrixrlGetMatrixModelview (); // Get internal modelview matrix642 MatrixrlGetMatrixProjection (); // Get internal projection matrix643 MatrixrlGetMatrixTransform (); // Get internal accumulated transform matrix644 MatrixrlGetMatrixProjectionStereo (inteye); // Get internal projection matrix for stereo render (selected eye)645 MatrixrlGetMatrixViewOffsetStereo (inteye); // Get internal view offset matrix for stereo render (selected eye)646 voidrlSetMatrixProjection (Matrixproj); // Set a custom projection matrix (replaces internal projection matrix)647 voidrlSetMatrixModelview (Matrixview); // Set a custom modelview matrix (replaces internal modelview matrix)648 voidrlSetMatrixProjectionStereo (Matrixright, Matrixleft); // Set eyes projection matrices for stereo rendering649 voidrlSetMatrixViewOffsetStereo (Matrixright, Matrixleft); // Set eyes view offsets matrices for stereo rendering650 651 // Quick and dirty cube/quad buffers load->draw->unload652 voidrlLoadDrawCube (); // Load and draw a cube653 voidrlLoadDrawQuad (); // Load and draw a quad654 655 // RLGL_H656 657 /***********************************************************************************
658 *
659 * RLGL IMPLEMENTATION
660 *
661 ************************************************************************************/662 663 // OpenGL 1.1 library for OSX664 // OpenGL extensions library665 666 // APIENTRY for OpenGL function pointer declarations is required667 668 // WINGDIAPI definition. Some Windows OpenGL headers need it669 670 // OpenGL 1.1 library671 672 // OpenGL 3 library for OSX673 // OpenGL 3 extensions library for OSX674 675 // GLAD extensions loading library, includes OpenGL headers676 677 //#include <EGL/egl.h> // EGL library -> not required, platform layer678 // OpenGL ES 2.0 library679 // OpenGL ES 2.0 extensions library680 681 // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi682 // provided headers (despite being defined in official Khronos GLES2 headers)683 684 // Required for: malloc(), free()685 // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]686 // Required for: sqrtf(), sinf(), cosf(), floor(), log()687 688 //----------------------------------------------------------------------------------689 // Defines and Macros690 //----------------------------------------------------------------------------------691 692 // Default shader vertex attribute names to set location points693 694 // Binded by default to shader location: 0695 696 // Binded by default to shader location: 1697 698 // Binded by default to shader location: 2699 700 // Binded by default to shader location: 3701 702 // Binded by default to shader location: 4703 704 // Binded by default to shader location: 5705 706 // model-view-projection matrix707 708 // view matrix709 710 // projection matrix711 712 // model matrix713 714 // normal matrix (transpose(inverse(matModelView))715 716 // color diffuse (base tint color, multiplied by texture color)717 718 // texture0 (texture slot active 0)719 720 // texture1 (texture slot active 1)721 722 // texture2 (texture slot active 2)723 724 //----------------------------------------------------------------------------------725 // Types and Structures Definition726 //----------------------------------------------------------------------------------727 728 // Current render batch729 // Default internal render batch730 731 // Current active render batch vertex counter (generic, used for all batches)732 // Current active texture coordinate (added on glVertex*())733 // Current active normal (added on glVertex*())734 // Current active color (added on glVertex*())735 736 // Current matrix mode737 // Current matrix pointer738 // Default modelview matrix739 // Default projection matrix740 // Transform matrix to be used with rlTranslate, rlRotate, rlScale741 // Require transform matrix application to current draw-call vertex (if required)742 // Matrix stack for push/pop743 // Matrix stack counter744 745 // Default texture used on shapes/poly drawing (required by shader)746 // Active texture ids to be enabled on batch drawing (0 active by default)747 // Default vertex shader id (used by default shader program)748 // Default fragment shader id (used by default shader program)749 // Default shader program id, supports vertex color and diffuse texture750 // Default shader locations pointer to be used on rendering751 // Current shader id to be used on rendering (by default, defaultShaderId)752 // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)753 754 // Stereo rendering flag755 // VR stereo rendering eyes projection matrices756 // VR stereo rendering eyes view offset matrices757 758 // Blending mode active759 // Blending source factor760 // Blending destination factor761 // Blending equation762 763 // Current framebuffer width764 // Current framebuffer height765 766 // Renderer state767 768 // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)769 // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)770 // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)771 // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)772 // float textures support (32 bit per channel) (GL_OES_texture_float)773 // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)774 // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)775 // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)776 // PVR texture compression support (GL_IMG_texture_compression_pvrtc)777 // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)778 // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)779 // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)780 // Compute shaders support (GL_ARB_compute_shader)781 // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)782 783 // Maximum anisotropy level supported (minimum is 2.0f)784 // Maximum bits for depth component785 786 // Extensions supported flags787 788 // OpenGL extension functions loader signature (same as GLADloadproc)789 790 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2791 792 //----------------------------------------------------------------------------------793 // Global Variables Definition794 //----------------------------------------------------------------------------------795 796 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2797 798 // NOTE: VAO functionality is exposed through extensions (OES)799 800 // NOTE: Instancing functionality could also be available through extension801 802 //----------------------------------------------------------------------------------803 // Module specific Functions Declaration804 //----------------------------------------------------------------------------------805 806 // Load default shader807 // Unload default shader808 809 // Get compressed format official GL identifier name810 // RLGL_SHOW_GL_DETAILS_INFO811 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2812 813 // Generate mipmaps data on CPU side814 // Generate next mipmap level on CPU side815 816 // Get pixel data size in bytes (image or texture)817 // Auxiliar matrix math functions818 // Get identity matrix819 // Multiply two matrices820 821 //----------------------------------------------------------------------------------822 // Module Functions Definition - Matrix operations823 //----------------------------------------------------------------------------------824 825 // Fallback to OpenGL 1.1 function calls826 //---------------------------------------827 828 // Choose the current matrix to be transformed829 830 //else if (mode == RL_TEXTURE) // Not supported831 832 // Push the current matrix into RLGL.State.stack833 834 // Pop lattest inserted matrix from RLGL.State.stack835 836 // Reset current matrix to identity matrix837 838 // Multiply the current matrix by a translation matrix839 840 // NOTE: We transpose matrix with multiplication order841 842 // Multiply the current matrix by a rotation matrix843 // NOTE: The provided angle must be in degrees844 845 // Axis vector (x, y, z) normalization846 847 // Rotation matrix generation848 849 // NOTE: We transpose matrix with multiplication order850 851 // Multiply the current matrix by a scaling matrix852 853 // NOTE: We transpose matrix with multiplication order854 855 // Multiply the current matrix by another matrix856 857 // Matrix creation from array858 859 // Multiply the current matrix by a perspective matrix generated by parameters860 861 // Multiply the current matrix by an orthographic matrix generated by parameters862 863 // NOTE: If left-right and top-botton values are equal it could create a division by zero,864 // response to it is platform/compiler dependant865 866 // Set the viewport area (transformation from normalized device coordinates to window coordinates)867 // NOTE: We store current viewport dimensions868 869 //----------------------------------------------------------------------------------870 // Module Functions Definition - Vertex level operations871 //----------------------------------------------------------------------------------872 873 // Fallback to OpenGL 1.1 function calls874 //---------------------------------------875 876 // Initialize drawing mode (how to organize vertex)877 878 // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS879 // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer880 881 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,882 // that way, following QUADS drawing will keep aligned with index processing883 // It implies adding some extra alignment vertex at the end of the draw,884 // those vertex are not processed but they are considered as an additional offset885 // for the next set of vertex to be drawn886 887 // Finish vertex providing888 889 // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,890 // as well as depth buffer bit-depth (16bit or 24bit or 32bit)891 // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)892 893 // Verify internal buffers limits894 // NOTE: This check is combined with usage of rlCheckRenderBatchLimit()895 896 // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),897 // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!898 // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw899 900 // Define one vertex (position)901 // NOTE: Vertex position data is the basic information required for drawing902 903 // Transform provided vector if required904 905 // Verify that current vertex buffer elements limit has not been reached906 907 // Add vertices908 909 // Add current texcoord910 911 // TODO: Add current normal912 // By default rlVertexBuffer type does not store normals913 914 // Add current color915 916 // Define one vertex (position)917 918 // Define one vertex (position)919 920 // Define one vertex (texture coordinate)921 // NOTE: Texture coordinates are limited to QUADS only922 923 // Define one vertex (normal)924 // NOTE: Normals limited to TRIANGLES only?925 926 // Define one vertex (color)927 928 // Define one vertex (color)929 930 // Define one vertex (color)931 932 //--------------------------------------------------------------------------------------933 // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)934 //--------------------------------------------------------------------------------------935 936 // Set current texture to use937 938 // NOTE: If quads batch limit is reached, we force a draw call and next batch starts939 940 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,941 // that way, following QUADS drawing will keep aligned with index processing942 // It implies adding some extra alignment vertex at the end of the draw,943 // those vertex are not processed but they are considered as an additional offset944 // for the next set of vertex to be drawn945 946 // Select and active a texture slot947 948 // Enable texture949 950 // Disable texture951 952 // Enable texture cubemap953 954 // Disable texture cubemap955 956 // Set texture parameters (wrap mode/filter mode)957 958 // Reset anisotropy filter, in case it was set959 960 // Enable shader program961 962 // Disable shader program963 964 // Enable rendering to texture (fbo)965 966 // Disable rendering to texture967 968 // Activate multiple draw color buffers969 // NOTE: One color buffer is always active by default970 971 // NOTE: Maximum number of draw buffers supported is implementation dependant,972 // it can be queried with glGet*() but it must be at least 8973 //GLint maxDrawBuffers = 0;974 //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);975 976 //----------------------------------------------------------------------------------977 // General render state configuration978 //----------------------------------------------------------------------------------979 980 // Enable color blending981 982 // Disable color blending983 984 // Enable depth test985 986 // Disable depth test987 988 // Enable depth write989 990 // Disable depth write991 992 // Enable backface culling993 994 // Disable backface culling995 996 // Enable scissor test997 998 // Disable scissor test999 1000 // Scissor test1001 1002 // Enable wire mode1003 1004 // NOTE: glPolygonMode() not available on OpenGL ES1005 1006 // Disable wire mode1007 1008 // NOTE: glPolygonMode() not available on OpenGL ES1009 1010 // Set the line drawing width1011 1012 // Get the line drawing width1013 1014 // Enable line aliasing1015 1016 // Disable line aliasing1017 1018 // Enable stereo rendering1019 1020 // Disable stereo rendering1021 1022 // Check if stereo render is enabled1023 1024 // Clear color buffer with color1025 1026 // Color values clamp to 0.0f(0) and 1.0f(255)1027 1028 // Clear used screen buffers (color and depth)1029 1030 // Clear used buffers: Color and Depth (Depth is used for 3D)1031 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used...1032 1033 // Check and log OpenGL error codes1034 1035 // Set blend mode1036 1037 // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()1038 1039 // Set blending mode factor and equation1040 1041 //----------------------------------------------------------------------------------1042 // Module Functions Definition - OpenGL Debug1043 //----------------------------------------------------------------------------------1044 1045 // Ignore non-significant error/warning codes (NVidia drivers)1046 // NOTE: Here there are the details with a sample output:1047 // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)1048 // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)1049 // will use VIDEO memory as the source for buffer object operations. (severity: low)1050 // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)1051 // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have1052 // a defined base level and cannot be used for texture mapping. (severity: low)1053 1054 //----------------------------------------------------------------------------------1055 // Module Functions Definition - rlgl functionality1056 //----------------------------------------------------------------------------------1057 1058 // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states1059 1060 // Enable OpenGL debug context if required1061 1062 // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message1063 1064 // Debug context options:1065 // - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints1066 // - 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 error1067 1068 // Init default white texture1069 // 1 pixel RGBA (4 bytes)1070 1071 // Init default Shader (customized for GL 3.3 and ES2)1072 // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs1073 1074 // Init default vertex arrays buffers1075 1076 // Init stack matrices (emulating OpenGL 1.1)1077 1078 // Init internal matrices1079 1080 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES21081 1082 // Initialize OpenGL default states1083 //----------------------------------------------------------1084 // Init state: Depth test1085 // Type of depth testing to apply1086 // Disable depth testing for 2D (only used for 3D)1087 1088 // Init state: Blending mode1089 // Color blending function (how colors are mixed)1090 // Enable color blending (required to work with transparencies)1091 1092 // Init state: Culling1093 // NOTE: All shapes/models triangles are drawn CCW1094 // Cull the back face (default)1095 // Front face are defined counter clockwise (default)1096 // Enable backface culling1097 1098 // Init state: Cubemap seamless1099 1100 // Seamless cubemaps (not supported on OpenGL ES 2.0)1101 1102 // Init state: Color hints (deprecated in OpenGL 3.0+)1103 // Improve quality of color and texture coordinate interpolation1104 // Smooth shading between vertex (vertex colors interpolation)1105 1106 // Store screen size into global variables1107 1108 //----------------------------------------------------------1109 1110 // Init state: Color/Depth buffers clear1111 // Set clear color (black)1112 // Set clear depth value (default)1113 // Clear color and depth buffers (depth buffer required for 3D)1114 1115 // Vertex Buffer Object deinitialization (memory free)1116 1117 // Unload default shader1118 1119 // Unload default texture1120 1121 // Load OpenGL extensions1122 // NOTE: External loader function must be provided1123 1124 // Also defined for GRAPHICS_API_OPENGL_211125 // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)1126 1127 // Get number of supported extensions1128 1129 // Get supported extensions list1130 // WARNING: glGetStringi() not available on OpenGL 2.11131 1132 // Register supported extensions flags1133 // OpenGL 3.3 extensions supported by default (core)1134 1135 // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans1136 // Texture compression: DXT1137 // Texture compression: ETC2/EAC1138 1139 // GRAPHICS_API_OPENGL_331140 1141 // Get supported extensions list1142 1143 // Allocate 512 strings pointers (2 KB)1144 // One big const string1145 1146 // NOTE: We have to duplicate string because glGetString() returns a const string1147 // Get extensions string size in bytes1148 1149 // Check required extensions1150 1151 // Check VAO support1152 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature1153 1154 // The extension is supported by our hardware and driver, try to get related functions pointers1155 // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...1156 1157 //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted1158 1159 // Check instanced rendering support1160 // Web ANGLE1161 1162 // Standard EXT1163 1164 // Check NPOT textures support1165 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature1166 1167 // Check texture float support1168 1169 // Check depth texture support1170 1171 // Check texture compression support: DXT1172 1173 // Check texture compression support: ETC11174 1175 // Check texture compression support: ETC2/EAC1176 1177 // Check texture compression support: PVR1178 1179 // Check texture compression support: ASTC1180 1181 // Check anisotropic texture filter support1182 1183 // Check clamp mirror wrap mode support1184 1185 // Free extensions pointers1186 1187 // Duplicated string must be deallocated1188 // GRAPHICS_API_OPENGL_ES21189 1190 // Check OpenGL information and capabilities1191 //------------------------------------------------------------------------------1192 // Show current OpenGL and GLSL version1193 1194 // NOTE: Anisotropy levels capability is an extension1195 1196 // Show some OpenGL GPU capabilities1197 1198 // GRAPHICS_API_OPENGL_431199 // RLGL_SHOW_GL_DETAILS_INFO1200 1201 // Show some basic info about GL supported features1202 1203 // RLGL_SHOW_GL_DETAILS_INFO1204 1205 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES21206 1207 // Get current OpenGL version1208 1209 // NOTE: Force OpenGL 3.3 on OSX1210 1211 // Set current framebuffer width1212 1213 // Set current framebuffer height1214 1215 // Get default framebuffer width1216 1217 // Get default framebuffer height1218 1219 // Get default internal texture (white texture)1220 // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A81221 1222 // Get default shader id1223 1224 // Get default shader locs1225 1226 // Render batch management1227 //------------------------------------------------------------------------------------------------1228 // Load render batch1229 1230 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)1231 //--------------------------------------------------------------------------------------------1232 1233 // 3 float by vertex, 4 vertex by quad1234 // 2 float by texcoord, 4 texcoord by quad1235 // 4 float by color, 4 colors by quad1236 1237 // 6 int by quad (indices)1238 1239 // 6 int by quad (indices)1240 1241 // Indices can be initialized right now1242 1243 //--------------------------------------------------------------------------------------------1244 1245 // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs1246 //--------------------------------------------------------------------------------------------1247 1248 // Initialize Quads VAO1249 1250 // Quads - Vertex buffers binding and attributes enable1251 // Vertex position buffer (shader-location = 0)1252 1253 // Vertex texcoord buffer (shader-location = 1)1254 1255 // Vertex color buffer (shader-location = 3)1256 1257 // Fill index buffer1258 1259 // Unbind the current VAO1260 1261 //--------------------------------------------------------------------------------------------1262 1263 // Init draw calls tracking system1264 //--------------------------------------------------------------------------------------------1265 1266 //batch.draws[i].vaoId = 0;1267 //batch.draws[i].shaderId = 0;1268 1269 //batch.draws[i].RLGL.State.projection = rlMatrixIdentity();1270 //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();1271 1272 // Record buffer count1273 // Reset draws counter1274 // Reset depth value1275 //--------------------------------------------------------------------------------------------1276 1277 // Unload default internal buffers vertex data from CPU and GPU1278 1279 // Unbind everything1280 1281 // Unload all vertex buffers data1282 1283 // Unbind VAO attribs data1284 1285 // Delete VBOs from GPU (VRAM)1286 1287 // Delete VAOs from GPU (VRAM)1288 1289 // Free vertex arrays memory from CPU (RAM)1290 1291 // Unload arrays1292 1293 // Draw render batch1294 // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)1295 1296 // Update batch vertex buffers1297 //------------------------------------------------------------------------------------------------------------1298 // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)1299 // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)1300 1301 // Activate elements VAO1302 1303 // Vertex positions buffer1304 1305 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer1306 1307 // Texture coordinates buffer1308 1309 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer1310 1311 // Colors buffer1312 1313 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer1314 1315 // NOTE: glMapBuffer() causes sync issue.1316 // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.1317 // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().1318 // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new1319 // allocated pointer immediately even if GPU is still working with the previous data.1320 1321 // Another option: map the buffer object into client's memory1322 // Probably this code could be moved somewhere else...1323 // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);1324 // if (batch->vertexBuffer[batch->currentBuffer].vertices)1325 // {1326 // Update vertex data1327 // }1328 // glUnmapBuffer(GL_ARRAY_BUFFER);1329 1330 // Unbind the current VAO1331 1332 //------------------------------------------------------------------------------------------------------------1333 1334 // Draw batch vertex buffers (considering VR stereo if required)1335 //------------------------------------------------------------------------------------------------------------1336 1337 // Setup current eye viewport (half screen width)1338 1339 // Set current eye view offset to modelview matrix1340 1341 // Set current eye projection matrix1342 1343 // Draw buffers1344 1345 // Set current shader and upload current MVP matrix1346 1347 // Create modelview-projection matrix and upload to shader1348 1349 // Bind vertex attrib: position (shader-location = 0)1350 1351 // Bind vertex attrib: texcoord (shader-location = 1)1352 1353 // Bind vertex attrib: color (shader-location = 3)1354 1355 // Setup some default shader values1356 1357 // Active default sampler2D: texture01358 1359 // Activate additional sampler textures1360 // Those additional textures will be common for all draw calls of the batch1361 1362 // Activate default sampler2D texture0 (one texture is always active for default batch shader)1363 // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls1364 1365 // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default1366 1367 // We need to define the number of indices to be processed: elementCount*61368 // NOTE: The final parameter tells the GPU the offset in bytes from the1369 // start of the index buffer to the location of the first index to process1370 1371 // Unbind textures1372 1373 // Unbind VAO1374 1375 // Unbind shader program1376 1377 // Restore viewport to default measures1378 1379 //------------------------------------------------------------------------------------------------------------1380 1381 // Reset batch buffers1382 //------------------------------------------------------------------------------------------------------------1383 // Reset vertex counter for next frame1384 1385 // Reset depth for next draw1386 1387 // Restore projection/modelview matrices1388 1389 // Reset RLGL.currentBatch->draws array1390 1391 // Reset active texture units for next batch1392 1393 // Reset draws counter to one draw for the batch1394 1395 //------------------------------------------------------------------------------------------------------------1396 1397 // Change to next buffer in the list (in case of multi-buffering)1398 1399 // Set the active render batch for rlgl1400 1401 // Update and draw internal render batch1402 1403 // NOTE: Stereo rendering is checked inside1404 1405 // Check internal buffer overflow for a given number of vertex1406 // and force a rlRenderBatch draw call if required1407 1408 // NOTE: Stereo rendering is checked inside1409 1410 // Restore state of last batch so we can continue adding vertices1411 1412 // Textures data management1413 //-----------------------------------------------------------------------------------------1414 // Convert image data to OpenGL texture (returns OpenGL valid Id)1415 1416 // Free any old binding1417 1418 // Check texture format support by OpenGL 1.1 (compressed textures not supported)1419 1420 // GRAPHICS_API_OPENGL_111421 1422 // Generate texture id1423 1424 // Mipmap data offset1425 1426 // Load the different mipmap levels1427 1428 // Security check for NPOT textures1429 1430 // Texture parameters configuration1431 // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used1432 1433 // NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used1434 1435 // Set texture to repeat on x-axis1436 // Set texture to repeat on y-axis1437 1438 // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!1439 // Set texture to clamp on x-axis1440 // Set texture to clamp on y-axis1441 1442 // Set texture to repeat on x-axis1443 // Set texture to repeat on y-axis1444 1445 // Magnification and minification filters1446 // Alternative: GL_LINEAR1447 // Alternative: GL_LINEAR1448 1449 // Activate Trilinear filtering if mipmaps are available1450 1451 // At this point we have the texture loaded in GPU and texture parameters configured1452 1453 // NOTE: If mipmaps were not in data, they are not generated automatically1454 1455 // Unbind current texture1456 1457 // Load depth texture/renderbuffer (to be attached to fbo)1458 // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions1459 1460 // In case depth textures not supported, we force renderbuffer usage1461 1462 // NOTE: We let the implementation to choose the best bit-depth1463 // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F1464 1465 // Create the renderbuffer that will serve as the depth attachment for the framebuffer1466 // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices1467 1468 // Load texture cubemap1469 // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),1470 // expected the following convention: +X, -X, +Y, -Y, +Z, -Z1471 1472 // Load cubemap faces1473 1474 // Instead of using a sized internal texture format (GL_RGB16F, GL_RGB32F), we let the driver to choose the better format for us (GL_RGB)1475 1476 // Set cubemap texture sampling parameters1477 1478 // Flag not supported on OpenGL ES 2.01479 1480 // Update already loaded texture in GPU with new data1481 // NOTE: We don't know safely if internal texture format is the expected one...1482 1483 // Get OpenGL internal formats and data type from raylib PixelFormat1484 1485 // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA1486 1487 // NOTE: Requires extension OES_texture_float1488 // NOTE: Requires extension OES_texture_float1489 // NOTE: Requires extension OES_texture_float1490 1491 // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.31492 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.31493 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.31494 // NOTE: Requires PowerVR GPU1495 // NOTE: Requires PowerVR GPU1496 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.31497 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.31498 1499 // Unload texture from GPU memory1500 1501 // Generate mipmap data for selected texture1502 1503 // Check if texture is power-of-two (POT)1504 1505 // WARNING: Manual mipmap generation only works for RGBA 32bit textures!1506 1507 // Retrieve texture data from VRAM1508 1509 // NOTE: Texture data size is reallocated to fit mipmaps data1510 // NOTE: CPU mipmap generation only supports RGBA 32bit data1511 1512 // Load the mipmaps1513 1514 // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data1515 1516 //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE1517 // Generate mipmaps automatically1518 1519 // Read texture pixel data1520 1521 // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)1522 // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE1523 //int width, height, format;1524 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);1525 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);1526 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);1527 1528 // NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.1529 // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.1530 // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)1531 // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)1532 1533 // glGetTexImage() is not available on OpenGL ES 2.01534 // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.1535 // Two possible Options:1536 // 1 - Bind texture to color fbo attachment and glReadPixels()1537 // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()1538 // We are using Option 1, just need to care for texture format on retrieval1539 // NOTE: This behaviour could be conditioned by graphic driver...1540 1541 // Attach our texture to FBO1542 1543 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format1544 1545 // Clean up temporal fbo1546 1547 // Read screen pixel data (color buffer)1548 1549 // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer1550 // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!1551 1552 // Flip image vertically!1553 1554 // Flip line1555 1556 // Set alpha component value to 255 (no trasparent image retrieval)1557 // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!1558 1559 // NOTE: image data should be freed1560 1561 // Framebuffer management (fbo)1562 //-----------------------------------------------------------------------------------------1563 // Load a framebuffer to be used for rendering1564 // NOTE: No textures attached1565 1566 // Create the framebuffer object1567 // Unbind any framebuffer1568 1569 // Attach color buffer texture to an fbo (unloads previous attachment)1570 // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture1571 1572 // Verify render texture is complete1573 1574 // Unload framebuffer from GPU memory1575 // NOTE: All attached textures/cubemaps/renderbuffers are also deleted1576 1577 // Query depth attachment to automatically delete texture/renderbuffer1578 1579 // Bind framebuffer to query depth texture type1580 1581 // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,1582 // the texture image is automatically detached from the currently bound framebuffer.1583 1584 // Vertex data management1585 //-----------------------------------------------------------------------------------------1586 // Load a new attributes buffer1587 1588 // Load a new attributes element buffer1589 1590 // Enable vertex buffer (VBO)1591 1592 // Disable vertex buffer (VBO)1593 1594 // Enable vertex buffer element (VBO element)1595 1596 // Disable vertex buffer element (VBO element)1597 1598 // Update vertex buffer with new data1599 // NOTE: dataSize and offset must be provided in bytes1600 1601 // Update vertex buffer elements with new data1602 // NOTE: dataSize and offset must be provided in bytes1603 1604 // Enable vertex array object (VAO)1605 1606 // Disable vertex array object (VAO)1607 1608 // Enable vertex attribute index1609 1610 // Disable vertex attribute index1611 1612 // Draw vertex array1613 1614 // Draw vertex array elements1615 1616 // Draw vertex array instanced1617 1618 // Draw vertex array elements instanced1619 1620 // Enable vertex state pointer1621 1622 //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors1623 1624 // Disable vertex state pointer1625 1626 // Load vertex array object (VAO)1627 1628 // Set vertex attribute1629 1630 // Set vertex attribute divisor1631 1632 // Unload vertex array object (VAO)1633 1634 // Unload vertex buffer (VBO)1635 1636 //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");1637 1638 // Shaders management1639 //-----------------------------------------------------------------------------------------------1640 // Load shader from code strings1641 // NOTE: If shader string is NULL, using default vertex/fragment shaders1642 1643 // Compile vertex shader (if provided)1644 1645 // In case no vertex shader was provided or compilation failed, we use default vertex shader1646 1647 // Compile fragment shader (if provided)1648 1649 // In case no fragment shader was provided or compilation failed, we use default fragment shader1650 1651 // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id1652 1653 // One of or both shader are new, we need to compile a new shader program1654 1655 // We can detach and delete vertex/fragment shaders (if not default ones)1656 // NOTE: We detach shader before deletion to make sure memory is freed1657 1658 // In case shader program loading failed, we assign default shader1659 1660 // In case shader loading fails, we return the default shader1661 1662 /*
1663 else
1664 {
1665 // Get available shader uniforms
1666 // NOTE: This information is useful for debug...
1667 int uniformCount = -1;
1668 glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
1669 1670 for (int i = 0; i < uniformCount; i++)
1671 {
1672 int namelen = -1;
1673 int num = -1;
1674 char name[256] = { 0 }; // Assume no variable names longer than 256
1675 GLenum type = GL_ZERO;
1676 1677 // Get the name of the uniforms
1678 glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
1679 1680 name[namelen] = 0;
1681 TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
1682 }
1683 }
1684 */1685 1686 // Compile custom shader and return shader id1687 1688 //case GL_GEOMETRY_SHADER:1689 1690 //case GL_GEOMETRY_SHADER:1691 1692 // Load custom shader strings and return program id1693 1694 // NOTE: Default attribute shader locations must be binded before linking1695 1696 // NOTE: If some attrib name is no found on the shader, it locations becomes -11697 1698 // NOTE: All uniform variables are intitialised to 0 when a program links1699 1700 // Get the size of compiled shader program (not available on OpenGL ES 2.0)1701 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.1702 //GLint binarySize = 0;1703 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);1704 1705 // Unload shader program1706 1707 // Get shader location uniform1708 1709 // Get shader location attribute1710 1711 // Set shader value uniform1712 1713 // Set shader value attribute1714 1715 // Set shader value uniform matrix1716 1717 // Set shader value uniform sampler1718 1719 // Check if texture is already active1720 1721 // Register a new active texture for the internal batch system1722 // NOTE: Default texture is always activated as GL_TEXTURE01723 1724 // Activate new texture unit1725 // Save texture id for binding on drawing1726 1727 // Set shader currently active (id and locations)1728 1729 // Load compute shader program1730 1731 // NOTE: All uniform variables are intitialised to 0 when a program links1732 1733 // Get the size of compiled shader program (not available on OpenGL ES 2.0)1734 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.1735 //GLint binarySize = 0;1736 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);1737 1738 // Dispatch compute shader (equivalent to *draw* for graphics pilepine)1739 1740 // Load shader storage buffer object (SSBO)1741 1742 // Unload shader storage buffer object (SSBO)1743 1744 // Update SSBO buffer data1745 1746 // Get SSBO buffer size1747 1748 // Read SSBO buffer data1749 1750 // Bind SSBO buffer1751 1752 // Copy SSBO buffer data1753 1754 // Bind image texture1755 1756 // Matrix state management1757 //-----------------------------------------------------------------------------------------1758 // Get internal modelview matrix1759 1760 // Get internal projection matrix1761 1762 // Get internal accumulated transform matrix1763 1764 // TODO: Consider possible transform matrices in the RLGL.State.stack1765 // Is this the right order? or should we start with the first stored matrix instead of the last one?1766 //Matrix matStackTransform = rlMatrixIdentity();1767 //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);1768 1769 // Get internal projection matrix for stereo render (selected eye)1770 1771 // Get internal view offset matrix for stereo render (selected eye)1772 1773 // Set a custom modelview matrix (replaces internal modelview matrix)1774 1775 // Set a custom projection matrix (replaces internal projection matrix)1776 1777 // Set eyes projection matrices for stereo rendering1778 1779 // Set eyes view offsets matrices for stereo rendering1780 1781 // Load and draw a quad in NDC1782 1783 // Positions Texcoords1784 1785 // Gen VAO to contain VBO1786 1787 // Gen and fill vertex buffer (VBO)1788 1789 // Bind vertex attributes (position, texcoords)1790 1791 // Positions1792 1793 // Texcoords1794 1795 // Draw quad1796 1797 // Delete buffers (VBO and VAO)1798 1799 // Load and draw a cube in NDC1800 1801 // Positions Normals Texcoords1802 1803 // Gen VAO to contain VBO1804 1805 // Gen and fill vertex buffer (VBO)1806 1807 // Bind vertex attributes (position, normals, texcoords)1808 1809 // Positions1810 1811 // Normals1812 1813 // Texcoords1814 1815 // Draw cube1816 1817 // Delete VBO and VAO1818 1819 // Get name string for pixel format1820 1821 // 8 bit per pixel (no alpha)1822 // 8*2 bpp (2 channels)1823 // 16 bpp1824 // 24 bpp1825 // 16 bpp (1 bit alpha)1826 // 16 bpp (4 bit alpha)1827 // 32 bpp1828 // 32 bpp (1 channel - float)1829 // 32*3 bpp (3 channels - float)1830 // 32*4 bpp (4 channels - float)1831 // 4 bpp (no alpha)1832 // 4 bpp (1 bit alpha)1833 // 8 bpp1834 // 8 bpp1835 // 4 bpp1836 // 4 bpp1837 // 8 bpp1838 // 4 bpp1839 // 4 bpp1840 // 8 bpp1841 // 2 bpp1842 1843 //----------------------------------------------------------------------------------1844 // Module specific Functions Definition1845 //----------------------------------------------------------------------------------1846 1847 // Load default shader (just vertex positioning and texture coloring)1848 // NOTE: This shader program is used for internal buffers1849 // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs1850 1851 // NOTE: All locations must be reseted to -1 (no location)1852 1853 // Vertex shader directly defined, no external file required1854 1855 // Fragment shader directly defined, no external file required1856 1857 // Precision required for OpenGL ES2 (WebGL)1858 1859 // NOTE: Compiled vertex/fragment shaders are not deleted,1860 // they are kept for re-use as default shaders in case some shader loading fails1861 // Compile default vertex shader1862 // Compile default fragment shader1863 1864 // Set default shader locations: attributes locations1865 1866 // Set default shader locations: uniform locations1867 1868 // Unload default shader1869 // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs1870 1871 // Get compressed format official GL identifier name1872 1873 // GL_EXT_texture_compression_s3tc1874 1875 // GL_3DFX_texture_compression_FXT11876 1877 // GL_IMG_texture_compression_pvrtc1878 1879 // GL_OES_compressed_ETC1_RGB8_texture1880 1881 // GL_ARB_texture_compression_rgtc1882 1883 // GL_ARB_texture_compression_bptc1884 1885 // GL_ARB_ES3_compatibility1886 1887 // GL_KHR_texture_compression_astc_hdr1888 1889 // RLGL_SHOW_GL_DETAILS_INFO1890 1891 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES21892 1893 // Mipmaps data is generated after image data1894 // NOTE: Only works with RGBA (4 bytes) data!1895 1896 // Required mipmap levels count (including base level)1897 1898 // Size in bytes (will include mipmaps...), RGBA only1899 1900 // Count mipmap levels required1901 1902 // Add mipmap size (in bytes)1903 1904 // RGBA: 4 bytes1905 1906 // Generate mipmaps1907 // NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)1908 1909 // Size of last mipmap1910 1911 // Mipmap size to store after offset1912 1913 // Add mipmap to data1914 1915 // free mipmap data1916 1917 // Manual mipmap generation (basic scaling algorithm)1918 1919 // Scaling algorithm works perfectly (box-filter)1920 1921 // GRAPHICS_API_OPENGL_111922 1923 // Get pixel data size in bytes (image or texture)1924 // NOTE: Size depends on pixel format1925 1926 // Size in bytes1927 // Bits per pixel1928 1929 // Total data size in bytes1930 1931 // Most compressed formats works on 4x4 blocks,1932 // if texture is smaller, minimum dataSize is 8 or 161933 1934 // Auxiliar math functions1935 1936 // Get identity matrix1937 1938 // Get two matrix multiplication1939 // NOTE: When multiplying matrices... the order matters!1940 1941 // RLGL_IMPLEMENTATION