public void onDrawFrame() { frametime = System.currentTimeMillis(); rerender = false; mMap.beginFrame(); draw(); mMap.doneFrame(rerender); mBufferPool.releaseBuffers(); TextureItem.disposeTextures(); }
private void draw() { GLState.setClearColor(mClearColor); gl.depthMask(true); gl.stencilMask(0xFF); gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT | GL.STENCIL_BUFFER_BIT); gl.depthMask(false); gl.stencilMask(0); GLState.test(false, false); GLState.blend(false); GLState.bindTex2D(-1); GLState.useProgram(-1); GLState.bindElementBuffer(-1); GLState.bindVertexBuffer(-1); mViewport.setFrom(mMap); if (GLAdapter.debugView) { /* modify this to scale only the view, to see * which tiles are rendered */ mViewport.mvp.setScale(0.5f, 0.5f, 1); mViewport.viewproj.multiplyLhs(mViewport.mvp); mViewport.proj.multiplyLhs(mViewport.mvp); } /* update layers */ LayerRenderer[] layers = mMap.layers().getLayerRenderer(); for (int i = 0, n = layers.length; i < n; i++) { LayerRenderer renderer = layers[i]; if (!renderer.isInitialized) { renderer.setup(); renderer.isInitialized = true; } renderer.update(mViewport); if (renderer.isReady) renderer.render(mViewport); if (GLAdapter.debug) GLUtils.checkGlError(renderer.getClass().getName()); } if (GLUtils.checkGlOutOfMemory("finish")) { BufferObject.checkBufferUsage(true); // FIXME also throw out some textures etc } }
public void onSurfaceChanged(int width, int height) { // log.debug("onSurfaceChanged: new={}, {}x{}", mNewSurface, width, height); if (width <= 0 || height <= 0) return; gl.viewport(0, 0, width, height); // GL.scissor(0, 0, width, height); // GL.enable(GL20.SCISSOR_TEST); gl.clearStencil(0x00); gl.disable(GL.CULL_FACE); gl.blendFunc(GL.ONE, GL.ONE_MINUS_SRC_ALPHA); gl.frontFace(GL.CW); gl.cullFace(GL.BACK); if (!mNewSurface) { mMap.updateMap(false); return; } mNewSurface = false; /** initialize quad indices used by Texture- and LineTexRenderer */ int[] vboIds = GLUtils.glGenBuffers(2); mQuadIndicesID = vboIds[0]; short[] indices = new short[MAX_INDICES]; for (int i = 0, j = 0; i < MAX_INDICES; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); indices[i + 3] = (short) (j + 2); indices[i + 4] = (short) (j + 1); indices[i + 5] = (short) (j + 3); } ShortBuffer buf = MapRenderer.getShortBuffer(indices.length); buf.put(indices); buf.flip(); GLState.bindElementBuffer(mQuadIndicesID); gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, indices.length * 2, buf, GL.STATIC_DRAW); GLState.bindElementBuffer(0); /** initialize default quad */ FloatBuffer floatBuffer = MapRenderer.getFloatBuffer(8); float[] quad = new float[] {-1, -1, -1, 1, 1, -1, 1, 1}; floatBuffer.put(quad); floatBuffer.flip(); mQuadVerticesID = vboIds[1]; GLState.bindVertexBuffer(mQuadVerticesID); gl.bufferData(GL.ARRAY_BUFFER, quad.length * 4, floatBuffer, GL.STATIC_DRAW); GLState.bindVertexBuffer(0); GLState.init(); mMap.updateMap(true); }