Update C sources
This commit is contained in:
parent
a460a0fc06
commit
1b0affeed0
96 changed files with 26693 additions and 11843 deletions
666
raylib/rlgl.h
666
raylib/rlgl.h
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl v4.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
* rlgl v4.2 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
*
|
||||
* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
|
||||
* that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...)
|
||||
|
@ -107,7 +107,7 @@
|
|||
#ifndef RLGL_H
|
||||
#define RLGL_H
|
||||
|
||||
#define RLGL_VERSION "4.0"
|
||||
#define RLGL_VERSION "4.2"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
|
@ -243,6 +243,7 @@
|
|||
#define RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST
|
||||
#define RL_TEXTURE_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR
|
||||
#define RL_TEXTURE_FILTER_ANISOTROPIC 0x3000 // Anisotropic filter (custom identifier)
|
||||
#define RL_TEXTURE_MIPMAP_BIAS_RATIO 0x4000 // Texture mipmap bias, percentage ratio (custom identifier)
|
||||
|
||||
#define RL_TEXTURE_WRAP_REPEAT 0x2901 // GL_REPEAT
|
||||
#define RL_TEXTURE_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE
|
||||
|
@ -282,37 +283,23 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef enum {
|
||||
OPENGL_11 = 1,
|
||||
OPENGL_21,
|
||||
OPENGL_33,
|
||||
OPENGL_43,
|
||||
OPENGL_ES_20
|
||||
} rlGlVersion;
|
||||
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
#include <stdbool.h>
|
||||
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||
// Boolean type
|
||||
typedef enum bool { false = 0, true = !false } bool;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL1,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL2,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL3,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL4,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL5,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL6,
|
||||
RL_ATTACHMENT_COLOR_CHANNEL7,
|
||||
RL_ATTACHMENT_DEPTH = 100,
|
||||
RL_ATTACHMENT_STENCIL = 200,
|
||||
} rlFramebufferAttachType;
|
||||
|
||||
typedef enum {
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X,
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y,
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y,
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z,
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z,
|
||||
RL_ATTACHMENT_TEXTURE2D = 100,
|
||||
RL_ATTACHMENT_RENDERBUFFER = 200,
|
||||
} rlFramebufferAttachTextureType;
|
||||
#if !defined(RL_MATRIX_TYPE)
|
||||
// Matrix, 4x4 components, column major, OpenGL style, right handed
|
||||
typedef struct Matrix {
|
||||
float m0, m4, m8, m12; // Matrix first row (4 components)
|
||||
float m1, m5, m9, m13; // Matrix second row (4 components)
|
||||
float m2, m6, m10, m14; // Matrix third row (4 components)
|
||||
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
||||
} Matrix;
|
||||
#define RL_MATRIX_TYPE
|
||||
#endif
|
||||
|
||||
// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
|
||||
typedef struct rlVertexBuffer {
|
||||
|
@ -343,8 +330,8 @@ typedef struct rlDrawCall {
|
|||
//unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShaderId
|
||||
unsigned int textureId; // Texture id to be used on the draw -> Use to create new draw call if changes
|
||||
|
||||
//Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default
|
||||
//Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default
|
||||
//Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default
|
||||
//Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default
|
||||
} rlDrawCall;
|
||||
|
||||
// rlRenderBatch type
|
||||
|
@ -358,38 +345,30 @@ typedef struct rlRenderBatch {
|
|||
float currentDepth; // Current depth value for next draw
|
||||
} rlRenderBatch;
|
||||
|
||||
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
#include <stdbool.h>
|
||||
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||
// Boolean type
|
||||
typedef enum bool { false = 0, true = !false } bool;
|
||||
#endif
|
||||
|
||||
#if !defined(RL_MATRIX_TYPE)
|
||||
// Matrix, 4x4 components, column major, OpenGL style, right handed
|
||||
typedef struct Matrix {
|
||||
float m0, m4, m8, m12; // Matrix first row (4 components)
|
||||
float m1, m5, m9, m13; // Matrix second row (4 components)
|
||||
float m2, m6, m10, m14; // Matrix third row (4 components)
|
||||
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
||||
} Matrix;
|
||||
#define RL_MATRIX_TYPE
|
||||
#endif
|
||||
// OpenGL version
|
||||
typedef enum {
|
||||
RL_OPENGL_11 = 1, // OpenGL 1.1
|
||||
RL_OPENGL_21, // OpenGL 2.1 (GLSL 120)
|
||||
RL_OPENGL_33, // OpenGL 3.3 (GLSL 330)
|
||||
RL_OPENGL_43, // OpenGL 4.3 (using GLSL 330)
|
||||
RL_OPENGL_ES_20 // OpenGL ES 2.0 (GLSL 100)
|
||||
} rlGlVersion;
|
||||
|
||||
// Trace log level
|
||||
// NOTE: Organized by priority level
|
||||
typedef enum {
|
||||
RL_LOG_ALL = 0, // Display all logs
|
||||
RL_LOG_TRACE, // Trace logging, intended for internal use only
|
||||
RL_LOG_DEBUG, // Debug logging, used for internal debugging, it should be disabled on release builds
|
||||
RL_LOG_INFO, // Info logging, used for program execution info
|
||||
RL_LOG_WARNING, // Warning logging, used on recoverable failures
|
||||
RL_LOG_ERROR, // Error logging, used on unrecoverable failures
|
||||
RL_LOG_FATAL, // Fatal logging, used to abort program: exit(EXIT_FAILURE)
|
||||
RL_LOG_NONE // Disable logging
|
||||
RL_LOG_ALL = 0, // Display all logs
|
||||
RL_LOG_TRACE, // Trace logging, intended for internal use only
|
||||
RL_LOG_DEBUG, // Debug logging, used for internal debugging, it should be disabled on release builds
|
||||
RL_LOG_INFO, // Info logging, used for program execution info
|
||||
RL_LOG_WARNING, // Warning logging, used on recoverable failures
|
||||
RL_LOG_ERROR, // Error logging, used on unrecoverable failures
|
||||
RL_LOG_FATAL, // Fatal logging, used to abort program: exit(EXIT_FAILURE)
|
||||
RL_LOG_NONE // Disable logging
|
||||
} rlTraceLogLevel;
|
||||
|
||||
// Texture formats (support depends on OpenGL version)
|
||||
// Texture pixel formats
|
||||
// NOTE: Support depends on OpenGL version
|
||||
typedef enum {
|
||||
RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
||||
RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels)
|
||||
|
@ -418,79 +397,107 @@ typedef enum {
|
|||
// NOTE 1: Filtering considers mipmaps if available in the texture
|
||||
// NOTE 2: Filter is accordingly set for minification and magnification
|
||||
typedef enum {
|
||||
RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation
|
||||
RL_TEXTURE_FILTER_BILINEAR, // Linear filtering
|
||||
RL_TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
|
||||
RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation
|
||||
RL_TEXTURE_FILTER_BILINEAR, // Linear filtering
|
||||
RL_TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
|
||||
RL_TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
|
||||
} rlTextureFilter;
|
||||
|
||||
// Color blending modes (pre-defined)
|
||||
typedef enum {
|
||||
RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
||||
RL_BLEND_ADDITIVE, // Blend textures adding colors
|
||||
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
|
||||
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
|
||||
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
|
||||
RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
|
||||
RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
|
||||
RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
||||
RL_BLEND_ADDITIVE, // Blend textures adding colors
|
||||
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
|
||||
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
|
||||
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
|
||||
RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
|
||||
RL_BLEND_CUSTOM, // Blend textures using custom src/dst factors (use rlSetBlendFactors())
|
||||
RL_BLEND_CUSTOM_SEPARATE // Blend textures using custom src/dst factors (use rlSetBlendFactorsSeparate())
|
||||
} rlBlendMode;
|
||||
|
||||
// Shader location point type
|
||||
typedef enum {
|
||||
RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
||||
RL_SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
||||
RL_SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02
|
||||
RL_SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal
|
||||
RL_SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent
|
||||
RL_SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color
|
||||
RL_SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection
|
||||
RL_SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform)
|
||||
RL_SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection
|
||||
RL_SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform)
|
||||
RL_SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal
|
||||
RL_SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view
|
||||
RL_SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color
|
||||
RL_SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color
|
||||
RL_SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color
|
||||
RL_SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
|
||||
RL_SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
|
||||
RL_SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal
|
||||
RL_SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
||||
RL_SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
||||
RL_SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
||||
RL_SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
||||
RL_SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
RL_SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
RL_SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
RL_SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
||||
RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
||||
RL_SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
||||
RL_SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02
|
||||
RL_SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal
|
||||
RL_SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent
|
||||
RL_SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color
|
||||
RL_SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection
|
||||
RL_SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform)
|
||||
RL_SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection
|
||||
RL_SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform)
|
||||
RL_SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal
|
||||
RL_SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view
|
||||
RL_SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color
|
||||
RL_SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color
|
||||
RL_SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color
|
||||
RL_SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
|
||||
RL_SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
|
||||
RL_SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal
|
||||
RL_SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
||||
RL_SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
||||
RL_SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
||||
RL_SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
||||
RL_SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
RL_SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
RL_SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
RL_SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
||||
} rlShaderLocationIndex;
|
||||
|
||||
#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO
|
||||
#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS
|
||||
#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO
|
||||
#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS
|
||||
|
||||
// Shader uniform data type
|
||||
typedef enum {
|
||||
RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
|
||||
RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float)
|
||||
RL_SHADER_UNIFORM_VEC3, // Shader uniform type: vec3 (3 float)
|
||||
RL_SHADER_UNIFORM_VEC4, // Shader uniform type: vec4 (4 float)
|
||||
RL_SHADER_UNIFORM_INT, // Shader uniform type: int
|
||||
RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int)
|
||||
RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
||||
RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int)
|
||||
RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
||||
RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
|
||||
RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float)
|
||||
RL_SHADER_UNIFORM_VEC3, // Shader uniform type: vec3 (3 float)
|
||||
RL_SHADER_UNIFORM_VEC4, // Shader uniform type: vec4 (4 float)
|
||||
RL_SHADER_UNIFORM_INT, // Shader uniform type: int
|
||||
RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int)
|
||||
RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
||||
RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int)
|
||||
RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
||||
} rlShaderUniformDataType;
|
||||
|
||||
// Shader attribute data types
|
||||
typedef enum {
|
||||
RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
|
||||
RL_SHADER_ATTRIB_VEC2, // Shader attribute type: vec2 (2 float)
|
||||
RL_SHADER_ATTRIB_VEC3, // Shader attribute type: vec3 (3 float)
|
||||
RL_SHADER_ATTRIB_VEC4 // Shader attribute type: vec4 (4 float)
|
||||
RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
|
||||
RL_SHADER_ATTRIB_VEC2, // Shader attribute type: vec2 (2 float)
|
||||
RL_SHADER_ATTRIB_VEC3, // Shader attribute type: vec3 (3 float)
|
||||
RL_SHADER_ATTRIB_VEC4 // Shader attribute type: vec4 (4 float)
|
||||
} rlShaderAttributeDataType;
|
||||
|
||||
// Framebuffer attachment type
|
||||
// NOTE: By default up to 8 color channels defined but it can be more
|
||||
typedef enum {
|
||||
RL_ATTACHMENT_COLOR_CHANNEL0 = 0, // Framebuffer attachmment type: color 0
|
||||
RL_ATTACHMENT_COLOR_CHANNEL1, // Framebuffer attachmment type: color 1
|
||||
RL_ATTACHMENT_COLOR_CHANNEL2, // Framebuffer attachmment type: color 2
|
||||
RL_ATTACHMENT_COLOR_CHANNEL3, // Framebuffer attachmment type: color 3
|
||||
RL_ATTACHMENT_COLOR_CHANNEL4, // Framebuffer attachmment type: color 4
|
||||
RL_ATTACHMENT_COLOR_CHANNEL5, // Framebuffer attachmment type: color 5
|
||||
RL_ATTACHMENT_COLOR_CHANNEL6, // Framebuffer attachmment type: color 6
|
||||
RL_ATTACHMENT_COLOR_CHANNEL7, // Framebuffer attachmment type: color 7
|
||||
RL_ATTACHMENT_DEPTH = 100, // Framebuffer attachmment type: depth
|
||||
RL_ATTACHMENT_STENCIL = 200, // Framebuffer attachmment type: stencil
|
||||
} rlFramebufferAttachType;
|
||||
|
||||
// Framebuffer texture attachment type
|
||||
typedef enum {
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, // Framebuffer texture attachment type: cubemap, +X side
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, // Framebuffer texture attachment type: cubemap, -X side
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, // Framebuffer texture attachment type: cubemap, +Y side
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, // Framebuffer texture attachment type: cubemap, -Y side
|
||||
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, // Framebuffer texture attachment type: cubemap, +Z side
|
||||
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, // Framebuffer texture attachment type: cubemap, -Z side
|
||||
RL_ATTACHMENT_TEXTURE2D = 100, // Framebuffer texture attachment type: texture2d
|
||||
RL_ATTACHMENT_RENDERBUFFER = 200, // Framebuffer texture attachment type: renderbuffer
|
||||
} rlFramebufferAttachTextureType;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Matrix operations
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -589,23 +596,24 @@ RLAPI void rlClearScreenBuffers(void); // Clear used screen buf
|
|||
RLAPI void rlCheckErrors(void); // Check and log OpenGL error codes
|
||||
RLAPI void rlSetBlendMode(int mode); // Set blending mode
|
||||
RLAPI void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
|
||||
RLAPI void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha); // Set blending mode factors and equations separately (using OpenGL factors)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - rlgl functionality
|
||||
//------------------------------------------------------------------------------------
|
||||
// rlgl initialization functions
|
||||
RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
|
||||
RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
|
||||
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required)
|
||||
RLAPI int rlGetVersion(void); // Get current OpenGL version
|
||||
RLAPI void rlSetFramebufferWidth(int width); // Set current framebuffer width
|
||||
RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width
|
||||
RLAPI void rlSetFramebufferHeight(int height); // Set current framebuffer height
|
||||
RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height
|
||||
RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
|
||||
RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
|
||||
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required)
|
||||
RLAPI int rlGetVersion(void); // Get current OpenGL version
|
||||
RLAPI void rlSetFramebufferWidth(int width); // Set current framebuffer width
|
||||
RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width
|
||||
RLAPI void rlSetFramebufferHeight(int height); // Set current framebuffer height
|
||||
RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height
|
||||
|
||||
RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id
|
||||
RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id
|
||||
RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations
|
||||
RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id
|
||||
RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id
|
||||
RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations
|
||||
|
||||
// Render batch management
|
||||
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
|
||||
|
@ -616,7 +624,8 @@ RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // D
|
|||
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
||||
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
||||
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||
RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits
|
||||
|
||||
RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -671,15 +680,15 @@ RLAPI unsigned int rlLoadComputeShaderProgram(unsigned int shaderId);
|
|||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
|
||||
|
||||
// Shader buffer storage object management (ssbo)
|
||||
RLAPI unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
||||
RLAPI unsigned int rlLoadShaderBuffer(unsigned int size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
||||
RLAPI void rlUnloadShaderBuffer(unsigned int ssboId); // Unload shader storage buffer object (SSBO)
|
||||
RLAPI void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned long long dataSize, unsigned long long offset); // Update SSBO buffer data
|
||||
RLAPI unsigned long long rlGetShaderBufferSize(unsigned int id); // Get SSBO buffer size
|
||||
RLAPI void rlReadShaderBufferElements(unsigned int id, void *dest, unsigned long long count, unsigned long long offset); // Bind SSBO buffer
|
||||
RLAPI void rlBindShaderBuffer(unsigned int id, unsigned int index); // Copy SSBO buffer data
|
||||
RLAPI void rlUpdateShaderBuffer(unsigned int id, const void *data, unsigned int dataSize, unsigned int offset); // Update SSBO buffer data
|
||||
RLAPI void rlBindShaderBuffer(unsigned int id, unsigned int index); // Bind SSBO buffer
|
||||
RLAPI void rlReadShaderBuffer(unsigned int id, void *dest, unsigned int count, unsigned int offset); // Read SSBO buffer data (GPU->CPU)
|
||||
RLAPI void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned int destOffset, unsigned int srcOffset, unsigned int count); // Copy SSBO data between buffers
|
||||
RLAPI unsigned int rlGetShaderBufferSize(unsigned int id); // Get SSBO buffer size
|
||||
|
||||
// Buffer management
|
||||
RLAPI void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned long long destOffset, unsigned long long srcOffset, unsigned long long count); // Copy SSBO buffer data
|
||||
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly); // Bind image texture
|
||||
|
||||
// Matrix state management
|
||||
|
@ -734,16 +743,11 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
|
||||
#include <OpenGL/gl3ext.h> // OpenGL 3 extensions library for OSX
|
||||
#else
|
||||
#define GLAD_MALLOC RL_MALLOC
|
||||
#define GLAD_FREE RL_FREE
|
||||
#define GLAD_MALLOC RL_MALLOC
|
||||
#define GLAD_FREE RL_FREE
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "external/glad.h" // GLAD extensions loading library, includes OpenGL headers
|
||||
#endif
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "external/glad.h" // GLAD extensions loading library, includes OpenGL headers
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
|
@ -924,10 +928,18 @@ typedef struct rlglData {
|
|||
Matrix projectionStereo[2]; // VR stereo rendering eyes projection matrices
|
||||
Matrix viewOffsetStereo[2]; // VR stereo rendering eyes view offset matrices
|
||||
|
||||
// Blending variables
|
||||
int currentBlendMode; // Blending mode active
|
||||
int glBlendSrcFactor; // Blending source factor
|
||||
int glBlendDstFactor; // Blending destination factor
|
||||
int glBlendEquation; // Blending equation
|
||||
int glBlendSrcFactorRGB; // Blending source RGB factor
|
||||
int glBlendDestFactorRGB; // Blending destination RGB factor
|
||||
int glBlendSrcFactorAlpha; // Blending source alpha factor
|
||||
int glBlendDestFactorAlpha; // Blending destination alpha factor
|
||||
int glBlendEquationRGB; // Blending equation for RGB
|
||||
int glBlendEquationAlpha; // Blending equation for alpha
|
||||
bool glCustomBlendModeModified; // Custom blending factor and equation modification status
|
||||
|
||||
int framebufferWidth; // Current framebuffer width
|
||||
int framebufferHeight; // Current framebuffer height
|
||||
|
@ -988,14 +1000,12 @@ static void rlUnloadShaderDefault(void); // Unload default shader
|
|||
static char *rlGetCompressedFormatName(int format); // Get compressed format official GL identifier name
|
||||
#endif // RLGL_SHOW_GL_DETAILS_INFO
|
||||
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
static int rlGenTextureMipmapsData(unsigned char *data, int baseWidth, int baseHeight); // Generate mipmaps data on CPU side
|
||||
static unsigned char *rlGenNextMipmapData(unsigned char *srcData, int srcWidth, int srcHeight); // Generate next mipmap level on CPU side
|
||||
#endif
|
||||
|
||||
static int rlGetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
|
||||
|
||||
// Auxiliar matrix math functions
|
||||
static Matrix rlMatrixIdentity(void); // Get identity matrix
|
||||
static Matrix rlMatrixMultiply(Matrix left, Matrix right); // Multiply two matrices
|
||||
static Matrix rlMatrixIdentity(void); // Get identity matrix
|
||||
static Matrix rlMatrixMultiply(Matrix left, Matrix right); // Multiply two matrices
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Matrix operations
|
||||
|
@ -1306,17 +1316,6 @@ void rlEnd(void)
|
|||
// as well as depth buffer bit-depth (16bit or 24bit or 32bit)
|
||||
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
|
||||
RLGL.currentBatch->currentDepth += (1.0f/20000.0f);
|
||||
|
||||
// Verify internal buffers limits
|
||||
// NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
|
||||
if (RLGL.State.vertexCounter >= (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4))
|
||||
{
|
||||
// WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
|
||||
// we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
|
||||
// If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
|
||||
for (int i = RLGL.State.stackCounter; i >= 0; i--) rlPopMatrix();
|
||||
rlDrawRenderBatch(RLGL.currentBatch);
|
||||
}
|
||||
}
|
||||
|
||||
// Define one vertex (position)
|
||||
|
@ -1335,32 +1334,51 @@ void rlVertex3f(float x, float y, float z)
|
|||
tz = RLGL.State.transform.m2*x + RLGL.State.transform.m6*y + RLGL.State.transform.m10*z + RLGL.State.transform.m14;
|
||||
}
|
||||
|
||||
// Verify that current vertex buffer elements limit has not been reached
|
||||
if (RLGL.State.vertexCounter < (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4))
|
||||
// WARNING: We can't break primitives when launching a new batch.
|
||||
// RL_LINES comes in pairs, RL_TRIANGLES come in groups of 3 vertices and RL_QUADS come in groups of 4 vertices.
|
||||
// We must check current draw.mode when a new vertex is required and finish the batch only if the draw.mode draw.vertexCount is %2, %3 or %4
|
||||
if (RLGL.State.vertexCounter > (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4))
|
||||
{
|
||||
// Add vertices
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter] = tx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 1] = ty;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 2] = tz;
|
||||
|
||||
// Add current texcoord
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy;
|
||||
|
||||
// TODO: Add current normal
|
||||
// By default rlVertexBuffer type does not store normals
|
||||
|
||||
// Add current color
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 1] = RLGL.State.colorg;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 2] = RLGL.State.colorb;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 3] = RLGL.State.colora;
|
||||
|
||||
RLGL.State.vertexCounter++;
|
||||
|
||||
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++;
|
||||
if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) &&
|
||||
(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%2 == 0))
|
||||
{
|
||||
// Reached the maximum number of vertices for RL_LINES drawing
|
||||
// Launch a draw call but keep current state for next vertices comming
|
||||
// NOTE: We add +1 vertex to the check for security
|
||||
rlCheckRenderBatchLimit(2 + 1);
|
||||
}
|
||||
else if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) &&
|
||||
(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%3 == 0))
|
||||
{
|
||||
rlCheckRenderBatchLimit(3 + 1);
|
||||
}
|
||||
else if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_QUADS) &&
|
||||
(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4 == 0))
|
||||
{
|
||||
rlCheckRenderBatchLimit(4 + 1);
|
||||
}
|
||||
}
|
||||
else TRACELOG(RL_LOG_ERROR, "RLGL: Batch elements overflow");
|
||||
|
||||
// Add vertices
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter] = tx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 1] = ty;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 2] = tz;
|
||||
|
||||
// Add current texcoord
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy;
|
||||
|
||||
// TODO: Add current normal
|
||||
// By default rlVertexBuffer type does not store normals
|
||||
|
||||
// Add current color
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 1] = RLGL.State.colorg;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 2] = RLGL.State.colorb;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 3] = RLGL.State.colora;
|
||||
|
||||
RLGL.State.vertexCounter++;
|
||||
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++;
|
||||
}
|
||||
|
||||
// Define one vertex (position)
|
||||
|
@ -1551,6 +1569,9 @@ void rlTextureParameters(unsigned int id, int param, int value)
|
|||
else TRACELOG(RL_LOG_WARNING, "GL: Anisotropic filtering not supported");
|
||||
#endif
|
||||
} break;
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
case RL_TEXTURE_MIPMAP_BIAS_RATIO: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, value/100.0f);
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
@ -1777,7 +1798,7 @@ void rlCheckErrors()
|
|||
void rlSetBlendMode(int mode)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (RLGL.State.currentBlendMode != mode)
|
||||
if (RLGL.State.currentBlendMode != mode || ((mode == RL_BLEND_CUSTOM || mode == RL_BLEND_CUSTOM_SEPARATE) && RLGL.State.glCustomBlendModeModified))
|
||||
{
|
||||
rlDrawRenderBatch(RLGL.currentBatch);
|
||||
|
||||
|
@ -1793,11 +1814,20 @@ void rlSetBlendMode(int mode)
|
|||
{
|
||||
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
|
||||
glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation);
|
||||
|
||||
} break;
|
||||
case RL_BLEND_CUSTOM_SEPARATE:
|
||||
{
|
||||
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactorsSeparate()
|
||||
glBlendFuncSeparate(RLGL.State.glBlendSrcFactorRGB, RLGL.State.glBlendDestFactorRGB, RLGL.State.glBlendSrcFactorAlpha, RLGL.State.glBlendDestFactorAlpha);
|
||||
glBlendEquationSeparate(RLGL.State.glBlendEquationRGB, RLGL.State.glBlendEquationAlpha);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
RLGL.State.currentBlendMode = mode;
|
||||
RLGL.State.glCustomBlendModeModified = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1806,9 +1836,39 @@ void rlSetBlendMode(int mode)
|
|||
void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
||||
RLGL.State.glBlendDstFactor = glDstFactor;
|
||||
RLGL.State.glBlendEquation = glEquation;
|
||||
if ((RLGL.State.glBlendSrcFactor != glSrcFactor) ||
|
||||
(RLGL.State.glBlendDstFactor != glDstFactor) ||
|
||||
(RLGL.State.glBlendEquation != glEquation))
|
||||
{
|
||||
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
||||
RLGL.State.glBlendDstFactor = glDstFactor;
|
||||
RLGL.State.glBlendEquation = glEquation;
|
||||
|
||||
RLGL.State.glCustomBlendModeModified = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set blending mode factor and equation separately for RGB and alpha
|
||||
void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if ((RLGL.State.glBlendSrcFactorRGB != glSrcRGB) ||
|
||||
(RLGL.State.glBlendDestFactorRGB != glDstRGB) ||
|
||||
(RLGL.State.glBlendSrcFactorAlpha != glSrcAlpha) ||
|
||||
(RLGL.State.glBlendDestFactorAlpha != glDstAlpha) ||
|
||||
(RLGL.State.glBlendEquationRGB != glEqRGB) ||
|
||||
(RLGL.State.glBlendEquationAlpha != glEqAlpha))
|
||||
{
|
||||
RLGL.State.glBlendSrcFactorRGB = glSrcRGB;
|
||||
RLGL.State.glBlendDestFactorRGB = glDstRGB;
|
||||
RLGL.State.glBlendSrcFactorAlpha = glSrcAlpha;
|
||||
RLGL.State.glBlendDestFactorAlpha = glDstAlpha;
|
||||
RLGL.State.glBlendEquationRGB = glEqRGB;
|
||||
RLGL.State.glBlendEquationAlpha = glEqAlpha;
|
||||
|
||||
RLGL.State.glCustomBlendModeModified = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1983,10 +2043,8 @@ void rlLoadExtensions(void *loader)
|
|||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) // Also defined for GRAPHICS_API_OPENGL_21
|
||||
// NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
|
||||
#if !defined(__APPLE__)
|
||||
if (gladLoadGL((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL extensions");
|
||||
else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL extensions loaded successfully");
|
||||
#endif
|
||||
if (gladLoadGL((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL extensions");
|
||||
else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL extensions loaded successfully");
|
||||
|
||||
// Get number of supported extensions
|
||||
GLint numExt = 0;
|
||||
|
@ -2000,6 +2058,18 @@ void rlLoadExtensions(void *loader)
|
|||
for (int i = 0; i < numExt; i++) TRACELOG(RL_LOG_INFO, " %s", glGetStringi(GL_EXTENSIONS, i));
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_21)
|
||||
// Register supported extensions flags
|
||||
// Optional OpenGL 2.1 extensions
|
||||
RLGL.ExtSupported.vao = GLAD_GL_ARB_vertex_array_object;
|
||||
RLGL.ExtSupported.instancing = (GLAD_GL_EXT_draw_instanced && GLAD_GL_ARB_instanced_arrays);
|
||||
RLGL.ExtSupported.texNPOT = GLAD_GL_ARB_texture_non_power_of_two;
|
||||
RLGL.ExtSupported.texFloat32 = GLAD_GL_ARB_texture_float;
|
||||
RLGL.ExtSupported.texDepth = GLAD_GL_ARB_depth_texture;
|
||||
RLGL.ExtSupported.maxDepthBits = 32;
|
||||
RLGL.ExtSupported.texAnisoFilter = GLAD_GL_EXT_texture_filter_anisotropic;
|
||||
RLGL.ExtSupported.texMirrorClamp = GLAD_GL_EXT_texture_mirror_clamp;
|
||||
#else
|
||||
// Register supported extensions flags
|
||||
// OpenGL 3.3 extensions supported by default (core)
|
||||
RLGL.ExtSupported.vao = true;
|
||||
|
@ -2010,15 +2080,17 @@ void rlLoadExtensions(void *loader)
|
|||
RLGL.ExtSupported.maxDepthBits = 32;
|
||||
RLGL.ExtSupported.texAnisoFilter = true;
|
||||
RLGL.ExtSupported.texMirrorClamp = true;
|
||||
#endif
|
||||
|
||||
// Optional OpenGL 3.3 extensions
|
||||
RLGL.ExtSupported.texCompASTC = GLAD_GL_KHR_texture_compression_astc_hdr && GLAD_GL_KHR_texture_compression_astc_ldr;
|
||||
RLGL.ExtSupported.texCompDXT = GLAD_GL_EXT_texture_compression_s3tc; // Texture compression: DXT
|
||||
RLGL.ExtSupported.texCompETC2 = GLAD_GL_ARB_ES3_compatibility; // Texture compression: ETC2/EAC
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
if (GLAD_GL_ARB_compute_shader) RLGL.ExtSupported.computeShader = true;
|
||||
if (GLAD_GL_ARB_shader_storage_buffer_object) RLGL.ExtSupported.ssbo = true;
|
||||
#endif
|
||||
#if !defined(__APPLE__)
|
||||
// NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
|
||||
if (GLAD_GL_EXT_texture_compression_s3tc) RLGL.ExtSupported.texCompDXT = true; // Texture compression: DXT
|
||||
if (GLAD_GL_ARB_ES3_compatibility) RLGL.ExtSupported.texCompETC2 = true; // Texture compression: ETC2/EAC
|
||||
RLGL.ExtSupported.computeShader = GLAD_GL_ARB_compute_shader;
|
||||
RLGL.ExtSupported.ssbo = GLAD_GL_ARB_shader_storage_buffer_object;
|
||||
#endif
|
||||
|
||||
#endif // GRAPHICS_API_OPENGL_33
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
|
@ -2184,12 +2256,10 @@ void rlLoadExtensions(void *loader)
|
|||
#else // RLGL_SHOW_GL_DETAILS_INFO
|
||||
|
||||
// Show some basic info about GL supported features
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (RLGL.ExtSupported.vao) TRACELOG(RL_LOG_INFO, "GL: VAO extension detected, VAO functions loaded successfully");
|
||||
else TRACELOG(RL_LOG_WARNING, "GL: VAO extension not found, VAO not supported");
|
||||
if (RLGL.ExtSupported.texNPOT) TRACELOG(RL_LOG_INFO, "GL: NPOT textures extension detected, full NPOT textures supported");
|
||||
else TRACELOG(RL_LOG_WARNING, "GL: NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)");
|
||||
#endif
|
||||
if (RLGL.ExtSupported.texCompDXT) TRACELOG(RL_LOG_INFO, "GL: DXT compressed textures supported");
|
||||
if (RLGL.ExtSupported.texCompETC1) TRACELOG(RL_LOG_INFO, "GL: ETC1 compressed textures supported");
|
||||
if (RLGL.ExtSupported.texCompETC2) TRACELOG(RL_LOG_INFO, "GL: ETC2/EAC compressed textures supported");
|
||||
|
@ -2207,22 +2277,18 @@ int rlGetVersion(void)
|
|||
{
|
||||
int glVersion = 0;
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
glVersion = OPENGL_11;
|
||||
glVersion = RL_OPENGL_11;
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_21)
|
||||
#if defined(__APPLE__)
|
||||
glVersion = OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX
|
||||
#else
|
||||
glVersion = OPENGL_21;
|
||||
#endif
|
||||
glVersion = RL_OPENGL_21;
|
||||
#elif defined(GRAPHICS_API_OPENGL_33)
|
||||
glVersion = OPENGL_33;
|
||||
glVersion = RL_OPENGL_33;
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
glVersion = OPENGL_43;
|
||||
glVersion = RL_OPENGL_43;
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glVersion = OPENGL_ES_20;
|
||||
glVersion = RL_OPENGL_ES_20;
|
||||
#endif
|
||||
return glVersion;
|
||||
}
|
||||
|
@ -2692,10 +2758,12 @@ bool rlCheckRenderBatchLimit(int vCount)
|
|||
if ((RLGL.State.vertexCounter + vCount) >=
|
||||
(RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4))
|
||||
{
|
||||
overflow = true;
|
||||
|
||||
// Store current primitive drawing mode and texture id
|
||||
int currentMode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode;
|
||||
int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId;
|
||||
|
||||
overflow = true;
|
||||
rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside
|
||||
|
||||
// Restore state of last batch so we can continue adding vertices
|
||||
|
@ -3063,6 +3131,7 @@ void rlUnloadTexture(unsigned int id)
|
|||
}
|
||||
|
||||
// Generate mipmap data for selected texture
|
||||
// NOTE: Only supports GPU mipmap generation
|
||||
void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
|
@ -3073,45 +3142,6 @@ void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int
|
|||
if (((width > 0) && ((width & (width - 1)) == 0)) &&
|
||||
((height > 0) && ((height & (height - 1)) == 0))) texIsPOT = true;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
if (texIsPOT)
|
||||
{
|
||||
// WARNING: Manual mipmap generation only works for RGBA 32bit textures!
|
||||
if (format == RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
|
||||
{
|
||||
// Retrieve texture data from VRAM
|
||||
void *texData = rlReadTexturePixels(id, width, height, format);
|
||||
|
||||
// NOTE: Texture data size is reallocated to fit mipmaps data
|
||||
// NOTE: CPU mipmap generation only supports RGBA 32bit data
|
||||
int mipmapCount = rlGenTextureMipmapsData(texData, width, height);
|
||||
|
||||
int size = width*height*4;
|
||||
int offset = size;
|
||||
|
||||
int mipWidth = width/2;
|
||||
int mipHeight = height/2;
|
||||
|
||||
// Load the mipmaps
|
||||
for (int level = 1; level < mipmapCount; level++)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, mipWidth, mipHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)texData + offset);
|
||||
|
||||
size = mipWidth*mipHeight*4;
|
||||
offset += size;
|
||||
|
||||
mipWidth /= 2;
|
||||
mipHeight /= 2;
|
||||
}
|
||||
|
||||
*mipmaps = mipmapCount + 1;
|
||||
RL_FREE(texData); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
|
||||
|
||||
TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Mipmaps generated manually on CPU side, total: %i", id, *mipmaps);
|
||||
}
|
||||
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Failed to generate mipmaps for provided texture format", id);
|
||||
}
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if ((texIsPOT) || (RLGL.ExtSupported.texNPOT))
|
||||
{
|
||||
|
@ -3934,7 +3964,7 @@ void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned
|
|||
}
|
||||
|
||||
// Load shader storage buffer object (SSBO)
|
||||
unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint)
|
||||
unsigned int rlLoadShaderBuffer(unsigned int size, const void *data, int usageHint)
|
||||
{
|
||||
unsigned int ssbo = 0;
|
||||
|
||||
|
@ -3958,7 +3988,7 @@ void rlUnloadShaderBuffer(unsigned int ssboId)
|
|||
}
|
||||
|
||||
// Update SSBO buffer data
|
||||
void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned long long dataSize, unsigned long long offset)
|
||||
void rlUpdateShaderBuffer(unsigned int id, const void *data, unsigned int dataSize, unsigned int offset)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
|
||||
|
@ -3967,7 +3997,7 @@ void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned lo
|
|||
}
|
||||
|
||||
// Get SSBO buffer size
|
||||
unsigned long long rlGetShaderBufferSize(unsigned int id)
|
||||
unsigned int rlGetShaderBufferSize(unsigned int id)
|
||||
{
|
||||
long long size = 0;
|
||||
|
||||
|
@ -3976,11 +4006,11 @@ unsigned long long rlGetShaderBufferSize(unsigned int id)
|
|||
glGetInteger64v(GL_SHADER_STORAGE_BUFFER_SIZE, &size);
|
||||
#endif
|
||||
|
||||
return (size > 0)? size : 0;
|
||||
return (size > 0)? (unsigned int)size : 0;
|
||||
}
|
||||
|
||||
// Read SSBO buffer data
|
||||
void rlReadShaderBufferElements(unsigned int id, void *dest, unsigned long long count, unsigned long long offset)
|
||||
// Read SSBO buffer data (GPU->CPU)
|
||||
void rlReadShaderBuffer(unsigned int id, void *dest, unsigned int count, unsigned int offset)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
|
||||
|
@ -3997,7 +4027,7 @@ void rlBindShaderBuffer(unsigned int id, unsigned int index)
|
|||
}
|
||||
|
||||
// Copy SSBO buffer data
|
||||
void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned long long destOffset, unsigned long long srcOffset, unsigned long long count)
|
||||
void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned int destOffset, unsigned int srcOffset, unsigned int count)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
glBindBuffer(GL_COPY_READ_BUFFER, srcId);
|
||||
|
@ -4501,132 +4531,6 @@ static char *rlGetCompressedFormatName(int format)
|
|||
|
||||
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
// Mipmaps data is generated after image data
|
||||
// NOTE: Only works with RGBA (4 bytes) data!
|
||||
static int rlGenTextureMipmapsData(unsigned char *data, int baseWidth, int baseHeight)
|
||||
{
|
||||
int mipmapCount = 1; // Required mipmap levels count (including base level)
|
||||
int width = baseWidth;
|
||||
int height = baseHeight;
|
||||
int size = baseWidth*baseHeight*4; // Size in bytes (will include mipmaps...), RGBA only
|
||||
|
||||
// Count mipmap levels required
|
||||
while ((width != 1) && (height != 1))
|
||||
{
|
||||
width /= 2;
|
||||
height /= 2;
|
||||
|
||||
TRACELOGD("TEXTURE: Next mipmap size: %i x %i", width, height);
|
||||
|
||||
mipmapCount++;
|
||||
|
||||
size += (width*height*4); // Add mipmap size (in bytes)
|
||||
}
|
||||
|
||||
TRACELOGD("TEXTURE: Total mipmaps required: %i", mipmapCount);
|
||||
TRACELOGD("TEXTURE: Total size of data required: %i", size);
|
||||
|
||||
unsigned char *temp = RL_REALLOC(data, size);
|
||||
|
||||
if (temp != NULL) data = temp;
|
||||
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to re-allocate required mipmaps memory");
|
||||
|
||||
width = baseWidth;
|
||||
height = baseHeight;
|
||||
size = (width*height*4); // RGBA: 4 bytes
|
||||
|
||||
// Generate mipmaps
|
||||
// NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)
|
||||
unsigned char *image = (unsigned char *)RL_MALLOC(width*height*4);
|
||||
unsigned char *mipmap = NULL;
|
||||
int offset = 0;
|
||||
|
||||
for (int i = 0; i < size; i += 4)
|
||||
{
|
||||
image[i] = data[i];
|
||||
image[i + 1] = data[i + 1];
|
||||
image[i + 2] = data[i + 2];
|
||||
image[i + 3] = data[i + 3];
|
||||
}
|
||||
|
||||
TRACELOGD("TEXTURE: Mipmap base size (%ix%i)", width, height);
|
||||
|
||||
for (int mip = 1; mip < mipmapCount; mip++)
|
||||
{
|
||||
mipmap = rlGenNextMipmapData(image, width, height);
|
||||
|
||||
offset += (width*height*4); // Size of last mipmap
|
||||
|
||||
width /= 2;
|
||||
height /= 2;
|
||||
size = (width*height*4); // Mipmap size to store after offset
|
||||
|
||||
// Add mipmap to data
|
||||
for (int i = 0; i < size; i += 4)
|
||||
{
|
||||
data[offset + i] = mipmap[i];
|
||||
data[offset + i + 1] = mipmap[i + 1];
|
||||
data[offset + i + 2] = mipmap[i + 2];
|
||||
data[offset + i + 3] = mipmap[i + 3];
|
||||
}
|
||||
|
||||
RL_FREE(image);
|
||||
|
||||
image = mipmap;
|
||||
mipmap = NULL;
|
||||
}
|
||||
|
||||
RL_FREE(mipmap); // free mipmap data
|
||||
|
||||
return mipmapCount;
|
||||
}
|
||||
|
||||
// Manual mipmap generation (basic scaling algorithm)
|
||||
static unsigned char *rlGenNextMipmapData(unsigned char *srcData, int srcWidth, int srcHeight)
|
||||
{
|
||||
int x2 = 0;
|
||||
int y2 = 0;
|
||||
unsigned char prow[4] = { 0 };
|
||||
unsigned char pcol[4] = { 0 };
|
||||
|
||||
int width = srcWidth/2;
|
||||
int height = srcHeight/2;
|
||||
|
||||
unsigned char *mipmap = (unsigned char *)RL_MALLOC(width*height*4);
|
||||
|
||||
// Scaling algorithm works perfectly (box-filter)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
y2 = 2*y;
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
x2 = 2*x;
|
||||
|
||||
prow[0] = (srcData[(y2*srcWidth + x2)*4 + 0] + srcData[(y2*srcWidth + x2 + 1)*4 + 0])/2;
|
||||
prow[1] = (srcData[(y2*srcWidth + x2)*4 + 1] + srcData[(y2*srcWidth + x2 + 1)*4 + 1])/2;
|
||||
prow[2] = (srcData[(y2*srcWidth + x2)*4 + 2] + srcData[(y2*srcWidth + x2 + 1)*4 + 2])/2;
|
||||
prow[3] = (srcData[(y2*srcWidth + x2)*4 + 3] + srcData[(y2*srcWidth + x2 + 1)*4 + 3])/2;
|
||||
|
||||
pcol[0] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 0] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 0])/2;
|
||||
pcol[1] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 1] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 1])/2;
|
||||
pcol[2] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 2] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 2])/2;
|
||||
pcol[3] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 3] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 3])/2;
|
||||
|
||||
mipmap[(y*width + x)*4 + 0] = (prow[0] + pcol[0])/2;
|
||||
mipmap[(y*width + x)*4 + 1] = (prow[1] + pcol[1])/2;
|
||||
mipmap[(y*width + x)*4 + 2] = (prow[2] + pcol[2])/2;
|
||||
mipmap[(y*width + x)*4 + 3] = (prow[3] + pcol[3])/2;
|
||||
}
|
||||
}
|
||||
|
||||
TRACELOGD("TEXTURE: Mipmap generated successfully (%ix%i)", width, height);
|
||||
|
||||
return mipmap;
|
||||
}
|
||||
#endif // GRAPHICS_API_OPENGL_11
|
||||
|
||||
// Get pixel data size in bytes (image or texture)
|
||||
// NOTE: Size depends on pixel format
|
||||
static int rlGetPixelDataSize(int width, int height, int format)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue