protected BufferObject assembleVertexPoints(RenderContext rc, int numLat, int numLon, float altitude) { int count = numLat * numLon; float[] altitudes = new float[count]; Arrays.fill(altitudes, altitude); float[] points = new float[count * 3]; rc.globe.geographicToCartesianGrid(this.fullSphereSector, numLat, numLon, altitudes, 1.0f, null, points, 0, 0); int size = points.length * 4; FloatBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(points).rewind(); return new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer); }
@Override public boolean useVertexTexCoordAttrib(DrawContext dc, int attribLocation) { boolean bufferBound = (this.vertexTexCoords != null && this.vertexTexCoords.bindBuffer(dc)); if (bufferBound){ GLES20.glVertexAttribPointer(attribLocation, 2, GLES20.GL_FLOAT, false, 0, 0); } return bufferBound; }
protected void loadBuffer(DrawContext dc) { int currentBuffer = dc.currentBuffer(this.bufferTarget); try { // Create the OpenGL buffer object. if (this.bufferId[0] == 0) { this.createBufferObject(dc); } // Make the OpenGL buffer object bound to the specified target. dc.bindBuffer(this.bufferTarget, this.bufferId[0]); // Load the current NIO buffer as the OpenGL buffer object's data. this.loadBufferObjectData(dc); } catch (Exception e) { // The NIO buffer could not be used as buffer data for an OpenGL buffer object. Delete the buffer object // to ensure that calls to bindBuffer fail. this.deleteBufferObject(dc); Logger.logMessage(Logger.ERROR, "BufferObject", "loadBuffer", "Exception attempting to load buffer data", e); } finally { // Restore the current OpenGL buffer object binding. dc.bindBuffer(this.bufferTarget, currentBuffer); } }
if (this.vertexPoints == null || !this.vertexPoints.bindBuffer(dc)) { return; // vertex buffer unspecified or failed to bind if (this.triStripElements == null || !this.triStripElements.bindBuffer(dc)) { return; // element buffer unspecified or failed to bind GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, this.triStripElements.getBufferLength(), GLES20.GL_UNSIGNED_SHORT, 0);
@Override public void release(DrawContext dc) { this.deleteBufferObject(dc); this.buffer = null; // buffer can be non-null if the object has not been bound }
public boolean bindBuffer(DrawContext dc) { if (this.buffer != null) { this.loadBuffer(dc); this.buffer = null; } if (this.bufferId[0] != 0) { dc.bindBuffer(this.bufferTarget, this.bufferId[0]); } return this.bufferId[0] != 0; }
public BufferObject putBufferObject(Object key, BufferObject buffer) { this.renderResourceCache.put(key, buffer, (buffer != null) ? buffer.getBufferByteCount() : 0); return buffer; }
public BufferObject getPointBuffer(RenderContext rc) { if (this.points == null) { return null; } BufferObject bufferObject = rc.getBufferObject(this.pointBufferKey); if (bufferObject != null) { return bufferObject; } // TODO consider a pool of terrain tiles // TODO consider a pool of terrain tile vertex buffers int size = this.points.length * 4; FloatBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(this.points).rewind(); return rc.putBufferObject(this.pointBufferKey, new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer)); } }
@Override public boolean useVertexPointAttrib(DrawContext dc, int attribLocation) { boolean bufferBound = (this.vertexPoints != null && this.vertexPoints.bindBuffer(dc)); if (bufferBound) { GLES20.glVertexAttribPointer(attribLocation, 3, GLES20.GL_FLOAT, false, 0, 0); } return bufferBound; }
/** * Returns an OpenGL buffer object containing a unit square expressed as four vertices at (0, 1), (0, 0), (1, 1) and * (1, 0). Each vertex is stored as two 32-bit floating point coordinates. The four vertices are in the order * required by a triangle strip. * <p/> * The OpenGL buffer object is created on first use and cached. Subsequent calls to this method return the cached * buffer object. * * @return the draw context's unit square OpenGL buffer object */ public BufferObject unitSquareBuffer() { if (this.unitSquareBuffer != null) { return this.unitSquareBuffer; } float[] points = new float[]{ 0, 1, // upper left corner 0, 0, // lower left corner 1, 1, // upper right corner 1, 0}; // lower right corner int size = points.length * 4; FloatBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(points).rewind(); BufferObject bufferObject = new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer); return (this.unitSquareBuffer = bufferObject); }
@Override public boolean drawTriangles(DrawContext dc) { boolean bufferBound = (this.elements != null && this.elements.bindBuffer(dc)); if (bufferBound) { GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, this.triStripElementRange.length(), GLES20.GL_UNSIGNED_SHORT, this.triStripElementRange.lower * 2); } return bufferBound; }
buffer.put(elements).rewind(); return new BufferObject(GLES20.GL_ELEMENT_ARRAY_BUFFER, size, buffer);
@Override public boolean drawLines(DrawContext dc) { boolean bufferBound = (this.elements != null && this.elements.bindBuffer(dc)); if (bufferBound) { GLES20.glDrawElements(GLES20.GL_LINES, this.lineElementRange.length(), GLES20.GL_UNSIGNED_SHORT, this.lineElementRange.lower * 2); } return bufferBound; }
buffer.put(this.levelSetVertexTexCoords).rewind(); this.levelSetVertexTexCoordBuffer = rc.putBufferObject(this.levelSetVertexTexCoordKey, new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer)); buffer.rewind(); this.levelSetElementBuffer = rc.putBufferObject(this.levelSetElementKey, new BufferObject(GLES20.GL_ELEMENT_ARRAY_BUFFER, size, buffer));
@Override public void draw(DrawContext dc) { if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build } if (!dc.unitSquareBuffer().bindBuffer(dc)) { return; // vertex buffer failed to bind } // Use the draw context's pick mode and use the drawable's color. this.program.enablePickMode(dc.pickMode); // Make multi-texture unit 0 active. dc.activeTextureUnit(GLES20.GL_TEXTURE0); // Disable writing to the depth buffer. GLES20.glDepthMask(false); // Use a unit square as the vertex point and vertex tex coord attributes. GLES20.glEnableVertexAttribArray(1 /*vertexTexCoord*/); // only vertexPoint is enabled by default GLES20.glVertexAttribPointer(0 /*vertexPoint*/, 2, GLES20.GL_FLOAT, false, 0, 0); GLES20.glVertexAttribPointer(1 /*vertexTexCoord*/, 2, GLES20.GL_FLOAT, false, 0, 0); // Draw this DrawableScreenTextures. this.doDraw(dc, this); // Draw all DrawableScreenTextures adjacent in the queue that share the same GLSL program. Drawable next; while ((next = dc.peekDrawable()) != null && this.canBatchWith(next)) { // check if the drawable at the front of the queue can be batched DrawableScreenTexture drawable = (DrawableScreenTexture) dc.pollDrawable(); // take it off the queue this.doDraw(dc, drawable); } // Restore the default WorldWind OpenGL state. GLES20.glDepthMask(true); GLES20.glDisableVertexAttribArray(1 /*vertexTexCoord*/); // only vertexPoint is enabled by default }
ShortBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asShortBuffer(); buffer.put(elements.array(), 0, elements.size()); BufferObject elementBuffer = new BufferObject(GLES20.GL_ELEMENT_ARRAY_BUFFER, size, buffer.rewind()); elementBuffer.ranges.put(TOP_RANGE, topRange); elementBuffer.ranges.put(OUTLINE_RANGE, outlineRange);
if (shape.drawState.vertexBuffer == null || !shape.drawState.vertexBuffer.bindBuffer(dc)) { continue; // vertex buffer unspecified or failed to bind if (shape.drawState.elementBuffer == null || !shape.drawState.elementBuffer.bindBuffer(dc)) { continue; // element buffer unspecified or failed to bind
FloatBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(this.vertexArray, 0, this.vertexArray.length); drawState.vertexBuffer = new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer.rewind()); rc.putBufferObject(this.vertexBufferKey, drawState.vertexBuffer);
if (this.drawState.vertexBuffer == null || !this.drawState.vertexBuffer.bindBuffer(dc)) { return; // vertex buffer unspecified or failed to bind if (this.drawState.elementBuffer == null || !this.drawState.elementBuffer.bindBuffer(dc)) { return; // element buffer unspecified or failed to bind
FloatBuffer buffer = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(this.vertexArray.array(), 0, this.vertexArray.size()); drawState.vertexBuffer = new BufferObject(GLES20.GL_ARRAY_BUFFER, size, buffer.rewind()); rc.putBufferObject(this.vertexBufferKey, drawState.vertexBuffer); buffer.put(this.outlineElements.array(), 0, this.outlineElements.size()); buffer.put(this.verticalElements.array(), 0, this.verticalElements.size()); drawState.elementBuffer = new BufferObject(GLES20.GL_ELEMENT_ARRAY_BUFFER, size, buffer.rewind()); rc.putBufferObject(this.elementBufferKey, drawState.elementBuffer);