Roi Atalla avatar Roi Atalla committed dab347f

Updated the binders to make them prettier.

Comments (0)

Files changed (10)

src/com/ra4king/opengl/util/scene/Scene.java

 			binders.add(binder);
 		}
 		
-		public int getProgram() {
-			return baseVariant.program.program.getProgram();
+		public ShaderProgram getProgram() {
+			return baseVariant.program.program;
 		}
 		
 		public void render(Matrix4 baseMatrix) {
 				glUniformMatrix3(variant.program.invNormalMatrixUniform, false, new Matrix3(objectMatrix.inverse().transpose()).inverse().toBuffer());
 			
 			for(StateBinder binder : binders)
-				binder.bindState(variant.program.program.getProgram());
+				binder.bindState(variant.program.program);
 			
 			for(TextureBinding binding : variant.texBindings) {
 				glActiveTexture(GL_TEXTURE0 + binding.texUnit);
 			}
 			
 			for(StateBinder binder : binders)
-				binder.unbindState(variant.program.program.getProgram());
+				binder.unbindState(variant.program.program);
 			
 			variant.program.program.end();
 		}

src/com/ra4king/opengl/util/scene/binders/StateBinder.java

 
 import java.util.HashMap;
 
+import com.ra4king.opengl.util.ShaderProgram;
+
 public interface StateBinder {
-	void bindState(int program);
+	void bindState(ShaderProgram program);
 	
-	void unbindState(int program);
+	void unbindState(ShaderProgram program);
 }
 
 abstract class UniformBinderBase implements StateBinder {
-	private HashMap<Integer,Integer> programUniformLocation = new HashMap<>();
+	private HashMap<ShaderProgram,Integer> programUniformLocation = new HashMap<>();
 	
-	public void associateWithProgram(int program, String uniform) {
-		programUniformLocation.put(program, glGetUniformLocation(program, uniform));
+	public void associateWithProgram(ShaderProgram program, String uniform) {
+		programUniformLocation.put(program, glGetUniformLocation(program.getProgram(), uniform));
 	}
 	
-	protected int getUniformLocation(int program) {
+	protected int getUniformLocation(ShaderProgram program) {
 		Integer i = programUniformLocation.get(program);
-		if(i == null)
-			return -1;
+		if(i == -1)
+			throw new IllegalArgumentException("Unassociated program");
 		return i;
 	}
 }

src/com/ra4king/opengl/util/scene/binders/TextureBinder.java

 import static org.lwjgl.opengl.GL13.*;
 import static org.lwjgl.opengl.GL33.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
+
 public class TextureBinder implements StateBinder {
-	private int texUnit;
-	private int texType = GL_TEXTURE_2D;
-	private int tex;
-	private int sampler;
+	public int texUnit;
+	public int texType = GL_TEXTURE_2D;
+	public int tex;
+	public int sampler;
 	
-	public void setTexture(int texUnit, int texType, int tex, int sampler) {
+	public TextureBinder() {}
+	
+	public TextureBinder(int texUnit, int texType, int tex, int sampler) {
+		setValue(texUnit, texType, tex, sampler);
+	}
+	
+	public void setValue(int texUnit, int texType, int tex, int sampler) {
 		this.texUnit = texUnit;
 		this.texType = texType;
 		this.tex = tex;
 	}
 	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glActiveTexture(GL_TEXTURE0 + texUnit);
 		glBindTexture(texType, tex);
 		glBindSampler(texUnit, sampler);
 	}
 	
 	@Override
-	public void unbindState(int program) {
+	public void unbindState(ShaderProgram program) {
 		glActiveTexture(GL_TEXTURE0 + texUnit);
 		glBindTexture(texType, 0);
 		glBindSampler(texUnit, 0);

src/com/ra4king/opengl/util/scene/binders/UniformBlockBinder.java

 import static org.lwjgl.opengl.GL30.*;
 import static org.lwjgl.opengl.GL31.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
+
 public class UniformBlockBinder implements StateBinder {
-	private int blockIndex;
-	private int uniformBuffer;
-	private int bufferOffset;
-	private int bufferSize;
+	public int blockIndex;
+	public int uniformBuffer;
+	public int bufferOffset;
+	public int bufferSize;
 	
-	public void setBlock(int blockIndex, int uniformBuffer, int bufferOffset, int bufferSize) {
+	public UniformBlockBinder() {}
+	
+	public UniformBlockBinder(int blockIndex, int uniformBuffer, int bufferOffset, int bufferSize) {
+		setValue(blockIndex, uniformBuffer, bufferOffset, bufferSize);
+	}
+	
+	public void setValue(int blockIndex, int uniformBuffer, int bufferOffset, int bufferSize) {
 		this.blockIndex = blockIndex;
 		this.uniformBuffer = uniformBuffer;
 		this.bufferOffset = bufferOffset;
 	}
 	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glBindBufferRange(GL_UNIFORM_BUFFER, blockIndex, uniformBuffer, bufferOffset, bufferSize);
 	}
 	
 	@Override
-	public void unbindState(int program) {
+	public void unbindState(ShaderProgram program) {
 		glBindBufferBase(GL_UNIFORM_BUFFER, blockIndex, 0);
 	}
 }

src/com/ra4king/opengl/util/scene/binders/UniformFloatBinder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
+
 public class UniformFloatBinder extends UniformBinderBase {
 	private float value;
 	
+	public UniformFloatBinder() {}
+	
+	public UniformFloatBinder(float value) {
+		setValue(value);
+	}
+	
 	public void setValue(float value) {
 		this.value = value;
 	}
 	
+	public float getValue() {
+		return value;
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniform1f(getUniformLocation(program), value);
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }

src/com/ra4king/opengl/util/scene/binders/UniformIntBinder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
+
 public class UniformIntBinder extends UniformBinderBase {
 	private int value;
 	
+	public UniformIntBinder() {}
+	
+	public UniformIntBinder(int value) {
+		setValue(value);
+	}
+	
 	public void setValue(int value) {
 		this.value = value;
 	}
 	
+	public int getValue() {
+		return value;
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniform1i(getUniformLocation(program), value);
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }

src/com/ra4king/opengl/util/scene/binders/UniformMat4Binder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Matrix4;
 
 public class UniformMat4Binder extends UniformBinderBase {
 	private Matrix4 value = new Matrix4().clearToIdentity();
 	
+	public UniformMat4Binder() {}
+	
+	public UniformMat4Binder(Matrix4 mat) {
+		setValue(mat);
+	}
+	
 	public void setValue(Matrix4 mat) {
 		value.set(mat);
 	}
 	
+	public Matrix4 getValue() {
+		return value.copy();
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniformMatrix4(getUniformLocation(program), false, value.toBuffer());
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }

src/com/ra4king/opengl/util/scene/binders/UniformVec2Binder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Vector2;
 
 public class UniformVec2Binder extends UniformBinderBase {
 	private Vector2 value = new Vector2();
 	
+	public UniformVec2Binder() {}
+	
+	public UniformVec2Binder(Vector2 vec) {
+		setValue(vec);
+	}
+	
 	public void setValue(Vector2 vec) {
 		value.set(vec);
 	}
 	
+	public Vector2 getValue() {
+		return value.copy();
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniform2(getUniformLocation(program), value.toBuffer());
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }

src/com/ra4king/opengl/util/scene/binders/UniformVec3Binder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Vector3;
 
 public class UniformVec3Binder extends UniformBinderBase {
 	private Vector3 value = new Vector3();
 	
+	public UniformVec3Binder() {}
+	
+	public UniformVec3Binder(Vector3 vec) {
+		setValue(vec);
+	}
+	
 	public void setValue(Vector3 vec) {
 		value.set(vec);
 	}
 	
+	public Vector3 getValue() {
+		return value.copy();
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniform3(getUniformLocation(program), value.toBuffer());
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }

src/com/ra4king/opengl/util/scene/binders/UniformVec4Binder.java

 
 import static org.lwjgl.opengl.GL20.*;
 
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Vector4;
 
 public class UniformVec4Binder extends UniformBinderBase {
 	private Vector4 value = new Vector4();
 	
+	public UniformVec4Binder() {}
+	
+	public UniformVec4Binder(Vector4 vec) {
+		setValue(vec);
+	}
+	
 	public void setValue(Vector4 vec) {
 		value.set(vec);
 	}
 	
+	public Vector4 getValue() {
+		return value.copy();
+	}
+	
 	@Override
-	public void bindState(int program) {
+	public void bindState(ShaderProgram program) {
 		glUniform4(getUniformLocation(program), value.toBuffer());
 	}
 	
 	@Override
-	public void unbindState(int program) {}
+	public void unbindState(ShaderProgram program) {}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.