List of usage examples for org.lwjgl.opengl GL30 glBindVertexArray
public static void glBindVertexArray(@NativeType("GLuint") int array)
From source file:org.spout.renderer.lwjgl.gl30.GL30VertexArray.java
License:Open Source License
@Override public void setData(VertexData vertexData) { checkCreated();/*ww w. j av a2 s .c o m*/ // Generate a new indices buffer if we don't have one yet if (indicesBufferID == 0) { indicesBufferID = GL15.glGenBuffers(); } // Bind the indices buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID); // Get the new count of indices final int newIndicesCount = vertexData.getIndicesCount(); // If the new count is greater than or 50% smaller than the old one, we'll reallocate the memory // In the first case because we need more space, in the other to save space if (newIndicesCount > indicesCount || newIndicesCount <= indicesCount * 0.5) { GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, vertexData.getIndicesBuffer(), GL15.GL_STATIC_DRAW); } else { // Else, we replace the data with the new one, but we don't resize, so some old data might be left trailing in the buffer GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, vertexData.getIndicesBuffer()); } // Unbind the indices buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); // Update the count to the new one indicesCount = newIndicesCount; indicesDrawCount = indicesCount; // Ensure that the indices offset and count fits inside the valid part of the buffer indicesOffset = Math.min(indicesOffset, indicesCount - 1); indicesDrawCount = indicesDrawCount - indicesOffset; // Bind the vao GL30.glBindVertexArray(id); // Create a new array of attribute buffers ID of the correct size final int attributeCount = vertexData.getAttributeCount(); final int[] newAttributeBufferIDs = new int[attributeCount]; // Copy all the old buffer IDs that will fit in the new array so we can reuse them System.arraycopy(attributeBufferIDs, 0, newAttributeBufferIDs, 0, Math.min(attributeBufferIDs.length, newAttributeBufferIDs.length)); // Delete any buffers that we don't need (new array is smaller than the previous one) for (int i = newAttributeBufferIDs.length; i < attributeBufferIDs.length; i++) { GL15.glDeleteBuffers(attributeBufferIDs[i]); } // Create new buffers if necessary (new array is larger than the previous one) for (int i = attributeBufferIDs.length; i < newAttributeBufferIDs.length; i++) { newAttributeBufferIDs[i] = GL15.glGenBuffers(); } // Copy the old valid attribute buffer sizes final int[] newAttributeBufferSizes = new int[attributeCount]; System.arraycopy(attributeBufferSizes, 0, newAttributeBufferSizes, 0, Math.min(attributeBufferSizes.length, newAttributeBufferSizes.length)); // Upload the new vertex data for (int i = 0; i < attributeCount; i++) { final VertexAttribute attribute = vertexData.getAttribute(i); final ByteBuffer attributeData = attribute.getData(); // Get the current buffer size final int bufferSize = newAttributeBufferSizes[i]; // Get the new buffer size final int newBufferSize = attributeData.remaining(); // Bind the target buffer GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, newAttributeBufferIDs[i]); // If the new count is greater than or 50% smaller than the old one, we'll reallocate the memory if (newBufferSize > bufferSize || newBufferSize <= bufferSize * 0.5) { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, attributeData, GL15.GL_STATIC_DRAW); } else { // Else, we replace the data with the new one, but we don't resize, so some old data might be left trailing in the buffer GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, attributeData); } // Update the buffer size to the new one newAttributeBufferSizes[i] = newBufferSize; // Next, we add the pointer to the data in the vao // We have three ways to interpret integer data if (attribute.getType().isInteger() && attribute.getUploadMode() == UploadMode.KEEP_INT) { // Directly as an int GL30.glVertexAttribIPointer(i, attribute.getSize(), attribute.getType().getGLConstant(), 0, 0); } else { // Or as a float, normalized or not GL20.glVertexAttribPointer(i, attribute.getSize(), attribute.getType().getGLConstant(), attribute.getUploadMode().normalize(), 0, 0); } // Finally enable the attribute GL20.glEnableVertexAttribArray(i); } // Unbind the last vbo GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind the vao GL30.glBindVertexArray(0); // Update the attribute buffer IDs to the new ones attributeBufferIDs = newAttributeBufferIDs; // Update the attribute buffer sizes to the new ones attributeBufferSizes = newAttributeBufferSizes; // Check for errors LWJGLUtil.checkForGLError(); }
From source file:org.spout.renderer.lwjgl.gl30.GL30VertexArray.java
License:Open Source License
@Override public void draw() { checkCreated();//w ww . jav a 2 s. com // Bind the vao GL30.glBindVertexArray(id); // Bind the index buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID); // Draw all indices with the provided mode GL11.glDrawElements(drawingMode.getGLConstant(), indicesDrawCount, GL11.GL_UNSIGNED_INT, indicesOffset * DataType.INT.getByteSize()); // Unbind the index buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind the vao GL30.glBindVertexArray(0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:ru.axialshift.vram.gl.VAOIncapsulator.java
License:Apache License
@Override protected void upload_gl() { glpointer = GL30.glGenVertexArrays(); GL30.glBindVertexArray(glpointer); vertexVBO.upload(); GL30.glBindVertexArray(0); indicesVBO.upload(); }
From source file:ru.axialshift.vram.gl.VAOIncapsulator.java
License:Apache License
@Override protected void unload_gl() { GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(glpointer); vertexVBO.unload(); indicesVBO.unload(); }
From source file:ru.axialshift.vram.gl.VAOIncapsulator.java
License:Apache License
public void drawDirectly() { GL30.glBindVertexArray(glpointer); if (contract != null) { contract.enableVBOAttribArrays(); }// ww w. j ava2s .c o m //GL20.glEnableVertexAttribArray(0); //GL20.glEnableVertexAttribArray(1); //GL20.glEnableVertexAttribArray(2); //GL20.glEnableVertexAttribArray(3); //GL20.glEnableVertexAttribArray(4); indicesVBO.draw(); GL30.glBindVertexArray(0); }
From source file:thebounzer.org.lwgldemo.Chapter3.java
License:Open Source License
@Override public void loopCycle() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(program.getId());// w w w. j ava 2s. co m vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); attributesBind(time += 0.01f); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL20.glUseProgram(0); }
From source file:thebounzer.org.lwgldemo.Chapter3.java
License:Open Source License
@Override public void destroy() { program.destroy(); GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoId); }
From source file:thebounzer.org.lwgldemo.Chapter5.java
License:Open Source License
@Override public void configure() { shaders.add(new GenericShader("src/main/resources/shadersCap5/shader.vert", GL20.GL_VERTEX_SHADER)); shaders.add(new GenericShader("src/main/resources/shadersCap5/shader.frag", GL20.GL_FRAGMENT_SHADER)); vaoId = GL30.glGenVertexArrays();//from w ww . j a v a2 s. c om GL30.glBindVertexArray(vaoId); GL11.glPointSize(5.0f); try { createAndBindVertexObject(vertex); } catch (IOException ex) { Logger.getLogger(Chapter5.class.getName()).log(Level.SEVERE, null, ex); } shaderSetup(); FloatBuffer matrixProjBuff = BufferUtils.createFloatBuffer(16); projMat.store(matrixProjBuff); matrixProjBuff.flip(); }
From source file:thebounzer.org.lwgldemo.Chapter5.java
License:Open Source License
@Override public void loopCycle() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); float f = (float) (time * Math.PI * 0.1f); Matrix4f modelViewM = new Matrix4f(); Matrix4f mat = new Matrix4f(); Matrix4f transOne = new Matrix4f(); Matrix4f transTwo = new Matrix4f(); Matrix4f rotaOne = new Matrix4f(); Matrix4f rotaTwo = new Matrix4f(); Matrix4f.translate(new Vector3f(0.0f, 0.0f, -0.4f), mat, transOne); Matrix4f.translate(new Vector3f((float) Math.sin(2.1f * f) * 0.5f, (float) Math.cos(1.7f * f) * 0.5f, (float) Math.sin(1.3f * f) * (float) Math.cos(1.5 * f) * 2.0f), mat, transTwo); Matrix4f.rotate(time * 45.0f, new Vector3f(0.0f, 1.0f, 0.0f), mat, rotaOne); Matrix4f.rotate(time * 81.0f, new Vector3f(1.0f, 0.0f, 0.0f), mat, rotaTwo); Matrix4f.mul(modelViewM, transOne, modelViewM); Matrix4f.mul(modelViewM, transTwo, modelViewM); Matrix4f.mul(modelViewM, rotaOne, modelViewM); Matrix4f.mul(modelViewM, rotaTwo, modelViewM); GL20.glUseProgram(program.getId());/*from w ww. ja v a2s .co m*/ FloatBuffer matrixBuf = BufferUtils.createFloatBuffer(16); modelViewM.store(matrixBuf); matrixBuf.flip(); int uniLoc = GL20.glGetUniformLocation(program.getId(), "mv_matrix"); GL20.glUniformMatrix4(uniLoc, false, matrixBuf); int uniProjMatLoc = GL20.glGetUniformLocation(program.getId(), "proj_matrix"); GL20.glUniformMatrix4(uniProjMatLoc, false, matrixBuf); vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); GL11.glDrawArrays(GL11.GL_POINTS, 0, 36); GL20.glUseProgram(0); time += 0.001f; }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static void glBindVertexArray(int a) { GL30.glBindVertexArray(a); }