Skip to content

add stressVAOpolicy bench #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 2.8.9)

project(osgTestBed)
# automatically add CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR to the include directories in every directory
SET(CMAKE_INCLUDE_CURRENT_DIR yes)


find_package(OpenSceneGraph REQUIRED)

subdirs(
stressVAOpolicy
)

SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin)
SET(MODULE_OUTPUT_PATH ${CMAKE_HOME_DIRECTORY}/bin)
SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_HOME_DIRECTORY}/lib)

SET(EXECUTABLE_OUTPUT_PATH_DEBUG ${CMAKE_HOME_DIRECTORY}/ar )
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_HOME_DIRECTORY}/bin)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_HOME_DIRECTORY}/bin)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib)

SET(CMAKE_DEBUG_POSTFIX "d")
29 changes: 29 additions & 0 deletions stressVAOpolicy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PROJECT(stressVAOpolicy)

set(DYNAMIC_OPENSCENEGRAPH True)
if(DYNAMIC_OPENSCENEGRAPH)
add_definitions(-DOSG_DYNAMIC_LIBRARY)
else()
add_definitions(-DOSG_LIBRARY_STATIC)
endif()

find_package(OpenSceneGraph 3.6.0 REQUIRED
osg
osgDB
osgGA
osgUtil
osgViewer
osgText
)

INCLUDE_directories(${OSG_INCLUDE_DIR})
SET(PROJECT_SOURCES
stressVAOpolicy.cpp
)

ADD_EXECUTABLE(stressVAOpolicy ${PROJECT_SOURCES} )

TARGET_LINK_LIBRARIES(stressVAOpolicy ${OPENTHREADS_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} )

SET_TARGET_PROPERTIES(stressVAOpolicy PROPERTIES PROJECT_LABEL "BenchTest stressVAOpolicy" DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

91 changes: 91 additions & 0 deletions stressVAOpolicy/stressVAOpolicy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

/// This program test robustness of VAS path
/// it collects geometries given in arg then add and remove them at runtime
/// stressing osg vas policy as well as driver vao policy

#include <osgUtil/MeshOptimizers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FirstPersonManipulator>

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <osgDB/ReadFile>

class GeomLoaderCB : public osg::NodeCallback
{
int _thresremoval; int _nbaddedatatime;
std::list<osg::ref_ptr<osg::Geometry> > _geoms;
public:
GeomLoaderCB(int thresremoval=1, int nbaddedatatime=1):_nbaddedatatime(nbaddedatatime), _thresremoval(thresremoval) {}

void setGeometryList(const osgUtil::GeometryCollector::GeometryList& geomlist) {
for(auto geom : geomlist) _geoms.push_back(geom);
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) {
osg::Group* gr = node->asGroup();
if(!gr || _geoms.empty() ) return;

if(gr->getNumChildren()>_thresremoval)
{
osg::Geometry* removedgeom = gr->getChild(0)->asGeometry();
if(removedgeom) {
OSG_WARN<<"removing "<< removedgeom <<std::endl;
gr->removeChildren(0,1);
}
return;
}

std::list<osg::ref_ptr<osg::Geometry> > ::iterator it= _geoms.begin();
int cpt=0;
while(it!=_geoms.end() && cpt++<_nbaddedatatime ) {
osg::Geometry *addedgeom = static_cast<osg::Geometry*>((*it)->clone(osg::CopyOp::DEEP_COPY_ALL));
addedgeom->setUseDisplayList(false);
addedgeom->setUseVertexBufferObjects(true);
addedgeom->setUseVertexArrayObject(true);
gr->addChild(addedgeom);
OSG_WARN<<"add "<< addedgeom <<std::endl;
it=_geoms.erase(it);
}
return;
}

};


int main(int argc, char **argv)
{
osg::ArgumentParser args(&argc,argv);
unsigned int geomcountaddedatatime=1, geomcountabovewichweremove=2;
while(args.read("--add",geomcountaddedatatime) ) { }
while(args.read("--remove",geomcountabovewichweremove) ) { }
osgUtil::GeometryCollector geomcollector(0,osgUtil::Optimizer::ALL_OPTIMIZATIONS);

osg::ref_ptr<osg::Node > loaded = osgDB::readNodeFiles(args);
if(!loaded.valid()) loaded = osgDB::readNodeFile("testdata/BIGCITY.ive");
if(loaded.valid())
{
loaded->accept(geomcollector);

osg::Group * root=new osg::Group;
root->setDataVariance(osg::Object::DYNAMIC);
GeomLoaderCB * loader=new GeomLoaderCB(geomcountabovewichweremove,geomcountaddedatatime);
loader->setGeometryList( geomcollector.getGeometryList() );
loaded=0;
root->setUpdateCallback(loader);

osgViewer::Viewer viewer;
viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::ThreadingHandler);
viewer.setRunFrameScheme(osgViewer::ViewerBase::CONTINUOUS);

viewer.setSceneData(root);

viewer.realize();
viewer.run();
}

}
Binary file added testdata/BIGCITY.ive.gz
Binary file not shown.