OGLplus (0.52.0) a C++ wrapper for OpenGL

buffer_masking.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_CONTEXT_BUFFER_MASKING_1201040722_HPP
14 #define OGLPLUS_CONTEXT_BUFFER_MASKING_1201040722_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/face_mode.hpp>
18 
19 namespace oglplus {
20 namespace context {
21 
23 struct RGBAMask
24 {
25  // private implementation detail, do not use
26  GLint _v[4];
27 
29  bool Red(void) const
30  {
31  return _v[0] == GL_TRUE;
32  }
33 
35  bool Green(void) const
36  {
37  return _v[1] == GL_TRUE;
38  }
39 
41  bool Blue(void) const
42  {
43  return _v[2] == GL_TRUE;
44  }
45 
47  bool Alpha(void) const
48  {
49  return _v[3] == GL_TRUE;
50  }
51 };
52 
54 
58 {
59 public:
61 
65  static void ColorMask(bool r, bool g, bool b, bool a)
66  {
67  OGLPLUS_GLFUNC(ColorMask)(
68  r ? GL_TRUE : GL_FALSE,
69  g ? GL_TRUE : GL_FALSE,
70  b ? GL_TRUE : GL_FALSE,
71  a ? GL_TRUE : GL_FALSE
72  );
73  OGLPLUS_VERIFY_SIMPLE(ColorMask);
74  }
75 
76 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_0
77 
82  static void ColorMask(GLuint buffer, bool r, bool g, bool b, bool a)
83  {
84  OGLPLUS_GLFUNC(ColorMaski)(
85  buffer,
86  r ? GL_TRUE : GL_FALSE,
87  g ? GL_TRUE : GL_FALSE,
88  b ? GL_TRUE : GL_FALSE,
89  a ? GL_TRUE : GL_FALSE
90  );
91  OGLPLUS_VERIFY(
92  ColorMaski,
93  Error,
94  Index(buffer)
95  );
96  }
97 #endif
98 
100 
104  static void DepthMask(bool mask)
105  {
106  OGLPLUS_GLFUNC(DepthMask)(mask ? GL_TRUE : GL_FALSE);
107  OGLPLUS_VERIFY_SIMPLE(DepthMask);
108  }
109 
111 
115  static void StencilMask(GLuint mask)
116  {
117  OGLPLUS_GLFUNC(StencilMask)(mask);
118  OGLPLUS_VERIFY_SIMPLE(StencilMask);
119  }
120 
122 
126  static void StencilMaskSeparate(Face face, GLuint mask)
127  {
128  OGLPLUS_GLFUNC(StencilMaskSeparate)(GLenum(face), mask);
129  OGLPLUS_VERIFY_SIMPLE(StencilMaskSeparate);
130  }
131 
133 
138  static oglplus::context::RGBAMask ColorWriteMask(GLuint buffer = 0)
139  {
141  OGLPLUS_GLFUNC(GetIntegeri_v)(
142  GL_COLOR_WRITEMASK,
143  buffer,
144  result._v
145  );
146  OGLPLUS_CHECK(
147  GetIntegeri_v,
148  Error,
149  Index(buffer)
150  );
151  return result;
152  }
153 
155 
160  static bool DepthWriteMask(void)
161  {
162  GLint result;
163  OGLPLUS_GLFUNC(GetIntegerv)(GL_DEPTH_WRITEMASK, &result);
164  OGLPLUS_VERIFY_SIMPLE(GetIntegerv);
165  return result == GL_TRUE;
166  }
167 
169 
175  static GLuint StencilWriteMask(bool backface = false)
176  {
177  GLint result;
178  OGLPLUS_GLFUNC(GetIntegerv)(
179  backface?
180  GL_STENCIL_BACK_WRITEMASK:
181  GL_STENCIL_WRITEMASK,
182  &result
183  );
184  OGLPLUS_VERIFY_SIMPLE(GetIntegerv);
185  return GLuint(result);
186  }
187 
188  static GLuint StencilWriteMask(Face face)
189  {
190  return StencilWriteMask(face == Face::Back);
191  }
192 };
193 
194 } // namespace context
195 } // namespace oglplus
196 
197 #endif // include guard
bool Blue(void) const
The blue component mask.
Definition: buffer_masking.hpp:41
static void DepthMask(bool mask)
Sets the depth mask.
Definition: buffer_masking.hpp:104
static oglplus::context::RGBAMask ColorWriteMask(GLuint buffer=0)
Returns the value of color buffer write mask.
Definition: buffer_masking.hpp:138
static GLuint StencilWriteMask(bool backface=false)
Returns the value of stencil write mask.
Definition: buffer_masking.hpp:175
static void ColorMask(bool r, bool g, bool b, bool a)
Sets the color mask.
Definition: buffer_masking.hpp:65
static void StencilMaskSeparate(Face face, GLuint mask)
Sets the stencil mask separately for front and back faces.
Definition: buffer_masking.hpp:126
bool Alpha(void) const
The alpha component mask.
Definition: buffer_masking.hpp:47
Face
Polygon facing enumeration.
Definition: face_mode.hpp:34
OpenGL face type-related enumeration.
Helper macro for optional checking of availability of GL function.
bool Red(void) const
The red component mask.
Definition: buffer_masking.hpp:29
static bool DepthWriteMask(void)
Returns the value of depth buffer write mask.
Definition: buffer_masking.hpp:160
bool Green(void) const
The green component mask.
Definition: buffer_masking.hpp:35
Wrappers for operations for fine control of buffer updates.
Definition: buffer_masking.hpp:57
Exception class for general OpenGL errors.
Definition: basic.hpp:43
Helper structure storing the clear color component mask.
Definition: buffer_masking.hpp:23
static void StencilMask(GLuint mask)
Sets the stencil mask.
Definition: buffer_masking.hpp:115
static void ColorMask(GLuint buffer, bool r, bool g, bool b, bool a)
Sets the color mask for a particular buffer.
Definition: buffer_masking.hpp:82

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