Cogs.Core
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Cogs::Editor::CADAttributeMap Class Referencefinal

#include <CADAttributeMap.h>

Public Member Functions

 CADAttributeMap (bool powerOfTwoTextures=true)
 
 CADAttributeMap (const CADAttributeMap &)=delete
 
CADAttributeMapoperator= (const CADAttributeMap &)=delete
 
std::span< const uint8_t > getAttributeMap () const
 
glm::uvec2 getAttrSize () const
 
void init (glm::uvec3 color, AttributeMapAlpha alpha)
 
bool growToContainIndex (size_t index)
 
void setColor (size_t index, glm::uvec3 color)
 
glm::vec3 getColor (size_t index) const
 
void setAlpha (size_t index, AttributeMapAlpha alpha)
 
AttributeMapAlpha getAlpha (size_t index)
 
bool isValidIndex (size_t index) const
 
uint8_t getAttribute (size_t index, size_t attrOffset)
 
void setAttribute (size_t index, size_t attrOffset, uint8_t attribute)
 
void resize (glm::uvec2 attrSize)
 
AttributeMapAlpha getDefaultAlpha () const
 
void setDefaultAlpha (AttributeMapAlpha alpha)
 Get default Alpha entry.
 
glm::uvec3 getDefaultColor () const
 Get default color value.
 
void setDefaultColor (glm::uvec3 color)
 Set default color value.
 

Static Public Member Functions

static glm::uvec2 getAttributeSize (size_t tagCount, bool powerOfTwo)
 
static constexpr uint8_t encodeAlpha (AttributeMapAlpha data) noexcept
 
static constexpr AttributeMapAlpha decodeAlpha (uint8_t alpha)
 

Private Attributes

bool powerOfTwoTextures = true
 
glm::uvec2 _attrSize = {}
 
std::vector< uint8_t > _attributeMap
 
glm::uvec3 defaultColor = { 0,0,0 }
 
AttributeMapAlpha defaultAlpha = { AttributeMapPixelTransparency::Off, AttributeMapPixelState::Default, }
 

Detailed Description

Handles Attribute map used to show a Cogs Asset without coloring, but with 2D Texture given an index into a CAD TAG mapping.

The Attribute map can be fed into a Cogs Texture. Colors are always passed as 8bit unsigned ints. The alpha channel is divided into two parts encoded using

See also
AttributeMapAlpha. Transparency is limited to two bits
AttributeMapPixelTransparency. Tag state is selectable using
AttributeMapPixelState Custom pixel shader is required to Display the data.

Definition at line 112 of file CADAttributeMap.h.

Constructor & Destructor Documentation

◆ CADAttributeMap()

Cogs::Editor::CADAttributeMap::CADAttributeMap ( bool  powerOfTwoTextures = true)
inlineexplicit

Initialized a new CADAttributeMap.

Parameters
powerOfTwoTextures- True if textures must be power of 2

Definition at line 118 of file CADAttributeMap.h.

Member Function Documentation

◆ decodeAlpha()

static constexpr AttributeMapAlpha Cogs::Editor::CADAttributeMap::decodeAlpha ( uint8_t  alpha)
inlinestaticconstexpr

Decodes the given alpha channel data into separate enum values for transparency and state. Any changes to this function need to also be synced with the equivalents in GLSL; CustomPS.es30

Definition at line 341 of file CADAttributeMap.h.

Referenced by getAlpha().

◆ encodeAlpha()

static constexpr uint8_t Cogs::Editor::CADAttributeMap::encodeAlpha ( AttributeMapAlpha  data)
inlinestaticconstexprnoexcept

Combines the given alpha state and the given data state, and returns an alpha number that can be unpacked into both of these later. Any changes to this function need to also be synced with the equivalents in GLSL; CustomPS.es30

Definition at line 325 of file CADAttributeMap.h.

Referenced by setAlpha().

◆ getAlpha()

AttributeMapAlpha Cogs::Editor::CADAttributeMap::getAlpha ( size_t  index)
inline

Gets the Alpha value for given Tag index.

Parameters
index- Tag Index.
Returns
Decoded alpha.

Definition at line 204 of file CADAttributeMap.h.

References decodeAlpha().

◆ getAttribute()

uint8_t Cogs::Editor::CADAttributeMap::getAttribute ( size_t  index,
size_t  attrOffset 
)
inline

Low level access: Get Specific attribute (RGBA) at given index.

Parameters
index- Tag index.
attrOffset- Attribute selector R=0..A=3
Returns
Attribute value

Definition at line 227 of file CADAttributeMap.h.

◆ getAttributeMap()

std::span< const uint8_t > Cogs::Editor::CADAttributeMap::getAttributeMap ( ) const
inline

Gets attribute map that can be passed to a Cogs texture as an array of 4 8bit values per entry.

Definition at line 128 of file CADAttributeMap.h.

Referenced by Cogs::Editor::CADAssetTexture::updateAttributeMap().

◆ getAttributeSize()

static glm::uvec2 Cogs::Editor::CADAttributeMap::getAttributeSize ( size_t  tagCount,
bool  powerOfTwo 
)
inlinestatic

Calculate texture dimensions to ensure NXY*NXY >== tagCount

Parameters
tagCount- Number of tags.
powerOfTwo- Require texture size to be power ot 2.
Returns
Texture dimensions in X and Y.

Definition at line 277 of file CADAttributeMap.h.

Referenced by growToContainIndex().

◆ getAttrSize()

glm::uvec2 Cogs::Editor::CADAttributeMap::getAttrSize ( ) const
inline

Gets attr size. E.g. Texture dimension in X and Y.

Definition at line 133 of file CADAttributeMap.h.

Referenced by Cogs::Editor::CADAssetTexture::getAttrSize(), and Cogs::Editor::CADAssetTexture::updateAttributeMap().

◆ getColor()

glm::vec3 Cogs::Editor::CADAttributeMap::getColor ( size_t  index) const
inline

Get RGB Color (0-255) of the given attribute index.

Parameters
index- Tag index.
Returns
Color

Definition at line 184 of file CADAttributeMap.h.

◆ getDefaultAlpha()

AttributeMapAlpha Cogs::Editor::CADAttributeMap::getDefaultAlpha ( ) const
inline

Get default Alpha entry.

Returns
Encoded Attribute. Note custom encoding of Alpha (W) channel.

Definition at line 301 of file CADAttributeMap.h.

◆ getDefaultColor()

glm::uvec3 Cogs::Editor::CADAttributeMap::getDefaultColor ( ) const
inline

Get default color value.

Definition at line 313 of file CADAttributeMap.h.

Referenced by Cogs::Editor::CADAssetTexture::showAll().

◆ growToContainIndex()

bool Cogs::Editor::CADAttributeMap::growToContainIndex ( size_t  index)
inline

Increase size of attribute map if needed to include the index in the map. can be used for dynamic resizing og the attribute map.

Parameters
index- Index to check.
Returns
True if map resized, e.g. Texture must be uploaded to Cogs.

Definition at line 155 of file CADAttributeMap.h.

References getAttributeSize(), isValidIndex(), and resize().

Referenced by Cogs::Editor::CADAssetTexture::updateAlphaById(), and Cogs::Editor::CADAssetTexture::updateColorById().

◆ init()

void Cogs::Editor::CADAttributeMap::init ( glm::uvec3  color,
AttributeMapAlpha  alpha 
)
inline

Init the Attribute map filling with given values.

Parameters
color- Color values to set.
alpha- Alpha value to set.

Definition at line 140 of file CADAttributeMap.h.

References setAlpha(), and setColor().

Referenced by Cogs::Editor::CADAssetTexture::showAll().

◆ isValidIndex()

bool Cogs::Editor::CADAttributeMap::isValidIndex ( size_t  index) const
inline

Check if index is valid, e.g. if map is large enough to contain index.

Parameters
index- Index to check.
Returns
True if valid, false if map must grow to contain the index.

Definition at line 215 of file CADAttributeMap.h.

Referenced by growToContainIndex().

◆ resize()

void Cogs::Editor::CADAttributeMap::resize ( glm::uvec2  attrSize)
inline

Resize the map, keeping values from the old map.

Parameters
attrSize- New Attribute size in X and Y.

Definition at line 248 of file CADAttributeMap.h.

References setAlpha(), and setColor().

Referenced by Cogs::Editor::CADAssetTexture::CADAssetTexture(), and growToContainIndex().

◆ setAlpha()

void Cogs::Editor::CADAttributeMap::setAlpha ( size_t  index,
AttributeMapAlpha  alpha 
)
inline

Set the Alpha value for the given Tag index.

Parameters
index- Tag index.
alpha- Decoded Alpha

Definition at line 194 of file CADAttributeMap.h.

References encodeAlpha().

Referenced by init(), resize(), and Cogs::Editor::CADAssetTexture::updateAlphaById().

◆ setAttribute()

void Cogs::Editor::CADAttributeMap::setAttribute ( size_t  index,
size_t  attrOffset,
uint8_t  attribute 
)
inline

Low level access: Set Texture CADAttributeMap at given index and offset(RGBA) to Source attribute.

Parameters
index- Tag index.
attrOffset- Source offset
attribute- New Attributes at index

Definition at line 239 of file CADAttributeMap.h.

◆ setColor()

void Cogs::Editor::CADAttributeMap::setColor ( size_t  index,
glm::uvec3  color 
)
inline

Get RGB Color (0-255) of the given attribute index.

Parameters
index- Tag index.
color- Color to set.

Definition at line 171 of file CADAttributeMap.h.

Referenced by init(), resize(), and Cogs::Editor::CADAssetTexture::updateColorById().

◆ setDefaultAlpha()

void Cogs::Editor::CADAttributeMap::setDefaultAlpha ( AttributeMapAlpha  alpha)
inline

Get default Alpha entry.

Definition at line 307 of file CADAttributeMap.h.

◆ setDefaultColor()

void Cogs::Editor::CADAttributeMap::setDefaultColor ( glm::uvec3  color)
inline

Set default color value.

Definition at line 316 of file CADAttributeMap.h.

Member Data Documentation

◆ _attributeMap

std::vector<uint8_t> Cogs::Editor::CADAttributeMap::_attributeMap
private

Definition at line 353 of file CADAttributeMap.h.

◆ _attrSize

glm::uvec2 Cogs::Editor::CADAttributeMap::_attrSize = {}
private

Definition at line 352 of file CADAttributeMap.h.

◆ defaultAlpha

AttributeMapAlpha Cogs::Editor::CADAttributeMap::defaultAlpha = { AttributeMapPixelTransparency::Off, AttributeMapPixelState::Default, }
private

Definition at line 355 of file CADAttributeMap.h.

◆ defaultColor

glm::uvec3 Cogs::Editor::CADAttributeMap::defaultColor = { 0,0,0 }
private

Definition at line 354 of file CADAttributeMap.h.

◆ powerOfTwoTextures

bool Cogs::Editor::CADAttributeMap::powerOfTwoTextures = true
private

Definition at line 351 of file CADAttributeMap.h.


The documentation for this class was generated from the following file: