Skip to content

Commit

Permalink
Improved usefulness of const objects. Added pointer alternatives for …
Browse files Browse the repository at this point in the history
…convenience to functions that take a reference. Cleaned up code a little.
  • Loading branch information
bwrrp committed Jan 25, 2008
1 parent 236bb0b commit cb5fc71
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 31 deletions.
2 changes: 2 additions & 0 deletions GLFragmentShader.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "GLFragmentShader.h"

// ----------------------------------------------------------------------------
GLFragmentShader::GLFragmentShader()
: GLShader(GL_FRAGMENT_SHADER)
{
}

// ----------------------------------------------------------------------------
GLFragmentShader::~GLFragmentShader()
{
}
49 changes: 43 additions & 6 deletions GLFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using namespace std;

// ----------------------------------------------------------------------------
// Need to use this factory to create FBOs
GLFramebuffer* GLFramebuffer::New(int width, int height)
{
Expand All @@ -25,6 +26,7 @@ GLFramebuffer* GLFramebuffer::New(int width, int height)
return new GLFramebuffer(width, height);
}

// ----------------------------------------------------------------------------
GLFramebuffer::GLFramebuffer(int width, int height)
: id(0), width(width), height(height), bound(false)
{
Expand All @@ -36,6 +38,7 @@ GLFramebuffer::GLFramebuffer(int width, int height)
#endif
}

// ----------------------------------------------------------------------------
GLFramebuffer::~GLFramebuffer()
{
//cout << "GLFramebuffer: Destructor" << endl;
Expand All @@ -56,6 +59,20 @@ GLFramebuffer::~GLFramebuffer()
#endif
}

// ----------------------------------------------------------------------------
GLRendertarget *GLFramebuffer::AttachRendertarget(int attachment, GLRendertarget *rt)
{
if (!rt)
{
return DetachRendertarget(attachment);
}
else
{
return AttachRendertarget(attachment, *rt);
}
}

// ----------------------------------------------------------------------------
GLRendertarget *GLFramebuffer::AttachRendertarget(int attachment, GLRendertarget &rt)
{
if (!bound) Bind();
Expand All @@ -71,6 +88,7 @@ GLRendertarget *GLFramebuffer::AttachRendertarget(int attachment, GLRendertarget
return oldRt;
}

// ----------------------------------------------------------------------------
GLRendertarget* GLFramebuffer::DetachRendertarget(int attachment)
{
if (!bound) Bind();
Expand All @@ -88,6 +106,7 @@ GLRendertarget* GLFramebuffer::DetachRendertarget(int attachment)
return rt;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreateDepthBuffer(int format)
{
GLRendertarget *depthbuffer = GLRenderbuffer::New(width, height, format);
Expand All @@ -96,6 +115,7 @@ bool GLFramebuffer::CreateDepthBuffer(int format)
return true;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreateDepthTexture(int format)
{
GLRendertarget *depthbuffer = GLRenderTexture2D::New(width, height,
Expand All @@ -105,6 +125,7 @@ bool GLFramebuffer::CreateDepthTexture(int format)
return true;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreateDepthTextureRectangle(int format)
{
if (!GLEW_ARB_texture_rectangle) return false;
Expand All @@ -116,6 +137,7 @@ bool GLFramebuffer::CreateDepthTextureRectangle(int format)
return true;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreatePackedDepthStencilBuffer()
{
if (!GLEW_EXT_packed_depth_stencil) return false;
Expand All @@ -127,6 +149,7 @@ bool GLFramebuffer::CreatePackedDepthStencilBuffer()
return true;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreatePackedDepthStencilTexture()
{
if (!GLEW_EXT_packed_depth_stencil) return false;
Expand All @@ -140,6 +163,7 @@ bool GLFramebuffer::CreatePackedDepthStencilTexture()
return true;
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::CreatePackedDepthStencilTextureRectangle()
{
if (!GLEW_ARB_texture_rectangle) return false;
Expand All @@ -154,7 +178,8 @@ bool GLFramebuffer::CreatePackedDepthStencilTextureRectangle()
return true;
}

void GLFramebuffer::Bind()
// ----------------------------------------------------------------------------
void GLFramebuffer::Bind()
{
if (bound)
{
Expand All @@ -174,6 +199,7 @@ void GLFramebuffer::Bind()
#endif
}

// ----------------------------------------------------------------------------
void GLFramebuffer::Unbind()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
Expand All @@ -195,17 +221,14 @@ void GLFramebuffer::Unbind()
#endif
}

bool GLFramebuffer::IsBound()
{
return bound;
}

// ----------------------------------------------------------------------------
int GLFramebuffer::GetStatus()
{
if (!bound) Bind();
return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::IsOk()
{
int status = GetStatus();
Expand All @@ -224,6 +247,7 @@ bool GLFramebuffer::IsOk()
}
}

// ----------------------------------------------------------------------------
GLTexture* GLFramebuffer::GetTexture2D(int attachment)
{
// Try to cast, return null if that attachment isn't a rendertarget
Expand All @@ -233,6 +257,19 @@ GLTexture* GLFramebuffer::GetTexture2D(int attachment)
return rt->GetTexture();
}

// ----------------------------------------------------------------------------
const GLTexture* GLFramebuffer::GetTexture2D(int attachment) const
{
// Try to cast, return null if that attachment isn't a rendertarget
map<int, GLRendertarget*>::const_iterator atit = attachments.find(attachment);
if (atit == attachments.end()) return 0;
const GLRenderTexture2D *rt = dynamic_cast<const GLRenderTexture2D*>(atit->second);
if (!rt) return 0;
// Return texture
return rt->GetTexture();
}

// ----------------------------------------------------------------------------
bool GLFramebuffer::Resize(int width, int height)
{
// Resize all attachments
Expand Down
8 changes: 5 additions & 3 deletions GLFramebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GLFramebuffer : public GLResource
static GLFramebuffer *New(int width, int height);
~GLFramebuffer();

GLRendertarget *AttachRendertarget(int attachment, GLRendertarget *rt);
GLRendertarget *AttachRendertarget(int attachment, GLRendertarget &rt);
GLRendertarget *DetachRendertarget(int attachment);

Expand All @@ -23,15 +24,16 @@ class GLFramebuffer : public GLResource

void Bind();
void Unbind();
bool IsBound();
bool IsBound() const { return bound; }

int GetStatus();
bool IsOk();

inline int GetWidth() { return width; }
inline int GetHeight() { return height; }
inline int GetWidth() const { return width; }
inline int GetHeight() const { return height; }

GLTexture *GetTexture2D(int attachment);
const GLTexture *GetTexture2D(int attachment) const;

bool Resize(int width, int height);

Expand Down
Loading

0 comments on commit cb5fc71

Please sign in to comment.