3#include "CADAttributeMap.h"
6#include "Bridge/BridgeApi.h"
7#include "Bridge/ResourceFunctions.h"
8#include "Resources/ResourceFlags.h"
9#include "Resources/Texture.h"
11#include "Cogs.Rendering/Rendering/DataFormat.h"
13#include <glm/vec2.hpp>
14#include <glm/vec3.hpp>
55 size_t childrenLength;
62 tagsTxtEntries.clear();
74 void addTag(std::string_view name,
int parentId, std::span<const int> children)
76 TagEntry& tag = tagsTxtEntries.emplace_back();
79 tag.nameLength = allNames.size() - tag.
nameOffset;
82 allChildren.insert(allChildren.end(), children.begin(), children.end());
87 size_t size()
const {
return tagsTxtEntries.size(); }
97 const TagEntry& e = this->tagsTxtEntries[index];
99 .
name = std::string_view(allNames.data() + e.
nameOffset, e.nameLength),
101 .children = std::span<const int>(allChildren.data() + e.
childrenOffset, e.childrenLength)
106 std::vector<TagEntry> tagsTxtEntries;
107 std::string allNames;
108 std::vector<int> allChildren;
124 : context(context), _attributeMap(powerOfTwoTextures)
127 textureId = ::getNextTextureId(context);
128 currentAttrSize = { 2, 2 };
129 _attributeMap.
resize(currentAttrSize);
140 CADAssetTexture& operator=(
const CADAssetTexture&) =
delete;
151 size_t getTagCount()
const {
return this->tagsTxtEntries.
size(); }
153 ITagEntry getTagAt(
size_t index)
const
155 return tagsTxtEntries.
getTagAt(index);
158 bool empty()
const {
return this->tagsTxtEntries.
size() == 0U; }
164 this->_attributeMap.
init(this->_attributeMap.
getDefaultColor(), this->_attributeMap.getDefaultAlpha());
177 this->_attributeMap.
setColor(index, color);
179 if (recurse && this->getTagCount() > index) {
180 const ITagEntry tag = this->getTagAt(index);
181 for (
const int childIndex : tag.
children) {
196 this->_attributeMap.
setAlpha(index, alpha);
198 if (recurse && this->getTagCount() > index) {
199 const ITagEntry tag = this->getTagAt(index);
200 for (
const int childIndex : tag.
children) {
212 bool resized = currentAttrSize != _attributeMap.
getAttrSize();
214 ::loadTextureResource(context, textureId, _attributeMap.
getAttributeMap().data(),
215 int(currentAttrSize.x),
int(currentAttrSize.y),
216 int(Cogs::TextureFormat::R8G8B8A8_UNORM), 0,
229 void addTag(std::string_view name,
int parentId, std::span<const int> children)
231 tagsTxtEntries.
addTag(name, parentId, children);
237 if (textureId != Cogs::Core::NoResourceId) {
238 ::releaseTexture(context, textureId);
239 textureId = Cogs::Core::NoResourceId;
245 CADAttributeMap _attributeMap;
246 TagContainer tagsTxtEntries;
247 ResourceId textureId;
248 glm::uvec2 currentAttrSize;
A Context instance contains all the services, systems and runtime components needed to use Cogs.
void updateColorById(size_t index, glm::uvec3 color, bool recurse)
CADAttributeMap & getAttributeMap()
bool updateAttributeMap()
CADAssetTexture(Cogs::Core::Context *context, bool powerOfTwoTextures=true)
void updateAlphaById(size_t index, AttributeMapAlpha alpha, bool recurse)
glm::uvec2 getAttrSize() const
void addTag(std::string_view name, int parentId, std::span< const int > children)
ResourceId getTextureId() const
void init(glm::uvec3 color, AttributeMapAlpha alpha)
glm::uvec2 getAttrSize() const
glm::uvec3 getDefaultColor() const
Get default color value.
void resize(glm::uvec2 attrSize)
bool growToContainIndex(size_t index)
std::span< const uint8_t > getAttributeMap() const
void setAlpha(size_t index, AttributeMapAlpha alpha)
void setColor(size_t index, glm::uvec3 color)
size_t size() const
Gets number of tags.
ITagEntry getTagAt(size_t index) const
void clear()
Clear tags storage.
void addTag(std::string_view name, int parentId, std::span< const int > children)
@ LinearColorSpace
For textures with RGBA format without color space information, mark the data as being in linear color...
@ NoMipMaps
Do not generate mipmaps.
std::span< const int > children