PerformanceMonitor.endActivity();
}
private void renderChunk(RenderableChunk chunk, ChunkMesh.RenderPhase phase, Camera camera, ChunkRenderMode mode) {
if (chunk.getMesh() != null) {
Material shader = null;
final Vector3f cameraPosition = camera.getPosition();
final Vector3f chunkPositionRelToCamera =
new Vector3f(chunk.getPosition().x * ChunkConstants.SIZE_X - cameraPosition.x,
chunk.getPosition().y * ChunkConstants.SIZE_Y - cameraPosition.y,
chunk.getPosition().z * ChunkConstants.SIZE_Z - cameraPosition.z);
if (mode == ChunkRenderMode.DEFAULT || mode == ChunkRenderMode.REFLECTION) {
shader = Assets.getMaterial("engine:prog.chunk");
shader.enable();
if (phase == ChunkMesh.RenderPhase.REFRACTIVE) {
shader.activateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
} else if (phase == ChunkMesh.RenderPhase.ALPHA_REJECT) {
shader.activateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
}
shader.setFloat3("chunkPositionWorld", chunk.getPosition().x * ChunkConstants.SIZE_X,
chunk.getPosition().y * ChunkConstants.SIZE_Y, chunk.getPosition().z * ChunkConstants.SIZE_Z);
shader.setFloat("animated", chunk.isAnimated() ? 1.0f : 0.0f);
if (mode == ChunkRenderMode.REFLECTION) {
shader.setFloat("clip", camera.getClipHeight());
} else {
shader.setFloat("clip", 0.0f);
}
} else if (mode == ChunkRenderMode.SHADOW_MAP) {
shader = Assets.getMaterial("engine:prog.shadowMap");
shader.enable();
} else if (mode == ChunkRenderMode.Z_PRE_PASS) {
CoreRegistry.get(ShaderManager.class).disableShader();
}
GL11.glPushMatrix();
GL11.glTranslatef(chunkPositionRelToCamera.x, chunkPositionRelToCamera.y, chunkPositionRelToCamera.z);
for (int i = 0; i < VERTICAL_SEGMENTS; i++) {
if (!chunk.getMesh()[i].isEmpty()) {
if (config.getRendering().getDebug().isRenderChunkBoundingBoxes()) {
AABBRenderer aabbRenderer = new AABBRenderer(chunk.getSubMeshAABB(i));
aabbRenderer.renderLocally(1f);
statRenderedTriangles += 12;
}
if (shader != null) {
shader.enable();
}
chunk.getMesh()[i].render(phase);
statRenderedTriangles += chunk.getMesh()[i].triangleCount();
}
}
if (mode == ChunkRenderMode.DEFAULT || mode == ChunkRenderMode.REFLECTION) {
// eclipse is paranoid about this - it thinks that shader could be null here
if (shader != null) {
if (phase == ChunkMesh.RenderPhase.REFRACTIVE) {
shader.deactivateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
} else if (phase == ChunkMesh.RenderPhase.ALPHA_REJECT) {
shader.deactivateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
}
}
}
GL11.glPopMatrix();