List of usage examples for org.lwjgl.opengl GL15 glMapBuffer
@Nullable @NativeType("void *") public static ByteBuffer glMapBuffer(@NativeType("GLenum") int target, @NativeType("GLenum") int access, long length, @Nullable ByteBuffer old_buffer)
From source file:name.martingeisse.stackd.client.system.OpenGlVertexBuffer.java
License:Open Source License
/** * Maps this buffer to main memory.//w w w.jav a 2 s.c o m * * @param readable whether the mapped buffer should be readable * @param writeable whether the mapped buffer should be writable */ public final void map(boolean readable, boolean writeable) { if (!readable && !writeable) { throw new IllegalArgumentException("requested buffer mapping that is neither readable nor writable"); } int access = (!readable ? GL15.GL_WRITE_ONLY : !writeable ? GL15.GL_READ_ONLY : GL15.GL_READ_WRITE); GL15.glMapBuffer(GL_ARRAY_BUFFER, access, size, null); }
From source file:net.kubin.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG) {/* ww w . ja v a 2s. c om*/ 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 BlockDef = 0; boolean special = false; Vec3i vec = new Vec3i(); BlockDef 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); BlockDef = chunk.getChunkData().getBlockDef(blockIndex); if (BlockDef == 0) { continue; } special = chunk.getChunkData().isSpecial(blockIndex); type = _blockManager.getBlockDef(BlockDef); 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 { 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.craftmania.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG)//from w w w. j a va 2 s. 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.minetweak.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG) {/* ww w . ja va 2 s . co 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:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static ByteBuffer glMapBuffer(int a, int b, long c, ByteBuffer d) { return GL15.glMapBuffer(a, b, c, d); }