16 enum class AttributeMapPixelState : uint8_t {
21 SelectedAndHighlighted = 4,
87 enum class AttributeMapPixelTransparency : uint8_t {
96 AttributeMapPixelTransparency transparency;
97 AttributeMapPixelState state;
119 : powerOfTwoTextures(powerOfTwoTextures)
142 uint32_t size = this->_attrSize.x * this->_attrSize.y;
143 for (uint32_t i = 0; i < size; i++) {
173 const size_t offset = index * 4;
174 this->_attributeMap[offset + 0] = uint8_t(color[0]);
175 this->_attributeMap[offset + 1] = uint8_t(color[1]);
176 this->_attributeMap[offset + 2] = uint8_t(color[2]);
185 const size_t offset = index * 4;
186 return glm::vec3(this->_attributeMap[offset + 0], this->_attributeMap[offset + 1], this->_attributeMap[offset + 2]);
217 return index * 4U < this->_attributeMap.size();
229 return this->_attributeMap[index * 4 + attrOffset];
241 this->_attributeMap[index * 4 + attrOffset] = attribute;
251 attrSize.x = std::max(2U, attrSize.x);
252 attrSize.y = std::max(2U, attrSize.y);
254 if (attrSize != this->_attrSize) {
255 glm::uvec2 oldSize = this->_attrSize;
256 this->_attrSize = attrSize;
257 this->_attributeMap.resize(this->_attrSize.x * this->_attrSize.y * 4);
259 if (attrSize.x > oldSize.x || attrSize.y > oldSize.y) {
261 uint32_t oldMaxIndex = oldSize.x * oldSize.y;
262 uint32_t newMaxSize = attrSize.x * attrSize.y;
263 for (uint32_t i = oldMaxIndex; i < newMaxSize; ++i) {
279 static constexpr uint32_t MinTexSize = 8;
280 uint32_t sizeX = MinTexSize;
281 while (sizeX * sizeX < tagCount) {
286 return { sizeX, sizeX };
289 uint32_t sizeY = MinTexSize;
290 while (sizeX * sizeY < tagCount) {
293 return { sizeX, sizeY };
309 defaultAlpha = alpha;
318 defaultColor = color;
333 const uint8_t bits = (uint8_t(data.state) << 2) | uint8_t(data.transparency);
345 AttributeMapPixelTransparency transparency = AttributeMapPixelTransparency(alpha & 3U);
346 AttributeMapPixelState state = AttributeMapPixelState(alpha >> 2U);
347 return { transparency, state };
351 bool powerOfTwoTextures =
true;
352 glm::uvec2 _attrSize = {};
353 std::vector<uint8_t> _attributeMap;
354 glm::uvec3 defaultColor = { 0,0,0 };
355 AttributeMapAlpha defaultAlpha = { AttributeMapPixelTransparency::Off, AttributeMapPixelState::Default, };
void init(glm::uvec3 color, AttributeMapAlpha alpha)
static constexpr uint8_t encodeAlpha(AttributeMapAlpha data) noexcept
AttributeMapAlpha getAlpha(size_t index)
CADAttributeMap(bool powerOfTwoTextures=true)
void setAttribute(size_t index, size_t attrOffset, uint8_t attribute)
bool isValidIndex(size_t index) const
glm::uvec2 getAttrSize() const
void setDefaultColor(glm::uvec3 color)
Set default color value.
static glm::uvec2 getAttributeSize(size_t tagCount, bool powerOfTwo)
static constexpr AttributeMapAlpha decodeAlpha(uint8_t alpha)
uint8_t getAttribute(size_t index, size_t attrOffset)
void setDefaultAlpha(AttributeMapAlpha alpha)
Get default Alpha entry.
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)
AttributeMapAlpha getDefaultAlpha() const
glm::vec3 getColor(size_t index) const
void setColor(size_t index, glm::uvec3 color)
@ Off
Disable capture and camera, consume no rendering resources.