Java Code Examples for android.opengl.GLES20#glBindTexture()
The following examples show how to use
android.opengl.GLES20#glBindTexture() .
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 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 2
Source File: GlUtil.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and * GL_CLAMP_TO_EDGE wrapping. */ public static int createExternalTexture() { int[] texId = new int[1]; GLES20.glGenTextures(1, IntBuffer.wrap(texId)); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texId[0]); GLES20.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); checkGlError(); return texId[0]; }
Example 3
Source File: ScreenRectangle.java From OpenGLESRecorder with Apache License 2.0 | 6 votes |
private void createTexture(int width, int height) { int [] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); GLUtil.checkGLError("genTexture"); int textureId = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLUtil.checkGLError("bindTexture"); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, width, height, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, null); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_MIRRORED_REPEAT); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_MIRRORED_REPEAT); GLUtil.checkGLError("setTextureParams"); mOffScreenTexture = textureId; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); }
Example 4
Source File: Painting.java From Telegram-FOSS 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 5
Source File: Texture2dProgram.java From PhotoMovie with Apache License 2.0 | 6 votes |
/** * Creates a texture object suitable for use with this program. * <p> * On exit, the texture will be bound. */ public int createTextureObject() { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); GlUtil.checkGlError("glGenTextures"); int texId = textures[0]; GLES20.glBindTexture(mTextureTarget, texId); GlUtil.checkGlError("glBindTexture " + texId); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GlUtil.checkGlError("glTexParameter"); return texId; }
Example 6
Source File: GreyScaleFilterRender.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.glUniform1i(uSamplerHandle, 4); GLES20.glActiveTexture(GLES20.GL_TEXTURE4); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousTexId); }
Example 7
Source File: MDBarrelDistortionLinePipe.java From MD360Player4Android with Apache License 2.0 | 6 votes |
private void draw(int index){ // Set our per-vertex lighting program. mProgram.use(); glCheck("MDBarrelDistortionLinePipe mProgram use"); object3D.uploadVerticesBufferIfNeed(mProgram, index); object3D.uploadTexCoordinateBufferIfNeed(mProgram, index); // Pass in the combined matrix. mDirector.beforeShot(); mDirector.shot(mProgram, MDPosition.getOriginalPosition()); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mDrawingCache.getTextureOutput()); object3D.draw(); }
Example 8
Source File: GlUtil.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
/** * Creates a texture from raw data. * * @param data Image data, in a "direct" ByteBuffer. * @param width Texture width, in pixels (not bytes). * @param height Texture height, in pixels. * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA). * @return Handle to texture. */ public static int createImageTexture(ByteBuffer data, int width, int height, int format) { int[] textureHandles = new int[1]; int textureHandle; GLES20.glGenTextures(1, textureHandles, 0); textureHandle = textureHandles[0]; GlUtil.checkGlError("glGenTextures"); // Bind the texture handle to the 2D texture target. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle); // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering // is smaller or larger than the source image. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GlUtil.checkGlError("loadImageTexture"); // Load the data from the buffer into the texture handle. GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, /*level*/ 0, format, width, height, /*border*/ 0, format, GLES20.GL_UNSIGNED_BYTE, data); GlUtil.checkGlError("loadImageTexture"); return textureHandle; }
Example 9
Source File: FDOG1ShaderProgram.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 0 to the uniform GLES20.glUniformMatrix4fv(mSTMatrixHandle, 1, false, img.getTransformMatrix(), 0); }
Example 10
Source File: GPUImageTwoInputFilter.java From SimpleVideoEditor with Apache License 2.0 | 5 votes |
@Override protected void onDrawArraysPre() { GLES20.glEnableVertexAttribArray(mFilterSecondTextureCoordinateAttribute); GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFilterSourceTexture2); GLES20.glUniform1i(mFilterInputTextureUniform2, 3); mTexture2CoordinatesBuffer.position(0); GLES20.glVertexAttribPointer(mFilterSecondTextureCoordinateAttribute, 2, GLES20.GL_FLOAT, false, 0, mTexture2CoordinatesBuffer); }
Example 11
Source File: CameraGLRendererBase.java From FaceDetectDemo with Apache License 2.0 | 5 votes |
private void initTexOES(int[] tex) { if(tex.length == 1) { GLES20.glGenTextures(1, tex, 0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); } }
Example 12
Source File: GLES20Canvas.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
@Override public void initializeTextureSize(BasicTexture texture, int format, int type) { int target = texture.getTarget(); GLES20.glBindTexture(target, texture.getId()); checkError(); int width = texture.getTextureWidth(); int height = texture.getTextureHeight(); GLES20.glTexImage2D(target, 0, format, width, height, 0, format, type, null); }
Example 13
Source File: GLES20Canvas.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
@Override public void setTextureParameters(BasicTexture texture) { int target = texture.getTarget(); GLES20.glBindTexture(target, texture.getId()); checkError(); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); }
Example 14
Source File: CameraGLRendererBase.java From faceswap with Apache License 2.0 | 5 votes |
private void initTexOES(int[] tex) { if(tex.length == 1) { GLES20.glGenTextures(1, tex, 0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); } }
Example 15
Source File: BaseRenderOffScreen.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
protected void initFBO(int width, int height, int[] fboId, int[] rboId, int[] texId) { GlUtil.checkGlError("initFBO_S"); GLES20.glGenFramebuffers(1, fboId, 0); GLES20.glGenRenderbuffers(1, rboId, 0); GLES20.glGenTextures(1, texId, 0); GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, rboId[0]); GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId[0]); GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, rboId[0]); GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId[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.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texId[0], 0); int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException("FrameBuffer uncompleted code: " + status); } GlUtil.checkGlError("initFBO_E"); }
Example 16
Source File: CameraGLRendererBase.java From faceswap with Apache License 2.0 | 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 17
Source File: CameraRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
@Override public void draw() { GlUtil.checkGlError("drawCamera start"); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderHandler.getFboId()[0]); surfaceTexture.getTransformMatrix(STMatrix); GLES20.glViewport(0, 0, width, height); GLES20.glUseProgram(program); GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); 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(aTextureCameraHandle, 2, GLES20.GL_FLOAT, false, SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex); GLES20.glEnableVertexAttribArray(aTextureCameraHandle); GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0); GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0); //camera GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureID[0]); //draw GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GlUtil.checkGlError("drawCamera end"); }
Example 18
Source File: GlTextureFrameBuffer.java From sealrtc-android with MIT License | 4 votes |
/** * (Re)allocate texture. Will do nothing if the requested size equals the current size. An * EGLContext must be bound on the current thread when calling this function. Must be called at * least once before using the framebuffer. May be called multiple times to change size. */ public void setSize(int width, int height) { if (width == 0 || height == 0) { throw new IllegalArgumentException("Invalid size: " + width + "x" + height); } if (width == this.width && height == this.height) { return; } this.width = width; this.height = height; // Allocate texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, 0, pixelFormat, width, height, 0, pixelFormat, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GlUtil.checkNoGLES2Error("GlTextureFrameBuffer setSize"); // Attach the texture to the framebuffer as color attachment. GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); GLES20.glFramebufferTexture2D( GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, textureId, 0); // Check that the framebuffer is in a good state. final int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) { throw new IllegalStateException("Framebuffer not complete, status: " + status); } GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); }
Example 19
Source File: MagicCameraView.java From TikTok with Apache License 2.0 | 4 votes |
private Bitmap drawPhoto(Bitmap bitmap, boolean isRotated){ int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] mFrameBuffers = new int[1]; int[] mFrameBufferTextures = new int[1]; if(beautyFilter == null) beautyFilter = new MagicBeautyFilter(); beautyFilter.init(); beautyFilter.onDisplaySizeChanged(width, height); beautyFilter.onInputSizeChanged(width, height); if(filter != null) { filter.onInputSizeChanged(width, height); filter.onDisplaySizeChanged(width, height); } GLES20.glGenFramebuffers(1, mFrameBuffers, 0); GLES20.glGenTextures(1, mFrameBufferTextures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0], 0); GLES20.glViewport(0, 0, width, height); int textureId = OpenGlUtils.loadTexture(bitmap, OpenGlUtils.NO_TEXTURE, true); FloatBuffer gLCubeBuffer = ByteBuffer.allocateDirect(TextureRotationUtil.CUBE_BAAB.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); FloatBuffer gLTextureBuffer = ByteBuffer .allocateDirect(TextureRotationUtil.TEXTURE_NO_ROTATION.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); gLCubeBuffer.put(TextureRotationUtil.CUBE_BAAB).position(0); if(isRotated) gLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, false)).position(0); else gLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, true)).position(0); if(filter == null){ beautyFilter.onDrawFrame(textureId, gLCubeBuffer, gLTextureBuffer); }else{ beautyFilter.onDrawFrame(textureId); filter.onDrawFrame(mFrameBufferTextures[0], gLCubeBuffer, gLTextureBuffer); } IntBuffer ib = IntBuffer.allocate(width * height); GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); result.copyPixelsFromBuffer(ib); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glDeleteTextures(1, new int[]{textureId}, 0); GLES20.glDeleteFramebuffers(mFrameBuffers.length, mFrameBuffers, 0); GLES20.glDeleteTextures(mFrameBufferTextures.length, mFrameBufferTextures, 0); beautyFilter.destroy(); beautyFilter = null; if(filter != null) { filter.onDisplaySizeChanged(surfaceWidth, surfaceHeight); filter.onInputSizeChanged(imageWidth, imageHeight); } return result; }
Example 20
Source File: GPUImageFilterGroup.java From SimpleVideoEditor with Apache License 2.0 | 4 votes |
@Override public void onOutputSizeChanged(final int width, final int height) { super.onOutputSizeChanged(width, height); if (mFrameBuffers != null) { destroyFramebuffers(); } int size = mFilters.size(); for (int i = 0; i < size; i++) { mFilters.get(i).onOutputSizeChanged(width, height); } if (mMergedFilters != null && mMergedFilters.size() > 0) { size = mMergedFilters.size(); mFrameBuffers = new int[size - 1]; mFrameBufferTextures = new int[size - 1]; for (int i = 0; i < size - 1; i++) { GLES20.glGenFramebuffers(1, mFrameBuffers, i); GLES20.glGenTextures(1, mFrameBufferTextures, i); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFrameBufferTextures[i]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[i]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mFrameBufferTextures[i], 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); } } }