Jump to content

Custom Class Binding Textures with GL vs. Using Minecraft's resource loader/manager


Recommended Posts

Posted

I've been looking at various source code on github to self-teach myself the various approaches to the custom special effects that mods such as Betweenlands, Astral Sorcery, etc. have that allow fading in and out particles, and one thing I noticed was that sometimes the modder makes their own class to bind the textures using a GL11 method:

Spoiler

package com.ninja3659.explorationexpansion.client.particle.util;

import org.lwjgl.opengl.GL11;

import com.ninja3659.explorationexpansion.util.Utils;

import akka.japi.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
 * Purpose of the Class: to bind the png texture id to a variable so that we can call the resource location. Essentially we are making our own Resource location handler
 * @author JEHan
 * 
 * {@link IResourceManagerReloadListener}
 *
 */

@SideOnly(Side.CLIENT)
public class BindableResource {
	//we need an ITO to load the texture
	private ITextureObject resource = null;//we set the ITO as null so that we initialize it and can use it
	private String path;//where it is located
	
	public BindableResource(String path) {
		this.path = path;
	}
	
	public String getPath() {
		return path;
	}
	
	public boolean isInitialized() {
		return resource != null;
	}
	
	public ITextureObject getResource() {
		return resource;
	}
	
	public void allocateGlId() {
		if (resource != null) return; //if the resource is already full, we don't need another
		resource = new SimpleTexture(new ResourceLocation(path));//establishes the resource
		try {
			resource.loadTexture(Minecraft.getMinecraft().getResourceManager());
		} catch (Exception e) {
			Utils.getLogger().error("EE Failed to load texture " + path);
			e.printStackTrace();//prits out error
			resource = TextureUtil.MISSING_TEXTURE;//sets texture to missing texture
			return;//finished
		}
	}
	
	public void bind() {
		if (resource == null) {
			allocateGlId();
		}
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, resource.getGlTextureId());
	}
}

I inputted the comments to help better understand the function of everything in the class

My question is what benefit does creating your own Resource-Binding class in terms of sprites and sprite sheets compared to using what is already built in to the game? Sorry if there isn't enough information or if this is in the wrong place, this is my first time attempting something more involved than the basic mob, block, etc. If this sorta thing requires understanding GL, is there anywhere I can learn about it?

Posted

You could do your own implementation, but what would be the advantage?

Minecraft does the same thing for you when you call 'TextureManager::bindTexture':


Personal I see no reasonable benefit from doing like it. It's just a: "I don't like how Minecraft it does" thing.

But correct me if someone think this is better.

Posted

One reason for it could be that sometimes the forge guys like to “mix things up a bit” and change the way things load, making updating a Royal pain, so by setting up your own implementation you sidestep that so you don’t have to worry about depreciated methods and completely revamped elements. I’d be willing to tempt it if I had the java experience and the time

Posted (edited)

That's a good point, but I don't thing the forge team make things worse, they try to optimize things.

I think only in 1.13 the loading could change, but more from the reason that minecraft updates to lwjgl 3. So you have to change it in your code anyways.

 

At the end it's up to you, if you know what you do, it's fine. :)

Edited by Lhykos

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.