mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 22:45:36 +00:00
DebugCustomDraw: Correct PerContextProgram use, clean up drawImplementation
This commit is contained in:
parent
4df62d53db
commit
d9ee54ae98
1 changed files with 20 additions and 34 deletions
|
@ -265,59 +265,45 @@ namespace Debug
|
||||||
|
|
||||||
const osg::StateSet* stateSet = getStateSet();
|
const osg::StateSet* stateSet = getStateSet();
|
||||||
|
|
||||||
auto program = static_cast<const osg::Program*>(stateSet->getAttribute(osg::StateAttribute::PROGRAM));
|
const osg::Program::PerContextProgram& pcp = *state->getLastAppliedProgramObject();
|
||||||
const osg::Program::PerContextProgram* pcp = program->getPCP(*state);
|
auto transLocation = pcp.getUniformLocation(stateSet->getUniform("trans")->getNameID());
|
||||||
if (!pcp)
|
auto colLocation = pcp.getUniformLocation(stateSet->getUniform("color")->getNameID());
|
||||||
{
|
auto scaleLocation = pcp.getUniformLocation(stateSet->getUniform("scale")->getNameID());
|
||||||
return;
|
auto normalAsColorLocation = pcp.getUniformLocation(stateSet->getUniform("useNormalAsColor")->getNameID());
|
||||||
}
|
|
||||||
|
|
||||||
const osg::Uniform* uTrans = stateSet->getUniform("trans");
|
auto drawPrimitive = [&](const osg::Drawable* primitive, const osg::Vec3f& pos, const osg::Vec3f& color,
|
||||||
const osg::Uniform* uCol = stateSet->getUniform("color");
|
const osg::Vec3f& scale, const bool normalAsColor) {
|
||||||
const osg::Uniform* uScale = stateSet->getUniform("scale");
|
ext->glUniform3f(transLocation, pos.x(), pos.y(), pos.z());
|
||||||
const osg::Uniform* uUseNormalAsColor = stateSet->getUniform("useNormalAsColor");
|
ext->glUniform3f(colLocation, color.x(), color.y(), color.z());
|
||||||
|
ext->glUniform3f(scaleLocation, scale.x(), scale.y(), scale.z());
|
||||||
|
ext->glUniform1i(normalAsColorLocation, normalAsColor);
|
||||||
|
primitive->drawImplementation(renderInfo);
|
||||||
|
};
|
||||||
|
|
||||||
auto transLocation = pcp->getUniformLocation(uTrans->getNameID());
|
drawPrimitive(mLinesToDraw, { 0.f, 0.f, 0.f }, { 1.f, 1.f, 1.f }, { 1.f, 1.f, 1.f }, true);
|
||||||
auto colLocation = pcp->getUniformLocation(uCol->getNameID());
|
|
||||||
auto scaleLocation = pcp->getUniformLocation(uScale->getNameID());
|
|
||||||
auto normalAsColorLocation = pcp->getUniformLocation(uUseNormalAsColor->getNameID());
|
|
||||||
|
|
||||||
ext->glUniform3f(transLocation, 0., 0., 0.);
|
|
||||||
ext->glUniform3f(colLocation, 1., 1., 1.);
|
|
||||||
ext->glUniform3f(scaleLocation, 1., 1., 1.);
|
|
||||||
ext->glUniform1i(normalAsColorLocation, true);
|
|
||||||
|
|
||||||
mLinesToDraw->drawImplementation(renderInfo);
|
|
||||||
|
|
||||||
ext->glUniform1i(normalAsColorLocation, false);
|
|
||||||
|
|
||||||
for (const auto& shapeToDraw : mShapesToDraw)
|
for (const auto& shapeToDraw : mShapesToDraw)
|
||||||
{
|
{
|
||||||
osg::Vec3f translation = shapeToDraw.mPosition;
|
const osg::Geometry* geometry = nullptr;
|
||||||
osg::Vec3f color = shapeToDraw.mColor;
|
|
||||||
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());
|
|
||||||
|
|
||||||
switch (shapeToDraw.mDrawShape)
|
switch (shapeToDraw.mDrawShape)
|
||||||
{
|
{
|
||||||
case DrawShape::Cube:
|
case DrawShape::Cube:
|
||||||
mCubeGeometry->drawImplementation(renderInfo);
|
geometry = mCubeGeometry;
|
||||||
break;
|
break;
|
||||||
case DrawShape::Cylinder:
|
case DrawShape::Cylinder:
|
||||||
mCylinderGeometry->drawImplementation(renderInfo);
|
geometry = mCylinderGeometry;
|
||||||
break;
|
break;
|
||||||
case DrawShape::WireCube:
|
case DrawShape::WireCube:
|
||||||
mWireCubeGeometry->drawImplementation(renderInfo);
|
geometry = mWireCubeGeometry;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
drawPrimitive(geometry, shapeToDraw.mPosition, shapeToDraw.mColor, shapeToDraw.mDims, false);
|
||||||
}
|
}
|
||||||
mShapesToDraw.clear();
|
mShapesToDraw.clear();
|
||||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexArray())->clear();
|
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexArray())->clear();
|
||||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getNormalArray())->clear();
|
static_cast<osg::Vec3Array*>(mLinesToDraw->getNormalArray())->clear();
|
||||||
static_cast<osg::DrawArrays*>(mLinesToDraw->getPrimitiveSet(0))->setCount(0);
|
static_cast<osg::DrawArrays*>(mLinesToDraw->getPrimitiveSet(0))->setCount(0);
|
||||||
|
pcp.resetAppliedUniforms();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue