This commit is contained in:
bkaradzic 2013-05-29 22:47:19 -07:00
parent af842a1c68
commit b8a69a700b
4 changed files with 28 additions and 24 deletions

View file

@ -455,28 +455,28 @@ void Atlas::updateRegion(const AtlasRegion& _region, const uint8_t* _bitmapBuffe
bgfx::updateTextureCube(m_textureHandle, (uint8_t)_region.getFaceIndex(), 0, _region.x, _region.y, _region.width, _region.height, mem);
}
void Atlas::packFaceLayerUV(uint32_t _idx, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride)
void Atlas::packFaceLayerUV(uint32_t _idx, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const
{
packUV(m_layers[_idx].faceRegion, _vertexBuffer, _offset, _stride);
}
void Atlas::packUV(uint16_t handle, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride)
void Atlas::packUV(uint16_t _regionHandle, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const
{
const AtlasRegion& region = m_regions[handle];
const AtlasRegion& region = m_regions[_regionHandle];
packUV(region, _vertexBuffer, _offset, _stride);
}
void Atlas::packUV(const AtlasRegion& _region, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride)
void Atlas::packUV(const AtlasRegion& _region, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const
{
static const int16_t minVal = -32768;
static const int16_t maxVal = 32767;
static const int16_t minVal = INT16_MIN;
static const int16_t maxVal = INT16_MAX;
float texMult = (float)(maxVal - minVal) / ( (float)(m_textureSize) );
int16_t x0 = (int16_t)( ((float)_region.x * texMult) - 32767.0f);
int16_t y0 = (int16_t)( ((float)_region.y * texMult) - 32767.0f);
int16_t x1 = (int16_t)( (((float)_region.x + _region.width) * texMult) - 32767.0f);
int16_t y1 = (int16_t)( (((float)_region.y + _region.height) * texMult) - 32767.0f);
int16_t w = (int16_t) ( (32767.0f / 4.0f) * (float) _region.getComponentIndex() );
int16_t x0 = (int16_t)( ((float)_region.x * texMult) - float(INT16_MAX) );
int16_t y0 = (int16_t)( ((float)_region.y * texMult) - float(INT16_MAX) );
int16_t x1 = (int16_t)( (((float)_region.x + _region.width) * texMult) - float(INT16_MAX) );
int16_t y1 = (int16_t)( (((float)_region.y + _region.height) * texMult) - float(INT16_MAX) );
int16_t w = (int16_t) ( (float(INT16_MAX) / 4.0f) * (float) _region.getComponentIndex() );
_vertexBuffer += _offset;
switch (_region.getFaceIndex() )

View file

@ -80,14 +80,14 @@ public:
/// @param vertexBuffer address of the first vertex we want to update. Must be valid up to vertexBuffer + offset + 3*stride + 4*sizeof(int16_t), which means the buffer must contains at least 4 vertex includind the first.
/// @param offset byte offset to the first uv coordinate of the vertex in the buffer
/// @param stride stride between tho UV coordinates, usually size of a Vertex.
void packUV(uint16_t _regionHandle, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride);
void packUV(const AtlasRegion& _region, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride);
void packUV(uint16_t _regionHandle, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const;
void packUV(const AtlasRegion& _region, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const;
/// Same as packUV but pack a whole face of the atlas cube, mostly used for debugging and visualizing atlas
void packFaceLayerUV(uint32_t _idx, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride);
void packFaceLayerUV(uint32_t _idx, uint8_t* _vertexBuffer, uint32_t _offset, uint32_t _stride) const;
/// Pack the vertex index of the region as 2 quad into an index buffer
void packIndex(uint16_t* _indexBuffer, uint32_t _startIndex, uint32_t _startVertex)
void packIndex(uint16_t* _indexBuffer, uint32_t _startIndex, uint32_t _startVertex) const
{
_indexBuffer[_startIndex + 0] = _startVertex + 0;
_indexBuffer[_startIndex + 1] = _startVertex + 1;
@ -143,7 +143,7 @@ public:
}
private:
void writeUV(uint8_t* _vertexBuffer, int16_t _x, int16_t _y, int16_t _z, int16_t _w)
static void writeUV(uint8_t* _vertexBuffer, int16_t _x, int16_t _y, int16_t _z, int16_t _w)
{
( (uint16_t*) _vertexBuffer)[0] = _x;
( (uint16_t*) _vertexBuffer)[1] = _y;

View file

@ -127,7 +127,7 @@ public:
~FontManager();
/// Retrieve the atlas used by the font manager (e.g. to add stuff to it)
Atlas* getAtlas()
const Atlas* getAtlas() const
{
return m_atlas;
}

View file

@ -368,6 +368,7 @@ void TextBuffer::appendGlyph(FontHandle _handle, CodePoint _codePoint)
m_penX += kerning;
const GlyphInfo& blackGlyph = m_fontManager->getBlackGlyph();
const Atlas* atlas = m_fontManager->getAtlas();
if (m_styleFlags & STYLE_BACKGROUND
&& m_backgroundColor & 0xFF000000)
@ -377,7 +378,7 @@ void TextBuffer::appendGlyph(FontHandle _handle, CodePoint _codePoint)
float x1 = ( (float)x0 + (glyph->advance_x) );
float y1 = (m_penY + m_lineAscender - m_lineDescender + m_lineGap);
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex
atlas->packUV(blackGlyph.regionIndex
, (uint8_t*)m_vertexBuffer
, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u)
, sizeof(TextVertex)
@ -406,7 +407,7 @@ void TextBuffer::appendGlyph(FontHandle _handle, CodePoint _codePoint)
float x1 = ( (float)x0 + (glyph->advance_x) );
float y1 = y0 + font.underlineThickness;
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex
atlas->packUV(blackGlyph.regionIndex
, (uint8_t*)m_vertexBuffer
, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u)
, sizeof(TextVertex)
@ -464,7 +465,7 @@ void TextBuffer::appendGlyph(FontHandle _handle, CodePoint _codePoint)
float x1 = ( (float)x0 + (glyph->advance_x) );
float y1 = y0 + font.underlineThickness;
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex
atlas->packUV(blackGlyph.regionIndex
, (uint8_t*)m_vertexBuffer
, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u)
, sizeof(TextVertex)
@ -490,7 +491,7 @@ void TextBuffer::appendGlyph(FontHandle _handle, CodePoint _codePoint)
float x1 = (x0 + glyph->width);
float y1 = (y0 + glyph->height);
m_fontManager->getAtlas()->packUV(glyph->regionIndex
atlas->packUV(glyph->regionIndex
, (uint8_t*)m_vertexBuffer
, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u)
, sizeof(TextVertex)
@ -757,7 +758,8 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount() );
bgfx::setIndexBuffer(ibh, bc.textBuffer->getIndexCount() );
} break;
}
break;
case DYNAMIC:
{
@ -793,7 +795,8 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount() );
bgfx::setIndexBuffer(ibh, bc.textBuffer->getIndexCount() );
} break;
}
break;
case TRANSIENT:
{
@ -805,7 +808,8 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
memcpy(tvb.data, bc.textBuffer->getVertexBuffer(), vertexSize);
bgfx::setVertexBuffer(&tvb, bc.textBuffer->getVertexCount() );
bgfx::setIndexBuffer(&tib, bc.textBuffer->getIndexCount() );
} break;
}
break;
}
bgfx::submit(_id, _depth);