Discussion:
[osg-users] Problems porting from osg-3.4.0 to osg-3.6.0
Herman Varma
2018-09-12 15:29:34 UTC
Permalink
Hello I am having trouble porting Ben Discoe’s VTP software from openSceneGraph-3.4.0 to osg-3.6.2

The problem lies in implementing the macro to replace META_object in shadowTechnique.h as depicted below.
. Can someone point out where my problem is.

/** CSimpleInterimShadowTechnique provides an implementation of a depth map shadow tuned to the needs of VTP.*/
class CSimpleInterimShadowTechnique : public osgShadow::ShadowTechnique
{
public:

// working ********************** in openSceneGraph-3.4.0
// CSimpleInterimShadowTechnique();
// CSimpleInterimShadowTechnique(const
// CSimpleInterimShadowTechnique& es, const osg::CopyOp&
// copyop=osg::CopyOp::SHALLOW_COPY);
// META_Object(osgShadow, CSimpleInterimShadowTechnique);
//***********************************************************

// Macro not working *****************in openSceneGraph-3.6.2
CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const CSimpleInterimShadowTechnique*>(obj) != NULL; } \
virtual const char* libraryName() const { return "osgShadow"; }\
virtual const char* className() const { return "CSimpleInterimShadowTechnique"; }


//**************************************************************

In the new implementation I am getting a C2259 error

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): error C2259: 'CSimpleInterimShadowTechnique': cannot instantiate abstract class

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: due to following members:

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'osg::Object *osg::Object::cloneType(void) const': is abstract

2>c:\apis\openscenegraph-3.6.2\build\include\osg\object(80): note: see declaration of 'osg::Object::cloneType'

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'osg::Object *osg::Object::clone(const osg::CopyOp &) const': is abstract

2>c:\apis\openscenegraph-3.6.2\build\include\osg\object(84): note: see declaration of 'osg::Object::clone'

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'void osgShadow::ShadowTechnique::resizeGLObjectBuffers(unsigned int)': is abstract

2>c:\apis\openscenegraph-3.6.2\build\include\osgshadow\shadowtechnique(66): note: see declaration of 'osgShadow::ShadowTechnique::resizeGLObjectBuffers'

2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'void osgShadow::ShadowTechnique::releaseGLObjects(osg::State *) const': is abstract

2>c:\apis\openscenegraph-3.6.2\build\include\osgshadow\shadowtechnique(71): note: see declaration of 'osgShadow::ShadowTechnique::releaseGLObjects'

The area where the error manifests is in this section of nodeOSG.cpp

//////////////////////////////////////////////////////////////////////
// vtShadow
//

vtShadow::vtShadow(const int ShadowTextureUnit, int LightNumber) :
m_ShadowTextureUnit(ShadowTextureUnit), m_LightNumber(LightNumber)
{
setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
setCastsShadowTraversalMask(CastsShadowTraversalMask);

#if VTLISPSM
osg::ref_ptr<CLightSpacePerspectiveShadowTechnique> pShadowTechnique = new CLightSpacePerspectiveShadowTechnique;
// No need to set the BaseTextureUnit as the default of zero is OK for us
// But the ShadowTextureUnit might be different (default 1)
pShadowTechnique->setShadowTextureUnit(m_ShadowTextureUnit);
pShadowTechnique->setLightNumber(m_LightNumber);
#else
//errorC2259 cannot instantiate abstract class in openSceneGraph-3.6.2
//statement working in osg-3.4.0
osg::ref_ptr<CSimpleInterimShadowTechnique> pShadowTechnique = new CSimpleInterimShadowTechnique;//*****************************Error here
#endif

#if !VTLISPSM
#if VTDEBUGSHADOWS
// add some instrumentation
pShadowTechnique->m_pParent = this;
#endif

pShadowTechnique->SetLightNumber(LightNumber);
pShadowTechnique->SetShadowTextureUnit(m_ShadowTextureUnit);
pShadowTechnique->SetShadowSphereRadius(50.0);
#endif
setShadowTechnique(pShadowTechnique.get());

SetOsgNode(this);
}

Help would be appreciated


Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74726#74726
Robert Osfield
2018-09-13 07:11:35 UTC
Permalink
Hi Herman,

To make sure that shadow techniques properly handling applications
opening new windows and properly handle clean up they need to
implement the resizeGLObjectBuffers(..) and releaseGLObjects(..)
methods. In 3.6.x to ensure this is done these methods are pure
virtual forcing the subclasses to implement them. The ShadowTechnique
implementation looks like:

/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize) = 0;

/** If State is non-zero, this function releases any
associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const = 0;

META_Object can only be used with concrete classes so you can't use it
in this for ShadowTechnique.

For the custom ShadowTechnique you simply need to provide
resizeGLObjectBuffers(..) and releaseGLObjects(..). To see what they
would need to be have a look at the various ShadowTechnique subclasses
in src/osgShadow.

Cheers,
Robert.
Post by Herman Varma
Hello I am having trouble porting Ben Discoe’s VTP software from openSceneGraph-3.4.0 to osg-3.6.2
The problem lies in implementing the macro to replace META_object in shadowTechnique.h as depicted below.
. Can someone point out where my problem is.
/** CSimpleInterimShadowTechnique provides an implementation of a depth map shadow tuned to the needs of VTP.*/
class CSimpleInterimShadowTechnique : public osgShadow::ShadowTechnique
{
// working ********************** in openSceneGraph-3.4.0
// CSimpleInterimShadowTechnique();
// CSimpleInterimShadowTechnique(const
// CSimpleInterimShadowTechnique& es, const osg::CopyOp&
// copyop=osg::CopyOp::SHALLOW_COPY);
// META_Object(osgShadow, CSimpleInterimShadowTechnique);
//***********************************************************
// Macro not working *****************in openSceneGraph-3.6.2
CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const CSimpleInterimShadowTechnique*>(obj) != NULL; } \
virtual const char* libraryName() const { return "osgShadow"; }\
virtual const char* className() const { return "CSimpleInterimShadowTechnique"; }
//**************************************************************
In the new implementation I am getting a C2259 error
2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): error C2259: 'CSimpleInterimShadowTechnique': cannot instantiate abstract class
2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'osg::Object *osg::Object::cloneType(void) const': is abstract
2>c:\apis\openscenegraph-3.6.2\build\include\osg\object(80): note: see declaration of 'osg::Object::cloneType'
2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'osg::Object *osg::Object::clone(const osg::CopyOp &) const': is abstract
2>c:\apis\openscenegraph-3.6.2\build\include\osg\object(84): note: see declaration of 'osg::Object::clone'
2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'void osgShadow::ShadowTechnique::resizeGLObjectBuffers(unsigned int)': is abstract
2>c:\apis\openscenegraph-3.6.2\build\include\osgshadow\shadowtechnique(66): note: see declaration of 'osgShadow::ShadowTechnique::resizeGLObjectBuffers'
2>c:\vtp_vsc\terrainsdk\vtlib\vtosg\nodeosg.cpp(1026): note: 'void osgShadow::ShadowTechnique::releaseGLObjects(osg::State *) const': is abstract
2>c:\apis\openscenegraph-3.6.2\build\include\osgshadow\shadowtechnique(71): note: see declaration of 'osgShadow::ShadowTechnique::releaseGLObjects'
The area where the error manifests is in this section of nodeOSG.cpp
//////////////////////////////////////////////////////////////////////
// vtShadow
//
m_ShadowTextureUnit(ShadowTextureUnit), m_LightNumber(LightNumber)
{
setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
setCastsShadowTraversalMask(CastsShadowTraversalMask);
#if VTLISPSM
osg::ref_ptr<CLightSpacePerspectiveShadowTechnique> pShadowTechnique = new CLightSpacePerspectiveShadowTechnique;
// No need to set the BaseTextureUnit as the default of zero is OK for us
// But the ShadowTextureUnit might be different (default 1)
pShadowTechnique->setShadowTextureUnit(m_ShadowTextureUnit);
pShadowTechnique->setLightNumber(m_LightNumber);
#else
//errorC2259 cannot instantiate abstract class in openSceneGraph-3.6.2
//statement working in osg-3.4.0
osg::ref_ptr<CSimpleInterimShadowTechnique> pShadowTechnique = new CSimpleInterimShadowTechnique;//*****************************Error here
#endif
#if !VTLISPSM
#if VTDEBUGSHADOWS
// add some instrumentation
pShadowTechnique->m_pParent = this;
#endif
pShadowTechnique->SetLightNumber(LightNumber);
pShadowTechnique->SetShadowTextureUnit(m_ShadowTextureUnit);
pShadowTechnique->SetShadowSphereRadius(50.0);
#endif
setShadowTechnique(pShadowTechnique.get());
SetOsgNode(this);
}
Help would be appreciated
Cheers,
Herman
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74726#74726
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Herman Varma
2018-09-13 12:47:55 UTC
Permalink
Hi Robert,

I am new in OSG so please be patient. I am still reading the book.

Just to clarify I should replace in the class CSimpleInterimShadowTechnique


CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgShadow, CSimpleInterimShadowTechnique);


with

CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const CSimpleInterimShadowTechnique*>(obj) != NULL; } \
virtual const char* libraryName() const { return "osgShadow"; }\
virtual const char* className() const { return "CSimpleInterimShadowTechnique"; }


removing META_object
and also add

/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize) = 0;

/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const = 0;

to the class.

Do I have this right?









Thank you!

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74741#74741
Robert Osfield
2018-09-13 13:31:13 UTC
Permalink
Hi Harman
Post by Herman Varma
Just to clarify I should replace in the class CSimpleInterimShadowTechnique
CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgShadow, CSimpleInterimShadowTechnique);
with
CSimpleInterimShadowTechnique();
CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const CSimpleInterimShadowTechnique*>(obj) != NULL; } \
virtual const char* libraryName() const { return "osgShadow"; }\
virtual const char* className() const { return "CSimpleInterimShadowTechnique"; }
There should be no need to replace the use of META_Object, the
original code should be fine. The only reason why META_Object macro
wasn't working is because the CSimpleInterimShadowTechnique doesn't
implement the pure virtual methods that have been added in 3.6.x - the
ones I mentioned above.
Post by Herman Varma
and also add
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize) = 0;
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const = 0;
to the class.
Do I have this right?
Yes, but you'll have to actually implement as well :-)

Have a look at the include/osgShadow/ShadowMap example as it
subclasses from ShadowTechnique is uses META_Objects and override the
required methods. Have a look at the src/osgShadow/ShadowMap.cpp to
see how the
resizeGLObjectBuffers and releaseGLObjects are implemented.

Robert
Herman Varma
2018-09-14 13:23:22 UTC
Permalink
Hi Robert

Just to let you know everything compiled and worked.
Thanks to your input I have Ben Discoe's software up and running with
OSG-3.6.2. He does not appear to be supporting VTP since 2015.


Thank you!

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74757#74757
Robert Osfield
2018-09-14 14:48:47 UTC
Permalink
Hi Herman,
Post by Herman Varma
Thanks to your input I have Ben Discoe's software up and running with
OSG-3.6.2. He does not appear to be supporting VTP since 2015.
Good to hear that you've completed the port.

OpenSceneGraph-3.6.3 is out now so you'll have to start all over again!

Thought this time is shouldn't be anything more than a recompile :-)

Cheers
Robert.

Loading...