Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Ravi Mathur
No worries, thank you for looking into it anyway. :)

To be honest, I don't think that "fixing" this behavior within OSG is worth
it. The code additions to ViewerBase::renderingTraversals() would be
duplicated from Renderer and SceneView, and would only benefit fringe cases
where the user wants NO_LIGHT with an explicitly disabled master camera.

I'm fine with the solution I outlined before (manually disabling
GL_LIGHTING on master camera). Plus as you said, most lighting management
should be done by the user anyway.

Ravi
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Robert Osfield
Hi Ravi,

Oh well.  I've removed the LightingMode changes, there is a little
clean up in there so I've merged this with master.

FYI, LightingMode is really just there for convince and backwards
compatibility back to the 1.0/2,0 days of the OSG.

These days I'd write lighting management all myself rather than
leverage these built-in defaults.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Ravi Mathur

robertosfield wrote:
> Ops, don't send modifications without compiling them first...
> 
> The View::LightingMode and SceneView::LightingMode aren't compatible
> enum's so can't be passed as is.  I've spotted a better way of doing
> this update, putting into the Renderer::updateSceneView() method along
> with the setting of the fusion distance.
> 
> Could you test this one?
> 
> Robert.
> 
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum


Unfortunately your update to Renderer::updateSceneView() doesn't address the 
issue, nor would I expect it to. SceneView already gets the updated 
osg::View::LightingMode value inside SceneView::inheritCullSettings(), which is 
called inside Renderer::cull() (line 69, just a few lines down from the call to 
updateSceneView()).

The problem is that the Renderer is never run for the master camera since I 
disabled it using mastercamera->setGraphicsContext(NULL). So the SceneViews for 
the slaves, which use the master camera's StateSet as their _globalStateSet, 
still have lighting enabled.

I'm not saying this behavior is wrong per se, since I did explicitly disable 
the master camera. But if any change is to made to the OSG, it would have to be 
in ViewerBase::renderingTraversals() since that is where the master camera's 
Renderer::cull() method would normally be called.

Let me think of an appropriate minimal update to 
ViewerBase::renderingTraversals(). Basically it needs to first update the 
lighting modes for each disabled camera's StateSet before performing 
Renderer::cull() for each enabled camera.

Ravi

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72713#72713





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Robert Osfield
Ops, don't send modifications without compiling them first...

The View::LightingMode and SceneView::LightingMode aren't compatible
enum's so can't be passed as is.  I've spotted a better way of doing
this update, putting into the Renderer::updateSceneView() method along
with the setting of the fusion distance.

Could you test this one?

Robert.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 

#include 
#include 
#include 

#include 
#include 

#include 
#include 

#include 

#include 

using namespace osgViewer;

//#define DEBUG_MESSAGE OSG_NOTICE
#define DEBUG_MESSAGE OSG_DEBUG

OpenGLQuerySupport::OpenGLQuerySupport():
_extensions(0)
{
}

class OSGVIEWER_EXPORT EXTQuerySupport : public OpenGLQuerySupport
{
 public:
EXTQuerySupport();
void checkQuery(osg::Stats* stats, osg::State* state, osg::Timer_t startTick);
virtual void beginQuery(unsigned int frameNumber, osg::State* state);
virtual void endQuery(osg::State* state);
virtual void initialize(osg::State* state, osg::Timer_t startTick);
 protected:
GLuint createQueryObject();
typedef std::pair QueryFrameNumberPair;
typedef std::list QueryFrameNumberList;
typedef std::vector QueryList;

QueryFrameNumberList_queryFrameNumberList;
QueryList   _availableQueryObjects;
double  _previousQueryTime;
};


EXTQuerySupport::EXTQuerySupport():
_previousQueryTime(0.0)
{
}

void EXTQuerySupport::checkQuery(osg::Stats* stats, osg::State* /*state*/,
 osg::Timer_t startTick)
{
for(QueryFrameNumberList::iterator itr = _queryFrameNumberList.begin();
itr != _queryFrameNumberList.end();
)
{
GLuint query = itr->first;
GLint available = 0;
_extensions->glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, );
if (available)
{
GLuint64 timeElapsed = 0;
_extensions->glGetQueryObjectui64v(query, GL_QUERY_RESULT, );

double timeElapsedSeconds = double(timeElapsed)*1e-9;
double currentTime = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick());
double estimatedEndTime = (_previousQueryTime + currentTime) * 0.5;
double estimatedBeginTime = estimatedEndTime - timeElapsedSeconds;

stats->setAttribute(itr->second, "GPU draw begin time", estimatedBeginTime);
stats->setAttribute(itr->second, "GPU draw end time", estimatedEndTime);
stats->setAttribute(itr->second, "GPU draw time taken", timeElapsedSeconds);


itr = _queryFrameNumberList.erase(itr);
_availableQueryObjects.push_back(query);
}
else
{
++itr;
}

}
_previousQueryTime = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick());
}

GLuint EXTQuerySupport::createQueryObject()
{
if (_availableQueryObjects.empty())
{
GLuint query;
_extensions->glGenQueries(1, );
return query;
}
else
{
GLuint query = _availableQueryObjects.back();
_availableQueryObjects.pop_back();
return query;
}
}

void EXTQuerySupport::beginQuery(unsigned int frameNumber, osg::State* /*state*/)
{
GLuint query = createQueryObject();
_extensions->glBeginQuery(GL_TIME_ELAPSED, query);
_queryFrameNumberList.push_back(QueryFrameNumberPair(query, frameNumber));
}

void EXTQuerySupport::endQuery(osg::State* /*state*/)
{
_extensions->glEndQuery(GL_TIME_ELAPSED);
}

void OpenGLQuerySupport::initialize(osg::State* state, osg::Timer_t /*startTick*/)
{
_extensions = state->get();
}

void EXTQuerySupport::initialize(osg::State* state, osg::Timer_t startTick)
{
OpenGLQuerySupport::initialize(state, startTick);
_previousQueryTime = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick());

}

class ARBQuerySupport : public OpenGLQuerySupport
{
public:
virtual void checkQuery(osg::Stats* stats, osg::State* state,
osg::Timer_t startTick);

virtual void beginQuery(unsigned int frameNumber, osg::State* state);
virtual void endQuery(osg::State* state);
virtual void initialize(osg::State* state, osg::Timer_t startTick);
protected:
typedef 

Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Robert Osfield
HI Ravi,

On 10 January 2018 at 14:53, Ravi Mathur  wrote:
> I just checked, and the same behavior & solution exists on master.

Looking at the internal setup of the rendering backend I think the
reason for the behavior is that the Renderer implement found in
OpenSceneGraph/src/osgViewer/Renderer.cpp constructor reads the View's
LightingMode and then passes this on to the SceneView's it setups to
do the rendering.  This setup happens when you add the slave cameras.

I think the problem comes in that the osg::View::LightingMode value
isn't passed onto the SceneView's by the Renderer's.

Attached is a modification of src/osgViewer/Renderer.cpp that passes
the View::LightingMode value to the SceneView on each new cull
traversal.

Could you try this out to see if it works, if so I'll check it in.

Robert.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 

#include 
#include 
#include 

#include 
#include 

#include 
#include 

#include 

#include 

using namespace osgViewer;

//#define DEBUG_MESSAGE OSG_NOTICE
#define DEBUG_MESSAGE OSG_DEBUG

OpenGLQuerySupport::OpenGLQuerySupport():
_extensions(0)
{
}

class OSGVIEWER_EXPORT EXTQuerySupport : public OpenGLQuerySupport
{
 public:
EXTQuerySupport();
void checkQuery(osg::Stats* stats, osg::State* state, osg::Timer_t startTick);
virtual void beginQuery(unsigned int frameNumber, osg::State* state);
virtual void endQuery(osg::State* state);
virtual void initialize(osg::State* state, osg::Timer_t startTick);
 protected:
GLuint createQueryObject();
typedef std::pair QueryFrameNumberPair;
typedef std::list QueryFrameNumberList;
typedef std::vector QueryList;

QueryFrameNumberList_queryFrameNumberList;
QueryList   _availableQueryObjects;
double  _previousQueryTime;
};


EXTQuerySupport::EXTQuerySupport():
_previousQueryTime(0.0)
{
}

void EXTQuerySupport::checkQuery(osg::Stats* stats, osg::State* /*state*/,
 osg::Timer_t startTick)
{
for(QueryFrameNumberList::iterator itr = _queryFrameNumberList.begin();
itr != _queryFrameNumberList.end();
)
{
GLuint query = itr->first;
GLint available = 0;
_extensions->glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, );
if (available)
{
GLuint64 timeElapsed = 0;
_extensions->glGetQueryObjectui64v(query, GL_QUERY_RESULT, );

double timeElapsedSeconds = double(timeElapsed)*1e-9;
double currentTime = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick());
double estimatedEndTime = (_previousQueryTime + currentTime) * 0.5;
double estimatedBeginTime = estimatedEndTime - timeElapsedSeconds;

stats->setAttribute(itr->second, "GPU draw begin time", estimatedBeginTime);
stats->setAttribute(itr->second, "GPU draw end time", estimatedEndTime);
stats->setAttribute(itr->second, "GPU draw time taken", timeElapsedSeconds);


itr = _queryFrameNumberList.erase(itr);
_availableQueryObjects.push_back(query);
}
else
{
++itr;
}

}
_previousQueryTime = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick());
}

GLuint EXTQuerySupport::createQueryObject()
{
if (_availableQueryObjects.empty())
{
GLuint query;
_extensions->glGenQueries(1, );
return query;
}
else
{
GLuint query = _availableQueryObjects.back();
_availableQueryObjects.pop_back();
return query;
}
}

void EXTQuerySupport::beginQuery(unsigned int frameNumber, osg::State* /*state*/)
{
GLuint query = createQueryObject();
_extensions->glBeginQuery(GL_TIME_ELAPSED, query);
_queryFrameNumberList.push_back(QueryFrameNumberPair(query, frameNumber));
}

void EXTQuerySupport::endQuery(osg::State* /*state*/)
{
_extensions->glEndQuery(GL_TIME_ELAPSED);
}

void OpenGLQuerySupport::initialize(osg::State* state, osg::Timer_t /*startTick*/)
{
_extensions = state->get();
}

void EXTQuerySupport::initialize(osg::State* state, osg::Timer_t startTick)
{
OpenGLQuerySupport::initialize(state, startTick);

Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Ravi Mathur

ravidavi wrote:
> 
> robertosfield wrote:
> > HI Ravi,
> > 
> > I haven't yet looked deeply into the issue as I'm still in post
> > holiday catch up mode.  What version of the OSG are you using?
> > 
> > Robert.
> > 
> 
> 
> I'm on the OpenSceneGraph-3.5.6 tag.


I just checked, and the same behavior & solution exists on master.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72709#72709





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Ravi Mathur

robertosfield wrote:
> HI Ravi,
> 
> I haven't yet looked deeply into the issue as I'm still in post
> holiday catch up mode.  What version of the OSG are you using?
> 
> Robert.
> 


I'm on the OpenSceneGraph-3.5.6 tag.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72708#72708





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-10 Thread Robert Osfield
HI Ravi,

> If Robert or any of the other experienced folks on here think that I'm 
> mistaken on this, or have other more elegant solutions, please let me know. 
> Otherwise I'll consider the matter closed.

I haven't yet looked deeply into the issue as I'm still in post
holiday catch up mode.  What version of the OSG are you using?

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Slave camera lighting with disabled main camera

2018-01-09 Thread Ravi Mathur
OK I figured it out after digging further into SceneView. In case anyone else 
ever runs into this, here is what's going on and how to fix it.

When a new View is created (e.g. osgViewer), it defaults to HEADLIGHT mode and 
internally creates the master Camera, along with a Renderer and SceneView for 
that camera. The SceneView initializes the master camera's StateSet with a new 
Light (diffuse+specular) and Light Model (ambient), enables the GL_LIGHTING 
mode, and internally sets itself up for HEADLIGHT mode.

>From here on, all slave cameras added to the View use the master camera's 
>StateSet as their global stateset (via their own SceneViews). Under normal 
>operations, calling View::setLightingMode(NO_LIGHT) results in the master 
>camera's SceneView removing lighting from the global stateset during the cull 
>stage. Consequently, all slave cameras also have their lighting disabled 
>(unless explicitly enabled in their own StateSet). This is all great and works 
>as expected.

However, in my example I was disabling the master camera by removing its 
graphics context. Because of this, the master camera's SceneView was never 
being executed during the cull stage, so the default (HEADLIGHT) lighting 
parameters were never removed from the master camera's stateset. Therefore all 
slaves were inheriting the HEADLIGHT lighting.

The solution to this is pretty simple: manually remove the lighting modes from 
the master camera's stateset after setting NO_LIGHT. Of course this is only 
necessary if you plan on disabling the master camera by removing its graphics 
context.


Code:
viewer.setLightingMode(View::NO_LIGHT);
StateSet* ss = viewer.getCamera()->getStateSet();
if(ss) ss->removeMode(GL_LIGHTING);
...
viewer.getCamera()->setGraphicsContext(NULL);




If Robert or any of the other experienced folks on here think that I'm mistaken 
on this, or have other more elegant solutions, please let me know. Otherwise 
I'll consider the matter closed.

Thanks!
Ravi

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72700#72700





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org