Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Viewport.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 Viewport_INCLUDE_ONCE
33 #define Viewport_INCLUDE_ONCE
34 
36 #include <vlCore/Object.hpp>
37 #include <vlCore/Rect.hpp>
38 #include <vlCore/Vector4.hpp>
39 #include <vlCore/vlnamespace.hpp>
40 
41 namespace vl
42 {
43  //-----------------------------------------------------------------------------
44  // Viewport
45  //-----------------------------------------------------------------------------
52  {
54 
55  public:
56  Viewport();
57  Viewport(int x, int y, int w, int h);
58 
59  void activate() const;
60 
61  bool null() { return mWidth == 0 || mHeight == 0; }
62 
63  void set(int x, int y, int w, int h) { mX = x; mY = y; mWidth = w; mHeight = h; }
64  void setX(int x) { mX = x; }
65  int x() const { return mX; }
66  void setY(int y) { mY = y; }
67  int y() const { return mY; }
68  void setWidth(int width) { mWidth = width; }
69  int width() const { return mWidth; }
70  void setHeight(int height) { mHeight = height; }
71  int height() const { return mHeight; }
72  fvec2 center() const { return fvec2(mX + mWidth / 2.0f, mY + mHeight / 2.0f); }
73 
77  RectI rect() const { return RectI(x(),y(),width(),height()); }
78 
79  void setClearColor(float r, float g, float b, float a) { mClearColor = fvec4(r,g,b,a); }
80  void setClearColor(const fvec4& color) { mClearColor = color; }
81  const fvec4& clearColor() const { return mClearColor; }
82 
83  void setClearColorInt(int r, int g, int b, int a) { mClearColorInt = ivec4(r,g,b,a); }
84  void setClearColorInt(const ivec4& color) { mClearColorInt = color; }
85  const ivec4& clearColorInt() const { return mClearColorInt; }
86 
87  void setClearColorUInt(unsigned int r, unsigned int g, unsigned int b, unsigned int a) { mClearColorUInt = uvec4(r,g,b,a); }
88  void setClearColorUInt(const uvec4& color) { mClearColorUInt = color; }
89  const uvec4& clearColorUInt() const { return mClearColorUInt; }
90 
91  void setClearStencil(int stencil) { mClearStencil = stencil; }
92  int clearStencil() const { return mClearStencil; }
93 
94  void setClearDepth(real depth) { mClearDepth = depth; }
95  real clearDepth() const { return mClearDepth; }
96 
98  void setClearFlags(EClearFlags clear_flags) { mClearFlags = clear_flags; }
99  EClearFlags clearFlags() const { return mClearFlags; }
100 
101  void setClearColorMode(EClearColorMode mode) { mClearColorMode = mode; }
102  EClearColorMode clearColorMode() const { return mClearColorMode; }
103 
107  bool isPointInside(int x, int y, int framebuffer_height) const;
108 
113  void setScissorEnabled(bool enable) { mScissorEnabled = enable; }
114  bool isScissorEnabled() const { return mScissorEnabled; }
115 
116  protected:
120 
125  int mX;
126  int mY;
127  int mWidth;
128  int mHeight;
129 
131  };
132 }
133 
134 #endif
int y() const
Definition: Viewport.hpp:67
real mClearDepth
Definition: Viewport.hpp:121
void setClearStencil(int stencil)
Definition: Viewport.hpp:91
EClearColorMode mClearColorMode
Definition: Viewport.hpp:124
uvec4 mClearColorUInt
Definition: Viewport.hpp:119
Vector4< float > fvec4
A 4 components vector with float precision.
Definition: Vector4.hpp:279
The RectI class represents a 2D rectangular area using int precision.
Definition: Rect.hpp:163
void setClearColor(const fvec4 &color)
Definition: Viewport.hpp:80
void setClearColor(float r, float g, float b, float a)
Definition: Viewport.hpp:79
void setClearColorInt(int r, int g, int b, int a)
Definition: Viewport.hpp:83
void setClearColorInt(const ivec4 &color)
Definition: Viewport.hpp:84
Vector4< unsigned int > uvec4
A 4 components vector with unsigned int precision.
Definition: Vector4.hpp:277
bool null()
Definition: Viewport.hpp:61
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
fvec4 mClearColor
Definition: Viewport.hpp:117
fvec2 center() const
Definition: Viewport.hpp:72
Visualization Library main namespace.
void setClearColorUInt(unsigned int r, unsigned int g, unsigned int b, unsigned int a)
Definition: Viewport.hpp:87
Vector2< float > fvec2
A 2 components vector with float precision.
Definition: Vector2.hpp:282
EClearColorMode clearColorMode() const
Definition: Viewport.hpp:102
int height() const
Definition: Viewport.hpp:71
int width() const
Definition: Viewport.hpp:69
int mClearStencil
Definition: Viewport.hpp:122
Vector4< int > ivec4
A 4 components vector with int precision.
Definition: Vector4.hpp:275
The base class for all the reference counted objects.
Definition: Object.hpp:158
bool isScissorEnabled() const
Definition: Viewport.hpp:114
const uvec4 & clearColorUInt() const
Definition: Viewport.hpp:89
EClearFlags mClearFlags
Definition: Viewport.hpp:123
ivec4 mClearColorInt
Definition: Viewport.hpp:118
Implements the viewport and clearing settings associated to a Camera.
Definition: Viewport.hpp:51
void setClearDepth(real depth)
Definition: Viewport.hpp:94
int x() const
Definition: Viewport.hpp:65
EClearColorMode
void setClearColorUInt(const uvec4 &color)
Definition: Viewport.hpp:88
EClearFlags
real clearDepth() const
Definition: Viewport.hpp:95
void setWidth(int width)
Definition: Viewport.hpp:68
void setClearColorMode(EClearColorMode mode)
Definition: Viewport.hpp:101
void setScissorEnabled(bool enable)
If scissor setup is enabled (by default it is), then glScissor is called during activate().
Definition: Viewport.hpp:113
const ivec4 & clearColorInt() const
Definition: Viewport.hpp:85
int clearStencil() const
Definition: Viewport.hpp:92
const fvec4 & clearColor() const
Definition: Viewport.hpp:81
void setY(int y)
Definition: Viewport.hpp:66
bool mScissorEnabled
Definition: Viewport.hpp:130
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
Visualization Library&#39;s enums in the &#39;vl&#39; namespace.
void setX(int x)
Definition: Viewport.hpp:64
void setHeight(int height)
Definition: Viewport.hpp:70
EClearFlags clearFlags() const
Definition: Viewport.hpp:99
void setClearFlags(EClearFlags clear_flags)
Usually you want to use rather RendererAbstract::setClearFlags()
Definition: Viewport.hpp:98