List of usage examples for org.lwjgl.opengl GL15 glBufferData
public static void glBufferData(@NativeType("GLenum") int target, @NativeType("void const *") double[] data, @NativeType("GLenum") int usage)
From source file:opengl.test.object.XO.java
private void initVertexO() { GL30.glBindVertexArray(vao);//bind vao this.VertexColorBuffer = objLoad .VertexColorLoad(XO.class.getClassLoader().getResourceAsStream("opengl/test/object/O.obj")); Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity : " + VertexColorBuffer.capacity()); this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); this.indices = objLoad .indicesLoad(XO.class.getClassLoader().getResourceAsStream("opengl/test/object/O.obj")); this.ebo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_DYNAMIC_DRAW); GL30.glBindVertexArray(0);//unbind vao }
From source file:org.ajgl.graphics.VertexBufferedObject.java
License:Open Source License
/** * Creates a vertex buffer object handler. * @param drawMode - The OpenGL draw mode of the object. * @param vertices - The vertices of the object * @return The int value of the handler. *//*from w ww . ja v a2 s. c o m*/ @OpenGLInfo(fwdCompatible = false, openGLVersion = "1.5", status = "Release") public static int createVboHandler(@DrawMode int drawMode, FloatBuffer vertices) { // Initialize vertex VBO handler int handler = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, handler); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, drawMode); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); return handler; }
From source file:org.bonsaimind.badgersvoyage.opengl.RenderObject.java
License:Open Source License
protected void createOpenGL(int programId) { modelMatrix = new Matrix4f(); modelMatrixLocation = GL20.glGetUniformLocation(programId, "modelMatrix"); modelMatrixBuffer = BufferUtils.createFloatBuffer(16); verticesCount = vertices.length / 3; verticesBuffer = BufferUtils.createFloatBuffer(vertices.length); verticesBuffer.put(vertices);// w ww. j ava 2s . com verticesBuffer.flip(); 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); }
From source file:org.craftmania.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG)/*from w w w . java2 s .com*/ System.out.println("Building " + meshType.name() + " Mesh for " + chunk.toString() + "..."); /* Make sure there are no list edits anymore */ chunk.performListChanges(); ChunkMesh mesh = chunk.getMesh(); mesh.destroy(meshType); /* Compute vertex count */ int vertexCount = chunk.getVertexCount(meshType); if (DEBUG) System.out.println("\tVertex Count = " + vertexCount); /* * If there are no faces visible yet (because of generating busy), don't * create a buffer */ if (vertexCount == 0) { return; } mesh.setVertexCount(meshType, vertexCount); /* Create a buffer */ int vbo = BufferManager.getInstance().createBuffer(); mesh.setVBO(meshType, vbo); /* Bind the buffer */ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); /* Allocate size for the buffer */ int size = vertexCount * STRIDE * FLOAT_SIZE; GL15.glBufferData(GL15.GL_ARRAY_BUFFER, size, GL15.GL_STATIC_DRAW); if (DEBUG) System.out.println( "\tCreate VBO: " + vbo + " with size = " + size + " (ERROR: " + GL11.glGetError() + ")"); /* Get the native buffer to write to */ ByteBuffer byteBuffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, size, null); if (byteBuffer == null) { System.out.println("\tCouldn't create a native VBO!: GL Error Code = " + GL11.glGetError()); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); mesh.destroy(meshType); Thread.dumpStack(); mesh.setVBO(meshType, -1); mesh.setVertexCount(meshType, 0); return; } FloatBuffer vertexBuffer = byteBuffer.asFloatBuffer(); /* Store all vertices in the buffer */ USED_SIZE = 0; /* Local temporary variables, used to speed up */ IntList blockList = chunk.getVisibleBlocks(); int blockIndex = -1; byte blockType = 0; boolean special = false; Vec3i vec = new Vec3i(); BlockType type; Block block = null; LightBuffer lightBuffer = chunk.getLightBuffer(); byte faceMask = 0; /* Iterate over the blocks */ for (int i = 0; i < blockList.size(); ++i) { blockIndex = blockList.get(i); blockType = chunk.getChunkData().getBlockType(blockIndex); if (blockType == 0) continue; special = chunk.getChunkData().isSpecial(blockIndex); type = _blockManager.getBlockType(blockType); if ((meshType == MeshType.OPAQUE && !type.isTranslucent() && type.hasNormalAABB()) || (meshType == MeshType.TRANSLUCENT && (type.isTranslucent() || !type.hasNormalAABB()))) { ChunkData.indexToPosition(blockIndex, vec); /* Build the light buffer */ vec.setX(vec.x() + chunk.getAbsoluteX()); vec.setZ(vec.z() + chunk.getAbsoluteZ()); lightBuffer.setReferencePoint(vec.x(), vec.y(), vec.z()); if (special) { block = chunk.getChunkData().getSpecialBlock(blockIndex); if (block.isVisible()) { block.storeInVBO(vertexBuffer, lightBuffer); } } else { if (type.isCrossed()) { type.getCrossedBlockBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f, lightBuffer); } else { faceMask = chunk.getChunkData().getFaceMask(blockIndex); type.getDefaultBlockBrush().setFaceMask(faceMask); type.getBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f, lightBuffer); } } } } /* Perform a check */ if (USED_SIZE != STRIDE * FLOAT_SIZE * mesh.getVertexCount(meshType)) { System.out.println("\t[WARNING!]: Used size = " + USED_SIZE); System.out.println("\t[WARNING!]: Vertex count = " + USED_SIZE / STRIDE / FLOAT_SIZE); mesh.setVertexCount(meshType, USED_SIZE / STRIDE / FLOAT_SIZE); } byteBuffer.flip(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:org.jogamp.glg2d.impl.shader.AnyModePipeline.java
License:Apache License
public void bindBufferData(FloatBuffer vertexBuffer) { bindBuffer();//w w w. j a v a2 s . 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 ww w . ja v a2s . 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.jogamp.glg2d.impl.shader.GL2ES2ImagePipeline.java
License:Apache License
protected void bufferData(FloatBuffer buffer) { vertexBufferId = ensureIsGLBuffer(vertexBufferId); GL20.glEnableVertexAttribArray(vertCoordLocation); GL20.glEnableVertexAttribArray(texCoordLocation); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(vertCoordLocation, 2, GL11.GL_FLOAT, false, 4 * (Float.SIZE / Byte.SIZE), 0); GL20.glVertexAttribPointer(texCoordLocation, 2, GL11.GL_FLOAT, false, 4 * (Float.SIZE / Byte.SIZE), 2 * (Float.SIZE / Byte.SIZE)); }
From source file:org.minetweak.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG) {/* ww w . j a v a2s. c o m*/ System.out.println("Building " + meshType.name() + " Mesh for " + chunk.toString() + "..."); } /* Make sure there are no list edits anymore */ chunk.performListChanges(); ChunkMesh mesh = chunk.getMesh(); mesh.destroy(meshType); /* Compute vertex count */ int vertexCount = chunk.getVertexCount(meshType); if (DEBUG) { System.out.println("\tVertex Count = " + vertexCount); } /* * If there are no faces visible yet (because of generating busy), don't * create a buffer */ if (vertexCount == 0) { return; } mesh.setVertexCount(meshType, vertexCount); /* Create a buffer */ int vbo = BufferManager.getInstance().createBuffer(); mesh.setVBO(meshType, vbo); /* Bind the buffer */ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); /* Allocate size for the buffer */ int size = vertexCount * STRIDE * FLOAT_SIZE; GL15.glBufferData(GL15.GL_ARRAY_BUFFER, size, GL15.GL_STATIC_DRAW); if (DEBUG) { System.out.println( "\tCreate VBO: " + vbo + " with size = " + size + " (ERROR: " + GL11.glGetError() + ")"); } /* Get the native buffer to write to */ ByteBuffer byteBuffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, size, null); if (byteBuffer == null) { System.out.println("\tCouldn't create a native VBO!: GL Error Code = " + GL11.glGetError()); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); mesh.destroy(meshType); Thread.dumpStack(); mesh.setVBO(meshType, -1); mesh.setVertexCount(meshType, 0); return; } FloatBuffer vertexBuffer = byteBuffer.asFloatBuffer(); /* Store all vertices in the buffer */ USED_SIZE = 0; /* Local temporary variables, used to speed up */ IntList blockList = chunk.getVisibleBlocks(); int blockIndex = -1; byte blockType = 0; boolean special = false; Vec3i vec = new Vec3i(); BlockType type; Block block = null; LightBuffer lightBuffer = chunk.getLightBuffer(); byte faceMask = 0; /* Iterate over the blocks */ for (int i = 0; i < blockList.size(); ++i) { blockIndex = blockList.get(i); blockType = chunk.getChunkData().getBlockType(blockIndex); if (blockType == 0) { continue; } special = chunk.getChunkData().isSpecial(blockIndex); type = _blockManager.getBlockType(blockType); if ((meshType == MeshType.OPAQUE && !type.isTranslucent() && type.hasNormalAABB()) || (meshType == MeshType.TRANSLUCENT && (type.isTranslucent() || !type.hasNormalAABB()))) { ChunkData.indexToPosition(blockIndex, vec); /* Build the light buffer */ vec.setX(vec.x() + chunk.getAbsoluteX()); vec.setZ(vec.z() + chunk.getAbsoluteZ()); lightBuffer.setReferencePoint(vec.x(), vec.y(), vec.z()); if (special) { block = chunk.getChunkData().getSpecialBlock(blockIndex); if (block.isVisible()) { block.storeInVBO(vertexBuffer, lightBuffer); } } else { if (type.isCrossed()) { type.getCrossedBlockBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f, lightBuffer); } else { faceMask = chunk.getChunkData().getFaceMask(blockIndex); type.getDefaultBlockBrush().setFaceMask(faceMask); type.getBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f, lightBuffer); } } } } /* Perform a check */ if (USED_SIZE != STRIDE * FLOAT_SIZE * mesh.getVertexCount(meshType)) { System.out.println("\t[WARNING!]: Used size = " + USED_SIZE); System.out.println("\t[WARNING!]: Vertex count = " + USED_SIZE / STRIDE / FLOAT_SIZE); mesh.setVertexCount(meshType, USED_SIZE / STRIDE / FLOAT_SIZE); } byteBuffer.flip(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:org.oscim.gdx.GdxGL20.java
License:Apache License
public void glBufferData(int target, int size, Buffer data, int usage) { if (data == null) throw new GdxRuntimeException("Using null for the data not possible, blame LWJGL"); else if (data instanceof ByteBuffer) GL15.glBufferData(target, (ByteBuffer) data, usage); else if (data instanceof IntBuffer) GL15.glBufferData(target, (IntBuffer) data, usage); else if (data instanceof FloatBuffer) GL15.glBufferData(target, (FloatBuffer) data, usage); else if (data instanceof DoubleBuffer) GL15.glBufferData(target, (DoubleBuffer) data, usage); else if (data instanceof ShortBuffer) // GL15.glBufferData(target, (ShortBuffer) data, usage); }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void bufferData(int target, int size, Buffer data, int usage) { if (data == null) GL15.glBufferData(target, size, usage); else if (data instanceof ByteBuffer) GL15.glBufferData(target, (ByteBuffer) data, usage); else if (data instanceof IntBuffer) GL15.glBufferData(target, (IntBuffer) data, usage); else if (data instanceof FloatBuffer) GL15.glBufferData(target, (FloatBuffer) data, usage); else if (data instanceof DoubleBuffer) GL15.glBufferData(target, (DoubleBuffer) data, usage); else if (data instanceof ShortBuffer) // GL15.glBufferData(target, (ShortBuffer) data, usage); }