From 621df2e4a98ea95da60371368a798ff410503ca0 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 26 Feb 2025 06:30:21 +1000 Subject: [PATCH] Canvas entity texture updating --- .../src/RenderableCanvasEntityItem.cpp | 32 +++++++------------ .../src/RenderableCanvasEntityItem.h | 4 +++ libraries/entities/src/CanvasEntityItem.h.in | 10 ++++++ .../src/gpu/gl45/GL45BackendTexture.cpp | 4 ++- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp index f1c77c26b5..f881b38e94 100644 --- a/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp @@ -12,30 +12,18 @@ using namespace render; using namespace render::entities; CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { - gpu::Byte pixels[256 * 256 * 4]; - - // dummy placeholder texture to make sure the per-frame thing works - for (int x = 0; x < 256; x++) { - for (int y = 0; y < 256; y++) { - pixels[(y * 256 * 4) + (x * 4) + 0] = 255; - pixels[(y * 256 * 4) + (x * 4) + 1] = 0; - pixels[(y * 256 * 4) + (x * 4) + 2] = 255; - pixels[(y * 256 * 4) + (x * 4) + 3] = 255; - } - } - - _texture = gpu::Texture::create2D(gpu::Element::COLOR_SRGBA_32, 256, 256); - _texture->setStoredMipFormat(gpu::Element::COLOR_SRGBA_32); - _texture->assignStoredMip(0, 256 * 256 * 4, pixels); - _texture->setSource(__FUNCTION__); - - _testTimer.setInterval(33); + _testTimer.setInterval(16); connect(&_testTimer, &QTimer::timeout, this, &CanvasEntityRenderer::onTimeout); _testTimer.start(); } CanvasEntityRenderer::~CanvasEntityRenderer() { } +void CanvasEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer &entity) { + _width = entity->getWidth(); + _height = entity->getHeight(); +} + void CanvasEntityRenderer::onTimeout() { gpu::Byte pixels[256 * 256 * 4]; @@ -49,8 +37,12 @@ void CanvasEntityRenderer::onTimeout() { } } - _texture->assignStoredMip(0, 256 * 256 * 4, pixels); + auto texture = gpu::Texture::createStrict(gpu::Element::COLOR_SRGBA_32, 256, 256); + texture->setStoredMipFormat(gpu::Element::COLOR_SRGBA_32); + texture->setAutoGenerateMips(false); + texture->assignStoredMip(0, 256 * 256 * 4, pixels); + texture->setSource("CanvasEntityRenderer"); + _texture = texture; _ticks += 1; - qDebug("onTimeout: _ticks = %d", _ticks); } diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.h b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h index fef1cdb721..21a19df9b7 100644 --- a/libraries/entities-renderer/src/RenderableCanvasEntityItem.h +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h @@ -32,12 +32,16 @@ protected: virtual bool wantsHandControllerPointerEvents() const override { return false; } virtual bool wantsKeyboardFocus() const override { return false; } + virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer &entity) override; + private: gpu::TexturePointer _texture; int _ticks = 0; QTimer _testTimer; void onTimeout(); + + int _width = 4, _height = 4; }; } } diff --git a/libraries/entities/src/CanvasEntityItem.h.in b/libraries/entities/src/CanvasEntityItem.h.in index 0eff35dddc..6b69ad3a13 100644 --- a/libraries/entities/src/CanvasEntityItem.h.in +++ b/libraries/entities/src/CanvasEntityItem.h.in @@ -23,6 +23,16 @@ public: ALLOW_INSTANTIATION // This class can be instantiated ENTITY_PROPERTY_SUBCLASS_METHODS + + int getWidth() { return width; } + int getHeight() { return height; } + uint32_t getClearColor() { return clearColor; } + +protected: +@Canvas_ENTITY_PROPS@ + + int width, height; + uint32_t clearColor; }; #endif // hifi_CanvasEntityItem_h diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 3d30ebf03e..263fa318a5 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -83,7 +83,9 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texturePointer) { case TextureUsageType::RESOURCE: #endif case TextureUsageType::STRICT_RESOURCE: - qCDebug(gpugllogging) << "Strict texture " << texture.source().c_str(); + if (texture.source() != "CanvasEntityRenderer") { + qCDebug(gpugllogging) << "Strict texture " << texture.source().c_str(); + } object = new GL45StrictResourceTexture(shared_from_this(), texture); break;