REVIEWED: Added new mechanism to avoid data types collision between modules that share same data types and can be used in standalone mode
This commit is contained in:
parent
aeb1a0da84
commit
b4fddf146b
6 changed files with 490 additions and 494 deletions
|
@ -48,14 +48,12 @@
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#define RAYMATH_STANDALONE
|
|
||||||
#define RAYMATH_HEADER_ONLY
|
|
||||||
#include "raymath.h" // Vector3, Quaternion and Matrix functionality
|
|
||||||
|
|
||||||
#define RLGL_IMPLEMENTATION
|
#define RLGL_IMPLEMENTATION
|
||||||
#define RLGL_STANDALONE
|
|
||||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
|
|
||||||
|
#define RAYMATH_STATIC_INLINE
|
||||||
|
#include "raymath.h" // Vector3, Quaternion and Matrix functionality
|
||||||
|
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
#define GLFW_INCLUDE_ES2
|
#define GLFW_INCLUDE_ES2
|
||||||
#endif
|
#endif
|
||||||
|
@ -79,21 +77,6 @@ typedef struct Color {
|
||||||
unsigned char a; // Color alpha value
|
unsigned char a; // Color alpha value
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
#if !defined(RAYMATH_STANDALONE)
|
|
||||||
// Vector2, 2 components
|
|
||||||
typedef struct Vector2 {
|
|
||||||
float x; // Vector x component
|
|
||||||
float y; // Vector y component
|
|
||||||
} Vector2;
|
|
||||||
|
|
||||||
// Vector3, 3 components
|
|
||||||
typedef struct Vector3 {
|
|
||||||
float x; // Vector x component
|
|
||||||
float y; // Vector y component
|
|
||||||
float z; // Vector z component
|
|
||||||
} Vector3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Camera type, defines a camera position/orientation in 3d space
|
// Camera type, defines a camera position/orientation in 3d space
|
||||||
typedef struct Camera {
|
typedef struct Camera {
|
||||||
Vector3 position; // Camera position
|
Vector3 position; // Camera position
|
||||||
|
|
30
src/config.h
30
src/config.h
|
@ -106,22 +106,22 @@
|
||||||
|
|
||||||
// Default shader vertex attribute names to set location points
|
// Default shader vertex attribute names to set location points
|
||||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||||
|
|
||||||
#define DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||||
#define DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||||
#define DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||||
#define DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||||
#define 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 DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||||
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||||
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||||
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
30
src/core.c
30
src/core.c
|
@ -2317,25 +2317,25 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
||||||
// NOTE: If any location is not found, loc point becomes -1
|
// NOTE: If any location is not found, loc point becomes -1
|
||||||
|
|
||||||
// Get handles to GLSL input attibute locations
|
// Get handles to GLSL input attibute locations
|
||||||
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||||
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||||
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (vertex shader)
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||||
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_VIEW);
|
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW);
|
||||||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
|
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
|
||||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_MODEL);
|
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL);
|
||||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
|
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
||||||
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0); // SHADER_LOC_MAP_ALBEDO
|
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0); // SHADER_LOC_MAP_ALBEDO
|
||||||
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1); // SHADER_LOC_MAP_METALNESS
|
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1); // SHADER_LOC_MAP_METALNESS
|
||||||
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2);
|
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
|
|
10
src/raylib.h
10
src/raylib.h
|
@ -128,6 +128,16 @@
|
||||||
#define CLITERAL(type) (type)
|
#define CLITERAL(type) (type)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// NOTE: We set some defines with some data types declared by raylib
|
||||||
|
// Other modules (raymath, rlgl) also require some of those types, so,
|
||||||
|
// to be able to use those other modules as standalone (not depending on raylib)
|
||||||
|
// this defines are very useful for internal check and avoid type (re)definitions
|
||||||
|
#define RL_VECTOR2_TYPE
|
||||||
|
#define RL_VECTOR3_TYPE
|
||||||
|
#define RL_VECTOR4_TYPE
|
||||||
|
#define RL_QUATERNION_TYPE
|
||||||
|
#define RL_MATRIX_TYPE
|
||||||
|
|
||||||
// Some Basic Colors
|
// Some Basic Colors
|
||||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||||
#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray
|
#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray
|
||||||
|
|
|
@ -9,14 +9,10 @@
|
||||||
* If not defined, the library is in header only mode and can be included in other headers
|
* If not defined, the library is in header only mode and can be included in other headers
|
||||||
* or source files without problems. But only ONE file should hold the implementation.
|
* or source files without problems. But only ONE file should hold the implementation.
|
||||||
*
|
*
|
||||||
* #define RAYMATH_HEADER_ONLY
|
* #define RAYMATH_STATIC_INLINE
|
||||||
* Define static inline functions code, so #include header suffices for use.
|
* Define static inline functions code, so #include header suffices for use.
|
||||||
* This may use up lots of memory.
|
* This may use up lots of memory.
|
||||||
*
|
*
|
||||||
* #define RAYMATH_STANDALONE
|
|
||||||
* Avoid raylib.h header inclusion in this file.
|
|
||||||
* Vector3 and Matrix data types are defined internally in raymath module.
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
*
|
*
|
||||||
|
@ -42,15 +38,8 @@
|
||||||
#ifndef RAYMATH_H
|
#ifndef RAYMATH_H
|
||||||
#define RAYMATH_H
|
#define RAYMATH_H
|
||||||
|
|
||||||
//#define RAYMATH_STANDALONE // NOTE: To use raymath as standalone lib, just uncomment this line
|
#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
|
||||||
//#define RAYMATH_HEADER_ONLY // NOTE: To compile functions as static inline, uncomment this line
|
#error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
|
||||||
|
|
||||||
#ifndef RAYMATH_STANDALONE
|
|
||||||
#include "raylib.h" // Required for: Vector3, Matrix structs definition
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_HEADER_ONLY)
|
|
||||||
#error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_HEADER_ONLY is contradictory"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(RAYMATH_IMPLEMENTATION)
|
#if defined(RAYMATH_IMPLEMENTATION)
|
||||||
|
@ -61,7 +50,7 @@
|
||||||
#else
|
#else
|
||||||
#define RMDEF extern inline // Provide external definition
|
#define RMDEF extern inline // Provide external definition
|
||||||
#endif
|
#endif
|
||||||
#elif defined(RAYMATH_HEADER_ONLY)
|
#elif defined(RAYMATH_STATIC_INLINE)
|
||||||
#define RMDEF static inline // Functions may be inlined, no external out-of-line definition
|
#define RMDEF static inline // Functions may be inlined, no external out-of-line definition
|
||||||
#else
|
#else
|
||||||
#if defined(__TINYC__)
|
#if defined(__TINYC__)
|
||||||
|
@ -100,38 +89,51 @@
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(RAYMATH_STANDALONE)
|
#if !defined(RL_VECTOR2_TYPE)
|
||||||
// Vector2 type
|
// Vector2 type
|
||||||
typedef struct Vector2 {
|
typedef struct Vector2 {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
} Vector2;
|
} Vector2;
|
||||||
|
#define RL_VECTOR2_TYPE
|
||||||
|
#endif
|
||||||
|
|
||||||
// Vector3 type
|
#if !defined(RL_VECTOR3_TYPE)
|
||||||
typedef struct Vector3 {
|
// Vector3 type
|
||||||
float x;
|
typedef struct Vector3 {
|
||||||
float y;
|
float x;
|
||||||
float z;
|
float y;
|
||||||
} Vector3;
|
float z;
|
||||||
|
} Vector3;
|
||||||
|
#define RL_VECTOR3_TYPE
|
||||||
|
#endif
|
||||||
|
|
||||||
// Vector4 type
|
#if !defined(RL_VECTOR4_TYPE)
|
||||||
typedef struct Vector4 {
|
// Vector4 type
|
||||||
float x;
|
typedef struct Vector4 {
|
||||||
float y;
|
float x;
|
||||||
float z;
|
float y;
|
||||||
float w;
|
float z;
|
||||||
} Vector4;
|
float w;
|
||||||
|
} Vector4;
|
||||||
|
#define RL_VECTOR4_TYPE
|
||||||
|
#endif
|
||||||
|
|
||||||
// Quaternion type
|
#if !defined(RL_QUATERNION_TYPE)
|
||||||
typedef Vector4 Quaternion;
|
// Quaternion type
|
||||||
|
typedef Vector4 Quaternion;
|
||||||
|
#define RL_QUATERNION_TYPE
|
||||||
|
#endif
|
||||||
|
|
||||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
#if !defined(RL_MATRIX_TYPE)
|
||||||
typedef struct Matrix {
|
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||||
float m0, m4, m8, m12;
|
typedef struct Matrix {
|
||||||
float m1, m5, m9, m13;
|
float m0, m4, m8, m12; // Matrix first row (4 components)
|
||||||
float m2, m6, m10, m14;
|
float m1, m5, m9, m13; // Matrix second row (4 components)
|
||||||
float m3, m7, m11, m15;
|
float m2, m6, m10, m14; // Matrix third row (4 components)
|
||||||
} Matrix;
|
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
||||||
|
} Matrix;
|
||||||
|
#define RL_MATRIX_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
|
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
|
||||||
|
|
803
src/rlgl.h
803
src/rlgl.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue