List of usage examples for org.lwjgl.opengl GL15 glBindBuffer
public static void glBindBuffer(@NativeType("GLenum") int target, @NativeType("GLuint") int buffer)
From source file:com.samrj.devil.gl.VAO.java
private VAO(Pair<VertexData, ShaderProgram> pair) { DGL.checkState();/*from w w w . ja v a 2 s.c o m*/ if (!DGL.getCapabilities().OpenGL30) throw new UnsupportedOperationException("Vertex arrays unsupported in OpenGL < 3.0"); id = GL30.glGenVertexArrays(); this.pair = pair; bind(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, pair.a.vbo()); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, pair.a.ibo()); for (ShaderProgram.Attribute satt : pair.b.getAttributes()) { VertexData.Attribute att = pair.a.getAttribute(satt.name); if (att != null) { AttributeType type = att.getType(); for (int layer = 0; layer < type.layers; layer++) { int location = satt.location + layer; GL20.glEnableVertexAttribArray(location); vertexAttribPointer(location, type, att.getStride(), att.getOffset() + layer * type.size); } } } }
From source file:com.samrj.devil.gl.VertexBuffer.java
License:Open Source License
/** * Completes this vertex buffer, uploading its vertex data to the GPU and * freeing local resources./* ww w . j ava 2 s. c o m*/ */ public void end() { ensureState(State.READY); if (numVertices <= 0) throw new IllegalStateException("No vertices emitted."); vbo = GL15.glGenBuffers(); int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, numVertices * vertexSize(), vertexBlock.address, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding); vramUsage += vertexBlock.size * 8L; vertexBlock.free(); vertexBlock = null; vertexBuffer = null; if (maxIndices > 0) { if (numIndices > 0) { ibo = GL15.glGenBuffers(); prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, numIndices * 4, indexBlock.address, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding); } vramUsage += indexBlock.size * 8L; indexBlock.free(); indexBlock = null; indexBuffer = null; } state = State.COMPLETE; Profiler.addUsedVRAM(vramUsage); }
From source file:com.samrj.devil.gl.VertexStream.java
License:Open Source License
@Override void onBegin() {//from w w w . j av a2 s . c om vboSize = maxVertices * vertexSize(); vertexBlock = new Memory(vboSize); vertexBuffer = vertexBlock.buffer; vbo = GL15.glGenBuffers(); 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.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding); if (maxIndices > 0) { eboSize = maxIndices * 4; indexBlock = new Memory(eboSize); indexBuffer = indexBlock.buffer; ibo = GL15.glGenBuffers(); 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.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding); } state = State.READY; Profiler.addUsedVRAM(vboSize * 8L); Profiler.addUsedVRAM(eboSize * 8L); }
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 ww w .j a va 2 s . co 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.samrj.devil.graphics.MeshDrawer.java
License:Open Source License
public MeshDrawer(Mesh mesh) { this.mesh = mesh; //Set up attributes. position = new Attribute(VEC3, mesh.positionOffset, true); normal = new Attribute(VEC3, mesh.normalOffset, mesh.hasNormals); uvs = new HashMap<>(); for (int i = 0; i < mesh.uvLayers.length; i++) { Attribute color = new Attribute(VEC2, mesh.uvOffsets[i], true); uvs.put(mesh.uvLayers[i], color); }/* ww w . j a v a 2 s. c o m*/ tangent = new Attribute(VEC3, mesh.tangentOffset, mesh.hasTangents); colors = new HashMap<>(); for (int i = 0; i < mesh.colorLayers.length; i++) { Attribute color = new Attribute(VEC3, mesh.colorOffsets[i], true); colors.put(mesh.colorLayers[i], color); } AttributeType groupsType, weightType; switch (mesh.numGroups) { case 0: groupsType = NONE; weightType = NONE; break; case 1: groupsType = INT; weightType = FLOAT; break; case 2: groupsType = VEC2I; weightType = VEC2; break; case 3: groupsType = VEC3I; weightType = VEC3; break; case 4: groupsType = VEC4I; weightType = VEC4; break; default: throw new IllegalArgumentException("Vertex group count over four."); } groups = new Attribute(groupsType, mesh.groupIndexOffset, mesh.numGroups > 0); weights = new Attribute(weightType, mesh.groupWeightOffset, mesh.numGroups > 0); material = new Attribute(INT, mesh.materialOffset, mesh.hasMaterials); vbo = GL15.glGenBuffers(); int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, mesh.vertexBlock.size, mesh.vertexBlock.address, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding); ibo = GL15.glGenBuffers(); prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.indexBlock.size, mesh.indexBlock.address, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding); attributes = new HashMap<>(); Profiler.addUsedVRAM(mesh.vertexBlock.size * 8L); Profiler.addUsedVRAM(mesh.indexBlock.size * 8L); }
From source file:com.timvisee.voxeltex.module.mesh.Mesh.java
License:Open Source License
/** * Render or draw the mesh using OpenGL. */// w w w .j a v a2 s . c o m public void draw(Material material) { // Bind the vertex buffer glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle); GL11.glVertexPointer(this.raw.getVertexAxisCount(), GL11.GL_FLOAT, 0, 0L); // Bind the normal coordinate buffer if available if (hasNormalData()) { glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle); GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0L); } // Bind the texture coordinate buffer if available if (hasTextureData()) { glBindBuffer(GL_ARRAY_BUFFER, vboTextureHandle); GL11.glTexCoordPointer(this.raw.getTextureAxisCount(), GL11.GL_FLOAT, 0, 0L); } // Enable the client states for the buffers that were bound GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); if (hasNormalData()) GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY); if (hasTextureData()) GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); // Draw the mesh GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.vertexCount); // Disable the client used states GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); if (hasNormalData()) GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY); if (hasTextureData()) GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); // Unbind all buffers GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java
License:Open Source License
public void create(int vaoId) { build();/*w ww. j av a2 s. 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:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java
License:Open Source License
public void destroy() { // Delete the vertex VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboId);// w ww . ja v a 2s .c o m // Delete the index VBO GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboiId); }
From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java
License:Open Source License
public void draw() { // Bind to the index VBO that has all the information about the order of // the vertices GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); // Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); // Put everything back to default (deselect) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
From source file:com.xrbpowered.gl.res.shaders.FeedbackVertices.java
License:Open Source License
public FeedbackVertices(Shader transformShader, Shader renderShader, int count, boolean createIndices) { this.transformShader = transformShader; this.renderShader = renderShader; this.countElements = count; vertexBuffer = BufferUtils.createByteBuffer(count * transformShader.info.getStride()).asFloatBuffer(); feedbackBuffer = BufferUtils.createByteBuffer(count * renderShader.info.getStride()).asFloatBuffer(); vaoId = GL30.glGenVertexArrays();//from w w w . j av a 2 s. c o m GL30.glBindVertexArray(vaoId); vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, count * transformShader.info.getStride(), GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); vboFeedbackId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboFeedbackId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, count * renderShader.info.getStride(), GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); if (createIndices) { indexBuffer = BufferUtils.createByteBuffer(count * 4).asIntBuffer(); vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, count * 4, GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); } Client.checkError(); }