MetaData.h#

Parent directory (texture)

The definition of the class used to represent Texture metadata.

Includes#

  • cstdint

  • cstring

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include <cstdint>
#include <cstring>

namespace pvr {
class TextureMetaData
{
public:
    enum Identifier
    {
        IdentifierTextureAtlasCoords = 0,
        IdentifierBumpData,
        IdentifierCubeMapOrder,
        IdentifierTextureOrientation,
        IdentifierBorderData,
        IdentifierPadding,
        IdentifierPerChannelType,
        IdentifierSupercompressionGlobalData,
        IdentifierMaxRange,
        IdentifierNumMetaDataTypes
    };

    enum Axis
    {
        AxisAxisX = 0,
        AxisAxisY = 1,
        AxisAxisZ = 2
    };

    enum AxisOrientation
    {
        AxisOrientationLeft = 1 << AxisAxisX,
        AxisOrientationRight = 0,
        AxisOrientationUp = 1 << AxisAxisY,
        AxisOrientationDown = 0,
        AxisOrientationOut = 1 << AxisAxisZ,
        AxisOrientationIn = 0
    };

public:
    TextureMetaData() : _fourCC(0), _key(0), _dataSize(0), _data(NULL) {}

    TextureMetaData(uint32_t fourCC, uint32_t key, uint32_t dataSize, const char* data) : _fourCC(0), _key(0), _dataSize(0), _data(NULL)
    {
        // Copy the data across.
        if (dataSize)
        {
            _data = new unsigned char[dataSize];
            memset(_data, 0, sizeof(unsigned char) * dataSize);
        }
        if (_data)
        {
            _fourCC = fourCC;
            _key = key;
            _dataSize = dataSize;
            if (data) { memcpy(_data, data, _dataSize); }
        }
    }

    TextureMetaData(const TextureMetaData& rhs) : _fourCC(0), _key(0), _dataSize(0), _data(NULL)
    {
        // Copy the data across.
        if (rhs._dataSize)
        {
            _data = new unsigned char[rhs._dataSize];
            memset(_data, 0, sizeof(unsigned char) * rhs._dataSize);
        }
        if (_data)
        {
            _fourCC = rhs._fourCC;
            _key = rhs._key;
            _dataSize = rhs._dataSize;
            if (rhs._data) { memcpy(_data, rhs._data, _dataSize); }
        }
    }
    TextureMetaData(const TextureMetaData&& rhs) : _fourCC(0), _key(0), _dataSize(0), _data(NULL)
    {
        // Copy the data across.
        if (rhs._dataSize)
        {
            _data = new unsigned char[rhs._dataSize];
            memset(_data, 0, sizeof(unsigned char) * rhs._dataSize);
        }
        if (_data)
        {
            _fourCC = rhs._fourCC;
            _key = rhs._key;
            _dataSize = rhs._dataSize;
            if (rhs._data) { memcpy(_data, rhs._data, _dataSize); }
        }
    }

    ~TextureMetaData()
    {
        if (_data)
        {
            delete[] _data;
            _data = NULL;
        }
    }

    TextureMetaData& operator=(const TextureMetaData& rhs)
    {
        // If it equals itself, return early.
        if (&rhs == this) { return *this; }

        // Initialize
        _fourCC = _key = _dataSize = 0;

        // Delete any old data
        if (_data)
        {
            delete[] _data;
            _data = NULL;
        }

        // Copy the data across.
        _data = new unsigned char[rhs._dataSize];
        if (_data)
        {
            _fourCC = rhs._fourCC;
            _key = rhs._key;
            _dataSize = rhs._dataSize;
            if (rhs._data) { memcpy(_data, rhs._data, _dataSize); }
        }

        return *this;
    }

    uint32_t getFourCC() const { return _fourCC; }

    uint32_t getDataSize() const { return _dataSize; }

    uint32_t getKey() const { return _key; }

    const unsigned char* getData() const { return _data; }
    unsigned char* getData() { return _data; }

    uint32_t getTotalSizeInMemory() const { return sizeof(_fourCC) + sizeof(_key) + sizeof(_dataSize) + _dataSize; }

private:
    uint32_t _fourCC; // A 4cc descriptor of the data type's creator.
    // Values equating to values between 'P' 'V' 'R' 0 and 'P' 'V' 'R' 255 will be used by our headers.
    uint32_t _key; // Enumeration key identifying the data type.
    uint32_t _dataSize; // Size of attached data.
    unsigned char* _data; // Data array, can be absolutely anything, the loader needs to know how to handle it based on fourCC and key.
};
} // namespace pvr