OGLplus (0.52.0) a C++ wrapper for OpenGL

framebuffer.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_DSA_FRAMEBUFFER_1310090720_HPP
14 #define OGLPLUS_DSA_FRAMEBUFFER_1310090720_HPP
15 
16 #include <oglplus/framebuffer.hpp>
17 #include <oglplus/color_buffer.hpp>
18 
19 namespace oglplus {
20 
21 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_4_5 || GL_ARB_direct_state_access
22 
23 template <>
24 struct ObjGenTag<tag::DirectState, tag::Framebuffer>
25 {
26  typedef tag::Create Type;
27 };
28 
30 
33 template <>
34 class ObjectOps<tag::DirectState, tag::Framebuffer>
35  : public ObjZeroOps<tag::DirectState, tag::Framebuffer>
36 {
37 protected:
38  ObjectOps(void){ }
39 public:
41  struct Property
42  {
44  typedef OneOf<
45  GLenum,
46  std::tuple<
49  >
51 
54  };
55 
57  void Bind(Target target)
58  {
60  }
61 
62 
64 
74  {
75  GLenum result = OGLPLUS_GLFUNC(CheckNamedFramebufferStatus)(
76  _name,
77  GLenum(target)
78  );
79  if(result == 0) OGLPLUS_CHECK(
80  CheckNamedFramebufferStatus,
82  Object(*this).
83  BindTarget(target)
84  );
85  return FramebufferStatus(result);
86  }
87 
89 
96  bool IsComplete(Target target) const
97  {
98  return Status(target) == FramebufferStatus::Complete;
99  }
100 
101  void HandleIncompleteError(FramebufferStatus status) const;
102 
104  void Complete(Target target) const
105  {
106  FramebufferStatus status = Status(target);
107  if(status != FramebufferStatus::Complete)
108  {
109  HandleIncompleteError(status);
110  }
111  }
112 
114 
127  Property::Attachment attachment,
128  RenderbufferName renderbuffer
129  )
130  {
131  OGLPLUS_GLFUNC(NamedFramebufferRenderbuffer)(
132  _name,
133  GLenum(attachment),
134  GL_RENDERBUFFER,
135  GetGLName(renderbuffer)
136  );
137  OGLPLUS_CHECK(
138  NamedFramebufferRenderbuffer,
139  ObjectPairError,
140  Subject(renderbuffer).
141  Object(*this)
142  );
143  }
144 
146 
159  FramebufferColorAttachmentNumber attachment_no,
160  RenderbufferName renderbuffer
161  )
162  {
163  OGLPLUS_GLFUNC(NamedFramebufferRenderbuffer)(
164  _name,
165  GL_COLOR_ATTACHMENT0 + GLuint(attachment_no),
166  GL_RENDERBUFFER,
167  GetGLName(renderbuffer)
168  );
169  OGLPLUS_CHECK(
170  NamedFramebufferRenderbuffer,
171  ObjectPairError,
172  Subject(renderbuffer).
173  Object(*this)
174  );
175  }
176 
177 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_2
178 
192  Property::Attachment attachment,
193  TextureName texture,
194  GLint level
195  )
196  {
197  OGLPLUS_GLFUNC(NamedFramebufferTexture)(
198  _name,
199  GLenum(attachment),
200  GetGLName(texture),
201  level
202  );
203  OGLPLUS_CHECK(
204  NamedFramebufferTexture,
205  ObjectPairError,
206  Subject(texture).
207  Object(*this).
208  Index(level)
209  );
210  }
211 
213 
226  FramebufferColorAttachmentNumber attachment_no,
227  TextureName texture,
228  GLint level
229  )
230  {
231  OGLPLUS_GLFUNC(NamedFramebufferTexture)(
232  _name,
233  GL_COLOR_ATTACHMENT0 + GLenum(attachment_no),
234  GetGLName(texture),
235  level
236  );
237  OGLPLUS_CHECK(
238  NamedFramebufferTexture,
239  ObjectPairError,
240  Subject(texture).
241  Object(*this).
242  Index(level)
243  );
244  }
245 #endif
246 
248 
261  Property::Attachment attachment,
262  TextureName texture,
263  GLint level,
264  GLint layer
265  )
266  {
267  OGLPLUS_GLFUNC(NamedFramebufferTextureLayer)(
268  _name,
269  GLenum(attachment),
270  GetGLName(texture),
271  level,
272  layer
273  );
274  OGLPLUS_CHECK(
275  NamedFramebufferTextureLayer,
276  ObjectPairError,
277  Subject(texture).
278  Object(*this).
279  Index(level)
280  );
281  }
282 
284  typedef OneOf<
285  GLenum,
286  std::tuple<
289  >
291 
293 
297  void DrawBuffer(ColorBuffer buffer)
298  {
299  OGLPLUS_GLFUNC(NamedFramebufferDrawBuffer)(
300  _name,
301  GLenum(buffer)
302  );
303  OGLPLUS_VERIFY(
304  NamedFramebufferDrawBuffer,
305  ObjectError,
306  Object(*this)
307  );
308  }
309 
311 
315  template <unsigned N>
316  void DrawBuffers(const EnumArray<ColorBuffer>& buffers)
317  {
318  OGLPLUS_GLFUNC(NamedFramebufferDrawBuffers)(
319  _name,
320  buffers.Count(),
321  buffers.Values()
322  );
323  OGLPLUS_VERIFY(
324  NamedFramebufferDrawBuffers,
325  ObjectError,
326  Object(*this)
327  );
328  }
329 
331 
335  void ReadBuffer(ColorBuffer buffer)
336  {
337  OGLPLUS_GLFUNC(NamedFramebufferReadBuffer)(_name, GLenum(buffer));
338  OGLPLUS_VERIFY(
339  NamedFramebufferReadBuffer,
340  ObjectError,
341  Object(*this)
342  );
343  }
344 };
345 
347 typedef ObjectOps<tag::DirectState, tag::Framebuffer>
349 
350 // Helper class for syntax-sugar operators
351 struct DSAFramebufferOpsAndAttch
352 {
353  typedef DSAFramebufferOps::Property::Attachment Attachment;
354 
355  DSAFramebufferOps& fbo;
356  Attachment attachment;
357 
358  DSAFramebufferOpsAndAttch(DSAFramebufferOps& f, Attachment a)
359  : fbo(f)
360  , attachment(a)
361  { }
362 };
363 
364 inline DSAFramebufferOpsAndAttch operator << (
365  DSAFramebufferOps& fbo,
366  DSAFramebufferOps::Property::Attachment attch
367 )
368 {
369  return DSAFramebufferOpsAndAttch(fbo, attch);
370 }
371 
372 // Bind
373 inline DSAFramebufferOps& operator << (
374  DSAFramebufferOps& fbo,
375  FramebufferTarget target
376 )
377 {
378  fbo.Bind(target);
379  return fbo;
380 }
381 
382 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_2
383 // AttachTexture
384 inline DSAFramebufferOps& operator << (
385  DSAFramebufferOpsAndAttch&& faa,
386  TextureName tex
387 )
388 {
389  faa.fbo.AttachTexture(faa.attachment, tex, 0);
390  return faa.fbo;
391 }
392 #endif
393 
394 // AttachRenderbuffer
395 inline DSAFramebufferOps& operator << (
396  DSAFramebufferOpsAndAttch&& faa,
397  RenderbufferName rbo
398 )
399 {
400  faa.fbo.AttachRenderbuffer(faa.attachment, rbo);
401  return faa.fbo;
402 }
403 
405 
408 typedef Object<DSAFramebufferOps> DSAFramebuffer;
409 
410 #endif // GL_ARB_direct_state_access
411 
412 } // namespace oglplus
413 
414 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
415 #include <oglplus/dsa/framebuffer.ipp>
416 #endif // OGLPLUS_LINK_LIBRARY
417 
418 #endif // include guard
OpenGL Color buffer enumeration.
FramebufferStatus
Framebuffer status enumeration.
Definition: framebuffer_status.hpp:24
void ReadBuffer(ColorBuffer buffer)
Sets the source color buffer for read operations.
Definition: framebuffer.hpp:335
void DrawBuffer(ColorBuffer buffer)
Sets the destination color buffer for draw operations.
Definition: framebuffer.hpp:297
void AttachTextureLayer(Property::Attachment attachment, TextureName texture, GLint level, GLint layer)
Attach a texture layer to the attachment point of this FBO.
Definition: framebuffer.hpp:260
Type for the framebuffer color attachment (implementation-dependent) number.
Definition: framebuffer_attachment.hpp:23
void AttachColorRenderbuffer(FramebufferColorAttachmentNumber attachment_no, RenderbufferName renderbuffer)
Attach a renderbuffer to the color attachment_no of this FBO.
Definition: framebuffer.hpp:158
FramebufferAttachment
Framebuffer object attachment points.
Definition: framebuffer_attachment.hpp:56
FramebufferStatus Status
Status of a Framebuffer.
Definition: framebuffer.hpp:53
void Complete(Target target) const
Throws an exception if the framebuffer is not complete.
Definition: framebuffer.hpp:104
void AttachTexture(Property::Attachment attachment, TextureName texture, GLint level)
Attach a texture to the attachment point of this FBO.
Definition: framebuffer.hpp:191
COLOR_BUFFER_BIT: Clear the color buffer.
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
OneOf< GLenum, std::tuple< oglplus::ColorBuffer, oglplus::FramebufferColorAttachment > > ColorBuffer
Color buffer specification type.
Definition: framebuffer.hpp:290
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
Framebuffer object wrappers.
void AttachRenderbuffer(Property::Attachment attachment, RenderbufferName renderbuffer)
Attach a renderbuffer to the attachment point of this FBO.
Definition: framebuffer.hpp:126
Stores a value having one of the listed types in a common representation.
Definition: one_of.hpp:60
Exception class for GL object-related errors.
Definition: object.hpp:24
FramebufferTarget
Framebuffer bind target.
Definition: framebuffer_target.hpp:24
Class wrapping framebuffer-related functionality with direct state access.
Definition: framebuffer.hpp:34
void AttachColorTexture(FramebufferColorAttachmentNumber attachment_no, TextureName texture, GLint level)
Attach a texture to the color attachment point of this FBO.
Definition: framebuffer.hpp:225
ObjectOps< tag::DirectState, tag::Framebuffer > DSAFramebufferOps
Framebuffer operations with direct state access.
Definition: framebuffer.hpp:348
bool IsComplete(Target target) const
Returns true if the framebuffer is complete.
Definition: framebuffer.hpp:96
FramebufferStatus Status(Target target) const
Checks the status of the framebuffer.
Definition: framebuffer.hpp:73
OneOf< GLenum, std::tuple< FramebufferAttachment, FramebufferColorAttachment > > Attachment
Attachment of a Framebuffer.
Definition: framebuffer.hpp:50
void DrawBuffers(const EnumArray< ColorBuffer > &buffers)
Sets the destination color buffers for draw operations.
Definition: framebuffer.hpp:316
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
Object< DSAFramebufferOps > DSAFramebuffer
An oglplus_object encapsulating the OpenGL framebuffer functionality.
Definition: framebuffer.hpp:408
FramebufferColorAttachment
Framebuffer color attachment points.
Definition: framebuffer_attachment.hpp:72

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).