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_FRAMEBUFFER_1107121519_HPP
14 #define OGLPLUS_FRAMEBUFFER_1107121519_HPP
15 
16 #include <oglplus/glfunc.hpp>
22 #include <oglplus/one_of.hpp>
24 #include <cassert>
25 
26 namespace oglplus {
27 
28 // NOTE: Xlib.h defines this symbol
29 // using the preprocessor.
30 #ifdef Status
31 #undef Status
32 #endif
33 
35 
42 template <>
43 class ObjGenDelOps<tag::Framebuffer>
44 {
45 protected:
46  static void Gen(tag::Generate, GLsizei count, GLuint* names)
47  {
48  assert(names != nullptr);
49  OGLPLUS_GLFUNC(GenFramebuffers)(count, names);
50  OGLPLUS_CHECK_SIMPLE(GenFramebuffers);
51  }
52 #if GL_VERSION_4_5 || GL_ARB_direct_state_access
53  static void Gen(tag::Create, GLsizei count, GLuint* names)
54  {
55  assert(names != nullptr);
56  OGLPLUS_GLFUNC(CreateFramebuffers)(count, names);
57  OGLPLUS_CHECK_SIMPLE(CreateFramebuffers);
58  }
59 #endif
60 
61  static void Delete(GLsizei count, GLuint* names)
62  {
63  assert(names != nullptr);
64  OGLPLUS_GLFUNC(DeleteFramebuffers)(count, names);
65  OGLPLUS_VERIFY_SIMPLE(DeleteFramebuffers);
66  }
67 
68  static GLboolean IsA(GLuint name)
69  {
70  assert(name != 0);
71  GLboolean result = OGLPLUS_GLFUNC(IsFramebuffer)(name);
72  OGLPLUS_VERIFY_SIMPLE(IsFramebuffer);
73  return result;
74  }
75 };
76 
78 template <>
79 class ObjBindingOps<tag::Framebuffer>
80 {
81 private:
82  static GLenum _binding_query(FramebufferTarget target);
83 protected:
84  static GLuint _binding(FramebufferTarget target);
85 public:
88 
90 
95  {
96  return FramebufferName(_binding(target));
97  }
98 
100 
104  static void Bind(
105  Target target,
106  FramebufferName framebuffer
107  )
108  {
109  OGLPLUS_GLFUNC(BindFramebuffer)(
110  GLenum(target),
111  GetGLName(framebuffer)
112  );
113  OGLPLUS_VERIFY(
114  BindFramebuffer,
115  ObjectError,
116  ObjectBinding(target)
117  );
118  }
119 };
120 
122 
125 template <>
127  : public FramebufferName
128  , public ObjBindingOps<tag::Framebuffer>
129 {
130 protected:
131  ObjCommonOps(void){ }
132 public:
134 
136 
140  void Bind(Target target) const
141  {
142  Bind(target, *this);
143  }
144 };
145 
147 
149 template <>
150 class ObjectOps<tag::ExplicitSel, tag::Framebuffer>
151  : public ObjZeroOps<tag::ExplicitSel, tag::Framebuffer>
152 {
153 protected:
154  ObjectOps(void){ }
155 public:
157  struct Property
158  {
160  typedef OneOf<
161  GLenum,
162  std::tuple<
166  >
168 
170  typedef OneOf<
171  GLenum,
172  std::tuple<
175  >
177 
180  };
181 
183 
193  {
194  GLenum result = OGLPLUS_GLFUNC(CheckFramebufferStatus)(
195  GLenum(target)
196  );
197  if(result == 0) OGLPLUS_CHECK(
198  CheckFramebufferStatus,
199  ObjectError,
200  ObjectBinding(target)
201  );
202  return FramebufferStatus(result);
203  }
204 
206 
213  static bool IsComplete(Target target)
214  {
215  return Status(target) == FramebufferStatus::Complete;
216  }
217 
218  static void HandleIncompleteError(Target target, FramebufferStatus status);
219 
221  static void Complete(Target target)
222  {
223  FramebufferStatus status = Status(target);
224  if(status != FramebufferStatus::Complete)
225  {
226  HandleIncompleteError(target, status);
227  }
228  }
229 
231 
243  static void AttachRenderbuffer(
244  Target target,
245  Property::Attachment attachment,
246  RenderbufferName renderbuffer
247  )
248  {
249  OGLPLUS_GLFUNC(FramebufferRenderbuffer)(
250  GLenum(target),
251  GLenum(attachment),
252  GL_RENDERBUFFER,
253  GetGLName(renderbuffer)
254  );
255  OGLPLUS_CHECK(
256  FramebufferRenderbuffer,
257  ObjectPairError,
258  Subject(renderbuffer).
259  ObjectBinding(target)
260  );
261  }
262 
264 
277  Target target,
278  FramebufferColorAttachmentNumber attachment_no,
279  RenderbufferName renderbuffer
280  )
281  {
282  OGLPLUS_GLFUNC(FramebufferRenderbuffer)(
283  GLenum(target),
284  GL_COLOR_ATTACHMENT0 + GLuint(attachment_no),
285  GL_RENDERBUFFER,
286  GetGLName(renderbuffer)
287  );
288  OGLPLUS_CHECK(
289  FramebufferRenderbuffer,
290  ObjectPairError,
291  Subject(renderbuffer).
292  ObjectBinding(target)
293  );
294  }
295 
296 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_2
297 
311  static void AttachTexture(
312  Target target,
313  Property::Attachment attachment,
314  TextureName texture,
315  GLint level
316  )
317  {
318  OGLPLUS_GLFUNC(FramebufferTexture)(
319  GLenum(target),
320  GLenum(attachment),
321  GetGLName(texture),
322  level
323  );
324  OGLPLUS_CHECK(
325  FramebufferTexture,
326  ObjectPairError,
327  Subject(texture).
328  ObjectBinding(target).
329  Index(level)
330  );
331  }
332 
334 
346  static void AttachColorTexture(
347  Target target,
348  FramebufferColorAttachmentNumber attachment_no,
349  TextureName texture,
350  GLint level
351  )
352  {
353  OGLPLUS_GLFUNC(FramebufferTexture)(
354  GLenum(target),
355  GL_COLOR_ATTACHMENT0 + GLenum(attachment_no),
356  GetGLName(texture),
357  level
358  );
359  OGLPLUS_CHECK(
360  FramebufferTexture,
361  ObjectPairError,
362  Subject(texture).
363  ObjectBinding(target).
364  Index(level)
365  );
366  }
367 #endif
368 
369 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_0
370 
383  static void AttachTexture1D(
384  Target target,
385  Property::Attachment attachment,
386  TextureTarget textarget,
387  TextureName texture,
388  GLint level
389  )
390  {
391  OGLPLUS_GLFUNC(FramebufferTexture1D)(
392  GLenum(target),
393  GLenum(attachment),
394  GLenum(textarget),
395  GetGLName(texture),
396  level
397  );
398  OGLPLUS_CHECK(
399  FramebufferTexture1D,
400  ObjectPairError,
401  Subject(texture).
402  ObjectBinding(target).
403  Index(level)
404  );
405  }
406 #endif
407 
409 
421  static void AttachTexture2D(
422  Target target,
423  Property::Attachment attachment,
424  TextureTarget textarget,
425  TextureName texture,
426  GLint level
427  )
428  {
429  OGLPLUS_GLFUNC(FramebufferTexture2D)(
430  GLenum(target),
431  GLenum(attachment),
432  GLenum(textarget),
433  GetGLName(texture),
434  level
435  );
436  OGLPLUS_CHECK(
437  FramebufferTexture2D,
438  ObjectPairError,
439  Subject(texture).
440  ObjectBinding(target).
441  Index(level)
442  );
443  }
444 
445 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_0
446 
459  static void AttachTexture3D(
460  Target target,
461  Property::Attachment attachment,
462  TextureTarget textarget,
463  TextureName texture,
464  GLint level,
465  GLint layer
466  )
467  {
468  OGLPLUS_GLFUNC(FramebufferTexture3D)(
469  GLenum(target),
470  GLenum(attachment),
471  GLenum(textarget),
472  GetGLName(texture),
473  level,
474  layer
475  );
476  OGLPLUS_CHECK(
477  FramebufferTexture3D,
478  ObjectPairError,
479  Subject(texture).
480  ObjectBinding(target).
481  Index(level)
482  );
483  }
484 #endif
485 
487 
499  static void AttachTextureLayer(
500  Target target,
501  Property::Attachment attachment,
502  TextureName texture,
503  GLint level,
504  GLint layer
505  )
506  {
507  OGLPLUS_GLFUNC(FramebufferTextureLayer)(
508  GLenum(target),
509  GLenum(attachment),
510  GetGLName(texture),
511  level,
512  layer
513  );
514  OGLPLUS_CHECK(
515  FramebufferTextureLayer,
516  ObjectPairError,
517  Subject(texture).
518  ObjectBinding(target).
519  Index(level)
520  );
521  }
522 
523 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_4_3 || GL_ARB_invalidate_subdata
524 
530  static void Invalidate(
531  Target target,
532  const EnumArray<Property::Buffer>& buffers
533  )
534  {
535  OGLPLUS_GLFUNC(InvalidateFramebuffer)(
536  GLenum(target),
537  buffers.Count(),
538  buffers.Values()
539  );
540  OGLPLUS_CHECK(
541  InvalidateFramebuffer,
542  ObjectError,
543  ObjectBinding(target)
544  );
545  }
546 
548 
553  static void Invalidate(
554  Target target,
555  GLsizei count,
556  const Property::Buffer* buffers
557  )
558  {
559  Invalidate(
560  target,
561  EnumArray<Property::Buffer>(count, buffers)
562  );
563  }
564 
566 
571  static void Invalidate(
572  Target target,
573  const EnumArray<Property::Buffer>& buffers,
574  GLint x,
575  GLint y,
576  GLsizei width,
577  GLsizei height
578  )
579  {
580  OGLPLUS_GLFUNC(InvalidateSubFramebuffer)(
581  GLenum(target),
582  buffers.Count(),
583  buffers.Values(),
584  x,
585  y,
586  width,
587  height
588  );
589  OGLPLUS_CHECK(
590  InvalidateSubFramebuffer,
591  ObjectError,
592  ObjectBinding(target)
593  );
594  }
595 
597 
602  static void Invalidate(
603  Target target,
604  GLsizei count,
605  const Property::Buffer* buffers,
606  GLint x,
607  GLint y,
608  GLsizei width,
609  GLsizei height
610  )
611  {
612  Invalidate(
613  target,
614  EnumArray<Property::Buffer>(count, buffers),
615  x,
616  y,
617  width,
618  height
619  );
620  }
621 #endif
622 };
623 
625 typedef ObjectOps<tag::ExplicitSel, tag::Framebuffer>
627 
630 
631 // Helper class for syntax-sugar operators
632 struct FramebufferTargetAndAttch
633 {
634  FramebufferTarget target;
635 
636  typedef FramebufferOps::Property::Attachment Attachment;
637  Attachment attachment;
638 
639  FramebufferTargetAndAttch(FramebufferTarget& t, Attachment a)
640  : target(t)
641  , attachment(a)
642  { }
643 };
644 
645 // syntax sugar operators
646 inline FramebufferTargetAndAttch operator | (
647  FramebufferTarget target,
648  FramebufferOps::Property::Attachment attachment
649 )
650 {
651  return FramebufferTargetAndAttch(target, attachment);
652 }
653 
654 inline FramebufferTargetAndAttch operator << (
655  FramebufferTarget target,
656  FramebufferOps::Property::Attachment attachment
657 )
658 {
659  return FramebufferTargetAndAttch(target, attachment);
660 }
661 
662 // Bind
663 inline FramebufferTarget operator << (
664  const FramebufferOps& fbo,
665  FramebufferTarget target
666 )
667 {
668  fbo.Bind(target);
669  return target;
670 }
671 
672 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_2
673 // AttachTexture
674 inline FramebufferTarget operator << (
675  FramebufferTargetAndAttch taa,
676  TextureName tex
677 )
678 {
680  taa.target,
681  taa.attachment,
682  tex,
683  0
684  );
685  return taa.target;
686 }
687 #endif
688 
689 // AttachRenderbuffer
690 inline FramebufferTarget operator << (
691  FramebufferTargetAndAttch taa,
692  RenderbufferName rbo
693 )
694 {
696  taa.target,
697  taa.attachment,
698  rbo
699  );
700  return taa.target;
701 }
702 
703 // Complete
704 inline FramebufferTarget operator << (
705  FramebufferTarget target,
706  FramebufferComplete
707 )
708 {
709  FramebufferOps::Complete(target);
710  return target;
711 }
712 
714 
717 typedef ObjectZero<ObjZeroOps<tag::ExplicitSel, tag::Framebuffer>>
719 
720 inline FramebufferTarget operator << (
721  DefaultFramebuffer dfb,
722  FramebufferTarget target
723 )
724 {
725  dfb.Bind(target);
726  return target;
727 }
728 
730 
733 typedef Object<FramebufferOps> Framebuffer;
734 
735 } // namespace oglplus
736 
737 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
738 #include <oglplus/framebuffer.ipp>
739 #endif // OGLPLUS_LINK_LIBRARY
740 
741 #endif // include guard
void Bind(Target target) const
Binds this framebuffer to the specified target.
Definition: framebuffer.hpp:140
FramebufferStatus
Framebuffer status enumeration.
Definition: framebuffer_status.hpp:24
ObjectOps< tag::ExplicitSel, tag::Framebuffer > FramebufferOps
Framebuffer operations with explicit selector.
Definition: framebuffer.hpp:626
OneOf< GLenum, std::tuple< FramebufferBuffer, FramebufferAttachment, FramebufferColorAttachment > > Buffer
Buffer of default FB or attachment of a FBO.
Definition: framebuffer.hpp:167
static void AttachColorTexture(Target target, FramebufferColorAttachmentNumber attachment_no, TextureName texture, GLint level)
Attach a texture to the color attachment point of target.
Definition: framebuffer.hpp:346
Type for the framebuffer color attachment (implementation-dependent) number.
Definition: framebuffer_attachment.hpp:23
static void AttachRenderbuffer(Target target, Property::Attachment attachment, RenderbufferName renderbuffer)
Attach a renderbuffer to the attachment point of target.
Definition: framebuffer.hpp:243
FramebufferAttachment
Framebuffer object attachment points.
Definition: framebuffer_attachment.hpp:56
Framebuffer exceptions.
OneOf< GLenum, std::tuple< FramebufferAttachment, FramebufferColorAttachment > > Attachment
Attachment of a Framebuffer.
Definition: framebuffer.hpp:176
Framebuffer bind target enumerations.
Generic OpenGL object wrapper.
ObjectZero< ObjZeroOps< tag::ExplicitSel, tag::Framebuffer > > DefaultFramebuffer
An oglplus_object encapsulating the default framebuffer functionality.
Definition: framebuffer.hpp:718
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
Framebuffer status enumeration.
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
Helper class used with syntax-sugar operators.
Definition: framebuffer.hpp:629
static bool IsComplete(Target target)
Returns true if the framebuffer is complete.
Definition: framebuffer.hpp:213
static FramebufferStatus Status(Target target)
Checks the status of the framebuffer.
Definition: framebuffer.hpp:192
static void AttachTexture1D(Target target, Property::Attachment attachment, TextureTarget textarget, TextureName texture, GLint level)
Attach a 1D texture to the attachment point of target.
Definition: framebuffer.hpp:383
FramebufferStatus Status
Status of a Framebuffer.
Definition: framebuffer.hpp:179
Helper macro for optional checking of availability of GL function.
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
static void Complete(Target target)
Throws an exception if the framebuffer is not complete.
Definition: framebuffer.hpp:221
FramebufferTarget Target
Framebuffer bind targets.
Definition: framebuffer.hpp:87
TextureTarget
Texture bind and image specification targets.
Definition: texture_target.hpp:27
Stores a value having one of the listed types in a common representation.
Definition: one_of.hpp:60
static void Bind(Target target, FramebufferName framebuffer)
Binds the specified framebuffer to the specified target.
Definition: framebuffer.hpp:104
static void Invalidate(Target target, GLsizei count, const Property::Buffer *buffers)
Invalidates the specified attachments or buffers of the Framebuffer.
Definition: framebuffer.hpp:553
FramebufferBuffer
Default framebuffer buffers.
Definition: framebuffer_attachment.hpp:40
static void AttachColorRenderbuffer(Target target, FramebufferColorAttachmentNumber attachment_no, RenderbufferName renderbuffer)
Attach a renderbuffer to the color attachment_no of target.
Definition: framebuffer.hpp:276
static void AttachTexture2D(Target target, Property::Attachment attachment, TextureTarget textarget, TextureName texture, GLint level)
Attach a 2D texture to the attachment point of target.
Definition: framebuffer.hpp:421
static FramebufferName Binding(Target target)
Returns the current Framebuffer bound to specified target.
Definition: framebuffer.hpp:94
static void AttachTexture3D(Target target, Property::Attachment attachment, TextureTarget textarget, TextureName texture, GLint level, GLint layer)
Attach a 3D texture to the attachment point of target.
Definition: framebuffer.hpp:459
Exception class for GL object-related errors.
Definition: object.hpp:24
FramebufferTarget
Framebuffer bind target.
Definition: framebuffer_target.hpp:24
Implements operations applicable to any object and any operation kind.
Definition: fwd.hpp:151
static void Invalidate(Target target, const EnumArray< Property::Buffer > &buffers)
Invalidates the specified attachments or buffers of the Framebuffer.
Definition: framebuffer.hpp:530
static void Invalidate(Target target, const EnumArray< Property::Buffer > &buffers, GLint x, GLint y, GLsizei width, GLsizei height)
Invalidates parts of attachments or buffers of the Framebuffer.
Definition: framebuffer.hpp:571
static void AttachTextureLayer(Target target, Property::Attachment attachment, TextureName texture, GLint level, GLint layer)
Attach a texture layer to the attachment point of target.
Definition: framebuffer.hpp:499
OpenGL Framebuffer attachment enumerations.
Object< FramebufferOps > Framebuffer
An oglplus_object encapsulating the framebuffer object functionality.
Definition: framebuffer.hpp:733
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
static void AttachTexture(Target target, Property::Attachment attachment, TextureName texture, GLint level)
Attach a texture to the attachment point of target.
Definition: framebuffer.hpp:311
static void Invalidate(Target target, GLsizei count, const Property::Buffer *buffers, GLint x, GLint y, GLsizei width, GLsizei height)
Invalidates parts of attachments or buffers of the Framebuffer.
Definition: framebuffer.hpp:602
Texture target enumeration.
Variant helper class used mostly with enums.
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).