use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method preDraw.
// moved and expanded from WorldVertexBufferUploader.draw
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());
}
}
use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class LightUtil method pack.
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]
}
}
}
use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class LightUtil method mapFormats.
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;
}
use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class LightUtil method unpack.
public static void unpack(int[] from, float[] to, VertexFormat formatFrom, int v, int e) {
int length = 4 < to.length ? 4 : to.length;
VertexFormatElement element = formatFrom.getElement(e);
int vertexStart = v * formatFrom.getNextOffset() + formatFrom.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 < length; i++) {
if (i < count) {
int pos = vertexStart + size * i;
int index = pos >> 2;
int offset = pos & 3;
int bits = from[index];
bits = bits >>> (offset * 8);
if ((pos + size - 1) / 4 != index) {
bits |= from[index + 1] << ((4 - offset) * 8);
}
bits &= mask;
if (type == VertexFormatElement.EnumType.FLOAT) {
to[i] = Float.intBitsToFloat(bits);
} else if (type == VertexFormatElement.EnumType.UBYTE || type == VertexFormatElement.EnumType.USHORT) {
to[i] = (float) bits / mask;
} else if (type == VertexFormatElement.EnumType.UINT) {
to[i] = (float) ((double) (bits & 0xFFFFFFFFL) / 0xFFFFFFFFL);
} else if (type == VertexFormatElement.EnumType.BYTE) {
to[i] = ((float) (byte) bits) / mask * 2;
} else if (type == VertexFormatElement.EnumType.SHORT) {
to[i] = ((float) (short) bits) / mask * 2;
} else if (type == VertexFormatElement.EnumType.INT) {
to[i] = ((float) (bits & 0xFFFFFFFFL)) / 0xFFFFFFFFL * 2;
}
} else {
to[i] = 0;
}
}
}
use of net.minecraft.client.renderer.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class VertexLighterFlat method processQuad.
@Override
protected void processQuad() {
float[][] position = quadData[posIndex];
float[][] normal = null;
float[][] lightmap = quadData[lightmapIndex];
float[][] color = quadData[colorIndex];
if (normalIndex != -1 && (quadData[normalIndex][0][0] != -1 || quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][2] != -1)) {
normal = quadData[normalIndex];
} else {
normal = new float[4][4];
Vector3f v1 = new Vector3f(position[3]);
Vector3f t = new Vector3f(position[1]);
Vector3f v2 = new Vector3f(position[2]);
v1.sub(t);
t.set(position[0]);
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
for (int v = 0; v < 4; v++) {
normal[v][0] = v1.x;
normal[v][1] = v1.y;
normal[v][2] = v1.z;
normal[v][3] = 0;
}
}
int multiplier = -1;
if (tint != -1) {
multiplier = blockInfo.getColorMultiplier(tint);
}
VertexFormat format = parent.getVertexFormat();
int count = format.getElementCount();
for (int v = 0; v < 4; v++) {
position[v][0] += blockInfo.getShx();
position[v][1] += blockInfo.getShy();
position[v][2] += blockInfo.getShz();
float x = position[v][0] - .5f;
float y = position[v][1] - .5f;
float z = position[v][2] - .5f;
//if(blockInfo.getBlock().isFullCube())
{
x += normal[v][0] * .5f;
y += normal[v][1] * .5f;
z += normal[v][2] * .5f;
}
float blockLight = lightmap[v][0], skyLight = lightmap[v][1];
updateLightmap(normal[v], lightmap[v], x, y, z);
if (dataLength[lightmapIndex] > 1) {
if (blockLight > lightmap[v][0])
lightmap[v][0] = blockLight;
if (skyLight > lightmap[v][1])
lightmap[v][1] = skyLight;
}
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
if (diffuse) {
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
for (int i = 0; i < 3; i++) {
color[v][i] *= d;
}
}
if (EntityRenderer.anaglyphEnable) {
applyAnaglyph(color[v]);
}
// no need for remapping cause all we could've done is add 1 element to the end
for (int e = 0; e < count; e++) {
VertexFormatElement element = format.getElement(e);
switch(element.getUsage()) {
case POSITION:
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
/*float[] pos = new float[4];
System.arraycopy(position[v], 0, pos, 0, position[v].length);
pos[0] += blockInfo.getBlockPos().getX();
pos[1] += blockInfo.getBlockPos().getY();
pos[2] += blockInfo.getBlockPos().getZ();*/
parent.put(e, position[v]);
break;
case NORMAL:
if (normalIndex != -1) {
parent.put(e, normal[v]);
break;
}
case COLOR:
parent.put(e, color[v]);
break;
case UV:
if (element.getIndex() == 1) {
parent.put(e, lightmap[v]);
break;
}
default:
parent.put(e, quadData[e][v]);
}
}
}
tint = -1;
}
Aggregations