Skip to content

Commit

Permalink
Fix some compile errors, fix the NVGL support in TiledModelLayer, sim…
Browse files Browse the repository at this point in the history
…plify DepthOffset
  • Loading branch information
gwaldron committed Dec 16, 2024
1 parent 20aa7d3 commit 4069b06
Show file tree
Hide file tree
Showing 28 changed files with 265 additions and 169 deletions.
6 changes: 3 additions & 3 deletions src/applications/osgearth_annotation/osgearth_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ main(int argc, char** argv)
geomStyle.getOrCreate<LineSymbol>()->stroke().mutable_value().color() = Color::Cyan;
geomStyle.getOrCreate<LineSymbol>()->stroke().mutable_value().width() = 5.0f;
geomStyle.getOrCreate<LineSymbol>()->tessellationSize() = Distance(75000, Units::METERS);
geomStyle.getOrCreate<RenderSymbol>()->depthOffset().mutable_value().enabled() = true;
geomStyle.getOrCreate<RenderSymbol>()->depthOffset();

FeatureNode* fnode = new FeatureNode(feature, geomStyle);

Expand Down Expand Up @@ -188,7 +188,7 @@ main(int argc, char** argv)
geomStyle.getOrCreate<LineSymbol>()->stroke().mutable_value().color() = Color::Lime;
geomStyle.getOrCreate<LineSymbol>()->stroke().mutable_value().width() = 3.0f;
geomStyle.getOrCreate<LineSymbol>()->tessellationSize() = Distance(75000, Units::METERS);
geomStyle.getOrCreate<RenderSymbol>()->depthOffset().mutable_value().enabled() = true;
geomStyle.getOrCreate<RenderSymbol>()->depthOffset();

FeatureNode* gnode = new FeatureNode(feature, geomStyle);
annoGroup->addChild( gnode );
Expand Down Expand Up @@ -225,7 +225,7 @@ main(int argc, char** argv)
pathStyle.getOrCreate<PointSymbol>()->smooth() = true;
pathStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
pathStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_GPU;
pathStyle.getOrCreate<RenderSymbol>()->depthOffset().mutable_value().enabled() = true;
pathStyle.getOrCreate<RenderSymbol>()->depthOffset();

//OE_INFO << "Path extent = " << pathFeature->getExtent().toString() << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion src/applications/osgearth_features/osgearth_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int main(int argc, char** argv)
ls->tessellationSize() = Distance(100, Units::KILOMETERS);

RenderSymbol* render = style.getOrCreate<RenderSymbol>();
render->depthOffset().mutable_value().enabled() = true;
render->depthOffset().mutable_value().automatic() = true;
}

if (useRaster)
Expand Down
41 changes: 15 additions & 26 deletions src/osgEarth/DepthOffset
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,29 @@ namespace osgEarth
DepthOffsetOptions(const Config& conf =Config());

public:
/** whether to enable depth offsetting (when applicable) */
optional<bool>& enabled() { return _enabled; }
const optional<bool>& enabled() const { return _enabled; }
//! whether to enable depth offsetting (when applicable)
OE_OPTION(bool, enabled, true);

/** depth bias (in meters) applied at the minimum camera range. */
optional<Distance>& minBias() { return _minBias; }
const optional<Distance>& minBias() const { return _minBias; }
//! a static depth offset distance (in meters) to apply to all geometry.
OE_OPTION(Distance, range, Distance(0.1, Units::METERS));

/** depth bias (in meters) applied at the maximum camera range. */
optional<Distance>& maxBias() { return _maxBias; }
const optional<Distance>& maxBias() const { return _maxBias; }
//! depth bias (in meters) applied at the minimum camera range.
OE_OPTION(Distance, minBias, Distance(100, Units::METERS));

/** camera range (in meters) at which to apply the minimum depth bias. */
optional<Distance>& minRange() { return _minRange; }
const optional<Distance>& minRange() const { return _minRange; }
//! depth bias (in meters) applied at the maximum camera range.
OE_OPTION(Distance, maxBias, Distance(10000, Units::METERS));

/** camera range (in meters) at which to apply the maximum depth bias. */
optional<Distance>& maxRange() { return _maxRange; }
const optional<Distance>& maxRange() const { return _maxRange; }
//! camera range (in meters) at which to apply the minimum depth bias.
OE_OPTION(Distance, minRange, Distance(1000, Units::METERS));

/** automatic calculation of the minRange based on geometry analysis */
optional<bool>& automatic() { return _auto; }
const optional<bool>& automatic() const { return _auto; }
//! camera range (in meters) at which to apply the maximum depth bias.
OE_OPTION(Distance, maxRange, Distance(10000000, Units::METERS));

//! automatic calculation of the minRange based on geometry analysis
OE_OPTION(bool, automatic, true);

public:
Config getConfig() const;

private:
optional<bool> _enabled;
optional<Distance> _minBias;
optional<Distance> _maxBias;
optional<Distance> _minRange;
optional<Distance> _maxRange;
optional<bool> _auto;
};
}

Expand Down
71 changes: 38 additions & 33 deletions src/osgEarth/DepthOffset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,50 +83,46 @@ namespace
//------------------------------------------------------------------------


DepthOffsetOptions::DepthOffsetOptions(const Config& conf) :
_enabled ( true ),
_minBias (Distance(100.0, Units::METERS)),
_maxBias (Distance(10000.0, Units::METERS)),
_minRange(Distance(1000.0, Units::METERS)),
_maxRange(Distance(10000000.0, Units::METERS)),
_auto ( true )
DepthOffsetOptions::DepthOffsetOptions(const Config& conf)
{
conf.get( "enabled", _enabled );
conf.get( "min_bias", _minBias );
conf.get( "max_bias", _maxBias );
conf.get( "min_range", _minRange );
conf.get( "max_range", _maxRange );
conf.get( "auto", _auto );
conf.get("enabled", _enabled);
conf.get("range", _range);
conf.get("min_bias", _minBias);
conf.get("max_bias", _maxBias);
conf.get("min_range", _minRange);
conf.get("max_range", _maxRange);
conf.get("auto", _automatic);
}


Config
DepthOffsetOptions::getConfig() const
{
Config conf("depth_offset");
conf.set( "enabled", _enabled );
conf.set( "min_bias", _minBias );
conf.set( "max_bias", _maxBias );
conf.set( "min_range", _minRange );
conf.set( "max_range", _maxRange );
conf.set( "auto", _auto );
conf.set("enabled", _enabled);
conf.set("range", _range);
conf.set("min_bias", _minBias);
conf.set("max_bias", _maxBias);
conf.set("min_range", _minRange);
conf.set("max_range", _maxRange);
conf.set("auto", _automatic);
return conf;
}


//------------------------------------------------------------------------

DepthOffsetAdapter::DepthOffsetAdapter() :
_dirty( false )
_dirty(false)
{
init();
}

DepthOffsetAdapter::DepthOffsetAdapter(osg::Node* graph) :
_dirty( false )
_dirty(false)
{
init();
setGraph( graph );
setGraph(graph);
}

void
Expand All @@ -150,10 +146,10 @@ DepthOffsetAdapter::setGraph(osg::Node* graph)

bool uninstall =
(_graph.valid() && _graph->getStateSet()) &&
(graphChanging || (_options.enabled() == false));
((graphChanging) || (_options.enabled() == false));

bool install =
(graph && graphChanging && _options.enabled() == true);
(graph && graphChanging) && _options.enabled() == true;

// shader package:
Shaders shaders;
Expand Down Expand Up @@ -206,11 +202,20 @@ DepthOffsetAdapter::updateUniforms()
{
if ( !_supported ) return;

_paramsUniform->set(osg::Vec4f(
(float)_options.minBias()->as(Units::METERS),
(float)_options.maxBias()->as(Units::METERS),
(float)_options.minRange()->as(Units::METERS),
(float)_options.maxRange()->as(Units::METERS)));
if (_options.range().isSet())
{
_paramsUniform->set(osg::Vec4f(0.0, 0.0,
(float)_options.range()->as(Units::METERS),
(float)_options.range()->as(Units::METERS)));
}
else
{
_paramsUniform->set(osg::Vec4f(
(float)_options.minBias()->as(Units::METERS),
(float)_options.maxBias()->as(Units::METERS),
(float)_options.minRange()->as(Units::METERS),
(float)_options.maxRange()->as(Units::METERS)));
}
}

void
Expand All @@ -219,7 +224,7 @@ DepthOffsetAdapter::setDepthOffsetOptions(const DepthOffsetOptions& options)
if ( !_supported ) return;

// if "enabled" changed, reset the graph.
bool reinitGraph = ( options.enabled() != _options.enabled() );
bool reinitGraph = (options.enabled() != _options.enabled());

_options = options;

Expand All @@ -236,12 +241,12 @@ DepthOffsetAdapter::setDepthOffsetOptions(const DepthOffsetOptions& options)
void
DepthOffsetAdapter::recalculate()
{
if ( _supported && _graph.valid() )
if (_supported && _graph.valid())
{
if ( _options.automatic() == true )
if (_options.automatic() == true && !_options.range().isSet())
{
GeometryAnalysisVisitor v;
_graph->accept( v );
_graph->accept(v);
float maxLen = osg::maximum(1.0f, sqrtf(v._segmentAnalyzer._maxLen2));
_options.minRange() = Distance(sqrtf(maxLen) * 19.0f, Units::METERS);
_dirty = false;
Expand Down
18 changes: 13 additions & 5 deletions src/osgEarth/DepthOffset.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ uniform vec4 oe_DepthOffset_params;
void oe_DepthOffset_vertex(inout vec4 vertexView)
{
// calculate range to target:
float range = length(vertexView.xyz);
float vertex_range = length(vertexView.xyz);

// extract params for clarity.
float minBias = oe_DepthOffset_params[0];
Expand All @@ -16,13 +16,21 @@ void oe_DepthOffset_vertex(inout vec4 vertexView)
float maxRange = oe_DepthOffset_params[3];

// calculate the depth offset bias for this range:
float ratio = (clamp(range, minRange, maxRange)-minRange)/(maxRange-minRange);
float bias = minBias + ratio * (maxBias-minBias);
float bias = minRange;
if (maxRange > minRange && maxBias > minBias)
{
float ratio = (clamp(vertex_range, minRange, maxRange) - minRange) / (maxRange - minRange);
bias = minBias + ratio * (maxBias - minBias);
}

// clamp the bias to 1/2 of the range of the vertex. We don't want to
// pull the vertex TOO close to the camera and certainly not behind it.
bias = min(bias, range*0.5);
bias = min(bias, maxBias);
bias = min(bias, vertex_range *0.5);

if (maxBias > minBias)
{
bias = min(bias, maxBias);
}

// pull the vertex towards the camera.
vec3 pullVec = normalize(vertexView.xyz);
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Feature::Feature(const Feature& rhs) : //, const osg::CopyOp& copyOp) :

Feature::Feature(Feature&& rhs) // : osg::Object(rhs)
{
_fid = rhs._fid;
_fid = std::move(rhs._fid);
_attrs = std::move(rhs._attrs);
_style = std::move(rhs._style);
_geoInterp = std::move(rhs._geoInterp);
Expand Down
3 changes: 3 additions & 0 deletions src/osgEarth/FeatureSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ FeatureSource::createFeatureCursor(
for(auto& feature : features)
{
std::string attr = feature->getString(options().fidAttribute().get());
for (auto& c : attr)
if (!isdigit(c))
c = ' ';
feature->setFID(as<FeatureID>(attr, 0));
}
result = new FeatureListCursor(std::move(features));
Expand Down
18 changes: 6 additions & 12 deletions src/osgEarth/FeatureSourceIndexNode
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,16 @@ namespace osgEarth
public:
FeatureSourceIndexOptions(const Config& conf =Config());

/** Whether indexing is enabled. */
optional<bool>& enabled() { return _enabled; }
const optional<bool>& enabled() const { return _enabled; }
//! Whether indexing is enabled.
OE_OPTION(bool, enabled, false);

/** Whether to embed the actual Feature objects in the index (instead of
* just the FeatureID). This is useful for feature sources that cannot
* be queried by ID (e.g., streaming data like TFS) */
optional<bool>& embedFeatures() { return _embedFeatures; }
const optional<bool>& embedFeatures() const { return _embedFeatures; }
//! Whether to embed the actual Feature objects in the index (instead of
//! just the FeatureID). This is useful for feature sources that cannot
//! be queried by ID (e.g., streaming data like TFS)
OE_OPTION(bool, embedFeatures, false);

public:
Config getConfig() const;

private:
optional<bool> _enabled;
optional<bool> _embedFeatures;
};

struct RefIDPair : public osg::Referenced
Expand Down
18 changes: 5 additions & 13 deletions src/osgEarth/FeatureSourceIndexNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ namespace
//-----------------------------------------------------------------------------


FeatureSourceIndexOptions::FeatureSourceIndexOptions(const Config& conf) :
_enabled ( false ),
_embedFeatures( false )
FeatureSourceIndexOptions::FeatureSourceIndexOptions(const Config& conf)
{
conf.get( "enabled", _enabled );
conf.get( "embed_features", _embedFeatures );
conf.get("enabled", _enabled);
conf.get("embed_features", _embedFeatures);
}

Config
FeatureSourceIndexOptions::getConfig() const
{
Config conf("feature_indexing");
conf.set( "enabled", _enabled );
conf.set( "embed_features", _embedFeatures );
conf.set("enabled", _enabled);
conf.set("embed_features", _embedFeatures);
return conf;
}

Expand Down Expand Up @@ -145,12 +143,6 @@ FeatureSourceIndexNode::getAllFIDs(std::vector<FeatureID>& output) const
{
output.push_back(iter.first);
}
//KeyIter<FID_to_RefIDPair> start( _fids.begin() );
//KeyIter<FID_to_RefIDPair> end ( _fids.end() );
//for(KeyIter<FID_to_RefIDPair> i = start; i != end; ++i )
//{
// output.push_back( *i );
//}

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/osgEarth/GeoCommon
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace osgEarth
enum GeoInterpolation
{
GEOINTERP_GREAT_CIRCLE,
GEOINTERP_RHUMB_LINE
GEOINTERP_RHUMB_LINE,
GEOINTERP_DEFAULT = GEOINTERP_RHUMB_LINE
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/osgEarth/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ Ring::splitAcrossAntimeridian()
auto mg = new MultiGeometry();
mg->add(left);
mg->add(right);
return mg;
}
else
{
Expand Down Expand Up @@ -1288,6 +1289,8 @@ MultiGeometry::splitAcrossAntimeridian()
}
}
}

return mg;
}

//----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/osgEarth/MVT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace osgEarth { namespace MVT

// Close the ring.
currentRing->close();

// New polygon
if (area > 0)
{
Expand Down Expand Up @@ -437,6 +437,7 @@ namespace osgEarth { namespace MVT
}
else
{
OE_SOFT_ASSERT(false, "MVT: unsupported geometry type \"" << feature.type() << "\"");
geometry = decodeLine(feature, key, layer.extent());
}

Expand Down
1 change: 0 additions & 1 deletion src/osgEarth/MeasureTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ MeasureToolHandler::rebuild()

// offset to mitigate Z fighting
RenderSymbol* render = _feature->style().mutable_value().getOrCreate<RenderSymbol>();
render->depthOffset().mutable_value().enabled() = true;
render->depthOffset().mutable_value().automatic() = true;

// define a style for the line
Expand Down
Loading

0 comments on commit 4069b06

Please sign in to comment.