forked from vram-guild/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.16-spiralhalo-LTS' into naive-shadow-2-LTS
- Loading branch information
Showing
13 changed files
with
223 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/grondag/canvas/pipeline/ProgramTextureData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package grondag.canvas.pipeline; | ||
|
||
import grondag.canvas.pipeline.config.ImageConfig; | ||
import grondag.canvas.pipeline.config.util.NamedDependency; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.texture.AbstractTexture; | ||
import net.minecraft.client.texture.ResourceTexture; | ||
import net.minecraft.client.texture.TextureManager; | ||
import net.minecraft.util.Identifier; | ||
import org.lwjgl.opengl.GL46; | ||
|
||
public class ProgramTextureData { | ||
final public int[] texIds; | ||
final public int[] texTargets; | ||
|
||
public ProgramTextureData(NamedDependency<ImageConfig>[] samplerImages) { | ||
texIds = new int[samplerImages.length]; | ||
texTargets = new int[samplerImages.length]; | ||
|
||
for (int i = 0; i < samplerImages.length; ++i) { | ||
final String imageName = samplerImages[i].name; | ||
|
||
int imageBind = 0; | ||
int bindTarget = GL46.GL_TEXTURE_2D; | ||
|
||
if (imageName.contains(":")) { | ||
final AbstractTexture tex = tryLoadResourceTexture(new Identifier(imageName)); | ||
|
||
if (tex != null) { | ||
imageBind = tex.getGlId(); | ||
} | ||
} else { | ||
final Image img = Pipeline.getImage(imageName); | ||
|
||
if (img != null) { | ||
imageBind = img.glId(); | ||
bindTarget = img.config.target; | ||
} | ||
} | ||
|
||
texIds[i] = imageBind; | ||
texTargets[i] = bindTarget; | ||
} | ||
} | ||
|
||
private static AbstractTexture tryLoadResourceTexture(Identifier identifier) { | ||
final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); | ||
final AbstractTexture existingTexture = textureManager.getTexture(identifier); | ||
|
||
if (existingTexture != null) { | ||
return existingTexture; | ||
} else { | ||
// NB: `registerTexture` will replace the texture with MissingSprite if not found. This is useful for | ||
// pipeline developers. | ||
// Additionally, TextureManager will handle removing missing textures on resource reload. | ||
ResourceTexture resourceTexture = new ResourceTexture(identifier); | ||
textureManager.registerTexture(identifier, resourceTexture); | ||
return textureManager.getTexture(identifier); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.