aboutsummaryrefslogtreecommitdiff
path: root/src/models.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2017-07-21 09:34:09 +0200
committerraysan5 <raysan5@gmail.com>2017-07-21 09:34:09 +0200
commit2679c4ae9b2fefdb0c150a7cd576d5d3297b027b (patch)
tree31f026ec3d4a0f3a49ecddaa5d9431b61b56de7f /src/models.c
parent63fd96354e7ceffcdf292a1aac6d564dc694377c (diff)
downloadraylib-2679c4ae9b2fefdb0c150a7cd576d5d3297b027b.tar.gz
raylib-2679c4ae9b2fefdb0c150a7cd576d5d3297b027b.zip
Review mesh loading and textures generation
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/models.c b/src/models.c
index 03e0cb45..7dce9fa6 100644
--- a/src/models.c
+++ b/src/models.c
@@ -597,12 +597,13 @@ Model LoadModel(const char *fileName)
}
// Load model from generated mesh
-Model LoadModelFromMesh(Mesh mesh, bool dynamic)
+// WARNING: A shallow copy of mesh is generated, passed by value,
+// as long as struct contains pointers to data and some values, we get a copy
+// of mesh pointing to same data as original version... be careful!
+Model LoadModelFromMesh(Mesh mesh)
{
Model model = { 0 };
- rlLoadMesh(&mesh, dynamic);
-
model.mesh = mesh;
model.transform = MatrixIdentity();
model.material = LoadMaterialDefault();
@@ -646,6 +647,7 @@ void UnloadMesh(Mesh *mesh)
}
// Generated cuboid mesh
+// NOTE: Vertex data is uploaded to GPU
Mesh GenMeshCube(float width, float height, float length)
{
Mesh mesh = { 0 };
@@ -759,11 +761,15 @@ Mesh GenMeshCube(float width, float height, float length)
mesh.vertexCount = 24;
mesh.triangleCount = 12;
+
+ // Upload vertex data to GPU (static mesh)
+ rlLoadMesh(&mesh, false);
return mesh;
}
// Generate a mesh from heightmap
+// NOTE: Vertex data is uploaded to GPU
Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
{
#define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
@@ -865,10 +871,15 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
}
free(pixels);
+
+ // Upload vertex data to GPU (static mesh)
+ rlLoadMesh(&mesh, false);
return mesh;
}
+// Generate a cubes mesh from pixel data
+// NOTE: Vertex data is uploaded to GPU
Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
{
Mesh mesh = { 0 };
@@ -1219,6 +1230,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
free(mapTexcoords);
free(cubicmapPixels); // Free image pixel data
+
+ // Upload vertex data to GPU (static mesh)
+ rlLoadMesh(&mesh, false);
return mesh;
}