FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16);
FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
for (Material material : meshByMaterial.keySet()) {
OpenGLMesh lastMesh = null;
material.enable();
material.setFloat("sunlight", 1.0f);
material.setFloat("blockLight", 1.0f);
material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix());
material.bindTextures();
Set<EntityRef> entities = meshByMaterial.get(material);
lastRendered = entities.size();
for (EntityRef entity : entities) {
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null || meshComp.mesh == null || !worldProvider.isBlockRelevant(location.getWorldPosition())) {
continue;
}
if (meshComp.mesh.isDisposed()) {
logger.error("Attempted to render disposed mesh");
continue;
}
location.getWorldRotation(worldRot);
location.getWorldPosition(worldPos);
float worldScale = location.getWorldScale();
matrixWorldSpace.set(worldRot, worldPos, worldScale);
transWorldSpace.set(matrixWorldSpace);
Vector3f worldPositionCameraSpace = new Vector3f();
worldPositionCameraSpace.sub(worldPos, cameraPosition);
matrixCameraSpace.set(worldRot, worldPositionCameraSpace, worldScale);
AABB aabb = meshComp.mesh.getAABB().transform(transWorldSpace);
if (worldRenderer.isAABBVisible(aabb)) {
if (meshComp.mesh != lastMesh) {
if (lastMesh != null) {
lastMesh.postRender();
}
lastMesh = (OpenGLMesh) meshComp.mesh;
lastMesh.preRender();
}
Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace);
MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44);
material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33);
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
material.setFloat3("colorOffset", meshComp.color.rf(), meshComp.color.gf(), meshComp.color.bf(), true);
material.setFloat("sunlight", worldRenderer.getSunlightValueAt(worldPos), true);
material.setFloat("blockLight", worldRenderer.getBlockLightValueAt(worldPos), true);
lastMesh.doRender();
}
}
if (lastMesh != null) {
lastMesh.postRender();
}
}
}