Java 类net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage 实例源码

项目:CustomWorldGen    文件:LightUtil.java   
public void put(int element, float... data)
{
    if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
    {
        System.arraycopy(auxColor, 0, buf, 0, buf.length);
        for(int i = 0; i < 4; i++)
        {
            buf[i] *= data[i];
        }
        super.put(element, buf);
    }
    else
    {
        super.put(element, data);
    }
    if(element == getVertexFormat().getElementCount() - 1)
    {
        vertices++;
        if(vertices == 4)
        {
            vertices = 0;
        }
    }
}
项目:CustomWorldGen    文件:VertexBufferConsumer.java   
public void put(int e, float... data)
{
    VertexFormat format = getVertexFormat();
    if(renderer.isColorDisabled() && format.getElement(e).getUsage() == EnumUsage.COLOR)
    {
        data = dummyColor;
    }
    LightUtil.pack(data, quadData, format, v, e);
    if(e == format.getElementCount() - 1)
    {
        v++;
        if(v == 4)
        {
            renderer.addVertexData(quadData);
            renderer.putPosition(offset.getX(), offset.getY(), offset.getZ());
            //Arrays.fill(quadData, 0);
            v = 0;
        }
    }
}
项目:CodeChickenLib    文件:VertexDataUtils.java   
public static List<BakedQuad> shadeQuadFaces(List<BakedQuad> quads) {
    LinkedList<BakedQuad> shadedQuads = new LinkedList<>();
    for (BakedQuad quad : quads) {
        int[] rawData = quad.getVertexData();
        for (int v = 0; v < 4; v++) {
            for (int e = 0; e < quad.getFormat().getElementCount(); e++) {
                VertexFormatElement element = quad.getFormat().getElement(e);
                if (element.getUsage() == EnumUsage.COLOR) {
                    float[] data = new float[4];
                    LightUtil.unpack(rawData, data, quad.getFormat(), v, e);

                    data = diffuseFaceLight(quad.getFace(), data);

                    LightUtil.pack(data, rawData, quad.getFormat(), v, e);
                }
            }
        }
        shadedQuads.add(new BakedQuad(rawData, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat()));
    }

    return shadedQuads;
}
项目:CustomWorldGen    文件:ForgeHooksClient.java   
public static void preDraw(EnumUsage attrType, VertexFormat format, int element, int stride, ByteBuffer buffer)
{
    VertexFormatElement attr = format.getElement(element);
    int count = attr.getElementCount();
    int constant = attr.getType().getGlConstant();
    buffer.position(format.getOffset(element));
    switch(attrType)
    {
        case POSITION:
            glVertexPointer(count, constant, stride, buffer);
            glEnableClientState(GL_VERTEX_ARRAY);
            break;
        case NORMAL:
            if(count != 3)
            {
                throw new IllegalArgumentException("Normal attribute should have the size 3: " + attr);
            }
            glNormalPointer(constant, stride, buffer);
            glEnableClientState(GL_NORMAL_ARRAY);
            break;
        case COLOR:
            glColorPointer(count, constant, stride, buffer);
            glEnableClientState(GL_COLOR_ARRAY);
            break;
        case UV:
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit + attr.getIndex());
            glTexCoordPointer(count, constant, stride, buffer);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
            break;
        case PADDING:
            break;
        case GENERIC:
            glEnableVertexAttribArray(attr.getIndex());
            glVertexAttribPointer(attr.getIndex(), count, constant, false, stride, buffer);
        default:
            FMLLog.severe("Unimplemented vanilla attribute upload: %s", attrType.getDisplayName());
    }
}
项目:CustomWorldGen    文件:ForgeHooksClient.java   
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());
    }
}
项目:CrystalMod    文件:ModelUVAverager.java   
@Override
public void put(
        final int element,
        final float... data )
{
    final VertexFormatElement e = getVertexFormat().getElement( element );
    if ( e.getUsage() == EnumUsage.UV && e.getIndex() != 1 )
    {
        sumU += data[0];
        sumV += data[1];
        ++vertCount;
    }
}
项目:CodeChickenLib    文件:VertexDataUtils.java   
/**
 * Gets the position for the element 'normal' in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format The format.
 * @return The element position, -1 if it does not exist.
 */
public static int getNormalElement(VertexFormat format) {
    for (int e = 0; e < format.getElementCount(); e++) {
        if (format.getElement(e).getUsage() == EnumUsage.NORMAL) {
            return e;
        }
    }
    return -1;
}
项目:CodeChickenLib    文件:VertexDataUtils.java   
/**
 * Gets the position for the element 'uv' in the elements list for use in LightUtil.pack/unpack for a given format.
 *
 * @param format The format.
 * @return The element position, -1 if it does not exist.
 */
public static int getUVElement(VertexFormat format) {
    for (int e = 0; e < format.getElementCount(); e++) {
        if (format.getElement(e).getUsage() == EnumUsage.UV && format.getElement(e).getIndex() == 0) {
            return e;
        }
    }
    return -1;
}
项目:OpenBlocks    文件:TileEntityImaginaryRenderer.java   
private static Map<VertexFormatElement, Integer> createElementOffsetMap(VertexFormat format) {
    ImmutableMap.Builder<VertexFormatElement, Integer> builder = ImmutableMap.builder();

    for (int i = 0; i < format.getElementCount(); i++) {
        VertexFormatElement vfe = format.getElement(i);
        if (vfe.getUsage() != EnumUsage.PADDING)
            builder.put(vfe, format.getOffset(i));
    }

    return builder.build();
}
项目:CustomWorldGen    文件:Attributes.java   
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;
}