summaryrefslogtreecommitdiffstats
path: root/jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2013-08-14 11:20:34 -0700
committerSascha Haeberling <haeberling@google.com>2013-08-14 11:20:34 -0700
commit8bddf8ce4f3dcbb56edb12cee7e93f3a9daa3f96 (patch)
tree3382b4b8b52be577c3d0525df0e7da8178673d1c /jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp
parenta34e8c7d439d17355df51e5e536bdbbd1744cc74 (diff)
downloadandroid_packages_apps_Camera2-8bddf8ce4f3dcbb56edb12cee7e93f3a9daa3f96.tar.gz
android_packages_apps_Camera2-8bddf8ce4f3dcbb56edb12cee7e93f3a9daa3f96.tar.bz2
android_packages_apps_Camera2-8bddf8ce4f3dcbb56edb12cee7e93f3a9daa3f96.zip
Copy over libjni_mosaic from Camera. We need to support the SRI pano
mode for Carlsbad. Change-Id: Id14e64d8248236e8170c12cfca2cbf2ca952e993
Diffstat (limited to 'jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp')
-rwxr-xr-xjni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp b/jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp
new file mode 100755
index 000000000..a956f23b7
--- /dev/null
+++ b/jni/feature_mos/src/mosaic_renderer/FrameBuffer.cpp
@@ -0,0 +1,98 @@
+#include "FrameBuffer.h"
+
+FrameBuffer::FrameBuffer()
+{
+ Reset();
+}
+
+FrameBuffer::~FrameBuffer() {
+}
+
+void FrameBuffer::Reset() {
+ mFrameBufferName = -1;
+ mTextureName = -1;
+ mWidth = 0;
+ mHeight = 0;
+ mFormat = -1;
+}
+
+bool FrameBuffer::InitializeGLContext() {
+ Reset();
+ return CreateBuffers();
+}
+
+bool FrameBuffer::Init(int width, int height, GLenum format) {
+ if (mFrameBufferName == (GLuint)-1) {
+ if (!CreateBuffers()) {
+ return false;
+ }
+ }
+ glBindFramebuffer(GL_FRAMEBUFFER, mFrameBufferName);
+ glBindTexture(GL_TEXTURE_2D, mTextureName);
+
+ glTexImage2D(GL_TEXTURE_2D,
+ 0,
+ format,
+ width,
+ height,
+ 0,
+ format,
+ GL_UNSIGNED_BYTE,
+ NULL);
+ if (!checkGlError("bind/teximage")) {
+ return false;
+ }
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ // This is necessary to work with user-generated frame buffers with
+ // dimensions that are NOT powers of 2.
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ // Attach texture to frame buffer.
+ glFramebufferTexture2D(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D,
+ mTextureName,
+ 0);
+ checkFramebufferStatus("FrameBuffer.cpp");
+ checkGlError("framebuffertexture2d");
+
+ if (!checkGlError("texture setup")) {
+ return false;
+ }
+ mWidth = width;
+ mHeight = height;
+ mFormat = format;
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ return true;
+}
+
+bool FrameBuffer::CreateBuffers() {
+ glGenFramebuffers(1, &mFrameBufferName);
+ glGenTextures(1, &mTextureName);
+ if (!checkGlError("texture generation")) {
+ return false;
+ }
+ return true;
+}
+
+GLuint FrameBuffer::GetTextureName() const {
+ return mTextureName;
+}
+
+GLuint FrameBuffer::GetFrameBufferName() const {
+ return mFrameBufferName;
+}
+
+GLenum FrameBuffer::GetFormat() const {
+ return mFormat;
+}
+
+int FrameBuffer::GetWidth() const {
+ return mWidth;
+}
+
+int FrameBuffer::GetHeight() const {
+ return mHeight;
+}