able to reference entity ids as textures

This commit is contained in:
HifiExperiments 2021-03-13 22:34:48 -08:00
parent 9a247172f3
commit 828e653849
9 changed files with 81 additions and 11 deletions

View file

@ -2155,6 +2155,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
return QSizeF(0.0f, 0.0f); 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]() { connect(this, &Application::aboutToQuit, [this]() {
setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
}); });

View file

@ -63,6 +63,7 @@ public:
virtual void addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName); virtual void addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName);
virtual void removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName); virtual void removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName);
static Pipeline getPipelineType(const graphics::MultiMaterial& materials); static Pipeline getPipelineType(const graphics::MultiMaterial& materials);
virtual gpu::TexturePointer getTexture() { return nullptr; }
virtual scriptable::ScriptableModelBase getScriptableModel() override { return scriptable::ScriptableModelBase(); } virtual scriptable::ScriptableModelBase getScriptableModel() override { return scriptable::ScriptableModelBase(); }

View file

@ -24,6 +24,8 @@ public:
ImageEntityRenderer(const EntityItemPointer& entity); ImageEntityRenderer(const EntityItemPointer& entity);
~ImageEntityRenderer(); ~ImageEntityRenderer();
gpu::TexturePointer getTexture() override { return _texture ? _texture->getGPUTexture() : nullptr; }
protected: protected:
Item::Bound getBound(RenderArgs* args) override; Item::Bound getBound(RenderArgs* args) override;
ShapeKey getShapeKey() override; ShapeKey getShapeKey() override;

View file

@ -55,6 +55,8 @@ public:
virtual void setProxyWindow(QWindow* proxyWindow) override; virtual void setProxyWindow(QWindow* proxyWindow) override;
virtual QObject* getEventHandler() override; virtual QObject* getEventHandler() override;
gpu::TexturePointer getTexture() override { return _texture; }
protected: protected:
virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override; virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;

View file

@ -887,16 +887,29 @@ void SphericalHarmonics::evalFromTexture(const Texture& texture, gpu::BackendTar
// TextureSource // TextureSource
const gpu::TexturePointer TextureSource::getGPUTexture() const {
if (_gpuTextureOperator) {
return _gpuTextureOperator();
}
return _gpuTexture;
}
void TextureSource::resetTexture(gpu::TexturePointer texture) { void TextureSource::resetTexture(gpu::TexturePointer texture) {
_gpuTexture = texture; _gpuTexture = texture;
_gpuTextureOperator = nullptr;
}
void TextureSource::resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator) {
_gpuTexture = nullptr;
_gpuTextureOperator = textureOperator;
} }
bool TextureSource::isDefined() const { bool TextureSource::isDefined() const {
if (_gpuTexture) { if (_gpuTextureOperator) {
return _gpuTexture->isDefined(); auto gpuTexture = _gpuTextureOperator();
} else { return gpuTexture && gpuTexture->isDefined();
return false;
} }
return _gpuTexture && _gpuTexture->isDefined();
} }
bool Texture::setMinMip(uint16 newMinMip) { bool Texture::setMinMip(uint16 newMinMip) {
@ -930,6 +943,7 @@ void Texture::setExternalTexture(uint32 externalId, void* externalFence) {
Lock lock(_externalMutex); Lock lock(_externalMutex);
assert(_externalRecycler); assert(_externalRecycler);
_externalUpdates.push_back({ externalId, externalFence }); _externalUpdates.push_back({ externalId, externalFence });
_defined = true;
} }
Texture::ExternalUpdates Texture::getUpdates() const { Texture::ExternalUpdates Texture::getUpdates() const {

View file

@ -700,16 +700,18 @@ public:
void setUrl(const QUrl& url) { _imageUrl = url; } void setUrl(const QUrl& url) { _imageUrl = url; }
const QUrl& getUrl() const { return _imageUrl; } const QUrl& getUrl() const { return _imageUrl; }
const gpu::TexturePointer getGPUTexture() const { return _gpuTexture; } const gpu::TexturePointer getGPUTexture() const;
void setType(int type) { _type = type; } void setType(int type) { _type = type; }
int getType() const { return _type; } int getType() const { return _type; }
void resetTexture(gpu::TexturePointer texture); void resetTexture(gpu::TexturePointer texture);
void resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator);
bool isDefined() const; bool isDefined() const;
protected: protected:
gpu::TexturePointer _gpuTexture; gpu::TexturePointer _gpuTexture;
std::function<gpu::TexturePointer()> _gpuTextureOperator { nullptr };
QUrl _imageUrl; QUrl _imageUrl;
int _type { 0 }; int _type { 0 };
}; };

View file

@ -18,11 +18,7 @@ void TextureMap::setTextureSource(TextureSourcePointer& textureSource) {
} }
bool TextureMap::isDefined() const { bool TextureMap::isDefined() const {
if (_textureSource) { return _textureSource && _textureSource->isDefined();
return _textureSource->isDefined();
} else {
return false;
}
} }
gpu::TextureView TextureMap::getTextureView() const { gpu::TextureView TextureMap::getTextureView() const {

View file

@ -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 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 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() { TextureCache::TextureCache() {
_ktxCache->initialize(); _ktxCache->initialize();
#if defined(DISABLE_KTX_CACHE) #if defined(DISABLE_KTX_CACHE)
@ -252,6 +254,10 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs
if (url.scheme() == RESOURCE_SCHEME) { if (url.scheme() == RESOURCE_SCHEME) {
return getResourceTexture(url); return getResourceTexture(url);
} }
QString decodedURL = url.toDisplayString(QUrl::FullyDecoded);
if (decodedURL.startsWith("{")) {
return getTextureByUUID(decodedURL);
}
auto modifiedUrl = url; auto modifiedUrl = url;
if (type == image::TextureUsage::SKY_TEXTURE) { if (type == image::TextureUsage::SKY_TEXTURE) {
QUrlQuery query { url.query() }; QUrlQuery query { url.query() };
@ -480,6 +486,12 @@ void NetworkTexture::setImage(gpu::TexturePointer texture, int originalWidth,
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self)); 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 { gpu::TexturePointer NetworkTexture::getFallbackTexture() const {
return getFallbackTextureForType(_type); return getFallbackTextureForType(_type);
} }
@ -1311,7 +1323,6 @@ void ImageReader::read() {
} }
NetworkTexturePointer TextureCache::getResourceTexture(const QUrl& resourceTextureUrl) { NetworkTexturePointer TextureCache::getResourceTexture(const QUrl& resourceTextureUrl) {
gpu::TexturePointer texture;
if (resourceTextureUrl == SPECTATOR_CAMERA_FRAME_URL) { if (resourceTextureUrl == SPECTATOR_CAMERA_FRAME_URL) {
if (!_spectatorCameraNetworkTexture) { if (!_spectatorCameraNetworkTexture) {
_spectatorCameraNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true)); _spectatorCameraNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true));
@ -1328,6 +1339,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(const QUrl& resourceTextu
_hmdPreviewNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true)); _hmdPreviewNetworkTexture.reset(new NetworkTexture(resourceTextureUrl, true));
} }
if (_hmdPreviewFramebuffer) { if (_hmdPreviewFramebuffer) {
gpu::TexturePointer texture;
texture = _hmdPreviewFramebuffer->getRenderBuffer(0); texture = _hmdPreviewFramebuffer->getRenderBuffer(0);
if (texture) { if (texture) {
texture->setSource(HMD_PREVIEW_FRAME_URL.toString().toStdString()); 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;
}

View file

@ -39,6 +39,12 @@ class Texture {
public: public:
gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); } gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); }
gpu::TextureSourcePointer _textureSource; 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. /// A texture loaded from the network.
@ -86,6 +92,7 @@ protected:
Q_INVOKABLE void loadTextureContent(const QByteArray& content); Q_INVOKABLE void loadTextureContent(const QByteArray& content);
Q_INVOKABLE void setImage(gpu::TexturePointer texture, int originalWidth, int originalHeight); Q_INVOKABLE void setImage(gpu::TexturePointer texture, int originalWidth, int originalHeight);
void setImageOperator(std::function<gpu::TexturePointer()> textureOperator);
Q_INVOKABLE void startRequestForNextMipLevel(); Q_INVOKABLE void startRequestForNextMipLevel();
@ -192,6 +199,8 @@ public:
const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height); const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height);
void updateSpectatorCameraNetworkTexture(); void updateSpectatorCameraNetworkTexture();
NetworkTexturePointer getTextureByUUID(const QString& uuid);
static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 }; static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 };
static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 }; static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 };