Cleanup uniformInjection

This commit is contained in:
Antoine 2021-06-14 14:50:23 +02:00
parent ae4a332eaf
commit acf62519f4
3 changed files with 16 additions and 30 deletions

View File

@ -4,7 +4,7 @@ import engine.math.Vector3f;
import static org.lwjgl.glfw.GLFW.glfwGetTime;
public class HorizontalProgressBar extends ObjectGl{
public class HorizontalProgressBar extends ObjectGl {
private float max;
private float current;
@ -18,24 +18,18 @@ public class HorizontalProgressBar extends ObjectGl{
this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBar.glsl");
}
public void setCurrent(float newCurrent){
public void setCurrent(float newCurrent) {
this.current = newCurrent;
}
public void setMax(float newMax){
public void setMax(float newMax) {
this.max = newMax;
}
/**
* Do shader binding, texture binding and vertexArray drawing
*/
public void render(){
this.shader.enable();
protected void uniformInjection() {
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
if (this.leftToRight == 1){
if (this.leftToRight == 1) {
this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth());
} else {
this.shader.setUniform1f("fill", Math.abs(((this.current / this.max) * this.getWidth()) - this.getWidth()));
@ -46,9 +40,5 @@ public class HorizontalProgressBar extends ObjectGl{
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
this.vertexArray.render();
this.shader.disable();
}
}

View File

@ -19,21 +19,13 @@ public class Letter extends ObjectGl {
this.indexBasedShader = b;
}
public void render(){
this.shader.enable();
if (this.texture != null) this.texture.bind();
protected void uniformInjection(){
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
if (this.indexBasedShader) this.shader.setUniform1i("index",this.index);
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
this.vertexArray.render();
if (this.texture != null) this.texture.unbind();
this.shader.disable();
}
}

View File

@ -265,6 +265,14 @@ public class ObjectGl {
return scalingFactor;
}
protected void uniformInjection(){
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
}
/**
* Do shader binding, texture binding and vertexArray drawing
*/
@ -273,11 +281,7 @@ public class ObjectGl {
this.shader.enable();
if (this.texture != null) this.texture.bind();
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
this.uniformInjection();
this.vertexArray.render();