Java Code Examples for android.opengl.GLES20#glActiveTexture()
The following examples show how to use
android.opengl.GLES20#glActiveTexture() .
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: Painting.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void renderBlit() { Shader shader = shaders.get("blit"); if (shader == null) { return; } GLES20.glUseProgram(shader.program); GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(renderProjection)); GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer); GLES20.glEnableVertexAttribArray(0); GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(1); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); Utils.HasGLError(); }
Example 2
Source File: GlRectDrawer.java From sealrtc-android with MIT License | 6 votes |
/** * Draw an OES texture frame with specified texture transformation matrix. Required resources * are allocated at the first call to this function. */ public void drawOes( int oesTextureId, float[] texMatrix, int frameWidth, int frameHeight, int viewportX, int viewportY, int viewportWidth, int viewportHeight) { prepareShader(OES_FRAGMENT_SHADER_STRING, texMatrix); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); // updateTexImage() may be called from another thread in another EGL context, so we need to // bind/unbind the texture in each draw call so that GLES understads it's a new texture. GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oesTextureId); drawRectangle(viewportX, viewportY, viewportWidth, viewportHeight); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); }
Example 3
Source File: Painting.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void renderBlit() { Shader shader = shaders.get("blit"); if (shader == null) { return; } GLES20.glUseProgram(shader.program); GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(renderProjection)); GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer); GLES20.glEnableVertexAttribArray(0); GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(1); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); Utils.HasGLError(); }
Example 4
Source File: ExposureFilterRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 6 votes |
@Override protected void drawFilter() { GLES20.glUseProgram(program); squareVertex.position(SQUARE_VERTEX_DATA_POS_OFFSET); GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false, SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex); GLES20.glEnableVertexAttribArray(aPositionHandle); squareVertex.position(SQUARE_VERTEX_DATA_UV_OFFSET); GLES20.glVertexAttribPointer(aTextureHandle, 2, GLES20.GL_FLOAT, false, SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex); GLES20.glEnableVertexAttribArray(aTextureHandle); GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0); GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0); GLES20.glUniform1f(uExposureHandle, exposure); GLES20.glUniform1i(uSamplerHandle, 4); GLES20.glActiveTexture(GLES20.GL_TEXTURE4); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousTexId); }
Example 5
Source File: FreeTransformFrameRenderFilter.java From LiTr with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void apply(long presentationTimeNs) { GlRenderUtils.checkGlError("onDrawFrame start"); GLES20.glUseProgram(glProgram); GlRenderUtils.checkGlError("glUseProgram"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, inputTextureId); GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, mvpMatrixOffset); GLES20.glUniformMatrix4fv(uStMatrixHandle, 1, false, inputTextureTransformMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GlRenderUtils.checkGlError("glDrawArrays"); }
Example 6
Source File: GLSurface.java From libcommon with Apache License 2.0 | 5 votes |
/** * ISurfaceの実装 */ @Override public void swap() { if (DEBUG) Log.v(TAG, "swap:"); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glActiveTexture(TEX_UNIT); GLES20.glBindTexture(TEX_TARGET, 0); }
Example 7
Source File: CameraGLRendererBase.java From MOAAP with MIT License | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 8
Source File: MagicLookupFilter.java From TikTok with Apache License 2.0 | 5 votes |
protected void onDrawArraysAfter(){ if (mLookupSourceTexture != -1){ GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); } }
Example 9
Source File: CameraGLRendererBase.java From OpenCV-Android-Object-Detection with MIT License | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 10
Source File: OrientationAlignedBilateralFilterShaderProgram.java From Spectaculum with Apache License 2.0 | 5 votes |
public void setTexture(Texture2D img, Texture2D tfm) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, img.getHandle()); GLES20.glUniform1i(mTextureHandle, 0); // bind texture unit 0 to the uniform GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tfm.getHandle()); GLES20.glUniform1i(mTextureHandle2, 1); // bind texture unit 1 to the uniform GLES20.glUniformMatrix4fv(mSTMatrixHandle, 1, false, img.getTransformMatrix(), 0); }
Example 11
Source File: TextureUtils.java From Pano360 with MIT License | 5 votes |
public static void bindTexture2D(int textureId,int activeTextureID,int handle,int idx){ if (textureId != GLEtc.NO_TEXTURE) { GLES20.glActiveTexture(activeTextureID); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniform1i(handle, idx); } }
Example 12
Source File: FrameRenderer.java From DanDanPlayForAndroid with MIT License | 4 votes |
@Override public void onDrawFrame() { FrameBuffer pendingOutputBuffer = pendingOutputBufferReference.getAndSet(null); if (pendingOutputBuffer == null && renderedOutputBuffer == null) { // There is no output buffer to render at the moment. return; } if (pendingOutputBuffer != null) { if (renderedOutputBuffer != null) { renderedOutputBuffer.release(); } renderedOutputBuffer = pendingOutputBuffer; } FrameBuffer outputBuffer = renderedOutputBuffer; // Set color matrix. Assume BT709 if the color space is unknown. float[] colorConversion = kColorConversion709; /*switch (outputBuffer.pixelFormat) { case FrameBuffer.COLORSPACE_BT601: colorConversion = kColorConversion601; break; case FrameBuffer.COLORSPACE_BT2020: colorConversion = kColorConversion2020; break; case FrameBuffer.COLORSPACE_BT709: default: break; // Do nothing }*/ int bitDepth = outputBuffer.bitDepth; int format = bitDepth == 1 ? GLES20.GL_LUMINANCE : GLES20.GL_LUMINANCE_ALPHA; GLES20.glUniformMatrix3fv(colorMatrixLocation, 1, false, colorConversion, 0); GLES20.glUniform1f(bitDepthLocation, bitDepth); for (int i = 0; i < 3; i++) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]); int width = outputBuffer.yuvStrides[i] / bitDepth; int height = (i == 0) ? outputBuffer.height : outputBuffer.height / 2; GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, GLES20.GL_UNSIGNED_BYTE, outputBuffer.yuvPlanes[i]); } // Set cropping of stride if either width or stride has changed. if (previousWidth != outputBuffer.width || previousStride != outputBuffer.yuvStrides[0]) { float crop = (float) outputBuffer.width * bitDepth / outputBuffer.yuvStrides[0]; // This buffer is consumed during each call to glDrawArrays. It needs to be a member variable // rather than a local variable to ensure that it doesn't get garbage collected. textureCoords = nativeFloatBuffer( 0.0f, 0.0f, 0.0f, 1.0f, crop, 0.0f, crop, 1.0f); GLES20.glVertexAttribPointer( texLocation, 2, GLES20.GL_FLOAT, false, 0, textureCoords); previousWidth = outputBuffer.width; previousStride = outputBuffer.yuvStrides[0]; } GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); checkNoGLES2Error(); }
Example 13
Source File: AnnotationRenderer.java From ARCore-Location with MIT License | 4 votes |
public void createOnGlThread(Context context, String text, int distance) { // Read the texture. Bitmap textureBitmap = null; try { textureBitmap = drawTextToAnnotation(context, text, metresReadable(distance)); textureBitmap.setHasAlpha(true); } catch (Exception e) { Log.e(TAG, "Exception reading texture", e); return; } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glGenTextures(mTextures.length, mTextures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); GLES20.glBlendColor(0,0,0,0); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glEnable(GLES20.GL_BLEND); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textureBitmap, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); textureBitmap.recycle(); ShaderUtil.checkGLError(TAG, "Texture loading"); // Build the geometry of a simple imageRenderer. int numVertices = 4; if (numVertices != QUAD_COORDS.length / COORDS_PER_VERTEX) { throw new RuntimeException("Unexpected number of vertices in BackgroundRenderer."); } ByteBuffer bbVertices = ByteBuffer.allocateDirect(QUAD_COORDS.length * Float.BYTES); bbVertices.order(ByteOrder.nativeOrder()); mQuadVertices = bbVertices.asFloatBuffer(); mQuadVertices.put(QUAD_COORDS); mQuadVertices.position(0); ByteBuffer bbTexCoords = ByteBuffer.allocateDirect(numVertices * TEXCOORDS_PER_VERTEX * Float.BYTES); bbTexCoords.order(ByteOrder.nativeOrder()); mQuadTexCoord = bbTexCoords.asFloatBuffer(); mQuadTexCoord.put(QUAD_TEXCOORDS); mQuadTexCoord.position(0); ByteBuffer bbTexCoordsTransformed = ByteBuffer.allocateDirect(numVertices * TEXCOORDS_PER_VERTEX * Float.BYTES); bbTexCoordsTransformed.order(ByteOrder.nativeOrder()); int vertexShader = loadGLShader(TAG, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER); int fragmentShader = loadGLShader(TAG, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER); mQuadProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(mQuadProgram, vertexShader); GLES20.glAttachShader(mQuadProgram, fragmentShader); GLES20.glLinkProgram(mQuadProgram); GLES20.glUseProgram(mQuadProgram); ShaderUtil.checkGLError(TAG, "Program creation"); mQuadPositionParam = GLES20.glGetAttribLocation(mQuadProgram, "a_Position"); mQuadTexCoordParam = GLES20.glGetAttribLocation(mQuadProgram, "a_TexCoord"); mTextureUniform = GLES20.glGetUniformLocation(mQuadProgram, "u_Texture"); mModelViewProjectionUniform = GLES20.glGetUniformLocation(mQuadProgram, "u_ModelViewProjection"); ShaderUtil.checkGLError(TAG, "Program parameters"); Matrix.setIdentityM(mModelMatrix, 0); }
Example 14
Source File: GSYVideoGLViewCustomRender.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
@Override public void onDrawFrame(GL10 glUnused) { super.onDrawFrame(glUnused); //curProgram = createProgram(getVertexShader(), mBitmapEffect.getShader(mSurfaceView)); GLES20.glUseProgram(curProgram); checkGlError("glUseProgram"); //绑定注入bitmap int mFilterInputTextureUniform2 = GLES20.glGetUniformLocation(curProgram, "sTexture2"); GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]); GLES20.glUniform1i(mFilterInputTextureUniform2, mTexturesBitmap[0]); 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, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices); checkGlError("glVertexAttribPointer maTextureHandle"); GLES20.glEnableVertexAttribArray(maTextureHandle); checkGlError("glEnableVertexAttribArray maTextureHandle"); GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); //水印透明 GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); checkGlError("glDrawArrays"); GLES20.glFinish(); GLES20.glDisable(GLES20.GL_BLEND); }
Example 15
Source File: ProgramTexture2d.java From sealrtc-android with MIT License | 4 votes |
@Override public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) { GlUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GlUtil.checkGlError("glUseProgram"); // Set the texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 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, Drawable2d.COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray()); 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, Drawable2d.TEXTURE_COORD_STRIDE, mDrawable2d.texCoordArray()); GlUtil.checkGlError("glVertexAttribPointer"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mDrawable2d.vertexCount()); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array, texture, and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glDisableVertexAttribArray(maTextureCoordLoc); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glUseProgram(0); }
Example 16
Source File: FilterGLThread.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void run() { if (!initied) { return; } if (!eglContext.equals(egl10.eglGetCurrentContext()) || !eglSurface.equals(egl10.eglGetCurrentSurface(EGL10.EGL_DRAW))) { if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { if (BuildVars.LOGS_ENABLED) { FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError())); } return; } } if (updateSurface) { videoSurfaceTexture.updateTexImage(); videoSurfaceTexture.getTransformMatrix(videoTextureMatrix); if (videoWidth == 0 || videoHeight == 0) { videoWidth = surfaceWidth; videoHeight = surfaceHeight; if (videoWidth > 1280 || videoHeight > 1280) { videoWidth /= 2; videoHeight /= 2; } } if (!renderDataSet && videoWidth > 0 && videoHeight > 0) { filterShaders.setRenderData(currentBitmap, orientation, videoTexture[0], videoWidth, videoHeight); renderDataSet = true; renderBufferWidth = filterShaders.getRenderBufferWidth(); renderBufferHeight = filterShaders.getRenderBufferHeight(); } updateSurface = false; filterShaders.onVideoFrameUpdate(videoTextureMatrix); videoFrameAvailable = true; } if (!renderDataSet) { return; } if (videoDelegate == null || videoFrameAvailable) { GLES20.glViewport(0, 0, renderBufferWidth, renderBufferHeight); filterShaders.drawEnhancePass(); if (videoDelegate == null) { filterShaders.drawSharpenPass(); } filterShaders.drawCustomParamsPass(); blurred = filterShaders.drawBlurPass(); } GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glUseProgram(simpleShaderProgram); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterShaders.getRenderTexture(blurred ? 0 : 1)); GLES20.glUniform1i(simpleSourceImageHandle, 0); GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle); GLES20.glVertexAttribPointer(simpleInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getTextureBuffer()); GLES20.glEnableVertexAttribArray(simplePositionHandle); GLES20.glVertexAttribPointer(simplePositionHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getVertexBuffer()); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); egl10.eglSwapBuffers(eglDisplay, eglSurface); }
Example 17
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 4 votes |
@Override public void onDrawFrame(GL10 unused) { angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f; GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -4, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f); GLES20.glUseProgram(shaderProgram); int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition"); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer); int texCoordHandle = GLES20.glGetAttribLocation(shaderProgram, "aTex"); GLES20.glVertexAttribPointer(texCoordHandle, 2, GLES20.GL_FLOAT, false, 0, texBuffer); int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); int texHandle = GLES20.glGetUniformLocation(shaderProgram, "sTex"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniform1i(texHandle, 0); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnableVertexAttribArray(texHandle); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glDrawElements( GLES20.GL_TRIANGLES, index.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(texHandle); GLES20.glDisable(GLES20.GL_DEPTH_TEST); }
Example 18
Source File: BaseFilter.java From AAVT with Apache License 2.0 | 4 votes |
/** * 绑定默认纹理 */ protected void onBindTexture(int textureId){ GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureId); GLES20.glUniform1i(mGLTexture,0); }
Example 19
Source File: VideoFrameDrawer.java From webrtc_android with MIT License | 4 votes |
/** * Upload |planes| into OpenGL textures, taking stride into consideration. * * @return Array of three texture indices corresponding to Y-, U-, and V-plane respectively. */ public int[] uploadYuvData(int width, int height, int[] strides, ByteBuffer[] planes) { final int[] planeWidths = new int[] {width, width / 2, width / 2}; final int[] planeHeights = new int[] {height, height / 2, height / 2}; // Make a first pass to see if we need a temporary copy buffer. int copyCapacityNeeded = 0; for (int i = 0; i < 3; ++i) { if (strides[i] > planeWidths[i]) { copyCapacityNeeded = Math.max(copyCapacityNeeded, planeWidths[i] * planeHeights[i]); } } // Allocate copy buffer if necessary. if (copyCapacityNeeded > 0 && (copyBuffer == null || copyBuffer.capacity() < copyCapacityNeeded)) { copyBuffer = ByteBuffer.allocateDirect(copyCapacityNeeded); } // Make sure YUV textures are allocated. if (yuvTextures == null) { yuvTextures = new int[3]; for (int i = 0; i < 3; i++) { yuvTextures[i] = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); } } // Upload each plane. for (int i = 0; i < 3; ++i) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]); // GLES only accepts packed data, i.e. stride == planeWidth. final ByteBuffer packedByteBuffer; if (strides[i] == planeWidths[i]) { // Input is packed already. packedByteBuffer = planes[i]; } else { YuvHelper.copyPlane( planes[i], strides[i], copyBuffer, planeWidths[i], planeWidths[i], planeHeights[i]); packedByteBuffer = copyBuffer; } GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE, planeWidths[i], planeHeights[i], 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, packedByteBuffer); } return yuvTextures; }
Example 20
Source File: Texture2dProgram.java From PLDroidShortVideo 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); }