mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:53:08 +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;
|
using namespace render::entities;
|
||||||
|
|
||||||
CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
|
CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
|
||||||
gpu::Byte pixels[256 * 256 * 4];
|
_testTimer.setInterval(16);
|
||||||
|
|
||||||
// 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);
|
|
||||||
connect(&_testTimer, &QTimer::timeout, this, &CanvasEntityRenderer::onTimeout);
|
connect(&_testTimer, &QTimer::timeout, this, &CanvasEntityRenderer::onTimeout);
|
||||||
_testTimer.start();
|
_testTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasEntityRenderer::~CanvasEntityRenderer() { }
|
CanvasEntityRenderer::~CanvasEntityRenderer() { }
|
||||||
|
|
||||||
|
void CanvasEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer &entity) {
|
||||||
|
_width = entity->getWidth();
|
||||||
|
_height = entity->getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasEntityRenderer::onTimeout() {
|
void CanvasEntityRenderer::onTimeout() {
|
||||||
gpu::Byte pixels[256 * 256 * 4];
|
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;
|
_ticks += 1;
|
||||||
qDebug("onTimeout: _ticks = %d", _ticks);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,16 @@ protected:
|
||||||
virtual bool wantsHandControllerPointerEvents() const override { return false; }
|
virtual bool wantsHandControllerPointerEvents() const override { return false; }
|
||||||
virtual bool wantsKeyboardFocus() const override { return false; }
|
virtual bool wantsKeyboardFocus() const override { return false; }
|
||||||
|
|
||||||
|
virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer &entity) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gpu::TexturePointer _texture;
|
gpu::TexturePointer _texture;
|
||||||
|
|
||||||
int _ticks = 0;
|
int _ticks = 0;
|
||||||
QTimer _testTimer;
|
QTimer _testTimer;
|
||||||
void onTimeout();
|
void onTimeout();
|
||||||
|
|
||||||
|
int _width = 4, _height = 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -23,6 +23,16 @@ public:
|
||||||
|
|
||||||
ALLOW_INSTANTIATION // This class can be instantiated
|
ALLOW_INSTANTIATION // This class can be instantiated
|
||||||
ENTITY_PROPERTY_SUBCLASS_METHODS
|
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
|
#endif // hifi_CanvasEntityItem_h
|
||||||
|
|
|
@ -83,7 +83,9 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texturePointer) {
|
||||||
case TextureUsageType::RESOURCE:
|
case TextureUsageType::RESOURCE:
|
||||||
#endif
|
#endif
|
||||||
case TextureUsageType::STRICT_RESOURCE:
|
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);
|
object = new GL45StrictResourceTexture(shared_from_this(), texture);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue