Add simple conditions (no opengl related tests) to buffers, stages and attachments
This commit is contained in:
parent
b1f098d959
commit
bb16463d63
4 changed files with 111 additions and 32 deletions
|
@ -32,7 +32,6 @@
|
|||
#include <simgear/structure/OSGVersion.hxx>
|
||||
#include <simgear/scene/material/EffectCullVisitor.hxx>
|
||||
#include <simgear/scene/util/RenderConstants.hxx>
|
||||
#include <simgear/scene/tgdb/userdata.hxx>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
@ -1036,8 +1035,6 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
|
|||
CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer,
|
||||
SGPropertyNode* gnode)
|
||||
{
|
||||
sgUserDataInit( globals->get_props() );
|
||||
|
||||
CameraGroup* cgroup = new CameraGroup(viewer);
|
||||
for (int i = 0; i < gnode->nChildren(); ++i) {
|
||||
SGPropertyNode* pNode = gnode->getChild(i);
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include <simgear/scene/util/SGSceneUserData.hxx>
|
||||
#include <simgear/scene/tgdb/GroundLightManager.hxx>
|
||||
#include <simgear/scene/tgdb/pt_lights.hxx>
|
||||
#include <simgear/scene/tgdb/userdata.hxx>
|
||||
#include <simgear/structure/OSGUtils.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
@ -502,6 +503,8 @@ public:
|
|||
void
|
||||
FGRenderer::init( void )
|
||||
{
|
||||
sgUserDataInit( globals->get_props() );
|
||||
|
||||
_classicalRenderer = !fgGetBool("/sim/rendering/rembrandt/enabled", false);
|
||||
_shadowMapSize = fgGetInt( "/sim/rendering/shadows/map-size", 4096 );
|
||||
fgAddChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
|
||||
|
@ -822,6 +825,13 @@ osg::Camera* FGRenderer::buildDefaultDeferredGeometryCamera( CameraInfo* info, o
|
|||
return buildDeferredGeometryCamera(info, gc, GEOMETRY_CAMERA, attachments);
|
||||
}
|
||||
|
||||
void buildAttachments(CameraInfo* info, osg::Camera* camera, const std::string& name, const std::vector<ref_ptr<FGRenderingPipeline::Attachment> > &attachments) {
|
||||
BOOST_FOREACH(ref_ptr<FGRenderingPipeline::Attachment> attachment, attachments) {
|
||||
if (attachment->valid())
|
||||
attachBufferToCamera( info, camera, attachment->component, name, attachment->buffer );
|
||||
}
|
||||
}
|
||||
|
||||
osg::Camera* FGRenderer::buildDeferredGeometryCamera( CameraInfo* info, osg::GraphicsContext* gc, const std::string& name, const std::vector<ref_ptr<FGRenderingPipeline::Attachment> > &attachments )
|
||||
{
|
||||
osg::Camera* camera = new osg::Camera;
|
||||
|
@ -837,9 +847,7 @@ osg::Camera* FGRenderer::buildDeferredGeometryCamera( CameraInfo* info, osg::Gra
|
|||
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
|
||||
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0);
|
||||
camera->setViewport( new osg::Viewport );
|
||||
BOOST_FOREACH(ref_ptr<FGRenderingPipeline::Attachment> attachment, attachments) {
|
||||
attachBufferToCamera( info, camera, attachment->component, name, attachment->buffer );
|
||||
}
|
||||
buildAttachments(info, camera, name, attachments);
|
||||
camera->setDrawBuffer(GL_FRONT);
|
||||
camera->setReadBuffer(GL_FRONT);
|
||||
|
||||
|
@ -907,9 +915,7 @@ osg::Camera* FGRenderer::buildDeferredShadowCamera( CameraInfo* info, osg::Graph
|
|||
mainShadowCamera->setAllowEventFocus(false);
|
||||
mainShadowCamera->setGraphicsContext(gc);
|
||||
mainShadowCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
|
||||
BOOST_FOREACH(ref_ptr<FGRenderingPipeline::Attachment> attachment, attachments) {
|
||||
attachBufferToCamera( info, mainShadowCamera, attachment->component, name, attachment->buffer );
|
||||
}
|
||||
buildAttachments(info, mainShadowCamera, name, attachments);
|
||||
mainShadowCamera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
mainShadowCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
mainShadowCamera->setProjectionMatrix(osg::Matrix::identity());
|
||||
|
@ -1131,9 +1137,7 @@ osg::Camera* FGRenderer::buildDeferredLightingCamera( CameraInfo* info, osg::Gra
|
|||
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 50);
|
||||
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
|
||||
camera->setViewport( new osg::Viewport );
|
||||
BOOST_FOREACH(ref_ptr<FGRenderingPipeline::Attachment> attachment, attachments) {
|
||||
attachBufferToCamera( info, camera, attachment->component, name, attachment->buffer );
|
||||
}
|
||||
buildAttachments(info, camera, name, attachments);
|
||||
camera->setDrawBuffer(GL_FRONT);
|
||||
camera->setReadBuffer(GL_FRONT);
|
||||
camera->setClearColor( osg::Vec4( 0., 0., 0., 1. ) );
|
||||
|
@ -1289,9 +1293,7 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, osg::Gr
|
|||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
camera->setRenderOrder(osg::Camera::NESTED_RENDER, stage->orderNum);
|
||||
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
|
||||
BOOST_FOREACH(ref_ptr<FGRenderingPipeline::Attachment> attachment, stage->attachments) {
|
||||
attachBufferToCamera( info, camera, attachment->component, stage->name, attachment->buffer );
|
||||
}
|
||||
buildAttachments(info, camera, stage->name, stage->attachments);
|
||||
camera->setDrawBuffer(GL_FRONT);
|
||||
camera->setReadBuffer(GL_FRONT);
|
||||
camera->setClearColor( osg::Vec4( 1., 1., 1., 1. ) );
|
||||
|
@ -1405,6 +1407,9 @@ void FGRenderer::buildStage(FGRenderingPipeline* rpipe, CameraInfo* info,
|
|||
const osg::Matrix& projection,
|
||||
osg::GraphicsContext* gc)
|
||||
{
|
||||
if (!stage->valid())
|
||||
return;
|
||||
|
||||
ref_ptr<Camera> camera;
|
||||
if (stage->type == "geometry")
|
||||
camera = buildDeferredGeometryCamera(info, gc, stage->name, stage->attachments);
|
||||
|
@ -1432,6 +1437,7 @@ void FGRenderer::buildBuffers(FGRenderingPipeline* rpipe, CameraInfo* info)
|
|||
{
|
||||
for (size_t i = 0; i < rpipe->buffers.size(); ++i) {
|
||||
osg::ref_ptr<FGRenderingPipeline::Buffer> buffer = rpipe->buffers[i];
|
||||
if (buffer->valid()) {
|
||||
bool fullscreen = buffer->width == -1 && buffer->height == -1;
|
||||
info->addBuffer(buffer->name, buildDeferredBuffer( buffer->internalFormat,
|
||||
buffer->sourceFormat,
|
||||
|
@ -1443,6 +1449,7 @@ void FGRenderer::buildBuffers(FGRenderingPipeline* rpipe, CameraInfo* info)
|
|||
info->getBuffer(buffer->name)->setTextureSize(buffer->width, buffer->height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CameraInfo* FGRenderer::buildCameraFromRenderingPipeline(FGRenderingPipeline* rpipe, CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
|
||||
|
|
|
@ -85,6 +85,40 @@ FGRenderingPipeline* makeRenderingPipeline(const std::string& name,
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
FGRenderingPipeline::Conditionable::parseCondition(SGPropertyNode* prop)
|
||||
{
|
||||
const SGPropertyNode* predProp = prop->getChild("condition");
|
||||
if (!predProp) {
|
||||
setAlwaysValid(true);
|
||||
} else {
|
||||
try {
|
||||
flightgear::PipelinePredParser parser;
|
||||
SGExpressionb* validExp = dynamic_cast<SGExpressionb*>(parser.read(predProp->getChild(0)));
|
||||
if (validExp)
|
||||
setValidExpression(validExp);
|
||||
else
|
||||
throw simgear::expression::ParseError("pipeline condition is not a boolean expression");
|
||||
}
|
||||
catch (simgear::expression::ParseError& except)
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_ALERT,
|
||||
"parsing pipeline condition " << except.getMessage());
|
||||
setAlwaysValid(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FGRenderingPipeline::Conditionable::setValidExpression(SGExpressionb* exp)
|
||||
{
|
||||
_validExpression = exp;
|
||||
}
|
||||
|
||||
bool FGRenderingPipeline::Conditionable::valid()
|
||||
{
|
||||
return _alwaysValid || _validExpression->getValue();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void findAttrOrHex(const simgear::effect::EffectPropertyMap<T>& pMap,
|
||||
const SGPropertyNode* prop,
|
||||
|
@ -172,11 +206,23 @@ FGRenderingPipeline::Buffer::Buffer(SGPropertyNode* prop)
|
|||
if (!nameProp.valid()) {
|
||||
throw sg_exception("Buffer name is mandatory");
|
||||
}
|
||||
internalFormat = GL_RGBA8;
|
||||
sourceFormat = GL_RGBA;
|
||||
sourceType = GL_UNSIGNED_BYTE;
|
||||
wrapMode = GL_CLAMP_TO_BORDER_ARB;
|
||||
name = nameProp->getStringValue();
|
||||
findAttrOrHex(internalFormats, prop->getChild("internal-format"), internalFormat);
|
||||
findAttrOrHex(sourceFormats, prop->getChild("source-format"), sourceFormat);
|
||||
findAttrOrHex(sourceTypes, prop->getChild("source-type"), sourceType);
|
||||
findAttrOrHex(wrapModes, prop->getChild("wrap-mode"), wrapMode);
|
||||
SGPropertyNode* internalFormatProp = prop->getChild("internal-format");
|
||||
if (internalFormatProp)
|
||||
findAttrOrHex(internalFormats, internalFormatProp, internalFormat);
|
||||
SGPropertyNode* sourceFormatProp = prop->getChild("source-format");
|
||||
if (sourceFormatProp)
|
||||
findAttrOrHex(sourceFormats, sourceFormatProp, sourceFormat);
|
||||
SGPropertyNode* sourceTypeProp = prop->getChild("source-type");
|
||||
if (sourceTypeProp)
|
||||
findAttrOrHex(sourceTypes, sourceTypeProp, sourceType);
|
||||
SGPropertyNode* wrapModeProp = prop->getChild("wrap-mode");
|
||||
if (wrapModeProp)
|
||||
findAttrOrHex(wrapModes, wrapModeProp, wrapMode);
|
||||
SGConstPropertyNode_ptr widthProp = getPropertyChild(prop, "width");
|
||||
if (!widthProp.valid())
|
||||
width = -1;
|
||||
|
@ -195,6 +241,8 @@ FGRenderingPipeline::Buffer::Buffer(SGPropertyNode* prop)
|
|||
|
||||
scaleFactor = prop->getFloatValue("scale-factor", 1.f);
|
||||
shadowComparison = prop->getBoolValue("shadow-comparison", false);
|
||||
|
||||
parseCondition(prop);
|
||||
}
|
||||
|
||||
simgear::effect::EffectNameValue<osg::Camera::BufferComponent> componentsInit[] =
|
||||
|
@ -232,6 +280,8 @@ FGRenderingPipeline::Stage::Stage(SGPropertyNode* prop)
|
|||
for (int i = 0; i < (int)attachments.size(); ++i) {
|
||||
this->attachments.push_back(new FGRenderingPipeline::Attachment(attachments[i]));
|
||||
}
|
||||
|
||||
parseCondition(prop);
|
||||
}
|
||||
|
||||
FGRenderingPipeline::Attachment::Attachment(SGPropertyNode* prop)
|
||||
|
@ -242,6 +292,8 @@ FGRenderingPipeline::Attachment::Attachment(SGPropertyNode* prop)
|
|||
throw sg_exception("Attachment buffer is mandatory");
|
||||
}
|
||||
buffer = bufferProp->getStringValue();
|
||||
|
||||
parseCondition(prop);
|
||||
}
|
||||
|
||||
FGRenderingPipeline::FGRenderingPipeline()
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <osg/Camera>
|
||||
#include <string>
|
||||
|
||||
#include <simgear/structure/SGExpression.hxx>
|
||||
|
||||
namespace simgear
|
||||
{
|
||||
class SGReaderWriterOptions;
|
||||
|
@ -24,7 +26,19 @@ namespace flightgear {
|
|||
|
||||
class FGRenderingPipeline : public osg::Referenced {
|
||||
public:
|
||||
struct Buffer : public osg::Referenced {
|
||||
class Conditionable : public osg::Referenced {
|
||||
public:
|
||||
Conditionable() : _alwaysValid(false) {}
|
||||
void parseCondition(SGPropertyNode* prop);
|
||||
bool getAlwaysValid() const { return _alwaysValid; }
|
||||
void setAlwaysValid(bool val) { _alwaysValid = val; }
|
||||
void setValidExpression(SGExpressionb* exp);
|
||||
bool valid();
|
||||
protected:
|
||||
bool _alwaysValid;
|
||||
SGSharedPtr<SGExpressionb> _validExpression;
|
||||
};
|
||||
struct Buffer : public Conditionable {
|
||||
Buffer(SGPropertyNode* prop);
|
||||
|
||||
std::string name;
|
||||
|
@ -40,14 +54,14 @@ public:
|
|||
//osg::Vec4 borderColor;
|
||||
};
|
||||
|
||||
struct Pass : public osg::Referenced {
|
||||
struct Pass : public Conditionable {
|
||||
Pass(SGPropertyNode* prop);
|
||||
|
||||
std::string name;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
struct Attachment : public osg::Referenced {
|
||||
struct Attachment : public Conditionable {
|
||||
Attachment(SGPropertyNode* prop);
|
||||
Attachment(osg::Camera::BufferComponent c, const std::string& b ) : component(c), buffer(b) {}
|
||||
|
||||
|
@ -56,7 +70,7 @@ public:
|
|||
};
|
||||
typedef std::vector<osg::ref_ptr<Attachment> > AttachmentList;
|
||||
|
||||
struct Stage : public osg::Referenced {
|
||||
struct Stage : public Conditionable {
|
||||
Stage(SGPropertyNode* prop);
|
||||
|
||||
std::string name;
|
||||
|
@ -78,4 +92,13 @@ public:
|
|||
const simgear::SGReaderWriterOptions* options);
|
||||
};
|
||||
|
||||
namespace flightgear {
|
||||
|
||||
class PipelinePredParser : public simgear::expression::ExpressionParser
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue