Android Open Source - FxCameraApp G L E S20 Framebuffer Object From Project Back to project page FxCameraApp .
License The source code is released under:
MIT License
If you think the Android project FxCameraApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.af.experiments.FxCameraApp.renderer;
/ / f r o m w w w . j a v a 2 s . c o m
import android.graphics.Bitmap;
import com.af.experiments.FxCameraApp.Utils.OpenGlUtils;
import java.nio.IntBuffer;
import static android.opengl.GLES20.*;
public class GLES20FramebufferObject {
private int mWidth;
private int mHeight;
private int mFramebufferName;
private int mRenderbufferName;
private int mTexName;
public int getWidth() {
return mWidth;
}
public int getHeight() {
return mHeight;
}
public int getTexName() {
return mTexName;
}
public void setup(final int width, final int height) {
final int [] args = new int [1];
glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
if (width > args[0] || height > args[0]) {
throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
}
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
if (width > args[0] || height > args[0]) {
throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
}
glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
final int saveFramebuffer = args[0];
glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
final int saveRenderbuffer = args[0];
glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
final int saveTexName = args[0];
release();
try {
mWidth = width;
mHeight = height;
glGenFramebuffers(args.length, args, 0);
mFramebufferName = args[0];
glBindFramebuffer(GL_FRAMEBUFFER, mFramebufferName);
glGenRenderbuffers(args.length, args, 0);
mRenderbufferName = args[0];
glBindRenderbuffer(GL_RENDERBUFFER, mRenderbufferName);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mRenderbufferName);
glGenTextures(args.length, args, 0);
mTexName = args[0];
glBindTexture(GL_TEXTURE_2D, mTexName);
OpenGlUtils.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexName, 0);
final int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
throw new RuntimeException("Failed to initialize framebuffer object " + status);
}
} catch (final RuntimeException e) {
release();
throw e;
}
glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
glBindTexture(GL_TEXTURE_2D, saveTexName);
}
public void release() {
final int [] args = new int [1];
args[0] = mTexName;
glDeleteTextures(args.length, args, 0);
mTexName = 0;
args[0] = mRenderbufferName;
glDeleteRenderbuffers(args.length, args, 0);
mRenderbufferName = 0;
args[0] = mFramebufferName;
glDeleteFramebuffers(args.length, args, 0);
mFramebufferName = 0;
}
public void enable() {
glBindFramebuffer(GL_FRAMEBUFFER, mFramebufferName);
}
public Bitmap getBitmap() {
return getBitmap(0, false);
}
public Bitmap getBitmap(final int orientation) {
return getBitmap(orientation, false);
}
public Bitmap getBitmap(final int orientation, final boolean mirror) {
final int [] pixels = new int [mWidth * mHeight];
final IntBuffer buffer = IntBuffer.wrap(pixels);
buffer.position(0);
enable();
glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return OpenGlUtils.createBitmap(pixels, mWidth, mHeight, Bitmap.Config.ARGB_8888, orientation, mirror);
}
}
Java Source Code List com.af.experiments.FxCameraApp.FilterAdapter.java com.af.experiments.FxCameraApp.MyActivity.java com.af.experiments.FxCameraApp.Utils.BitmapFactoryUtils.java com.af.experiments.FxCameraApp.Utils.ExifUtils.java com.af.experiments.FxCameraApp.Utils.Fps.java com.af.experiments.FxCameraApp.Utils.LogWriter.java com.af.experiments.FxCameraApp.Utils.OpenGlUtils.java com.af.experiments.FxCameraApp.View.CameraView.java com.af.experiments.FxCameraApp.View.DefaultPreview.java com.af.experiments.FxCameraApp.View.GlPreview.java com.af.experiments.FxCameraApp.View.PreviewTexture.java com.af.experiments.FxCameraApp.camera.CameraHelperBase.java com.af.experiments.FxCameraApp.camera.CameraHelperCupcake.java com.af.experiments.FxCameraApp.camera.CameraHelperDonut.java com.af.experiments.FxCameraApp.camera.CameraHelperEclair.java com.af.experiments.FxCameraApp.camera.CameraHelperFactory.java com.af.experiments.FxCameraApp.camera.CameraHelperFroyo.java com.af.experiments.FxCameraApp.camera.CameraHelperGingerbread.java com.af.experiments.FxCameraApp.camera.CameraHelperHonycomb.java com.af.experiments.FxCameraApp.camera.CameraHelperICS.java com.af.experiments.FxCameraApp.camera.CameraHelper.java com.af.experiments.FxCameraApp.display.DisplayHelperBase.java com.af.experiments.FxCameraApp.display.DisplayHelperFactory.java com.af.experiments.FxCameraApp.display.DisplayHelperFroyo.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycombMR2.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycomb.java com.af.experiments.FxCameraApp.display.DisplayHelper.java com.af.experiments.FxCameraApp.ogles.DefaultConfigChooser.java com.af.experiments.FxCameraApp.ogles.DefaultContextFactory.java com.af.experiments.FxCameraApp.ogles.DefaultWindowSurfaceFactory.java com.af.experiments.FxCameraApp.ogles.EGLLogWrapper.java com.af.experiments.FxCameraApp.ogles.GLES20ConfigChooser.java com.af.experiments.FxCameraApp.ogles.GLES20ContextFactory.java com.af.experiments.FxCameraApp.ogles.GlImageBitmapTexture.java com.af.experiments.FxCameraApp.ogles.GlImageResourceTexture.java com.af.experiments.FxCameraApp.ogles.GlImageTexture.java com.af.experiments.FxCameraApp.ogles.GlPreviewTextureFactory.java com.af.experiments.FxCameraApp.ogles.GlSurfaceTexture.java com.af.experiments.FxCameraApp.ogles.GlTextureView.java com.af.experiments.FxCameraApp.ogles.PixelBuffer.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperBase.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperFactory.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelper.java com.af.experiments.FxCameraApp.ogles.Texture.java com.af.experiments.FxCameraApp.renderer.GLES20FramebufferObject.java com.af.experiments.FxCameraApp.renderer.GlFrameBufferObjectRenderer.java com.af.experiments.FxCameraApp.renderer.MainRenderer.java com.af.experiments.FxCameraApp.shaders.GlBilateralShader.java com.af.experiments.FxCameraApp.shaders.GlBoxBlurShader.java com.af.experiments.FxCameraApp.shaders.GlBulgeDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlCGAColorspaceShader.java com.af.experiments.FxCameraApp.shaders.GlColorInvertShader.java com.af.experiments.FxCameraApp.shaders.GlColorMatrixShader.java com.af.experiments.FxCameraApp.shaders.GlColorPackingShader.java com.af.experiments.FxCameraApp.shaders.GlConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlEmbossShader.java com.af.experiments.FxCameraApp.shaders.GlFalseColorShader.java com.af.experiments.FxCameraApp.shaders.GlFastBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGaussianBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGlassSphereShader.java com.af.experiments.FxCameraApp.shaders.GlGrayScaleShader.java com.af.experiments.FxCameraApp.shaders.GlHarrisCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlHazeShader.java com.af.experiments.FxCameraApp.shaders.GlMonochromeShader.java com.af.experiments.FxCameraApp.shaders.GlNobleCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlPerlinNoiseShader.java com.af.experiments.FxCameraApp.shaders.GlPinchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolarPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolkaDotShader.java com.af.experiments.FxCameraApp.shaders.GlPosterizeShader.java com.af.experiments.FxCameraApp.shaders.GlPreviewShader.java com.af.experiments.FxCameraApp.shaders.GlSepiaShader.java com.af.experiments.FxCameraApp.shaders.GlShaderGroup.java com.af.experiments.FxCameraApp.shaders.GlShader.java com.af.experiments.FxCameraApp.shaders.GlSharpenShader.java com.af.experiments.FxCameraApp.shaders.GlShiTomasiFeatureDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSobelEdgeDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSphereRefractionShader.java com.af.experiments.FxCameraApp.shaders.GlStretchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3ConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3TextureSamplingShader.java com.af.experiments.FxCameraApp.shaders.GlToneShader.java com.af.experiments.FxCameraApp.shaders.GlTwoInputShader.java com.af.experiments.FxCameraApp.shaders.GlVignetteShader.java com.af.experiments.FxCameraApp.shaders.GlWeakPixelInclusionShader.java com.af.experiments.FxCameraApp.shaders.GlWhiteBalanceShader.java com.af.experiments.FxCameraApp.shaders.GlXRayShader.java com.af.experiments.FxCameraApp.shaders.GlXYDerivativeShader.java com.af.experiments.FxCameraApp.shaders.fx.GlLutShader.java