58 lines
1.1 KiB
Java
58 lines
1.1 KiB
Java
package speiger.src.coreengine.rendering.textures.base;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.opengl.GL46;
|
|
|
|
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
|
import speiger.src.coreengine.rendering.utils.values.IGLValue;
|
|
import speiger.src.coreengine.rendering.utils.values.textures.GLTextureType;
|
|
|
|
public abstract class BaseTexture implements ITexture {
|
|
protected int id;
|
|
|
|
protected BaseTexture() {
|
|
track();
|
|
}
|
|
|
|
protected BaseTexture(int id) {
|
|
this.id = id;
|
|
track();
|
|
}
|
|
|
|
protected void createTexture() {
|
|
this.id = GL46.glCreateTextures(textureType().glValue());
|
|
}
|
|
|
|
protected IGLValue textureType() {
|
|
return GLTextureType.TEXTURE_2D;
|
|
}
|
|
|
|
protected void removeTexture() {
|
|
if(id == 0) return;
|
|
GL11.glDeleteTextures(id);
|
|
id = 0;
|
|
}
|
|
|
|
protected void track() {
|
|
GLStateTracker.TEXTURE_TRACKER.registerTexture(this);
|
|
}
|
|
|
|
@Override
|
|
public int id() {
|
|
return id;
|
|
}
|
|
|
|
@Override
|
|
public void bind(int unit) {
|
|
GLStateTracker.TEXTURES.bind(unit, id);
|
|
}
|
|
|
|
@Override
|
|
public void delete(boolean untrack) {
|
|
removeTexture();
|
|
if(untrack) {
|
|
GLStateTracker.TEXTURE_TRACKER.deleteTexture(this);
|
|
}
|
|
}
|
|
}
|