mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 17:15:34 +00:00
Try to uncursify DebugDrawer scene representation
This commit is contained in:
parent
d975ed33ab
commit
38ab09a52e
5 changed files with 67 additions and 62 deletions
|
@ -432,8 +432,9 @@ namespace MWRender
|
|||
mViewer->getIncrementalCompileOperation()->setTargetFrameRate(Settings::cells().mTargetFramerate);
|
||||
}
|
||||
|
||||
mDebugDraw
|
||||
= std::make_unique<Debug::DebugDrawer>(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode);
|
||||
mDebugDraw = new Debug::DebugDrawer(mResourceSystem->getSceneManager()->getShaderManager());
|
||||
mRootNode->addChild(mDebugDraw);
|
||||
|
||||
mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
|
||||
|
||||
mEffectManager = std::make_unique<EffectManager>(sceneRoot, mResourceSystem);
|
||||
|
|
|
@ -335,7 +335,7 @@ namespace MWRender
|
|||
osg::ref_ptr<NpcAnimation> mPlayerAnimation;
|
||||
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
|
||||
std::unique_ptr<Camera> mCamera;
|
||||
std::unique_ptr<Debug::DebugDrawer> mDebugDraw;
|
||||
osg::ref_ptr<Debug::DebugDrawer> mDebugDraw;
|
||||
|
||||
osg::ref_ptr<StateUpdater> mStateUpdater;
|
||||
osg::ref_ptr<SharedUniformStateUpdater> mSharedUniformStateUpdater;
|
||||
|
|
|
@ -215,12 +215,12 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
|||
geom.addPrimitiveSet(indices);
|
||||
}
|
||||
|
||||
static int getIdexBufferReadFromFrame(const long long int& nFrame)
|
||||
static int getIndexBufferReadFromFrame(const unsigned int& nFrame)
|
||||
{
|
||||
return nFrame % 2;
|
||||
}
|
||||
|
||||
static int getIdexBufferWriteFromFrame(const long long int& nFrame)
|
||||
static int getIndexBufferWriteFromFrame(const unsigned int& nFrame)
|
||||
{
|
||||
return (nFrame + 1) % 2;
|
||||
}
|
||||
|
@ -248,6 +248,16 @@ namespace Debug
|
|||
makeLineInstance(*mLinesToDraw);
|
||||
}
|
||||
|
||||
DebugCustomDraw::DebugCustomDraw(const DebugCustomDraw& copy, const osg::CopyOp& copyop)
|
||||
: Drawable(copy, copyop)
|
||||
, mShapesToDraw(copy.mShapesToDraw)
|
||||
, mLinesToDraw(copy.mLinesToDraw)
|
||||
, mCubeGeometry(copy.mCubeGeometry)
|
||||
, mCylinderGeometry(copy.mCylinderGeometry)
|
||||
, mWireCubeGeometry(copy.mWireCubeGeometry)
|
||||
{
|
||||
}
|
||||
|
||||
void DebugCustomDraw::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
auto state = renderInfo.getState();
|
||||
|
@ -308,43 +318,23 @@ namespace Debug
|
|||
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexArray())->clear();
|
||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getNormalArray())->clear();
|
||||
}
|
||||
|
||||
class DebugDrawCallback : public SceneUtil::NodeCallback<DebugDrawCallback>
|
||||
{
|
||||
public:
|
||||
DebugDrawCallback(Debug::DebugDrawer& debugDrawer)
|
||||
: mDebugDrawer(debugDrawer)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
mDebugDrawer.mCurrentFrame = nv->getTraversalNumber();
|
||||
int indexRead = getIdexBufferReadFromFrame(mDebugDrawer.mCurrentFrame);
|
||||
auto& lines = mDebugDrawer.mCustomDebugDrawer[indexRead]->mLinesToDraw;
|
||||
lines->removePrimitiveSet(0, 1);
|
||||
lines->addPrimitiveSet(new osg::DrawArrays(
|
||||
osg::PrimitiveSet::LINES, 0, static_cast<osg::Vec3Array*>(lines->getVertexArray())->size()));
|
||||
|
||||
nv->pushOntoNodePath(mDebugDrawer.mCustomDebugDrawer[indexRead]);
|
||||
nv->apply(*mDebugDrawer.mCustomDebugDrawer[indexRead]);
|
||||
nv->popFromNodePath();
|
||||
}
|
||||
|
||||
Debug::DebugDrawer& mDebugDrawer;
|
||||
};
|
||||
}
|
||||
|
||||
Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr<osg::Group> parentNode)
|
||||
: mParentNode(std::move(parentNode))
|
||||
Debug::DebugDrawer::DebugDrawer(const DebugDrawer& copy, const osg::CopyOp& copyop)
|
||||
: Drawable(copy, copyop)
|
||||
, mCurrentFrame(copy.mCurrentFrame)
|
||||
, mCustomDebugDrawer(copy.mCustomDebugDrawer)
|
||||
{
|
||||
}
|
||||
|
||||
Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager)
|
||||
{
|
||||
mCurrentFrame = 0;
|
||||
|
||||
auto program = shaderManager.getProgram("debug");
|
||||
|
||||
mDebugDrawSceneObjects = new osg::Group;
|
||||
mDebugDrawSceneObjects->setCullingActive(false);
|
||||
osg::StateSet* stateset = mDebugDrawSceneObjects->getOrCreateStateSet();
|
||||
setCullingActive(false);
|
||||
osg::StateSet* stateset = getOrCreateStateSet();
|
||||
stateset->addUniform(new osg::Uniform("color", osg::Vec3f(1., 1., 1.)));
|
||||
stateset->addUniform(new osg::Uniform("trans", osg::Vec3f(0., 0., 0.)));
|
||||
stateset->addUniform(new osg::Uniform("scale", osg::Vec3f(1., 1., 1.)));
|
||||
|
@ -378,19 +368,28 @@ Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_p
|
|||
mCustomDebugDrawer[i]->mCubeGeometry = cubeGeometry;
|
||||
mCustomDebugDrawer[i]->mCylinderGeometry = cylinderGeom;
|
||||
}
|
||||
mDebugDrawSceneObjects->addCullCallback(new DebugDrawCallback(*this));
|
||||
|
||||
mParentNode->addChild(mDebugDrawSceneObjects);
|
||||
}
|
||||
|
||||
Debug::DebugDrawer::~DebugDrawer()
|
||||
void Debug::DebugDrawer::accept(osg::NodeVisitor& nv)
|
||||
{
|
||||
mParentNode->removeChild(mDebugDrawSceneObjects);
|
||||
if (!nv.validNodeMask(*this))
|
||||
return;
|
||||
|
||||
mCurrentFrame = nv.getTraversalNumber();
|
||||
int indexRead = getIndexBufferReadFromFrame(mCurrentFrame);
|
||||
auto& lines = mCustomDebugDrawer[indexRead]->mLinesToDraw;
|
||||
lines->removePrimitiveSet(0, 1);
|
||||
lines->addPrimitiveSet(new osg::DrawArrays(
|
||||
osg::PrimitiveSet::LINES, 0, static_cast<osg::Vec3Array*>(lines->getVertexArray())->size()));
|
||||
|
||||
nv.pushOntoNodePath(this);
|
||||
mCustomDebugDrawer[indexRead]->accept(nv);
|
||||
nv.popFromNodePath();
|
||||
}
|
||||
|
||||
void Debug::DebugDrawer::drawCube(osg::Vec3f mPosition, osg::Vec3f mDims, osg::Vec3f mColor)
|
||||
{
|
||||
mCustomDebugDrawer[getIdexBufferWriteFromFrame(mCurrentFrame)]->mShapesToDraw.push_back(
|
||||
mCustomDebugDrawer[getIndexBufferWriteFromFrame(mCurrentFrame)]->mShapesToDraw.push_back(
|
||||
{ mPosition, mDims, mColor, DrawShape::Cube });
|
||||
}
|
||||
|
||||
|
@ -403,12 +402,12 @@ void Debug::DebugDrawer::drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec
|
|||
|
||||
void Debug::DebugDrawer::addDrawCall(const DrawCall& draw)
|
||||
{
|
||||
mCustomDebugDrawer[getIdexBufferWriteFromFrame(mCurrentFrame)]->mShapesToDraw.push_back(draw);
|
||||
mCustomDebugDrawer[getIndexBufferWriteFromFrame(mCurrentFrame)]->mShapesToDraw.push_back(draw);
|
||||
}
|
||||
|
||||
void Debug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color)
|
||||
{
|
||||
const int indexWrite = getIdexBufferWriteFromFrame(mCurrentFrame);
|
||||
const int indexWrite = getIndexBufferWriteFromFrame(mCurrentFrame);
|
||||
const auto& lines = mCustomDebugDrawer[indexWrite]->mLinesToDraw;
|
||||
auto vertices = static_cast<osg::Vec3Array*>(lines->getVertexArray());
|
||||
auto colors = static_cast<osg::Vec3Array*>(lines->getNormalArray());
|
||||
|
|
|
@ -70,6 +70,9 @@ namespace Debug
|
|||
{
|
||||
public:
|
||||
DebugCustomDraw();
|
||||
DebugCustomDraw(const DebugCustomDraw& copy, const osg::CopyOp& copyop);
|
||||
|
||||
META_Object(Debug, DebugCustomDraw)
|
||||
|
||||
mutable std::vector<DrawCall> mShapesToDraw;
|
||||
osg::ref_ptr<osg::Geometry> mLinesToDraw;
|
||||
|
@ -81,12 +84,15 @@ namespace Debug
|
|||
virtual void drawImplementation(osg::RenderInfo&) const override;
|
||||
};
|
||||
|
||||
struct DebugDrawer
|
||||
struct DebugDrawer : public osg::Drawable
|
||||
{
|
||||
friend DebugDrawCallback;
|
||||
DebugDrawer() = default;
|
||||
DebugDrawer(const DebugDrawer& copy, const osg::CopyOp& copyop);
|
||||
DebugDrawer(Shader::ShaderManager& shaderManager);
|
||||
|
||||
DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr<osg::Group> parentNode);
|
||||
~DebugDrawer();
|
||||
META_Object(Debug, DebugDrawer)
|
||||
|
||||
void accept(osg::NodeVisitor& nv) override;
|
||||
|
||||
void drawCube(
|
||||
osg::Vec3f mPosition, osg::Vec3f mDims = osg::Vec3(50., 50., 50.), osg::Vec3f mColor = colorWhite);
|
||||
|
@ -95,11 +101,9 @@ namespace Debug
|
|||
void addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color = colorWhite);
|
||||
|
||||
private:
|
||||
long long int mCurrentFrame;
|
||||
unsigned int mCurrentFrame;
|
||||
|
||||
std::array<osg::ref_ptr<DebugCustomDraw>, 2> mCustomDebugDrawer;
|
||||
osg::ref_ptr<osg::Group> mDebugDrawSceneObjects;
|
||||
osg::ref_ptr<osg::Group> mParentNode;
|
||||
};
|
||||
}
|
||||
#endif // !
|
||||
|
|
|
@ -175,18 +175,19 @@ namespace SceneUtil
|
|||
mgr->addWrapper(new GeometrySerializer);
|
||||
|
||||
// ignore the below for now to avoid warning spam
|
||||
const char* ignore[] = { "MWRender::PtrHolder", "Resource::TemplateRef", "Resource::TemplateMultiRef",
|
||||
"SceneUtil::CompositeStateSetUpdater", "SceneUtil::UBOManager", "SceneUtil::LightListCallback",
|
||||
"SceneUtil::LightManagerUpdateCallback", "SceneUtil::FFPLightStateAttribute",
|
||||
"SceneUtil::UpdateRigBounds", "SceneUtil::UpdateRigGeometry", "SceneUtil::LightSource",
|
||||
"SceneUtil::DisableLight", "SceneUtil::MWShadowTechnique", "SceneUtil::TextKeyMapHolder",
|
||||
"Shader::AddedState", "Shader::RemovedAlphaFunc", "NifOsg::FlipController",
|
||||
"NifOsg::KeyframeController", "NifOsg::Emitter", "NifOsg::ParticleColorAffector",
|
||||
"NifOsg::ParticleSystem", "NifOsg::GravityAffector", "NifOsg::ParticleBomb", "NifOsg::GrowFadeAffector",
|
||||
"NifOsg::InverseWorldMatrix", "NifOsg::StaticBoundingBoxCallback", "NifOsg::GeomMorpherController",
|
||||
"NifOsg::UpdateMorphGeometry", "NifOsg::UVController", "NifOsg::VisController", "osgMyGUI::Drawable",
|
||||
"osg::DrawCallback", "osg::UniformBufferObject", "osgOQ::ClearQueriesCallback",
|
||||
"osgOQ::RetrieveQueriesCallback", "osg::DummyObject" };
|
||||
const char* ignore[]
|
||||
= { "Debug::DebugDrawer", "MWRender::PtrHolder", "Resource::TemplateRef", "Resource::TemplateMultiRef",
|
||||
"SceneUtil::CompositeStateSetUpdater", "SceneUtil::UBOManager", "SceneUtil::LightListCallback",
|
||||
"SceneUtil::LightManagerUpdateCallback", "SceneUtil::FFPLightStateAttribute",
|
||||
"SceneUtil::UpdateRigBounds", "SceneUtil::UpdateRigGeometry", "SceneUtil::LightSource",
|
||||
"SceneUtil::DisableLight", "SceneUtil::MWShadowTechnique", "SceneUtil::TextKeyMapHolder",
|
||||
"Shader::AddedState", "Shader::RemovedAlphaFunc", "NifOsg::FlipController",
|
||||
"NifOsg::KeyframeController", "NifOsg::Emitter", "NifOsg::ParticleColorAffector",
|
||||
"NifOsg::ParticleSystem", "NifOsg::GravityAffector", "NifOsg::ParticleBomb",
|
||||
"NifOsg::GrowFadeAffector", "NifOsg::InverseWorldMatrix", "NifOsg::StaticBoundingBoxCallback",
|
||||
"NifOsg::GeomMorpherController", "NifOsg::UpdateMorphGeometry", "NifOsg::UVController",
|
||||
"NifOsg::VisController", "osgMyGUI::Drawable", "osg::DrawCallback", "osg::UniformBufferObject",
|
||||
"osgOQ::ClearQueriesCallback", "osgOQ::RetrieveQueriesCallback", "osg::DummyObject" };
|
||||
for (size_t i = 0; i < sizeof(ignore) / sizeof(ignore[0]); ++i)
|
||||
{
|
||||
mgr->addWrapper(makeDummySerializer(ignore[i]));
|
||||
|
|
Loading…
Reference in a new issue