Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Scissor.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Scissor_INCLUDE_ONCE
33 #define Scissor_INCLUDE_ONCE
34 
35 #include <vlCore/Object.hpp>
36 #include <vlCore/Rect.hpp>
37 #include <vlGraphics/Viewport.hpp>
38 
39 namespace vl
40 {
47  class Scissor: public Object
48  {
50 
51  public:
52  Scissor() {}
53 
54  Scissor(int x, int y, int width, int height)
55  {
56  setScissor(x,y,width,height);
57  }
61  void enable(const Viewport* viewport) const
62  {
63  RectI r = viewport->rect().intersected(scissorRect());
64  glEnable(GL_SCISSOR_TEST);
65  if (r.isNull())
66  glScissor(0,0,0,0);
67  else
68  glScissor(r.x(), r.y(), r.width(), r.height());
69  }
73  void disable()
74  {
75  glDisable(GL_SCISSOR_TEST);
76  }
77 
83  void setScissor(int x, int y, int width, int height) { setScissor( RectI(x,y,width,height) ); }
89  void setScissor(const RectI& scissor) { mScissor = scissor; }
93  const RectI& scissorRect() const { return mScissor; }
94 
98  bool operator<(const Scissor& other) const
99  {
100  return mScissor < other.mScissor;
101  }
102 
103  protected:
105  };
106 }
107 
108 #endif
void disable()
Disables the scissor test.
Definition: Scissor.hpp:73
The RectI class represents a 2D rectangular area using int precision.
Definition: Rect.hpp:163
RectI mScissor
Definition: Scissor.hpp:104
const RectI & scissorRect() const
Returns the scissor box.
Definition: Scissor.hpp:93
bool isNull() const
Definition: Rect.hpp:83
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
T height() const
Definition: Rect.hpp:72
T width() const
Definition: Rect.hpp:71
The base class for all the reference counted objects.
Definition: Object.hpp:158
T x() const
Definition: Rect.hpp:69
Implements the viewport and clearing settings associated to a Camera.
Definition: Viewport.hpp:51
Rect intersected(const Rect &other) const
Definition: Rect.hpp:86
Scissor(int x, int y, int width, int height)
Definition: Scissor.hpp:54
bool operator<(const Scissor &other) const
Defines a sort of lexicographic sorting that make possible the use of the Scissor class with STL cont...
Definition: Scissor.hpp:98
T y() const
Definition: Rect.hpp:70
The Scissor class wraps the OpenGL function glScissor(), see http://www.opengl.org/sdk/docs/man/xhtml...
Definition: Scissor.hpp:47
void enable(const Viewport *viewport) const
Enables the scissor test on the area specified by scissorRect() clipped against the given Viewport...
Definition: Scissor.hpp:61
RectI rect() const
Returns the rectangular area that defines the viewport computed as RectI(x(), y(), x()+width()-1, y()+height()-1).
Definition: Viewport.hpp:77
void setScissor(int x, int y, int width, int height)
Defines the scissor box.
Definition: Scissor.hpp:83
void setScissor(const RectI &scissor)
Defines the scissor box.
Definition: Scissor.hpp:89