Added osg::Capability and Cabibilityi base classes to wrap up glEnable/glDisable + glEnablei/glDisablei functionality, with osg::Enablei and osg::Disablei concrete implementations.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14564 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
457d41d385
commit
5efe60dcf5
@ -25,6 +25,7 @@
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/ColorMask>
|
||||
#include <osg/Material>
|
||||
#include <osg/Capability>
|
||||
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
@ -354,6 +355,12 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
// test for new glEnablei/glDisablei functionality.
|
||||
camera->getOrCreateStateSet()->setAttribute(new osg::Enablei(GL_BLEND, 0));
|
||||
camera->getOrCreateStateSet()->setAttribute(new osg::Disablei(GL_BLEND, 1));
|
||||
#endif
|
||||
|
||||
// we can also read back any of the targets as an image, modify this image and push it back
|
||||
if (useImage) {
|
||||
// which texture to get the image from
|
||||
|
170
include/osg/Capability
Normal file
170
include/osg/Capability
Normal file
@ -0,0 +1,170 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_ENABLEI
|
||||
#define OSG_ENABLEI 1
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class OSG_EXPORT Capability : public osg::StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
Capability();
|
||||
|
||||
Capability(GLenum capability):
|
||||
_capability(capability) {}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Capability(const Capability& cap,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
StateAttribute(cap, copyop),
|
||||
_capability(cap._capability) {}
|
||||
|
||||
META_Object(osg, Capability);
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// Check for equal types, then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Parameter macros below.
|
||||
COMPARE_StateAttribute_Types(Capability,sa)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_capability);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Return the Type identifier of the attribute's class type.*/
|
||||
virtual Type getType() const { return static_cast<Type>(CAPABILITY+_capability); }
|
||||
|
||||
void setCapability(GLenum capability) { _capability = capability; }
|
||||
|
||||
GLenum getCapability() const { return _capability; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Capability();
|
||||
|
||||
GLenum _capability;
|
||||
|
||||
};
|
||||
|
||||
/** Encapsulates glEnablei/glDisablei
|
||||
*/
|
||||
class OSG_EXPORT Capabilityi : public osg::Capability
|
||||
{
|
||||
public :
|
||||
|
||||
Capabilityi();
|
||||
|
||||
Capabilityi(GLenum capability, unsigned int buf):
|
||||
Capability(capability),
|
||||
_index(buf) {}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Capabilityi(const Capabilityi& cap,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Capability(cap,copyop),
|
||||
_index(cap._index) {}
|
||||
|
||||
META_Object(osg, Capabilityi);
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// Check for equal types, then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Parameter macros below.
|
||||
COMPARE_StateAttribute_Types(Capabilityi,sa)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_index);
|
||||
COMPARE_StateAttribute_Parameter(_capability);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Return the member identifier within the attribute's class type. Used for light number/clip plane number etc.*/
|
||||
virtual unsigned int getMember() const { return _index; }
|
||||
|
||||
/** Set the renderbuffer index of the Enablei. */
|
||||
void setIndex(unsigned int buf) { _index = buf; }
|
||||
|
||||
/** Get the renderbuffer index of the Enablei. */
|
||||
unsigned int getIndex() const { return _index; }
|
||||
|
||||
/** Encapsulates queries of extension availability, obtains extension function pointers. */
|
||||
struct OSG_EXPORT Extensions : public osg::Referenced
|
||||
{
|
||||
Extensions(unsigned int contextID);
|
||||
|
||||
void (GL_APIENTRY * glEnablei) (GLenum capability, GLuint buf);
|
||||
void (GL_APIENTRY * glDisablei) (GLenum capability, GLuint buf);
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Capabilityi();
|
||||
|
||||
unsigned int _index;
|
||||
|
||||
};
|
||||
|
||||
class OSG_EXPORT Enablei : public Capabilityi
|
||||
{
|
||||
public :
|
||||
|
||||
Enablei() {}
|
||||
|
||||
Enablei(unsigned int buf, GLenum capability):
|
||||
Capabilityi(buf, capability) {}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Enablei(const Enablei& ei,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Capabilityi(ei,copyop) {}
|
||||
|
||||
META_Object(osg, Capabilityi);
|
||||
|
||||
virtual void apply(State&) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Enablei() {}
|
||||
};
|
||||
|
||||
|
||||
class OSG_EXPORT Disablei : public Capabilityi
|
||||
{
|
||||
public :
|
||||
|
||||
Disablei() {}
|
||||
|
||||
Disablei(unsigned int buf, GLenum capability):
|
||||
Capabilityi(buf, capability) {}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Disablei(const Disablei& ei,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Capabilityi(ei,copyop) {}
|
||||
|
||||
META_Object(osg, Capabilityi);
|
||||
|
||||
virtual void apply(State&) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Disablei() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -197,7 +197,9 @@ class OSG_EXPORT StateAttribute : public Object
|
||||
|
||||
FRAME_BUFFER_OBJECT,
|
||||
|
||||
VERTEX_ATTRIB_DIVISOR
|
||||
VERTEX_ATTRIB_DIVISOR,
|
||||
|
||||
CAPABILITY = 100
|
||||
};
|
||||
|
||||
/** Simple pairing between an attribute type and the member within that attribute type group.*/
|
||||
|
@ -43,6 +43,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/Callback
|
||||
${HEADER_PATH}/Camera
|
||||
${HEADER_PATH}/CameraView
|
||||
${HEADER_PATH}/Capability
|
||||
${HEADER_PATH}/ClampColor
|
||||
${HEADER_PATH}/ClearNode
|
||||
${HEADER_PATH}/ClipNode
|
||||
@ -239,6 +240,7 @@ SET(TARGET_SRC
|
||||
BufferIndexBinding.cpp
|
||||
BufferObject.cpp
|
||||
Callback.cpp
|
||||
Capability.cpp
|
||||
Camera.cpp
|
||||
CameraView.cpp
|
||||
ClampColor.cpp
|
||||
|
72
src/osg/Capability.cpp
Normal file
72
src/osg/Capability.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osg/Capability>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/State>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
Capability::Capability():
|
||||
_capability(0)
|
||||
{
|
||||
}
|
||||
|
||||
Capability::~Capability()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Capabilityi::Extensions::Extensions(unsigned int contextID)
|
||||
{
|
||||
setGLExtensionFuncPtr(glEnablei, "glEnablei");
|
||||
setGLExtensionFuncPtr(glDisablei, "glDisablei");
|
||||
}
|
||||
|
||||
Capabilityi::Capabilityi():
|
||||
_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
Capabilityi::~Capabilityi()
|
||||
{
|
||||
}
|
||||
|
||||
void Enablei::apply(State& state) const
|
||||
{
|
||||
const Extensions* extensions = state.get<Extensions>();
|
||||
if (extensions->glEnablei)
|
||||
{
|
||||
OSG_NOTICE<<"extensions->glEnablei("<<_capability<<", "<<_index<<")"<<std::endl;
|
||||
extensions->glEnablei(_capability, static_cast<GLuint>(_index));
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN<<"Warning: Enablei::apply(..) failed, Enablei is not support by OpenGL driver."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Disablei::apply(State& state) const
|
||||
{
|
||||
const Extensions* extensions = state.get<Extensions>();
|
||||
if (extensions->glDisablei)
|
||||
{
|
||||
OSG_NOTICE<<"extensions->glDisablei("<<_capability<<", "<<_index<<")"<<std::endl;
|
||||
extensions->glDisablei(_capability, static_cast<GLuint>(_index));
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN<<"Warning: Enablei::apply(..) failed, Enablei is not support by OpenGL driver."<<std::endl;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user