in Minecraft/src/main/java/com/microsoft/Malmo/Utils/TextureHelper.java [265:351]
public static void glBindTexture(int target, int texture)
{
// The Minecraft render code is selecting a texture.
// If we are producing a colour map, this is our opportunity to activate our special fragment shader,
// which will ignore the texture and use a solid colour - either the colour we pass in, or a colour based
// on the texture coords (if using the block texture atlas).
if (isProducingColourMap && colourmapFrame)
{
if (shaderID != -1)
{
// Have we encountered this texture before?
Integer col = texturesToColours.get(texture);
if (col == null)
{
// No - are we drawing an entity?
if (currentEntity != null)
{
// Has the user requested a specific mapping?
if (idealMobColours != null)
{
// Yes, in which case use black unless a mapping is found:
col = 0;
String entName = EntityList.getKey(currentEntity).toString();
for (String ent : idealMobColours.keySet())
{
if (entName.equals(ent))
{
col = idealMobColours.get(ent);
}
}
}
else
{
// Provide a default mapping from entity to colour
String ent = EntityList.getEntityString(currentEntity);
if (ent == null) // Happens if, for example, currentEntity is of type EntityOtherPlayerMP.
ent = currentEntity.getClass().getName();
col = (ent.hashCode()) % 0xffffff;
}
texturesToColours.put(texture, col);
}
else
{
// Not drawing an entity. Check the misc mappings:
for (String resID : miscTexturesToColours.keySet())
{
ITextureObject tex = Minecraft.getMinecraft().getTextureManager().getTexture(new ResourceLocation(resID));
if (tex != null && tex.getGlTextureId() == texture)
{
// Match
col = miscTexturesToColours.get(resID);
}
}
if (col == null)
{
// Still no match.
// Finally, see if this is the block atlas texture:
ITextureObject blockatlas = Minecraft.getMinecraft().getTextureManager().getTexture(new ResourceLocation("textures/atlas/blocks.png"));
if (blockatlas != null && blockatlas.getGlTextureId() == texture)
{
col = -1;
}
}
if (col != null) // Put this in the map for easy access next time.
texturesToColours.put(texture, col);
}
}
if (col != null)
{
OpenGlHelper.glUseProgram(shaderID);
int entColUniformLocR = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourR");
int entColUniformLocG = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourG");
int entColUniformLocB = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourB");
if (entColUniformLocR != -1 && entColUniformLocG != -1 && entColUniformLocB != -1)
{
OpenGlHelper.glUniform1i(entColUniformLocR, col != -1 ? (col >> 16) & 0xff : -1);
OpenGlHelper.glUniform1i(entColUniformLocG, col != -1 ? (col >> 8) & 0xff : -1);
OpenGlHelper.glUniform1i(entColUniformLocB, col != -1 ? col & 0xff : -1);
}
}
else
OpenGlHelper.glUseProgram(0);
}
}
// Finally, pass call on to OpenGL:
GL11.glBindTexture(target, texture);
}