Skip to content

Instantly share code, notes, and snippets.

@retep998
Created April 9, 2013 08:24
Show Gist options
  • Save retep998/5343957 to your computer and use it in GitHub Desktop.
Save retep998/5343957 to your computer and use it in GitHub Desktop.
A quick fix for the HD texturepack performance bug. https://mojang.atlassian.net/browse/MC-13206
public void copyFrom(int par1, int par2, Texture par3Texture, boolean par4)
{
if (this.textureTarget != 32879)
{
ByteBuffer bytebuffer = par3Texture.getTextureData();
this.textureData.position(0);
bytebuffer.position(0);
/* Forge:
*
* Optimize these loops a bit for non-rotated textures.
* Should help the FPS loss on higher resolution texture packs.
* If it becomes a major issue we may have to look into a more
* optimized animation system.
*
* https://mojang.atlassian.net/browse/MC-13206
*/
//update - added by retep998
boolean update = true;
if (!par4)
{
int scanSize = par3Texture.getWidth() * 4;
int w4 = width * 4;
int targetY = (par2 * w4) + (par1 * 4);
for (int y = 0; y < par3Texture.getHeight(); y++)
{
textureData.position(targetY);
for (int x = 0; x < scanSize; x++)
{
textureData.put(bytebuffer.get());
}
targetY += w4;
}
//This whole if block - added by retep998
if (this.textureCreated && this.height != 1 && this.textureDepth == 1)
{
update = false;
bytebuffer.position(0);
GL11.glTexSubImage2D(this.textureTarget, 0, par1, par2, par3Texture.getWidth(),par3Texture.getHeight(), this.textureFormat, GL11.GL_UNSIGNED_BYTE, bytebuffer);
}
}
for (int k = 0; par4 && k < par3Texture.getHeight(); ++k)
{
int l = par2 + k;
int i1 = k * par3Texture.getWidth() * 4;
int j1 = l * this.width * 4;
if (par4)
{
l = par1 + (par3Texture.getHeight() - k - 1); //BUGFIX: targetY -> targetX and -1
}
for (int k1 = 0; k1 < par3Texture.getWidth(); ++k1)
{
int l1 = j1 + (k1 + par1) * 4;
int i2 = i1 + k1 * 4;
if (par4)
{
l1 = (par2 + k1) * this.width * 4 + l * 4; //BUGFIX: targetX -> targetY and parens
}
this.textureData.put(l1 + 0, bytebuffer.get(i2 + 0));
this.textureData.put(l1 + 1, bytebuffer.get(i2 + 1));
this.textureData.put(l1 + 2, bytebuffer.get(i2 + 2));
this.textureData.put(l1 + 3, bytebuffer.get(i2 + 3));
}
}
this.textureData.position(this.width * this.height * 4);
if (this.autoCreate)
{
this.createTexture();
}
else if (update)//The if (update) - added by retep998
{
this.textureCreated = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment