List of usage examples for org.lwjgl.opengl GL15 GL_STREAM_DRAW
int GL_STREAM_DRAW
To view the source code for org.lwjgl.opengl GL15 GL_STREAM_DRAW.
Click Source Link
From source file:com.samrj.devil.gl.VertexStream.java
License:Open Source License
/** * Uploads this vertex data to the GPU and clears the stream, allowing new * data to be emitted.//from w ww .ja v a 2 s .c o m */ public void upload() { ensureState(State.READY); //Allocate new stores, orphaning the old ones to allow for asynchronous drawing. int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboSize, GL15.GL_STREAM_DRAW); GL15.nglBufferSubData(GL15.GL_ARRAY_BUFFER, 0, bufferedVerts * vertexSize(), vertexBlock.address); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding); if (maxIndices > 0) { prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, eboSize, GL15.GL_STREAM_DRAW); GL15.nglBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, bufferedInds * 4, indexBlock.address); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding); } uploadedVerts = bufferedVerts; uploadedInds = bufferedInds; clear(); }
From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java
License:Open Source License
public void create(int vaoId) { build();/* w ww . j a v a 2s . c om*/ GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW); // Put the position coordinates in attribute list 0 GL20.glVertexAttribPointer(0, RenderingConstants.POSITION_ELEMENT_COUNT, GL11.GL_FLOAT, false, RenderingConstants.STRIDE, RenderingConstants.POSITION_BYTE_OFFSET); // Put the color components in attribute list 1 GL20.glVertexAttribPointer(1, RenderingConstants.COLOUR_ELEMENT_COUNT, GL11.GL_FLOAT, false, RenderingConstants.STRIDE, RenderingConstants.COLOUR_BYTE_OFFSET); // Put the texture coordinates in attribute list 2 GL20.glVertexAttribPointer(2, RenderingConstants.TEXTURE_ELEMENT_COUNT, GL11.GL_FLOAT, false, RenderingConstants.STRIDE, RenderingConstants.TEXTURE_BYTE_OFFSET); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); // Create a new VBO for the indices and select it (bind) - INDICES vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) { // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class vertices = new VertexData[vertex.length]; for (int i = 0; i < vertex.length; i++) { vertices[i] = new VertexData(); vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z); vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f); vertices[i].setST(uv[i].x, uv[i].y); }//from w w w . j a v a2s.c o m // Put each 'Vertex' in one FloatBuffer verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (int i = 0; i < vertices.length; i++) { // Add position, color and texture floats to the buffer verticesFloatBuffer.put(vertices[i].getElements()); } verticesFloatBuffer.flip(); // OpenGL expects to draw vertices in counter clockwise order by default // TODO: Move this to Setup. byte[] indices = { 0, 1, 2, 2, 3, 0 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); // Create a new Vertex Array Object in memory and select it (bind) vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW); // Put the position coordinates in attribute list 0 GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.positionByteOffset); // Put the color components in attribute list 1 GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.colorByteOffset); // Put the texture coordinates in attribute list 2 GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.textureByteOffset); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); // Create a new VBO for the indices and select it (bind) - INDICES vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); Game.cameraPos = new Vector3f(0, 0, -1); Game.exitOnGLError("setupQuad"); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public void resizeBuffer() { vertByteBuff = BufferUtils.createByteBuffer(vertexCount * Vertex.stride); ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer(); for (Drawable object : objects) { object.store(vertFloatBuff);//from w ww .ja va2 s . com indicesBuffer.put(object.getIndices()); } for (Drawable object : orthoObjects) { object.store(vertFloatBuff); indicesBuffer.put(object.getIndices()); } indicesBuffer.flip(); vertFloatBuff.flip(); GL30.glBindVertexArray(vaoId); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertFloatBuff, GL15.GL_STREAM_DRAW); GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.stride, 0); GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.stride, 16); GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, Vertex.stride, 32); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
From source file:org.jogamp.glg2d.impl.shader.AnyModePipeline.java
License:Apache License
public void bindBufferData(FloatBuffer vertexBuffer) { bindBuffer();/*from w ww . ja v a 2s. c o m*/ int count = vertexBuffer.limit() - vertexBuffer.position(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuffer, GL15.GL_STREAM_DRAW); }
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 {//from w ww. jav a2 s .c om 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:uk.co.ifs_studios.engine.geometry.BasicDrawElement.java
License:Open Source License
/** * Set colors to DrawElement./*from w w w . jav a 2 s . co m*/ * * @param colors * - Colors. */ public void setColors(Color[] colors) { float[] colorValues = new float[colors.length * 4]; int colorIndex = 0; for (int i = 0; i < colorValues.length; i += 4) { colorValues[i + 0] = colors[colorIndex].getRed(); colorValues[i + 1] = colors[colorIndex].getGreen(); colorValues[i + 2] = colors[colorIndex].getBlue(); colorValues[i + 3] = colors[colorIndex].getAlpha(); colorIndex++; } FloatBuffer colorsBuffer = BufferUtils.createFloatBuffer(colorValues.length); colorsBuffer.put(colorValues); colorsBuffer.flip(); GL30.glBindVertexArray(this.vao); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.cbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorsBuffer, GL15.GL_STREAM_DRAW); GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:voxels.Mesh.java
License:Open Source License
private void createMesh() { // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class VertexData v0 = new VertexData(); v0.setXYZ(-0.5f, 0.5f, 0.5f);// w ww. java 2s . c o m v0.setRGB(1, 0, 0); v0.setST(0, 0); VertexData v1 = new VertexData(); v1.setXYZ(-0.5f, -0.5f, 0.5f); v1.setRGB(0, 1, 0); v1.setST(0, 1); VertexData v2 = new VertexData(); v2.setXYZ(0.5f, -0.5f, 0.5f); v2.setRGB(0, 0, 1); v2.setST(1, 1); VertexData v3 = new VertexData(); v3.setXYZ(0.5f, 0.5f, 0.5f); v3.setRGB(1, 1, 1); v3.setST(1, 0); VertexData v4 = new VertexData(); v4.setXYZ(-0.5f, 0.5f, -0.5f); v4.setRGB(1, 0, 0); v4.setST(0, 0); VertexData v5 = new VertexData(); v5.setXYZ(-0.5f, -0.5f, -0.5f); v5.setRGB(0, 1, 0); v5.setST(0, 1); VertexData v6 = new VertexData(); v6.setXYZ(-0.5f, -0.5f, 0.5f); v6.setRGB(0, 0, 1); v6.setST(1, 1); VertexData v7 = new VertexData(); v7.setXYZ(-0.5f, 0.5f, 0.5f); v7.setRGB(1, 1, 1); v7.setST(1, 0); VertexData v8 = new VertexData(); v8.setXYZ(-0.5f, 0.5f, -0.5f); v8.setRGB(1, 0, 0); v8.setST(0, 0); VertexData v9 = new VertexData(); v9.setXYZ(-0.5f, 0.5f, 0.5f); v9.setRGB(0, 1, 0); v9.setST(0, 1); VertexData v10 = new VertexData(); v10.setXYZ(0.5f, 0.5f, 0.5f); v10.setRGB(0, 0, 1); v10.setST(1, 1); VertexData v11 = new VertexData(); v11.setXYZ(0.5f, 0.5f, -0.5f); v11.setRGB(1, 1, 1); v11.setST(1, 0); VertexData v12 = new VertexData(); v12.setXYZ(0.5f, -0.5f, 0.5f); v12.setRGB(1, 0, 0); v12.setST(0, 0); VertexData v13 = new VertexData(); v13.setXYZ(-0.5f, -0.5f, 0.5f); v13.setRGB(0, 1, 0); v13.setST(0, 1); VertexData v14 = new VertexData(); v14.setXYZ(-0.5f, -0.5f, -0.5f); v14.setRGB(0, 0, 1); v14.setST(1, 1); VertexData v15 = new VertexData(); v15.setXYZ(0.5f, -0.5f, -0.5f); v15.setRGB(1, 1, 1); v15.setST(1, 0); VertexData v16 = new VertexData(); v16.setXYZ(0.5f, -0.5f, -0.5f); v16.setRGB(1, 0, 0); v16.setST(0, 0); VertexData v17 = new VertexData(); v17.setXYZ(-0.5f, -0.5f, -0.5f); v17.setRGB(0, 1, 0); v17.setST(0, 1); VertexData v18 = new VertexData(); v18.setXYZ(-0.5f, 0.5f, -0.5f); v18.setRGB(0, 0, 1); v18.setST(1, 1); VertexData v19 = new VertexData(); v19.setXYZ(0.5f, 0.5f, -0.5f); v19.setRGB(1, 1, 1); v19.setST(1, 0); VertexData v20 = new VertexData(); v20.setXYZ(0.5f, -0.5f, 0.5f); v20.setRGB(1, 0, 0); v20.setST(0, 0); VertexData v21 = new VertexData(); v21.setXYZ(0.5f, -0.5f, -0.5f); v21.setRGB(0, 1, 0); v21.setST(0, 1); VertexData v22 = new VertexData(); v22.setXYZ(0.5f, 0.5f, -0.5f); v22.setRGB(0, 0, 1); v22.setST(1, 1); VertexData v23 = new VertexData(); v23.setXYZ(0.5f, 0.5f, 0.5f); v23.setRGB(1, 1, 1); v23.setST(1, 0); vertices = new VertexData[] { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23 }; // Put each 'Vertex' in one FloatBuffer verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (VertexData vertice : vertices) { // Add position, color and texture floats to the buffer verticesFloatBuffer.put(vertice.getElements()); } verticesFloatBuffer.flip(); // OpenGL expects to draw vertices in counter clockwise order by default short[] indices = new short[6 * vertices.length / 4]; for (short i = 0; i < indices.length / 6; i++) { // 0, 1, 2, 2, 3, 0,4, 5 , 0, 5, 1, 0, 1, 5, 2, 5, 6, 2, 3, 0, 7, 0, 2, 7, 8, 6, 4, 6, 5, 4, 2, 3, 8, 3, 6, 8 indices[i * 6 + 0] = (short) (0 + 4 * i); indices[i * 6 + 1] = (short) (1 + 4 * i); indices[i * 6 + 2] = (short) (2 + 4 * i); indices[i * 6 + 3] = (short) (2 + 4 * i); indices[i * 6 + 4] = (short) (3 + 4 * i); indices[i * 6 + 5] = (short) (0 + 4 * i); } //indices = new byte[]{0, 1, 2, 2, 3, 0,4, 5 , 0, 5, 1, 0, 1, 5, 2, 5, 6, 2, 3, 0, 7, 0, 2, 7, 8, 6, 4, 6, 5, 4, 2, 3, 8, 3, 6, 8}; vertices = null; indicesCount = indices.length; ShortBuffer indicesBuffer = BufferUtils.createShortBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); // Create a new Vertex Array Object in memory and select it (bind) vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW); // Put the position coordinates in attribute list 0 GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.positionByteOffset); // Put the color components in attribute list 1 GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.colorByteOffset); // Put the texture coordinates in attribute list 2 GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.textureByteOffset); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); // Create a new VBO for the indices and select it (bind) - INDICES vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }