sRGB support for D3D9

This commit is contained in:
MikePopoloski 2015-05-02 23:54:51 -04:00
parent 8919b15468
commit d5923e25fe
2 changed files with 12 additions and 1 deletions

View File

@ -1895,6 +1895,7 @@ namespace bgfx
_imageContainer.m_hasAlpha = hasAlpha;
_imageContainer.m_cubeMap = numFaces > 1;
_imageContainer.m_ktx = false;
_imageContainer.m_srgb = colorSpace > 0;
return TextureFormat::Unknown != format;
}

View File

@ -1077,6 +1077,8 @@ namespace bgfx { namespace d3d9
DX_CHECK(m_device->SetRenderTarget(ii, NULL) );
}
DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) );
DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_flags & BGFX_RESET_SRGB_BACKBUFFER) ));
}
else
{
@ -1098,6 +1100,8 @@ namespace bgfx { namespace d3d9
IDirect3DSurface9* depthStencil = frameBuffer.m_depthStencil;
DX_CHECK(m_device->SetDepthStencilSurface(NULL != depthStencil ? depthStencil : m_backBufferDepthStencil) );
DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE) );
}
m_fbh = _fbh;
@ -1288,7 +1292,7 @@ namespace bgfx { namespace d3d9
void setSamplerState(uint8_t _stage, uint32_t _flags, bool _vertex = false)
{
const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK);
const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK | BGFX_TEXTURE_SRGB);
BX_CHECK(_stage < BX_COUNTOF(m_samplerFlags), "");
if (m_samplerFlags[_stage][_vertex] != flags)
{
@ -1310,6 +1314,7 @@ namespace bgfx { namespace d3d9
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAGFILTER, magFilter) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MIPFILTER, mipFilter) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_SRGBTEXTURE, 0 != (flags & BGFX_TEXTURE_SRGB)) );
}
}
@ -2423,6 +2428,11 @@ namespace bgfx { namespace d3d9
createTexture(textureWidth, textureHeight, numMips);
}
if (imageContainer.m_srgb)
{
m_flags |= BGFX_TEXTURE_SRGB;
}
BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s."
, this - s_renderD3D9->m_textures
, getName( (TextureFormat::Enum)m_textureFormat)