This commit is contained in:
eaglercraft 2024-05-30 22:20:39 -07:00
commit cfab2e85bf
23 changed files with 216 additions and 47 deletions

View file

@ -30,6 +30,7 @@ public abstract class AbstractTexture implements ITextureObject {
protected boolean mipmap;
protected boolean blurLast;
protected boolean mipmapLast;
protected boolean hasAllocated;
public void setBlurMipmapDirect(boolean parFlag, boolean parFlag2) {
if (blur != parFlag || mipmap != parFlag2) {
@ -67,6 +68,7 @@ public abstract class AbstractTexture implements ITextureObject {
public int getGlTextureId() {
if (this.glTextureId == -1) {
this.glTextureId = TextureUtil.glGenTextures();
hasAllocated = false;
}
return this.glTextureId;
@ -79,4 +81,18 @@ public abstract class AbstractTexture implements ITextureObject {
}
}
/**
* This function is needed due to EaglercraftX's use of glTexStorage2D to
* allocate memory for textures, some OpenGL implementations don't like it when
* you call glTexStorage2D on the same texture object more than once
*/
protected void regenerateIfNotAllocated() {
if (this.glTextureId != -1) {
if (hasAllocated) {
EaglercraftGPU.regenerateTexture(glTextureId);
}
hasAllocated = true;
}
}
}

View file

@ -40,6 +40,7 @@ public class DynamicTexture extends AbstractTexture {
this.width = textureWidth;
this.height = textureHeight;
this.dynamicTextureData = new int[textureWidth * textureHeight];
this.hasAllocated = true;
TextureUtil.allocateTexture(this.getGlTextureId(), textureWidth, textureHeight);
}

View file

@ -91,6 +91,7 @@ public class LayeredColorMaskTexture extends AbstractTexture {
return;
}
regenerateIfNotAllocated();
TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
}
}

View file

@ -63,6 +63,7 @@ public class LayeredTexture extends AbstractTexture {
return;
}
regenerateIfNotAllocated();
TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
}
}

View file

@ -62,6 +62,7 @@ public class SimpleTexture extends AbstractTexture {
}
}
regenerateIfNotAllocated();
TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, flag, flag1);
} finally {
if (inputstream != null) {

View file

@ -74,6 +74,7 @@ public class TextureMap extends AbstractTexture implements ITickableTextureObjec
private int height;
private boolean isEaglerPBRMode = false;
public int eaglerPBRMaterialTexture = -1;
private boolean hasAllocatedEaglerPBRMaterialTexture = false;
public static final int _GL_FRAMEBUFFER = 0x8D40;
public static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0;
@ -173,6 +174,7 @@ public class TextureMap extends AbstractTexture implements ITickableTextureObjec
if (isEaglerPBRMode) {
if (eaglerPBRMaterialTexture == -1) {
eaglerPBRMaterialTexture = GlStateManager.generateTexture();
hasAllocatedEaglerPBRMaterialTexture = false;
}
if (copyMaterialFramebuffer == null) {
GlStateManager.bindTexture(eaglerPBRMaterialTexture);
@ -422,9 +424,14 @@ public class TextureMap extends AbstractTexture implements ITickableTextureObjec
logger.info("Created: {}x{} {}-atlas", new Object[] { Integer.valueOf(stitcher.getCurrentWidth()),
Integer.valueOf(stitcher.getCurrentHeight()), this.basePath });
regenerateIfNotAllocated();
TextureUtil.allocateTextureImpl(this.getGlTextureId(), this.mipmapLevels, stitcher.getCurrentWidth(),
stitcher.getCurrentHeight());
if (isEaglerPBRMode) {
if (hasAllocatedEaglerPBRMaterialTexture) {
EaglercraftGPU.regenerateTexture(eaglerPBRMaterialTexture);
}
hasAllocatedEaglerPBRMaterialTexture = true;
TextureUtil.allocateTextureImpl(eaglerPBRMaterialTexture, this.mipmapLevels, stitcher.getCurrentWidth(),
stitcher.getCurrentHeight() * 2);
}

View file

@ -326,7 +326,7 @@ public class TextureUtil {
public static int[] convertComponentOrder(int[] arr) {
for (int i = 0; i < arr.length; ++i) {
int j = arr[i];
arr[i] = (j & 0xFF000000) | ((j >> 16) & 0xFF) | (j & 0xFF00) | ((j << 16) & 0xFF0000);
arr[i] = ((j >> 16) & 0xFF) | (j & 0xFF00FF00) | ((j << 16) & 0xFF0000);
}
return arr;
}

View file

@ -136,6 +136,8 @@ public abstract class ResourcePackListEntry implements GuiListExtended.IGuiListE
protected abstract void func_148313_c();
protected abstract String getEaglerFolderName();
protected boolean func_148310_d() {
return true;
}
@ -183,7 +185,7 @@ public abstract class ResourcePackListEntry implements GuiListExtended.IGuiListE
if (deleteInstead) {
this.mc.loadingScreen.eaglerShow(I18n.format("resourcePack.load.deleting"), this.func_148312_b());
EaglerFolderResourcePack.deleteResourcePack(EaglerFolderResourcePack.RESOURCE_PACKS,
this.func_148312_b());
this.getEaglerFolderName());
} else {
this.resourcePacksGUI.getSelectedResourcePacks().add(0, this);
}

View file

@ -100,4 +100,9 @@ public class ResourcePackListEntryDefault extends ResourcePackListEntry {
protected boolean func_148310_d() {
return false;
}
@Override
protected String getEaglerFolderName() {
return null;
}
}

View file

@ -50,4 +50,9 @@ public class ResourcePackListEntryFound extends ResourcePackListEntry {
public ResourcePackRepository.Entry func_148318_i() {
return this.field_148319_c;
}
@Override
protected String getEaglerFolderName() {
return field_148319_c.getResourcePackName();
}
}