diff options
| author | Ray <[email protected]> | 2021-04-23 09:09:34 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-04-23 09:09:34 +0200 |
| commit | 8a55c60e470412580fd6b526cb9ea1b55fdf6cec (patch) | |
| tree | a2cace01b0bbcaf02c10832a5c0b780153911dbc /examples/shaders | |
| parent | 03815ec4fe0676030838bb91907bf211b178e86e (diff) | |
| download | raylib-8a55c60e470412580fd6b526cb9ea1b55fdf6cec.tar.gz raylib-8a55c60e470412580fd6b526cb9ea1b55fdf6cec.zip | |
Update shaders_mesh_instancing.c
Diffstat (limited to 'examples/shaders')
| -rw-r--r-- | examples/shaders/shaders_mesh_instancing.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/shaders/shaders_mesh_instancing.c b/examples/shaders/shaders_mesh_instancing.c index 290a2948..11662f73 100644 --- a/examples/shaders/shaders_mesh_instancing.c +++ b/examples/shaders/shaders_mesh_instancing.c @@ -27,6 +27,8 @@ #define GLSL_VERSION 100 #endif +#define MAX_INSTANCES 10000 + //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -56,15 +58,14 @@ int main(void) camera.fovy = 45.0f; camera.projection = CAMERA_PERSPECTIVE; - const int instances = 10000; // Number of instances to display Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); - Matrix *rotations = RL_MALLOC(instances*sizeof(Matrix)); // Rotation state of instances - Matrix *rotationsInc = RL_MALLOC(instances*sizeof(Matrix)); // Per-frame rotation animation of instances - Matrix *translations = RL_MALLOC(instances*sizeof(Matrix)); // Locations of instances + Matrix *rotations = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Rotation state of instances + Matrix *rotationsInc = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Per-frame rotation animation of instances + Matrix *translations = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Locations of instances // Scatter random cubes around - for (int i = 0; i < instances; i++) + for (int i = 0; i < MAX_INSTANCES; i++) { x = GetRandomValue(-50, 50); y = GetRandomValue(-50, 50); @@ -81,7 +82,7 @@ int main(void) rotations[i] = MatrixIdentity(); } - Matrix *transforms = RL_MALLOC(instances*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl + Matrix *transforms = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION), TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION)); @@ -146,7 +147,7 @@ int main(void) SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3); // Apply per-instance transformations - for (int i = 0; i < instances; i++) + for (int i = 0; i < MAX_INSTANCES; i++) { rotations[i] = MatrixMultiply(rotations[i], rotationsInc[i]); transforms[i] = MatrixMultiply(rotations[i], translations[i]); @@ -174,7 +175,7 @@ int main(void) BeginMode3D(camera); //DrawMesh(cube, material, MatrixIdentity()); - DrawMeshInstanced(cube, material, transforms, instances); + DrawMeshInstanced(cube, material, transforms, MAX_INSTANCES); EndMode3D(); DrawText("A CUBE OF DANCING CUBES!", 490, 10, 20, MAROON); |
