}
// Draw the prim faces
for (int j = 0; j < Faces.size(); j++)
{
TextureEntryFace teFace = Prim.Textures.GetFace(j);
Face face = Faces.get(j);
FaceData data = (FaceData)face.UserData;
if (data == null)
continue;
if (teFace == null)
continue;
// Don't render transparent faces
Color4 RGBA = teFace.getRGBA();
if (data.TextureInfo.FullAlpha || RGBA.getA() <= 0.01f) continue;
boolean switchedLightsOff = false;
if (pass == RenderPass.Picking)
{
data.PickingID = pickingID;
byte[] primNrBytes = new byte[2];
Utils.uint16ToBytes(pickingID, primNrBytes, 0);
// byte[] faceColor = new byte[] { primNrBytes[0], primNrBytes[1], (byte)j, (byte)255 };
GL11.glColor4f( primNrBytes[0], primNrBytes[1], (byte)j, (byte)255);
}
else if (pass == RenderPass.Invisible)
{
if (!data.TextureInfo.IsInvisible) continue;
HasInvisibleFaces = true;
}
else
{
// System.out.println("Pass is Simple..");
if (data.TextureInfo.IsInvisible)
{
System.out.println("Primitive is invisible.. so skipping texturing...");
continue;
}
boolean belongToAlphaPass = (RGBA.getA() < 0.99f) || (data.TextureInfo.HasAlpha && !data.TextureInfo.IsMask);
//TODO only for debugging
if (belongToAlphaPass && pass != RenderPass.Alpha) continue;
if (!belongToAlphaPass && pass == RenderPass.Alpha) continue;
// System.out.println("Going to Activate Texture");
if (pass == RenderPass.Simple)
{
HasSimpleFaces = true;
}
else if (pass == RenderPass.Alpha)
{
HasAlphaFaces = true;
}
if (teFace.getFullbright())
{
GL11.glDisable(GL11.GL_LIGHTING );
switchedLightsOff = true;
}
float shiny = 0f;
switch (teFace.getShiny())
{
case High:
shiny = 0.96f;
break;
case Medium:
shiny = 0.64f;
break;
case Low:
shiny = 0.24f;
break;
}
if (shiny > 0f)
{
//TODO need to handle
// scene.StartShiny();
}
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, shiny);
GL11.glColor4f(RGBA.getR(), RGBA.getG(), RGBA.getB(), RGBA.getA());
//Optmized by keeping a instance buffer, as materialData is constant
// float[] materialData = new float[] { 0.5f, 0.5f, 0.5f, 1f };
// final FloatBuffer materialDataBuffer = ByteBuffer
// .allocateDirect(materialData.length*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
// materialDataBuffer.put(materialData);
materialDataBuffer.position(0);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, materialDataBuffer);
// System.out.println("Trying to Activate the Texture " + data.TextureInfo.TextureID
// + " --> "+ data.TextureInfo.TexturePointer);
if (data.TextureInfo.TexturePointer == 0)
{
TextureInfo teInfo;
if ((teInfo = scene.textureManager.getTextureInfo(teFace.getTextureID()))!=null)
{
data.TextureInfo = teInfo;
}
}
if (data.TextureInfo.TexturePointer == 0)
{
System.out.println("Texture pointer is 0 .. requesting to download.." + teFace.getTextureID());
GL11.glDisable(GL11.GL_TEXTURE_2D);
if (!data.TextureInfo.FetchFailed)
{
scene.textureManager.requestDownloadTexture(new TextureLoadItem(data, this.Prim, teFace));
}
else
{
System.out.println("Texture Download failed for " + teFace.getTextureID());
}
}
else
{
// System.out.println("Texture pointer is not 0 ..");