private SharedGeometry(GLDrawContext dc, int index) { this.index = index; geometry = dc.generateGeometry(CAPACITY*4, EGeometryFormatType.Texture2D, true, "sharedgeometry-" + index); }
private void validate(GLDrawContext dc) { if(!geometry.isValid()) { geometry = dc.generateGeometry(CAPACITY*4, EGeometryFormatType.Texture2D, true, "sharedgeometry-" + index); size = 0; } }
private void generateGeometry(MapDrawContext context) throws IllegalBufferException { int vertices = bufferWidth*bufferHeight*3*2; shapeHandle = context.getGl().generateGeometry(vertices, EGeometryFormatType.Texture3D, false, "background-shape"); colorHandle = context.getGl().generateGeometry(vertices, EGeometryFormatType.ColorOnly, true, "background-color"); ByteBuffer shape_bfr = ByteBuffer.allocateDirect(BYTES_PER_FIELD_SHAPE*bufferWidth).order(ByteOrder.nativeOrder()); ByteBuffer color_bfr = ByteBuffer.allocateDirect(BYTES_PER_FIELD_COLOR*bufferWidth).order(ByteOrder.nativeOrder()); for(int y = 0;y != bufferHeight;y++) { for(int x = 0; x != bufferWidth;x++) { addTrianglesToGeometry(context, shape_bfr, x, y); } context.getGl().updateGeometryAt(shapeHandle, BYTES_PER_FIELD_SHAPE*bufferWidth*y, shape_bfr); shape_bfr.rewind(); } for(int y = 0;y != bufferHeight;y++) { int line_bfr4 = y*bufferWidth*4; for(int x = 0; x != bufferWidth;x++) { addColorTrianglesToGeometry(context, color_bfr, x, y, line_bfr4+x*4); } context.getGl().updateGeometryAt(colorHandle, BYTES_PER_FIELD_COLOR*bufferWidth*y, color_bfr); color_bfr.rewind(); } }
private void checkStaticHandles(GLDrawContext gl) throws IllegalBufferException { checkHandles(gl); if(buildHandle == null || !buildHandle.isValid()) { buildHandle = gl.generateGeometry(3, EGeometryFormatType.Texture2D, true, "building-progress"); } if(rectHandle == null || SharedGeometry.isInvalid(gl, rectHandle)) { rectHandle = SharedGeometry.addGeometry(gl, SharedGeometry.createQuadGeometry(0, 1, 1, 0, 0, 0, 1, 1)); } }
if(geometry == null || !geometry.isValid()) { geometry = context.storeGeometry( new float[] {0, 0, 0, 0, width, 0, 1, 0,(stride + 1) * width, height, 1, 1, stride * width, height, 0, 1,}, EGeometryFormatType.Texture2D, false, "minimap"); lineGeometry = context.generateGeometry(6, EGeometryFormatType.VertexOnly2D, true, "minimap-frame");
private void drawSelectionHint(GLDrawContext gl) { if (this.currentSelectionAreaStart != null && this.currentSelectionAreaEnd != null) { if(selectionArea == null || !selectionArea.isValid()) { selectionArea = gl.generateGeometry(4, EGeometryFormatType.VertexOnly2D, true, "selection-area"); } if(updateSelectionArea) { updateSelectionArea(); try { gl.updateGeometryAt(selectionArea, 0, selectionAreaBuffer); } catch (IllegalBufferException e) { e.printStackTrace(); } updateSelectionArea = false; } try { gl.draw2D(selectionArea, null, EGeometryType.LineLoop, 0, 4, 0, 0, 0, 1, 1, 1, null, 1); } catch (IllegalBufferException e) { e.printStackTrace(); } } }
@Override public void drawAt(GLDrawContext gl) { FloatRectangle position = getPosition(); float fillX = barFillPercentage < .01f ? 0 : barFillPercentage > .99f ? 1 : EMPTY_X * (1 - barFillPercentage) + FULL_X * barFillPercentage; float maxX = position.getMinX() * (1 - fillX) + position.getMaxX() * fillX; try { if (geometry == null || !geometry.isValid()) geometry = gl.generateGeometry(4, EGeometryFormatType.VertexOnly2D, false, name); if (!position.equals(writtenPosition) || writtenMaxX != maxX) { writtenPosition = position; writtenMaxX = maxX; geometryBfr.asFloatBuffer().put(new float[]{ maxX, position.getMinY(), position.getMinX(), position.getMinY(), position.getMinX(), position.getMaxY(), maxX, position.getMaxY()}); gl.updateGeometryAt(geometry, 0, geometryBfr); } gl.draw2D(geometry, null, EGeometryType.Quad, 0, 4, 0, 0, 0, 1, 1, 1, barColor, 1); } catch(IllegalBufferException ex) { ex.printStackTrace(); } super.drawBackground(gl); }