mirror of
https://github.com/lubosz/overte.git
synced 2025-04-10 04:52:17 +02:00
able to reference entity ids as textures
This commit is contained in:
parent
9a247172f3
commit
828e653849
9 changed files with 81 additions and 11 deletions
|
@ -2155,6 +2155,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
return QSizeF(0.0f, 0.0f);
|
||||
});
|
||||
|
||||
Texture::setUnboundTextureForUUIDOperator([this](const QUuid& entityID) -> gpu::TexturePointer {
|
||||
if (_aboutToQuit) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto renderable = getEntities()->renderableForEntityId(entityID);
|
||||
if (renderable) {
|
||||
return renderable->getTexture();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
connect(this, &Application::aboutToQuit, [this]() {
|
||||
setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
|
||||
});
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
virtual void addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName);
|
||||
virtual void removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName);
|
||||
static Pipeline getPipelineType(const graphics::MultiMaterial& materials);
|
||||
virtual gpu::TexturePointer getTexture() { return nullptr; }
|
||||
|
||||
virtual scriptable::ScriptableModelBase getScriptableModel() override { return scriptable::ScriptableModelBase(); }
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ public:
|
|||
ImageEntityRenderer(const EntityItemPointer& entity);
|
||||
~ImageEntityRenderer();
|
||||
|
||||
gpu::TexturePointer getTexture() override { return _texture ? _texture->getGPUTexture() : nullptr; }
|
||||
|
||||
protected:
|
||||
Item::Bound getBound(RenderArgs* args) override;
|
||||
ShapeKey getShapeKey() override;
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
virtual void setProxyWindow(QWindow* proxyWindow) override;
|
||||
virtual QObject* getEventHandler() override;
|
||||
|
||||
gpu::TexturePointer getTexture() override { return _texture; }
|
||||
|
||||
protected:
|
||||
virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
|
||||
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
|
||||
|
|
|
@ -887,16 +887,29 @@ void SphericalHarmonics::evalFromTexture(const Texture& texture, gpu::BackendTar
|
|||
|
||||
|
||||
// TextureSource
|
||||
const gpu::TexturePointer TextureSource::getGPUTexture() const {
|
||||
if (_gpuTextureOperator) {
|
||||
return _gpuTextureOperator();
|
||||
}
|
||||
return _gpuTexture;
|
||||
}
|
||||
|
||||
void TextureSource::resetTexture(gpu::TexturePointer texture) {
|
||||
_gpuTexture = texture;
|
||||
_gpuTextureOperator = nullptr;
|
||||
}
|
||||
|
||||
void TextureSource::resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator) {
|
||||
_gpuTexture = nullptr;
|
||||
_gpuTextureOperator = textureOperator;
|
||||
}
|
||||
|
||||
bool TextureSource::isDefined() const {
|
||||
if (_gpuTexture) {
|
||||
return _gpuTexture->isDefined();
|
||||
} else {
|
||||
return false;
|
||||
if (_gpuTextureOperator) {
|
||||
auto gpuTexture = _gpuTextureOperator();
|
||||
return gpuTexture && gpuTexture->isDefined();
|
||||
}
|
||||
return _gpuTexture && _gpuTexture->isDefined();
|
||||
}
|
||||
|
||||
bool Texture::setMinMip(uint16 newMinMip) {
|
||||
|
@ -930,6 +943,7 @@ void Texture::setExternalTexture(uint32 externalId, void* externalFence) {
|
|||
Lock lock(_externalMutex);
|
||||
assert(_externalRecycler);
|
||||
_externalUpdates.push_back({ externalId, externalFence });
|
||||
_defined = true;
|
||||
}
|
||||
|
||||
Texture::ExternalUpdates Texture::getUpdates() const {
|
||||
|
|
|
@ -700,16 +700,18 @@ public:
|
|||
|
||||
void setUrl(const QUrl& url) { _imageUrl = url; }
|
||||
const QUrl& getUrl() const { return _imageUrl; }
|
||||
const gpu::TexturePointer getGPUTexture() const { return _gpuTexture; }
|
||||
const gpu::TexturePointer getGPUTexture() const;
|
||||
void setType(int type) { _type = type; }
|
||||
int getType() const { return _type; }
|
||||
|
||||
void resetTexture(gpu::TexturePointer texture);
|
||||
void resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator);
|
||||
|
||||
bool isDefined() const;
|
||||
|
||||
protected:
|
||||
gpu::TexturePointer _gpuTexture;
|
||||
std::function<gpu::TexturePointer()> _gpuTextureOperator { nullptr };
|
||||
QUrl _imageUrl;
|
||||
int _type { 0 };
|
||||
};
|
||||
|
|
|
@ -18,11 +18,7 @@ void TextureMap::setTextureSource(TextureSourcePointer& textureSource) {
|
|||
}
|
||||
|
||||
bool TextureMap::isDefined() const {
|
||||
if (_textureSource) {
|
||||
return _textureSource->isDefined();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return _textureSource && _textureSource->isDefined();
|
||||
}
|
||||
|
||||
gpu::TextureView TextureMap::getTextureView() const {
|
||||
|
|
|
@ -98,6 +98,8 @@ static const QUrl HMD_PREVIEW_FRAME_URL("resource://hmdPreviewFrame");
|
|||
static const float SKYBOX_LOAD_PRIORITY { 10.0f }; // Make sure skybox loads first
|
||||
static const float HIGH_MIPS_LOAD_PRIORITY { 9.0f }; // Make sure high mips loads after skybox but before models
|
||||
|
||||
std::function<gpu::TexturePointer(const QUuid&)> Texture::_unboundTextureForUUIDOperator { nullptr };
|
||||
|
||||
TextureCache::TextureCache() {
|
||||
_ktxCache->initialize();
|
||||
#if defined(DISABLE_KTX_CACHE)
|
||||
|
@ -252,6 +254,10 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs
|
|||
if (url.scheme() == RESOURCE_SCHEME) {
|
||||
return getResourceTexture(url);
|
||||
}
|
||||
QString decodedURL = url.toDisplayString(QUrl::FullyDecoded);
|
||||
if (decodedURL.startsWith("{")) {
|
||||
return getTextureByUUID(decodedURL);
|
||||
}
|
||||
auto modifiedUrl = url;
|
||||
if (type == image::TextureUsage::SKY_TEXTURE) {
|
||||
QUrlQuery query { url.query() };
|
||||
|
@ -480,6 +486,12 @@ void NetworkTexture::setImage(gpu::TexturePointer texture, int originalWidth,
|
|||
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));
|
||||
}
|
||||
|
||||
void NetworkTexture::setImageOperator(std::function<gpu::TexturePointer()> textureOperator) {
|
||||
_textureSource->resetTextureOperator(textureOperator);
|
||||
finishedLoading((bool)textureOperator);
|
||||
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));
|
||||
}
|
||||
|
||||
gpu::TexturePointer NetworkTexture::getFallbackTexture() const {
|
||||
return getFallbackTextureForType(_type);
|
||||
}
|
||||
|
@ -1311,7 +1323,6 @@ void ImageReader::read() {
|
|||
}
|
||||
|
||||
NetworkTexturePointer TextureCache::getResourceTexture(const QUrl& resourceTextureUrl) {
|
||||
gpu::TexturePointer texture;
|
||||
if (resourceTextureUrl == SPECTATOR_CAMERA_FRAME_URL) {
|
||||
if (!_spectatorCameraNetworkTexture) {
|
||||
_spectatorCameraNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true));
|
||||
|
@ -1328,6 +1339,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(const QUrl& resourceTextu
|
|||
_hmdPreviewNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true));
|
||||
}
|
||||
if (_hmdPreviewFramebuffer) {
|
||||
gpu::TexturePointer texture;
|
||||
texture = _hmdPreviewFramebuffer->getRenderBuffer(0);
|
||||
if (texture) {
|
||||
texture->setSource(HMD_PREVIEW_FRAME_URL.toString().toStdString());
|
||||
|
@ -1374,3 +1386,22 @@ void TextureCache::updateSpectatorCameraNetworkTexture() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkTexturePointer TextureCache::getTextureByUUID(const QString& uuid) {
|
||||
QUuid quuid = QUuid(uuid);
|
||||
if (!quuid.isNull()) {
|
||||
// We mark this as a resource texture because it's just a reference to another texture. The source
|
||||
// texture will be marked properly
|
||||
NetworkTexturePointer toReturn = NetworkTexturePointer(new NetworkTexture(uuid, true));
|
||||
toReturn->setImageOperator(Texture::getTextureForUUIDOperator(uuid));
|
||||
return toReturn;
|
||||
}
|
||||
return NetworkTexturePointer();
|
||||
}
|
||||
|
||||
std::function<gpu::TexturePointer()> Texture::getTextureForUUIDOperator(const QUuid& uuid) {
|
||||
if (_unboundTextureForUUIDOperator) {
|
||||
return std::bind(_unboundTextureForUUIDOperator, uuid);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
|
@ -39,6 +39,12 @@ class Texture {
|
|||
public:
|
||||
gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); }
|
||||
gpu::TextureSourcePointer _textureSource;
|
||||
|
||||
static std::function<gpu::TexturePointer()> getTextureForUUIDOperator(const QUuid& uuid);
|
||||
static void setUnboundTextureForUUIDOperator(std::function<gpu::TexturePointer(const QUuid&)> textureForUUIDOperator) { _unboundTextureForUUIDOperator = textureForUUIDOperator; }
|
||||
|
||||
private:
|
||||
static std::function<gpu::TexturePointer(const QUuid&)> _unboundTextureForUUIDOperator;
|
||||
};
|
||||
|
||||
/// A texture loaded from the network.
|
||||
|
@ -86,6 +92,7 @@ protected:
|
|||
Q_INVOKABLE void loadTextureContent(const QByteArray& content);
|
||||
|
||||
Q_INVOKABLE void setImage(gpu::TexturePointer texture, int originalWidth, int originalHeight);
|
||||
void setImageOperator(std::function<gpu::TexturePointer()> textureOperator);
|
||||
|
||||
Q_INVOKABLE void startRequestForNextMipLevel();
|
||||
|
||||
|
@ -192,6 +199,8 @@ public:
|
|||
const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height);
|
||||
void updateSpectatorCameraNetworkTexture();
|
||||
|
||||
NetworkTexturePointer getTextureByUUID(const QString& uuid);
|
||||
|
||||
static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 };
|
||||
static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 };
|
||||
|
||||
|
|
Loading…
Reference in a new issue