mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 18:06:57 +02:00
Canvas closer but still not working
This commit is contained in:
parent
a3641c27a4
commit
b28bac1f5f
6 changed files with 23 additions and 39 deletions
|
@ -11,34 +11,12 @@
|
||||||
using namespace render;
|
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) { }
|
||||||
auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity);
|
|
||||||
_width = canvas->getWidth();
|
|
||||||
_width = canvas->getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
CanvasEntityRenderer::~CanvasEntityRenderer() { }
|
CanvasEntityRenderer::~CanvasEntityRenderer() { }
|
||||||
|
|
||||||
void CanvasEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
|
void CanvasEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) {
|
||||||
_width = entity->getWidth();
|
_texture = entity->getTexture();
|
||||||
_height = entity->getHeight();
|
|
||||||
|
|
||||||
qDebug() << "width: " << _width << ", height: " << _height;
|
qDebug() << "CanvasEntityRenderer::doRenderUpdateAsynchronousTyped";
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,10 @@ 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 doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
|
virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gpu::TexturePointer _texture;
|
gpu::TexturePointer _texture;
|
||||||
|
|
||||||
int _width, _height;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
EntityItemPointer CanvasEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
EntityItemPointer CanvasEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
std::shared_ptr<CanvasEntityItem> entity(new CanvasEntityItem(entityID), [](CanvasEntityItem* ptr) { ptr->deleteLater(); });
|
std::shared_ptr<CanvasEntityItem> entity(new CanvasEntityItem(entityID), [](CanvasEntityItem* ptr) { ptr->deleteLater(); });
|
||||||
entity->setProperties(properties);
|
entity->setProperties(properties);
|
||||||
size_t bufferSize = 4 * static_cast<size_t>(properties._width) + static_cast<size_t>(properties._height);
|
size_t bufferSize = 4 * static_cast<size_t>(properties._width) * static_cast<size_t>(properties._height);
|
||||||
qDebug() << __FUNCTION__ << ": (4 * " << properties._width << " * " << properties._height << " = " << bufferSize;
|
|
||||||
entity->_imageData = QByteArray(bufferSize, (unsigned char)255);
|
entity->_imageData = QByteArray(bufferSize, (unsigned char)255);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +82,7 @@ bool CanvasEntityItem::setSubClassProperties(const EntityItemProperties& propert
|
||||||
|
|
||||||
// reallocate and resize if the size properties are changed
|
// reallocate and resize if the size properties are changed
|
||||||
if (oldWidth != getWidth() || oldHeight != getHeight()) {
|
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);
|
_imageData = QByteArray(bufferSize, (unsigned char)255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,16 +102,22 @@ QByteArray& CanvasEntityItem::getImageData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasEntityItem::setImageData(const QByteArray& data) {
|
void CanvasEntityItem::setImageData(const QByteArray& data) {
|
||||||
if (data.length() != _imageData.length()) {
|
if (data.length() != _width * _height * 4) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageData = data;
|
_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) {
|
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!";
|
qCWarning(entities) << "CanvasEntityItem::setImageSubData unimplemented!";
|
||||||
|
|
||||||
_needsRenderUpdate = false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define hifi_CanvasEntityItem_h
|
#define hifi_CanvasEntityItem_h
|
||||||
|
|
||||||
#include "EntityItem.h"
|
#include "EntityItem.h"
|
||||||
|
#include <gpu/Texture.h>
|
||||||
|
|
||||||
class CanvasEntityItem : public EntityItem {
|
class CanvasEntityItem : public EntityItem {
|
||||||
public:
|
public:
|
||||||
|
@ -28,10 +29,13 @@ public:
|
||||||
void setImageData(const QByteArray& data);
|
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);
|
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:
|
protected:
|
||||||
@Canvas_ENTITY_PROPS@
|
@Canvas_ENTITY_PROPS@
|
||||||
|
|
||||||
QByteArray _imageData;
|
QByteArray _imageData;
|
||||||
|
gpu::TexturePointer _texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_CanvasEntityItem_h
|
#endif // hifi_CanvasEntityItem_h
|
||||||
|
|
|
@ -267,7 +267,7 @@ enum:SOUND_LOOP prop:loop type:bool default:true,
|
||||||
enum:SOUND_POSITIONAL prop:positional type:bool default:true,
|
enum:SOUND_POSITIONAL prop:positional type:bool default:true,
|
||||||
enum:SOUND_LOCAL_ONLY prop:localOnly type:bool default:false,
|
enum:SOUND_LOCAL_ONLY prop:localOnly type:bool default:false,
|
||||||
Canvas
|
Canvas
|
||||||
enum:CANVAS_WIDTH prop:width type:uint16_t default:300 renderProp,
|
enum:CANVAS_WIDTH prop:width type:uint16_t default:300 basicProp,
|
||||||
enum:CANVAS_HEIGHT prop:height type:uint16_t default:150 renderProp,
|
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_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,
|
enum:CANVAS_BG_ALPHA prop:bgAlpha type:float default:1.0f min:0.0f max:1.0f basicProp,
|
||||||
|
|
|
@ -2702,7 +2702,6 @@ void EntityScriptingInterface::canvasSubmitImage(const QUuid& entityID, const QB
|
||||||
|
|
||||||
if (imageData.length() != canvas->getImageData().length()) {
|
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) << "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);
|
canvas->setImageData(imageData);
|
||||||
|
|
Loading…
Reference in a new issue