Search in sources :

Example 6 with VertexFormatElement

use of net.minecraft.client.renderer.vertex.VertexFormatElement in project ImmersiveEngineering by BluSunrize.

the class BakedModelTransformer method transform.

private static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer, Function<VertexFormat, VertexFormat> formatRemapper) {
    VertexFormat format = quad.getFormat();
    VertexFormat newFormat = formatRemapper.apply(format);
    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(newFormat);
    if (quad.hasTintIndex())
        builder.setQuadTint(quad.getTintIndex());
    builder.setQuadOrientation(quad.getFace());
    LightUtil.putBakedQuad(builder, quad);
    UnpackedBakedQuad unpackedQuad = builder.build();
    try {
        float[][][] unpackedData = getUnpackedData(unpackedQuad);
        int count = newFormat.getElementCount();
        for (int v = 0; v < 4; v++) {
            for (int e = 0; e < count; e++) {
                VertexFormatElement element = newFormat.getElement(e);
                unpackedData[v][e] = transformer.transform(quad, element.getType(), element.getUsage(), unpackedData[v][e]);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return unpackedQuad;
}
Also used : UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 7 with VertexFormatElement

use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.

the class Attributes method moreSpecific.

/*
     * Can first format be used where second is expected
     */
public static boolean moreSpecific(VertexFormat first, VertexFormat second) {
    int size = first.getNextOffset();
    if (size != second.getNextOffset())
        return false;
    int padding = 0;
    int j = 0;
    for (VertexFormatElement firstAttr : first.getElements()) {
        while (j < second.getElementCount() && second.getElement(j).getUsage() == EnumUsage.PADDING) {
            padding += second.getElement(j++).getSize();
        }
        if (j >= second.getElementCount() && padding == 0) {
            // if no padding is left, but there are still elements in first (we're processing one) - it doesn't fit
            return false;
        }
        if (padding == 0) {
            // no padding - attributes have to match
            VertexFormatElement secondAttr = second.getElement(j++);
            if (firstAttr.getIndex() != secondAttr.getIndex() || firstAttr.getElementCount() != secondAttr.getElementCount() || firstAttr.getType() != secondAttr.getType() || firstAttr.getUsage() != secondAttr.getUsage()) {
                return false;
            }
        } else {
            // padding - attribute should fit in it
            padding -= firstAttr.getSize();
            if (padding < 0)
                return false;
        }
    }
    if (padding != 0 || j != second.getElementCount())
        return false;
    return true;
}
Also used : VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement)

Example 8 with VertexFormatElement

use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.

the class VertexLighterFlat method getVertexFormat.

private static VertexFormat getVertexFormat(IVertexConsumer parent) {
    VertexFormat format = parent.getVertexFormat();
    if (format.hasNormal())
        return format;
    format = new VertexFormat(format);
    format.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.NORMAL, 4));
    return format;
}
Also used : VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 9 with VertexFormatElement

use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method postDraw.

public static void postDraw(EnumUsage attrType, VertexFormat format, int element, int stride, ByteBuffer buffer) {
    VertexFormatElement attr = format.getElement(element);
    switch(attrType) {
        case POSITION:
            glDisableClientState(GL_VERTEX_ARRAY);
            break;
        case NORMAL:
            glDisableClientState(GL_NORMAL_ARRAY);
            break;
        case COLOR:
            glDisableClientState(GL_COLOR_ARRAY);
            // is this really needed?
            GlStateManager.resetColor();
            break;
        case UV:
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit + attr.getIndex());
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
            break;
        case PADDING:
            break;
        case GENERIC:
            glDisableVertexAttribArray(attr.getIndex());
        default:
            FMLLog.severe("Unimplemented vanilla attribute upload: %s", attrType.getDisplayName());
    }
}
Also used : VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement)

Aggregations

VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)9 VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)3 Vector3f (javax.vecmath.Vector3f)1 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)1