feat(graphics): update GLTextureBinding
package engine.graphics.gl.shader;
+import engine.graphics.gl.texture.GLSampler;
import engine.graphics.gl.texture.GLTexture;
+import engine.graphics.gl.texture.GLTexture2D;
import engine.graphics.gl.util.GLHelper;
import engine.graphics.shader.TextureBinding;
import engine.graphics.texture.Sampler;
@@ -13,8 +15,8 @@ import org.lwjgl.opengl.GL45;
public final class GLTextureBinding implements TextureBinding {
private final int unit;
- private Texture texture;
- private Sampler sampler;
+ private Texture texture = GLTexture2D.EMPTY;
+ private Sampler sampler = GLSampler.DEFAULT;
public GLTextureBinding(int unit) {
this.unit = unit;
@@ -37,17 +39,16 @@ public final class GLTextureBinding implements TextureBinding {
@Override
public void set(Texture texture) {
- set(texture, null);
+ set(texture, GLSampler.DEFAULT);
}
@Override
public void set(Texture texture, Sampler sampler) {
- this.texture = texture;
- this.sampler = sampler;
+ this.texture = texture == null ? GLTexture2D.EMPTY : texture;
+ this.sampler = sampler == null ? GLSampler.DEFAULT : sampler;
}
public void bind() {
- if (texture != null) {
GLTexture glTexture = (GLTexture) texture;
if (GLHelper.isOpenGL45()) {
GL45.glBindTextureUnit(unit, glTexture.getId());
@@ -55,10 +56,6 @@ public final class GLTextureBinding implements TextureBinding {
GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit);
GL11.glBindTexture(glTexture.getTarget(), glTexture.getId());
}
- }
-
- if (sampler != null) {
GL33.glBindSampler(unit, sampler.getId());
}
}
-}
