mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Fix font rendering (#2653)
* Fix subpixel font rendering * remove const
This commit is contained in:
@@ -266,7 +266,10 @@ public:
|
||||
float view[16];
|
||||
bx::mtxLookAt(view, eye, at);
|
||||
|
||||
const float centering = 0.5f;
|
||||
float centering = 0.0f;
|
||||
if (bgfx::getRendererType() == bgfx::RendererType::Direct3D9) {
|
||||
centering = -0.5f;
|
||||
}
|
||||
|
||||
// Setup a top-left ortho matrix for screen space drawing.
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
|
||||
@@ -253,7 +253,10 @@ public:
|
||||
float view[16];
|
||||
bx::mtxLookAt(view, eye, at);
|
||||
|
||||
const float centering = 0.5f;
|
||||
float centering = 0.0f;
|
||||
if (bgfx::getRendererType() == bgfx::RendererType::Direct3D9) {
|
||||
centering = -0.5f;
|
||||
}
|
||||
|
||||
// Setup a top-left ortho matrix for screen space drawing.
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -135,8 +135,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
struct PackedLayer;
|
||||
PackedLayer* m_layers;
|
||||
AtlasRegion* m_regions;
|
||||
@@ -148,7 +146,6 @@ private:
|
||||
bgfx::TextureHandle m_textureHandle;
|
||||
uint16_t m_textureSize;
|
||||
float m_texelSize;
|
||||
float m_texelOffset[2];
|
||||
|
||||
uint16_t m_regionCount;
|
||||
uint16_t m_maxRegionCount;
|
||||
|
||||
Reference in New Issue
Block a user