Skip to content

Commit

Permalink
Improved texture compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Oct 26, 2023
1 parent fd6becc commit f89d925
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
20 changes: 16 additions & 4 deletions src/main/java/net/vulkanmod/gl/GlTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static int genTextureId() {
return id;
}

public static void bindTexture(int i) {
if(i == -1)
public static void bindTexture(int id) {
if(id == -1)
return;

boundTextureId = i;
boundTexture = map.get(i);
boundTextureId = id;
boundTexture = map.get(id);

if(boundTexture == null)
throw new NullPointerException("bound texture is null");
Expand Down Expand Up @@ -90,6 +90,10 @@ public static void setVulkanImage(int id, VulkanImage vulkanImage) {
texture.vulkanImage = vulkanImage;
}

public static GlTexture getBoundTexture() {
return boundTexture;
}

final int id;
VulkanImage vulkanImage;
int internalFormat;
Expand Down Expand Up @@ -130,6 +134,14 @@ private void uploadImage(@Nullable ByteBuffer pixels) {
}
}

public VulkanImage getVulkanImage() {
return vulkanImage;
}

public void setVulkanImage(VulkanImage vulkanImage) {
this.vulkanImage = vulkanImage;
}

private static int vulkanFormat(int glFormat, int type) {
return switch (glFormat) {
case GL11.GL_RGBA ->
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/vulkanmod/interfaces/VAbstractTextureI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

public interface VAbstractTextureI {

public void bindTexture();
void bindTexture();

void setId(int i);

public VulkanImage getVulkanImage();
VulkanImage getVulkanImage();

public void setVulkanImage(VulkanImage image);
void setVulkanImage(VulkanImage image);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ public static void assertOnGameThreadOrInit() {
@Overwrite
public static void _setShaderTexture(int i, ResourceLocation location) {
if (i >= 0 && i < shaderTextures.length) {
TextureManager texturemanager = Minecraft.getInstance().getTextureManager();
AbstractTexture abstracttexture = texturemanager.getTexture(location);
//abstracttexture.bindTexture();
VTextureSelector.bindTexture(i, ((VAbstractTextureI)abstracttexture).getVulkanImage());
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
AbstractTexture abstractTexture = textureManager.getTexture(location);
abstractTexture.bind();

//shaderTextures[i] = abstracttexture.getId();
//shaderTextures[i] = abstractTexture.getId();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public void bindTexture() {

if (vulkanImage != null)
VTextureSelector.bindTexture(vulkanImage);
else
VTextureSelector.bindTexture(VTextureSelector.getWhiteTexture());
}

public VulkanImage getVulkanImage() {
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/net/vulkanmod/mixin/texture/MTextureUtil.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.vulkanmod.mixin.texture;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import net.vulkanmod.gl.GlTexture;
import net.vulkanmod.vulkan.texture.VTextureSelector;
import net.vulkanmod.vulkan.texture.VulkanImage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

Expand All @@ -23,5 +23,22 @@ public static int generateTextureId() {
* @author
*/
@Overwrite(remap = false)
public static void prepareImage(NativeImage.InternalGlFormat internalGlFormat, int id, int j, int k, int l) {}
public static void prepareImage(NativeImage.InternalGlFormat internalGlFormat, int id, int mipLevels, int width, int height) {
GlTexture.bindTexture(id);
GlTexture glTexture = GlTexture.getBoundTexture();
VulkanImage image = glTexture.getVulkanImage();

if(image == null || image.mipLevels != mipLevels || image.width != width || image.height != height) {
if(image != null)
image.free();

image = new VulkanImage.Builder(width, height)
.setLinearFiltering(false)
.setClamp(false)
.createVulkanImage();

glTexture.setVulkanImage(image);
VTextureSelector.bindTexture(image);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/vulkanmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"texture.MSpriteAtlasTexture",
"texture.MSpriteContents",
"texture.MTextureManager",
"texture.MTextureUtil",
"texture.MNativeImage",

"util.ScreenshotRecorderM",
Expand Down

0 comments on commit f89d925

Please sign in to comment.