Go to the documentation of this file.00001 #ifndef GLW_RENDERBUFFER_H
00002 #define GLW_RENDERBUFFER_H
00003
00004 #include "./renderable.h"
00005
00006 namespace glw
00007 {
00008
00009 class RenderbufferArguments : public RenderableArguments
00010 {
00011 public:
00012
00013 typedef RenderableArguments BaseType;
00014 typedef RenderbufferArguments ThisType;
00015
00016 GLsizei width;
00017 GLsizei height;
00018
00019 RenderbufferArguments(void)
00020 : BaseType ()
00021 , width (0)
00022 , height (0)
00023 {
00024 }
00025
00026 RenderbufferArguments(GLenum aFormat, GLsizei aWidth, GLsizei aHeight)
00027 : BaseType (aFormat)
00028 , width (aWidth)
00029 , height (aHeight)
00030 {
00031 ;
00032 }
00033
00034 void clear(void)
00035 {
00036 BaseType::clear();
00037 this->width = 0;
00038 this->height = 0;
00039 }
00040 };
00041
00042 class Renderbuffer : public Renderable
00043 {
00044 friend class Context;
00045
00046 public:
00047
00048 typedef Renderable BaseType;
00049 typedef Renderbuffer ThisType;
00050
00051 virtual ~Renderbuffer(void)
00052 {
00053 this->destroy();
00054 }
00055
00056 virtual Type type(void) const
00057 {
00058 return RenderbufferType;
00059 }
00060
00061 virtual int imageDimensions(void) const
00062 {
00063 return 2;
00064 }
00065
00066 virtual bool isArray(void) const
00067 {
00068 return false;
00069 }
00070
00071 GLsizei width(void) const
00072 {
00073 return this->m_width;
00074 }
00075
00076 GLsizei height(void) const
00077 {
00078 return this->m_height;
00079 }
00080
00081 void setStorage(GLenum target, GLint unit, GLenum format, GLsizei width, GLsizei height)
00082 {
00083 (void)unit;
00084 GLW_ASSERT(this->isValid());
00085 glRenderbufferStorage(target, format, width, height);
00086 this->m_format = format;
00087 this->m_width = width;
00088 this->m_height = height;
00089 }
00090
00091 protected:
00092
00093 GLsizei m_width;
00094 GLsizei m_height;
00095
00096 Renderbuffer(Context * ctx)
00097 : BaseType (ctx)
00098 , m_width (0)
00099 , m_height (0)
00100 {
00101 ;
00102 }
00103
00104 bool create(const RenderbufferArguments & args)
00105 {
00106 this->destroy();
00107 GLint boundName = 0;
00108 glGetIntegerv(GL_RENDERBUFFER_BINDING, &boundName);
00109 glGenRenderbuffers(1, &(this->m_name));
00110 glBindRenderbuffer(GL_RENDERBUFFER, this->m_name);
00111 glRenderbufferStorage(GL_RENDERBUFFER, args.format, args.width, args.height);
00112 glBindRenderbuffer(GL_RENDERBUFFER, boundName);
00113 this->m_format = args.format;
00114 this->m_width = args.width;
00115 this->m_height = args.height;
00116 return true;
00117 }
00118
00119 virtual void doDestroy(void)
00120 {
00121 glDeleteRenderbuffers(1, &(this->m_name));
00122 this->m_format = GL_NONE;
00123 this->m_width = 0;
00124 this->m_height = 0;
00125 }
00126
00127 virtual bool doIsValid(void) const
00128 {
00129 return ((this->m_format != GL_NONE) && (this->m_width > 0) && (this->m_height > 0));
00130 }
00131 };
00132
00133 namespace detail { template <> struct BaseOf <Renderbuffer> { typedef Renderable Type; }; };
00134 typedef detail::ObjectSharedPointerTraits <Renderbuffer> ::Type RenderbufferPtr;
00135
00136 class SafeRenderbuffer : public SafeRenderable
00137 {
00138 friend class Context;
00139 friend class BoundRenderbuffer;
00140
00141 public:
00142
00143 typedef SafeRenderable BaseType;
00144 typedef SafeRenderbuffer ThisType;
00145
00146 SafeRenderbuffer(void)
00147 : BaseType()
00148 {
00149 ;
00150 }
00151
00152 GLsizei width(void) const
00153 {
00154 return this->object()->width();
00155 }
00156
00157 GLsizei height(void) const
00158 {
00159 return this->object()->height();
00160 }
00161
00162 protected:
00163
00164 SafeRenderbuffer(const RenderbufferPtr & renderbuffer)
00165 : BaseType(renderbuffer)
00166 {
00167 ;
00168 }
00169
00170 const RenderbufferPtr & object(void) const
00171 {
00172 return static_cast<const RenderbufferPtr &>(BaseType::object());
00173 }
00174
00175 RenderbufferPtr & object(void)
00176 {
00177 return static_cast<RenderbufferPtr &>(BaseType::object());
00178 }
00179 };
00180
00181 namespace detail { template <> struct BaseOf <SafeRenderbuffer> { typedef SafeRenderable Type; }; };
00182 namespace detail { template <> struct ObjectBase <SafeRenderbuffer> { typedef Renderbuffer Type; }; };
00183 namespace detail { template <> struct ObjectSafe <Renderbuffer > { typedef SafeRenderbuffer Type; }; };
00184 typedef detail::ObjectSharedPointerTraits <SafeRenderbuffer> ::Type RenderbufferHandle;
00185
00186 class RenderbufferBindingParams : public RenderableBindingParams
00187 {
00188 public:
00189
00190 typedef RenderableBindingParams BaseType;
00191 typedef RenderbufferBindingParams ThisType;
00192
00193 RenderbufferBindingParams(void)
00194 : BaseType(GL_RENDERBUFFER, 0)
00195 {
00196 ;
00197 }
00198 };
00199
00200 class BoundRenderbuffer : public BoundRenderable
00201 {
00202 friend class Context;
00203
00204 public:
00205
00206 typedef BoundRenderable BaseType;
00207 typedef BoundRenderbuffer ThisType;
00208
00209 BoundRenderbuffer(void)
00210 : BaseType()
00211 {
00212 ;
00213 }
00214
00215 const RenderbufferHandle & handle(void) const
00216 {
00217 return static_cast<const RenderbufferHandle &>(BaseType::handle());
00218 }
00219
00220 RenderbufferHandle & handle(void)
00221 {
00222 return static_cast<RenderbufferHandle &>(BaseType::handle());
00223 }
00224
00225 void setStorage(GLenum format, GLsizei width, GLsizei height)
00226 {
00227 this->object()->setStorage(this->m_target, this->m_unit, format, width, height);
00228 }
00229
00230 protected:
00231
00232 BoundRenderbuffer(const RenderbufferHandle & handle, const RenderbufferBindingParams & params)
00233 : BaseType(handle, params)
00234 {
00235 ;
00236 }
00237
00238 const RenderbufferPtr & object(void) const
00239 {
00240 return this->handle()->object();
00241 }
00242
00243 RenderbufferPtr & object(void)
00244 {
00245 return this->handle()->object();
00246 }
00247
00248 virtual void bind(void)
00249 {
00250 glBindRenderbuffer(this->m_target, this->object()->name());
00251 }
00252
00253 virtual void unbind(void)
00254 {
00255 glBindRenderbuffer(this->m_target, 0);
00256 }
00257 };
00258
00259 namespace detail { template <> struct ParamsOf <BoundRenderbuffer> { typedef RenderbufferBindingParams Type; }; };
00260 namespace detail { template <> struct BaseOf <BoundRenderbuffer> { typedef BoundObject Type; }; };
00261 namespace detail { template <> struct ObjectBase <BoundRenderbuffer> { typedef Renderbuffer Type; }; };
00262 namespace detail { template <> struct ObjectBound <Renderbuffer > { typedef BoundRenderbuffer Type; }; };
00263 typedef detail::ObjectSharedPointerTraits <BoundRenderbuffer> ::Type BoundRenderbufferHandle;
00264
00265 };
00266
00267 #endif // GLW_RENDERBUFFER_H