From e97ded844b029c3833688a7f27ef326941f4dff7 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 26 Feb 2025 02:54:59 +1000 Subject: [PATCH] Initial broken work for Canvas entity --- .../src/RenderableCanvasEntityItem.cpp | 33 +++++++ .../src/RenderableCanvasEntityItem.h | 41 +++++++++ .../entities/src/CanvasEntityItem.cpp.in | 88 +++++++++++++++++++ libraries/entities/src/CanvasEntityItem.h.in | 28 ++++++ .../entities/src/EntityItemProperties.txt | 3 +- libraries/entities/src/EntityTypes.cpp | 2 + libraries/entities/src/EntityTypes.h | 1 + 7 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp create mode 100644 libraries/entities-renderer/src/RenderableCanvasEntityItem.h create mode 100644 libraries/entities/src/CanvasEntityItem.cpp.in create mode 100644 libraries/entities/src/CanvasEntityItem.h.in diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp new file mode 100644 index 0000000000..238eca3370 --- /dev/null +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.cpp @@ -0,0 +1,33 @@ +// +// Created by Ada on 2025-02-24 +// Copyright 2025 Overte e.V. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "RenderableCanvasEntityItem.h" + +using namespace render; +using namespace render::entities; + +CanvasEntityRenderer::CanvasEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { + gpu::Byte pixels[256 * 256 * 4]; + + // grayscale XOR placeholder texture + 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__); +} + +CanvasEntityRenderer::~CanvasEntityRenderer() { } diff --git a/libraries/entities-renderer/src/RenderableCanvasEntityItem.h b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h new file mode 100644 index 0000000000..050a6be02f --- /dev/null +++ b/libraries/entities-renderer/src/RenderableCanvasEntityItem.h @@ -0,0 +1,41 @@ +// +// Created by Ada on 2025-02-24 +// Copyright 2025 Overte e.V. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef hifi_RenderableCanvasEntityItem_h +#define hifi_RenderableCanvasEntityItem_h + +#include +#include "RenderableEntityItem.h" + +namespace render { namespace entities { + +class CanvasEntityRenderer : public TypedEntityRenderer { + Q_OBJECT + using Parent = TypedEntityRenderer; + friend class EntityRenderer; + +public: + CanvasEntityRenderer(const EntityItemPointer& entity); + ~CanvasEntityRenderer(); + + gpu::TexturePointer getTexture() override { return _texture; } + +protected: + virtual void doRender(RenderArgs* args) override { } + virtual bool isTransparent() const override { return false; } + virtual bool wantsHandControllerPointerEvents() const override { return false; } + virtual bool wantsKeyboardFocus() const override { return false; } + +private: + gpu::TexturePointer _texture; +}; + +} } + +#endif // hifi_RenderableCanvasEntityItem_h diff --git a/libraries/entities/src/CanvasEntityItem.cpp.in b/libraries/entities/src/CanvasEntityItem.cpp.in new file mode 100644 index 0000000000..2b16fe7dd4 --- /dev/null +++ b/libraries/entities/src/CanvasEntityItem.cpp.in @@ -0,0 +1,88 @@ +// +// Created by Ada on 2025-02-04 +// Copyright 2025 Overte e.V. +// +// Distributed under the Apache license, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +#include "CanvasEntityItem.h" + +#include + +#include "EntitiesLogging.h" +#include "EntityItemProperties.h" +#include "EntityTreeElement.h" + +EntityItemPointer CanvasEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + std::shared_ptr entity(new CanvasEntityItem(entityID), [](CanvasEntityItem* ptr) { ptr->deleteLater(); }); + entity->setProperties(properties); + return entity; +} + +CanvasEntityItem::CanvasEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { + _type = EntityTypes::Canvas; +} + +CanvasEntityItem::~CanvasEntityItem() {} + +void CanvasEntityItem::debugDump() const { + qCDebug(entities) << "CanvasEntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " name:" << _name; + qCDebug(entities) << " position:" << debugTreeVector(getWorldPosition()); + qCDebug(entities) << " dimensions:" << debugTreeVector(getScaledDimensions()); + qCDebug(entities) << " editedAgo:" << debugTime(getLastEdited(), usecTimestampNow()); + qCDebug(entities) << " pointer:" << this; + + @Base_ENTITY_DEBUG@ + +} + +void CanvasEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + @Canvas_ENTITY_APPEND@ + +} + +int CanvasEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData, + bool& somethingChanged) { + int bytesRead = 0; + const unsigned char* dataAt = data; + + @Canvas_ENTITY_READ@ + + return bytesRead; +} + +EntityPropertyFlags CanvasEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + + @Canvas_REQUESTED_PROPS@ + + return requestedProperties; +} + +bool CanvasEntityItem::setSubClassProperties(const EntityItemProperties& properties) { + bool somethingChanged = false; + + @Canvas_ENTITY_SET_FROM@ + + return somethingChanged; +} + +EntityItemProperties CanvasEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const { + EntityItemProperties properties = EntityItem::getProperties(desiredProperties, allowEmptyDesiredProperties); // get the properties from our base class + + @Canvas_ENTITY_COPY_TO@ + + return properties; +} diff --git a/libraries/entities/src/CanvasEntityItem.h.in b/libraries/entities/src/CanvasEntityItem.h.in new file mode 100644 index 0000000000..0eff35dddc --- /dev/null +++ b/libraries/entities/src/CanvasEntityItem.h.in @@ -0,0 +1,28 @@ +// +// Created by Ada on 2025-02-04 +// Copyright 2025 Overte e.V. +// +// Distributed under the Apache license, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +#ifndef hifi_CanvasEntityItem_h +#define hifi_CanvasEntityItem_h + +#include "EntityItem.h" + +class CanvasEntityItem : public EntityItem { +public: + static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + CanvasEntityItem(const EntityItemID& entityItemID); + ~CanvasEntityItem(); + + bool shouldBePhysical() const override { return false; } + + virtual bool supportsDetailedIntersection() const override { return false; } + + ALLOW_INSTANTIATION // This class can be instantiated + ENTITY_PROPERTY_SUBCLASS_METHODS +}; + +#endif // hifi_CanvasEntityItem_h diff --git a/libraries/entities/src/EntityItemProperties.txt b/libraries/entities/src/EntityItemProperties.txt index 6fde40d0ab..a7489f6981 100644 --- a/libraries/entities/src/EntityItemProperties.txt +++ b/libraries/entities/src/EntityItemProperties.txt @@ -265,4 +265,5 @@ enum:SOUND_PITCH, prop:pitch type:float default:1.0f min:1.0f/16.0f max:16.0f, enum:SOUND_PLAYING prop:playing type:bool default:true, 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, \ No newline at end of file +enum:SOUND_LOCAL_ONLY prop:localOnly type:bool default:false, +Canvas diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 2873920793..ac847e8dce 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -37,6 +37,7 @@ #include "ZoneEntityItem.h" #include "MaterialEntityItem.h" #include "SoundEntityItem.h" +#include "CanvasEntityItem.h" QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; @@ -64,6 +65,7 @@ REGISTER_ENTITY_TYPE(Light) REGISTER_ENTITY_TYPE(Zone) REGISTER_ENTITY_TYPE(Material) REGISTER_ENTITY_TYPE(Sound) +REGISTER_ENTITY_TYPE(Canvas) bool EntityTypes::typeIsValid(EntityType type) { return type > EntityType::Unknown && type <= EntityType::NUM_TYPES; diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 2b14e417df..ed4c3108f0 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -116,6 +116,7 @@ public: Zone, Material, Sound, + Canvas, NUM_TYPES } EntityType;