Allow DefaultChunkRenderer to be more extensible #17
No files matched your search
+41
-11
@@ -56,8 +56,35 @@ public abstract class DefaultChunkRenderer extends ShaderChunkRenderer {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
protected void configureShaderInterface() {
|
||||
if (this.activeProgram == null) {
|
||||
throw new IllegalStateException("No active program");
|
||||
}
|
||||
configureShaderInterface(this.activeProgram.getInterface());
|
||||
}
|
||||
|
||||
protected abstract void configureShaderInterface(ChunkShaderInterface shader);
|
||||
|
||||
protected boolean canRender() {
|
||||
return this.activeProgram != null;
|
||||
}
|
||||
|
||||
protected void setMatrices(ChunkRenderMatrices matrices) {
|
||||
if (this.activeProgram == null) {
|
||||
throw new IllegalStateException("No active program");
|
||||
}
|
||||
ChunkShaderInterface shader = this.activeProgram.getInterface();
|
||||
shader.setProjectionMatrix(matrices.projection());
|
||||
shader.setModelViewMatrix(matrices.modelView());
|
||||
}
|
||||
|
||||
protected GlPrimitiveType getPrimitiveType() {
|
||||
if (this.activeProgram == null) {
|
||||
throw new IllegalStateException("No active program");
|
||||
}
|
||||
return this.activeProgram.getInterface().getPrimitiveType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(ChunkRenderMatrices matrices,
|
||||
CommandList commandList,
|
||||
@@ -69,26 +96,25 @@ public abstract class DefaultChunkRenderer extends ShaderChunkRenderer {
|
||||
return;
|
||||
}
|
||||
|
||||
super.begin(renderPass);
|
||||
this.begin(renderPass);
|
||||
|
||||
// Default implementation will check if an active program exists
|
||||
// If there is no active program, shader compilation probably failed, and we can't render anything.
|
||||
if (this.activeProgram != null) {
|
||||
if (this.canRender()) {
|
||||
boolean useBlockFaceCulling = this.useBlockFaceCulling();
|
||||
|
||||
GLDebug.pushGroup(770, renderPass.name() + " terrain pass");
|
||||
|
||||
ChunkShaderInterface shader = this.activeProgram.getInterface();
|
||||
shader.setProjectionMatrix(matrices.projection());
|
||||
shader.setModelViewMatrix(matrices.modelView());
|
||||
this.setMatrices(matrices);
|
||||
|
||||
var primitiveType = shader.getPrimitiveType();
|
||||
var primitiveType = this.getPrimitiveType();
|
||||
|
||||
Iterator<ChunkRenderList> iterator = renderLists.iterator(renderPass.isReverseOrder());
|
||||
|
||||
this.currentRenderPass = renderPass;
|
||||
this.currentVertexFormat = this.renderPassConfiguration.getVertexTypeForPass(this.currentRenderPass).getVertexFormat();
|
||||
|
||||
this.configureShaderInterface(shader);
|
||||
this.configureShaderInterface();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
ChunkRenderList renderList = iterator.next();
|
||||
@@ -112,7 +138,7 @@ public abstract class DefaultChunkRenderer extends ShaderChunkRenderer {
|
||||
|
||||
var tessellation = this.prepareTessellation(commandList, region);
|
||||
|
||||
setModelMatrixUniforms(shader, region, camera);
|
||||
this.setModelMatrixUniforms(region, camera);
|
||||
executeDrawBatch(commandList, tessellation, primitiveType, this.batch);
|
||||
}
|
||||
|
||||
@@ -122,7 +148,7 @@ public abstract class DefaultChunkRenderer extends ShaderChunkRenderer {
|
||||
GLDebug.popGroup();
|
||||
}
|
||||
|
||||
super.end(renderPass);
|
||||
this.end(renderPass);
|
||||
}
|
||||
|
||||
private static void fillCommandBuffer(MultiDrawBatch batch,
|
||||
@@ -258,12 +284,16 @@ public abstract class DefaultChunkRenderer extends ShaderChunkRenderer {
|
||||
return planes;
|
||||
}
|
||||
|
||||
private static void setModelMatrixUniforms(ChunkShaderInterface shader, RenderRegion region, CameraTransform camera) {
|
||||
protected void setModelMatrixUniforms(RenderRegion region, CameraTransform camera) {
|
||||
if (this.activeProgram == null) {
|
||||
throw new IllegalStateException("No active program");
|
||||
}
|
||||
|
||||
float x = getCameraTranslation(region.getOriginX(), camera.intX, camera.fracX);
|
||||
float y = getCameraTranslation(region.getOriginY(), camera.intY, camera.fracY);
|
||||
float z = getCameraTranslation(region.getOriginZ(), camera.intZ, camera.fracZ);
|
||||
|
||||
shader.setRegionOffset(x, y, z);
|
||||
this.activeProgram.getInterface().setRegionOffset(x, y, z);
|
||||
}
|
||||
|
||||
private static float getCameraTranslation(int chunkBlockPos, int cameraBlockPos, float cameraPos) {
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public abstract class ShaderChunkRenderer implements ChunkRenderer {
|
||||
|
||||
protected final RenderDevice device;
|
||||
|
||||
protected GlProgram<ChunkShaderInterface> activeProgram;
|
||||
protected @Nullable GlProgram<ChunkShaderInterface> activeProgram;
|
||||
|
||||
public ShaderChunkRenderer(RenderDevice device, RenderPassConfiguration<?> renderPassConfiguration) {
|
||||
this.device = device;
|
||||
|
||||
Reference in new issue
Block a user