Java Code Examples for android.opengl.GLES20#glDrawArrays()
The following examples show how to use
android.opengl.GLES20#glDrawArrays() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TexturedRectangle.java From Spectaculum with Apache License 2.0 | 6 votes |
public void draw(TextureShaderProgram shaderProgram) { // write vertex data mVertices.position(sPositionOffset); GLES20.glVertexAttribPointer(shaderProgram.mPositionHandle, sPositionDataSize, GLES20.GL_FLOAT, false, sStrideBytes, mVertices); GLES20.glEnableVertexAttribArray(shaderProgram.mPositionHandle); // write uv data mVertices.position(sUVOffset); GLES20.glVertexAttribPointer(shaderProgram.mTextureCoordHandle, sUVDataSize, GLES20.GL_FLOAT, false, sStrideBytes, mVertices); GLES20.glEnableVertexAttribArray(shaderProgram.mTextureCoordHandle); //GLES20.glActiveTexture(GLES20.GL_TEXTURE0); //GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID); // write the MVP matrix GLES20.glUniformMatrix4fv(shaderProgram.mMVPMatrixHandle, 1, false, mMVPMatrix, 0); // finally, render the rectangle GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLUtils.checkError("TexturedRectangle.draw"); }
Example 2
Source File: GlFilter.java From CameraRecorder-android with MIT License | 6 votes |
public void draw(final int texName, final GLES20FramebufferObject fbo) { useProgram(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferName); GLES20.glEnableVertexAttribArray(getHandle("aPosition")); GLES20.glVertexAttribPointer(getHandle("aPosition"), VERTICES_DATA_POS_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_POS_OFFSET); GLES20.glEnableVertexAttribArray(getHandle("aTextureCoord")); GLES20.glVertexAttribPointer(getHandle("aTextureCoord"), VERTICES_DATA_UV_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_UV_OFFSET); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texName); GLES20.glUniform1i(getHandle("sTexture"), 0); onDraw(); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(getHandle("aPosition")); GLES20.glDisableVertexAttribArray(getHandle("aTextureCoord")); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
Example 3
Source File: TreasureHuntActivity.java From PanoramaGL with Apache License 2.0 | 6 votes |
/** * Draw the floor. * * <p>This feeds in data for the floor into the shader. Note that this doesn't feed in data about * position of the light, so if we rewrite our code to draw the floor first, the lighting might * look strange. */ public void drawFloor() { GLES20.glUseProgram(floorProgram); // Set ModelView, MVP, position, normals, and color. GLES20.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0); GLES20.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0); GLES20.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0); GLES20.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0); GLES20.glVertexAttribPointer( floorPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, floorVertices); GLES20.glVertexAttribPointer(floorNormalParam, 3, GLES20.GL_FLOAT, false, 0, floorNormals); GLES20.glVertexAttribPointer(floorColorParam, 4, GLES20.GL_FLOAT, false, 0, floorColors); GLES20.glEnableVertexAttribArray(floorPositionParam); GLES20.glEnableVertexAttribArray(floorNormalParam); GLES20.glEnableVertexAttribArray(floorColorParam); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 24); checkGLError("drawing floor"); }
Example 4
Source File: GSYVideoGLViewCustomRender4.java From GSYVideoPlayer with Apache License 2.0 | 6 votes |
@Override public void onDrawFrame(GL10 glUnused) { super.onDrawFrame(glUnused); GLES20.glUseProgram(mProgram); float[] transform = new float[16]; Matrix.setIdentityM(transform, 0); Matrix.scaleM(transform, 0, (float) mCurrentViewWidth / mSurfaceView.getWidth(), (float) mCurrentViewHeight / mSurfaceView.getHeight(), 1); GLES20.glUniformMatrix4fv(getMuSTMatrixHandle(), 1, false, mSTMatrix, 0); GLES20.glUniformMatrix4fv(getMuMVPMatrixHandle(), 1, false, transform, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFinish(); }
Example 5
Source File: TextureRender.java From LiveMultimedia with Apache License 2.0 | 5 votes |
public void drawFrame(SurfaceTexture st) { checkGlError("onDrawFrame start"); st.getTransformMatrix(mSTMatrix); GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(mProgram); checkGlError("glUseProgram"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID); mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET); GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices); checkGlError("glVertexAttribPointer maPosition"); GLES20.glEnableVertexAttribArray(maPositionHandle); checkGlError("glEnableVertexAttribArray maPositionHandle"); mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET); GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices); checkGlError("glVertexAttribPointer maTextureHandle"); GLES20.glEnableVertexAttribArray(maTextureHandle); checkGlError("glEnableVertexAttribArray maTextureHandle"); Matrix.setIdentityM(mMVPMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); checkGlError("glDrawArrays"); GLES20.glFinish(); }
Example 6
Source File: MDAbsObject3D.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
public void draw() { // Draw if (getIndicesBuffer() != null){ getIndicesBuffer().position(0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, getNumIndices(), GLES20.GL_UNSIGNED_SHORT, getIndicesBuffer()); } else { GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, getNumIndices()); } }
Example 7
Source File: GLES20Canvas.java From LB-Launcher with Apache License 2.0 | 5 votes |
private void draw(ShaderParameter[] params, int type, int count, float x, float y, float width, float height) { setMatrix(params, x, y, width, height); int positionHandle = params[INDEX_POSITION].handle; GLES20.glEnableVertexAttribArray(positionHandle); checkError(); GLES20.glDrawArrays(type, 0, count); checkError(); GLES20.glDisableVertexAttribArray(positionHandle); checkError(); }
Example 8
Source File: TextureManager.java From spydroid-ipcamera with GNU General Public License v3.0 | 5 votes |
public void drawFrame() { checkGlError("onDrawFrame start"); mSurfaceTexture.getTransformMatrix(mSTMatrix); //GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f); //GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(mProgram); checkGlError("glUseProgram"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID); mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET); GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices); checkGlError("glVertexAttribPointer maPosition"); GLES20.glEnableVertexAttribArray(maPositionHandle); checkGlError("glEnableVertexAttribArray maPositionHandle"); mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET); GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices); checkGlError("glVertexAttribPointer maTextureHandle"); GLES20.glEnableVertexAttribArray(maTextureHandle); checkGlError("glEnableVertexAttribArray maTextureHandle"); Matrix.setIdentityM(mMVPMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); checkGlError("glDrawArrays"); GLES20.glFinish(); }
Example 9
Source File: FlatShadedProgram.java From PhotoMovie with Apache License 2.0 | 5 votes |
/** * Issues the draw call. Does the full setup on every call. * * @param mvpMatrix The 4x4 projection matrix. * @param color A 4-element color vector. * @param vertexBuffer Buffer with vertex data. * @param firstVertex Index of first vertex to use in vertexBuffer. * @param vertexCount Number of vertices in vertexBuffer. * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2). * @param vertexStride Width, in bytes, of the data for each vertex (often vertexCount * * sizeof(float)). */ public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer, int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) { GlUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GlUtil.checkGlError("glUseProgram"); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Copy the color vector in. GLES20.glUniform4fv(muColorLoc, 1, color, 0); GlUtil.checkGlError("glUniform4fv "); // Enable the "aPosition" vertex attribute. GLES20.glEnableVertexAttribArray(maPositionLoc); GlUtil.checkGlError("glEnableVertexAttribArray"); // Connect vertexBuffer to "aPosition". GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); GlUtil.checkGlError("glVertexAttribPointer"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glUseProgram(0); }
Example 10
Source File: GLDrawer2D.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 5 votes |
/** * draw specific texture with specific texture matrix * @param tex_id texture ID * @param tex_matrix texture matrix、if this is null, the last one use(we don't check size of this array and needs at least 16 of float) */ public void draw(final int tex_id, final float[] tex_matrix) { GLES20.glUseProgram(hProgram); if (tex_matrix != null) GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, tex_matrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex_id); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, VERTEX_NUM); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); GLES20.glUseProgram(0); }
Example 11
Source File: MagicCameraInputFilter.java From TikTok with Apache License 2.0 | 5 votes |
@Override public int onDrawFrame(int textureId, FloatBuffer vertexBuffer, FloatBuffer textureBuffer) { GLES20.glUseProgram(mGLProgId); runPendingOnDrawTasks(); if(!isInitialized()) { return OpenGlUtils.NOT_INIT; } vertexBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, vertexBuffer); GLES20.glEnableVertexAttribArray(mGLAttribPosition); textureBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0, textureBuffer); GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate); GLES20.glUniformMatrix4fv(mTextureTransformMatrixLocation, 1, false, mTextureTransformMatrix, 0); if(isBeautyChange){ GLES20.glUniform1f(mParamsLocation, mLevel); isBeautyChange = false; } if(textureId != OpenGlUtils.NO_TEXTURE){ GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId); GLES20.glUniform1i(mGLUniformTexture, 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(mGLAttribPosition); GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); return OpenGlUtils.ON_DRAWN; }
Example 12
Source File: FlatShadedProgram.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
/** * Issues the draw call. Does the full setup on every call. * * @param mvpMatrix The 4x4 projection matrix. * @param color A 4-element color vector. * @param vertexBuffer Buffer with vertex data. * @param firstVertex Index of first vertex to use in vertexBuffer. * @param vertexCount Number of vertices in vertexBuffer. * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2). * @param vertexStride Width, in bytes, of the data for each vertex (often vertexCount * * sizeof(float)). */ public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer, int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) { GlUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GlUtil.checkGlError("glUseProgram"); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Copy the color vector in. GLES20.glUniform4fv(muColorLoc, 1, color, 0); GlUtil.checkGlError("glUniform4fv "); // Enable the "aPosition" vertex attribute. GLES20.glEnableVertexAttribArray(maPositionLoc); GlUtil.checkGlError("glEnableVertexAttribArray"); // Connect vertexBuffer to "aPosition". GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); GlUtil.checkGlError("glVertexAttribPointer"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glUseProgram(0); }
Example 13
Source File: GLDrawer2D.java From AudioVideoRecordingSample with Apache License 2.0 | 5 votes |
/** * draw specific texture with specific texture matrix * @param tex_id texture ID * @param tex_matrix texture matrix、if this is null, the last one use(we don't check size of this array and needs at least 16 of float) */ public void draw(final int tex_id, final float[] tex_matrix) { GLES20.glUseProgram(hProgram); if (tex_matrix != null) GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, tex_matrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex_id); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, VERTEX_NUM); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); GLES20.glUseProgram(0); }
Example 14
Source File: ZeroMemoryVertexBufferObject.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override public void draw(final int pPrimitiveType, final int pOffset, final int pCount) { GLES20.glDrawArrays(pPrimitiveType, pOffset, pCount); }
Example 15
Source File: ZeroMemoryVertexBufferObject.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override public void draw(final int pPrimitiveType, final int pCount) { GLES20.glDrawArrays(pPrimitiveType, 0, pCount); }
Example 16
Source File: ParticleSystem.java From StarWars.Android with MIT License | 4 votes |
@Override public void render() { final int stride = Const.BYTES_PER_FLOAT * (POS_DATA_SIZE + TEXTURE_COORDS_DATA_SIZE + MISC_DATA_SIZE); // a_Position glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferId); GLES20.glEnableVertexAttribArray(mRenderer.positionHandle); GLES20.glVertexAttribPointer(mRenderer.positionHandle, POS_DATA_SIZE, GLES20.GL_FLOAT, false, stride, 0 ); // a_TexCoordinate glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferId); GLES20.glEnableVertexAttribArray(mRenderer.textureCoordinateHandle); GLES20.glVertexAttribPointer(mRenderer.textureCoordinateHandle, TEXTURE_COORDS_DATA_SIZE, GLES20.GL_FLOAT, false, stride, Const.BYTES_PER_FLOAT * (POS_DATA_SIZE) ); // a_Misc glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferId); GLES20.glEnableVertexAttribArray(mRenderer.miscHandle); GLES20.glVertexAttribPointer(mRenderer.miscHandle, MISC_DATA_SIZE, GLES20.GL_FLOAT, false, stride, Const.BYTES_PER_FLOAT * (POS_DATA_SIZE + TEXTURE_COORDS_DATA_SIZE) ); // Clear the currently bound buffer (so future OpenGL calls do not use this buffer). glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); // Draw tiles GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, PARTICLE_COUNT * 6); }
Example 17
Source File: Texture2dProgram.java From VideoRecorder with Apache License 2.0 | 4 votes |
/** * Issues the draw call. Does the full setup on every call. * * @param mvpMatrix The 4x4 projection matrix. * @param vertexBuffer Buffer with vertex position data. * @param firstVertex Index of first vertex to use in vertexBuffer. * @param vertexCount Number of vertices in vertexBuffer. * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2). * @param vertexStride Width, in bytes, of the position data for each vertex (often * vertexCount * sizeof(float)). * @param texMatrix A 4x4 transformation matrix for texture coords. (Primarily intended * for use with SurfaceTexture.) * @param texBuffer Buffer with vertex texture data. * @param texStride Width, in bytes, of the texture data for each vertex. */ public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride, float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) { GLUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GLUtil.checkGlError("glUseProgram"); // Set the texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(mTextureTarget, textureId); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0); GLUtil.checkGlError("glUniformMatrix4fv"); // Copy the texture transformation matrix over. GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0); GLUtil.checkGlError("glUniformMatrix4fv"); // Enable the "aPosition" vertex attribute. GLES20.glEnableVertexAttribArray(maPositionLoc); GLUtil.checkGlError("glEnableVertexAttribArray"); // Connect vertexBuffer to "aPosition". GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); GLUtil.checkGlError("glVertexAttribPointer"); // Enable the "aTextureCoord" vertex attribute. GLES20.glEnableVertexAttribArray(maTextureCoordLoc); GLUtil.checkGlError("glEnableVertexAttribArray"); // Connect texBuffer to "aTextureCoord". GLES20.glVertexAttribPointer(maTextureCoordLoc, 2, GLES20.GL_FLOAT, false, texStride, texBuffer); GLUtil.checkGlError("glVertexAttribPointer"); // Populate the convolution kernel, if present. if (muKernelLoc >= 0) { GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0); GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0); GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust); } // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GLUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array, texture, and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glDisableVertexAttribArray(maTextureCoordLoc); GLES20.glBindTexture(mTextureTarget, 0); GLES20.glUseProgram(0); }
Example 18
Source File: PhotoFilterView.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean drawBlurPass() { if (showOriginal || blurType == 0) { return false; } if (needUpdateBlurTexture) { GLES20.glUseProgram(blurShaderProgram); GLES20.glUniform1i(blurSourceImageHandle, 0); GLES20.glEnableVertexAttribArray(blurInputTexCoordHandle); GLES20.glVertexAttribPointer(blurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(blurPositionHandle); GLES20.glVertexAttribPointer(blurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[0], 0); GLES20.glClear(0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[1]); GLES20.glUniform1f(blurWidthHandle, 0.0f); GLES20.glUniform1f(blurHeightHandle, 1.0f / renderBufferHeight); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[2]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[2], 0); GLES20.glClear(0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[0]); GLES20.glUniform1f(blurWidthHandle, 1.0f / renderBufferWidth); GLES20.glUniform1f(blurHeightHandle, 0.0f); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); needUpdateBlurTexture = false; } GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[0], 0); GLES20.glClear(0); if (blurType == 1) { GLES20.glUseProgram(radialBlurShaderProgram); GLES20.glUniform1i(radialBlurSourceImageHandle, 0); GLES20.glUniform1i(radialBlurSourceImage2Handle, 1); GLES20.glUniform1f(radialBlurExcludeSizeHandle, blurExcludeSize); GLES20.glUniform1f(radialBlurExcludeBlurSizeHandle, blurExcludeBlurSize); GLES20.glUniform2f(radialBlurExcludePointHandle, blurExcludePoint.x, blurExcludePoint.y); GLES20.glUniform1f(radialBlurAspectRatioHandle, (float) renderBufferHeight / (float) renderBufferWidth); GLES20.glEnableVertexAttribArray(radialBlurInputTexCoordHandle); GLES20.glVertexAttribPointer(radialBlurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(radialBlurPositionHandle); GLES20.glVertexAttribPointer(radialBlurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer); } else if (blurType == 2) { GLES20.glUseProgram(linearBlurShaderProgram); GLES20.glUniform1i(linearBlurSourceImageHandle, 0); GLES20.glUniform1i(linearBlurSourceImage2Handle, 1); GLES20.glUniform1f(linearBlurExcludeSizeHandle, blurExcludeSize); GLES20.glUniform1f(linearBlurExcludeBlurSizeHandle, blurExcludeBlurSize); GLES20.glUniform1f(linearBlurAngleHandle, blurAngle); GLES20.glUniform2f(linearBlurExcludePointHandle, blurExcludePoint.x, blurExcludePoint.y); GLES20.glUniform1f(linearBlurAspectRatioHandle, (float) renderBufferHeight / (float) renderBufferWidth); GLES20.glEnableVertexAttribArray(linearBlurInputTexCoordHandle); GLES20.glVertexAttribPointer(linearBlurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(linearBlurPositionHandle); GLES20.glVertexAttribPointer(linearBlurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[1]); GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[2]); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); return true; }
Example 19
Source File: PreviewShader.java From retroboy with MIT License | 4 votes |
@Override public void draw() { // Check if a new frame is available synchronized (this) { if (_updateSurface) { _previewTexture.updateTexImage(); _previewTexture.getTransformMatrix(mSTMatrix); _updateSurface = false; } } // Transfer the screen ratio projection GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0); GLES20.glUniform1f(muCRatioHandle, _cRatio); // Bind the preview texture GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, _previewTextureHandle); GLES20.glUniform1i(_previewTextureLocation, 0); checkGlError("glBindTexture"); // Prepare the triangles _vertexbuf.position(TRIANGLE_VERTICES_DATA_POS_OFFSET); GLES20.glVertexAttribPointer( maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, _vertexbuf); checkGlError("glVertexAttribPointer maPosition"); GLES20.glEnableVertexAttribArray(maPositionHandle); checkGlError("glEnableVertexAttribArray maPositionHandle"); _vertexbuf.position(TRIANGLE_VERTICES_DATA_UV_OFFSET); GLES20.glVertexAttribPointer( maTextureCoordHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, _vertexbuf); checkGlError("glVertexAttribPointer maTextureHandle"); GLES20.glEnableVertexAttribArray(maTextureCoordHandle); checkGlError("glEnableVertexAttribArray maTextureHandle"); // Draw two triangles to form a square GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 1, 3); checkGlError("glDrawArrays"); }
Example 20
Source File: GlRectDrawer.java From sealrtc-android with MIT License | 4 votes |
private void drawRectangle(int x, int y, int width, int height) { // Draw quad. GLES20.glViewport(x, y, width, height); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); }