Update C sources
This commit is contained in:
parent
2a66186c7d
commit
1868520849
27 changed files with 4582 additions and 2234 deletions
516
raylib/rlgl.h
516
raylib/rlgl.h
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl v4.5 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
* rlgl v5.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
|
||||
|
@ -62,17 +62,17 @@
|
|||
* When loading a shader, the following vertex attributes and uniform
|
||||
* location names are tried to be set automatically:
|
||||
*
|
||||
* #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_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
* #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
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView)))
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
|
@ -85,7 +85,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2014-2024 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,16 +107,17 @@
|
|||
#ifndef RLGL_H
|
||||
#define RLGL_H
|
||||
|
||||
#define RLGL_VERSION "4.5"
|
||||
#define RLGL_VERSION "5.0"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// Function specifiers in case library is build/used as a shared library
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
#if defined(_WIN32)
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
// NOTE: visibility(default) attribute makes symbols "visible" when compiled with -fvisibility=hidden
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __attribute__((visibility("default"))) // We are building the library as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
|
||||
// Function specifiers definition
|
||||
|
@ -318,6 +319,28 @@
|
|||
#define RL_BLEND_SRC_ALPHA 0x80CB // GL_BLEND_SRC_ALPHA
|
||||
#define RL_BLEND_COLOR 0x8005 // GL_BLEND_COLOR
|
||||
|
||||
#define RL_READ_FRAMEBUFFER 0x8CA8 // GL_READ_FRAMEBUFFER
|
||||
#define RL_DRAW_FRAMEBUFFER 0x8CA9 // GL_DRAW_FRAMEBUFFER
|
||||
|
||||
// Default shader vertex attribute locations
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD 1
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL 2
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
@ -346,6 +369,7 @@ typedef struct rlVertexBuffer {
|
|||
|
||||
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *normals; // Vertex normal (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
unsigned int *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
||||
|
@ -354,7 +378,7 @@ typedef struct rlVertexBuffer {
|
|||
unsigned short *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
||||
#endif
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[4]; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
|
||||
unsigned int vboId[5]; // OpenGL Vertex Buffer Objects id (5 types of vertex data)
|
||||
} rlVertexBuffer;
|
||||
|
||||
// Draw call type
|
||||
|
@ -555,30 +579,33 @@ typedef enum {
|
|||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
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 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(const float *matf); // Multiply the current matrix by another matrix
|
||||
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 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(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
|
||||
RLAPI void rlSetClipPlanes(double near, double far); // Set clip planes distances
|
||||
RLAPI double rlGetCullDistanceNear(); // Get cull plane distance near
|
||||
RLAPI double rlGetCullDistanceFar(); // Get cull plane distance far
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
//------------------------------------------------------------------------------------
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -592,13 +619,13 @@ RLAPI bool rlEnableVertexArray(unsigned int vaoId); // Enable vertex array (
|
|||
RLAPI void rlDisableVertexArray(void); // Disable vertex array (VAO, if supported)
|
||||
RLAPI void rlEnableVertexBuffer(unsigned int id); // Enable vertex buffer (VBO)
|
||||
RLAPI void rlDisableVertexBuffer(void); // Disable vertex buffer (VBO)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id);// Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id); // Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index);// Disable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
#endif
|
||||
|
||||
// Textures state
|
||||
|
@ -617,11 +644,13 @@ RLAPI void rlDisableShader(void); // Disable shader progra
|
|||
// Framebuffer state
|
||||
RLAPI void rlEnableFramebuffer(unsigned int id); // Enable render texture (fbo)
|
||||
RLAPI void rlDisableFramebuffer(void); // Disable render texture (fbo), return to default framebuffer
|
||||
RLAPI unsigned int rlGetActiveFramebuffer(void); // Get the currently active render texture (fbo), 0 for default framebuffer
|
||||
RLAPI void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
|
||||
RLAPI void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int bufferMask); // Blit active framebuffer to main framebuffer
|
||||
RLAPI void rlBindFramebuffer(unsigned int target, unsigned int framebuffer); // Bind framebuffer (FBO)
|
||||
|
||||
// General render state
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlDisableColorBlend(void); // Disable color blending
|
||||
RLAPI void rlEnableDepthTest(void); // Enable depth test
|
||||
RLAPI void rlDisableDepthTest(void); // Disable depth test
|
||||
|
@ -629,12 +658,13 @@ 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 rlColorMask(bool r, bool g, bool b, bool a); // Color mask control
|
||||
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
|
||||
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlDisableWireMode(void); // Disable wire mode ( and point ) maybe rename
|
||||
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
||||
RLAPI float rlGetLineWidth(void); // Get the line drawing width
|
||||
|
@ -671,48 +701,48 @@ RLAPI int *rlGetShaderLocsDefault(void); // Get default shader lo
|
|||
// Render batch management
|
||||
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
|
||||
// but this render batch API is exposed in case of custom batches are required
|
||||
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
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 rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
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
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Vertex buffers management
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load a new attributes element buffer
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update GPU buffer with new data
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements with new data
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer);
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
|
||||
RLAPI void rlDrawVertexArray(int offset, int count);
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer);
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances);
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer object
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load vertex buffer elements object
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update vertex buffer object data on GPU buffer
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements data on GPU buffer
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId); // Unload vertex array (vao)
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId); // Unload vertex buffer object
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, int offset); // Set vertex attribute data configuration
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor); // Set vertex attribute data divisor
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value, when attribute to provided
|
||||
RLAPI void rlDrawVertexArray(int offset, int count); // Draw vertex array (currently active vao)
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer); // Draw vertex array elements
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances); // Draw vertex array (currently active vao) with instancing
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances); // Draw vertex array elements with instancing
|
||||
|
||||
// Textures management
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture data
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap data
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update texture with new data on GPU
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
||||
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
||||
RLAPI void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps); // Generate mipmap data for selected texture
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||
|
||||
// Framebuffer management (fbo)
|
||||
RLAPI unsigned int rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI unsigned int rlLoadFramebuffer(void); // Load an empty framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||
|
||||
|
@ -723,14 +753,14 @@ RLAPI unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fSha
|
|||
RLAPI void rlUnloadShaderProgram(unsigned int id); // Unload shader program
|
||||
RLAPI int rlGetLocationUniform(unsigned int shaderId, const char *uniformName); // Get shader location uniform
|
||||
RLAPI int rlGetLocationAttrib(unsigned int shaderId, const char *attribName); // Get shader location attribute
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
|
||||
RLAPI void rlSetUniformSampler(int locIndex, unsigned int textureId); // Set shader value sampler
|
||||
RLAPI void rlSetShader(unsigned int id, int *locs); // Set shader currently active (id and locations)
|
||||
|
||||
// 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 pipeline)
|
||||
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)
|
||||
|
@ -773,6 +803,12 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
|
||||
#if defined(RLGL_IMPLEMENTATION)
|
||||
|
||||
// Expose OpenGL functions from glad in raylib
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define GLAD_API_CALL_EXPORT
|
||||
#define GLAD_API_CALL_EXPORT_BUILD
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
|
@ -891,6 +927,14 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#endif
|
||||
|
||||
#ifndef GL_PROGRAM_POINT_SIZE
|
||||
#define GL_PROGRAM_POINT_SIZE 0x8642
|
||||
#endif
|
||||
|
||||
#ifndef GL_LINE_WIDTH
|
||||
#define GL_LINE_WIDTH 0x0B21
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
|
||||
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
|
||||
|
@ -912,22 +956,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" // Bound by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#endif
|
||||
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||
|
@ -1042,6 +1086,9 @@ typedef void *(*rlglLoadProc)(const char *name); // OpenGL extension functions
|
|||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static double rlCullDistanceNear = RL_CULL_DISTANCE_NEAR;
|
||||
static double rlCullDistanceFar = RL_CULL_DISTANCE_FAR;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
static rlglData RLGL = { 0 };
|
||||
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
||||
|
@ -1072,8 +1119,15 @@ static const char *rlGetCompressedFormatName(int format); // Get compressed form
|
|||
static int rlGetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
|
||||
|
||||
// Auxiliar matrix math functions
|
||||
typedef struct rl_float16 {
|
||||
float v[16];
|
||||
} rl_float16;
|
||||
static rl_float16 rlMatrixToFloatV(Matrix mat); // Get float array of matrix data
|
||||
#define rlMatrixToFloat(mat) (rlMatrixToFloatV(mat).v) // Get float vector for Matrix
|
||||
static Matrix rlMatrixIdentity(void); // Get identity matrix
|
||||
static Matrix rlMatrixMultiply(Matrix left, Matrix right); // Multiply two matrices
|
||||
static Matrix rlMatrixTranspose(Matrix mat); // Transposes provided matrix
|
||||
static Matrix rlMatrixInvert(Matrix mat); // Invert provided matrix
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Matrix operations
|
||||
|
@ -1242,7 +1296,7 @@ void rlMultMatrixf(const float *matf)
|
|||
matf[2], matf[6], matf[10], matf[14],
|
||||
matf[3], matf[7], matf[11], matf[15] };
|
||||
|
||||
*RLGL.State.currentMatrix = rlMatrixMultiply(*RLGL.State.currentMatrix, mat);
|
||||
*RLGL.State.currentMatrix = rlMatrixMultiply(mat, *RLGL.State.currentMatrix);
|
||||
}
|
||||
|
||||
// Multiply the current matrix by a perspective matrix generated by parameters
|
||||
|
@ -1316,6 +1370,25 @@ void rlViewport(int x, int y, int width, int height)
|
|||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
// Set clip planes distances
|
||||
void rlSetClipPlanes(double near, double far)
|
||||
{
|
||||
rlCullDistanceNear = near;
|
||||
rlCullDistanceFar = far;
|
||||
}
|
||||
|
||||
// Get cull plane distance near
|
||||
double rlGetCullDistanceNear(void)
|
||||
{
|
||||
return rlCullDistanceNear;
|
||||
}
|
||||
|
||||
// Get cull plane distance far
|
||||
double rlGetCullDistanceFar(void)
|
||||
{
|
||||
return rlCullDistanceFar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vertex level operations
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -1436,7 +1509,10 @@ void rlVertex3f(float x, float y, float z)
|
|||
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;
|
||||
|
||||
// WARNING: By default rlVertexBuffer struct does not store normals
|
||||
// Add current normal
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter] = RLGL.State.normalx;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter + 1] = RLGL.State.normaly;
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].normals[3*RLGL.State.vertexCounter + 2] = RLGL.State.normalz;
|
||||
|
||||
// Add current color
|
||||
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr;
|
||||
|
@ -1472,9 +1548,26 @@ void rlTexCoord2f(float x, float y)
|
|||
// NOTE: Normals limited to TRIANGLES only?
|
||||
void rlNormal3f(float x, float y, float z)
|
||||
{
|
||||
RLGL.State.normalx = x;
|
||||
RLGL.State.normaly = y;
|
||||
RLGL.State.normalz = z;
|
||||
float normalx = x;
|
||||
float normaly = y;
|
||||
float normalz = z;
|
||||
if (RLGL.State.transformRequired)
|
||||
{
|
||||
normalx = RLGL.State.transform.m0*x + RLGL.State.transform.m4*y + RLGL.State.transform.m8*z;
|
||||
normaly = RLGL.State.transform.m1*x + RLGL.State.transform.m5*y + RLGL.State.transform.m9*z;
|
||||
normalz = RLGL.State.transform.m2*x + RLGL.State.transform.m6*y + RLGL.State.transform.m10*z;
|
||||
}
|
||||
float length = sqrtf(normalx*normalx + normaly*normaly + normalz*normalz);
|
||||
if (length != 0.0f)
|
||||
{
|
||||
float ilength = 1.0f / length;
|
||||
normalx *= ilength;
|
||||
normaly *= ilength;
|
||||
normalz *= ilength;
|
||||
}
|
||||
RLGL.State.normalx = normalx;
|
||||
RLGL.State.normaly = normaly;
|
||||
RLGL.State.normalz = normalz;
|
||||
}
|
||||
|
||||
// Define one vertex (color)
|
||||
|
@ -1713,6 +1806,16 @@ void rlEnableFramebuffer(unsigned int id)
|
|||
#endif
|
||||
}
|
||||
|
||||
// return the active render texture (fbo)
|
||||
unsigned int rlGetActiveFramebuffer(void)
|
||||
{
|
||||
GLint fboId = 0;
|
||||
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES3)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fboId);
|
||||
#endif
|
||||
return fboId;
|
||||
}
|
||||
|
||||
// Disable rendering to texture
|
||||
void rlDisableFramebuffer(void)
|
||||
{
|
||||
|
@ -1729,6 +1832,14 @@ void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX
|
|||
#endif
|
||||
}
|
||||
|
||||
// Bind framebuffer object (fbo)
|
||||
void rlBindFramebuffer(unsigned int target, unsigned int framebuffer)
|
||||
{
|
||||
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
||||
glBindFramebuffer(target, framebuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Activate multiple draw color buffers
|
||||
// NOTE: One color buffer is always active by default
|
||||
void rlActiveDrawBuffers(int count)
|
||||
|
@ -1805,6 +1916,9 @@ void rlEnableBackfaceCulling(void) { glEnable(GL_CULL_FACE); }
|
|||
// Disable backface culling
|
||||
void rlDisableBackfaceCulling(void) { glDisable(GL_CULL_FACE); }
|
||||
|
||||
// Set color mask active for screen read/draw
|
||||
void rlColorMask(bool r, bool g, bool b, bool a) { glColorMask(r, g, b, a); }
|
||||
|
||||
// Set face culling mode
|
||||
void rlSetCullFace(int mode)
|
||||
{
|
||||
|
@ -2122,7 +2236,10 @@ void rlglInit(int width, int height)
|
|||
RLGL.State.currentShaderLocs = RLGL.State.defaultShaderLocs;
|
||||
|
||||
// Init default vertex arrays buffers
|
||||
// Simulate that the default shader has the location RL_SHADER_LOC_VERTEX_NORMAL to bind the normal buffer for the default render batch
|
||||
RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL] = RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL;
|
||||
RLGL.defaultBatch = rlLoadRenderBatch(RL_DEFAULT_BATCH_BUFFERS, RL_DEFAULT_BATCH_BUFFER_ELEMENTS);
|
||||
RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL] = -1;
|
||||
RLGL.currentBatch = &RLGL.defaultBatch;
|
||||
|
||||
// Init stack matrices (emulating OpenGL 1.1)
|
||||
|
@ -2567,6 +2684,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
|||
|
||||
batch.vertexBuffer[i].vertices = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
|
||||
batch.vertexBuffer[i].texcoords = (float *)RL_MALLOC(bufferElements*2*4*sizeof(float)); // 2 float by texcoord, 4 texcoord by quad
|
||||
batch.vertexBuffer[i].normals = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
|
||||
batch.vertexBuffer[i].colors = (unsigned char *)RL_MALLOC(bufferElements*4*4*sizeof(unsigned char)); // 4 float by color, 4 colors by quad
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
batch.vertexBuffer[i].indices = (unsigned int *)RL_MALLOC(bufferElements*6*sizeof(unsigned int)); // 6 int by quad (indices)
|
||||
|
@ -2577,6 +2695,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
|||
|
||||
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].vertices[j] = 0.0f;
|
||||
for (int j = 0; j < (2*4*bufferElements); j++) batch.vertexBuffer[i].texcoords[j] = 0.0f;
|
||||
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].normals[j] = 0.0f;
|
||||
for (int j = 0; j < (4*4*bufferElements); j++) batch.vertexBuffer[i].colors[j] = 0;
|
||||
|
||||
int k = 0;
|
||||
|
@ -2626,16 +2745,23 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
|||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Vertex color buffer (shader-location = 3)
|
||||
// Vertex normal buffer (shader-location = 2)
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferElements*3*4*sizeof(float), batch.vertexBuffer[i].normals, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Vertex color buffer (shader-location = 3)
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferElements*4*4*sizeof(unsigned char), batch.vertexBuffer[i].colors, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
|
||||
// Fill index buffer
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]);
|
||||
glGenBuffers(1, &batch.vertexBuffer[i].vboId[4]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[4]);
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(int), batch.vertexBuffer[i].indices, GL_STATIC_DRAW);
|
||||
#endif
|
||||
|
@ -2690,10 +2816,10 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
|||
if (RLGL.ExtSupported.vao)
|
||||
{
|
||||
glBindVertexArray(batch.vertexBuffer[i].vaoId);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(2);
|
||||
glDisableVertexAttribArray(3);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL);
|
||||
glDisableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
@ -2702,6 +2828,7 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
|||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[1]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
||||
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[4]);
|
||||
|
||||
// Delete VAOs from GPU (VRAM)
|
||||
if (RLGL.ExtSupported.vao) glDeleteVertexArrays(1, &batch.vertexBuffer[i].vaoId);
|
||||
|
@ -2709,6 +2836,7 @@ void rlUnloadRenderBatch(rlRenderBatch batch)
|
|||
// Free vertex arrays memory from CPU (RAM)
|
||||
RL_FREE(batch.vertexBuffer[i].vertices);
|
||||
RL_FREE(batch.vertexBuffer[i].texcoords);
|
||||
RL_FREE(batch.vertexBuffer[i].normals);
|
||||
RL_FREE(batch.vertexBuffer[i].colors);
|
||||
RL_FREE(batch.vertexBuffer[i].indices);
|
||||
}
|
||||
|
@ -2743,8 +2871,13 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
|||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*2*sizeof(float), batch->vertexBuffer[batch->currentBuffer].texcoords);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
// Colors buffer
|
||||
// Normals buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*3*sizeof(float), batch->vertexBuffer[batch->currentBuffer].normals);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].normals, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
// Colors buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*4*sizeof(unsigned char), batch->vertexBuffer[batch->currentBuffer].colors);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer
|
||||
|
||||
|
@ -2797,13 +2930,30 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
|||
|
||||
// Create modelview-projection matrix and upload to shader
|
||||
Matrix matMVP = rlMatrixMultiply(RLGL.State.modelview, RLGL.State.projection);
|
||||
float matMVPfloat[16] = {
|
||||
matMVP.m0, matMVP.m1, matMVP.m2, matMVP.m3,
|
||||
matMVP.m4, matMVP.m5, matMVP.m6, matMVP.m7,
|
||||
matMVP.m8, matMVP.m9, matMVP.m10, matMVP.m11,
|
||||
matMVP.m12, matMVP.m13, matMVP.m14, matMVP.m15
|
||||
};
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MVP], 1, false, matMVPfloat);
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MVP], 1, false, rlMatrixToFloat(matMVP));
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_PROJECTION] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_PROJECTION], 1, false, rlMatrixToFloat(RLGL.State.projection));
|
||||
}
|
||||
|
||||
// WARNING: For the following setup of the view, model, and normal matrices, it is expected that
|
||||
// transformations and rendering occur between rlPushMatrix and rlPopMatrix.
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_VIEW] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_VIEW], 1, false, rlMatrixToFloat(RLGL.State.modelview));
|
||||
}
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MODEL] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MODEL], 1, false, rlMatrixToFloat(RLGL.State.transform));
|
||||
}
|
||||
|
||||
if (RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_NORMAL] != -1)
|
||||
{
|
||||
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_NORMAL], 1, false, rlMatrixToFloat(rlMatrixTranspose(rlMatrixInvert(RLGL.State.transform))));
|
||||
}
|
||||
|
||||
if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId);
|
||||
else
|
||||
|
@ -2818,12 +2968,17 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
|
|||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
|
||||
// Bind vertex attrib: color (shader-location = 3)
|
||||
// Bind vertex attrib: normal (shader-location = 2)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_NORMAL]);
|
||||
|
||||
// Bind vertex attrib: color (shader-location = 3)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[4]);
|
||||
}
|
||||
|
||||
// Setup some default shader values
|
||||
|
@ -3378,7 +3533,6 @@ void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Read texture pixel data
|
||||
void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
||||
{
|
||||
|
@ -3422,7 +3576,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
|||
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
|
||||
// We are using Option 1, just need to care for texture format on retrieval
|
||||
// NOTE: This behaviour could be conditioned by graphic driver...
|
||||
unsigned int fboId = rlLoadFramebuffer(width, height);
|
||||
unsigned int fboId = rlLoadFramebuffer();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
@ -3476,7 +3630,7 @@ unsigned char *rlReadScreenPixels(int width, int height)
|
|||
//-----------------------------------------------------------------------------------------
|
||||
// Load a framebuffer to be used for rendering
|
||||
// NOTE: No textures attached
|
||||
unsigned int rlLoadFramebuffer(int width, int height)
|
||||
unsigned int rlLoadFramebuffer(void)
|
||||
{
|
||||
unsigned int fboId = 0;
|
||||
|
||||
|
@ -3784,10 +3938,14 @@ unsigned int rlLoadVertexArray(void)
|
|||
}
|
||||
|
||||
// Set vertex attribute
|
||||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
|
||||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, int offset)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
||||
// NOTE: Data type could be: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT
|
||||
// Additional types (depends on OpenGL version or extensions):
|
||||
// - GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, GL_FIXED,
|
||||
// - GL_INT_2_10_10_10_REV, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_10F_11F_11F_REV
|
||||
glVertexAttribPointer(index, compSize, type, normalized, stride, (void *)offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -3970,12 +4128,12 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
|||
glAttachShader(program, fShaderId);
|
||||
|
||||
// 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);
|
||||
glBindAttribLocation(program, 3, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, 4, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, 5, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
|
||||
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
|
||||
|
||||
|
@ -4108,7 +4266,14 @@ void rlSetUniformSampler(int locIndex, unsigned int textureId)
|
|||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Check if texture is already active
|
||||
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) if (RLGL.State.activeTextureId[i] == textureId) return;
|
||||
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
if (RLGL.State.activeTextureId[i] == textureId)
|
||||
{
|
||||
glUniform1i(locIndex, 1 + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Register a new active texture for the internal batch system
|
||||
// NOTE: Default texture is always activated as GL_TEXTURE0
|
||||
|
@ -4431,10 +4596,10 @@ void rlLoadDrawQuad(void)
|
|||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
|
||||
|
||||
// Bind vertex attributes (position, texcoords)
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
|
||||
|
||||
// Draw quad
|
||||
glBindVertexArray(quadVAO);
|
||||
|
@ -4505,12 +4670,12 @@ void rlLoadDrawCube(void)
|
|||
|
||||
// Bind vertex attributes (position, normals, texcoords)
|
||||
glBindVertexArray(cubeVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
|
||||
glEnableVertexAttribArray(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
glVertexAttribPointer(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
@ -4658,14 +4823,14 @@ static void rlLoadShaderDefault(void)
|
|||
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Default shader loaded successfully", RLGL.State.defaultShaderId);
|
||||
|
||||
// Set default shader locations: attributes locations
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexPosition");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexTexCoord");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexColor");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
|
||||
// Set default shader locations: uniform locations
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGL.State.defaultShaderId, "mvp");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "colDiffuse");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "texture0");
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
||||
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0);
|
||||
}
|
||||
else TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to load default shader", RLGL.State.defaultShaderId);
|
||||
}
|
||||
|
@ -4817,6 +4982,31 @@ static int rlGetPixelDataSize(int width, int height, int format)
|
|||
|
||||
// Auxiliar math functions
|
||||
|
||||
// Get float array of matrix data
|
||||
static rl_float16 rlMatrixToFloatV(Matrix mat)
|
||||
{
|
||||
rl_float16 result = { 0 };
|
||||
|
||||
result.v[0] = mat.m0;
|
||||
result.v[1] = mat.m1;
|
||||
result.v[2] = mat.m2;
|
||||
result.v[3] = mat.m3;
|
||||
result.v[4] = mat.m4;
|
||||
result.v[5] = mat.m5;
|
||||
result.v[6] = mat.m6;
|
||||
result.v[7] = mat.m7;
|
||||
result.v[8] = mat.m8;
|
||||
result.v[9] = mat.m9;
|
||||
result.v[10] = mat.m10;
|
||||
result.v[11] = mat.m11;
|
||||
result.v[12] = mat.m12;
|
||||
result.v[13] = mat.m13;
|
||||
result.v[14] = mat.m14;
|
||||
result.v[15] = mat.m15;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get identity matrix
|
||||
static Matrix rlMatrixIdentity(void)
|
||||
{
|
||||
|
@ -4856,4 +5046,76 @@ static Matrix rlMatrixMultiply(Matrix left, Matrix right)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Transposes provided matrix
|
||||
static Matrix rlMatrixTranspose(Matrix mat)
|
||||
{
|
||||
Matrix result = { 0 };
|
||||
|
||||
result.m0 = mat.m0;
|
||||
result.m1 = mat.m4;
|
||||
result.m2 = mat.m8;
|
||||
result.m3 = mat.m12;
|
||||
result.m4 = mat.m1;
|
||||
result.m5 = mat.m5;
|
||||
result.m6 = mat.m9;
|
||||
result.m7 = mat.m13;
|
||||
result.m8 = mat.m2;
|
||||
result.m9 = mat.m6;
|
||||
result.m10 = mat.m10;
|
||||
result.m11 = mat.m14;
|
||||
result.m12 = mat.m3;
|
||||
result.m13 = mat.m7;
|
||||
result.m14 = mat.m11;
|
||||
result.m15 = mat.m15;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Invert provided matrix
|
||||
static Matrix rlMatrixInvert(Matrix mat)
|
||||
{
|
||||
Matrix result = { 0 };
|
||||
|
||||
// Cache the matrix values (speed optimization)
|
||||
float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
|
||||
float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
|
||||
float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
|
||||
float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
|
||||
|
||||
float b00 = a00*a11 - a01*a10;
|
||||
float b01 = a00*a12 - a02*a10;
|
||||
float b02 = a00*a13 - a03*a10;
|
||||
float b03 = a01*a12 - a02*a11;
|
||||
float b04 = a01*a13 - a03*a11;
|
||||
float b05 = a02*a13 - a03*a12;
|
||||
float b06 = a20*a31 - a21*a30;
|
||||
float b07 = a20*a32 - a22*a30;
|
||||
float b08 = a20*a33 - a23*a30;
|
||||
float b09 = a21*a32 - a22*a31;
|
||||
float b10 = a21*a33 - a23*a31;
|
||||
float b11 = a22*a33 - a23*a32;
|
||||
|
||||
// Calculate the invert determinant (inlined to avoid double-caching)
|
||||
float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
|
||||
|
||||
result.m0 = (a11*b11 - a12*b10 + a13*b09)*invDet;
|
||||
result.m1 = (-a01*b11 + a02*b10 - a03*b09)*invDet;
|
||||
result.m2 = (a31*b05 - a32*b04 + a33*b03)*invDet;
|
||||
result.m3 = (-a21*b05 + a22*b04 - a23*b03)*invDet;
|
||||
result.m4 = (-a10*b11 + a12*b08 - a13*b07)*invDet;
|
||||
result.m5 = (a00*b11 - a02*b08 + a03*b07)*invDet;
|
||||
result.m6 = (-a30*b05 + a32*b02 - a33*b01)*invDet;
|
||||
result.m7 = (a20*b05 - a22*b02 + a23*b01)*invDet;
|
||||
result.m8 = (a10*b10 - a11*b08 + a13*b06)*invDet;
|
||||
result.m9 = (-a00*b10 + a01*b08 - a03*b06)*invDet;
|
||||
result.m10 = (a30*b04 - a31*b02 + a33*b00)*invDet;
|
||||
result.m11 = (-a20*b04 + a21*b02 - a23*b00)*invDet;
|
||||
result.m12 = (-a10*b09 + a11*b07 - a12*b06)*invDet;
|
||||
result.m13 = (a00*b09 - a01*b07 + a02*b06)*invDet;
|
||||
result.m14 = (-a30*b03 + a31*b01 - a32*b00)*invDet;
|
||||
result.m15 = (a20*b03 - a21*b01 + a22*b00)*invDet;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // RLGL_IMPLEMENTATION
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue