Canvas closer but still not working

This commit is contained in:
Ada 2025-02-27 06:22:56 +10:00
parent a3641c27a4
commit b28bac1f5f
6 changed files with 23 additions and 39 deletions

View file

@ -11,34 +11,12 @@
using namespace render;
using namespace render::entities;
CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity);
_width = canvas->getWidth();
_width = canvas->getHeight();
}
CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { }
CanvasEntityRenderer::~CanvasEntityRenderer() { }
void CanvasEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
_width = entity->getWidth();
_height = entity->getHeight();
void CanvasEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) {
_texture = entity->getTexture();
qDebug() << "width: " << _width << ", height: " << _height;
if (entity->needsRenderUpdate()) {
// misaligned size, can't safely copy
if (entity->getImageData().length() != _width * _height * 4) {
entity->setNeedsRenderUpdate(false);
return;
}
auto texture = gpu::Texture::createStrict(gpu::Element::COLOR_SRGBA_32, _width, _height);
texture->setStoredMipFormat(gpu::Element::COLOR_SRGBA_32);
texture->setAutoGenerateMips(false);
texture->assignStoredMip(0, _width * _height * 4, reinterpret_cast<const uint8_t*>(entity->getImageData().data()));
texture->setSource("CanvasEntityRenderer");
_texture = texture;
entity->setNeedsRenderUpdate(false);
}
qDebug() << "CanvasEntityRenderer::doRenderUpdateAsynchronousTyped";
}

View file

@ -32,12 +32,10 @@ protected:
virtual bool wantsHandControllerPointerEvents() const override { return false; }
virtual bool wantsKeyboardFocus() const override { return false; }
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override;
private:
gpu::TexturePointer _texture;
int _width, _height;
};
} }

View file

@ -16,8 +16,7 @@
EntityItemPointer CanvasEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
std::shared_ptr<CanvasEntityItem> entity(new CanvasEntityItem(entityID), [](CanvasEntityItem* ptr) { ptr->deleteLater(); });
entity->setProperties(properties);
size_t bufferSize = 4 * static_cast<size_t>(properties._width) + static_cast<size_t>(properties._height);
qDebug() << __FUNCTION__ << ": (4 * " << properties._width << " * " << properties._height << " = " << bufferSize;
size_t bufferSize = 4 * static_cast<size_t>(properties._width) * static_cast<size_t>(properties._height);
entity->_imageData = QByteArray(bufferSize, (unsigned char)255);
return entity;
}
@ -83,7 +82,7 @@ bool CanvasEntityItem::setSubClassProperties(const EntityItemProperties& propert
// reallocate and resize if the size properties are changed
if (oldWidth != getWidth() || oldHeight != getHeight()) {
size_t bufferSize = 4 * static_cast<size_t>(getWidth()) + static_cast<size_t>(getHeight());
size_t bufferSize = 4 * static_cast<size_t>(getWidth()) * static_cast<size_t>(getHeight());
_imageData = QByteArray(bufferSize, (unsigned char)255);
}
@ -103,16 +102,22 @@ QByteArray& CanvasEntityItem::getImageData() {
}
void CanvasEntityItem::setImageData(const QByteArray& data) {
if (data.length() != _imageData.length()) {
if (data.length() != _width * _height * 4) {
return;
}
_imageData = data;
_needsRenderUpdate = true;
auto texture = gpu::Texture::createStrict(gpu::Element::COLOR_SRGBA_32, _width, _height);
texture->setStoredMipFormat(gpu::Element::COLOR_SRGBA_32);
texture->setAutoGenerateMips(false);
texture->assignStoredMip(0, _width * _height * 4, reinterpret_cast<const uint8_t*>(_imageData.data()));
texture->setSource("CanvasEntityRenderer");
_texture = texture;
setNeedsRenderUpdate(true);
}
void CanvasEntityItem::setImageSubData(const QByteArray& data, uint32_t dx, uint32_t dy, uint32_t dw, uint32_t dh, uint32_t sx, uint32_t sy, uint32_t sw, uint32_t sh) {
qCWarning(entities) << "CanvasEntityItem::setImageSubData unimplemented!";
_needsRenderUpdate = false;
}

View file

@ -9,6 +9,7 @@
#define hifi_CanvasEntityItem_h
#include "EntityItem.h"
#include <gpu/Texture.h>
class CanvasEntityItem : public EntityItem {
public:
@ -28,10 +29,13 @@ public:
void setImageData(const QByteArray& data);
void setImageSubData(const QByteArray& data, uint32_t dx, uint32_t dy, uint32_t dw, uint32_t dh, uint32_t sx, uint32_t sy, uint32_t sw, uint32_t sh);
gpu::TexturePointer getTexture() const { return _texture; }
protected:
@Canvas_ENTITY_PROPS@
QByteArray _imageData;
gpu::TexturePointer _texture;
};
#endif // hifi_CanvasEntityItem_h

View file

@ -267,7 +267,7 @@ enum:SOUND_LOOP prop:loop type:bool default:true,
enum:SOUND_POSITIONAL prop:positional type:bool default:true,
enum:SOUND_LOCAL_ONLY prop:localOnly type:bool default:false,
Canvas
enum:CANVAS_WIDTH prop:width type:uint16_t default:300 renderProp,
enum:CANVAS_HEIGHT prop:height type:uint16_t default:150 renderProp,
enum:CANVAS_WIDTH prop:width type:uint16_t default:300 basicProp,
enum:CANVAS_HEIGHT prop:height type:uint16_t default:150 basicProp,
enum:CANVAS_BG_COLOR prop:bgColor type:u8vec3Color default:ENTITY_ITEM_DEFAULT_COLOR basicProp,
enum:CANVAS_BG_ALPHA prop:bgAlpha type:float default:1.0f min:0.0f max:1.0f basicProp,

View file

@ -2702,7 +2702,6 @@ void EntityScriptingInterface::canvasSubmitImage(const QUuid& entityID, const QB
if (imageData.length() != canvas->getImageData().length()) {
qCDebug(entities) << "canvasSubmitImage with different sized buffers on " << entityID << ": input size: " << imageData.length() << ", canvas size: " << canvas->getImageData().length();
qCDebug(entities) << "width: " << canvas->getWidth() << ", height: " << canvas->getHeight();
}
canvas->setImageData(imageData);