Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfStencilBufferMode.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2008, 2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include "glfStencilBufferMode.hh"
26 #include "glfException.hh"
27 
28 #include <limits>
29 
30 #ifdef WIN32
31 #undef max
32 #endif
33 
34 using namespace BIAS;
35 using namespace std;
36 
38 
40 {
41  enableTest_ = GL_FALSE;
42  stencilMask_ = numeric_limits<GLuint>::max();
43  stencilFunc_ = GL_ALWAYS;
44  referenceValue_ = 0;
45 
46  stencilFail_ = stencilPassZFail_ = stencilPassZPass_ = GL_KEEP;
47 }
48 
50 {
51  enableTest_ = enable ? GL_TRUE : GL_FALSE;
52 }
53 
55 {
56  stencilMask_ = mask;
57 }
58 
59 void glfStencilBufferMode::SetStencilFunc(GLenum comparisonFunc)
60 {
61  stencilFunc_ = comparisonFunc;
62 }
63 
64 void glfStencilBufferMode::SetReferenceValue(GLint referenceValue)
65 {
66  referenceValue_ = referenceValue;
67 }
68 
70 SetStencilOperation(GLenum stencilFail, GLenum stencilPassZFail, GLenum stencilPassZPass)
71 {
72  stencilFail_ = stencilFail;
73  stencilPassZFail_ = stencilPassZFail;
74  stencilPassZPass_ = stencilPassZPass;
75 }
76 
78 {
79  if (enableTest_) {
80  glEnable(GL_STENCIL_TEST);
81  glStencilFunc(stencilFunc_, referenceValue_, stencilMask_);
82  glStencilOp(stencilFail_, stencilPassZFail_, stencilPassZPass_);
83  } else {
84  glDisable(GL_STENCIL_TEST);
85  }
86 
87  GLF_THROW_ON_OPENGL_ERROR;
88 }
void SetStencilTest(bool enable)
Sets whether to use stencil buffer tests.
Defines the usage of the stencil buffer.
void SetStencilOperation(GLenum stencilFail, GLenum stencilPassZFail, GLenum stencilPassZPass)
Defines the operation of the stencil test.
void SetReferenceValue(GLint referenceValue)
Sets the reference value for the comprison function.
void SetStencilMask(GLuint mask)
Sets the mask of bits that shall be considered for stencil test from the stencil mask and the stencil...
void Bind() const
Binds the stencil buffer mode.
void SetStencilFunc(GLenum comparisonFunc)
Sets the stencil buffer comparison function.
static const glfStencilBufferMode DEFAULT
The default stencil buffer mode.