use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.
the class RenderableWorldImpl method onChunkUnloaded.
@Override
public void onChunkUnloaded(Vector3i chunkCoordinates) {
if (renderableRegion.encompasses(chunkCoordinates)) {
RenderableChunk chunk;
Iterator<RenderableChunk> iterator = chunksInProximityOfCamera.iterator();
while (iterator.hasNext()) {
chunk = iterator.next();
if (chunk.getPosition().equals(chunkCoordinates)) {
chunk.disposeMesh();
iterator.remove();
break;
}
}
}
}
use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.
the class RenderableWorldImpl method updateChunksInProximity.
/**
* Updates the list of chunks around the player.
*
* @return True if the list was changed
*/
@Override
public boolean updateChunksInProximity(Region3i newRenderableRegion) {
if (!newRenderableRegion.equals(renderableRegion)) {
Vector3i chunkPosition;
RenderableChunk chunk;
Iterator<Vector3i> chunksToRemove = renderableRegion.subtract(newRenderableRegion);
while (chunksToRemove.hasNext()) {
chunkPosition = chunksToRemove.next();
Iterator<RenderableChunk> nearbyChunks = chunksInProximityOfCamera.iterator();
while (nearbyChunks.hasNext()) {
chunk = nearbyChunks.next();
if (chunk.getPosition().equals(chunkPosition)) {
chunk.disposeMesh();
nearbyChunks.remove();
break;
}
}
}
boolean chunksHaveBeenAdded = false;
Iterator<Vector3i> chunksToAdd = newRenderableRegion.subtract(renderableRegion);
while (chunksToAdd.hasNext()) {
chunkPosition = chunksToAdd.next();
chunk = chunkProvider.getChunk(chunkPosition);
if (chunk != null) {
chunksInProximityOfCamera.add(chunk);
chunksHaveBeenAdded = true;
}
}
if (chunksHaveBeenAdded) {
Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
}
renderableRegion = newRenderableRegion;
return true;
}
return false;
}
use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.
the class RenderableWorldImpl method pregenerateChunks.
/**
* @return true if pregeneration is complete
*/
@Override
public boolean pregenerateChunks() {
boolean pregenerationIsComplete = true;
chunkProvider.completeUpdate();
chunkProvider.beginUpdate();
RenderableChunk chunk;
ChunkMesh newMesh;
ChunkView localView;
for (Vector3i chunkCoordinates : calculateRenderableRegion(renderingConfig.getViewDistance())) {
chunk = chunkProvider.getChunk(chunkCoordinates);
if (chunk == null) {
pregenerationIsComplete = false;
} else if (chunk.isDirty()) {
localView = worldProvider.getLocalView(chunkCoordinates);
if (localView == null) {
continue;
}
chunk.setDirty(false);
newMesh = chunkTessellator.generateMesh(localView, ChunkConstants.SIZE_Y, 0);
newMesh.generateVBOs();
if (chunk.hasMesh()) {
chunk.getMesh().dispose();
}
chunk.setMesh(newMesh);
pregenerationIsComplete = false;
break;
}
}
return pregenerationIsComplete;
}
use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.
the class RenderableWorldImpl method queueVisibleChunks.
/**
* Updates the currently visible chunks (in sight of the player).
*/
@Override
public int queueVisibleChunks(boolean isFirstRenderingStageForCurrentFrame) {
PerformanceMonitor.startActivity("Queueing Visible Chunks");
statDirtyChunks = 0;
statVisibleChunks = 0;
statIgnoredPhases = 0;
int processedChunks = 0;
int chunkCounter = 0;
ChunkMesh mesh;
boolean isDynamicShadows = renderingConfig.isDynamicShadows();
for (RenderableChunk chunk : chunksInProximityOfCamera) {
if (isChunkValidForRender(chunk)) {
mesh = chunk.getMesh();
if (isDynamicShadows && isFirstRenderingStageForCurrentFrame && chunkCounter < maxChunksForShadows && isChunkVisibleFromMainLight(chunk)) {
if (triangleCount(mesh, ChunkMesh.RenderPhase.OPAQUE) > 0) {
renderQueues.chunksOpaqueShadow.add(chunk);
} else {
statIgnoredPhases++;
}
}
if (isChunkVisible(chunk)) {
if (triangleCount(mesh, ChunkMesh.RenderPhase.OPAQUE) > 0) {
renderQueues.chunksOpaque.add(chunk);
} else {
statIgnoredPhases++;
}
if (triangleCount(mesh, ChunkMesh.RenderPhase.REFRACTIVE) > 0) {
renderQueues.chunksAlphaBlend.add(chunk);
} else {
statIgnoredPhases++;
}
if (triangleCount(mesh, ChunkMesh.RenderPhase.ALPHA_REJECT) > 0 && chunkCounter < MAX_BILLBOARD_CHUNKS) {
renderQueues.chunksAlphaReject.add(chunk);
} else {
statIgnoredPhases++;
}
statVisibleChunks++;
if (statVisibleChunks < MAX_ANIMATED_CHUNKS) {
chunk.setAnimated(true);
} else {
chunk.setAnimated(false);
}
}
if (isChunkVisibleReflection(chunk)) {
renderQueues.chunksOpaqueReflection.add(chunk);
}
// Process all chunks in the area, not only the visible ones
if (isFirstRenderingStageForCurrentFrame && (chunk.isDirty() || !chunk.hasMesh())) {
statDirtyChunks++;
chunkMeshUpdateManager.queueChunkUpdate(chunk);
processedChunks++;
}
}
chunkCounter++;
}
PerformanceMonitor.endActivity();
return processedChunks;
}
use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.
the class AlphaRejectBlocksNode method process.
/**
* Renders the world's semi-transparent blocks, i.e. tree foliage and terrain plants.
* Does not render fully opaque blocks, i.e. the typical landscape blocks.
*
* Takes advantage of the two methods
*
* - WorldRenderer.increaseTrianglesCount(int)
* - WorldRenderer.increaseNotReadyChunkCount(int)
*
* to publish some statistics over its own activity.
*/
@Override
public void process() {
PerformanceMonitor.startActivity("rendering/" + getUri());
chunkMaterial.activateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
// Common Shader Parameters
chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), true);
// Specific Shader Parameters
// TODO: This is necessary right now because activateFeature removes all material parameters.
// TODO: Remove this explicit binding once we get rid of activateFeature, or find a way to retain parameters through it.
chunkMaterial.setInt("textureAtlas", 0, true);
chunkMaterial.setInt("textureEffects", 1, true);
chunkMaterial.setInt("textureLava", 2, true);
if (normalMappingIsEnabled) {
chunkMaterial.setInt("textureAtlasNormal", 3, true);
if (parallaxMappingIsEnabled) {
chunkMaterial.setInt("textureAtlasHeight", 4, true);
chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
}
}
chunkMaterial.setFloat("clip", 0.0f, true);
// Actual Node Processing
final Vector3f cameraPosition = activeCamera.getPosition();
int numberOfRenderedTriangles = 0;
int numberOfChunksThatAreNotReadyYet = 0;
while (renderQueues.chunksAlphaReject.size() > 0) {
RenderableChunk chunk = renderQueues.chunksAlphaReject.poll();
if (chunk.hasMesh()) {
final ChunkMesh chunkMesh = chunk.getMesh();
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
numberOfRenderedTriangles += chunkMesh.render(ALPHA_REJECT, chunkPosition, cameraPosition);
} else {
// TODO: verify - should we count them only in ChunksOpaqueNode?
numberOfChunksThatAreNotReadyYet++;
}
}
worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
chunkMaterial.deactivateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
PerformanceMonitor.endActivity();
}
Aggregations