OGLplus (0.52.0) a C++ wrapper for OpenGL

buffer_clearing.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_CONTEXT_BUFFER_CLEARING_1201040722_HPP
14 #define OGLPLUS_CONTEXT_BUFFER_CLEARING_1201040722_HPP
15 
16 #include <oglplus/glfunc.hpp>
18 #include <oglplus/color_buffer.hpp>
19 #include <oglplus/bitfield.hpp>
20 
21 namespace oglplus {
22 
24 
28 
29 namespace context {
30 
31 class BufferClearing;
32 
34 struct RGBAValue
35 {
36  // private implementation detail, do not use
37  GLfloat _v[4];
38 
40  GLfloat Red(void) const
41  {
42  return _v[0];
43  }
44 
46  GLfloat Green(void) const
47  {
48  return _v[1];
49  }
50 
52  GLfloat Blue(void) const
53  {
54  return _v[2];
55  }
56 
58  GLfloat Alpha(void) const
59  {
60  return _v[3];
61  }
62 };
63 
65 
77 class ClrBits
78 {
79 private:
80  GLbitfield _bits;
81 
82  GLbitfield _forward(void)
83  {
84  GLbitfield res = _bits;
85  _bits = 0;
86  return res;
87  }
88 
89  friend class BufferClearing;
90 
91 #if !OGLPLUS_NO_DELETED_FUNCTIONS
92  ClrBits(void) = delete;
93  ClrBits(const ClrBits&) = delete;
94 #else
95  ClrBits(void);
96  ClrBits(const ClrBits&);
97 #endif
98 
99  ClrBits(GLbitfield bit)
100  : _bits(bit)
101  { }
102 
103  inline ClrBits _make(GLbitfield bit)
104  {
105  return ClrBits(_forward() | bit);
106  }
107 public:
109 
113  inline ClrBits ColorBuffer(void)
114  {
115  return _make(GL_COLOR_BUFFER_BIT);
116  }
117 
119 
123  inline ClrBits DepthBuffer(void)
124  {
125  return _make(GL_DEPTH_BUFFER_BIT);
126  }
127 
129 
133  inline ClrBits StencilBuffer(void)
134  {
135  return _make(GL_STENCIL_BUFFER_BIT);
136  }
137 
138  inline ClrBits(ClrBits&& temp)
139  : _bits(temp._forward())
140  { }
141 
142  void DoIt(void) const
143  {
144  if(_bits)
145  {
146  OGLPLUS_GLFUNC(Clear)(_bits);
147  OGLPLUS_VERIFY_SIMPLE(Clear);
148  }
149  }
150 
151  void Dismiss(void)
152  {
153  _bits = 0;
154  }
155 
156  void operator()(void) const
157  {
158  DoIt();
159  }
160 
161  void operator()(bool dismiss)
162  {
163  DoIt();
164  if(dismiss) Dismiss();
165  }
166 
168 
172  inline ~ClrBits(void)
173  {
174  try{ DoIt(); }
175  catch(...){ }
176  }
177 };
178 
180 
184 {
185 public:
187 
193  static void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a)
194  {
195  OGLPLUS_GLFUNC(ClearColor)(r, g, b, a);
196  OGLPLUS_VERIFY_SIMPLE(ClearColor);
197  }
198 
199 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_0
200 
207  static void ClearDepth(GLclampd d)
208  {
209  OGLPLUS_GLFUNC(ClearDepth)(d);
210  OGLPLUS_VERIFY_SIMPLE(ClearDepth);
211  }
212 #else
213  static void ClearDepth(GLfloat d)
214  {
215  OGLPLUS_GLFUNC(ClearDepthf)(d);
216  OGLPLUS_VERIFY_SIMPLE(ClearDepthf);
217  }
218 #endif
219 
221 
227  static void ClearStencil(GLint s)
228  {
229  OGLPLUS_GLFUNC(ClearStencil)(s);
230  OGLPLUS_VERIFY_SIMPLE(ClearStencil);
231  }
232 
234 
256  static ClrBits Clear(void)
257  {
258  return ClrBits(0);
259  }
260 
262 
284  {
285  OGLPLUS_GLFUNC(Clear)(GLbitfield(bits));
286  OGLPLUS_VERIFY_SIMPLE(Clear);
287  }
288 
289 
291 
300  static void ClearColorBuffer(
301  GLint draw_buffer,
302  const GLint* value
303  )
304  {
305  OGLPLUS_GLFUNC(ClearBufferiv)(
306  GL_COLOR,
307  draw_buffer,
308  value
309  );
310  OGLPLUS_CHECK(
311  ClearBufferiv,
312  Error,
313  Index(draw_buffer)
314  );
315  }
316 
318 
326  static void ClearColorBuffer(
327  ColorBuffer buffer,
328  GLint draw_buffer,
329  const GLint* value
330  )
331  {
332  OGLPLUS_GLFUNC(ClearBufferiv)(
333  GLenum(buffer),
334  draw_buffer,
335  value
336  );
337  OGLPLUS_CHECK(
338  ClearBufferiv,
339  Error,
340  EnumParam(buffer).
341  Index(draw_buffer)
342  );
343  }
344 
346 
355  static void ClearColorBuffer(
356  GLint draw_buffer,
357  const GLuint* value
358  )
359  {
360  OGLPLUS_GLFUNC(ClearBufferuiv)(
361  GL_COLOR,
362  draw_buffer,
363  value
364  );
365  OGLPLUS_CHECK(
366  ClearBufferuiv,
367  Error,
368  Index(draw_buffer)
369  );
370  }
371 
373 
381  static void ClearColorBuffer(
382  ColorBuffer buffer,
383  GLint draw_buffer,
384  const GLuint* value
385  )
386  {
387  OGLPLUS_GLFUNC(ClearBufferuiv)(
388  GLenum(buffer),
389  draw_buffer,
390  value
391  );
392  OGLPLUS_CHECK(
393  ClearBufferuiv,
394  Error,
395  EnumParam(buffer).
396  Index(draw_buffer)
397  );
398  }
399 
401 
410  static void ClearColorBuffer(
411  GLint draw_buffer,
412  const GLfloat* value
413  )
414  {
415  OGLPLUS_GLFUNC(ClearBufferfv)(
416  GL_COLOR,
417  draw_buffer,
418  value
419  );
420  OGLPLUS_CHECK(
421  ClearBufferfv,
422  Error,
423  Index(draw_buffer)
424  );
425  }
426 
428 
436  static void ClearColorBuffer(
437  ColorBuffer buffer,
438  GLint draw_buffer,
439  const GLfloat* value
440  )
441  {
442  OGLPLUS_GLFUNC(ClearBufferfv)(
443  GLenum(buffer),
444  draw_buffer,
445  value
446  );
447  OGLPLUS_CHECK(
448  ClearBufferfv,
449  Error,
450  EnumParam(buffer).
451  Index(draw_buffer)
452  );
453  }
454 
456 
465  static void ClearDepthBuffer(GLfloat value)
466  {
467  OGLPLUS_GLFUNC(ClearBufferfv)(GL_DEPTH, 0, &value);
468  OGLPLUS_CHECK_SIMPLE(ClearBufferfv);
469  }
470 
472 
481  static void ClearStencilBuffer(GLint value)
482  {
483  OGLPLUS_GLFUNC(ClearBufferiv)(GL_STENCIL, 0, &value);
484  OGLPLUS_CHECK_SIMPLE(ClearBufferiv);
485  }
486 
488 
497  static void ClearStencilBuffer(GLfloat depth_value, GLint stencil_value)
498  {
499  OGLPLUS_GLFUNC(ClearBufferfi)(
500  GL_DEPTH_STENCIL,
501  0,
502  depth_value,
503  stencil_value
504  );
505  OGLPLUS_CHECK_SIMPLE(ClearBufferfi);
506  }
507 
509 
517  {
519  OGLPLUS_GLFUNC(GetFloatv)(GL_COLOR_CLEAR_VALUE, result._v);
520  OGLPLUS_VERIFY_SIMPLE(GetFloatv);
521  return result;
522  }
523 
525 
532  static GLfloat DepthClearValue(void)
533  {
534  GLfloat result;
535  OGLPLUS_GLFUNC(GetFloatv)(GL_DEPTH_CLEAR_VALUE, &result);
536  OGLPLUS_VERIFY_SIMPLE(GetFloatv);
537  return result;
538  }
539 
541 
548  static GLint ClearStencilValue(void)
549  {
550  GLint result;
551  OGLPLUS_GLFUNC(GetIntegerv)(GL_STENCIL_CLEAR_VALUE, &result);
552  OGLPLUS_VERIFY_SIMPLE(GetIntegerv);
553  return result;
554  }
555 };
556 
557 } // namespace context
558 } // namespace oglplus
559 
560 #endif // include guard
OpenGL Color buffer enumeration.
OpenGL bitfield-related helpers.
GLfloat Green(void) const
The green component.
Definition: buffer_clearing.hpp:46
static void Clear(Bitfield< oglplus::ClearBit > bits)
Clears buffers specified by the bits parameter.
Definition: buffer_clearing.hpp:283
static GLint ClearStencilValue(void)
Returns the value used for clearing of the stencil buffer.
Definition: buffer_clearing.hpp:548
ClrBits DepthBuffer(void)
Calling this member function causes the depth buffer to be cleared.
Definition: buffer_clearing.hpp:123
static void ClearColorBuffer(ColorBuffer buffer, GLint draw_buffer, const GLuint *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:381
static void ClearColorBuffer(ColorBuffer buffer, GLint draw_buffer, const GLfloat *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:436
static void ClearDepthBuffer(GLfloat value)
Clears the depth buffer.
Definition: buffer_clearing.hpp:465
~ClrBits(void)
The destructor does the actual clearing of the buffers.
Definition: buffer_clearing.hpp:172
static void ClearColorBuffer(GLint draw_buffer, const GLint *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:300
static void ClearStencilBuffer(GLfloat depth_value, GLint stencil_value)
Clears the depth and the stencil buffer.
Definition: buffer_clearing.hpp:497
static ClrBits Clear(void)
Clears buffers specified by calling functions of the returned object.
Definition: buffer_clearing.hpp:256
static void ClearColorBuffer(GLint draw_buffer, const GLuint *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:355
static void ClearDepth(GLclampd d)
Sets the clear depth.
Definition: buffer_clearing.hpp:207
This template serves as a wrapper for OpenGL bitfields.
Definition: bitfield.hpp:56
GLfloat Alpha(void) const
The alpha component.
Definition: buffer_clearing.hpp:58
static void ClearStencil(GLint s)
Sets the clear stencil buffer value.
Definition: buffer_clearing.hpp:227
BufferSelectBit ClearBit
Draw buffer clear bit enumeration.
Definition: buffer_clearing.hpp:27
static void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a)
Sets the clear color.
Definition: buffer_clearing.hpp:193
static void ClearColorBuffer(ColorBuffer buffer, GLint draw_buffer, const GLint *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:326
Helper macro for optional checking of availability of GL function.
static void ClearStencilBuffer(GLint value)
Clears the stencil buffer.
Definition: buffer_clearing.hpp:481
GLfloat Blue(void) const
The blue component.
Definition: buffer_clearing.hpp:52
Wrapper for the operations that are used to clear the draw buffers.
Definition: buffer_clearing.hpp:183
GLfloat Red(void) const
The red component.
Definition: buffer_clearing.hpp:40
static void ClearColorBuffer(GLint draw_buffer, const GLfloat *value)
Clears the specified color draw buffer.
Definition: buffer_clearing.hpp:410
Color, depth or stencil buffer selection bit enumeration.
Exception class for general OpenGL errors.
Definition: basic.hpp:43
Helper class used by BufferClearing::Clear()
Definition: buffer_clearing.hpp:77
static oglplus::context::RGBAValue ColorClearValue(void)
Returns the color value used for clearing of the color buffer.
Definition: buffer_clearing.hpp:516
ClrBits StencilBuffer(void)
Calling this member function causes the stencil buffer to be cleared.
Definition: buffer_clearing.hpp:133
static GLfloat DepthClearValue(void)
Returns the depth value used for clearing of the depth buffer.
Definition: buffer_clearing.hpp:532
ColorBuffer
Enumeration of color buffers for read/write operations.
Definition: color_buffer.hpp:28
ClrBits ColorBuffer(void)
Calling this member function causes the color buffer to be cleared.
Definition: buffer_clearing.hpp:113
BufferSelectBit
Buffer selection bit enumeration.
Definition: buffer_select_bit.hpp:29
Helper structure storing the clear color components.
Definition: buffer_clearing.hpp:34

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).