List of usage examples for org.lwjgl.opengl GL20 glGetUniformLocation
@NativeType("GLint") public static int glGetUniformLocation(@NativeType("GLuint") int program, @NativeType("GLchar const *") CharSequence name)
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * /*from w w w . j a v a2 s . c o m*/ * @param program ID/index of the program * @param name Name of the variable * @param value Value to set the variable */ public void setUniformFloat(int program, String name, float value) { if (has_opengl2) { int loc = GL20.glGetUniformLocation(program, name); checkVariableLocation(loc, name); GL20.glUniform1f(loc, value); } else if (has_arb) { int loc = ARBShaderObjects.glGetUniformLocationARB(program, name); checkVariableLocation(loc, name); ARBShaderObjects.glUniform1fARB(loc, value); } }
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * /* w ww . j a va 2s .c om*/ * @param program ID/index of the program * @param name Name of the variable * @param value Value to set the variable */ public void setUniformFloatArray(int program, String name, float values[]) { if (has_opengl2) { int loc = GL20.glGetUniformLocation(program, name); checkVariableLocation(loc, name); if (values.length == 1) GL20.glUniform1f(loc, values[0]); if (values.length == 2) GL20.glUniform2f(loc, values[0], values[1]); else if (values.length == 3) GL20.glUniform3f(loc, values[0], values[1], values[2]); else if (values.length == 4) GL20.glUniform4f(loc, values[0], values[1], values[2], values[3]); } else if (has_arb) { int loc = ARBShaderObjects.glGetUniformLocationARB(program, name); checkVariableLocation(loc, name); if (values.length == 1) ARBShaderObjects.glUniform1fARB(loc, values[0]); if (values.length == 2) ARBShaderObjects.glUniform2fARB(loc, values[0], values[1]); else if (values.length == 3) ARBShaderObjects.glUniform3fARB(loc, values[0], values[1], values[2]); else if (values.length == 4) ARBShaderObjects.glUniform4fARB(loc, values[0], values[1], values[2], values[3]); } }
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * // www. j av a 2 s . c om * @param program ID/index of the program * @param name Name of the variable * @param value Value to set the variable */ public void setUniformFloatArray(int program, String name, boolean transpose, float[][] matrix) { FloatBuffer matBuffer = matrixPrepare(matrix); if (has_opengl2) { int loc = GL20.glGetUniformLocation(program, name); checkVariableLocation(loc, name); switch (matrix.length) { case 2: GL20.glUniformMatrix2(loc, transpose, matBuffer); break; case 3: GL20.glUniformMatrix3(loc, transpose, matBuffer); break; case 4: GL20.glUniformMatrix4(loc, transpose, matBuffer); break; } } else if (has_arb) { int loc = ARBShaderObjects.glGetUniformLocationARB(program, name); checkVariableLocation(loc, name); switch (matrix.length) { case 2: ARBShaderObjects.glUniformMatrix2ARB(loc, transpose, matBuffer); break; case 3: ARBShaderObjects.glUniformMatrix3ARB(loc, transpose, matBuffer); break; case 4: ARBShaderObjects.glUniformMatrix4ARB(loc, transpose, matBuffer); break; } } }
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * Get's the location of a uniform variable * @param program The ID/index of the program * @param name The name of the variable/* w w w . j av a2 s . c o m*/ * @return The location of the variable, or -1 if it isn't found */ public int getUniformVariableLocation(int program, String name) { CharSequence param = new StringBuffer(name); if (has_opengl2) { return GL20.glGetUniformLocation(program, param); } else if (has_arb) { return ARBShaderObjects.glGetUniformLocationARB(program, param); } return -1; }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
private void SetupShaders(String shaderPath, String fragPath) { // Load the vertex shader and fragment shader vsId = ShaderHandler.loadShader(shaderPath); fsId = ShaderHandler.loadFrag(fragPath); // Create a new shader program that links both shaders pId = GL20.glCreateProgram();// ww w . j a v a 2 s.c o m GL20.glAttachShader(pId, vsId); GL20.glAttachShader(pId, fsId); // Position information will be attribute 0 GL20.glBindAttribLocation(pId, 0, "in_Position"); // Color information will be attribute 1 GL20.glBindAttribLocation(pId, 1, "in_Color"); // Textute information will be attribute 2 GL20.glBindAttribLocation(pId, 2, "in_TextureCoord"); GL20.glLinkProgram(pId); GL20.glValidateProgram(pId); // Get matrices uniform locations projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix"); viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix"); modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix"); decayLocation = GL20.glGetUniformLocation(pId, "decay"); Game.exitOnGLError("setupShaders"); }
From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java
License:Open Source License
@Override public void link() { ensureCreated("Program must be created to link."); // Link the program GL20.glLinkProgram(id);/*from w w w. ja v a 2 s. c om*/ // Check program link success if (GL20.glGetProgrami(id, GL_LINK_STATUS) == GL_FALSE) { final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH); throw new IllegalStateException( "Program could not be linked\n" + GL20.glGetProgramInfoLog(id, logLength)); } // Check for errors RenderUtil.checkGLError(); // Validate the program GL20.glValidateProgram(id); // Check program validation success if (GL20.glGetProgrami(id, GL_VALIDATE_STATUS) == GL_FALSE) { final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH); System.err.println("Program validation failed:\n" + GL20.glGetProgramInfoLog(id, logLength)); } // Check for errors RenderUtil.checkGLError(); /* * Load the program uniforms */ // Get the maximum uniform name length final int maxNameLength = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORM_MAX_LENGTH); // Create a buffer to store the name of the uniform final ByteBuffer nameBuffer = BufferUtils.createByteBuffer(maxNameLength); // Create a buffer to store the length of the uniform name final IntBuffer lengthBuffer = BufferUtils.createIntBuffer(1); // Create a buffer to store the uniform size final IntBuffer sizeBuffer = BufferUtils.createIntBuffer(1); // Create a buffer to stroe the uniform type final IntBuffer typeBuffer = BufferUtils.createIntBuffer(1); // Create a byte array to store the name in final byte[] nameBytes = new byte[maxNameLength]; int textureUnit = 0; final int uniformCount = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORMS); for (int i = 0; i < uniformCount; ++i) { // Retrieve the attributes of the uniform (length, size, type and name) GL20.glGetActiveUniform(id, i, lengthBuffer, sizeBuffer, typeBuffer, nameBuffer); // Get the length of the uniform name final int length = lengthBuffer.get(); // Get the name from the buffer and put it in the byte[] nameBuffer.get(nameBytes, 0, length); final String name = new String(nameBytes, 0, length); // Convert the name buffer to a String this.uniforms.put(name, GL20.glGetUniformLocation(id, name)); // Check if the uniform is a texture/sampler switch (typeBuffer.get()) { case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: this.textures.put(textureUnit++, name); break; default: break; } // Clear the buffers lengthBuffer.clear(); sizeBuffer.clear(); typeBuffer.clear(); nameBuffer.clear(); } // Check for errors RenderUtil.checkGLError(); }
From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java
License:Apache License
private int fetchUniformLocation(String name) { Integer location;//from w w w . java 2 s. c om if ((location = uniforms.get(name)) == null) { location = GL20.glGetUniformLocation(program, name); if (location == -1 && pedantic) throw new IllegalArgumentException("no uniform with name '" + name + "' in shader"); uniforms.put(name, location); } return location; }
From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java
License:Apache License
private void fetchUniforms() { params.clear();// w w w . j ava 2 s . c o m GL20.glGetProgram(program, GL20.GL_ACTIVE_UNIFORMS, params); int numUniforms = params.get(0); uniformNames = new String[numUniforms]; for (int i = 0; i < numUniforms; i++) { params.clear(); params.put(0, 256); type.clear(); String name = glGetActiveUniform(program, i, params, type); int location = GL20.glGetUniformLocation(program, name); uniforms.put(name, location); uniformTypes.put(name, type.get(0)); uniformNames[i] = name; } }
From source file:net.smert.frameworkgl.opengl.helpers.ShaderHelper.java
License:Apache License
public int getUniformLocation(int programID, String uniformName) { return GL20.glGetUniformLocation(programID, uniformName); }
From source file:opengl.test.object.CaroTable.java
@Override protected void initUniformValues() { this.bind();/*from w ww . j a va 2 s.c o m*/ modelID = GL20.glGetUniformLocation(this.getProgramID(), "model"); Matrix4F m = new Matrix4F(); GL20.glUniformMatrix4fv(modelID, false, m.toFloatBuffer()); viewID = GL20.glGetUniformLocation(this.getProgramID(), "view"); Matrix4F v = new Matrix4F(); GL20.glUniformMatrix4fv(viewID, false, v.toFloatBuffer()); projectionID = GL20.glGetUniformLocation(this.getProgramID(), "projection"); Matrix4F p = new Matrix4F(); GL20.glUniformMatrix4fv(projectionID, false, p.toFloatBuffer()); //--------------------------- int uniTex = GL20.glGetUniformLocation(this.getProgramID(), "texImage"); GL20.glUniform1i(uniTex, 0); this.unbind(); }