List of usage examples for org.lwjgl.opengl GL15 glBufferSubData
public static void glBufferSubData(@NativeType("GLenum") int target, @NativeType("GLintptr") long offset, @NativeType("void const *") double[] data)
From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java
License:Apache License
public void updateBufferElementData(int vboID, int offsetBytes, ByteBuffer byteBuffer) { GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID); GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, offsetBytes, byteBuffer); }
From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java
License:Apache License
public void updateBufferElementData(int vboID, int offsetBytes, IntBuffer intBuffer) { GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID); GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, offsetBytes, intBuffer); }
From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java
License:Apache License
public void updateBufferElementData(int vboID, int offsetBytes, ShortBuffer shortBuffer) { GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID); GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, offsetBytes, shortBuffer); }
From source file:org.jogamp.glg2d.impl.shader.GeometryShaderStrokePipeline.java
License:Apache License
protected void bindBuffer(FloatBuffer vertexBuffer) { GL20.glEnableVertexAttribArray(vertCoordLocation); GL20.glEnableVertexAttribArray(vertBeforeLocation); GL20.glEnableVertexAttribArray(vertAfterLocation); if (GL15.glIsBuffer(vertCoordBuffer)) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertCoordBuffer); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertexBuffer); } else {/* w ww . j a va 2 s .co m*/ vertCoordBuffer = GLG2DUtils.genBufferId(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertCoordBuffer); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuffer, GL15.GL_STREAM_DRAW); } GL20.glVertexAttribPointer(vertCoordLocation, 2, GL11.GL_FLOAT, false, 0, 2 * (Float.SIZE / Byte.SIZE)); GL20.glVertexAttribPointer(vertBeforeLocation, 2, GL11.GL_FLOAT, false, 0, 0); GL20.glVertexAttribPointer(vertAfterLocation, 2, GL11.GL_FLOAT, false, 0, 4 * (Float.SIZE / Byte.SIZE)); }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void bufferSubData(int target, int offset, int size, Buffer data) { if (data == null) throw new GdxRuntimeException("Using null for the data not possible, blame LWJGL"); else if (data instanceof ByteBuffer) GL15.glBufferSubData(target, offset, (ByteBuffer) data); else if (data instanceof IntBuffer) GL15.glBufferSubData(target, offset, (IntBuffer) data); else if (data instanceof FloatBuffer) GL15.glBufferSubData(target, offset, (FloatBuffer) data); else if (data instanceof DoubleBuffer) GL15.glBufferSubData(target, offset, (DoubleBuffer) data); else if (data instanceof ShortBuffer) // GL15.glBufferSubData(target, offset, (ShortBuffer) data); }
From source file:org.spout.engine.renderer.vertexbuffer.SpoutFloatBuffer.java
License:Open Source License
public boolean flush(boolean force) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); SpoutRenderer.checkGLError();//from www . j ava 2 s . co m //Re/Allocate if needed if (buffer.limit() > allocated) { allocated = buffer.limit(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, allocated * FLOAT_SIZE, usage); SpoutRenderer.checkGLError(); } //GL15.glBufferData(GL15.GL_ARRAY_BUFFER, 0, usage); //SpoutRenderer.checkGLError(); int end; if (force) { end = buffer.capacity(); } else { end = Math.min(current + STEP, buffer.capacity()); } buffer.position(current); buffer.limit(end); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, current * FLOAT_SIZE, buffer); SpoutRenderer.checkGLError(); current = end; GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); SpoutRenderer.checkGLError(); if (end == buffer.capacity()) { buffer = null; return true; } return false; }
From source file:org.spout.renderer.lwjgl.gl20.GL20VertexArray.java
License:Open Source License
@Override public void setData(VertexData vertexData) { checkCreated();/*from w ww.ja v a 2 s. co 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 if (extension.has()) { extension.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)); // If we don't have a vao, we have to save the properties manually if (!extension.has()) { attributeSizes = new int[attributeCount]; attributeTypes = new int[attributeCount]; attributeNormalizing = new boolean[attributeCount]; } // 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 if (extension.has()) { // As a float, normalized or not GL20.glVertexAttribPointer(i, attribute.getSize(), attribute.getType().getGLConstant(), attribute.getUploadMode().normalize(), 0, 0); // Enable the attribute GL20.glEnableVertexAttribArray(i); } else { // Else we save the properties for rendering attributeSizes[i] = attribute.getSize(); attributeTypes[i] = attribute.getType().getGLConstant(); attributeNormalizing[i] = attribute.getUploadMode().normalize(); } } // Unbind the last vbo GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind the vao if (extension.has()) { extension.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 setData(VertexData vertexData) { checkCreated();// www. j a v a 2 s. c om // 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:playn.java.JavaGL20.java
License:Apache License
@Override public void glBufferSubData(int target, int offset, int size, Buffer data) { // Limit the buffer to the given size, restoring it afterwards int oldLimit = data.limit(); if (data instanceof ByteBuffer) { ByteBuffer subData = (ByteBuffer) data; subData.limit(subData.position() + size); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof IntBuffer) { IntBuffer subData = (IntBuffer) data; subData.limit(subData.position() + size / 4); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof FloatBuffer) { FloatBuffer subData = (FloatBuffer) data; subData.limit(subData.position() + size / 4); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof DoubleBuffer) { DoubleBuffer subData = (DoubleBuffer) data; subData.limit(subData.position() + size / 8); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof ShortBuffer) { ShortBuffer subData = (ShortBuffer) data; subData.limit(subData.position() + size / 2); GL15.glBufferSubData(target, offset, subData); }/*from www . j av a 2 s . co m*/ data.limit(oldLimit); }
From source file:processing.lwjgl.PGL.java
License:Open Source License
public void bufferSubData(int target, int offset, int size, Buffer data) { if (data instanceof ByteBuffer) { GL15.glBufferSubData(target, offset, (ByteBuffer) data); } else if (data instanceof ShortBuffer) { GL15.glBufferSubData(target, offset, (ShortBuffer) data); } else if (data instanceof IntBuffer) { GL15.glBufferSubData(target, offset, (IntBuffer) data); } else if (data instanceof FloatBuffer) { GL15.glBufferSubData(target, offset, (FloatBuffer) data); }//from ww w .j a v a 2 s. c om }