Update C sources
This commit is contained in:
parent
22ca1484d1
commit
781c207678
27 changed files with 13963 additions and 4637 deletions
235
raylib/rlgl.h
235
raylib/rlgl.h
|
@ -1,15 +1,15 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl v4.2 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
* rlgl v4.5 - 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...)
|
||||
*
|
||||
* When chosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
|
||||
* When choosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
|
||||
* initialized on rlglInit() to accumulate vertex data.
|
||||
*
|
||||
* When an internal state change is required all the stored vertex data is renderer in batch,
|
||||
* additioanlly, rlDrawRenderBatchActive() could be called to force flushing of the batch.
|
||||
* additionally, rlDrawRenderBatchActive() could be called to force flushing of the batch.
|
||||
*
|
||||
* Some additional resources are also loaded for convenience, here the complete list:
|
||||
* - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data
|
||||
|
@ -61,12 +61,11 @@
|
|||
* When loading a shader, the following vertex attribute and uniform
|
||||
* location names are tried to be set automatically:
|
||||
*
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
|
@ -85,7 +84,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2022 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -107,7 +106,7 @@
|
|||
#ifndef RLGL_H
|
||||
#define RLGL_H
|
||||
|
||||
#define RLGL_VERSION "4.2"
|
||||
#define RLGL_VERSION "4.5"
|
||||
|
||||
// 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
|
||||
|
@ -264,7 +263,7 @@
|
|||
#define RL_UNSIGNED_BYTE 0x1401 // GL_UNSIGNED_BYTE
|
||||
#define RL_FLOAT 0x1406 // GL_FLOAT
|
||||
|
||||
// Buffer usage hint
|
||||
// GL buffer usage hint
|
||||
#define RL_STREAM_DRAW 0x88E0 // GL_STREAM_DRAW
|
||||
#define RL_STREAM_READ 0x88E1 // GL_STREAM_READ
|
||||
#define RL_STREAM_COPY 0x88E2 // GL_STREAM_COPY
|
||||
|
@ -280,6 +279,39 @@
|
|||
#define RL_VERTEX_SHADER 0x8B31 // GL_VERTEX_SHADER
|
||||
#define RL_COMPUTE_SHADER 0x91B9 // GL_COMPUTE_SHADER
|
||||
|
||||
// GL blending factors
|
||||
#define RL_ZERO 0 // GL_ZERO
|
||||
#define RL_ONE 1 // GL_ONE
|
||||
#define RL_SRC_COLOR 0x0300 // GL_SRC_COLOR
|
||||
#define RL_ONE_MINUS_SRC_COLOR 0x0301 // GL_ONE_MINUS_SRC_COLOR
|
||||
#define RL_SRC_ALPHA 0x0302 // GL_SRC_ALPHA
|
||||
#define RL_ONE_MINUS_SRC_ALPHA 0x0303 // GL_ONE_MINUS_SRC_ALPHA
|
||||
#define RL_DST_ALPHA 0x0304 // GL_DST_ALPHA
|
||||
#define RL_ONE_MINUS_DST_ALPHA 0x0305 // GL_ONE_MINUS_DST_ALPHA
|
||||
#define RL_DST_COLOR 0x0306 // GL_DST_COLOR
|
||||
#define RL_ONE_MINUS_DST_COLOR 0x0307 // GL_ONE_MINUS_DST_COLOR
|
||||
#define RL_SRC_ALPHA_SATURATE 0x0308 // GL_SRC_ALPHA_SATURATE
|
||||
#define RL_CONSTANT_COLOR 0x8001 // GL_CONSTANT_COLOR
|
||||
#define RL_ONE_MINUS_CONSTANT_COLOR 0x8002 // GL_ONE_MINUS_CONSTANT_COLOR
|
||||
#define RL_CONSTANT_ALPHA 0x8003 // GL_CONSTANT_ALPHA
|
||||
#define RL_ONE_MINUS_CONSTANT_ALPHA 0x8004 // GL_ONE_MINUS_CONSTANT_ALPHA
|
||||
|
||||
// GL blending functions/equations
|
||||
#define RL_FUNC_ADD 0x8006 // GL_FUNC_ADD
|
||||
#define RL_MIN 0x8007 // GL_MIN
|
||||
#define RL_MAX 0x8008 // GL_MAX
|
||||
#define RL_FUNC_SUBTRACT 0x800A // GL_FUNC_SUBTRACT
|
||||
#define RL_FUNC_REVERSE_SUBTRACT 0x800B // GL_FUNC_REVERSE_SUBTRACT
|
||||
#define RL_BLEND_EQUATION 0x8009 // GL_BLEND_EQUATION
|
||||
#define RL_BLEND_EQUATION_RGB 0x8009 // GL_BLEND_EQUATION_RGB // (Same as BLEND_EQUATION)
|
||||
#define RL_BLEND_EQUATION_ALPHA 0x883D // GL_BLEND_EQUATION_ALPHA
|
||||
#define RL_BLEND_DST_RGB 0x80C8 // GL_BLEND_DST_RGB
|
||||
#define RL_BLEND_SRC_RGB 0x80C9 // GL_BLEND_SRC_RGB
|
||||
#define RL_BLEND_DST_ALPHA 0x80CA // GL_BLEND_DST_ALPHA
|
||||
#define RL_BLEND_SRC_ALPHA 0x80CB // GL_BLEND_SRC_ALPHA
|
||||
#define RL_BLEND_COLOR 0x8005 // GL_BLEND_COLOR
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -472,18 +504,18 @@ typedef enum {
|
|||
} rlShaderAttributeDataType;
|
||||
|
||||
// Framebuffer attachment type
|
||||
// NOTE: By default up to 8 color channels defined but it can be more
|
||||
// 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
|
||||
RL_ATTACHMENT_COLOR_CHANNEL0 = 0, // Framebuffer attachment type: color 0
|
||||
RL_ATTACHMENT_COLOR_CHANNEL1, // Framebuffer attachment type: color 1
|
||||
RL_ATTACHMENT_COLOR_CHANNEL2, // Framebuffer attachment type: color 2
|
||||
RL_ATTACHMENT_COLOR_CHANNEL3, // Framebuffer attachment type: color 3
|
||||
RL_ATTACHMENT_COLOR_CHANNEL4, // Framebuffer attachment type: color 4
|
||||
RL_ATTACHMENT_COLOR_CHANNEL5, // Framebuffer attachment type: color 5
|
||||
RL_ATTACHMENT_COLOR_CHANNEL6, // Framebuffer attachment type: color 6
|
||||
RL_ATTACHMENT_COLOR_CHANNEL7, // Framebuffer attachment type: color 7
|
||||
RL_ATTACHMENT_DEPTH = 100, // Framebuffer attachment type: depth
|
||||
RL_ATTACHMENT_STENCIL = 200, // Framebuffer attachment type: stencil
|
||||
} rlFramebufferAttachType;
|
||||
|
||||
// Framebuffer texture attachment type
|
||||
|
@ -498,6 +530,12 @@ typedef enum {
|
|||
RL_ATTACHMENT_RENDERBUFFER = 200, // Framebuffer texture attachment type: renderbuffer
|
||||
} rlFramebufferAttachTextureType;
|
||||
|
||||
// Face culling mode
|
||||
typedef enum {
|
||||
RL_CULL_FACE_FRONT = 0,
|
||||
RL_CULL_FACE_BACK
|
||||
} rlCullMode;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Matrix operations
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -508,12 +546,12 @@ extern "C" { // Prevents name mangling of functions
|
|||
|
||||
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
||||
RLAPI void rlPopMatrix(void); // Pop lattest inserted matrix from stack
|
||||
RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack
|
||||
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
||||
RLAPI void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
||||
RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
||||
RLAPI void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlMultMatrixf(const float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area
|
||||
|
@ -559,6 +597,7 @@ RLAPI void rlDisableTexture(void); // Disable texture
|
|||
RLAPI void rlEnableTextureCubemap(unsigned int id); // Enable texture cubemap
|
||||
RLAPI void rlDisableTextureCubemap(void); // Disable texture cubemap
|
||||
RLAPI void rlTextureParameters(unsigned int id, int param, int value); // Set texture parameters (filter, wrap)
|
||||
RLAPI void rlCubemapParameters(unsigned int id, int param, int value); // Set cubemap parameters (filter, wrap)
|
||||
|
||||
// Shader state
|
||||
RLAPI void rlEnableShader(unsigned int id); // Enable shader program
|
||||
|
@ -578,6 +617,7 @@ RLAPI void rlEnableDepthMask(void); // Enable depth write
|
|||
RLAPI void rlDisableDepthMask(void); // Disable depth write
|
||||
RLAPI void rlEnableBackfaceCulling(void); // Enable backface culling
|
||||
RLAPI void rlDisableBackfaceCulling(void); // Disable backface culling
|
||||
RLAPI void rlSetCullFace(int mode); // Set face culling mode
|
||||
RLAPI void rlEnableScissorTest(void); // Enable scissor test
|
||||
RLAPI void rlDisableScissorTest(void); // Disable scissor test
|
||||
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
||||
|
@ -603,7 +643,7 @@ RLAPI void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha,
|
|||
//------------------------------------------------------------------------------------
|
||||
// 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 rlglClose(void); // De-initialize 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
|
||||
|
@ -677,7 +717,7 @@ RLAPI void rlSetShader(unsigned int id, int *locs);
|
|||
|
||||
// Compute shader management
|
||||
RLAPI unsigned int rlLoadComputeShaderProgram(unsigned int shaderId); // Load compute shader program
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
|
||||
|
||||
// Shader buffer storage object management (ssbo)
|
||||
RLAPI unsigned int rlLoadShaderBuffer(unsigned int size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
||||
|
@ -689,7 +729,7 @@ RLAPI void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned
|
|||
RLAPI unsigned int rlGetShaderBufferSize(unsigned int id); // Get SSBO buffer size
|
||||
|
||||
// Buffer management
|
||||
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly); // Bind image texture
|
||||
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, int format, bool readonly); // Bind image texture
|
||||
|
||||
// Matrix state management
|
||||
RLAPI Matrix rlGetMatrixModelview(void); // Get internal modelview matrix
|
||||
|
@ -751,10 +791,17 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
//#include <EGL/egl.h> // EGL library -> not required, platform layer
|
||||
#include <GLES2/gl2.h> // OpenGL ES 2.0 library
|
||||
#include <GLES2/gl2ext.h> // OpenGL ES 2.0 extensions library
|
||||
// NOTE: OpenGL ES 2.0 can be enabled on PLATFORM_DESKTOP,
|
||||
// in that case, functions are loaded from a custom glad for OpenGL ES 2.0
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define GLAD_GLES2_IMPLEMENTATION
|
||||
#include "external/glad_gles2.h"
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
//#include <EGL/egl.h> // EGL library -> not required, platform layer
|
||||
#include <GLES2/gl2.h> // OpenGL ES 2.0 library
|
||||
#include <GLES2/gl2ext.h> // OpenGL ES 2.0 extensions library
|
||||
#endif
|
||||
|
||||
// It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
|
||||
// provided headers (despite being defined in official Khronos GLES2 headers)
|
||||
|
@ -846,22 +893,22 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
|
||||
// Default shader vertex attribute names to set location points
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
#endif
|
||||
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||
|
@ -949,7 +996,8 @@ typedef struct rlglData {
|
|||
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
||||
bool instancing; // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
|
||||
bool texNPOT; // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
|
||||
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
|
||||
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_OES_depth_texture)
|
||||
bool texDepthWebGL; // Depth textures supported WebGL specific (GL_WEBGL_depth_texture)
|
||||
bool texFloat32; // float textures support (32 bit per channel) (GL_OES_texture_float)
|
||||
bool texCompDXT; // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
|
||||
bool texCompETC1; // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
|
||||
|
@ -1041,7 +1089,7 @@ void rlLoadIdentity(void) { glLoadIdentity(); }
|
|||
void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); }
|
||||
void rlRotatef(float angle, float x, float y, float z) { glRotatef(angle, x, y, z); }
|
||||
void rlScalef(float x, float y, float z) { glScalef(x, y, z); }
|
||||
void rlMultMatrixf(float *matf) { glMultMatrixf(matf); }
|
||||
void rlMultMatrixf(const float *matf) { glMultMatrixf(matf); }
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Choose the current matrix to be transformed
|
||||
|
@ -1166,7 +1214,7 @@ void rlScalef(float x, float y, float z)
|
|||
}
|
||||
|
||||
// Multiply the current matrix by another matrix
|
||||
void rlMultMatrixf(float *matf)
|
||||
void rlMultMatrixf(const float *matf)
|
||||
{
|
||||
// Matrix creation from array
|
||||
Matrix mat = { matf[0], matf[4], matf[8], matf[12],
|
||||
|
@ -1578,6 +1626,50 @@ void rlTextureParameters(unsigned int id, int param, int value)
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
// Set cubemap parameters (wrap mode/filter mode)
|
||||
void rlCubemapParameters(unsigned int id, int param, int value)
|
||||
{
|
||||
#if !defined(GRAPHICS_API_OPENGL_11)
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
||||
|
||||
// Reset anisotropy filter, in case it was set
|
||||
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
|
||||
switch (param)
|
||||
{
|
||||
case RL_TEXTURE_WRAP_S:
|
||||
case RL_TEXTURE_WRAP_T:
|
||||
{
|
||||
if (value == RL_TEXTURE_WRAP_MIRROR_CLAMP)
|
||||
{
|
||||
if (RLGL.ExtSupported.texMirrorClamp) glTexParameteri(GL_TEXTURE_CUBE_MAP, param, value);
|
||||
else TRACELOG(RL_LOG_WARNING, "GL: Clamp mirror wrap mode not supported (GL_MIRROR_CLAMP_EXT)");
|
||||
}
|
||||
else glTexParameteri(GL_TEXTURE_CUBE_MAP, param, value);
|
||||
|
||||
} break;
|
||||
case RL_TEXTURE_MAG_FILTER:
|
||||
case RL_TEXTURE_MIN_FILTER: glTexParameteri(GL_TEXTURE_CUBE_MAP, param, value); break;
|
||||
case RL_TEXTURE_FILTER_ANISOTROPIC:
|
||||
{
|
||||
if (value <= RLGL.ExtSupported.maxAnisotropyLevel) glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
|
||||
else if (RLGL.ExtSupported.maxAnisotropyLevel > 0.0f)
|
||||
{
|
||||
TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, (int)RLGL.ExtSupported.maxAnisotropyLevel);
|
||||
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
|
||||
}
|
||||
else TRACELOG(RL_LOG_WARNING, "GL: Anisotropic filtering not supported");
|
||||
} break;
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
case RL_TEXTURE_MIPMAP_BIAS_RATIO: glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_LOD_BIAS, value/100.0f);
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Enable shader program
|
||||
void rlEnableShader(unsigned int id)
|
||||
{
|
||||
|
@ -1671,6 +1763,17 @@ void rlEnableBackfaceCulling(void) { glEnable(GL_CULL_FACE); }
|
|||
// Disable backface culling
|
||||
void rlDisableBackfaceCulling(void) { glDisable(GL_CULL_FACE); }
|
||||
|
||||
// Set face culling mode
|
||||
void rlSetCullFace(int mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case RL_CULL_FACE_BACK: glCullFace(GL_BACK); break;
|
||||
case RL_CULL_FACE_FRONT: glCullFace(GL_FRONT); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable scissor test
|
||||
void rlEnableScissorTest(void) { glEnable(GL_SCISSOR_TEST); }
|
||||
|
||||
|
@ -1798,7 +1901,7 @@ void rlCheckErrors()
|
|||
void rlSetBlendMode(int mode)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (RLGL.State.currentBlendMode != mode || ((mode == RL_BLEND_CUSTOM || mode == RL_BLEND_CUSTOM_SEPARATE) && RLGL.State.glCustomBlendModeModified))
|
||||
if ((RLGL.State.currentBlendMode != mode) || ((mode == RL_BLEND_CUSTOM || mode == RL_BLEND_CUSTOM_SEPARATE) && RLGL.State.glCustomBlendModeModified))
|
||||
{
|
||||
rlDrawRenderBatch(RLGL.currentBatch);
|
||||
|
||||
|
@ -2094,6 +2197,12 @@ void rlLoadExtensions(void *loader)
|
|||
#endif // GRAPHICS_API_OPENGL_33
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
if (gladLoadGLES2((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL ES2.0 functions");
|
||||
else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL ES2.0 loaded successfully");
|
||||
#endif
|
||||
|
||||
// Get supported extensions list
|
||||
GLint numExt = 0;
|
||||
const char **extList = RL_MALLOC(512*sizeof(const char *)); // Allocate 512 strings pointers (2 KB)
|
||||
|
@ -2169,11 +2278,12 @@ void rlLoadExtensions(void *loader)
|
|||
if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) RLGL.ExtSupported.texFloat32 = true;
|
||||
|
||||
// Check depth texture support
|
||||
if ((strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) ||
|
||||
(strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0)) RLGL.ExtSupported.texDepth = true;
|
||||
if (strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) RLGL.ExtSupported.texDepth = true;
|
||||
if (strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0) RLGL.ExtSupported.texDepthWebGL = true; // WebGL requires unsized internal format
|
||||
if (RLGL.ExtSupported.texDepthWebGL) RLGL.ExtSupported.texDepth = true;
|
||||
|
||||
if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) RLGL.ExtSupported.maxDepthBits = 24;
|
||||
if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) RLGL.ExtSupported.maxDepthBits = 32;
|
||||
if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) RLGL.ExtSupported.maxDepthBits = 24; // Not available on WebGL
|
||||
if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) RLGL.ExtSupported.maxDepthBits = 32; // Not available on WebGL
|
||||
|
||||
// Check texture compression support: DXT
|
||||
if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
|
||||
|
@ -2658,7 +2768,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
|||
|
||||
for (int i = 0, vertexOffset = 0; i < batch->drawCounter; i++)
|
||||
{
|
||||
// Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
|
||||
// Bind current draw call texture, activated as GL_TEXTURE0 and Bound to sampler2D texture0 by default
|
||||
glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId);
|
||||
|
||||
if ((batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount);
|
||||
|
@ -2926,7 +3036,7 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,
|
|||
}
|
||||
|
||||
// Load depth texture/renderbuffer (to be attached to fbo)
|
||||
// WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
|
||||
// WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture and WebGL requires WEBGL_depth_texture extensions
|
||||
unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
||||
{
|
||||
unsigned int id = 0;
|
||||
|
@ -2940,9 +3050,14 @@ unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
|||
unsigned int glInternalFormat = GL_DEPTH_COMPONENT;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (RLGL.ExtSupported.maxDepthBits == 32) glInternalFormat = GL_DEPTH_COMPONENT32_OES;
|
||||
else if (RLGL.ExtSupported.maxDepthBits == 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES;
|
||||
else glInternalFormat = GL_DEPTH_COMPONENT16;
|
||||
// WARNING: WebGL platform requires unsized internal format definition (GL_DEPTH_COMPONENT)
|
||||
// while other platforms using OpenGL ES 2.0 require/support sized internal formats depending on the GPU capabilities
|
||||
if (!RLGL.ExtSupported.texDepthWebGL || useRenderBuffer)
|
||||
{
|
||||
if (RLGL.ExtSupported.maxDepthBits == 32) glInternalFormat = GL_DEPTH_COMPONENT32_OES;
|
||||
else if (RLGL.ExtSupported.maxDepthBits == 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES;
|
||||
else glInternalFormat = GL_DEPTH_COMPONENT16;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!useRenderBuffer && RLGL.ExtSupported.texDepth)
|
||||
|
@ -3134,6 +3249,7 @@ void rlUnloadTexture(unsigned int id)
|
|||
// NOTE: Only supports GPU mipmap generation
|
||||
void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
|
||||
// Check if texture is power-of-two (POT)
|
||||
|
@ -3142,7 +3258,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_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if ((texIsPOT) || (RLGL.ExtSupported.texNPOT))
|
||||
{
|
||||
//glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorithm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
|
||||
|
@ -3154,10 +3269,12 @@ void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int
|
|||
*mipmaps = 1 + (int)floor(log(MAX(width, height))/log(2));
|
||||
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Mipmaps generated automatically, total: %i", id, *mipmaps);
|
||||
}
|
||||
#endif
|
||||
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Failed to generate mipmaps", id);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
#else
|
||||
TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] GPU mipmap generation not supported", id);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -3358,7 +3475,7 @@ void rlUnloadFramebuffer(unsigned int id)
|
|||
|
||||
unsigned int depthIdU = (unsigned int)depthId;
|
||||
if (depthType == GL_RENDERBUFFER) glDeleteRenderbuffers(1, &depthIdU);
|
||||
else if (depthType == GL_RENDERBUFFER) glDeleteTextures(1, &depthIdU);
|
||||
else if (depthType == GL_TEXTURE) glDeleteTextures(1, &depthIdU);
|
||||
|
||||
// NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
|
||||
// the texture image is automatically detached from the currently bound framebuffer.
|
||||
|
@ -3625,12 +3742,14 @@ unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode)
|
|||
// NOTE: We detach shader before deletion to make sure memory is freed
|
||||
if (vertexShaderId != RLGL.State.defaultVShaderId)
|
||||
{
|
||||
glDetachShader(id, vertexShaderId);
|
||||
// WARNING: Shader program linkage could fail and returned id is 0
|
||||
if (id > 0) glDetachShader(id, vertexShaderId);
|
||||
glDeleteShader(vertexShaderId);
|
||||
}
|
||||
if (fragmentShaderId != RLGL.State.defaultFShaderId)
|
||||
{
|
||||
glDetachShader(id, fragmentShaderId);
|
||||
// WARNING: Shader program linkage could fail and returned id is 0
|
||||
if (id > 0) glDetachShader(id, fragmentShaderId);
|
||||
glDeleteShader(fragmentShaderId);
|
||||
}
|
||||
|
||||
|
@ -3738,7 +3857,7 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
|||
glAttachShader(program, vShaderId);
|
||||
glAttachShader(program, fShaderId);
|
||||
|
||||
// NOTE: Default attribute shader locations must be binded before linking
|
||||
// NOTE: Default attribute shader locations must be Bound before linking
|
||||
glBindAttribLocation(program, 0, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
glBindAttribLocation(program, 1, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
glBindAttribLocation(program, 2, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
|
@ -4037,7 +4156,7 @@ void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned int de
|
|||
}
|
||||
|
||||
// Bind image texture
|
||||
void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly)
|
||||
void rlBindImageTexture(unsigned int id, unsigned int index, int format, bool readonly)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
unsigned int glInternalFormat = 0, glFormat = 0, glType = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue