mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Canvas entity texture updating
This commit is contained in:
parent
addd65a160
commit
621df2e4a9
4 changed files with 29 additions and 21 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
} }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue