Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/osgEarthCesium/AssetAccessor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumAsync/IAssetResponse.h>
#include <CesiumAsync/ASyncSystem.h>
#include <osgDB/Options>
#include <osgEarth/Cache>

Expand All @@ -24,7 +25,7 @@ namespace osgEarth {

virtual const CesiumAsync::HttpHeaders& headers() const override;

virtual gsl::span<const std::byte> data() const override;
virtual std::span<const std::byte> data() const override;

uint16_t _statusCode = 0;
std::string _contentType;
Expand Down Expand Up @@ -71,7 +72,7 @@ namespace osgEarth {
const std::string& verb,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
const gsl::span<const std::byte>& contentPayload) override;
const std::span<const std::byte>& contentPayload) override;

virtual void tick() noexcept override;

Expand Down
6 changes: 3 additions & 3 deletions src/osgEarthCesium/AssetAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const CesiumAsync::HttpHeaders& AssetResponse::headers() const
return _headers;
}

gsl::span<const std::byte> AssetResponse::data() const
std::span<const std::byte> AssetResponse::data() const
{
return gsl::span<const std::byte>(_result.data(), _result.size());
return std::span<const std::byte>(_result.data(), _result.size());
}

/**********************************************/
Expand Down Expand Up @@ -131,7 +131,7 @@ AssetAccessor::request(
const std::string& verb,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
const gsl::span<const std::byte>& contentPayload)
const std::span<const std::byte>& contentPayload)
{
auto request = std::make_shared<AssetRequest>(verb, url, headers);
return asyncSystem.createFuture<std::shared_ptr<CesiumAsync::IAssetRequest>>(
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthCesium/CesiumCreditsNode
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace osgEarth {

private:

void nextFrame();
void updateCredits();

osg::Texture2D* getOrCreateTexture(const std::string& url);
std::map< std::string, osg::ref_ptr< osg::Texture2D > > _textureCache;


std::vector< std::string > _credits;
size_t _lastCreditsCount;
osg::Camera* _camera;
osg::observer_ptr< osg::View > _view;
std::shared_ptr< CesiumUtility::CreditSystem > _creditSystem;
Expand Down
132 changes: 67 additions & 65 deletions src/osgEarthCesium/CesiumCreditsNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace
}

CesiumCreditsNode::CesiumCreditsNode(osg::View* view, CesiumUtility::CreditSystem* creditSystem)
: _lastCreditsCount(0)
{
setNumChildrenRequiringUpdateTraversal(1);

Expand All @@ -147,84 +148,87 @@ CesiumCreditsNode::CesiumCreditsNode(osg::View* view, CesiumUtility::CreditSyste
addChild(_camera);
}

void CesiumCreditsNode::nextFrame()
{
_creditSystem->startNextFrame();
}

void CesiumCreditsNode::updateCredits()
{
std::vector< ParsedCredit > parsedCredits;

auto creditSystem = _creditSystem;
auto credits = creditSystem->getCreditsToShowThisFrame();
for (auto& credit : credits)
{
if (creditSystem->shouldBeShownOnScreen(credit))
{
auto html = creditSystem->getHtml(credit);
parseCredit(html, parsedCredits);
}
}
auto credits = _creditSystem->getSnapshot();

_camera->removeChildren(0, _camera->getNumChildren());
auto creditsToShowThisFrame = credits.currentCredits;

osg::Geode* geode = new osg::Geode();
_camera->addChild(geode);
auto updated = creditsToShowThisFrame.size() != _lastCreditsCount || credits.removedCredits.size() > 0;

float margin = 4.0f;
osg::Vec3 position(5, 5, 0);
for (unsigned int i = 0; i < parsedCredits.size(); ++i)
{
auto& c = parsedCredits[i];
if (!c.text.empty())
{
osgText::Text* text = new osgText::Text;
text->setFont(osgEarth::Registry::instance()->getDefaultFont());
text->setPosition(position);
text->setText(c.text);
geode->addDrawable(text);
position.x() += (text->getBoundingBox().xMax() - text->getBoundingBox().xMin()) + margin;
if (updated) {
_lastCreditsCount = creditsToShowThisFrame.size();

for (auto& credit : creditsToShowThisFrame) {
if (creditSystem->shouldBeShownOnScreen(credit))
{
auto html = creditSystem->getHtml(credit);
parseCredit(html, parsedCredits);
}
}
_camera->removeChildren(0, _camera->getNumChildren());

osg::Geode* geode = new osg::Geode();
_camera->addChild(geode);

if (!c.image.empty())
float margin = 4.0f;
osg::Vec3 position(5, 5, 0);
for (unsigned int i = 0; i < parsedCredits.size(); ++i)
{
osg::Texture2D* texture = getOrCreateTexture(c.image);
if (texture)
auto& c = parsedCredits[i];
if (!c.text.empty())
{
osg::Geometry* geometry = new osg::Geometry;
osg::Vec3Array* verts = new osg::Vec3Array;
geometry->setVertexArray(verts);
verts->push_back(osg::Vec3(0, 0, 0));
verts->push_back(osg::Vec3(texture->getImage()->s(), 0, 0));
verts->push_back(osg::Vec3(texture->getImage()->s(), texture->getImage()->t(), 0));
verts->push_back(osg::Vec3(0, texture->getImage()->t(), 0));

osg::Vec2Array* texCoords = new osg::Vec2Array;
geometry->setTexCoordArray(0, texCoords);
texCoords->push_back(osg::Vec2(0, 0));
texCoords->push_back(osg::Vec2(1, 0));
texCoords->push_back(osg::Vec2(1, 1));
texCoords->push_back(osg::Vec2(0, 1));

osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1, 1, 1, 1));
geometry->setColorArray(colors, osg::Array::BIND_OVERALL);

geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
osg::DrawElementsUByte* de = new osg::DrawElementsUByte(GL_TRIANGLES);
de->push_back(0); de->push_back(1); de->push_back(2);
de->push_back(0); de->push_back(2); de->push_back(3);

geometry->addPrimitiveSet(de);

osgEarth::Registry::shaderGenerator().run(geometry);
geode->addDrawable(geometry);

position.x() += texture->getImage()->s() + margin;
osgText::Text* text = new osgText::Text;
text->setFont(osgEarth::Registry::instance()->getDefaultFont());
text->setPosition(position);
text->setText(c.text);
geode->addDrawable(text);
position.x() += (text->getBoundingBox().xMax() - text->getBoundingBox().xMin()) + margin;
}

if (!c.image.empty())
{
osg::Texture2D* texture = getOrCreateTexture(c.image);
if (texture)
{
osg::Geometry* geometry = new osg::Geometry;
osg::Vec3Array* verts = new osg::Vec3Array;
geometry->setVertexArray(verts);
verts->push_back(osg::Vec3(0, 0, 0));
verts->push_back(osg::Vec3(texture->getImage()->s(), 0, 0));
verts->push_back(osg::Vec3(texture->getImage()->s(), texture->getImage()->t(), 0));
verts->push_back(osg::Vec3(0, texture->getImage()->t(), 0));

osg::Vec2Array* texCoords = new osg::Vec2Array;
geometry->setTexCoordArray(0, texCoords);
texCoords->push_back(osg::Vec2(0, 0));
texCoords->push_back(osg::Vec2(1, 0));
texCoords->push_back(osg::Vec2(1, 1));
texCoords->push_back(osg::Vec2(0, 1));

osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1, 1, 1, 1));
geometry->setColorArray(colors, osg::Array::BIND_OVERALL);

geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
osg::DrawElementsUByte* de = new osg::DrawElementsUByte(GL_TRIANGLES);
de->push_back(0); de->push_back(1); de->push_back(2);
de->push_back(0); de->push_back(2); de->push_back(3);

geometry->addPrimitiveSet(de);

osgEarth::Registry::shaderGenerator().run(geometry);
geode->addDrawable(geometry);

position.x() += texture->getImage()->s() + margin;
}
}
}
}

}

osg::Texture2D* CesiumCreditsNode::getOrCreateTexture(const std::string& url)
Expand Down Expand Up @@ -254,8 +258,6 @@ void CesiumCreditsNode::traverse(osg::NodeVisitor& nv)
{
// Get the credits from the previous frame.
updateCredits();
// Tell Cesium to start collecting new credits
nextFrame();
auto vp = _view->getCamera()->getViewport();
if (vp)
{
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthCesium/PrepareRenderResources
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace osgEarth {
void* pMainThreadResult) noexcept;

virtual void* prepareRasterInLoadThread(
CesiumGltf::ImageCesium& image,
CesiumGltf::ImageAsset& image,
const std::any& rendererOptions);

virtual void* prepareRasterInMainThread(
Expand Down
8 changes: 4 additions & 4 deletions src/osgEarthCesium/PrepareRenderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace
const GLenum redFormat = GL_RED;
#endif

osg::Image* getOsgImage(CesiumGltf::ImageCesium& image)
osg::Image* getOsgImage(CesiumGltf::ImageAsset& image)
{
GLenum format = GL_RGB;
GLenum texFormat = GL_RGB8;
Expand Down Expand Up @@ -386,9 +386,9 @@ namespace {
}

// Load the image
auto& image = _model->images[texture.source].cesium;
auto image = _model->images[texture.source].pAsset;

osg::Image* osgImage = getOsgImage(image);
osg::Image* osgImage = getOsgImage(*image);

if (osgImage)
{
Expand Down Expand Up @@ -628,7 +628,7 @@ void PrepareRendererResources::free(
}

void* PrepareRendererResources::prepareRasterInLoadThread(
CesiumGltf::ImageCesium& image,
CesiumGltf::ImageAsset& image,
const std::any& rendererOptions)
{
osg::Image* osgImage = getOsgImage(image);
Expand Down
Loading