use of net.minecraft.client.render.BufferBuilder in project sodium-fabric by CaffeineMC.
the class MixinRebuildTask method render.
/**
* @author JellySquid
*/
@Overwrite
private Set<BlockEntity> render(float cameraX, float cameraY, float cameraZ, ChunkBuilder.ChunkData data, BlockBufferBuilderStorage buffers) {
ExtendedChunkData edata = (ExtendedChunkData) data;
BlockPos from = this.parent.getOrigin().toImmutable();
BlockPos to = from.add(15, 15, 15);
ChunkOcclusionDataBuilder occlusion = new ChunkOcclusionDataBuilder();
Set<BlockEntity> set = Sets.newHashSet();
ChunkRendererRegion world = this.region;
Vector3f translation = new Vector3f();
if (world != null) {
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
int minX = from.getX();
int minY = from.getY();
int minZ = from.getZ();
int maxX = to.getX();
int maxY = to.getY();
int maxZ = to.getZ();
BlockPos.Mutable pos = new BlockPos.Mutable();
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) {
pos.set(x, y, z);
BlockState blockState = world.getBlockState(pos);
FluidState fluidState = blockState.getFluidState();
Block block = blockState.getBlock();
if (blockState.isFullOpaque(world, pos)) {
occlusion.markClosed(pos);
}
if (block.hasBlockEntity()) {
BlockEntity entity = world.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
if (entity != null) {
this.addBlockEntity(data, set, entity);
}
}
if (!fluidState.isEmpty()) {
RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
BufferBuilder builder = buffers.get(layer);
if (!builder.isBuilding()) {
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
edata.getInitializedLayers().add(layer);
}
blockRenderManager.renderFluid(pos, world, builder, fluidState);
}
if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
RenderLayer layer = RenderLayers.getBlockLayer(blockState);
BufferBuilder builder = buffers.get(layer);
if (!builder.isBuilding()) {
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
edata.getInitializedLayers().add(layer);
}
translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
this.pipeline.renderBlock(blockState, pos, world, translation, builder, true);
}
}
}
}
for (RenderLayer layer : edata.getInitializedLayers()) {
BufferBuilder builder = buffers.get(layer);
if (layer == RenderLayer.getTranslucent()) {
builder.sortQuads(cameraX - (float) from.getX(), cameraY - (float) from.getY(), cameraZ - (float) from.getZ());
edata.setTranslucentBufferState(builder.popState());
}
builder.end();
if (((ChunkMeshBuilder) builder).isEmpty()) {
continue;
}
edata.getNonEmptyLayers().add(layer);
}
if (edata.getNonEmptyLayers().size() > 0) {
edata.markNonEmpty();
}
}
edata.setOcclusionData(occlusion.build());
this.region = null;
this.pipeline = null;
return set;
}
use of net.minecraft.client.render.BufferBuilder in project sodium-fabric by CaffeineMC.
the class ChunkRenderRebuildTask method generateMesh.
private ChunkMeshInfo generateMesh(VertexBufferCache buffers) {
ChunkMeshInfo info = new ChunkMeshInfo();
ChunkOcclusionDataBuilder occlusionDataBuilder = new ChunkOcclusionDataBuilder();
Vector3f translation = new Vector3f();
BlockPos from = this.render.getOrigin();
BlockPos to = from.add(16, 16, 16);
int minX = from.getX();
int minY = from.getY();
int minZ = from.getZ();
int maxX = to.getX();
int maxY = to.getY();
int maxZ = to.getZ();
BlockPos.Mutable pos = new BlockPos.Mutable();
for (int z = minZ; z < maxZ; z++) {
for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) {
pos.set(x, y, z);
BlockState blockState = this.region.getBlockState(pos);
FluidState fluidState = blockState.getFluidState();
Block block = blockState.getBlock();
if (blockState.isFullOpaque(this.region, pos)) {
occlusionDataBuilder.markClosed(pos);
}
if (block.hasBlockEntity()) {
BlockEntity entity = this.region.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
if (entity != null) {
BlockEntityRenderer<BlockEntity> renderer = BlockEntityRenderDispatcher.INSTANCE.get(entity);
if (renderer != null) {
info.blockEntities.add(entity);
if (renderer.rendersOutsideBoundingBox(entity)) {
info.globalEntities.add(entity);
}
}
}
}
if (!fluidState.isEmpty()) {
RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
BufferBuilder builder = buffers.get(layer);
if (!builder.isBuilding()) {
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
this.fallbackPipeline.renderFluid(pos, this.region, builder, fluidState);
}
if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
RenderLayer layer = RenderLayers.getBlockLayer(blockState);
BufferBuilder builder = buffers.get(layer);
if (!builder.isBuilding()) {
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
this.pipeline.renderBlock(blockState, pos, this.region, translation, builder, true);
}
}
}
}
BufferBuilder.State translucentBufferState = null;
for (RenderLayer layer : RenderLayer.getBlockLayers()) {
BufferBuilder builder = buffers.get(layer);
if (!builder.isBuilding()) {
continue;
}
if (((ChunkMeshBuilder) builder).isEmpty()) {
continue;
}
if (layer == RenderLayer.getTranslucent()) {
builder.sortQuads((float) this.camera.x - (float) from.getX(), (float) this.camera.y - (float) from.getY(), (float) this.camera.z - (float) from.getZ());
translucentBufferState = builder.popState();
}
info.presentLayers.add(layer);
}
info.occlusionGraph = occlusionDataBuilder.build();
info.translucentBufferState = translucentBufferState;
return info;
}
use of net.minecraft.client.render.BufferBuilder in project sodium-fabric by CaffeineMC.
the class ChunkRenderRebuildTask method performBuild.
@Override
public ChunkRenderUploadTask performBuild(VertexBufferCache buffers) {
ChunkMeshInfo meshInfo;
Object2ObjectMap<RenderLayer, BufferUploadData> uploads;
if (this.region == null) {
meshInfo = new ChunkMeshInfo();
meshInfo.occlusionGraph = new ChunkOcclusionData();
meshInfo.occlusionGraph.addOpenEdgeFaces(EnumSet.allOf(Direction.class));
uploads = Object2ObjectMaps.emptyMap();
} else {
meshInfo = this.generateMesh(buffers);
uploads = new Object2ObjectArrayMap<>();
for (RenderLayer layer : meshInfo.presentLayers) {
BufferBuilder builder = buffers.get(layer);
builder.end();
uploads.put(layer, ((CloneableBufferBuilder) builder).copyData());
}
}
return new Result(this.render, meshInfo, uploads);
}
use of net.minecraft.client.render.BufferBuilder in project KiwiClient by TangyKiwi.
the class GlyphPage method drawChar.
public float drawChar(MatrixStack stack, char ch, float x, float y, float red, float blue, float green, float alpha) {
Glyph glyph = glyphCharacterMap.get(ch);
if (glyph == null)
return 0;
float pageX = glyph.x / (float) imgSize;
float pageY = glyph.y / (float) imgSize;
float pageWidth = glyph.width / (float) imgSize;
float pageHeight = glyph.height / (float) imgSize;
float width = glyph.width;
float height = glyph.height;
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE);
bufferBuilder.vertex(stack.peek().getPositionMatrix(), x, y + height, 0).color(red, green, blue, alpha).texture(pageX, pageY + pageHeight).next();
bufferBuilder.vertex(stack.peek().getPositionMatrix(), x + width, y + height, 0).color(red, green, blue, alpha).texture(pageX + pageWidth, pageY + pageHeight).next();
bufferBuilder.vertex(stack.peek().getPositionMatrix(), x + width, y, 0).color(red, green, blue, alpha).texture(pageX + pageWidth, pageY).next();
bufferBuilder.vertex(stack.peek().getPositionMatrix(), x, y, 0).color(red, green, blue, alpha).texture(pageX, pageY).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
return width - 8;
}
use of net.minecraft.client.render.BufferBuilder in project KiwiClient by TangyKiwi.
the class ShaderEffectWrapper method drawFramebufferToMain.
public void drawFramebufferToMain(String framebuffer) {
Framebuffer buffer = getFramebuffer(framebuffer);
Shader blitshader = mc.gameRenderer.blitScreenShader;
blitshader.addSampler("DiffuseSampler", buffer.getColorAttachment());
double w = mc.getWindow().getFramebufferWidth();
double h = mc.getWindow().getFramebufferHeight();
float ws = (float) buffer.viewportWidth / (float) buffer.textureWidth;
float hs = (float) buffer.viewportHeight / (float) buffer.textureHeight;
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
GlStateManager._colorMask(true, true, true, false);
GlStateManager._disableDepthTest();
GlStateManager._depthMask(false);
GlStateManager._viewport(0, 0, (int) w, (int) h);
blitshader.bind();
Tessellator tessellator = RenderSystem.renderThreadTesselator();
BufferBuilder bufferBuilder = tessellator.getBuffer();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
bufferBuilder.vertex(0, h, 0).texture(0f, 0f).color(255, 255, 255, 255).next();
bufferBuilder.vertex(w, h, 0).texture(ws, 0f).color(255, 255, 255, 255).next();
bufferBuilder.vertex(w, 0, 0).texture(ws, hs).color(255, 255, 255, 255).next();
bufferBuilder.vertex(0, 0, 0).texture(0f, hs).color(255, 255, 255, 255).next();
bufferBuilder.end();
BufferRenderer.postDraw(bufferBuilder);
blitshader.unbind();
GlStateManager._depthMask(true);
GlStateManager._colorMask(true, true, true, true);
RenderSystem.disableBlend();
}
Aggregations