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