Skip to content

Commit

Permalink
Reduce the number of operator[] calls in Debug
Browse files Browse the repository at this point in the history
This makes loading 1M objects ~800ms faster in Debug.
  • Loading branch information
zeux committed Nov 12, 2018
1 parent c347df8 commit f40e84a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/niagara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,21 +582,23 @@ int main(int argc, const char** argv)

for (uint32_t i = 0; i < drawCount; ++i)
{
MeshDraw& draw = draws[i];

size_t meshIndex = rand() % geometry.meshes.size();
const Mesh& mesh = geometry.meshes[meshIndex];

draws[i].position[0] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draws[i].position[1] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draws[i].position[2] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draws[i].scale = (float(rand()) / RAND_MAX) + 1;
draw.position[0] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draw.position[1] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draw.position[2] = (float(rand()) / RAND_MAX) * sceneRadius * 2 - sceneRadius;
draw.scale = (float(rand()) / RAND_MAX) + 1;

vec3 axis((float(rand()) / RAND_MAX) * 2 - 1, (float(rand()) / RAND_MAX) * 2 - 1, (float(rand()) / RAND_MAX) * 2 - 1);
float angle = glm::radians((float(rand()) / RAND_MAX) * 90.f);

draws[i].orientation = rotate(quat(1, 0, 0, 0), angle, axis);
draw.orientation = rotate(quat(1, 0, 0, 0), angle, axis);

draws[i].meshIndex = uint32_t(meshIndex);
draws[i].vertexOffset = mesh.vertexOffset;
draw.meshIndex = uint32_t(meshIndex);
draw.vertexOffset = mesh.vertexOffset;
}

Buffer db = {};
Expand Down

0 comments on commit f40e84a

Please sign in to comment.