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 } }
@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { Log.d(TAG, "onSurfaceCreated"); GLUtils.init(); GLUtils.printSysConfig(); // set the background color GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f); // set up the "camera" Matrix.setLookAtM( mViewMatrix, 0, 0.0f, 0.0f, 1.0f, // eye x,y,z 0.0f, 0.0f, 0.0f, // look x,y,z 0.0f, 1.0f, 0.0f); // up x,y,z mExternalSurfaceTexture = new ExternalSurfaceTexture(); mReadExternalTextureShaderProgram = new ReadExternalTextureShaderProgram(); mDefaultShaderProgram = new TextureShaderProgram(); mTextureToScreenShaderProgram = new TextureShaderProgram(); if (mOnExternalSurfaceTextureCreatedListener != null) { mOnExternalSurfaceTextureCreatedListener.onExternalSurfaceTextureCreated( mExternalSurfaceTexture); } mFrameRateCalculator = new FrameRateCalculator(30); }
public void saveCurrentFrame(OnFrameCapturedCallback callback) { callback.onFrameCaptured(GLUtils.getFrameBuffer(mWidth, mHeight)); }
/* The format of the grid parameters is the following: * <grid> * <resolution nx=10 ny=10></resolution> * <point> * <coord x="0.5" y="+0.5"></coord> * <texcoord s="0.0" t="1.0"></texcoord> * </point> * <point> * <coord x="x" y="y"></coord> * <texcoord s="s" t="t"></texcoord> * </point> * </grid> */ protected void initGrid(XMLElement xml) { int n = xml.getChildCount(); // if there is only one parameter line, it should contain the // grid dimensions. if (n == 1) { numLayers = 1; } else { numLayers = n - 1; } points = new GLTexturedPoint[numLayers]; XMLElement child; String name, wStr, hStr, modeName; int ptLayer = 0; for (int i = 0; i < n; i++) { child = xml.getChild(i); name = child.getName(); if (name.equals("resolution")) { wStr = child.getStringAttribute("nx"); hStr = child.getStringAttribute("ny"); usingSrcTexRes = false; if (wStr.equals("w")) resX = 0; else if (wStr.equals("w0")) resX = -1; else if (wStr.equals("w1")) resX = -2; else if (wStr.equals("w2")) resX = -3; else if (wStr.equals("w3")) resX = -4; else if (wStr.equals("w4")) resX = -5; else if (wStr.equals("w5")) resX = -6; else resX = child.getIntAttribute("nx"); if (hStr.equals("h")) resY = 0; else if (hStr.equals("h0")) resY = -1; else if (hStr.equals("h1")) resY = -2; else if (hStr.equals("h2")) resY = -3; else if (hStr.equals("h3")) resY = -4; else if (hStr.equals("h4")) resY = -5; else if (hStr.equals("h5")) resY = -6; else resY = child.getIntAttribute("ny"); if ((resX <= 0) || (resY <= 0)) if (resX != resY) System.err.println("Source width and height are different!"); else if (resX < 0) { usingSrcTexRes = true; srcTexIdx = -(resX + 1); } modeName = child.getStringAttribute("mode"); mode = GLUtils.parsePrimitiveType(modeName); } else if (name.equals("point")) { points[ptLayer] = new GLTexturedPoint(child); ptLayer++; } } if (n == 1) { points[0] = new GLTexturedPoint(); points[0].setAsUndefined(); } }
public static void setBackgroundColor(int color) { mClearColor = GLUtils.colorToFloat(color); }
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); }