| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_Scissor |
|---|
| 15 | #define OSG_Scissor 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/StateAttribute> |
|---|
| 18 | |
|---|
| 19 | namespace osg { |
|---|
| 20 | |
|---|
| 21 | /** Encapsulate OpenGL glScissor. */ |
|---|
| 22 | class OSG_EXPORT Scissor : public StateAttribute |
|---|
| 23 | { |
|---|
| 24 | public : |
|---|
| 25 | Scissor(); |
|---|
| 26 | |
|---|
| 27 | Scissor(int x,int y,int width,int height): |
|---|
| 28 | _x(x), |
|---|
| 29 | _y(y), |
|---|
| 30 | _width(width), |
|---|
| 31 | _height(height) {} |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /** Copy constructor using CopyOp to manage deep vs shallow copy. */ |
|---|
| 35 | Scissor(const Scissor& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 36 | StateAttribute(vp,copyop), |
|---|
| 37 | _x(vp._x), |
|---|
| 38 | _y(vp._y), |
|---|
| 39 | _width(vp._width), |
|---|
| 40 | _height(vp._height) {} |
|---|
| 41 | |
|---|
| 42 | META_StateAttribute(osg, Scissor, SCISSOR); |
|---|
| 43 | |
|---|
| 44 | /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| 45 | virtual int compare(const StateAttribute& sa) const |
|---|
| 46 | { |
|---|
| 47 | // check the types are equal and then create the rhs variable |
|---|
| 48 | // used by the COMPARE_StateAttribute_Parameter macros below. |
|---|
| 49 | COMPARE_StateAttribute_Types(Scissor,sa) |
|---|
| 50 | |
|---|
| 51 | // compare each parameter in turn against the rhs. |
|---|
| 52 | COMPARE_StateAttribute_Parameter(_x) |
|---|
| 53 | COMPARE_StateAttribute_Parameter(_y) |
|---|
| 54 | COMPARE_StateAttribute_Parameter(_width) |
|---|
| 55 | COMPARE_StateAttribute_Parameter(_height) |
|---|
| 56 | |
|---|
| 57 | return 0; // passed all the above comparison macros, must be equal. |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const |
|---|
| 62 | { |
|---|
| 63 | usage.usesMode(GL_SCISSOR_TEST); |
|---|
| 64 | return true; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | inline void setScissor(int x,int y,int width,int height) |
|---|
| 68 | { |
|---|
| 69 | _x = x; |
|---|
| 70 | _y = y; |
|---|
| 71 | _width = width; |
|---|
| 72 | _height = height; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | void getScissor(int& x,int& y,int& width,int& height) const |
|---|
| 76 | { |
|---|
| 77 | x = _x; |
|---|
| 78 | y = _y; |
|---|
| 79 | width = _width; |
|---|
| 80 | height = _height; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | inline int& x() { return _x; } |
|---|
| 84 | inline int x() const { return _x; } |
|---|
| 85 | |
|---|
| 86 | inline int& y() { return _y; } |
|---|
| 87 | inline int y() const { return _y; } |
|---|
| 88 | |
|---|
| 89 | inline int& width() { return _width; } |
|---|
| 90 | inline int width() const { return _width; } |
|---|
| 91 | |
|---|
| 92 | inline int& height() { return _height; } |
|---|
| 93 | inline int height() const { return _height; } |
|---|
| 94 | |
|---|
| 95 | virtual void apply(State& state) const; |
|---|
| 96 | |
|---|
| 97 | protected: |
|---|
| 98 | |
|---|
| 99 | virtual ~Scissor(); |
|---|
| 100 | |
|---|
| 101 | int _x; |
|---|
| 102 | int _y; |
|---|
| 103 | int _width; |
|---|
| 104 | int _height; |
|---|
| 105 | |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | #endif |
|---|