Fixed some rendering stuff

Fixed some Rendering BS
This commit is contained in:
PeytonPlayz595 2023-07-19 13:06:48 -04:00
parent 5a4eff2040
commit 0deaced874
3 changed files with 175 additions and 228 deletions

View File

@ -73,7 +73,6 @@ public final class GameSettings {
if(var1 == 6) {
this.anaglyph = !this.anaglyph;
this.mc.renderEngine.refreshTextures();
}
if(var1 == 7) {

View File

@ -1,247 +1,203 @@
package net.minecraft.client.render;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import net.minecraft.client.GameSettings;
import net.minecraft.client.render.texture.TextureFX;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import net.PeytonPlayz585.minecraft.MinecraftImage;
import net.minecraft.client.GameSettings;
import net.minecraft.client.render.texture.TextureFX;
public class RenderEngine {
private HashMap textureMap = new HashMap();
private HashMap textureContentsMap = new HashMap();
private IntBuffer singleIntBuffer = BufferUtils.createIntBuffer(1);
private ByteBuffer imageData = BufferUtils.createByteBuffer(262144);
private List textureList = new ArrayList();
private Map urlToImageDataMap = new HashMap();
private GameSettings options;
private boolean clampTexture = false;
public RenderEngine(GameSettings var1) {
this.options = var1;
public RenderEngine(GameSettings gamesettings) {
textureMap = new HashMap();
textureNameToImageMap = new HashMap();
singleIntBuffer = BufferUtils.createIntBuffer(1);
imageDataB1 = BufferUtils.createByteBuffer(0x100000);
imageDataB2 = BufferUtils.createByteBuffer(0x100000);
//imageDataInt = GLAllocation.createDirectIntBuffer(0x40000);
textureList = new ArrayList();
clampTexture = false;
blurTexture = false;
options = gamesettings;
}
public final int getTexture(String var1) {
Integer var2 = (Integer)this.textureMap.get(var1);
if(var2 != null) {
return var2.intValue();
} else {
try {
this.singleIntBuffer.clear();
GL11.glGenTextures(this.singleIntBuffer);
int var4 = this.singleIntBuffer.get(0);
if(var1.startsWith("##")) {
this.setupTexture(unwrapImageByColumns(ImageIO.read(RenderEngine.class.getResourceAsStream(var1.substring(2)))), var4);
} else if(var1.startsWith("%%")) {
this.clampTexture = true;
this.setupTexture(ImageIO.read(RenderEngine.class.getResourceAsStream(var1.substring(2))), var4);
this.clampTexture = false;
} else {
this.setupTexture(ImageIO.read(RenderEngine.class.getResourceAsStream(var1)), var4);
}
this.textureMap.put(var1, Integer.valueOf(var4));
return var4;
} catch (IOException var3) {
throw new RuntimeException("!!");
}
public int getTexture(String s) {
Integer integer = (Integer) textureMap.get(s);
if (integer != null) {
return integer.intValue();
}
}
private static BufferedImage unwrapImageByColumns(BufferedImage var0) {
int var1 = var0.getWidth() / 16;
BufferedImage var2 = new BufferedImage(16, var0.getHeight() * var1, 2);
Graphics var3 = var2.getGraphics();
for(int var4 = 0; var4 < var1; ++var4) {
var3.drawImage(var0, -var4 << 4, var4 * var0.getHeight(), (ImageObserver)null);
}
var3.dispose();
return var2;
}
private void setupTexture(BufferedImage var1, int var2) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
if(this.clampTexture) {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
} else {
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);
}
var2 = var1.getWidth();
int var3 = var1.getHeight();
int[] var4 = new int[var2 * var3];
byte[] var5 = new byte[var2 * var3 << 2];
var1.getRGB(0, 0, var2, var3, var4, 0, var2);
for(int var11 = 0; var11 < var4.length; ++var11) {
int var6 = var4[var11] >>> 24;
int var7 = var4[var11] >> 16 & 255;
int var8 = var4[var11] >> 8 & 255;
int var9 = var4[var11] & 255;
if(this.options != null && this.options.anaglyph) {
int var10 = (var7 * 30 + var8 * 59 + var9 * 11) / 100;
var8 = (var7 * 30 + var8 * 70) / 100;
var9 = (var7 * 30 + var9 * 70) / 100;
var7 = var10;
var8 = var8;
var9 = var9;
}
var5[var11 << 2] = (byte)var7;
var5[(var11 << 2) + 1] = (byte)var8;
var5[(var11 << 2) + 2] = (byte)var9;
var5[(var11 << 2) + 3] = (byte)var6;
}
this.imageData.clear();
this.imageData.put(var5);
this.imageData.position(0).limit(var5.length);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, var2, var3, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageData);
}
public final int getTextureForDownloadableImage(String var1, String var2) {
ThreadDownloadImageData var6 = (ThreadDownloadImageData)this.urlToImageDataMap.get(var1);
if(var6 != null && var6.image != null && !var6.textureSetupComplete) {
if(var6.textureName < 0) {
BufferedImage var4 = var6.image;
this.singleIntBuffer.clear();
GL11.glGenTextures(this.singleIntBuffer);
int var5 = this.singleIntBuffer.get(0);
this.setupTexture(var4, var5);
this.textureContentsMap.put(Integer.valueOf(var5), var4);
var6.textureName = var5;
try {
singleIntBuffer.clear();
BufferUtils.generateTextureNames(singleIntBuffer);
int i = singleIntBuffer.get(0);
//if (s.startsWith("##")) {
// setupTexture(unwrapImageByColumns(readTextureImage(texturepackbase.func_6481_a(s.substring(2)))), i);
//} else
if (s.startsWith("%clamp%")) {
clampTexture = true;
setupTexture(readTextureImage(GL11.loadResourceBytes(s.substring(7))), i);
clampTexture = false;
} else if (s.startsWith("%blur%")) {
blurTexture = true;
setupTexture(readTextureImage(GL11.loadResourceBytes(s.substring(6))), i);
blurTexture = false;
} else {
this.setupTexture(var6.image, var6.textureName);
if(s.equals("/terrain.png")) {
useMipmaps = true;
}
setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i);
useMipmaps = false;
}
var6.textureSetupComplete = true;
textureMap.put(s, Integer.valueOf(i));
return i;
} catch (IOException ioexception) {
throw new RuntimeException("!!");
}
return var6 != null && var6.textureName >= 0 ? var6.textureName : this.getTexture(var2);
}
public int allocateAndSetupTexture(MinecraftImage bufferedimage) {
singleIntBuffer.clear();
BufferUtils.generateTextureNames(singleIntBuffer);
int i = singleIntBuffer.get(0);
setupTexture(bufferedimage, i);
textureNameToImageMap.put(Integer.valueOf(i), bufferedimage);
return i;
}
public int allocateAndSetupTexture(byte[] data, int w, int h) {
int i = GL11.glGenTextures();
bindTexture(i);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10242 /* GL_TEXTURE_WRAP_S */, 10497 /* GL_REPEAT */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10243 /* GL_TEXTURE_WRAP_T */, 10497 /* GL_REPEAT */);
imageDataB1.clear();
imageDataB1.put(data);
imageDataB1.position(0).limit(data.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, w, h, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
return i;
}
public final ThreadDownloadImageData obtainImageData(String var1, ImageBufferDownload var2) {
ThreadDownloadImageData var3 = (ThreadDownloadImageData)this.urlToImageDataMap.get(var1);
if(var3 == null) {
this.urlToImageDataMap.put(var1, new ThreadDownloadImageData(var1, var2));
public void setupTexture(MinecraftImage bufferedimage, int i) {
bindTexture(i);
if (useMipmaps) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, GL11.GL_NEAREST_MIPMAP_LINEAR);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, GL11.GL_NEAREST /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, GL11.GL_TEXTURE_MAX_LEVEL, 4);
} else {
++var3.referenceCount;
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */);
}
if (blurTexture) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */);
}
if (clampTexture) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10242 /* GL_TEXTURE_WRAP_S */, 10496 /* GL_CLAMP */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10243 /* GL_TEXTURE_WRAP_T */, 10496 /* GL_CLAMP */);
} else {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10242 /* GL_TEXTURE_WRAP_S */, 10497 /* GL_REPEAT */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10243 /* GL_TEXTURE_WRAP_T */, 10497 /* GL_REPEAT */);
}
int j = bufferedimage.w;
int k = bufferedimage.h;
int ai[] = bufferedimage.data;
byte abyte0[] = new byte[j * k * 4];
for (int l = 0; l < ai.length; l++) {
int j1 = ai[l] >> 24 & 0xff;
int l1 = ai[l] >> 16 & 0xff;
int j2 = ai[l] >> 8 & 0xff;
int l2 = ai[l] >> 0 & 0xff;
if (options != null && options.anaglyph) {
int j3 = (l1 * 30 + j2 * 59 + l2 * 11) / 100;
int l3 = (l1 * 30 + j2 * 70) / 100;
int j4 = (l1 * 30 + l2 * 70) / 100;
l1 = j3;
j2 = l3;
l2 = j4;
}
abyte0[l * 4 + 0] = (byte) l1;
abyte0[l * 4 + 1] = (byte) j2;
abyte0[l * 4 + 2] = (byte) l2;
abyte0[l * 4 + 3] = (byte) j1;
}
imageDataB1.clear();
imageDataB1.put(abyte0);
imageDataB1.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
if (useMipmaps) {
for (int i1 = 1; i1 <= 4; i1++) {
int k1 = j >> i1 - 1;
int i2 = j >> i1;
int k2 = k >> i1;
imageDataB2.clear();
for (int i3 = 0; i3 < i2; i3++) {
for (int k3 = 0; k3 < k2; k3++) {
int i4 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 0) * k1) * 4);
int k4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 0) * k1) * 4);
int l4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 1) * k1) * 4);
int i5 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 1) * k1) * 4);
int j5 = averageColor(averageColor(i4, k4), averageColor(l4, i5));
imageDataB2.putInt((i3 + k3 * i2) * 4, j5);
}
return var3;
}
public final void releaseImageData(String var1) {
ThreadDownloadImageData var2 = (ThreadDownloadImageData)this.urlToImageDataMap.get(var1);
if(var2 != null) {
--var2.referenceCount;
if(var2.referenceCount == 0) {
if(var2.textureName >= 0) {
int var3 = var2.textureName;
this.textureContentsMap.remove(Integer.valueOf(var3));
this.singleIntBuffer.clear();
this.singleIntBuffer.put(var3);
this.singleIntBuffer.flip();
GL11.glDeleteTextures(this.singleIntBuffer);
}
this.urlToImageDataMap.remove(var1);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, i1, 6408 /* GL_RGBA */, i2, k2, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
}
}
public final void registerTextureFX(TextureFX var1) {
this.textureList.add(var1);
var1.onTick();
}
public final void updateDynamicTextures() {
int var1;
TextureFX var2;
for(var1 = 0; var1 < this.textureList.size(); ++var1) {
var2 = (TextureFX)this.textureList.get(var1);
var2.anaglyphEnabled = this.options.anaglyph;
var2.onTick();
this.imageData.clear();
this.imageData.put(var2.imageData);
this.imageData.position(0).limit(var2.imageData.length);
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, var2.iconIndex % 16 << 4, var2.iconIndex / 16 << 4, 16, 16, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageData);
}
for(var1 = 0; var1 < this.textureList.size(); ++var1) {
var2 = (TextureFX)this.textureList.get(var1);
if(var2.textureId > 0) {
this.imageData.clear();
this.imageData.put(var2.imageData);
this.imageData.position(0).limit(var2.imageData.length);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2.textureId);
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 16, 16, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageData);
}
}
}
public final void refreshTextures() {
Iterator var1 = this.textureContentsMap.keySet().iterator();
int var2;
BufferedImage var3;
while(var1.hasNext()) {
var2 = ((Integer)var1.next()).intValue();
var3 = (BufferedImage)this.textureContentsMap.get(Integer.valueOf(var2));
this.setupTexture(var3, var2);
}
ThreadDownloadImageData var5;
for(var1 = this.urlToImageDataMap.values().iterator(); var1.hasNext(); var5.textureSetupComplete = false) {
var5 = (ThreadDownloadImageData)var1.next();
}
var1 = this.textureMap.keySet().iterator();
while(var1.hasNext()) {
String var6 = (String)var1.next();
try {
if(var6.startsWith("##")) {
var3 = unwrapImageByColumns(ImageIO.read(RenderEngine.class.getResourceAsStream(var6.substring(2))));
} else if(var6.startsWith("%%")) {
this.clampTexture = true;
var3 = ImageIO.read(RenderEngine.class.getResourceAsStream(var6.substring(2)));
this.clampTexture = false;
} else {
var3 = ImageIO.read(RenderEngine.class.getResourceAsStream(var6));
}
var2 = ((Integer)this.textureMap.get(var6)).intValue();
this.setupTexture(var3, var2);
} catch (IOException var4) {
var4.printStackTrace();
}
}
}
public static void bindTexture(int var0) {
if(var0 >= 0) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var0);
}
}
}
public void deleteTexture(int i) {
GL11.glDeleteTextures(i);
}
public int getTextureForDownloadableImage(String s, String s1) {
return getTexture("/mob/char.png");
}
private int averageColor(int i, int j) {
int k = (i & 0xff000000) >> 24 & 0xff;
int l = (j & 0xff000000) >> 24 & 0xff;
return ((k + l >> 1) << 24) + ((i & 0xfefefe) + (j & 0xfefefe) >> 1);
}
private MinecraftImage readTextureImage(byte[] inputstream) throws IOException {
return GL11.loadPNG(inputstream);
}
public static void bindTexture(int i) {
if (i < 0) {
return;
} else {
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i);
return;
}
}
public static boolean useMipmaps = false;
private HashMap textureMap;
private HashMap textureNameToImageMap;
private IntBuffer singleIntBuffer;
private ByteBuffer imageDataB1;
private ByteBuffer imageDataB2;
private java.util.List<TextureFX> textureList;
private GameSettings options;
private boolean clampTexture;
private boolean blurTexture;
}

View File

@ -738,17 +738,9 @@ public final class RenderGlobal implements IWorldAccess {
}
public final void obtainEntitySkin(Entity var1) {
if(var1.skinUrl != null) {
this.renderEngine.obtainImageData(var1.skinUrl, new ImageBufferDownload());
}
}
public final void releaseEntitySkin(Entity var1) {
if(var1.skinUrl != null) {
this.renderEngine.releaseImageData(var1.skinUrl);
}
}
public final void updateAllRenderers() {