Search in sources :

Example 1 with VertexConsumer

use of com.mojang.blaze3d.vertex.VertexConsumer in project MinecraftForge by MinecraftForge.

the class BakedRenderable method render.

@Override
public void render(PoseStack poseStack, MultiBufferSource bufferSource, Function<ResourceLocation, RenderType> renderTypeFunction, int lightmapCoord, int overlayCoord, float partialTicks, IModelData renderValues) {
    var rt = renderTypeFunction.apply(InventoryMenu.BLOCK_ATLAS);
    VertexConsumer bb = bufferSource.getBuffer(rt);
    for (Direction direction : MODEL_FACINGS) {
        for (BakedQuad quad : model.getQuads(null, direction, rand, renderValues)) {
            bb.putBulkData(poseStack.last(), quad, 1, 1, 1, 1, lightmapCoord, overlayCoord, true);
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Direction(net.minecraft.core.Direction)

Example 2 with VertexConsumer

use of com.mojang.blaze3d.vertex.VertexConsumer in project MinecraftForge by MinecraftForge.

the class IForgeVertexConsumer method putBulkData.

// Copy of putBulkData with alpha support
default void putBulkData(PoseStack.Pose matrixEntry, BakedQuad bakedQuad, float[] baseBrightness, float red, float green, float blue, float alpha, int[] lightmapCoords, int overlayCoords, boolean readExistingColor) {
    int[] aint = bakedQuad.getVertices();
    Vec3i faceNormal = bakedQuad.getDirection().getNormal();
    Vector3f normal = new Vector3f((float) faceNormal.getX(), (float) faceNormal.getY(), (float) faceNormal.getZ());
    Matrix4f matrix4f = matrixEntry.pose();
    normal.transform(matrixEntry.normal());
    int intSize = DefaultVertexFormat.BLOCK.getIntegerSize();
    int vertexCount = aint.length / intSize;
    try (MemoryStack memorystack = MemoryStack.stackPush()) {
        ByteBuffer bytebuffer = memorystack.malloc(DefaultVertexFormat.BLOCK.getVertexSize());
        IntBuffer intbuffer = bytebuffer.asIntBuffer();
        for (int v = 0; v < vertexCount; ++v) {
            ((Buffer) intbuffer).clear();
            intbuffer.put(aint, v * 8, 8);
            float f = bytebuffer.getFloat(0);
            float f1 = bytebuffer.getFloat(4);
            float f2 = bytebuffer.getFloat(8);
            float cr;
            float cg;
            float cb;
            float ca;
            if (readExistingColor) {
                float r = (float) (bytebuffer.get(12) & 255) / 255.0F;
                float g = (float) (bytebuffer.get(13) & 255) / 255.0F;
                float b = (float) (bytebuffer.get(14) & 255) / 255.0F;
                float a = (float) (bytebuffer.get(15) & 255) / 255.0F;
                cr = r * baseBrightness[v] * red;
                cg = g * baseBrightness[v] * green;
                cb = b * baseBrightness[v] * blue;
                ca = a * alpha;
            } else {
                cr = baseBrightness[v] * red;
                cg = baseBrightness[v] * green;
                cb = baseBrightness[v] * blue;
                ca = alpha;
            }
            int lightmapCoord = applyBakedLighting(lightmapCoords[v], bytebuffer);
            float f9 = bytebuffer.getFloat(16);
            float f10 = bytebuffer.getFloat(20);
            Vector4f pos = new Vector4f(f, f1, f2, 1.0F);
            pos.transform(matrix4f);
            applyBakedNormals(normal, bytebuffer, matrixEntry.normal());
            ((VertexConsumer) this).vertex(pos.x(), pos.y(), pos.z(), cr, cg, cb, ca, f9, f10, overlayCoords, lightmapCoord, normal.x(), normal.y(), normal.z());
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) Vec3i(net.minecraft.core.Vec3i) Matrix4f(com.mojang.math.Matrix4f) Vector4f(com.mojang.math.Vector4f) MemoryStack(org.lwjgl.system.MemoryStack) Vector3f(com.mojang.math.Vector3f) IntBuffer(java.nio.IntBuffer) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)2 Matrix4f (com.mojang.math.Matrix4f)1 Vector3f (com.mojang.math.Vector3f)1 Vector4f (com.mojang.math.Vector4f)1 Buffer (java.nio.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 IntBuffer (java.nio.IntBuffer)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 Direction (net.minecraft.core.Direction)1 Vec3i (net.minecraft.core.Vec3i)1 MemoryStack (org.lwjgl.system.MemoryStack)1