List of usage examples for org.lwjgl.opengl GL20 glGetActiveUniform
public static void glGetActiveUniform(@NativeType("GLuint") int program, @NativeType("GLuint") int index, @Nullable @NativeType("GLsizei *") int[] length, @NativeType("GLint *") int[] size, @NativeType("GLenum *") int[] type, @NativeType("GLchar *") ByteBuffer name)
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Program.java
License:MIT License
@Override public void link() { checkCreated();// w ww . j a v a 2s.c o m // Add the attribute layouts to the program state final TObjectIntIterator<String> iterator = attributeLayouts.iterator(); while (iterator.hasNext()) { iterator.advance(); // Bind the index to the name GL20.glBindAttribLocation(id, iterator.value(), iterator.key()); } // Link program GL20.glLinkProgram(id); // Check program link status if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000)); } if (CausticUtil.isDebugEnabled()) { // Validate program GL20.glValidateProgram(id); // Check program validation status if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { final Logger logger = CausticUtil.getCausticLogger(); logger.log(Level.WARNING, "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}", GL20.glGetProgramInfoLog(id, 1000)); } } // Load uniforms uniforms.clear(); final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS); final int maxLength = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH); final IntBuffer lengthBuffer = CausticUtil.createIntBuffer(1); final IntBuffer ignored1 = CausticUtil.createIntBuffer(1); final IntBuffer ignored2 = CausticUtil.createIntBuffer(1); final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(maxLength); final byte[] nameBytes = new byte[maxLength]; for (int i = 0; i < uniformCount; i++) { lengthBuffer.clear(); ignored1.clear(); ignored2.clear(); nameBuffer.clear(); GL20.glGetActiveUniform(id, i, lengthBuffer, ignored1, ignored2, nameBuffer); final int length = lengthBuffer.get(); nameBuffer.get(nameBytes, 0, length); // Simplify array names final String name = new String(nameBytes, 0, length).replaceFirst("\\[\\d+\\]", ""); uniforms.put(name, GL20.glGetUniformLocation(id, name)); uniformValues.put(name, UNSET); } // Check for errors LWJGLUtil.checkForGLError(); }
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);//w w w . jav a2 s.c o m // 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:org.spout.renderer.lwjgl.gl20.GL20Program.java
License:Open Source License
@Override public void link() { checkCreated();//from ww w .ja va 2 s . c om // Add the attribute layouts to the program state final TObjectIntIterator<String> iterator = attributeLayouts.iterator(); while (iterator.hasNext()) { iterator.advance(); // Bind the index to the name GL20.glBindAttribLocation(id, iterator.value(), iterator.key()); } // Link program GL20.glLinkProgram(id); // Check program link status if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000)); } if (CausticUtil.isDebugEnabled()) { // Validate program GL20.glValidateProgram(id); // Check program validation status if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { final Logger logger = CausticUtil.getCausticLogger(); logger.log(Level.WARNING, "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}", GL20.glGetProgramInfoLog(id, 1000)); } } // Load uniforms uniforms.clear(); final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS); for (int i = 0; i < uniformCount; i++) { final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(256); GL20.glGetActiveUniform(id, i, CausticUtil.createIntBuffer(1), CausticUtil.createIntBuffer(1), CausticUtil.createIntBuffer(1), nameBuffer); nameBuffer.rewind(); final byte[] nameBytes = new byte[256]; nameBuffer.get(nameBytes); // Simplify array names final String name = new String(nameBytes).trim().replaceFirst("\\[\\d+\\]", ""); uniforms.put(name, GL20.glGetUniformLocation(id, name)); } // Check for errors LWJGLUtil.checkForGLError(); }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static void glGetActiveUniform(int a, int b, IntBuffer c, IntBuffer d, IntBuffer e, ByteBuffer f) { GL20.glGetActiveUniform(a, b, c, d, e, f); }