List of usage examples for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER
int GL_ARRAY_BUFFER
To view the source code for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.
Click Source Link
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
@Override public void endWriteGeometry(GeometryHandle geometry) { if (canUseVBOs) { GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }//from w w w. j a v a 2 s . c o m }
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
@Override public GeometryHandle generateGeometry(int bytes) { int vertexBufferId; if (canUseVBOs) { vertexBufferId = allocateVBO();// ww w.j a v a 2s . c om if (vertexBufferId == 0) { return null; } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, BufferUtils.createByteBuffer(bytes), GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } else { ByteBuffer bb = ByteBuffer.allocateDirect(bytes); bb.order(ByteOrder.nativeOrder()); vertexBufferId = geometries.size(); geometries.add(bb); } return new LWJGLGeometryHandle(this, vertexBufferId); }
From source file:gui.lwjgl.GUIElementLoader.java
/** * Stores data in an attribute list of a VAO. * * @param vaoID The id of the VAO to which data will be added. * @param attributeNumber The number of the attribute list in which the data * will be stored.//from ww w. ja v a 2 s . com * @param data The data that will be stored in the attribute list. */ private static void storeDataInAttributeList(int vaoID, int attributeNumber, int coordinateSize, float[] data) { // bind VAO so that it can be used. bindVAO(vaoID); // Create new VBO. int vboID = GL15.glGenBuffers(); // Adds VBO to list so that it can be cleared when needed. vbos.add(vboID); // VBO has to be bound aswel. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); // Converts float array to an instance of FloatBuffer, which can // be stored in a VBO. FloatBuffer buffer = Convert.toReadableFloatBuffer(data); // Puts the buffer into the VBO, and GL_STATIC_DRAW tells it that it // won't ever be modified. GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); // Specifies that this is for the Vertex Array. GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0); // Unbind the VBO. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // unbind VAO so that another may be bound. unbindVAO(); }
From source file:itdelatrisu.opsu.render.CurveRenderState.java
License:Open Source License
/** * Restore the old OpenGL state that's backed up in {@code state}. * @param state the old state to restore */// w w w.java 2 s . c o m private void endRender(RenderState state) { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPopMatrix(); GL11.glEnable(GL11.GL_BLEND); GL20.glUseProgram(state.oldProgram); GL13.glActiveTexture(state.texUnit); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer); if (!state.depthWriteEnabled) GL11.glDepthMask(false); if (!state.depthEnabled) GL11.glDisable(GL11.GL_DEPTH_TEST); if (state.texEnabled) GL11.glEnable(GL11.GL_TEXTURE_2D); if (state.smoothedPoly) GL11.glEnable(GL11.GL_POLYGON_SMOOTH); if (!state.blendEnabled) GL11.glDisable(GL11.GL_BLEND); }
From source file:itdelatrisu.opsu.render.CurveRenderState.java
License:Open Source License
/** * Do the actual drawing of the curve into the currently bound framebuffer. * @param color the color of the curve/* w w w . j a v a2s .co m*/ * @param borderColor the curve border color * @param curve the points along the curve */ private void draw_curve(Color color, Color borderColor, Vec2f[] curve) { staticState.initGradient(); RenderState state = startRender(); int vtx_buf; // the size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone) FloatBuffer buff = BufferUtils .createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2)) .asFloatBuffer(); staticState.initShaderProgram(); vtx_buf = GL15.glGenBuffers(); for (int i = 0; i < curve.length; ++i) { float x = curve[i].x; float y = curve[i].y; //if (i == 0 || i == curve.length - 1){ fillCone(buff, x, y, NewCurveStyleState.DIVIDES); if (i != 0) { float last_x = curve[i - 1].x; float last_y = curve[i - 1].y; double diff_x = x - last_x; double diff_y = y - last_y; x = (float) (x - diff_x / 2); y = (float) (y - diff_y / 2); fillCone(buff, x, y, NewCurveStyleState.DIVIDES); } } buff.flip(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW); GL20.glUseProgram(staticState.program); GL20.glEnableVertexAttribArray(staticState.attribLoc); GL20.glEnableVertexAttribArray(staticState.texCoordLoc); GL20.glUniform1i(staticState.texLoc, 0); GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b); GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a); //stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w) //2*4 is for skipping the first 2 floats (u,v) GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4); GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0); for (int i = 0; i < curve.length * 2 - 1; ++i) GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2); GL20.glDisableVertexAttribArray(staticState.texCoordLoc); GL20.glDisableVertexAttribArray(staticState.attribLoc); GL15.glDeleteBuffers(vtx_buf); endRender(state); }
From source file:ivorius.ivtoolkit.models.data.VertexBufferObject.java
License:Apache License
private void bufferChanged() { if (isBound) { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage); isDirty = false; } }
From source file:ivorius.ivtoolkit.models.data.VertexBufferObject.java
License:Apache License
/** * Disposes of all resources this VertexBufferObject uses. *//*from ww w . j a v a 2 s . com*/ @Override public void dispose() { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); if (bufferHandle > 0) GL15.glDeleteBuffers(bufferHandle); bufferHandle = 0; }
From source file:kubex.gui.Chunk.java
License:Creative Commons License
/** * Updates this chunk graphics card data, for it to match the current chunk data. Normally called when some part of the chunk has changed *//*from w w w. j a va 2 s . c om*/ public void update() { if (this.changed) { if (this.updateFlag) this.changed = false; else { this.WF.requestChunkUpdate(this); //If the cube has changed we request an update } } //If the buffer of triangles isn't null, we have new data to upload if (this.toUpload != null) { if (this.getUpdateAccessSemaphore().tryAcquire()) { //Prevents us to upload data to the graphic card and create a new triangle buffer at the same time if (this.triangleNum == 0 && this.triangleLiquidNum == 0) { //If there are no triangles to draw //Bye array! if (this.chunkCubes.isTrueStorage()) { //If there was triangles to draw before, but now there aren't, we can substitute the array of chunk cubes over a constant value, saving memory byte defval = this.chunkCubes.get(0, 0, 0); //Not only the air chunks arent draw: Underground ones can be fully culled too this.WF.getMapHandler().storeChunk(getX(), getY(), getZ(), this.chunkCubes, this.initcializedFlag); //IF the chunk was all air it wouldn't matter, but if it isnt drawed //Because its culled, it contains different cubes inside it, they just cant be seen //We dispose the chunk per now, until some of this cubes can be seen, and then we will load it again. Saving memory! this.chunkCubes = new ConstantValueCubeStorage(defval, this, CubeStorageType.CUBES_STORAGE); //If it is air, it will always return 0. If it is solid, any solid value will do. } //We are disposing the chunk till some part of it can be seen, so we delete the vbo per now too if (this.vbo != -1) { glDeleteBuffers(this.vbo); this.vbo = -1; } } else { //If the chunk was disposed, we reload it. Finally some part of it is visible! if (this.vbo == -1) this.vbo = glGenBuffers(); if (!this.chunkCubes.isTrueStorage()) { this.notifyCubeStorageUpdate(this.chunkCubes.get(0, 0, 0), CubeStorageType.CUBES_STORAGE); //Reload the original values into chunkCubes } //Upload the buffer data to the graphics card glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); glBufferData(GL15.GL_ARRAY_BUFFER, (this.triangleNum + this.triangleLiquidNum) * SAN * 4, GL15.GL_DYNAMIC_DRAW); //Yes, the content can indeed change: But it doesn't change very often, so GL_DYNAMIC_DRAW is an overkill. glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, this.toUpload); glBufferSubData(GL15.GL_ARRAY_BUFFER, this.triangleNum * SAN * 4, this.toUploadLiquid); glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } //Recycle buffers and dispose resources used FloatBufferPool.recycleBuffer(this.toUpload); FloatBufferPool.recycleBuffer(this.toUploadLiquid); this.toUpload = null; this.toUploadLiquid = null; this.solidEmpty = false; this.liquidEmpty = false; if (this.triangleNum == 0) this.solidEmpty = true; if (this.triangleLiquidNum == 0) this.liquidEmpty = true; this.getUpdateAccessSemaphore().release(); } } }
From source file:kubex.gui.Chunk.java
License:Creative Commons License
/** * Draws this chunk into the screen, used the data already uploaded to the graphics card, using a shader <VSP> and a camera <c> * /* w w w . j ava 2s . co m*/ * If no boundary checker is especified, the check will use the camera view frustrum, and no draw will happen if the entire chunk is outside of it. * If a boundary checker is especified (Used normally for shadows), the check will use the boundary checker, and no draw will happen if the entire chunk is outside the bounds specified by <bc> */ public void draw(Camera c, VoxelShaderProgram VSP, BoundaryChecker bc) { if (changed || this.toUpload != null) update(); //We update this chunk before drawing if some part of it has changed if (this.solidEmpty && this.liquidEmpty) return; //If it is empty, we dont bother drawing this.drawed = true; if (bc == null) { //If no boundary check is especified, we check over the standard view frustrum boundary Matrix4f mvp = new Matrix4f(); this.chunkModelMatrix.m30 = (float) (chunkx * Chunk.CHUNK_DIMENSION - this.WF.getCameraCenter().x); this.chunkModelMatrix.m31 = (float) (chunky * Chunk.CHUNK_DIMENSION - this.WF.getCameraCenter().y); this.chunkModelMatrix.m32 = (float) (chunkz * Chunk.CHUNK_DIMENSION - this.WF.getCameraCenter().z); Matrix4f.mul(c.getProjectionViewMatrix(), this.chunkModelMatrix, mvp); Vector4f coords = MatrixHelper.multiply(mvp, CENTER_VECTOR); float xc = coords.x / (coords.w); float yc = coords.y / (coords.w); double normDiam = CHUNK_RADIUS / Math.abs(coords.w); if (Math.abs(xc) > 1 + normDiam || Math.abs(yc) > 1 + normDiam || coords.z < -CHUNK_RADIUS) { this.drawed = false; //If the sphere envolving the chunk is outside the view frustrum, we dont draw it (It cant be seen, anyways) } } else { if (!bc.sharesBoundariesWith( (float) (this.getX() * Chunk.CHUNK_DIMENSION + CENTER_VECTOR.x - this.WF.getCameraCenter().x), (float) (this.getY() * Chunk.CHUNK_DIMENSION + CENTER_VECTOR.y - this.WF.getCameraCenter().y), (float) (this.getZ() * Chunk.CHUNK_DIMENSION + CENTER_VECTOR.z - this.WF.getCameraCenter().z), (float) CHUNK_RADIUS)) this.drawed = false; } if (drawed) { if (this.solidEmpty) return; glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); VSP.setupAttributes(); //Coordinates are centered in the player, to avoid floating point errors at high distances MatrixHelper.uploadTranslationMatrix(this.chunkModelMatrix, chunkx * Chunk.CHUNK_DIMENSION, chunky * Chunk.CHUNK_DIMENSION, chunkz * Chunk.CHUNK_DIMENSION, this.WF.getCameraCenter(), VSP.getModelMatrixLoc()); glDrawArrays(GL_TRIANGLES, 0, this.triangleNum); glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } }
From source file:kubex.gui.Chunk.java
License:Creative Commons License
/** * Draws the chunk liquid triangles into the screen. They will be only drawed if the chunk is on the boundary check, checked before in draw(), which setted a flag this.drawed if so. *///from w w w. ja v a 2 s . co m public void drawLiquids(Camera c, VoxelShaderProgram VSP) { if (this.liquidEmpty) return; if (this.drawed) { glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); VSP.setupAttributes(); MatrixHelper.uploadTranslationMatrix(this.chunkModelMatrix, chunkx * Chunk.CHUNK_DIMENSION, chunky * Chunk.CHUNK_DIMENSION, chunkz * Chunk.CHUNK_DIMENSION, this.WF.getCameraCenter(), VSP.getModelMatrixLoc()); glDrawArrays(GL_TRIANGLES, this.triangleNum, this.triangleLiquidNum); glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } }