From 01a1b297f1dc19c53d0d9777eea7c226ca0daddb Mon Sep 17 00:00:00 2001
From: Frederic Plourde<[email protected]>
Date: Mon, 3 Oct 2011 14:40:25 -0400
Subject: [PATCH gles] Add FBO capabilities to the opengl plugin.

This patch adds a simple GLFbo class in the opengl plugin source directory.
It is mostly copy&paste from the nux FBO implementation, but does not
include the ::paint().
Also, at the moment, the class only suppors one color attachment.
---
 plugins/opengl/include/opengl/fbo.h |   70 +++++++++++++++
 plugins/opengl/src/fbo.cpp          |  164
+++++++++++++++++++++++++++++++++++
 2 files changed, 234 insertions(+), 0 deletions(-)

diff --git a/plugins/opengl/include/opengl/fbo.h
b/plugins/opengl/include/opengl/fbo.h
new file mode 100644
index 0000000..b1e4097
--- /dev/null
+++ b/plugins/opengl/include/opengl/fbo.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2010-11 Canonical Ltd.
+ * Copyright (c) 2011 Collabora Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the names of
+ * Collabora Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Collabora Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * COLLABORA LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL COLLABORA LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Let's use this GLFbo class until we've got all the nux opengl stuff
+ * available in a separate lib.
+ */
+
+#ifndef _GLFbo_H
+#define _GLFbo_H
+
+#ifdef USE_GLES
+#include<GLES2/gl2.h>
+#else
+#include<GL/gl.h>
+#endif
+
+#include<core/core.h>
+#include<opengl/opengl.h>
+#include<opengl/matrix.h>
+
+class GLFbo
+{
+public:
+
+    GLFbo (CompOutput *o, GLTexture* texPtr);
+    ~GLFbo ();
+
+public:
+
+
+static void checkError(const char* label, bool fetch = true);
+
+    void bind ();
+    void unbind ();
+
+    bool status ();
+    bool bound ();
+
+    GLuint getTexID () { return texture->name (); }
+
+private:
+
+    GLuint    mFboHandle; // actual handle to the framebuffer_ext
+    bool      mFboStatus; // did the framebuffer texture bind succeed
+    GLTexture* texture;
+    CompOutput *output;
+    unsigned int mBoundCnt;
+};
+
+#endif
diff --git a/plugins/opengl/src/fbo.cpp b/plugins/opengl/src/fbo.cpp
new file mode 100644
index 0000000..3fd7c01
--- /dev/null
+++ b/plugins/opengl/src/fbo.cpp
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2010-11 Canonical Ltd.
+ * Copyright (c) 2006 Collabora, ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Collabora, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Collabora, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * COLLABORA, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL COLLABORA, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Let's use this GLFbo class until we've got all the nux opengl stuff
+ * available in a separate lib.
+ */
+
+#include<opengl/fbo.h>
+#include "privates.h"
+
+void
+GLFbo::checkError(const char* label, bool fetch)
+{
+    GLenum err = glGetError ();
+
+    printf ("%s :\n", label);
+    if (fetch)
+    {
+    if (err != GL_NO_ERROR)
+    {
+        switch (err)
+        {
+        case GL_INVALID_ENUM:
+            compLogMessage ("fbo", CompLogLevelWarn, "invalid enum");
+            break;
+        case GL_INVALID_VALUE:
+            compLogMessage ("fbo", CompLogLevelWarn, "invalid value");
+            break;
+        case GL_INVALID_OPERATION:
+            compLogMessage ("fbo", CompLogLevelWarn, "invalid operation");
+            break;
+        case GL_INVALID_FRAMEBUFFER_OPERATION:
+            compLogMessage ("fbo", CompLogLevelWarn, "invalid
framebuffer operation");
+            break;
+        case GL_OUT_OF_MEMORY:
+            compLogMessage ("fbo", CompLogLevelWarn, "out of memory");
+            break;
+        default:
+            compLogMessage ("fbo", CompLogLevelWarn, "Unknown GL error !");
+            break;
+        }
+    }
+    }
+}
+
+bool
+GLFbo::bound ()
+{
+    return mBoundCnt>  0;
+}
+
+bool
+GLFbo::status ()
+{
+    return mFboStatus;
+}
+
+void
+GLFbo::bind ()
+{
+    if (mBoundCnt)
+    {
+    mBoundCnt++;
+    return;
+    }
+
+    (*GL::bindFramebuffer) (GL_FRAMEBUFFER, mFboHandle);
+    (*GL::framebufferTexture2D) (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                               GL_TEXTURE_2D, texture->name (), 0);
+
+    /* Ensure that a framebuffer is actually available */
+    if (!mFboStatus)
+    {
+    GLint status = (*GL::checkFramebufferStatus) (GL_FRAMEBUFFER);
+
+    if (status != GL_FRAMEBUFFER_COMPLETE)
+    {
+        switch (status)
+        {
+        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+            compLogMessage ("fbo", CompLogLevelWarn, "attachment
incomplete");
+            break;
+        case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+            compLogMessage ("fbo", CompLogLevelWarn, "dimensions
incomplete");
+            break;
+        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+            compLogMessage ("fbo", CompLogLevelWarn, "no buffers
attached to fbo");
+            break;
+        case GL_FRAMEBUFFER_UNSUPPORTED:
+            compLogMessage ("fbo", CompLogLevelWarn, "unsupported
internal format");
+            break;
+        default:
+            compLogMessage ("fbo", CompLogLevelWarn, "unable to bind
the framebuffer for an unknown reason");
+            break;
+        }
+
+        GL::bindFramebuffer (GL_FRAMEBUFFER, 0);
+        GL::deleteFramebuffers (1,&mFboHandle);
+
+        mFboHandle = 0;
+        mFboStatus = false;
+    }
+    else
+        mFboStatus = true;
+    }
+
+    if (mFboStatus)
+    {
+    glViewport (0,
+            0,
+            output->width(),
+            output->height());
+
+    mBoundCnt++;
+    }
+}
+
+void
+GLFbo::unbind ()
+{
+    mBoundCnt--;
+
+    if (mBoundCnt)
+    return;
+
+    (*GL::framebufferTexture2D) (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                 GL_TEXTURE_2D, 0, 0);
+    (*GL::bindFramebuffer) (GL_FRAMEBUFFER, 0);
+}
+
+GLFbo::GLFbo (CompOutput *o, GLTexture* texPtr)
+    : mFboStatus (false)
+    , texture (texPtr)
+    , output (o)
+    , mBoundCnt (0)
+{
+    (*GL::genFramebuffers) (1,&mFboHandle);
+}
+
+GLFbo::~GLFbo ()
+{
+    (*GL::deleteFramebuffers) (1,&mFboHandle);
+    GLTexture::decRef (texture);
+}
--
1.7.4.1


_______________________________________________
dev mailing list
[email protected]
http://lists.compiz.org/mailman/listinfo/dev

Reply via email to