| 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_POLYGONOFFSET |
|---|
| 15 | #define OSG_POLYGONOFFSET 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/StateAttribute> |
|---|
| 18 | |
|---|
| 19 | #ifndef GL_POLYGON_OFFSET_LINE |
|---|
| 20 | #define GL_POLYGON_OFFSET_LINE 0x2A02 |
|---|
| 21 | #define GL_POLYGON_OFFSET_POINT 0x2A01 |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | namespace osg { |
|---|
| 25 | |
|---|
| 26 | /** PolygonOffset - encapsulates the OpenGL glPolygonOffset state.*/ |
|---|
| 27 | class OSG_EXPORT PolygonOffset : public StateAttribute |
|---|
| 28 | { |
|---|
| 29 | public : |
|---|
| 30 | |
|---|
| 31 | PolygonOffset(); |
|---|
| 32 | |
|---|
| 33 | PolygonOffset(float factor, float units); |
|---|
| 34 | |
|---|
| 35 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 36 | PolygonOffset(const PolygonOffset& po,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 37 | StateAttribute(po,copyop), |
|---|
| 38 | _factor(po._factor), |
|---|
| 39 | _units(po._units) {} |
|---|
| 40 | |
|---|
| 41 | META_StateAttribute(osg, PolygonOffset, POLYGONOFFSET); |
|---|
| 42 | |
|---|
| 43 | /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ |
|---|
| 44 | virtual int compare(const StateAttribute& sa) const |
|---|
| 45 | { |
|---|
| 46 | // check the types are equal and then create the rhs variable |
|---|
| 47 | // used by the COMPARE_StateAttribute_Parameter macros below. |
|---|
| 48 | COMPARE_StateAttribute_Types(PolygonOffset,sa) |
|---|
| 49 | |
|---|
| 50 | // compare each parameter in turn against the rhs. |
|---|
| 51 | COMPARE_StateAttribute_Parameter(_factor) |
|---|
| 52 | COMPARE_StateAttribute_Parameter(_units) |
|---|
| 53 | |
|---|
| 54 | return 0; // passed all the above comparison macros, must be equal. |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const |
|---|
| 58 | { |
|---|
| 59 | usage.usesMode(GL_POLYGON_OFFSET_FILL); |
|---|
| 60 | #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) |
|---|
| 61 | usage.usesMode(GL_POLYGON_OFFSET_LINE); |
|---|
| 62 | usage.usesMode(GL_POLYGON_OFFSET_POINT); |
|---|
| 63 | #endif |
|---|
| 64 | return true; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | inline void setFactor(float factor) { _factor = factor; } |
|---|
| 68 | inline float getFactor() const { return _factor; } |
|---|
| 69 | |
|---|
| 70 | inline void setUnits(float units) { _units = units; } |
|---|
| 71 | inline float getUnits() const { return _units; } |
|---|
| 72 | |
|---|
| 73 | virtual void apply(State& state) const; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | static void setFactorMultiplier(float multiplier); |
|---|
| 77 | static float getFactorMultiplier(); |
|---|
| 78 | |
|---|
| 79 | static void setUnitsMultiplier(float multiplier); |
|---|
| 80 | static float getUnitsMultiplier(); |
|---|
| 81 | |
|---|
| 82 | static bool areFactorAndUnitsMultipliersSet(); |
|---|
| 83 | |
|---|
| 84 | /** Checks with the OpenGL driver to try and pick multiplier appropriate for the hardware. |
|---|
| 85 | note, requires a valid graphics context to be current. */ |
|---|
| 86 | static void setFactorAndUnitsMultipliersUsingBestGuessForDriver(); |
|---|
| 87 | |
|---|
| 88 | protected : |
|---|
| 89 | |
|---|
| 90 | virtual ~PolygonOffset(); |
|---|
| 91 | |
|---|
| 92 | float _factor; |
|---|
| 93 | float _units; |
|---|
| 94 | |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | #endif |
|---|