1 module raylib.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-2022 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 approximation 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_ALPHA_PREMULTIPLY = 5, // Blend premultiplied textures considering alpha 377 RL_BLEND_CUSTOM = 6 // Blend textures using custom src/dst factors (use rlSetBlendFactors()) 378 } 379 380 // Shader location point type 381 enum rlShaderLocationIndex 382 { 383 RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position 384 RL_SHADER_LOC_VERTEX_TEXCOORD01 = 1, // Shader location: vertex attribute: texcoord01 385 RL_SHADER_LOC_VERTEX_TEXCOORD02 = 2, // Shader location: vertex attribute: texcoord02 386 RL_SHADER_LOC_VERTEX_NORMAL = 3, // Shader location: vertex attribute: normal 387 RL_SHADER_LOC_VERTEX_TANGENT = 4, // Shader location: vertex attribute: tangent 388 RL_SHADER_LOC_VERTEX_COLOR = 5, // Shader location: vertex attribute: color 389 RL_SHADER_LOC_MATRIX_MVP = 6, // Shader location: matrix uniform: model-view-projection 390 RL_SHADER_LOC_MATRIX_VIEW = 7, // Shader location: matrix uniform: view (camera transform) 391 RL_SHADER_LOC_MATRIX_PROJECTION = 8, // Shader location: matrix uniform: projection 392 RL_SHADER_LOC_MATRIX_MODEL = 9, // Shader location: matrix uniform: model (transform) 393 RL_SHADER_LOC_MATRIX_NORMAL = 10, // Shader location: matrix uniform: normal 394 RL_SHADER_LOC_VECTOR_VIEW = 11, // Shader location: vector uniform: view 395 RL_SHADER_LOC_COLOR_DIFFUSE = 12, // Shader location: vector uniform: diffuse color 396 RL_SHADER_LOC_COLOR_SPECULAR = 13, // Shader location: vector uniform: specular color 397 RL_SHADER_LOC_COLOR_AMBIENT = 14, // Shader location: vector uniform: ambient color 398 RL_SHADER_LOC_MAP_ALBEDO = 15, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE) 399 RL_SHADER_LOC_MAP_METALNESS = 16, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR) 400 RL_SHADER_LOC_MAP_NORMAL = 17, // Shader location: sampler2d texture: normal 401 RL_SHADER_LOC_MAP_ROUGHNESS = 18, // Shader location: sampler2d texture: roughness 402 RL_SHADER_LOC_MAP_OCCLUSION = 19, // Shader location: sampler2d texture: occlusion 403 RL_SHADER_LOC_MAP_EMISSION = 20, // Shader location: sampler2d texture: emission 404 RL_SHADER_LOC_MAP_HEIGHT = 21, // Shader location: sampler2d texture: height 405 RL_SHADER_LOC_MAP_CUBEMAP = 22, // Shader location: samplerCube texture: cubemap 406 RL_SHADER_LOC_MAP_IRRADIANCE = 23, // Shader location: samplerCube texture: irradiance 407 RL_SHADER_LOC_MAP_PREFILTER = 24, // Shader location: samplerCube texture: prefilter 408 RL_SHADER_LOC_MAP_BRDF = 25 // Shader location: sampler2d texture: brdf 409 } 410 411 enum RL_SHADER_LOC_MAP_DIFFUSE = rlShaderLocationIndex.RL_SHADER_LOC_MAP_ALBEDO; 412 enum RL_SHADER_LOC_MAP_SPECULAR = rlShaderLocationIndex.RL_SHADER_LOC_MAP_METALNESS; 413 414 // Shader uniform data type 415 enum rlShaderUniformDataType 416 { 417 RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float 418 RL_SHADER_UNIFORM_VEC2 = 1, // Shader uniform type: vec2 (2 float) 419 RL_SHADER_UNIFORM_VEC3 = 2, // Shader uniform type: vec3 (3 float) 420 RL_SHADER_UNIFORM_VEC4 = 3, // Shader uniform type: vec4 (4 float) 421 RL_SHADER_UNIFORM_INT = 4, // Shader uniform type: int 422 RL_SHADER_UNIFORM_IVEC2 = 5, // Shader uniform type: ivec2 (2 int) 423 RL_SHADER_UNIFORM_IVEC3 = 6, // Shader uniform type: ivec3 (3 int) 424 RL_SHADER_UNIFORM_IVEC4 = 7, // Shader uniform type: ivec4 (4 int) 425 RL_SHADER_UNIFORM_SAMPLER2D = 8 // Shader uniform type: sampler2d 426 } 427 428 // Shader attribute data types 429 enum rlShaderAttributeDataType 430 { 431 RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float 432 RL_SHADER_ATTRIB_VEC2 = 1, // Shader attribute type: vec2 (2 float) 433 RL_SHADER_ATTRIB_VEC3 = 2, // Shader attribute type: vec3 (3 float) 434 RL_SHADER_ATTRIB_VEC4 = 3 // Shader attribute type: vec4 (4 float) 435 } 436 437 //------------------------------------------------------------------------------------ 438 // Functions Declaration - Matrix operations 439 //------------------------------------------------------------------------------------ 440 441 // Prevents name mangling of functions 442 443 void rlMatrixMode(int mode); // Choose the current matrix to be transformed 444 void rlPushMatrix(); // Push the current matrix to stack 445 void rlPopMatrix(); // Pop lattest inserted matrix from stack 446 void rlLoadIdentity(); // Reset current matrix to identity matrix 447 void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix 448 void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix 449 void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix 450 void rlMultMatrixf(float* matf); // Multiply the current matrix by another matrix 451 void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); 452 void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar); 453 void rlViewport(int x, int y, int width, int height); // Set the viewport area 454 455 //------------------------------------------------------------------------------------ 456 // Functions Declaration - Vertex level operations 457 //------------------------------------------------------------------------------------ 458 void rlBegin(int mode); // Initialize drawing mode (how to organize vertex) 459 void rlEnd(); // Finish vertex providing 460 void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int 461 void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float 462 void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float 463 void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float 464 void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float 465 void rlColor4ub(ubyte r, ubyte g, ubyte b, ubyte a); // Define one vertex (color) - 4 byte 466 void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float 467 void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float 468 469 //------------------------------------------------------------------------------------ 470 // Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2) 471 // NOTE: This functions are used to completely abstract raylib code from OpenGL layer, 472 // some of them are direct wrappers over OpenGL calls, some others are custom 473 //------------------------------------------------------------------------------------ 474 475 // Vertex buffers state 476 bool rlEnableVertexArray(uint vaoId); // Enable vertex array (VAO, if supported) 477 void rlDisableVertexArray(); // Disable vertex array (VAO, if supported) 478 void rlEnableVertexBuffer(uint id); // Enable vertex buffer (VBO) 479 void rlDisableVertexBuffer(); // Disable vertex buffer (VBO) 480 void rlEnableVertexBufferElement(uint id); // Enable vertex buffer element (VBO element) 481 void rlDisableVertexBufferElement(); // Disable vertex buffer element (VBO element) 482 void rlEnableVertexAttribute(uint index); // Enable vertex attribute index 483 void rlDisableVertexAttribute(uint index); // Disable vertex attribute index 484 485 // Enable attribute state pointer 486 // Disable attribute state pointer 487 488 // Textures state 489 void rlActiveTextureSlot(int slot); // Select and active a texture slot 490 void rlEnableTexture(uint id); // Enable texture 491 void rlDisableTexture(); // Disable texture 492 void rlEnableTextureCubemap(uint id); // Enable texture cubemap 493 void rlDisableTextureCubemap(); // Disable texture cubemap 494 void rlTextureParameters(uint id, int param, int value); // Set texture parameters (filter, wrap) 495 496 // Shader state 497 void rlEnableShader(uint id); // Enable shader program 498 void rlDisableShader(); // Disable shader program 499 500 // Framebuffer state 501 void rlEnableFramebuffer(uint id); // Enable render texture (fbo) 502 void rlDisableFramebuffer(); // Disable render texture (fbo), return to default framebuffer 503 void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers 504 505 // General render state 506 void rlEnableColorBlend(); // Enable color blending 507 void rlDisableColorBlend(); // Disable color blending 508 void rlEnableDepthTest(); // Enable depth test 509 void rlDisableDepthTest(); // Disable depth test 510 void rlEnableDepthMask(); // Enable depth write 511 void rlDisableDepthMask(); // Disable depth write 512 void rlEnableBackfaceCulling(); // Enable backface culling 513 void rlDisableBackfaceCulling(); // Disable backface culling 514 void rlEnableScissorTest(); // Enable scissor test 515 void rlDisableScissorTest(); // Disable scissor test 516 void rlScissor(int x, int y, int width, int height); // Scissor test 517 void rlEnableWireMode(); // Enable wire mode 518 void rlDisableWireMode(); // Disable wire mode 519 void rlSetLineWidth(float width); // Set the line drawing width 520 float rlGetLineWidth(); // Get the line drawing width 521 void rlEnableSmoothLines(); // Enable line aliasing 522 void rlDisableSmoothLines(); // Disable line aliasing 523 void rlEnableStereoRender(); // Enable stereo rendering 524 void rlDisableStereoRender(); // Disable stereo rendering 525 bool rlIsStereoRenderEnabled(); // Check if stereo render is enabled 526 527 void rlClearColor(ubyte r, ubyte g, ubyte b, ubyte a); // Clear color buffer with color 528 void rlClearScreenBuffers(); // Clear used screen buffers (color and depth) 529 void rlCheckErrors(); // Check and log OpenGL error codes 530 void rlSetBlendMode(int mode); // Set blending mode 531 void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors) 532 533 //------------------------------------------------------------------------------------ 534 // Functions Declaration - rlgl functionality 535 //------------------------------------------------------------------------------------ 536 // rlgl initialization functions 537 void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states) 538 void rlglClose(); // De-inititialize rlgl (buffers, shaders, textures) 539 void rlLoadExtensions(void* loader); // Load OpenGL extensions (loader function required) 540 int rlGetVersion(); // Get current OpenGL version 541 void rlSetFramebufferWidth(int width); // Set current framebuffer width 542 int rlGetFramebufferWidth(); // Get default framebuffer width 543 void rlSetFramebufferHeight(int height); // Set current framebuffer height 544 int rlGetFramebufferHeight(); // Get default framebuffer height 545 546 uint rlGetTextureIdDefault(); // Get default texture id 547 uint rlGetShaderIdDefault(); // Get default shader id 548 int* rlGetShaderLocsDefault(); // Get default shader locations 549 550 // Render batch management 551 // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode 552 // but this render batch API is exposed in case of custom batches are required 553 rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system 554 void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system 555 void rlDrawRenderBatch(rlRenderBatch* batch); // Draw render batch data (Update->Draw->Reset) 556 void rlSetRenderBatchActive(rlRenderBatch* batch); // Set the active render batch for rlgl (NULL for default internal) 557 void rlDrawRenderBatchActive(); // Update and draw internal render batch 558 bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex 559 void rlSetTexture(uint id); // Set current texture for render batch and check buffers limits 560 561 //------------------------------------------------------------------------------------------------------------------------ 562 563 // Vertex buffers management 564 uint rlLoadVertexArray(); // Load vertex array (vao) if supported 565 uint rlLoadVertexBuffer(const(void)* buffer, int size, bool dynamic); // Load a vertex buffer attribute 566 uint rlLoadVertexBufferElement(const(void)* buffer, int size, bool dynamic); // Load a new attributes element buffer 567 void rlUpdateVertexBuffer(uint bufferId, const(void)* data, int dataSize, int offset); // Update GPU buffer with new data 568 void rlUpdateVertexBufferElements(uint id, const(void)* data, int dataSize, int offset); // Update vertex buffer elements with new data 569 void rlUnloadVertexArray(uint vaoId); 570 void rlUnloadVertexBuffer(uint vboId); 571 void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, const(void)* pointer); 572 void rlSetVertexAttributeDivisor(uint index, int divisor); 573 void rlSetVertexAttributeDefault(int locIndex, const(void)* value, int attribType, int count); // Set vertex attribute default value 574 void rlDrawVertexArray(int offset, int count); 575 void rlDrawVertexArrayElements(int offset, int count, const(void)* buffer); 576 void rlDrawVertexArrayInstanced(int offset, int count, int instances); 577 void rlDrawVertexArrayElementsInstanced(int offset, int count, const(void)* buffer, int instances); 578 579 // Textures management 580 uint rlLoadTexture(const(void)* data, int width, int height, int format, int mipmapCount); // Load texture in GPU 581 uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo) 582 uint rlLoadTextureCubemap(const(void)* data, int size, int format); // Load texture cubemap 583 void rlUpdateTexture(uint id, int offsetX, int offsetY, int width, int height, int format, const(void)* data); // Update GPU texture with new data 584 void rlGetGlTextureFormats(int format, uint* glInternalFormat, uint* glFormat, uint* glType); // Get OpenGL internal formats 585 const(char)* rlGetPixelFormatName(uint format); // Get name string for pixel format 586 void rlUnloadTexture(uint id); // Unload texture from GPU memory 587 void rlGenTextureMipmaps(uint id, int width, int height, int format, int* mipmaps); // Generate mipmap data for selected texture 588 void* rlReadTexturePixels(uint id, int width, int height, int format); // Read texture pixel data 589 ubyte* rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer) 590 591 // Framebuffer management (fbo) 592 uint rlLoadFramebuffer(int width, int height); // Load an empty framebuffer 593 void rlFramebufferAttach(uint fboId, uint texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer 594 bool rlFramebufferComplete(uint id); // Verify framebuffer is complete 595 void rlUnloadFramebuffer(uint id); // Delete framebuffer from GPU 596 597 // Shaders management 598 uint rlLoadShaderCode(const(char)* vsCode, const(char)* fsCode); // Load shader from code strings 599 uint rlCompileShader(const(char)* shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER) 600 uint rlLoadShaderProgram(uint vShaderId, uint fShaderId); // Load custom shader program 601 void rlUnloadShaderProgram(uint id); // Unload shader program 602 int rlGetLocationUniform(uint shaderId, const(char)* uniformName); // Get shader location uniform 603 int rlGetLocationAttrib(uint shaderId, const(char)* attribName); // Get shader location attribute 604 void rlSetUniform(int locIndex, const(void)* value, int uniformType, int count); // Set shader value uniform 605 void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix 606 void rlSetUniformSampler(int locIndex, uint textureId); // Set shader value sampler 607 void rlSetShader(uint id, int* locs); // Set shader currently active (id and locations) 608 609 // Compute shader management 610 uint rlLoadComputeShaderProgram(uint shaderId); // Load compute shader program 611 void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine) 612 613 // Shader buffer storage object management (ssbo) 614 uint rlLoadShaderBuffer(ulong size, const(void)* data, int usageHint); // Load shader storage buffer object (SSBO) 615 void rlUnloadShaderBuffer(uint ssboId); // Unload shader storage buffer object (SSBO) 616 void rlUpdateShaderBufferElements(uint id, const(void)* data, ulong dataSize, ulong offset); // Update SSBO buffer data 617 ulong rlGetShaderBufferSize(uint id); // Get SSBO buffer size 618 void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); // Bind SSBO buffer 619 void rlBindShaderBuffer(uint id, uint index); // Copy SSBO buffer data 620 621 // Buffer management 622 void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); // Copy SSBO buffer data 623 void rlBindImageTexture(uint id, uint index, uint format, int readonly); // Bind image texture 624 625 // Matrix state management 626 Matrix rlGetMatrixModelview(); // Get internal modelview matrix 627 Matrix rlGetMatrixProjection(); // Get internal projection matrix 628 Matrix rlGetMatrixTransform(); // Get internal accumulated transform matrix 629 Matrix rlGetMatrixProjectionStereo(int eye); // Get internal projection matrix for stereo render (selected eye) 630 Matrix rlGetMatrixViewOffsetStereo(int eye); // Get internal view offset matrix for stereo render (selected eye) 631 void rlSetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) 632 void rlSetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) 633 void rlSetMatrixProjectionStereo(Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering 634 void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering 635 636 // Quick and dirty cube/quad buffers load->draw->unload 637 void rlLoadDrawCube(); // Load and draw a cube 638 void rlLoadDrawQuad(); // Load and draw a quad 639 640 // RLGL_H 641 642 /*********************************************************************************** 643 * 644 * RLGL IMPLEMENTATION 645 * 646 ************************************************************************************/ 647 648 // OpenGL 1.1 library for OSX 649 // OpenGL extensions library 650 651 // APIENTRY for OpenGL function pointer declarations is required 652 653 // WINGDIAPI definition. Some Windows OpenGL headers need it 654 655 // OpenGL 1.1 library 656 657 // OpenGL 3 library for OSX 658 // OpenGL 3 extensions library for OSX 659 660 // GLAD extensions loading library, includes OpenGL headers 661 662 //#include <EGL/egl.h> // EGL library -> not required, platform layer 663 // OpenGL ES 2.0 library 664 // OpenGL ES 2.0 extensions library 665 666 // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi 667 // provided headers (despite being defined in official Khronos GLES2 headers) 668 669 // Required for: malloc(), free() 670 // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading] 671 // Required for: sqrtf(), sinf(), cosf(), floor(), log() 672 673 //---------------------------------------------------------------------------------- 674 // Defines and Macros 675 //---------------------------------------------------------------------------------- 676 677 // Default shader vertex attribute names to set location points 678 679 // Binded by default to shader location: 0 680 681 // Binded by default to shader location: 1 682 683 // Binded by default to shader location: 2 684 685 // Binded by default to shader location: 3 686 687 // Binded by default to shader location: 4 688 689 // Binded by default to shader location: 5 690 691 // model-view-projection matrix 692 693 // view matrix 694 695 // projection matrix 696 697 // model matrix 698 699 // normal matrix (transpose(inverse(matModelView)) 700 701 // color diffuse (base tint color, multiplied by texture color) 702 703 // texture0 (texture slot active 0) 704 705 // texture1 (texture slot active 1) 706 707 // texture2 (texture slot active 2) 708 709 //---------------------------------------------------------------------------------- 710 // Types and Structures Definition 711 //---------------------------------------------------------------------------------- 712 713 // Current render batch 714 // Default internal render batch 715 716 // Current active render batch vertex counter (generic, used for all batches) 717 // Current active texture coordinate (added on glVertex*()) 718 // Current active normal (added on glVertex*()) 719 // Current active color (added on glVertex*()) 720 721 // Current matrix mode 722 // Current matrix pointer 723 // Default modelview matrix 724 // Default projection matrix 725 // Transform matrix to be used with rlTranslate, rlRotate, rlScale 726 // Require transform matrix application to current draw-call vertex (if required) 727 // Matrix stack for push/pop 728 // Matrix stack counter 729 730 // Default texture used on shapes/poly drawing (required by shader) 731 // Active texture ids to be enabled on batch drawing (0 active by default) 732 // Default vertex shader id (used by default shader program) 733 // Default fragment shader id (used by default shader program) 734 // Default shader program id, supports vertex color and diffuse texture 735 // Default shader locations pointer to be used on rendering 736 // Current shader id to be used on rendering (by default, defaultShaderId) 737 // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs) 738 739 // Stereo rendering flag 740 // VR stereo rendering eyes projection matrices 741 // VR stereo rendering eyes view offset matrices 742 743 // Blending mode active 744 // Blending source factor 745 // Blending destination factor 746 // Blending equation 747 748 // Current framebuffer width 749 // Current framebuffer height 750 751 // Renderer state 752 753 // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object) 754 // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays) 755 // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot) 756 // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture) 757 // float textures support (32 bit per channel) (GL_OES_texture_float) 758 // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc) 759 // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1) 760 // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility) 761 // PVR texture compression support (GL_IMG_texture_compression_pvrtc) 762 // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr) 763 // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp) 764 // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic) 765 // Compute shaders support (GL_ARB_compute_shader) 766 // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object) 767 768 // Maximum anisotropy level supported (minimum is 2.0f) 769 // Maximum bits for depth component 770 771 // Extensions supported flags 772 773 // OpenGL extension functions loader signature (same as GLADloadproc) 774 775 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 776 777 //---------------------------------------------------------------------------------- 778 // Global Variables Definition 779 //---------------------------------------------------------------------------------- 780 781 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 782 783 // NOTE: VAO functionality is exposed through extensions (OES) 784 785 // NOTE: Instancing functionality could also be available through extension 786 787 //---------------------------------------------------------------------------------- 788 // Module specific Functions Declaration 789 //---------------------------------------------------------------------------------- 790 791 // Load default shader 792 // Unload default shader 793 794 // Get compressed format official GL identifier name 795 // RLGL_SHOW_GL_DETAILS_INFO 796 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 797 798 // Generate mipmaps data on CPU side 799 // Generate next mipmap level on CPU side 800 801 // Get pixel data size in bytes (image or texture) 802 // Auxiliar matrix math functions 803 // Get identity matrix 804 // Multiply two matrices 805 806 //---------------------------------------------------------------------------------- 807 // Module Functions Definition - Matrix operations 808 //---------------------------------------------------------------------------------- 809 810 // Fallback to OpenGL 1.1 function calls 811 //--------------------------------------- 812 813 // Choose the current matrix to be transformed 814 815 //else if (mode == RL_TEXTURE) // Not supported 816 817 // Push the current matrix into RLGL.State.stack 818 819 // Pop lattest inserted matrix from RLGL.State.stack 820 821 // Reset current matrix to identity matrix 822 823 // Multiply the current matrix by a translation matrix 824 825 // NOTE: We transpose matrix with multiplication order 826 827 // Multiply the current matrix by a rotation matrix 828 // NOTE: The provided angle must be in degrees 829 830 // Axis vector (x, y, z) normalization 831 832 // Rotation matrix generation 833 834 // NOTE: We transpose matrix with multiplication order 835 836 // Multiply the current matrix by a scaling matrix 837 838 // NOTE: We transpose matrix with multiplication order 839 840 // Multiply the current matrix by another matrix 841 842 // Matrix creation from array 843 844 // Multiply the current matrix by a perspective matrix generated by parameters 845 846 // Multiply the current matrix by an orthographic matrix generated by parameters 847 848 // NOTE: If left-right and top-botton values are equal it could create a division by zero, 849 // response to it is platform/compiler dependant 850 851 // Set the viewport area (transformation from normalized device coordinates to window coordinates) 852 // NOTE: We store current viewport dimensions 853 854 //---------------------------------------------------------------------------------- 855 // Module Functions Definition - Vertex level operations 856 //---------------------------------------------------------------------------------- 857 858 // Fallback to OpenGL 1.1 function calls 859 //--------------------------------------- 860 861 // Initialize drawing mode (how to organize vertex) 862 863 // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS 864 // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer 865 866 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, 867 // that way, following QUADS drawing will keep aligned with index processing 868 // It implies adding some extra alignment vertex at the end of the draw, 869 // those vertex are not processed but they are considered as an additional offset 870 // for the next set of vertex to be drawn 871 872 // Finish vertex providing 873 874 // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values, 875 // as well as depth buffer bit-depth (16bit or 24bit or 32bit) 876 // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) 877 878 // Verify internal buffers limits 879 // NOTE: This check is combined with usage of rlCheckRenderBatchLimit() 880 881 // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(), 882 // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call! 883 // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw 884 885 // Define one vertex (position) 886 // NOTE: Vertex position data is the basic information required for drawing 887 888 // Transform provided vector if required 889 890 // Verify that current vertex buffer elements limit has not been reached 891 892 // Add vertices 893 894 // Add current texcoord 895 896 // TODO: Add current normal 897 // By default rlVertexBuffer type does not store normals 898 899 // Add current color 900 901 // Define one vertex (position) 902 903 // Define one vertex (position) 904 905 // Define one vertex (texture coordinate) 906 // NOTE: Texture coordinates are limited to QUADS only 907 908 // Define one vertex (normal) 909 // NOTE: Normals limited to TRIANGLES only? 910 911 // Define one vertex (color) 912 913 // Define one vertex (color) 914 915 // Define one vertex (color) 916 917 //-------------------------------------------------------------------------------------- 918 // Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2) 919 //-------------------------------------------------------------------------------------- 920 921 // Set current texture to use 922 923 // NOTE: If quads batch limit is reached, we force a draw call and next batch starts 924 925 // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, 926 // that way, following QUADS drawing will keep aligned with index processing 927 // It implies adding some extra alignment vertex at the end of the draw, 928 // those vertex are not processed but they are considered as an additional offset 929 // for the next set of vertex to be drawn 930 931 // Select and active a texture slot 932 933 // Enable texture 934 935 // Disable texture 936 937 // Enable texture cubemap 938 939 // Disable texture cubemap 940 941 // Set texture parameters (wrap mode/filter mode) 942 943 // Reset anisotropy filter, in case it was set 944 945 // Enable shader program 946 947 // Disable shader program 948 949 // Enable rendering to texture (fbo) 950 951 // Disable rendering to texture 952 953 // Activate multiple draw color buffers 954 // NOTE: One color buffer is always active by default 955 956 // NOTE: Maximum number of draw buffers supported is implementation dependant, 957 // it can be queried with glGet*() but it must be at least 8 958 //GLint maxDrawBuffers = 0; 959 //glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); 960 961 //---------------------------------------------------------------------------------- 962 // General render state configuration 963 //---------------------------------------------------------------------------------- 964 965 // Enable color blending 966 967 // Disable color blending 968 969 // Enable depth test 970 971 // Disable depth test 972 973 // Enable depth write 974 975 // Disable depth write 976 977 // Enable backface culling 978 979 // Disable backface culling 980 981 // Enable scissor test 982 983 // Disable scissor test 984 985 // Scissor test 986 987 // Enable wire mode 988 989 // NOTE: glPolygonMode() not available on OpenGL ES 990 991 // Disable wire mode 992 993 // NOTE: glPolygonMode() not available on OpenGL ES 994 995 // Set the line drawing width 996 997 // Get the line drawing width 998 999 // Enable line aliasing 1000 1001 // Disable line aliasing 1002 1003 // Enable stereo rendering 1004 1005 // Disable stereo rendering 1006 1007 // Check if stereo render is enabled 1008 1009 // Clear color buffer with color 1010 1011 // Color values clamp to 0.0f(0) and 1.0f(255) 1012 1013 // Clear used screen buffers (color and depth) 1014 1015 // Clear used buffers: Color and Depth (Depth is used for 3D) 1016 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used... 1017 1018 // Check and log OpenGL error codes 1019 1020 // Set blend mode 1021 1022 // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors() 1023 1024 // Set blending mode factor and equation 1025 1026 //---------------------------------------------------------------------------------- 1027 // Module Functions Definition - OpenGL Debug 1028 //---------------------------------------------------------------------------------- 1029 1030 // Ignore non-significant error/warning codes (NVidia drivers) 1031 // NOTE: Here there are the details with a sample output: 1032 // - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low) 1033 // - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4) 1034 // will use VIDEO memory as the source for buffer object operations. (severity: low) 1035 // - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium) 1036 // - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have 1037 // a defined base level and cannot be used for texture mapping. (severity: low) 1038 1039 //---------------------------------------------------------------------------------- 1040 // Module Functions Definition - rlgl functionality 1041 //---------------------------------------------------------------------------------- 1042 1043 // Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states 1044 1045 // Enable OpenGL debug context if required 1046 1047 // glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message 1048 1049 // Debug context options: 1050 // - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints 1051 // - 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 1052 1053 // Init default white texture 1054 // 1 pixel RGBA (4 bytes) 1055 1056 // Init default Shader (customized for GL 3.3 and ES2) 1057 // Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs 1058 1059 // Init default vertex arrays buffers 1060 1061 // Init stack matrices (emulating OpenGL 1.1) 1062 1063 // Init internal matrices 1064 1065 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 1066 1067 // Initialize OpenGL default states 1068 //---------------------------------------------------------- 1069 // Init state: Depth test 1070 // Type of depth testing to apply 1071 // Disable depth testing for 2D (only used for 3D) 1072 1073 // Init state: Blending mode 1074 // Color blending function (how colors are mixed) 1075 // Enable color blending (required to work with transparencies) 1076 1077 // Init state: Culling 1078 // NOTE: All shapes/models triangles are drawn CCW 1079 // Cull the back face (default) 1080 // Front face are defined counter clockwise (default) 1081 // Enable backface culling 1082 1083 // Init state: Cubemap seamless 1084 1085 // Seamless cubemaps (not supported on OpenGL ES 2.0) 1086 1087 // Init state: Color hints (deprecated in OpenGL 3.0+) 1088 // Improve quality of color and texture coordinate interpolation 1089 // Smooth shading between vertex (vertex colors interpolation) 1090 1091 // Store screen size into global variables 1092 1093 //---------------------------------------------------------- 1094 1095 // Init state: Color/Depth buffers clear 1096 // Set clear color (black) 1097 // Set clear depth value (default) 1098 // Clear color and depth buffers (depth buffer required for 3D) 1099 1100 // Vertex Buffer Object deinitialization (memory free) 1101 1102 // Unload default shader 1103 1104 // Unload default texture 1105 1106 // Load OpenGL extensions 1107 // NOTE: External loader function must be provided 1108 1109 // Also defined for GRAPHICS_API_OPENGL_21 1110 // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions) 1111 1112 // Get number of supported extensions 1113 1114 // Get supported extensions list 1115 // WARNING: glGetStringi() not available on OpenGL 2.1 1116 1117 // Register supported extensions flags 1118 // OpenGL 3.3 extensions supported by default (core) 1119 1120 // NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans 1121 // Texture compression: DXT 1122 // Texture compression: ETC2/EAC 1123 1124 // GRAPHICS_API_OPENGL_33 1125 1126 // Get supported extensions list 1127 1128 // Allocate 512 strings pointers (2 KB) 1129 // One big const string 1130 1131 // NOTE: We have to duplicate string because glGetString() returns a const string 1132 // Get extensions string size in bytes 1133 1134 // Check required extensions 1135 1136 // Check VAO support 1137 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature 1138 1139 // The extension is supported by our hardware and driver, try to get related functions pointers 1140 // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance... 1141 1142 //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted 1143 1144 // Check instanced rendering support 1145 // Web ANGLE 1146 1147 // Standard EXT 1148 1149 // Check NPOT textures support 1150 // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature 1151 1152 // Check texture float support 1153 1154 // Check depth texture support 1155 1156 // Check texture compression support: DXT 1157 1158 // Check texture compression support: ETC1 1159 1160 // Check texture compression support: ETC2/EAC 1161 1162 // Check texture compression support: PVR 1163 1164 // Check texture compression support: ASTC 1165 1166 // Check anisotropic texture filter support 1167 1168 // Check clamp mirror wrap mode support 1169 1170 // Free extensions pointers 1171 1172 // Duplicated string must be deallocated 1173 // GRAPHICS_API_OPENGL_ES2 1174 1175 // Check OpenGL information and capabilities 1176 //------------------------------------------------------------------------------ 1177 // Show current OpenGL and GLSL version 1178 1179 // NOTE: Anisotropy levels capability is an extension 1180 1181 // Show some OpenGL GPU capabilities 1182 1183 // GRAPHICS_API_OPENGL_43 1184 // RLGL_SHOW_GL_DETAILS_INFO 1185 1186 // Show some basic info about GL supported features 1187 1188 // RLGL_SHOW_GL_DETAILS_INFO 1189 1190 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 1191 1192 // Get current OpenGL version 1193 1194 // NOTE: Force OpenGL 3.3 on OSX 1195 1196 // Set current framebuffer width 1197 1198 // Set current framebuffer height 1199 1200 // Get default framebuffer width 1201 1202 // Get default framebuffer height 1203 1204 // Get default internal texture (white texture) 1205 // NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8 1206 1207 // Get default shader id 1208 1209 // Get default shader locs 1210 1211 // Render batch management 1212 //------------------------------------------------------------------------------------------------ 1213 // Load render batch 1214 1215 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes) 1216 //-------------------------------------------------------------------------------------------- 1217 1218 // 3 float by vertex, 4 vertex by quad 1219 // 2 float by texcoord, 4 texcoord by quad 1220 // 4 float by color, 4 colors by quad 1221 1222 // 6 int by quad (indices) 1223 1224 // 6 int by quad (indices) 1225 1226 // Indices can be initialized right now 1227 1228 //-------------------------------------------------------------------------------------------- 1229 1230 // Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs 1231 //-------------------------------------------------------------------------------------------- 1232 1233 // Initialize Quads VAO 1234 1235 // Quads - Vertex buffers binding and attributes enable 1236 // Vertex position buffer (shader-location = 0) 1237 1238 // Vertex texcoord buffer (shader-location = 1) 1239 1240 // Vertex color buffer (shader-location = 3) 1241 1242 // Fill index buffer 1243 1244 // Unbind the current VAO 1245 1246 //-------------------------------------------------------------------------------------------- 1247 1248 // Init draw calls tracking system 1249 //-------------------------------------------------------------------------------------------- 1250 1251 //batch.draws[i].vaoId = 0; 1252 //batch.draws[i].shaderId = 0; 1253 1254 //batch.draws[i].RLGL.State.projection = rlMatrixIdentity(); 1255 //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity(); 1256 1257 // Record buffer count 1258 // Reset draws counter 1259 // Reset depth value 1260 //-------------------------------------------------------------------------------------------- 1261 1262 // Unload default internal buffers vertex data from CPU and GPU 1263 1264 // Unbind everything 1265 1266 // Unload all vertex buffers data 1267 1268 // Unbind VAO attribs data 1269 1270 // Delete VBOs from GPU (VRAM) 1271 1272 // Delete VAOs from GPU (VRAM) 1273 1274 // Free vertex arrays memory from CPU (RAM) 1275 1276 // Unload arrays 1277 1278 // Draw render batch 1279 // NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer) 1280 1281 // Update batch vertex buffers 1282 //------------------------------------------------------------------------------------------------------------ 1283 // NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0) 1284 // TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required) 1285 1286 // Activate elements VAO 1287 1288 // Vertex positions buffer 1289 1290 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer 1291 1292 // Texture coordinates buffer 1293 1294 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer 1295 1296 // Colors buffer 1297 1298 //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer 1299 1300 // NOTE: glMapBuffer() causes sync issue. 1301 // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job. 1302 // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer(). 1303 // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new 1304 // allocated pointer immediately even if GPU is still working with the previous data. 1305 1306 // Another option: map the buffer object into client's memory 1307 // Probably this code could be moved somewhere else... 1308 // batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); 1309 // if (batch->vertexBuffer[batch->currentBuffer].vertices) 1310 // { 1311 // Update vertex data 1312 // } 1313 // glUnmapBuffer(GL_ARRAY_BUFFER); 1314 1315 // Unbind the current VAO 1316 1317 //------------------------------------------------------------------------------------------------------------ 1318 1319 // Draw batch vertex buffers (considering VR stereo if required) 1320 //------------------------------------------------------------------------------------------------------------ 1321 1322 // Setup current eye viewport (half screen width) 1323 1324 // Set current eye view offset to modelview matrix 1325 1326 // Set current eye projection matrix 1327 1328 // Draw buffers 1329 1330 // Set current shader and upload current MVP matrix 1331 1332 // Create modelview-projection matrix and upload to shader 1333 1334 // Bind vertex attrib: position (shader-location = 0) 1335 1336 // Bind vertex attrib: texcoord (shader-location = 1) 1337 1338 // Bind vertex attrib: color (shader-location = 3) 1339 1340 // Setup some default shader values 1341 1342 // Active default sampler2D: texture0 1343 1344 // Activate additional sampler textures 1345 // Those additional textures will be common for all draw calls of the batch 1346 1347 // Activate default sampler2D texture0 (one texture is always active for default batch shader) 1348 // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls 1349 1350 // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default 1351 1352 // We need to define the number of indices to be processed: elementCount*6 1353 // NOTE: The final parameter tells the GPU the offset in bytes from the 1354 // start of the index buffer to the location of the first index to process 1355 1356 // Unbind textures 1357 1358 // Unbind VAO 1359 1360 // Unbind shader program 1361 1362 // Restore viewport to default measures 1363 1364 //------------------------------------------------------------------------------------------------------------ 1365 1366 // Reset batch buffers 1367 //------------------------------------------------------------------------------------------------------------ 1368 // Reset vertex counter for next frame 1369 1370 // Reset depth for next draw 1371 1372 // Restore projection/modelview matrices 1373 1374 // Reset RLGL.currentBatch->draws array 1375 1376 // Reset active texture units for next batch 1377 1378 // Reset draws counter to one draw for the batch 1379 1380 //------------------------------------------------------------------------------------------------------------ 1381 1382 // Change to next buffer in the list (in case of multi-buffering) 1383 1384 // Set the active render batch for rlgl 1385 1386 // Update and draw internal render batch 1387 1388 // NOTE: Stereo rendering is checked inside 1389 1390 // Check internal buffer overflow for a given number of vertex 1391 // and force a rlRenderBatch draw call if required 1392 1393 // NOTE: Stereo rendering is checked inside 1394 1395 // Restore state of last batch so we can continue adding vertices 1396 1397 // Textures data management 1398 //----------------------------------------------------------------------------------------- 1399 // Convert image data to OpenGL texture (returns OpenGL valid Id) 1400 1401 // Free any old binding 1402 1403 // Check texture format support by OpenGL 1.1 (compressed textures not supported) 1404 1405 // GRAPHICS_API_OPENGL_11 1406 1407 // Generate texture id 1408 1409 // Mipmap data offset 1410 1411 // Load the different mipmap levels 1412 1413 // Security check for NPOT textures 1414 1415 // Texture parameters configuration 1416 // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used 1417 1418 // 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 1419 1420 // Set texture to repeat on x-axis 1421 // Set texture to repeat on y-axis 1422 1423 // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work! 1424 // Set texture to clamp on x-axis 1425 // Set texture to clamp on y-axis 1426 1427 // Set texture to repeat on x-axis 1428 // Set texture to repeat on y-axis 1429 1430 // Magnification and minification filters 1431 // Alternative: GL_LINEAR 1432 // Alternative: GL_LINEAR 1433 1434 // Activate Trilinear filtering if mipmaps are available 1435 1436 // At this point we have the texture loaded in GPU and texture parameters configured 1437 1438 // NOTE: If mipmaps were not in data, they are not generated automatically 1439 1440 // Unbind current texture 1441 1442 // Load depth texture/renderbuffer (to be attached to fbo) 1443 // WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions 1444 1445 // In case depth textures not supported, we force renderbuffer usage 1446 1447 // NOTE: We let the implementation to choose the best bit-depth 1448 // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F 1449 1450 // Create the renderbuffer that will serve as the depth attachment for the framebuffer 1451 // NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices 1452 1453 // Load texture cubemap 1454 // NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other), 1455 // expected the following convention: +X, -X, +Y, -Y, +Z, -Z 1456 1457 // Load cubemap faces 1458 1459 // 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) 1460 1461 // Set cubemap texture sampling parameters 1462 1463 // Flag not supported on OpenGL ES 2.0 1464 1465 // Update already loaded texture in GPU with new data 1466 // NOTE: We don't know safely if internal texture format is the expected one... 1467 1468 // Get OpenGL internal formats and data type from raylib PixelFormat 1469 1470 // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA 1471 1472 // NOTE: Requires extension OES_texture_float 1473 // NOTE: Requires extension OES_texture_float 1474 // NOTE: Requires extension OES_texture_float 1475 1476 // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3 1477 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3 1478 // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3 1479 // NOTE: Requires PowerVR GPU 1480 // NOTE: Requires PowerVR GPU 1481 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3 1482 // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3 1483 1484 // Unload texture from GPU memory 1485 1486 // Generate mipmap data for selected texture 1487 1488 // Check if texture is power-of-two (POT) 1489 1490 // WARNING: Manual mipmap generation only works for RGBA 32bit textures! 1491 1492 // Retrieve texture data from VRAM 1493 1494 // NOTE: Texture data size is reallocated to fit mipmaps data 1495 // NOTE: CPU mipmap generation only supports RGBA 32bit data 1496 1497 // Load the mipmaps 1498 1499 // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data 1500 1501 //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE 1502 // Generate mipmaps automatically 1503 1504 // Read texture pixel data 1505 1506 // NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0) 1507 // Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE 1508 //int width, height, format; 1509 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 1510 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 1511 //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); 1512 1513 // 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. 1514 // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting. 1515 // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.) 1516 // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.) 1517 1518 // glGetTexImage() is not available on OpenGL ES 2.0 1519 // Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id. 1520 // Two possible Options: 1521 // 1 - Bind texture to color fbo attachment and glReadPixels() 1522 // 2 - Create an fbo, activate it, render quad with texture, glReadPixels() 1523 // We are using Option 1, just need to care for texture format on retrieval 1524 // NOTE: This behaviour could be conditioned by graphic driver... 1525 1526 // Attach our texture to FBO 1527 1528 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format 1529 1530 // Clean up temporal fbo 1531 1532 // Read screen pixel data (color buffer) 1533 1534 // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer 1535 // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly! 1536 1537 // Flip image vertically! 1538 1539 // Flip line 1540 1541 // Set alpha component value to 255 (no trasparent image retrieval) 1542 // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! 1543 1544 // NOTE: image data should be freed 1545 1546 // Framebuffer management (fbo) 1547 //----------------------------------------------------------------------------------------- 1548 // Load a framebuffer to be used for rendering 1549 // NOTE: No textures attached 1550 1551 // Create the framebuffer object 1552 // Unbind any framebuffer 1553 1554 // Attach color buffer texture to an fbo (unloads previous attachment) 1555 // NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture 1556 1557 // Verify render texture is complete 1558 1559 // Unload framebuffer from GPU memory 1560 // NOTE: All attached textures/cubemaps/renderbuffers are also deleted 1561 1562 // Query depth attachment to automatically delete texture/renderbuffer 1563 1564 // Bind framebuffer to query depth texture type 1565 1566 // NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer, 1567 // the texture image is automatically detached from the currently bound framebuffer. 1568 1569 // Vertex data management 1570 //----------------------------------------------------------------------------------------- 1571 // Load a new attributes buffer 1572 1573 // Load a new attributes element buffer 1574 1575 // Enable vertex buffer (VBO) 1576 1577 // Disable vertex buffer (VBO) 1578 1579 // Enable vertex buffer element (VBO element) 1580 1581 // Disable vertex buffer element (VBO element) 1582 1583 // Update vertex buffer with new data 1584 // NOTE: dataSize and offset must be provided in bytes 1585 1586 // Update vertex buffer elements with new data 1587 // NOTE: dataSize and offset must be provided in bytes 1588 1589 // Enable vertex array object (VAO) 1590 1591 // Disable vertex array object (VAO) 1592 1593 // Enable vertex attribute index 1594 1595 // Disable vertex attribute index 1596 1597 // Draw vertex array 1598 1599 // Draw vertex array elements 1600 1601 // Draw vertex array instanced 1602 1603 // Draw vertex array elements instanced 1604 1605 // Enable vertex state pointer 1606 1607 //case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors 1608 1609 // Disable vertex state pointer 1610 1611 // Load vertex array object (VAO) 1612 1613 // Set vertex attribute 1614 1615 // Set vertex attribute divisor 1616 1617 // Unload vertex array object (VAO) 1618 1619 // Unload vertex buffer (VBO) 1620 1621 //TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)"); 1622 1623 // Shaders management 1624 //----------------------------------------------------------------------------------------------- 1625 // Load shader from code strings 1626 // NOTE: If shader string is NULL, using default vertex/fragment shaders 1627 1628 // Compile vertex shader (if provided) 1629 1630 // In case no vertex shader was provided or compilation failed, we use default vertex shader 1631 1632 // Compile fragment shader (if provided) 1633 1634 // In case no fragment shader was provided or compilation failed, we use default fragment shader 1635 1636 // In case vertex and fragment shader are the default ones, no need to recompile, we can just assign the default shader program id 1637 1638 // One of or both shader are new, we need to compile a new shader program 1639 1640 // We can detach and delete vertex/fragment shaders (if not default ones) 1641 // NOTE: We detach shader before deletion to make sure memory is freed 1642 1643 // In case shader program loading failed, we assign default shader 1644 1645 // In case shader loading fails, we return the default shader 1646 1647 /* 1648 else 1649 { 1650 // Get available shader uniforms 1651 // NOTE: This information is useful for debug... 1652 int uniformCount = -1; 1653 glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount); 1654 1655 for (int i = 0; i < uniformCount; i++) 1656 { 1657 int namelen = -1; 1658 int num = -1; 1659 char name[256] = { 0 }; // Assume no variable names longer than 256 1660 GLenum type = GL_ZERO; 1661 1662 // Get the name of the uniforms 1663 glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name); 1664 1665 name[namelen] = 0; 1666 TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name)); 1667 } 1668 } 1669 */ 1670 1671 // Compile custom shader and return shader id 1672 1673 //case GL_GEOMETRY_SHADER: 1674 1675 //case GL_GEOMETRY_SHADER: 1676 1677 // Load custom shader strings and return program id 1678 1679 // NOTE: Default attribute shader locations must be binded before linking 1680 1681 // NOTE: If some attrib name is no found on the shader, it locations becomes -1 1682 1683 // NOTE: All uniform variables are intitialised to 0 when a program links 1684 1685 // Get the size of compiled shader program (not available on OpenGL ES 2.0) 1686 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero. 1687 //GLint binarySize = 0; 1688 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize); 1689 1690 // Unload shader program 1691 1692 // Get shader location uniform 1693 1694 // Get shader location attribute 1695 1696 // Set shader value uniform 1697 1698 // Set shader value attribute 1699 1700 // Set shader value uniform matrix 1701 1702 // Set shader value uniform sampler 1703 1704 // Check if texture is already active 1705 1706 // Register a new active texture for the internal batch system 1707 // NOTE: Default texture is always activated as GL_TEXTURE0 1708 1709 // Activate new texture unit 1710 // Save texture id for binding on drawing 1711 1712 // Set shader currently active (id and locations) 1713 1714 // Load compute shader program 1715 1716 // NOTE: All uniform variables are intitialised to 0 when a program links 1717 1718 // Get the size of compiled shader program (not available on OpenGL ES 2.0) 1719 // NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero. 1720 //GLint binarySize = 0; 1721 //glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize); 1722 1723 // Dispatch compute shader (equivalent to *draw* for graphics pilepine) 1724 1725 // Load shader storage buffer object (SSBO) 1726 1727 // Unload shader storage buffer object (SSBO) 1728 1729 // Update SSBO buffer data 1730 1731 // Get SSBO buffer size 1732 1733 // Read SSBO buffer data 1734 1735 // Bind SSBO buffer 1736 1737 // Copy SSBO buffer data 1738 1739 // Bind image texture 1740 1741 // Matrix state management 1742 //----------------------------------------------------------------------------------------- 1743 // Get internal modelview matrix 1744 1745 // Get internal projection matrix 1746 1747 // Get internal accumulated transform matrix 1748 1749 // TODO: Consider possible transform matrices in the RLGL.State.stack 1750 // Is this the right order? or should we start with the first stored matrix instead of the last one? 1751 //Matrix matStackTransform = rlMatrixIdentity(); 1752 //for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform); 1753 1754 // Get internal projection matrix for stereo render (selected eye) 1755 1756 // Get internal view offset matrix for stereo render (selected eye) 1757 1758 // Set a custom modelview matrix (replaces internal modelview matrix) 1759 1760 // Set a custom projection matrix (replaces internal projection matrix) 1761 1762 // Set eyes projection matrices for stereo rendering 1763 1764 // Set eyes view offsets matrices for stereo rendering 1765 1766 // Load and draw a quad in NDC 1767 1768 // Positions Texcoords 1769 1770 // Gen VAO to contain VBO 1771 1772 // Gen and fill vertex buffer (VBO) 1773 1774 // Bind vertex attributes (position, texcoords) 1775 1776 // Positions 1777 1778 // Texcoords 1779 1780 // Draw quad 1781 1782 // Delete buffers (VBO and VAO) 1783 1784 // Load and draw a cube in NDC 1785 1786 // Positions Normals Texcoords 1787 1788 // Gen VAO to contain VBO 1789 1790 // Gen and fill vertex buffer (VBO) 1791 1792 // Bind vertex attributes (position, normals, texcoords) 1793 1794 // Positions 1795 1796 // Normals 1797 1798 // Texcoords 1799 1800 // Draw cube 1801 1802 // Delete VBO and VAO 1803 1804 // Get name string for pixel format 1805 1806 // 8 bit per pixel (no alpha) 1807 // 8*2 bpp (2 channels) 1808 // 16 bpp 1809 // 24 bpp 1810 // 16 bpp (1 bit alpha) 1811 // 16 bpp (4 bit alpha) 1812 // 32 bpp 1813 // 32 bpp (1 channel - float) 1814 // 32*3 bpp (3 channels - float) 1815 // 32*4 bpp (4 channels - float) 1816 // 4 bpp (no alpha) 1817 // 4 bpp (1 bit alpha) 1818 // 8 bpp 1819 // 8 bpp 1820 // 4 bpp 1821 // 4 bpp 1822 // 8 bpp 1823 // 4 bpp 1824 // 4 bpp 1825 // 8 bpp 1826 // 2 bpp 1827 1828 //---------------------------------------------------------------------------------- 1829 // Module specific Functions Definition 1830 //---------------------------------------------------------------------------------- 1831 1832 // Load default shader (just vertex positioning and texture coloring) 1833 // NOTE: This shader program is used for internal buffers 1834 // NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs 1835 1836 // NOTE: All locations must be reseted to -1 (no location) 1837 1838 // Vertex shader directly defined, no external file required 1839 1840 // Fragment shader directly defined, no external file required 1841 1842 // Precision required for OpenGL ES2 (WebGL) 1843 1844 // NOTE: Compiled vertex/fragment shaders are not deleted, 1845 // they are kept for re-use as default shaders in case some shader loading fails 1846 // Compile default vertex shader 1847 // Compile default fragment shader 1848 1849 // Set default shader locations: attributes locations 1850 1851 // Set default shader locations: uniform locations 1852 1853 // Unload default shader 1854 // NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs 1855 1856 // Get compressed format official GL identifier name 1857 1858 // GL_EXT_texture_compression_s3tc 1859 1860 // GL_3DFX_texture_compression_FXT1 1861 1862 // GL_IMG_texture_compression_pvrtc 1863 1864 // GL_OES_compressed_ETC1_RGB8_texture 1865 1866 // GL_ARB_texture_compression_rgtc 1867 1868 // GL_ARB_texture_compression_bptc 1869 1870 // GL_ARB_ES3_compatibility 1871 1872 // GL_KHR_texture_compression_astc_hdr 1873 1874 // RLGL_SHOW_GL_DETAILS_INFO 1875 1876 // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 1877 1878 // Mipmaps data is generated after image data 1879 // NOTE: Only works with RGBA (4 bytes) data! 1880 1881 // Required mipmap levels count (including base level) 1882 1883 // Size in bytes (will include mipmaps...), RGBA only 1884 1885 // Count mipmap levels required 1886 1887 // Add mipmap size (in bytes) 1888 1889 // RGBA: 4 bytes 1890 1891 // Generate mipmaps 1892 // NOTE: Every mipmap data is stored after data (RGBA - 4 bytes) 1893 1894 // Size of last mipmap 1895 1896 // Mipmap size to store after offset 1897 1898 // Add mipmap to data 1899 1900 // free mipmap data 1901 1902 // Manual mipmap generation (basic scaling algorithm) 1903 1904 // Scaling algorithm works perfectly (box-filter) 1905 1906 // GRAPHICS_API_OPENGL_11 1907 1908 // Get pixel data size in bytes (image or texture) 1909 // NOTE: Size depends on pixel format 1910 1911 // Size in bytes 1912 // Bits per pixel 1913 1914 // Total data size in bytes 1915 1916 // Most compressed formats works on 4x4 blocks, 1917 // if texture is smaller, minimum dataSize is 8 or 16 1918 1919 // Auxiliar math functions 1920 1921 // Get identity matrix 1922 1923 // Get two matrix multiplication 1924 // NOTE: When multiplying matrices... the order matters! 1925 1926 // RLGL_IMPLEMENTATION