mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
2 years ago
|
#ifndef OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
||
|
#define OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
||
|
|
||
2 years ago
|
#include <osg/Vec3f>
|
||
|
#include <osg/ref_ptr>
|
||
|
#include <vector>
|
||
|
|
||
|
namespace osg
|
||
|
{
|
||
|
class Group;
|
||
|
class Geometry;
|
||
|
}
|
||
2 years ago
|
namespace Shader
|
||
|
{
|
||
|
class ShaderManager;
|
||
|
}
|
||
2 years ago
|
|
||
|
namespace MWRenderDebug
|
||
|
{
|
||
|
static const osg::Vec3f colorWhite = osg::Vec3(1., 1., 1.);
|
||
|
static const osg::Vec3f colorRed = osg::Vec3(1., 0., 0.);
|
||
|
static const osg::Vec3f colorBlue = osg::Vec3(0., 0., 1.);
|
||
|
static const osg::Vec3f colorGreen = osg::Vec3(0., 1., 0.);
|
||
|
static const osg::Vec3f colorBlack = osg::Vec3(0., 0., 0.);
|
||
|
static const osg::Vec3f colorDarkGrey= osg::Vec3(0.25, 0.25, 0.25);
|
||
|
|
||
2 years ago
|
enum class DrawShape
|
||
|
{
|
||
|
Cube,
|
||
|
Cylinder,
|
||
|
WireCube,
|
||
|
};
|
||
2 years ago
|
|
||
2 years ago
|
struct DrawCall
|
||
2 years ago
|
{
|
||
2 years ago
|
osg::Vec3f mPosition;
|
||
2 years ago
|
osg::Vec3f mDims;
|
||
|
osg::Vec3f mColor;
|
||
|
|
||
2 years ago
|
DrawShape mDrawShape;
|
||
|
|
||
|
static DrawCall cube(osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite) { return { pos, dims, color, DrawShape::Cube}; }
|
||
|
static DrawCall wireCube(osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite) { return { pos, dims, color, DrawShape::WireCube}; }
|
||
|
static DrawCall cylinder(osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite) { return { pos, dims, color, DrawShape::Cylinder}; }
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
class DebugCustomDraw : public osg::Drawable
|
||
2 years ago
|
{
|
||
|
public:
|
||
2 years ago
|
DebugCustomDraw( std::vector<DrawCall>& cubesToDraw,osg::ref_ptr<osg::Geometry>& linesToDraw ,std::mutex& mutex) : mShapsToDraw(cubesToDraw),mLinesToDraw(linesToDraw), mDrawCallMutex(mutex) {}
|
||
2 years ago
|
|
||
2 years ago
|
std::vector<DrawCall>& mShapsToDraw;
|
||
2 years ago
|
osg::ref_ptr<osg::Geometry>& mLinesToDraw;
|
||
2 years ago
|
|
||
|
std::mutex& mDrawCallMutex;
|
||
|
|
||
|
osg::ref_ptr<osg::Geometry> mCubeGeometry;
|
||
2 years ago
|
osg::ref_ptr<osg::Geometry> mCylinderGeometry;
|
||
|
osg::ref_ptr<osg::Geometry> mWireCubeGeometry;
|
||
|
|
||
2 years ago
|
virtual osg::BoundingSphere computeBound() const
|
||
|
{
|
||
|
return osg::BoundingSphere();
|
||
|
}
|
||
|
|
||
|
virtual void drawImplementation(osg::RenderInfo&) const;
|
||
|
};
|
||
|
|
||
2 years ago
|
struct DebugLines;
|
||
|
|
||
2 years ago
|
struct DebugDrawer
|
||
|
{
|
||
2 years ago
|
DebugDrawer(Shader::ShaderManager& shaderManager,osg::ref_ptr<osg::Group> parentNode);
|
||
2 years ago
|
~DebugDrawer();
|
||
2 years ago
|
|
||
|
void update();
|
||
2 years ago
|
void drawCube(osg::Vec3f mPosition, osg::Vec3f mDims = osg::Vec3(50.,50.,50.), osg::Vec3f mColor = colorWhite);
|
||
|
void drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f mColor = colorWhite);
|
||
2 years ago
|
void addDrawCall(const DrawCall& draw);
|
||
2 years ago
|
void addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color = colorWhite);
|
||
2 years ago
|
|
||
2 years ago
|
private:
|
||
2 years ago
|
|
||
2 years ago
|
std::unique_ptr<DebugLines> mDebugLines;
|
||
|
|
||
2 years ago
|
std::vector<DrawCall> mShapesToDrawRead;
|
||
|
std::vector<DrawCall> mShapesToDrawWrite;
|
||
2 years ago
|
std::mutex mDrawCallMutex;
|
||
|
|
||
2 years ago
|
osg::ref_ptr<DebugCustomDraw> mCustomDebugDrawer;
|
||
2 years ago
|
osg::ref_ptr<osg::Group> mDebugDrawSceneObjects;
|
||
2 years ago
|
};
|
||
|
}
|
||
2 years ago
|
#endif // !
|