public static int[] mapFormats(VertexFormat from, VertexFormat to) { int fromCount = from.getElementCount(); int toCount = to.getElementCount(); int[] eMap = new int[fromCount]; for(int e = 0; e < fromCount; e++) { VertexFormatElement expected = from.getElement(e); int e2; for(e2 = 0; e2 < toCount; e2++) { VertexFormatElement current = to.getElement(e2); if(expected.getUsage() == current.getUsage() && expected.getIndex() == current.getIndex()) { break; } } eMap[e] = e2; } return eMap; }
private static void putVertex(UnpackedBakedQuad.Builder builder, VertexFormat format, EnumFacing face, Vertex5 vert, Colour colour) { for (int e = 0; e < format.getElementCount(); e++) { VertexFormatElement element = format.getElement(e); switch (element.getUsage()) { case POSITION: Vector3 vec = vert.vec; builder.put(e, (float) vec.x, (float) vec.y, (float) vec.z, 1); break; case NORMAL: builder.put(e, face.getFrontOffsetX(), face.getFrontOffsetY(), face.getFrontOffsetZ(), 0); break; case COLOR: builder.put(e, (colour.r & 0xFF) / 255F, (colour.g & 0xFF) / 255F, (colour.b & 0xFF) / 255F, (colour.a & 0xFF) / 255F); break; case UV: UV uv = vert.uv; builder.put(e, (float) uv.u, (float) uv.v, 0, 1); break; default: builder.put(e); break; } } }
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; }
private void applyVertexDataForType(int index, VertexFormatElement.EnumUsage type, UnpackedBakedQuad.Builder builder) { switch (type) { case POSITION: builder.put(index, x, y, z, 1); break; case UV: builder.put(index, u, v, 0, 1); break; case COLOR: builder.put(index, r, g, b, a); break; case NORMAL: builder.put(index, nX, nY, nZ, 0); break; case PADDING: //TODO: figure this one out builder.put(index); break; case GENERIC: //TODO: figure this one out builder.put(index); } }
public final void transformUnpackedVertexDataElement(VertexFormatElement.EnumUsage type, float[] data, Vector4f temp) { switch (type) { case POSITION: case NORMAL: this.matrices.transform(data[0], data[1], data[2], 1, temp); data[0] = temp.x; data[1] = temp.y; data[2] = temp.z; break; case COLOR: data[0] = getRed(); data[1] = getGreen(); data[2] = getBlue(); data[3] = getAlpha(); break; } }
@Override public void put(int elementIndex, float... data) { ei = elementIndex; VertexFormatElement element = getVertexFormat().getElement(elementIndex); if (elementIndex == 0) { vertex++; } /** @see net.minecraftforge.client.model.obj.OBJModel.OBJBakedModel#putVertexData */ if (element == DefaultVertexFormats.POSITION_3F) { pos(data[0], data[1], data[2]); } else if (element == DefaultVertexFormats.COLOR_4UB) { color((char) data[0], (char) data[1], (char) data[2], (char) data[3]); } else if (element == DefaultVertexFormats.TEX_2F) { tex(data[0], data[1]); } else if (element == DefaultVertexFormats.NORMAL_3B) { normal((byte) data[0], (byte) data[1], (byte) data[2]); } else { bakery.put(ei, data); } }
@SuppressWarnings("unchecked") public BWBakedModel(@SuppressWarnings("deprecation") IBakedModel wrapped, VertexFormat format) { this.wrapped = wrapped; this.format = format; this.matrix.translate(-0.5, -0.5, -0.5); if (!((List<VertexFormatElement>) format.getElements()).stream().anyMatch(VertexFormatElement::isPositionElement)) return; // VertexFormat doesn't have a position getGeneralQuads().stream() .map(this::quadToFace) .forEachOrdered(faces::add); Arrays.stream(Direction.VALID_DIRECTIONS) .map(this::getFaceQuads) .flatMap(Collection::stream) .map(this::quadToFace) .forEachOrdered(faces::add); }
public RenderSkyVC() { Minecraft mcIn = Minecraft.getMinecraft(); world = mcIn.theWorld; this.mc = mcIn; this.renderManager = mcIn.getRenderManager(); this.renderEngine = mcIn.getTextureManager(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GlStateManager.bindTexture(0); this.vboEnabled = OpenGlHelper.useVbo(); this.vertexBufferFormat = new VertexFormat(); this.vertexBufferFormat.setElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); this.generateSky(); this.generateSky2(); }
private void addQuad(final UnpackedBakedQuad.Builder builder, EnumFacing face, TextureAtlasSprite sprite, Vertex position, Vertex texture) { for (int e = 0; e < format.getElementCount(); e++) { final VertexFormatElement el = format.getElement(e); switch (el.getUsage()) { case POSITION: builder.put(e, position.x, position.y, position.z); break; case NORMAL: builder.put(e, face.getFrontOffsetX(), face.getFrontOffsetY(), face.getFrontOffsetZ()); break; case COLOR: builder.put(e, 1, 1, 1, 1); break; case UV: if (el.getIndex() == 0) { builder.put(e, sprite.getInterpolatedU(16 * texture.u), sprite.getInterpolatedV(16 * texture.v)); } else { builder.put(e, 0, 0); } break; default: builder.put(e); } } }
public List<RealmsVertexFormatElement> getElements() { List<RealmsVertexFormatElement> list = new ArrayList(); for (VertexFormatElement vertexformatelement : this.v.getElements()) { list.add(new RealmsVertexFormatElement(vertexformatelement)); } return list; }
private void func_181667_k() { ++this.field_181678_g; this.field_181678_g %= this.vertexFormat.getElementCount(); this.field_181677_f = this.vertexFormat.getElement(this.field_181678_g); if (this.field_181677_f.getUsage() == VertexFormatElement.EnumUsage.PADDING) { this.func_181667_k(); } }
public RenderGlobal(Minecraft mcIn) { this.mc = mcIn; this.renderManager = mcIn.getRenderManager(); this.renderEngine = mcIn.getTextureManager(); this.renderEngine.bindTexture(locationForcefieldPng); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GlStateManager.bindTexture(0); this.updateDestroyBlockIcons(); this.vboEnabled = OpenGlHelper.useVbo(); if (this.vboEnabled) { this.renderContainer = new VboRenderList(); this.renderChunkFactory = new VboChunkFactory(); } else { this.renderContainer = new RenderList(); this.renderChunkFactory = new ListChunkFactory(); } this.vertexBufferFormat = new VertexFormat(); this.vertexBufferFormat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); this.generateStars(); this.generateSky(); this.generateSky2(); }
public static VertexFormat makeDefVertexFormatBlock() { VertexFormat vertexformat = new VertexFormat(); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.func_181721_a(new VertexFormatElement(1, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static VertexFormat makeDefVertexFormatItem() { VertexFormat vertexformat = new VertexFormat(); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static VertexFormat makeDefVertexFormatTextured() { VertexFormat vertexformat = new VertexFormat(); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static void setDefBakedFormat(VertexFormat vf) { vf.clear(); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vf.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); }
public RenderGlobal(Minecraft mcIn) { this.cloudRenderer = new CloudRenderer(mcIn); this.mc = mcIn; this.renderManager = mcIn.getRenderManager(); this.renderEngine = mcIn.getTextureManager(); this.renderEngine.bindTexture(locationForcefieldPng); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GlStateManager.bindTexture(0); this.updateDestroyBlockIcons(); this.vboEnabled = OpenGlHelper.useVbo(); if (this.vboEnabled) { this.renderContainer = new VboRenderList(); this.renderChunkFactory = new VboChunkFactory(); } else { this.renderContainer = new RenderList(); this.renderChunkFactory = new ListChunkFactory(); } this.vertexBufferFormat = new VertexFormat(); this.vertexBufferFormat.func_181721_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); this.generateStars(); this.generateSky(); this.generateSky2(); }
public static VertexFormat makeDefVertexFormatBlock() { VertexFormat vertexformat = new VertexFormat(); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.addElement(new VertexFormatElement(1, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static VertexFormat makeDefVertexFormatItem() { VertexFormat vertexformat = new VertexFormat(); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static VertexFormat makeDefVertexFormatTextured() { VertexFormat vertexformat = new VertexFormat(); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vertexformat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); return vertexformat; }
public static void setDefBakedFormat(VertexFormat vf) { vf.clear(); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.UBYTE, VertexFormatElement.EnumUsage.COLOR, 4)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 2)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.PADDING, 2)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); vf.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.PADDING, 4)); }
public List<RealmsVertexFormatElement> getElements() { List<RealmsVertexFormatElement> list = Lists.<RealmsVertexFormatElement>newArrayList(); for (VertexFormatElement vertexformatelement : this.v.getElements()) { list.add(new RealmsVertexFormatElement(vertexformatelement)); } return list; }
private void nextVertexFormatIndex() { ++this.vertexFormatIndex; this.vertexFormatIndex %= this.vertexFormat.getElementCount(); this.vertexFormatElement = this.vertexFormat.getElement(this.vertexFormatIndex); if (this.vertexFormatElement.getUsage() == VertexFormatElement.EnumUsage.PADDING) { this.nextVertexFormatIndex(); } }
public RenderGlobal(Minecraft mcIn) { this.renderEnv = new RenderEnv(this.theWorld, Blocks.AIR.getDefaultState(), new BlockPos(0, 0, 0)); this.renderOverlayDamaged = false; this.renderOverlayEyes = false; this.cloudRenderer = new CloudRenderer(mcIn); this.mc = mcIn; this.renderManager = mcIn.getRenderManager(); this.renderEngine = mcIn.getTextureManager(); this.renderEngine.bindTexture(FORCEFIELD_TEXTURES); GlStateManager.glTexParameteri(3553, 10242, 10497); GlStateManager.glTexParameteri(3553, 10243, 10497); GlStateManager.bindTexture(0); this.updateDestroyBlockIcons(); this.vboEnabled = OpenGlHelper.useVbo(); if (this.vboEnabled) { this.renderContainer = new VboRenderList(); this.renderChunkFactory = new VboChunkFactory(); } else { this.renderContainer = new RenderList(); this.renderChunkFactory = new ListChunkFactory(); } this.vertexBufferFormat = new VertexFormat(); this.vertexBufferFormat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); this.generateStars(); this.generateSky(); this.generateSky2(); }
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()); } }
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()); } }
public static void pack(float[] from, int[] to, VertexFormat formatTo, int v, int e) { VertexFormatElement element = formatTo.getElement(e); int vertexStart = v * formatTo.getNextOffset() + formatTo.getOffset(e); int count = element.getElementCount(); VertexFormatElement.EnumType type = element.getType(); int size = type.getSize(); int mask = (256 << (8 * (size - 1))) - 1; for(int i = 0; i < 4; i++) { if(i < count) { int pos = vertexStart + size * i; int index = pos >> 2; int offset = pos & 3; int bits = 0; float f = i < from.length ? from[i] : 0; if(type == VertexFormatElement.EnumType.FLOAT) { bits = Float.floatToRawIntBits(f); } else if( type == VertexFormatElement.EnumType.UBYTE || type == VertexFormatElement.EnumType.USHORT || type == VertexFormatElement.EnumType.UINT ) { bits = (int)(f * mask); } else { bits = (int)(f * mask / 2); } to[index] &= ~(mask << (offset * 8)); to[index] |= (((bits & mask) << (offset * 8))); // TODO handle overflow into to[index + 1] } } }
@SuppressWarnings("incomplete-switch") public void draw(VertexBuffer vertexBufferIn) { if (vertexBufferIn.getVertexCount() > 0) { VertexFormat vertexformat = vertexBufferIn.getVertexFormat(); int i = vertexformat.getNextOffset(); ByteBuffer bytebuffer = vertexBufferIn.getByteBuffer(); List<VertexFormatElement> list = vertexformat.getElements(); for (int j = 0; j < list.size(); ++j) { VertexFormatElement vertexformatelement = (VertexFormatElement)list.get(j); VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.getUsage(); int k = vertexformatelement.getType().getGlConstant(); int l = vertexformatelement.getIndex(); bytebuffer.position(vertexformat.getOffset(j)); // moved to VertexFormatElement.preDraw vertexformatelement.getUsage().preDraw(vertexformat, j, i, bytebuffer); } GlStateManager.glDrawArrays(vertexBufferIn.getDrawMode(), 0, vertexBufferIn.getVertexCount()); int i1 = 0; for (int j1 = list.size(); i1 < j1; ++i1) { VertexFormatElement vertexformatelement1 = (VertexFormatElement)list.get(i1); VertexFormatElement.EnumUsage vertexformatelement$enumusage1 = vertexformatelement1.getUsage(); int k1 = vertexformatelement1.getIndex(); // moved to VertexFormatElement.postDraw vertexformatelement1.getUsage().postDraw(vertexformat, i1, i, bytebuffer); } } vertexBufferIn.reset(); }
public RenderGlobal(Minecraft mcIn) { this.mc = mcIn; this.renderManager = mcIn.getRenderManager(); this.renderEngine = mcIn.getTextureManager(); this.renderEngine.bindTexture(FORCEFIELD_TEXTURES); GlStateManager.glTexParameteri(3553, 10242, 10497); GlStateManager.glTexParameteri(3553, 10243, 10497); GlStateManager.bindTexture(0); this.updateDestroyBlockIcons(); this.vboEnabled = OpenGlHelper.useVbo(); if (this.vboEnabled) { this.renderContainer = new VboRenderList(); this.renderChunkFactory = new VboChunkFactory(); } else { this.renderContainer = new RenderList(); this.renderChunkFactory = new ListChunkFactory(); } this.vertexBufferFormat = new VertexFormat(); this.vertexBufferFormat.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3)); this.generateStars(); this.generateSky(); this.generateSky2(); }
@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; } }
private FlattenedModelCache() { this.cache = CacheBuilder.newBuilder().weakKeys().expireAfterAccess(10, TimeUnit.MINUTES) .build(new CacheLoader<IBakedModel, IBakedModel>() { @Override public IBakedModel load(final IBakedModel key) { IBakedModel model = ForgeHooksClient.handleCameraTransforms(key, ItemCameraTransforms.TransformType.GUI, false); if (model.isGui3d() && !model.isBuiltInRenderer()) { model = ModelTransformer.transform(model, null, 0, (quad, element, data) -> { if (element.getUsage() == VertexFormatElement.EnumUsage.NORMAL) { data[0] /= 1.5f; data[2] *= 1.7f; } return data; }); } return model; } }); }
@Override public void put(int e, float... data) { VertexFormat format = getVertexFormat(); VertexFormatElement fmte = format.getElement(e); switch (fmte.getUsage()) { case POSITION: ccrs.vert.vec.set(data).add(offset); break; case UV: if (fmte.getIndex() == 0) { ccrs.vert.uv.set(data[0], data[1]); } else { ccrs.brightness = (int) (data[1] * 0xFFFF / 2) << 16 | (int) (data[0] * 0xFFFF / 2); } break; case COLOR: ccrs.colour = Colour.packRGBA(data); break; case NORMAL: ccrs.normal.set(data); break; case PADDING: break; default: throw new UnsupportedOperationException("Generic vertex format element"); } if (e == format.getElementCount() - 1) { ccrs.writeVert(); } }
public void writeVert() { if (r instanceof BakingVertexBuffer) { ((BakingVertexBuffer) r).setSprite(sprite); } for (int e = 0; e < fmt.getElementCount(); e++) { VertexFormatElement fmte = fmt.getElement(e); switch (fmte.getUsage()) { case POSITION: r.pos(vert.vec.x, vert.vec.y, vert.vec.z); break; case UV: if (fmte.getIndex() == 0) { r.tex(vert.uv.u, vert.uv.v); } else { r.lightmap(brightness >> 16 & 65535, brightness & 65535); } break; case COLOR: if (r.isColorDisabled()) { //-_- Fucking mojang.. r.nextVertexFormatIndex(); } else { r.color(colour >>> 24, colour >> 16 & 0xFF, colour >> 8 & 0xFF, alphaOverride >= 0 ? alphaOverride : colour & 0xFF); } break; case NORMAL: r.normal((float) normal.x, (float) normal.y, (float) normal.z); break; case PADDING: break; default: throw new UnsupportedOperationException("Generic vertex format element"); } } r.endVertex(); }