|
|
@@ -259,7 +259,7 @@ Atlas::Atlas(uint16_t _textureSize, uint16_t _maxRegionsCount)
|
|
|
BX_ASSERT(_textureSize >= 64 && _textureSize <= 4096, "Invalid _textureSize %d.", _textureSize);
|
|
|
BX_ASSERT(_maxRegionsCount >= 64 && _maxRegionsCount <= 32000, "Invalid _maxRegionsCount %d.", _maxRegionsCount);
|
|
|
|
|
|
- init();
|
|
|
+ m_texelSize = float(UINT16_MAX) / float(m_textureSize);
|
|
|
|
|
|
m_layers = new PackedLayer[6];
|
|
|
for (int ii = 0; ii < 6; ++ii)
|
|
|
@@ -287,7 +287,7 @@ Atlas::Atlas(uint16_t _textureSize, const uint8_t* _textureBuffer, uint16_t _reg
|
|
|
{
|
|
|
BX_ASSERT(_regionCount <= 64 && _maxRegionsCount <= 4096, "_regionCount %d, _maxRegionsCount %d", _regionCount, _maxRegionsCount);
|
|
|
|
|
|
- init();
|
|
|
+ m_texelSize = float(UINT16_MAX) / float(m_textureSize);
|
|
|
|
|
|
m_regions = new AtlasRegion[_regionCount];
|
|
|
m_textureBuffer = new uint8_t[getTextureBufferSize()];
|
|
|
@@ -313,30 +313,6 @@ Atlas::~Atlas()
|
|
|
delete [] m_textureBuffer;
|
|
|
}
|
|
|
|
|
|
-void Atlas::init()
|
|
|
-{
|
|
|
- m_texelSize = float(UINT16_MAX) / float(m_textureSize);
|
|
|
- float texelHalf = m_texelSize/2.0f;
|
|
|
- switch (bgfx::getRendererType() )
|
|
|
- {
|
|
|
- case bgfx::RendererType::Direct3D9:
|
|
|
- m_texelOffset[0] = 0.0f;
|
|
|
- m_texelOffset[1] = 0.0f;
|
|
|
- break;
|
|
|
-
|
|
|
- case bgfx::RendererType::Direct3D11:
|
|
|
- case bgfx::RendererType::Direct3D12:
|
|
|
- m_texelOffset[0] = texelHalf;
|
|
|
- m_texelOffset[1] = texelHalf;
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- m_texelOffset[0] = texelHalf;
|
|
|
- m_texelOffset[1] = -texelHalf;
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
uint16_t Atlas::addRegion(uint16_t _width, uint16_t _height, const uint8_t* _bitmapBuffer, AtlasRegion::Type _type, uint16_t outline)
|
|
|
{
|
|
|
if (m_regionCount >= m_maxRegionCount)
|
|
|
@@ -469,10 +445,10 @@ static void writeUV(uint8_t* _vertexBuffer, int16_t _x, int16_t _y, int16_t _z,
|
|
|
|
|
|
void Atlas::packUV(const AtlasRegion& _region, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const
|
|
|
{
|
|
|
- int16_t x0 = (int16_t)( ( (float)_region.x * m_texelSize + m_texelOffset[0]) - float(INT16_MAX) );
|
|
|
- int16_t y0 = (int16_t)( ( (float)_region.y * m_texelSize + m_texelOffset[1]) - float(INT16_MAX) );
|
|
|
- int16_t x1 = (int16_t)( ( ( (float)_region.x + _region.width) * m_texelSize + m_texelOffset[0]) - float(INT16_MAX) );
|
|
|
- int16_t y1 = (int16_t)( ( ( (float)_region.y + _region.height) * m_texelSize + m_texelOffset[1]) - float(INT16_MAX) );
|
|
|
+ int16_t x0 = (int16_t)( ( (float)_region.x * m_texelSize) - float(INT16_MAX) );
|
|
|
+ int16_t y0 = (int16_t)( ( (float)_region.y * m_texelSize) - float(INT16_MAX) );
|
|
|
+ int16_t x1 = (int16_t)( ( ( (float)_region.x + _region.width) * m_texelSize) - float(INT16_MAX) );
|
|
|
+ int16_t y1 = (int16_t)( ( ( (float)_region.y + _region.height) * m_texelSize) - float(INT16_MAX) );
|
|
|
int16_t ww = (int16_t)( (float(INT16_MAX) / 4.0f) * (float)_region.getComponentIndex() );
|
|
|
|
|
|
_vertexBuffer += _offset;
|