use of org.terasology.engine.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class ChunkMeshTypeHandler method deserialize.
@Override
public Optional<ChunkMesh> deserialize(PersistedData data) {
List<ByteBuffer> asBuffers = new ArrayList<>();
for (PersistedData datum : data.getAsArray()) {
ByteBuffer buffer = datum.getAsByteBuffer();
ByteBuffer directBuffer = BufferUtils.createByteBuffer(buffer.limit());
directBuffer.put(buffer);
directBuffer.rewind();
asBuffers.add(directBuffer);
}
ChunkMesh result = new ChunkMeshImpl();
for (ChunkMesh.RenderType renderType : ChunkMesh.RenderType.values()) {
result.getVertexElements(renderType).buffer.replace(asBuffers.remove(0));
result.getVertexElements(renderType).indices.replace(asBuffers.remove(0));
}
result.updateMesh();
return Optional.of(result);
}
use of org.terasology.engine.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class RenderableWorldImpl method pregenerateChunks.
/**
* @return true if pregeneration is complete
*/
@Override
public boolean pregenerateChunks() {
boolean pregenerationIsComplete = true;
chunkProvider.update();
Chunk chunk;
ChunkMesh newMesh;
ChunkView localView;
for (Vector3ic 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);
newMesh.updateMesh();
newMesh.discardData();
if (chunk.hasMesh()) {
chunk.getMesh().dispose();
}
chunk.setMesh(newMesh);
pregenerationIsComplete = false;
break;
}
}
return pregenerationIsComplete;
}
use of org.terasology.engine.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class LodChunkProvider method createChunks.
private void createChunks() {
Block unloaded = blockManager.getBlock(BlockManager.UNLOADED_ID);
try {
while (true) {
Vector3ic pos = neededChunks.take();
// Actually the log scale
Integer scale = requiredChunks.get(pos);
if (scale == null) {
// This chunk is being removed in the main thread.
continue;
}
Chunk chunk = new PreLodChunk(scaleDown(pos, scale), blockManager, extraDataManager);
generator.createChunk(chunk, (1 << scale) * (2f / (Chunks.SIZE_X - 2) + 1));
InternalLightProcessor.generateInternalLighting(chunk, 1 << scale);
// tintChunk(chunk);
ChunkView view = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(chunk.getPosition(new Vector3i())), new Vector3i(), unloaded);
ChunkMesh mesh = tessellator.generateMesh(view, 1 << scale, 1);
readyChunks.add(new LodChunk(pos, mesh, scale));
}
} catch (InterruptedException ignored) {
}
}
use of org.terasology.engine.rendering.primitives.ChunkMesh 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;
renderQueues.clear();
ChunkMesh mesh;
boolean isDynamicShadows = renderingConfig.isDynamicShadows();
int billboardLimit = (int) renderingConfig.getBillboardLimit();
List<RenderableChunk> allChunks = new ArrayList<>(chunksInProximityOfCamera);
allChunks.addAll(chunkMeshRenderer.getRenderableChunks());
if (lodChunkProvider != null) {
lodChunkProvider.addAllChunks(allChunks);
}
for (RenderableChunk chunk : allChunks) {
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 && (billboardLimit == 0 || chunkCounter < billboardLimit)) {
renderQueues.chunksAlphaReject.add(chunk);
} else {
statIgnoredPhases++;
}
statVisibleChunks++;
chunk.setAnimated(statVisibleChunks < MAX_ANIMATED_CHUNKS);
}
if (isChunkVisibleReflection(chunk)) {
renderQueues.chunksOpaqueReflection.add(chunk);
}
}
chunkCounter++;
}
if (isFirstRenderingStageForCurrentFrame) {
for (Chunk chunk : chunksInProximityOfCamera) {
if (isChunkValidForRender(chunk) && (chunk.isDirty() || !chunk.hasMesh())) {
statDirtyChunks++;
chunkMeshUpdateManager.queueChunkUpdate(chunk);
processedChunks++;
}
}
}
PerformanceMonitor.endActivity();
return processedChunks;
}
use of org.terasology.engine.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class RenderableWorldImpl method generateVBOs.
@Override
public void generateVBOs() {
PerformanceMonitor.startActivity("Building Mesh VBOs");
ChunkMesh pendingMesh;
chunkMeshUpdateManager.setCameraPosition(playerCamera.getPosition());
for (Chunk chunk : chunkMeshUpdateManager.availableChunksForUpdate()) {
if (chunk.hasPendingMesh() && chunksInProximityOfCamera.contains(chunk)) {
pendingMesh = chunk.getPendingMesh();
pendingMesh.updateMesh();
pendingMesh.discardData();
if (chunk.hasMesh()) {
chunk.getMesh().dispose();
}
chunk.setMesh(pendingMesh);
chunk.setPendingMesh(null);
} else {
if (chunk.hasPendingMesh()) {
chunk.getPendingMesh().dispose();
chunk.setPendingMesh(null);
}
}
}
PerformanceMonitor.endActivity();
}
Aggregations