List of usage examples for org.lwjgl.opengl GL15 glGenBuffers
@NativeType("void") public static int glGenBuffers()
From source file:com.opengrave.og.gui.UIElement.java
License:Open Source License
public int getBufferID() { if (bufferID == 0) { bufferID = GL15.glGenBuffers(); } return bufferID; }
From source file:com.opengrave.og.light.Depth2DFramebuffer.java
License:Open Source License
public Depth2DFramebuffer(int size) { framebufferSize = size;// ww w .j a v a 2 s .c o m framebuffer = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); shadowMap = new Texture2DShadowMap(framebufferSize); shadowMap.bindToFrameBuffer(); // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0); GL11.glDrawBuffer(GL11.GL_NONE); Util.checkErr(); GL11.glReadBuffer(GL11.GL_NONE); int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); if (i != GL30.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException("Framebuffer creation failed with code: " + i); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); // TESTING STUFF count = 2; FloatBuffer pos = BufferUtils.createFloatBuffer(3 * 3 * count); FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 3 * count); pos.put(0.75f).put(0.75f).put(0f); pos.put(0.75f).put(0.25f).put(0f); pos.put(0.25f).put(0.75f).put(0f); pos.put(0.25f).put(0.25f).put(0f); pos.put(0.75f).put(0.25f).put(0f); pos.put(0.25f).put(0.75f).put(0f); pos.flip(); tex.put(1f).put(1f); tex.put(1f).put(0f); tex.put(0f).put(1f); tex.put(0f).put(0f); tex.put(1f).put(0f); tex.put(0f).put(1f); tex.flip(); vao_ID = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao_ID); int vbo_pos_ID = GL15.glGenBuffers(); int vbo_tex_ID = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_pos_ID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, pos, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_ID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tex, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0); }
From source file:com.redthirddivision.quad.rendering.models.Model.java
License:Apache License
private void storeInAttribList(int attribNumber, int coordSize, float[] data) { int vboID = GL15.glGenBuffers(); ResourceManager.addVBO(vboID);// ww w .j a v a 2 s .c o m GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); FloatBuffer buffer = Util.storeInFloatBuffer(data); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(attribNumber, coordSize, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:com.redthirddivision.quad.rendering.models.Model.java
License:Apache License
private void bindIndicesBuffer(int[] indices) { int vboID = GL15.glGenBuffers(); ResourceManager.addVBO(vboID);/*from w w w .ja va 2 s . co m*/ GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID); IntBuffer buffer = Util.storeInIntBuffer(indices); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); }
From source file:com.rfdickerson.openworld.CubeGeometry.java
@Override void init() {/* w ww. j a v a 2s . c o m*/ float[] vertices = { -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f }; byte[] indices = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 4, 3, 5, 0, 4, 6, 0, 6, 1 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length); verticesBuffer.put(vertices); verticesBuffer.flip(); //vertexCount = 6; vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); 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); this.isLoaded = true; exitOnGLError("init terrain patch"); }
From source file:com.rfdickerson.openworld.RenderSurface.java
@Override void init() {//from w w w . j a v a 2 s.co m float[] vertices = { -0.5f, 0f, -0.5f, -0.5f, 0f, 0.5f, 0.5f, 0f, 0.5f, 0.5f, 0f, -0.5f }; byte[] indices = { 0, 1, 3, 1, 2, 3 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length); verticesBuffer.put(vertices); verticesBuffer.flip(); //vertexCount = 6; vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); 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); this.isLoaded = true; exitOnGLError("init terrain patch"); }
From source file:com.runescape.client.revised.client.lwjgl.Mesh.java
License:Open Source License
public Mesh() { this.setVbo(GL15.glGenBuffers()); this.setSize(0); }
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./*from w w w . j a v a 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() {/* w ww . j a va2s .co m*/ 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.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 av a 2 s. com*/ 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); }