List of usage examples for org.lwjgl.opengl ARBVertexBufferObject GL_ARRAY_BUFFER_ARB
int GL_ARRAY_BUFFER_ARB
To view the source code for org.lwjgl.opengl ARBVertexBufferObject GL_ARRAY_BUFFER_ARB.
Click Source Link
From source file:com.a2client.corex.MeshBuffer.java
License:Open Source License
public void load(Const.BUFFER_TYPE buffer_type, MyInputStream in) { try {//from w w w . j a v a2 s .c o m Count = in.readInt(); Stride = in.readInt(); int total = Count * Stride; byte[] bytes = new byte[total]; int readed = in.read(bytes); if (readed != total) { Log.error("MeshBuffer load wrong bytes, total=" + total + " readed=" + readed); return; } Data = ByteBuffer.allocateDirect(total); Data.put(bytes); Data.flip(); DataPtr = MemoryUtil.getAddress(Data); if (buffer_type == Const.BUFFER_TYPE.btIndex) { DType = ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB; RType = Const.RES_TYPE.rtMeshIdex; switch (Stride) { case 1: IndexType = GL11.GL_UNSIGNED_BYTE; break; case 2: IndexType = GL11.GL_UNSIGNED_SHORT; break; case 3: IndexType = GL11.GL_FALSE; break; case 4: IndexType = GL11.GL_UNSIGNED_INT; break; default: IndexType = GL11.GL_FALSE; } } else { DType = ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB; RType = Const.RES_TYPE.rtMeshVertex; } // ? ? VBO ID = ARBVertexBufferObject.glGenBuffersARB(); ARBVertexBufferObject.glBindBufferARB(DType, ID); ARBVertexBufferObject.glBufferDataARB(DType, Data, ARBBufferObject.GL_STATIC_DRAW_ARB); ResManager.Active.put(RType, this); // Data = null; } catch (IOException e) { e.printStackTrace(); } }
From source file:com.a2client.corex.Render.java
License:Open Source License
static public void ResetBind() { ResManager.Active.clear();//from w ww .j a v a 2 s . c o m if (!multi_texture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // GL11.glBindTexture(, 0); // cube map } else { for (int i = 0; i < 16; i++) { ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB + i); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // GL11.glBindTexture(, 0); // cube map } ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB); } ARBShaderObjects.glUseProgramObjectARB(0); ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 0); ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0); // slick unbind textures // TextureImpl.unbind(); }
From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java
License:Open Source License
public static int setupVBO(final AbstractBufferData<? extends Buffer> data, final RenderContext context) { if (data == null) { return 0; }// ww w .j av a2 s.com final RendererRecord rendRecord = context.getRendererRecord(); int vboID = data.getVBOID(context.getGlContextRep()); if (vboID != 0) { updateVBO(data, rendRecord, vboID, 0); return vboID; } final Buffer dataBuffer = data.getBuffer(); if (dataBuffer != null) { // XXX: should we be rewinding? Maybe make that the programmer's responsibility. dataBuffer.rewind(); vboID = makeVBOId(); data.setVBOID(context.getGlContextRep(), vboID); rendRecord.invalidateVBO(); LwjglRendererUtil.setBoundVBO(rendRecord, vboID); if (dataBuffer instanceof FloatBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (FloatBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof ByteBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (ByteBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof IntBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (IntBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof ShortBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (ShortBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } } else { throw new Ardor3dException("Attempting to create a vbo id for a FloatBufferData with no Buffer value."); } return vboID; }
From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java
License:Open Source License
public static void updateVBO(final AbstractBufferData<? extends Buffer> data, final RendererRecord rendRecord, final int vboID, final int offsetBytes) { if (data.isNeedsRefresh()) { final Buffer dataBuffer = data.getBuffer(); dataBuffer.rewind();/*from w w w. j av a 2s . c o m*/ LwjglRendererUtil.setBoundVBO(rendRecord, vboID); if (dataBuffer instanceof FloatBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (FloatBuffer) dataBuffer); } else if (dataBuffer instanceof ByteBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (ByteBuffer) dataBuffer); } else if (dataBuffer instanceof IntBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (IntBuffer) dataBuffer); } else if (dataBuffer instanceof ShortBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (ShortBuffer) dataBuffer); } data.setNeedsRefresh(false); } }
From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java
License:Open Source License
private void initializeInterleavedVBO(final RenderContext context, final FloatBufferData interleaved, final FloatBufferData vertexCoords, final FloatBufferData normalCoords, final FloatBufferData colorCoords, final List<FloatBufferData> textureCoords, final int bufferSize) { // keep around buffer size if (interleaved.getBufferCapacity() != 1) { final FloatBuffer buffer = BufferUtils.createFloatBufferOnHeap(1); interleaved.setBuffer(buffer);/*from w w w . j ava 2 s . c o m*/ } interleaved.getBuffer().rewind(); interleaved.getBuffer().put(bufferSize); final RendererRecord rendRecord = context.getRendererRecord(); final ContextCapabilities caps = context.getCapabilities(); final int vboID = makeVBOId(); interleaved.setVBOID(context.getGlContextRep(), vboID); rendRecord.invalidateVBO(); LwjglRendererUtil.setBoundVBO(rendRecord, vboID); ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, bufferSize, getGLVBOAccessMode(interleaved.getVboAccessMode())); int offsetBytes = 0; if (normalCoords != null) { normalCoords.getBuffer().rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, normalCoords.getBuffer()); offsetBytes += normalCoords.getBufferLimit() * 4; } if (colorCoords != null) { colorCoords.getBuffer().rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, colorCoords.getBuffer()); offsetBytes += colorCoords.getBufferLimit() * 4; } if (textureCoords != null) { final TextureState ts = (TextureState) context.getCurrentState(RenderState.StateType.Texture); if (ts != null) { for (int i = 0; i <= ts.getMaxTextureIndexUsed() && i < caps.getNumberOfFragmentTexCoordUnits(); i++) { if (textureCoords == null || i >= textureCoords.size()) { continue; } final FloatBufferData textureBufferData = textureCoords.get(i); final FloatBuffer textureBuffer = textureBufferData != null ? textureBufferData.getBuffer() : null; if (textureBuffer != null) { textureBuffer.rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, textureBuffer); offsetBytes += textureBufferData.getBufferLimit() * 4; } } } } if (vertexCoords != null) { vertexCoords.getBuffer().rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, vertexCoords.getBuffer()); } interleaved.setNeedsRefresh(false); }
From source file:com.ardor3d.scene.state.lwjgl.util.LwjglRendererUtil.java
License:Open Source License
public static void setBoundVBO(final RendererRecord rendRecord, final int id) { if (!rendRecord.isVboValid() || rendRecord.getCurrentVboId() != id) { ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id); rendRecord.setCurrentVboId(id);/* w w w. j a v a2 s.c o m*/ rendRecord.setVboValid(true); } }
From source file:com.mitchellkember.mycraft.GameRenderer.java
License:Open Source License
/** * Creates the VBO that this GameRenderer will use. * /*from w ww . j a v a 2 s . c om*/ * @throws LWJGLException if VBOs are not supported */ private void initializeData() throws LWJGLException { if (!GLContext.getCapabilities().GL_ARB_vertex_buffer_object) { Mycraft.LOGGER.log(Level.SEVERE, "GL_ARB_vertex_buffer_object not supported."); throw new LWJGLException("GL_ARB_vertex_buffer_object not supported"); } // Create it bufferObjectID = ARBVertexBufferObject.glGenBuffersARB(); // Vertex Data interleaved format: XYZST final int position = 3; final int texcoords = 2; final int sizeOfInt = 4; // 4 bytes in an int final int vertexDataSize = (position + texcoords) * sizeOfInt; // Bind it ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, bufferObjectID); // Vertex and texture pointers glVertexPointer(3, GL_INT, vertexDataSize, 0); glTexCoordPointer(2, GL_INT, vertexDataSize, position * sizeOfInt); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); }
From source file:com.mitchellkember.mycraft.GameRenderer.java
License:Open Source License
/** * Updates the VBO when the a {@code chunk} in the GameState has changed. * /*from w ww. j a v a2s .co m*/ * @param chunk the chunk that has changed */ @Override public void gameStateChunkChanged(Chunk chunk) { byte[][][] data = chunk.getData(); IntBuffer vertexData = BufferUtils.createIntBuffer(70000); try { for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z > -16; z--) { if (data[x][y][-z] != 0) vertexData.put(cubeData(x, y, z)); } } } } catch (BufferOverflowException boe1) { // Try again with more memory try { vertexData = BufferUtils.createIntBuffer(150000); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z > -16; z--) { if (data[x][y][-z] != 0) vertexData.put(cubeData(x, y, z)); } } } } catch (BufferOverflowException boe2) { // Bail out System.out.println("Oops! Mycraft has crashed!"); Mycraft.LOGGER.log(Level.SEVERE, boe2.toString(), boe2); System.exit(1); } } numVerts = vertexData.position() / 5; vertexData.flip(); // Upload data ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vertexData, ARBVertexBufferObject.GL_DYNAMIC_DRAW_ARB); }
From source file:com.owens.oobjloader.lwjgl.VBOFactory.java
License:BSD License
public static VBO build(int textureID, ArrayList<Face> triangles) { // log.log(INFO, "building a vbo!"); if (triangles.size() <= 0) { throw new RuntimeException("Can not build a VBO if we have no triangles with which to build it."); }/*from www. ja va 2 s . c o m*/ // Now sort out the triangle/vertex indices, so we can use a // VertexArray in our VBO. Note the following is NOT the most efficient way // to do this, but hopefully it is clear. // First build a map of the unique FaceVertex objects, since Faces may share FaceVertex objects. // And while we're at it, assign each unique FaceVertex object an index as we run across them, storing // this index in the map, for use later when we build the "index" buffer that refers to the vertice buffer. // And lastly, keep a list of the unique vertice objects, in the order that we find them in. HashMap<FaceVertex, Integer> indexMap = new HashMap<FaceVertex, Integer>(); int nextVertexIndex = 0; ArrayList<FaceVertex> faceVertexList = new ArrayList<FaceVertex>(); for (Face face : triangles) { for (FaceVertex vertex : face.vertices) { if (!indexMap.containsKey(vertex)) { indexMap.put(vertex, nextVertexIndex++); faceVertexList.add(vertex); } } } // Now build the buffers for the VBO/IBO int verticeAttributesCount = nextVertexIndex; int indicesCount = triangles.size() * 3; int numMIssingNormals = 0; int numMissingUV = 0; FloatBuffer verticeAttributes; log.log(INFO, "Creating buffer of size " + verticeAttributesCount + " vertices at " + VBO.ATTR_SZ_FLOATS + " floats per vertice for a total of " + (verticeAttributesCount * VBO.ATTR_SZ_FLOATS) + " floats."); verticeAttributes = BufferUtils.createFloatBuffer(verticeAttributesCount * VBO.ATTR_SZ_FLOATS); if (null == verticeAttributes) { log.log(SEVERE, "Unable to allocate verticeAttributes buffer of size " + (verticeAttributesCount * VBO.ATTR_SZ_FLOATS) + " floats."); } for (FaceVertex vertex : faceVertexList) { verticeAttributes.put(vertex.v.x); verticeAttributes.put(vertex.v.y); verticeAttributes.put(vertex.v.z); if (vertex.n == null) { // @TODO: What's a reasonable default normal? Maybe add code later to calculate normals if not present in .obj file. verticeAttributes.put(1.0f); verticeAttributes.put(1.0f); verticeAttributes.put(1.0f); numMIssingNormals++; } else { verticeAttributes.put(vertex.n.x); verticeAttributes.put(vertex.n.y); verticeAttributes.put(vertex.n.z); } // @TODO: What's a reasonable default texture coord? if (vertex.t == null) { // verticeAttributes.put(0.5f); // verticeAttributes.put(0.5f); verticeAttributes.put((float) Math.random()); verticeAttributes.put((float) Math.random()); numMissingUV++; } else { verticeAttributes.put(vertex.t.u); verticeAttributes.put(vertex.t.v); } } verticeAttributes.flip(); log.log(INFO, "Had " + numMIssingNormals + " missing normals and " + numMissingUV + " missing UV coords"); IntBuffer indices; // indices into the vertices, to specify triangles. indices = BufferUtils.createIntBuffer(indicesCount); for (Face face : triangles) { for (FaceVertex vertex : face.vertices) { int index = indexMap.get(vertex); indices.put(index); } } indices.flip(); // Allrighty! Now give them to OpenGL! IntBuffer verticeAttributesIDBuf = BufferUtils.createIntBuffer(1); ARBVertexBufferObject.glGenBuffersARB(verticeAttributesIDBuf); ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticeAttributesIDBuf.get(0)); ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticeAttributes, ARBVertexBufferObject.GL_STATIC_DRAW_ARB); IntBuffer indicesIDBuf = BufferUtils.createIntBuffer(1); ARBVertexBufferObject.glGenBuffersARB(indicesIDBuf); ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indicesIDBuf.get(0)); ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indices, ARBVertexBufferObject.GL_STATIC_DRAW_ARB); // our copy of the data is no longer necessary, it is safe in OpenGL. // We don't need to null this out but it makes the point. verticeAttributes = null; indices = null; return new VBO(textureID, verticeAttributesIDBuf.get(0), indicesIDBuf.get(0), indicesCount); }
From source file:net.adam_keenan.voxel.world.BlockVBO.java
License:Creative Commons License
public void render(BlockType type, float x, float y, float z) { TextureLoader.bind(Textures.SHEET);//from w w w.j ava 2s . co m int vertID = this.blockVertexBufferID, texID; switch (type) { case DIRT: texID = dirtTextureID; break; case STONE: texID = stoneTextureID; break; case GRASS: texID = grassTextureID; break; case AIR: texID = 0; break; case FIRE: texID = grassTextureID; vertID = this.projectileVBOID; break; default: texID = stoneTextureID; break; } if (texID == 0) return; GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); // Vertex array ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vertID); GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0); // Texture array ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, texID); GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0); // Index array ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexBufferID); // Draw 'em up GL12.glDrawRangeElements(GL11.GL_QUADS, 0, 6 * 4, 6 * 4, GL11.GL_UNSIGNED_INT, 0); GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); GL11.glPopMatrix(); TextureLoader.unbind(); }