|
|
@@ -1,50 +1,36 @@
|
|
|
-#ifndef _FBO_H_
|
|
|
-#define _FBO_H_
|
|
|
+#ifndef FBO_H
|
|
|
+#define FBO_H
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
-#include "Common.h"
|
|
|
+#include "Exception.h"
|
|
|
|
|
|
|
|
|
-/**
|
|
|
- * The class is actually a wrapper to avoid common mistakes
|
|
|
- */
|
|
|
+/// The class is actually a wrapper to avoid common mistakes
|
|
|
class Fbo
|
|
|
{
|
|
|
PROPERTY_R(uint, glId, getGlId) ///< OpenGL identification
|
|
|
|
|
|
public:
|
|
|
- Fbo();
|
|
|
+ Fbo(): glId(0) {}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a new FBO
|
|
|
- */
|
|
|
+ /// Creates a new FBO
|
|
|
void create();
|
|
|
|
|
|
- /**
|
|
|
- * Binds FBO
|
|
|
- */
|
|
|
+ /// Binds FBO
|
|
|
void bind() const;
|
|
|
|
|
|
- /**
|
|
|
- * Unbinds the FBO. Actually unbinds all FBOs
|
|
|
- */
|
|
|
+ /// Unbinds the FBO. Actually unbinds all FBOs
|
|
|
static void unbind();
|
|
|
|
|
|
- /**
|
|
|
- * Checks the status of an initialized FBO
|
|
|
- * @return True if FBO is ok and false if not
|
|
|
- */
|
|
|
- bool isGood() const;
|
|
|
+ /// Checks the status of an initialized FBO and if fails throw exception
|
|
|
+ /// @exception Exception
|
|
|
+ void checkIfGood() const;
|
|
|
|
|
|
- /**
|
|
|
- * Set the number of color attachements of the FBO
|
|
|
- */
|
|
|
+ /// Set the number of color attachements of the FBO
|
|
|
void setNumOfColorAttachements(uint num) const;
|
|
|
|
|
|
- /**
|
|
|
- * Returns the GL id of the current attached FBO
|
|
|
- * @return Returns the GL id of the current attached FBO
|
|
|
- */
|
|
|
+ /// Returns the GL id of the current attached FBO
|
|
|
+ /// @return Returns the GL id of the current attached FBO
|
|
|
static uint getCurrentFbo();
|
|
|
};
|
|
|
|
|
|
@@ -53,21 +39,16 @@ class Fbo
|
|
|
// Inlines =
|
|
|
//======================================================================================================================
|
|
|
|
|
|
-inline Fbo::Fbo():
|
|
|
- glId(0)
|
|
|
-{}
|
|
|
-
|
|
|
-
|
|
|
inline void Fbo::create()
|
|
|
{
|
|
|
- DEBUG_ERR(glId != 0); // FBO already initialized
|
|
|
+ RASSERT_THROW_EXCEPTION(glId != 0); // FBO already initialized
|
|
|
glGenFramebuffers(1, &glId);
|
|
|
}
|
|
|
|
|
|
|
|
|
inline void Fbo::bind() const
|
|
|
{
|
|
|
- DEBUG_ERR(glId == 0); // FBO not initialized
|
|
|
+ RASSERT_THROW_EXCEPTION(glId == 0); // FBO not initialized
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, glId);
|
|
|
}
|
|
|
|
|
|
@@ -78,19 +59,22 @@ inline void Fbo::unbind()
|
|
|
}
|
|
|
|
|
|
|
|
|
-inline bool Fbo::isGood() const
|
|
|
+inline void Fbo::checkIfGood() const
|
|
|
{
|
|
|
- DEBUG_ERR(glId == 0); // FBO not initialized
|
|
|
- DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
|
|
|
+ RASSERT_THROW_EXCEPTION(glId == 0); // FBO not initialized
|
|
|
+ RASSERT_THROW_EXCEPTION(getCurrentFbo() != glId); // another FBO is binded
|
|
|
|
|
|
- return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
|
|
|
+ if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
|
+ {
|
|
|
+ throw EXCEPTION("FBO is incomplete");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
inline void Fbo::setNumOfColorAttachements(uint num) const
|
|
|
{
|
|
|
- DEBUG_ERR(glId == 0); // FBO not initialized
|
|
|
- DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
|
|
|
+ RASSERT_THROW_EXCEPTION(glId == 0); // FBO not initialized
|
|
|
+ RASSERT_THROW_EXCEPTION(getCurrentFbo() != glId); // another FBO is binded
|
|
|
|
|
|
if(num == 0)
|
|
|
{
|
|
|
@@ -99,11 +83,11 @@ inline void Fbo::setNumOfColorAttachements(uint num) const
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
|
|
|
- GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
|
|
|
- GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
|
|
|
+ static GLenum colorAttachments[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
|
|
|
+ GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
|
|
|
+ GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7};
|
|
|
|
|
|
- DEBUG_ERR(num > sizeof(colorAttachments)/sizeof(GLenum));
|
|
|
+ RASSERT_THROW_EXCEPTION(num > sizeof(colorAttachments)/sizeof(GLenum));
|
|
|
glDrawBuffers(num, colorAttachments);
|
|
|
}
|
|
|
}
|
|
|
@@ -116,4 +100,5 @@ inline uint Fbo::getCurrentFbo()
|
|
|
return (uint)fboGlId;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#endif
|