mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-15 16:39:41 +00:00
cleaned some code and fixed some naming issues
Moved debug draw to components, fixed some whitespace issues, added include guard fixed uniform name, removed old files Fixes some more whitespace weirdness
This commit is contained in:
parent
12b3424dd7
commit
2a980ecb50
7 changed files with 50 additions and 82 deletions
|
@ -23,7 +23,7 @@ add_openmw_dir (mwrender
|
||||||
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager
|
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager
|
||||||
bulletdebugdraw globalmap characterpreview camera localmap water terrainstorage ripplesimulation
|
bulletdebugdraw globalmap characterpreview camera localmap water terrainstorage ripplesimulation
|
||||||
renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover
|
renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover
|
||||||
postprocessor pingpongcull luminancecalculator pingpongcanvas transparentpass navmeshmode debugdraw
|
postprocessor pingpongcull luminancecalculator pingpongcanvas transparentpass navmeshmode
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwinput
|
add_openmw_dir (mwinput
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "../mwbase/luamanager.hpp"
|
#include "../mwbase/luamanager.hpp"
|
||||||
|
|
||||||
#include "../mwrender/renderingmanager.hpp"
|
#include "../mwrender/renderingmanager.hpp"
|
||||||
#include "../mwrender/debugdraw.hpp"
|
#include <components/debug/debugdraw.hpp>
|
||||||
|
|
||||||
#include "../mwmechanics/aibreathe.hpp"
|
#include "../mwmechanics/aibreathe.hpp"
|
||||||
|
|
||||||
|
@ -1628,7 +1628,8 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
debugRender.addDrawCall(MWRenderDebug::DrawCall::wireCube(actorPos));
|
debugRender.addDrawCall(MWRenderDebug::DrawCall::wireCube(actorPos));
|
||||||
}
|
}
|
||||||
|
debugRender.addLine(actorPos, actorPos + osg::Vec3(0., 0., 200.),MWRenderDebug::colorBlue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!isDead && (!godmode || !isPlayer) && actor.getPtr().getClass().getCreatureStats(actor.getPtr()).isParalyzed())
|
if (!isDead && (!godmode || !isPlayer) && actor.getPtr().getClass().getCreatureStats(actor.getPtr()).isParalyzed())
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
|
|
||||||
#include <components/detournavigator/navigator.hpp>
|
#include <components/detournavigator/navigator.hpp>
|
||||||
#include <components/detournavigator/navmeshcacheitem.hpp>
|
#include <components/detournavigator/navmeshcacheitem.hpp>
|
||||||
|
#include <components/debug/debugdraw.hpp>
|
||||||
|
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -82,7 +83,7 @@
|
||||||
#include "screenshotmanager.hpp"
|
#include "screenshotmanager.hpp"
|
||||||
#include "groundcover.hpp"
|
#include "groundcover.hpp"
|
||||||
#include "postprocessor.hpp"
|
#include "postprocessor.hpp"
|
||||||
#include "debugdraw.hpp"
|
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
@ -490,7 +491,7 @@ namespace MWRender
|
||||||
mViewer->getIncrementalCompileOperation()->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
|
mViewer->getIncrementalCompileOperation()->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebugDraw = std::make_unique<MWRenderDebug::DebugDrawer>(*this, mRootNode);
|
mDebugDraw = std::make_unique<MWRenderDebug::DebugDrawer>(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode);
|
||||||
mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
|
mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
|
||||||
|
|
||||||
mEffectManager = std::make_unique<EffectManager>(sceneRoot, mResourceSystem);
|
mEffectManager = std::make_unique<EffectManager>(sceneRoot, mResourceSystem);
|
||||||
|
|
|
@ -205,7 +205,7 @@ add_component_dir (stereo
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (debug
|
add_component_dir (debug
|
||||||
debugging debuglog gldebug
|
debugging debuglog gldebug debugdraw
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(NOT WIN32 AND NOT APPLE)
|
IF(NOT WIN32 AND NOT APPLE)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#include "debugdraw.hpp"
|
#include "debugdraw.hpp"
|
||||||
#include <components/resource/resourcesystem.hpp>
|
|
||||||
#include <components/resource/scenemanager.hpp>
|
|
||||||
#include <components/shader/shadermanager.hpp>
|
#include <components/shader/shadermanager.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +10,7 @@
|
||||||
#include <osg/GLExtensions>
|
#include <osg/GLExtensions>
|
||||||
|
|
||||||
|
|
||||||
static osg::Vec3 sphereCoordToCarthesian(float theta ,float phi ,float r )
|
static osg::Vec3 sphereCoordToCartesian(float theta ,float phi ,float r )
|
||||||
{
|
{
|
||||||
osg::Vec3 returnVec = osg::Vec3(0.0,0.0,0.0);
|
osg::Vec3 returnVec = osg::Vec3(0.0,0.0,0.0);
|
||||||
float phiToHorizontal = osg::PI_2 - phi ;
|
float phiToHorizontal = osg::PI_2 - phi ;
|
||||||
|
@ -68,7 +66,6 @@ static void generateWireCube(osg::Geometry& geom, float dim)
|
||||||
|
|
||||||
static void generateCube(osg::Geometry& geom, float dim)
|
static void generateCube(osg::Geometry& geom, float dim)
|
||||||
{
|
{
|
||||||
|
|
||||||
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
||||||
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> indices = new osg::DrawElementsUShort(osg::DrawElementsUShort::TRIANGLES, 0);
|
osg::ref_ptr<osg::DrawElementsUShort> indices = new osg::DrawElementsUShort(osg::DrawElementsUShort::TRIANGLES, 0);
|
||||||
|
@ -79,15 +76,12 @@ static void generateCube(osg::Geometry& geom, float dim)
|
||||||
osg::Vec3f u(0., 0., 0.);
|
osg::Vec3f u(0., 0., 0.);
|
||||||
osg::Vec3f v(0., 0., 0.);
|
osg::Vec3f v(0., 0., 0.);
|
||||||
int axis = i_face / 2;
|
int axis = i_face / 2;
|
||||||
//if (axis != 2)
|
|
||||||
// continue;
|
|
||||||
int dir = i_face % 2 == 0 ? -1 : 1;
|
int dir = i_face % 2 == 0 ? -1 : 1;
|
||||||
float float_dir = dir;
|
float float_dir = dir;
|
||||||
normale[axis] = float_dir;
|
normale[axis] = float_dir;
|
||||||
u[(axis + 1) % 3] = 1.0;
|
u[(axis + 1) % 3] = 1.0;
|
||||||
v[(axis + 2) % 3] = 1.0;
|
v[(axis + 2) % 3] = 1.0;
|
||||||
|
|
||||||
|
|
||||||
for (int i_point = 0; i_point < 4; i_point++)
|
for (int i_point = 0; i_point < 4; i_point++)
|
||||||
{
|
{
|
||||||
float iu = i_point % 2 == 1 ? float_dir : -float_dir;//This is to get the right triangle orientation when the normal changes*
|
float iu = i_point % 2 == 1 ? float_dir : -float_dir;//This is to get the right triangle orientation when the normal changes*
|
||||||
|
@ -113,7 +107,6 @@ static void generateCube(osg::Geometry& geom, float dim)
|
||||||
geom.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
geom.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
||||||
geom.setVertexAttribArray(1, normals, osg::Array::BIND_PER_VERTEX);
|
geom.setVertexAttribArray(1, normals, osg::Array::BIND_PER_VERTEX);
|
||||||
geom.addPrimitiveSet(indices);
|
geom.addPrimitiveSet(indices);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +125,7 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||||
for (int i = 0 ;i < subdiv; i++)
|
for (int i = 0 ;i < subdiv; i++)
|
||||||
{
|
{
|
||||||
float theta = (float(i )/ float(subdiv )) * osg::PI * 2.;
|
float theta = (float(i )/ float(subdiv )) * osg::PI * 2.;
|
||||||
osg::Vec3 pos= sphereCoordToCarthesian(theta, osg::PI_2, 1.);
|
osg::Vec3 pos= sphereCoordToCartesian(theta, osg::PI_2, 1.);
|
||||||
pos *= radius;
|
pos *= radius;
|
||||||
pos.z() = height / 2.;
|
pos.z() = height / 2.;
|
||||||
vertices->push_back(pos);
|
vertices->push_back(pos);
|
||||||
|
@ -158,7 +151,7 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||||
for (int i = 0 ;i < subdiv; i++)
|
for (int i = 0 ;i < subdiv; i++)
|
||||||
{
|
{
|
||||||
float theta = float(i)/ float(subdiv) * osg::PI*2.;
|
float theta = float(i)/ float(subdiv) * osg::PI*2.;
|
||||||
osg::Vec3 pos= sphereCoordToCarthesian(theta, osg::PI_2, 1.);
|
osg::Vec3 pos= sphereCoordToCartesian(theta, osg::PI_2, 1.);
|
||||||
pos *= radius;
|
pos *= radius;
|
||||||
pos.z() = - height / 2.;
|
pos.z() = - height / 2.;
|
||||||
vertices->push_back(pos);
|
vertices->push_back(pos);
|
||||||
|
@ -170,7 +163,7 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||||
for (int i = 0 ;i < subdiv; i++)
|
for (int i = 0 ;i < subdiv; i++)
|
||||||
{
|
{
|
||||||
float theta = float(i )/ float(subdiv) * osg::PI*2.;
|
float theta = float(i )/ float(subdiv) * osg::PI*2.;
|
||||||
osg::Vec3 normal = sphereCoordToCarthesian(theta, osg::PI_2, 1.);
|
osg::Vec3 normal = sphereCoordToCartesian(theta, osg::PI_2, 1.);
|
||||||
auto posTop = normal;
|
auto posTop = normal;
|
||||||
posTop *= radius;
|
posTop *= radius;
|
||||||
auto posBot = posTop;
|
auto posBot = posTop;
|
||||||
|
@ -199,7 +192,6 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||||
indices->push_back(v4);
|
indices->push_back(v4);
|
||||||
indices->push_back(v3);
|
indices->push_back(v3);
|
||||||
indices->push_back(v1);
|
indices->push_back(v1);
|
||||||
|
|
||||||
}
|
}
|
||||||
for (int i = 0 ;i < subdiv; i++)
|
for (int i = 0 ;i < subdiv; i++)
|
||||||
{
|
{
|
||||||
|
@ -227,7 +219,7 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||||
|
|
||||||
namespace MWRenderDebug
|
namespace MWRenderDebug
|
||||||
{
|
{
|
||||||
void CubeCustomDraw::drawImplementation(osg::RenderInfo& renderInfo) const
|
void DebugCustomDraw::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||||
{
|
{
|
||||||
auto state = renderInfo.getState();
|
auto state = renderInfo.getState();
|
||||||
osg::GLExtensions* ext = osg::GLExtensions::Get( state->getContextID(), true );
|
osg::GLExtensions* ext = osg::GLExtensions::Get( state->getContextID(), true );
|
||||||
|
@ -243,24 +235,21 @@ namespace MWRenderDebug
|
||||||
std::lock_guard lock(mDrawCallMutex);
|
std::lock_guard lock(mDrawCallMutex);
|
||||||
|
|
||||||
osg::Uniform* uTrans = const_cast<osg::Uniform*>( stateSet->getUniform("trans"));
|
osg::Uniform* uTrans = const_cast<osg::Uniform*>( stateSet->getUniform("trans"));
|
||||||
osg::Uniform* uCol = const_cast<osg::Uniform*>( stateSet->getUniform("passColor"));
|
osg::Uniform* uCol = const_cast<osg::Uniform*>( stateSet->getUniform("color"));
|
||||||
osg::Uniform* uScale = const_cast<osg::Uniform*>( stateSet->getUniform("scale"));
|
osg::Uniform* uScale = const_cast<osg::Uniform*>( stateSet->getUniform("scale"));
|
||||||
osg::Uniform* uUseNormalAsColor = const_cast<osg::Uniform*>( stateSet->getUniform("useNormalAsColor"));
|
osg::Uniform* uUseNormalAsColor = const_cast<osg::Uniform*>( stateSet->getUniform("useNormalAsColor"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto transLocation = pcp->getUniformLocation(uTrans->getNameID() );
|
auto transLocation = pcp->getUniformLocation(uTrans->getNameID() );
|
||||||
auto colLocation = pcp->getUniformLocation(uCol->getNameID() );
|
auto colLocation = pcp->getUniformLocation(uCol->getNameID() );
|
||||||
auto scaleLocation = pcp->getUniformLocation(uScale->getNameID() );
|
auto scaleLocation = pcp->getUniformLocation(uScale->getNameID() );
|
||||||
auto normalAsColorLocation = pcp->getUniformLocation(uUseNormalAsColor->getNameID() );
|
auto normalAsColorLocation = pcp->getUniformLocation(uUseNormalAsColor->getNameID() );
|
||||||
|
|
||||||
|
|
||||||
ext->glUniform3f(transLocation, 0., 0., 0.);
|
ext->glUniform3f(transLocation, 0., 0., 0.);
|
||||||
ext->glUniform3f(colLocation, 1., 1., 1.);
|
ext->glUniform3f(colLocation, 1., 1., 1.);
|
||||||
ext->glUniform3f(scaleLocation, 1., 1., 1.);
|
ext->glUniform3f(scaleLocation, 1., 1., 1.);
|
||||||
ext->glUniform1i(normalAsColorLocation, 1);
|
ext->glUniform1i(normalAsColorLocation, 1);
|
||||||
|
|
||||||
mlinesToDraw->drawImplementation(renderInfo);
|
mLinesToDraw->drawImplementation(renderInfo);
|
||||||
|
|
||||||
ext->glUniform1i(normalAsColorLocation, 0);
|
ext->glUniform1i(normalAsColorLocation, 0);
|
||||||
|
|
||||||
|
@ -270,17 +259,10 @@ namespace MWRenderDebug
|
||||||
osg::Vec3f color = shapeToDraw.mColor;
|
osg::Vec3f color = shapeToDraw.mColor;
|
||||||
osg::Vec3f scale = shapeToDraw.mDims;
|
osg::Vec3f scale = shapeToDraw.mDims;
|
||||||
|
|
||||||
|
ext->glUniform3f(transLocation, translation.x(), translation.y(), translation.z());
|
||||||
|
ext->glUniform3f(colLocation, color.x(), color.y(), color.z());
|
||||||
|
ext->glUniform3f(scaleLocation, scale.x(), scale.y(), scale.z());
|
||||||
|
|
||||||
if (uTrans)
|
|
||||||
ext->glUniform3f(transLocation, translation.x(), translation.y(), translation.z());
|
|
||||||
if (uCol)
|
|
||||||
{
|
|
||||||
ext->glUniform3f(colLocation, color.x(), color.y(), color.z());
|
|
||||||
}
|
|
||||||
if (uScale)
|
|
||||||
{
|
|
||||||
ext->glUniform3f(scaleLocation, scale.x(), scale.y(), scale.z());
|
|
||||||
}
|
|
||||||
switch (shapeToDraw.mDrawShape)
|
switch (shapeToDraw.mDrawShape)
|
||||||
{
|
{
|
||||||
case DrawShape::Cube:
|
case DrawShape::Cube:
|
||||||
|
@ -302,16 +284,8 @@ namespace MWRenderDebug
|
||||||
|
|
||||||
static void makeLineInstance( osg::Geometry& lines)
|
static void makeLineInstance( osg::Geometry& lines)
|
||||||
{
|
{
|
||||||
auto vertices = new osg::Vec3Array;
|
auto vertices = new osg::Vec3Array;
|
||||||
auto color = new osg::Vec3Array;
|
auto color = new osg::Vec3Array;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
vertices->push_back(osg::Vec3());
|
|
||||||
vertices->push_back(osg::Vec3(0., 0., 0.));
|
|
||||||
color->push_back(osg::Vec3(1., 1., 1.));
|
|
||||||
color->push_back(osg::Vec3(1., 1., 1.));
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.setUseVertexArrayObject(true);
|
lines.setUseVertexArrayObject(true);
|
||||||
lines.setUseDisplayList(false);
|
lines.setUseDisplayList(false);
|
||||||
|
@ -321,19 +295,15 @@ namespace MWRenderDebug
|
||||||
lines.setVertexAttribArray(1, color, osg::Array::BIND_PER_VERTEX);
|
lines.setVertexAttribArray(1, color, osg::Array::BIND_PER_VERTEX);
|
||||||
|
|
||||||
lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size()));
|
lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size()));
|
||||||
|
|
||||||
//lines.setStateSet(stateSet->clone(osg::CopyOp::DEEP_COPY_ALL)->asStateSet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLines()
|
DebugLines()
|
||||||
{
|
{
|
||||||
|
|
||||||
mLinesWrite = new osg::Geometry();
|
mLinesWrite = new osg::Geometry();
|
||||||
mLinesRead = new osg::Geometry();
|
mLinesRead = new osg::Geometry();
|
||||||
|
|
||||||
makeLineInstance(*mLinesRead);
|
makeLineInstance(*mLinesRead);
|
||||||
makeLineInstance(*mLinesWrite);
|
makeLineInstance(*mLinesWrite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(std::mutex& mutex)
|
void update(std::mutex& mutex)
|
||||||
|
@ -346,30 +316,28 @@ namespace MWRenderDebug
|
||||||
mLinesWrite.swap(mLinesRead);
|
mLinesWrite.swap(mLinesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static_cast<osg::Vec3Array*>(mLinesWrite->getVertexAttribArray(0))->clear();
|
||||||
static_cast<osg::Vec3Array*>(mLinesWrite->getVertexAttribArray(0))->resize(2, osg::Vec3());
|
static_cast<osg::Vec3Array*>(mLinesWrite->getVertexAttribArray(1))->clear();
|
||||||
static_cast<osg::Vec3Array*>(mLinesWrite->getVertexAttribArray(1))->resize(2, osg::Vec3());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> mLinesWrite;
|
osg::ref_ptr<osg::Geometry> mLinesWrite;
|
||||||
osg::ref_ptr<osg::Geometry> mLinesRead;
|
osg::ref_ptr<osg::Geometry> mLinesRead;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
MWRenderDebug::DebugDrawer::DebugDrawer(MWRender::RenderingManager& renderingManager,osg::ref_ptr<osg::Group> parentNode)
|
MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager,osg::ref_ptr<osg::Group> parentNode)
|
||||||
{
|
{
|
||||||
auto& shaderManager = renderingManager.getResourceSystem()->getSceneManager()->getShaderManager();
|
|
||||||
auto vertexShader = shaderManager.getShader("debugDraw_vertex.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::VERTEX);
|
auto vertexShader = shaderManager.getShader("debugDraw_vertex.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::VERTEX);
|
||||||
auto fragmentShader = shaderManager.getShader("debugDraw_fragment.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::FRAGMENT);
|
auto fragmentShader = shaderManager.getShader("debugDraw_fragment.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::FRAGMENT);
|
||||||
|
|
||||||
auto program = shaderManager.getProgram(vertexShader, fragmentShader);
|
auto program = shaderManager.getProgram(vertexShader, fragmentShader);
|
||||||
mDebugLines = std::make_unique<DebugLines>();
|
mDebugLines = std::make_unique<DebugLines>();
|
||||||
mcustomCubesDrawer = new CubeCustomDraw(mShapesToDrawRead,mDebugLines->mLinesRead, mDrawCallMutex);
|
mCustomDebugDrawer = new DebugCustomDraw(mShapesToDrawRead,mDebugLines->mLinesRead, mDrawCallMutex);
|
||||||
|
|
||||||
mDebugDrawSceneObjects = new osg::Group;
|
mDebugDrawSceneObjects = new osg::Group;
|
||||||
mDebugDrawSceneObjects->setCullingActive(false);
|
mDebugDrawSceneObjects->setCullingActive(false);
|
||||||
osg::StateSet* stateset = mDebugDrawSceneObjects->getOrCreateStateSet();
|
osg::StateSet* stateset = mDebugDrawSceneObjects->getOrCreateStateSet();
|
||||||
stateset->addUniform(new osg::Uniform("passColor", osg::Vec3f(1., 1., 1.)));
|
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("trans", osg::Vec3f(0., 0., 0.)));
|
||||||
stateset->addUniform(new osg::Uniform("scale", osg::Vec3f(1., 1., 1.)));
|
stateset->addUniform(new osg::Uniform("scale", osg::Vec3f(1., 1., 1.)));
|
||||||
stateset->addUniform(new osg::Uniform("useNormalAsColor", 0));
|
stateset->addUniform(new osg::Uniform("useNormalAsColor", 0));
|
||||||
|
@ -382,22 +350,22 @@ MWRenderDebug::DebugDrawer::DebugDrawer(MWRender::RenderingManager& renderingMan
|
||||||
cubeGeometry->setSupportsDisplayList(false);
|
cubeGeometry->setSupportsDisplayList(false);
|
||||||
cubeGeometry->setUseVertexBufferObjects(true);
|
cubeGeometry->setUseVertexBufferObjects(true);
|
||||||
generateCube(*cubeGeometry,1.);
|
generateCube(*cubeGeometry,1.);
|
||||||
mcustomCubesDrawer->mCubeGeometry = cubeGeometry;
|
mCustomDebugDrawer ->mCubeGeometry = cubeGeometry;
|
||||||
|
|
||||||
auto cylinderGeom = new osg::Geometry;
|
auto cylinderGeom = new osg::Geometry;
|
||||||
cylinderGeom->setSupportsDisplayList(false);
|
cylinderGeom->setSupportsDisplayList(false);
|
||||||
cylinderGeom->setUseVertexBufferObjects(true);
|
cylinderGeom->setUseVertexBufferObjects(true);
|
||||||
generateCylinder(*cylinderGeom, .5, 1., 20);
|
generateCylinder(*cylinderGeom, .5, 1., 20);
|
||||||
mcustomCubesDrawer->mCylinderGeometry = cylinderGeom;
|
mCustomDebugDrawer ->mCylinderGeometry = cylinderGeom;
|
||||||
|
|
||||||
auto wireCube = new osg::Geometry;
|
auto wireCube = new osg::Geometry;
|
||||||
wireCube->setSupportsDisplayList(false);
|
wireCube->setSupportsDisplayList(false);
|
||||||
wireCube->setUseVertexBufferObjects(true);
|
wireCube->setUseVertexBufferObjects(true);
|
||||||
generateWireCube(*wireCube, 1.);
|
generateWireCube(*wireCube, 1.);
|
||||||
mcustomCubesDrawer->mWireCubeGeometry = wireCube;
|
mCustomDebugDrawer->mWireCubeGeometry = wireCube;
|
||||||
mcustomCubesDrawer->setStateSet( stateset);
|
mCustomDebugDrawer->setStateSet(stateset);
|
||||||
|
|
||||||
mDebugDrawSceneObjects->addChild(mcustomCubesDrawer);
|
mDebugDrawSceneObjects->addChild(mCustomDebugDrawer);
|
||||||
|
|
||||||
parentNode->addChild(mDebugDrawSceneObjects);
|
parentNode->addChild(mDebugDrawSceneObjects);
|
||||||
}
|
}
|
||||||
|
@ -436,8 +404,8 @@ void MWRenderDebug::DebugDrawer::addDrawCall(const DrawCall& draw)
|
||||||
|
|
||||||
void MWRenderDebug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color)
|
void MWRenderDebug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color)
|
||||||
{
|
{
|
||||||
auto vertices = static_cast<osg::Vec3Array*>(mDebugLines->mLinesWrite->getVertexAttribArray(0));
|
auto vertices = static_cast<osg::Vec3Array*>(mDebugLines->mLinesWrite->getVertexAttribArray(0));
|
||||||
auto colors = static_cast<osg::Vec3Array*>(mDebugLines->mLinesWrite->getVertexAttribArray(1));
|
auto colors = static_cast<osg::Vec3Array*>(mDebugLines->mLinesWrite->getVertexAttribArray(1));
|
||||||
|
|
||||||
vertices->push_back(start);
|
vertices->push_back(start);
|
||||||
vertices->push_back(end);
|
vertices->push_back(end);
|
|
@ -1,14 +1,19 @@
|
||||||
#pragma once
|
#ifndef OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
||||||
|
#define OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
||||||
|
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "renderingmanager.hpp"
|
|
||||||
|
|
||||||
namespace osg
|
namespace osg
|
||||||
{
|
{
|
||||||
class Group;
|
class Group;
|
||||||
class Geometry;
|
class Geometry;
|
||||||
}
|
}
|
||||||
|
namespace Shader
|
||||||
|
{
|
||||||
|
class ShaderManager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWRenderDebug
|
namespace MWRenderDebug
|
||||||
{
|
{
|
||||||
|
@ -37,16 +42,15 @@ namespace MWRenderDebug
|
||||||
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 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 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}; }
|
static DrawCall cylinder(osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite) { return { pos, dims, color, DrawShape::Cylinder}; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CubeCustomDraw : public osg::Drawable
|
class DebugCustomDraw : public osg::Drawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CubeCustomDraw( std::vector<DrawCall>& cubesToDraw,osg::ref_ptr<osg::Geometry>& linesToDraw ,std::mutex& mutex) : mShapsToDraw(cubesToDraw),mlinesToDraw(linesToDraw), mDrawCallMutex(mutex) {}
|
DebugCustomDraw( std::vector<DrawCall>& cubesToDraw,osg::ref_ptr<osg::Geometry>& linesToDraw ,std::mutex& mutex) : mShapsToDraw(cubesToDraw),mLinesToDraw(linesToDraw), mDrawCallMutex(mutex) {}
|
||||||
|
|
||||||
std::vector<DrawCall>& mShapsToDraw;
|
std::vector<DrawCall>& mShapsToDraw;
|
||||||
osg::ref_ptr<osg::Geometry>& mlinesToDraw;
|
osg::ref_ptr<osg::Geometry>& mLinesToDraw;
|
||||||
|
|
||||||
std::mutex& mDrawCallMutex;
|
std::mutex& mDrawCallMutex;
|
||||||
|
|
||||||
|
@ -54,21 +58,19 @@ namespace MWRenderDebug
|
||||||
osg::ref_ptr<osg::Geometry> mCylinderGeometry;
|
osg::ref_ptr<osg::Geometry> mCylinderGeometry;
|
||||||
osg::ref_ptr<osg::Geometry> mWireCubeGeometry;
|
osg::ref_ptr<osg::Geometry> mWireCubeGeometry;
|
||||||
|
|
||||||
|
|
||||||
virtual osg::BoundingSphere computeBound() const
|
virtual osg::BoundingSphere computeBound() const
|
||||||
{
|
{
|
||||||
return osg::BoundingSphere();
|
return osg::BoundingSphere();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void drawImplementation(osg::RenderInfo&) const;
|
virtual void drawImplementation(osg::RenderInfo&) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DebugLines;
|
struct DebugLines;
|
||||||
|
|
||||||
struct DebugDrawer
|
struct DebugDrawer
|
||||||
{
|
{
|
||||||
DebugDrawer(MWRender::RenderingManager& manager,osg::ref_ptr<osg::Group> parentNode);
|
DebugDrawer(Shader::ShaderManager& shaderManager,osg::ref_ptr<osg::Group> parentNode);
|
||||||
~DebugDrawer();
|
~DebugDrawer();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
@ -85,7 +87,8 @@ namespace MWRenderDebug
|
||||||
std::vector<DrawCall> mShapesToDrawWrite;
|
std::vector<DrawCall> mShapesToDrawWrite;
|
||||||
std::mutex mDrawCallMutex;
|
std::mutex mDrawCallMutex;
|
||||||
|
|
||||||
osg::ref_ptr<CubeCustomDraw> mcustomCubesDrawer;
|
osg::ref_ptr<DebugCustomDraw> mCustomDebugDrawer;
|
||||||
osg::ref_ptr<osg::Group> mDebugDrawSceneObjects;
|
osg::ref_ptr<osg::Group> mDebugDrawSceneObjects;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endif // !
|
|
@ -3,12 +3,7 @@
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
|
uniform vec3 color;
|
||||||
// vec4 mw_modelToClip(vec4 pos);
|
|
||||||
// vec4 mw_modelToView(vec4 pos);
|
|
||||||
// vec4 mw_viewToClip(vec4 pos);
|
|
||||||
|
|
||||||
uniform vec3 passColor;
|
|
||||||
uniform vec3 trans;
|
uniform vec3 trans;
|
||||||
uniform vec3 scale;
|
uniform vec3 scale;
|
||||||
uniform int useNormalAsColor;
|
uniform int useNormalAsColor;
|
||||||
|
@ -24,5 +19,5 @@ void main()
|
||||||
gl_Position = projectionMatrix * gl_ModelViewMatrix * vec4(aPos * scale + trans, 1.);
|
gl_Position = projectionMatrix * gl_ModelViewMatrix * vec4(aPos * scale + trans, 1.);
|
||||||
|
|
||||||
vertexNormal = useNormalAsColor == 1? vec3(1.,1.,1.) : aNormal ;
|
vertexNormal = useNormalAsColor == 1? vec3(1.,1.,1.) : aNormal ;
|
||||||
vertexColor = useNormalAsColor == 1? aNormal : passColor.xyz;
|
vertexColor = useNormalAsColor == 1? aNormal : color.xyz;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue