RenderBuffer.hh 4.37 KB
Newer Older
Robert Menzel's avatar
Robert Menzel committed
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

6
7
#ifndef ACGL_OPENGL_OBJECTS_RENDERBUFFER_HH
#define ACGL_OPENGL_OBJECTS_RENDERBUFFER_HH
Robert Menzel's avatar
Robert Menzel committed
8

Robert Menzel's avatar
Robert Menzel committed
9
10
#include <ACGL/ACGL.hh>

11
#include <ACGL/Base/Macros.hh>
Robert Menzel's avatar
Robert Menzel committed
12
13
14
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>

Robert Menzel's avatar
Robert Menzel committed
15
16

namespace ACGL{
Robert Menzel's avatar
Robert Menzel committed
17
namespace OpenGL{
Robert Menzel's avatar
Robert Menzel committed
18
19
20

class RenderBuffer
{
21
22
    ACGL_NOT_COPYABLE(RenderBuffer)

23
24
25
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
Robert Menzel's avatar
Robert Menzel committed
26
27
28
public:
    RenderBuffer(
        GLenum _internalFormat)
29
    :   mObjectName(0),
Robert Menzel's avatar
Robert Menzel committed
30
        mInternalFormat(_internalFormat),
31
        mWidth(0),
32
33
        mHeight(0),
        mSamples(0)
Robert Menzel's avatar
Robert Menzel committed
34
    {
35
        glGenRenderbuffers(1, &mObjectName);
36
37
38
39
        if (openGLCriticalErrorOccured() ) {
            ACGL::Utils::error() << "could not generate renderbuffer!" << std::endl;
            return;
        }
Robert Menzel's avatar
Robert Menzel committed
40
41
42
43
    }

    virtual ~RenderBuffer(void)
    {
44
        // buffer 0 will get ignored by OpenGL
45
        glDeleteRenderbuffers(1, &mObjectName);
Robert Menzel's avatar
Robert Menzel committed
46
47
    }

48
49
50
    // ==================================================================================================== \/
    // ============================================================================================ GETTERS \/
    // ==================================================================================================== \/
Robert Menzel's avatar
Robert Menzel committed
51
public:
52
53
    inline GLuint  operator()        (void) const { return mObjectName;     }
    inline GLuint  getObjectName     (void) const { return mObjectName;     }
Robert Menzel's avatar
Robert Menzel committed
54
55
56
57
    inline GLenum  getInternalFormat (void) const { return mInternalFormat; }
    inline GLsizei getWidth          (void) const { return mWidth;          }
    inline GLsizei getHeight         (void) const { return mHeight;         }

58
59
60
61
62
63
64
65
66
67
68
69
70
    // ==================================================================================================== \/
    // ============================================================================================ METHODS \/
    // ==================================================================================================== \/
public:
    //! Get the actual number of samples
    inline int_t getSamples(void) const
    {
        glBindRenderbuffer(GL_RENDERBUFFER, mObjectName);
        GLint samples;
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
        return (int_t)samples;
    }

71
72
73
    // ===================================================================================================== \/
    // ============================================================================================ WRAPPERS \/
    // ===================================================================================================== \/
74
public:    
75
76
77
    //! Bind the renderbuffer
    inline void bind(void) const
    {
78
        glBindRenderbuffer(GL_RENDERBUFFER, mObjectName);
79
80
81
82
83
    }

    //! Set texture size and NULL data
    inline void setSize(
        GLsizei _width,
84
85
        GLsizei _height,
        GLsizei _samples = 0)
86
87
88
    {
        mWidth = _width;
        mHeight = _height;
89
        mSamples = _samples;
90
        glBindRenderbuffer(GL_RENDERBUFFER, mObjectName);
91
92
93
94

#if (ACGL_OPENGL_VERSION >= 30)
        glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, mInternalFormat, mWidth, mHeight);
#else
95
        glRenderbufferStorage(GL_RENDERBUFFER, mInternalFormat, mWidth, mHeight);
96
97
#endif // OpenGL >= 3.0

98
99
    }

100
101
102
    // =================================================================================================== \/
    // ============================================================================================ FIELDS \/
    // =================================================================================================== \/
Robert Menzel's avatar
Robert Menzel committed
103
protected:
104
    GLuint  mObjectName;
Robert Menzel's avatar
Robert Menzel committed
105
106
107
    GLenum  mInternalFormat;
    GLsizei mWidth;
    GLsizei mHeight;
108
    GLsizei mSamples;
Robert Menzel's avatar
Robert Menzel committed
109
110
};

111
ACGL_SHARED_TYPEDEF(RenderBuffer)
Robert Menzel's avatar
Robert Menzel committed
112
113

} // OpenGL
Robert Menzel's avatar
Robert Menzel committed
114
115
} // ACGL

116
#endif // ACGL_OPENGL_OBJECTS_RENDERBUFFER_HH