diff --git a/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp b/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp index bf95dc0a7..44cd8cf4b 100644 --- a/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp +++ b/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/include/osg/Capability b/include/osg/Capability new file mode 100644 index 000000000..a195b1040 --- /dev/null +++ b/include/osg/Capability @@ -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 +#include + +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(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 diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 4aaaee96a..228db3658 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -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.*/ diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 275667358..db3c6dbdd 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -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 diff --git a/src/osg/Capability.cpp b/src/osg/Capability.cpp new file mode 100644 index 000000000..1a6bee7c4 --- /dev/null +++ b/src/osg/Capability.cpp @@ -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 +#include +#include + +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(); + if (extensions->glEnablei) + { + OSG_NOTICE<<"extensions->glEnablei("<<_capability<<", "<<_index<<")"<glEnablei(_capability, static_cast(_index)); + } + else + { + OSG_WARN<<"Warning: Enablei::apply(..) failed, Enablei is not support by OpenGL driver."<(); + if (extensions->glDisablei) + { + OSG_NOTICE<<"extensions->glDisablei("<<_capability<<", "<<_index<<")"<glDisablei(_capability, static_cast(_index)); + } + else + { + OSG_WARN<<"Warning: Enablei::apply(..) failed, Enablei is not support by OpenGL driver."<