Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gwaldron/osgearth
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbeverage committed Dec 8, 2023
2 parents a2048c2 + 6e638f5 commit b32304e
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 104 deletions.
27 changes: 18 additions & 9 deletions src/applications/osgearth_viewer/osgearth_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <osgEarth/MapNode>
#include <osgEarth/Threading>
#include <osgEarth/ShaderGenerator>
#include <osgEarth/PhongLightingEffect>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgUtil/Optimizer>
Expand Down Expand Up @@ -78,21 +79,29 @@ main(int argc, char** argv)
viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);

// load an earth file, and support all or our example command-line options
auto node = MapNodeHelper().load(arguments, &viewer);
auto node = MapNodeHelper().loadWithoutControls(arguments, &viewer);
if (node.valid())
{
viewer.setSceneData( node );

if (!MapNode::get(node))
if (MapNode::get(node))
{
// not an earth file? Just view as a normal OSG node or image
viewer.setSceneData(node);
}
else
{
// not an earth file? Just view as a normal OSG node or image with basic lighting
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
osgUtil::Optimizer opt;
opt.optimize(node, osgUtil::Optimizer::INDEX_MESH);

osg::LightSource* sunLS = new osg::LightSource();
sunLS->getLight()->setPosition(osg::Vec4d(1, -1, 1, 0));
auto group = new osg::Group();
group->addChild(sunLS);
group->addChild(node);
auto phong = new PhongLightingEffect();
phong->attach(group->getOrCreateStateSet());
ShaderGenerator gen;
node->accept(gen);
gen.run(group);

MapNodeHelper().configureView(&viewer);
viewer.setSceneData(group);
}

return Metrics::run(viewer);
Expand Down
177 changes: 87 additions & 90 deletions src/osgEarth/ExampleResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,49 @@ MapNodeHelper::loadWithoutControls(
GLUtils::enableGLDebugging();
}

// collect the views
osgViewer::Viewer::Views views;
if (viewer)
{
viewer->getViews(views);
}

// configures each view with some stock goodies
for (auto view : views)
{
configureView(view);
}

// vsync on/off?
optional<bool> vsync;
if (args.read("--vsync"))
vsync = true;
else if (args.read("--novsync"))
vsync = false;

// VP debugging
if (args.read("--vpdebug") || args.read("--vp-debug"))
{
GLUtils::enableGLDebugging();
VirtualProgram::enableGLDebugging();
}

if (viewer)
{
MultiRealizeOperation* op = new MultiRealizeOperation();

if (viewer->getRealizeOperation())
op->_ops.push_back(viewer->getRealizeOperation());

GL3RealizeOperation* rop = new GL3RealizeOperation();
if (vsync.isSet())
rop->setSyncToVBlank(vsync.get());

op->_ops.push_back(rop);

viewer->setRealizeOperation(op);
}

// read in the Earth file:
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(args, myReadOptions.get());

Expand Down Expand Up @@ -395,13 +438,6 @@ MapNodeHelper::loadWithoutControls(
mapNode->getTerrainOptions().setGPUTessellation(true);
}

// collect the views
osgViewer::Viewer::Views views;
if (viewer)
{
viewer->getViews(views);
}

// a root node to hold everything:
osg::ref_ptr<osg::Group> root = new osg::Group();
root->addChild(node);
Expand All @@ -428,42 +464,6 @@ MapNodeHelper::loadWithoutControls(
}
}

// configures each view with some stock goodies
for (auto view : views)
{
configureView(view);
}

// vsync on/off?
optional<bool> vsync;
if (args.read("--vsync"))
vsync = true;
else if (args.read("--novsync"))
vsync = false;

// VP debugging
if (args.read("--vpdebug") || args.read("--vp-debug"))
{
GLUtils::enableGLDebugging();
VirtualProgram::enableGLDebugging();
}

if (viewer)
{
MultiRealizeOperation* op = new MultiRealizeOperation();

if (viewer->getRealizeOperation())
op->_ops.push_back(viewer->getRealizeOperation());

GL3RealizeOperation* rop = new GL3RealizeOperation();
if (vsync.isSet())
rop->setSyncToVBlank(vsync.get());

op->_ops.push_back(rop);

viewer->setRealizeOperation(op);
}

return root;
}

Expand Down Expand Up @@ -509,6 +509,50 @@ MapNodeHelper::load(
GLUtils::enableGLDebugging();
}

// collect the views
osgViewer::Viewer::Views views;
if (viewer)
{
viewer->getViews(views);
}

// configures each view with some stock goodies
for (osgViewer::Viewer::Views::iterator view = views.begin(); view != views.end(); ++view)
{
configureView(*view);
}

// vsync on/off?
optional<bool> vsync;
if (args.read("--vsync"))
vsync = true;
else if (args.read("--novsync"))
vsync = false;

// VP debugging
if (args.read("--vpdebug") || args.read("--vp-debug"))
{
GLUtils::enableGLDebugging();
VirtualProgram::enableGLDebugging();
}

if (viewer)
{
MultiRealizeOperation* op = new MultiRealizeOperation();

if (viewer->getRealizeOperation())
op->_ops.push_back(viewer->getRealizeOperation());

GL3RealizeOperation* rop = new GL3RealizeOperation();

if (vsync.isSet())
rop->setSyncToVBlank(vsync.get());

op->_ops.push_back(rop);

viewer->setRealizeOperation(op);
}

// read in the Earth file:
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(args, myReadOptions.get());

Expand All @@ -532,13 +576,6 @@ MapNodeHelper::load(
mapNode->getTerrainOptions().setGPUTessellation(true);
}

// collect the views
osgViewer::Viewer::Views views;
if (viewer)
{
viewer->getViews(views);
}

// warn about not having an earth manip
for (osgViewer::Viewer::Views::iterator view = views.begin(); view != views.end(); ++view)
{
Expand Down Expand Up @@ -576,46 +613,6 @@ MapNodeHelper::load(
}
}

// configures each view with some stock goodies
for (osgViewer::Viewer::Views::iterator view = views.begin(); view != views.end(); ++view)
{
configureView( *view );
}

// vsync on/off?
optional<bool> vsync;
if (args.read("--vsync"))
vsync = true;
else if (args.read("--novsync"))
vsync = false;

// VP debugging
if (args.read("--vpdebug") || args.read("--vp-debug"))
{
GLUtils::enableGLDebugging();
VirtualProgram::enableGLDebugging();
}

if (viewer)
{
MultiRealizeOperation* op = new MultiRealizeOperation();

if (viewer->getRealizeOperation())
op->_ops.push_back(viewer->getRealizeOperation());

#ifdef OSG_GL3_AVAILABLE
GL3RealizeOperation* rop = new GL3RealizeOperation();
#else
CustomRealizeOperation* rop = new GL3RealizeOperation();
#endif
if (vsync.isSet())
rop->setSyncToVBlank(vsync.get());

op->_ops.push_back(rop);

viewer->setRealizeOperation(op);
}

return root;
}

Expand Down
9 changes: 9 additions & 0 deletions src/osgEarth/GLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ namespace
{
const std::string& s = severities[severity - GL_DEBUG_SEVERITY_HIGH];
OE_WARN << "GL (" << s << ", " << source << ") -- " << message << std::endl;

std::stringstream buf;
CallStack stack;
for(unsigned i=1; i<stack.symbols.size(); ++i)
{
buf << " -> " << stack.symbols[i];
if (stack.symbols[i] == "main") break;
}
OE_WARN << "Call stack:" << buf.str() << std::endl;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/osgEarth/Lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ GenerateGL3LightingUniforms::apply(osg::LightSource& lightSource)
lightSource.addCullCallback(new LightSourceGL3UniformGenerator());
}

#if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
//#if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
// If there's no FFP, we need to replace the Light with a LightGL3 to prevent
// error messages on the console.
if (dynamic_cast<LightGL3*>(lightSource.getLight()) == 0L)
{
lightSource.setLight(new LightGL3(*lightSource.getLight()));
}
#endif
//#endif
}

apply(static_cast<osg::Node&>(lightSource));
Expand Down
4 changes: 2 additions & 2 deletions src/osgEarth/ShaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ ShaderFactory::createMains(
{
// We require attribute aliasing and matrix uniforms.
OE_SOFT_ASSERT(state.getUseVertexAttributeAliasing(),
"OpenSceneGraph vertex attribute aliasing must be enabled");
"OpenSceneGraph vertex attribute aliasing must be enabled. Consider installing the GL3RealizeOperation in your viewer.");

OE_SOFT_ASSERT(state.getUseModelViewAndProjectionUniforms(),
"OpenSceneGraph matrix uniforms must be enabled");
"OpenSceneGraph matrix uniforms must be enabled. Consider installing the GL3RealizeOperation in your viewer.");

StageMask stages =
VirtualProgram::STAGE_VERTEX |
Expand Down
10 changes: 10 additions & 0 deletions src/osgEarth/Utils
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ namespace osgEarth { namespace Util
Function _func;
std::stack<osg::Matrix> _transformStack;
};

/**
* Records the thread's call stack at the time of construction.
*/
class OSGEARTH_EXPORT CallStack
{
public:
CallStack();
std::vector<std::string> symbols;
};
} }

#endif // OSGEARTH_UTILS_H
65 changes: 64 additions & 1 deletion src/osgEarth/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,67 @@ CustomRenderLeaf::render(osg::RenderInfo& renderInfo, osgUtil::RenderLeaf* previ
{
state.decrementDynamicObjectCount();
}
}
}

//.....

#ifdef WIN32
#include <Windows.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")
#elif defined(__GNUC__)
#include <execinfo.h>
#include <cstdlib>
#include <cstring>
#include <cxxabi.h>
#endif

CallStack::CallStack()
{
#ifdef WIN32
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);

void* stack[100];
WORD frames = CaptureStackBackTrace(0, 100, stack, NULL);

SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);

for (int i = 0; i < frames; i++)
{
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
symbols.emplace_back(symbol->Name);
}

free(symbol);
#else
auto trim = [](const char* in, std::string& out)
{
std::string temp(in);
auto start = temp.find_first_of('(');
auto end = temp.find_first_of('+', start);
out = temp.substr(start + 1, end - 1 - start);
};

void* stack[100];
int frames = backtrace(stack, 100);
char** bt = backtrace_symbols(stack, frames);
for (int i = 0; i < frames; ++i)
{
std::string buf;
int status = -1;
trim(bt[i], buf);
char* demangled = abi::__cxa_demangle(buf.c_str(), nullptr, nullptr, &status);
if (status == 0) {
buf = demangled;
free(demangled);
}
symbols.emplace_back(buf);
if (buf == "main")
break;
}
free(bt);
#endif
}

0 comments on commit b32304e

Please sign in to comment.