From addd65a1602d59cef2e3cc2d64de179c03057405 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 26 Feb 2025 04:55:14 +1000 Subject: [PATCH] Canvas frame update experiment --- .../src/RenderableCanvasEntityItem.cpp | 25 ++++++++++++++++++- .../src/RenderableCanvasEntityItem.h | 4 +++ .../src/RenderableEntityItem.cpp | 5 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp index 238eca3370..f1c77c26b5 100644 --- a/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp @@ -14,7 +14,7 @@ using namespace render::entities; CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { gpu::Byte pixels[256 * 256 * 4]; - // grayscale XOR placeholder texture + // 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; @@ -28,6 +28,29 @@ CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Pa _texture->setStoredMipFormat(gpu::Element::COLOR_SRGBA_32); _texture->assignStoredMip(0, 256 * 256 * 4, pixels); _texture->setSource(__FUNCTION__); + + _testTimer.setInterval(33); + connect(&_testTimer, &QTimer::timeout, this, &CanvasEntityRenderer::onTimeout); + _testTimer.start(); } CanvasEntityRenderer::~CanvasEntityRenderer() { } + +void CanvasEntityRenderer::onTimeout() { + gpu::Byte pixels[256 * 256 * 4]; + + // XOR placeholder texture + for (int x = 0; x < 256; x++) { + for (int y = 0; y < 256; y++) { + pixels[(y * 256 * 4) + (x * 4) + 0] = ((x + _ticks) ^ (y + _ticks)); + pixels[(y * 256 * 4) + (x * 4) + 1] = ((x + _ticks) ^ (y + _ticks)); + pixels[(y * 256 * 4) + (x * 4) + 2] = ((x + _ticks) ^ (y + _ticks)); + pixels[(y * 256 * 4) + (x * 4) + 3] = 255; + } + } + + _texture->assignStoredMip(0, 256 * 256 * 4, pixels); + + _ticks += 1; + qDebug("onTimeout: _ticks = %d", _ticks); +} diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.h b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h index 050a6be02f..fef1cdb721 100644 --- a/libraries/entities-renderer/src/RenderableCanvasEntityItem.h +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h @@ -34,6 +34,10 @@ protected: private: gpu::TexturePointer _texture; + + int _ticks = 0; + QTimer _testTimer; + void onTimeout(); }; } } diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index 7ca3a5c341..a3e4cbb105 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -31,6 +31,7 @@ #include "RenderableLightEntityItem.h" #include "RenderableZoneEntityItem.h" #include "RenderableMaterialEntityItem.h" +#include "RenderableCanvasEntityItem.h" #include "RenderPipelines.h" @@ -433,6 +434,10 @@ EntityRenderer::Pointer EntityRenderer::addToScene(EntityTreeRenderer& renderer, result = make_renderer(entity); break; + case Type::Canvas: + result = make_renderer(entity); + break; + default: break; }