summaryrefslogtreecommitdiffhomepage
path: root/src/models.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-05-01 17:31:44 +0200
committerraysan5 <[email protected]>2020-05-01 17:31:44 +0200
commit51c3bef4972047dc9927643fd1f1826970203f7d (patch)
tree361acf41e1a5edb81ff3f2a615884e2fbb08d690 /src/models.c
parent1c15dc72928c55fe01a1ed58c2a1d329eb80029d (diff)
downloadraylib-51c3bef4972047dc9927643fd1f1826970203f7d.tar.gz
raylib-51c3bef4972047dc9927643fd1f1826970203f7d.zip
Review exposed #defines and allow user re-defining
There are multiple #define values around raylib, usually not exposed for redefinition, just reviewed all of them to allow users redefining them on compile time if required. Also, multiple #define have been renamed and commented.
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/models.c b/src/models.c
index 8b013ea5..7e174cae 100644
--- a/src/models.c
+++ b/src/models.c
@@ -92,7 +92,9 @@
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
-#define MAX_MESH_VBO 7 // Maximum number of vbo per mesh
+#ifndef DEFAULT_MESH_VERTEX_BUFFERS
+ #define DEFAULT_MESH_VERTEX_BUFFERS 7 // Number of vertex buffers (VBO) per mesh
+#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
@@ -1224,7 +1226,7 @@ bool IsModelAnimationValid(Model model, ModelAnimation anim)
Mesh GenMeshPoly(int sides, float radius)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
int vertexCount = sides*3;
// Vertices definition
@@ -1287,7 +1289,7 @@ Mesh GenMeshPoly(int sides, float radius)
Mesh GenMeshPlane(float width, float length, int resX, int resZ)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
#define CUSTOM_MESH_GEN_PLANE
#if defined(CUSTOM_MESH_GEN_PLANE)
@@ -1390,7 +1392,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
mesh.vertexCount = plane->ntriangles*3;
mesh.triangleCount = plane->ntriangles;
@@ -1422,7 +1424,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
Mesh GenMeshCube(float width, float height, float length)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
#define CUSTOM_MESH_GEN_CUBE
#if defined(CUSTOM_MESH_GEN_CUBE)
@@ -1588,7 +1590,7 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron
RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings);
par_shapes_scale(sphere, radius, radius, radius);
@@ -1627,7 +1629,7 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings);
par_shapes_scale(sphere, radius, radius, radius);
@@ -1666,7 +1668,7 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
Mesh GenMeshCylinder(float radius, float height, int slices)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
// Instance a cylinder that sits on the Z=0 plane using the given tessellation
// levels across the UV domain. Think of "slices" like a number of pizza
@@ -1726,7 +1728,7 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
if (radius > 1.0f) radius = 1.0f;
else if (radius < 0.1f) radius = 0.1f;
@@ -1769,7 +1771,7 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
if (radius > 3.0f) radius = 3.0f;
else if (radius < 0.5f) radius = 0.5f;
@@ -1813,7 +1815,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
#define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
int mapX = heightmap.width;
int mapZ = heightmap.height;
@@ -1947,7 +1949,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
{
Mesh mesh = { 0 };
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
Color *cubicmapPixels = GetImageData(cubicmap);
@@ -2889,7 +2891,7 @@ static Model LoadOBJ(const char *fileName)
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
- mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
int vCount = 0;
int vtCount = 0;
@@ -3161,7 +3163,7 @@ static Model LoadIQM(const char *fileName)
model.meshes[i].animVertices = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
model.meshes[i].animNormals = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
- model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
}
// Triangles data processing
@@ -3551,7 +3553,7 @@ static Model LoadGLTF(const char *fileName)
model.materials = RL_MALLOC(model.materialCount*sizeof(Material));
model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int));
- for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
+ for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
for (int i = 0; i < model.materialCount - 1; i++)
{