1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSG_POLYGONOFFSET
15#define OSG_POLYGONOFFSET 1
17#include <osg/StateAttribute>
19#ifndef GL_POLYGON_OFFSET_LINE
20 #define GL_POLYGON_OFFSET_LINE 0x2A02
21 #define GL_POLYGON_OFFSET_POINT 0x2A01
26/** PolygonOffset - encapsulates the OpenGL glPolygonOffset state.*/
27class OSG_EXPORT PolygonOffset : public StateAttribute
33 PolygonOffset(float factor, float units);
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),
41 META_StateAttribute(osg, PolygonOffset, POLYGONOFFSET);
43 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
44 virtual int compare(const StateAttribute& sa) const
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)
50 // compare each parameter in turn against the rhs.
51 COMPARE_StateAttribute_Parameter(_factor)
52 COMPARE_StateAttribute_Parameter(_units)
54 return 0; // passed all the above comparison macros, must be equal.
57 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
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);
67 inline void setFactor(float factor) { _factor = factor; }
68 inline float getFactor() const { return _factor; }
70 inline void setUnits(float units) { _units = units; }
71 inline float getUnits() const { return _units; }
73 virtual void apply(State& state) const;
76 static void setFactorMultiplier(float multiplier);
77 static float getFactorMultiplier();
79 static void setUnitsMultiplier(float multiplier);
80 static float getUnitsMultiplier();
82 static bool areFactorAndUnitsMultipliersSet();
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();
90 virtual ~PolygonOffset();