mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-02 11:02:28 +02:00
DX11:
Disable D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY when compiling pixel shaders in Debug configurations as well. Properly support centered text drawing, even though it's not used, yet. Credits go to xsacha for this one. Found an awesome hacky way to free the buffer memory used by ReplaceTexture2D. At least it gets freed at all now... Various other tweaks to texture conversion. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5724 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
ce3eb2a13b
commit
762ce28977
@ -88,7 +88,7 @@ bool CompilePixelShader(const char* code, unsigned int len, ID3D10Blob** blob)
|
|||||||
ID3D10Blob* errorBuffer = NULL;
|
ID3D10Blob* errorBuffer = NULL;
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
UINT flags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY|D3D10_SHADER_DEBUG|D3D10_SHADER_WARNINGS_ARE_ERRORS;
|
UINT flags = D3D10_SHADER_DEBUG|D3D10_SHADER_WARNINGS_ARE_ERRORS;
|
||||||
#else
|
#else
|
||||||
UINT flags = D3D10_SHADER_OPTIMIZATION_LEVEL3;
|
UINT flags = D3D10_SHADER_OPTIMIZATION_LEVEL3;
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,12 +23,23 @@ namespace D3D
|
|||||||
{
|
{
|
||||||
|
|
||||||
// buffers for storing the data for DEFAULT textures
|
// buffers for storing the data for DEFAULT textures
|
||||||
const char* texbuf = NULL;
|
u8* texbuf = NULL;
|
||||||
unsigned int texbufsize = 0;
|
unsigned int texbufsize = 0;
|
||||||
|
|
||||||
|
// TODO: Remove this class and properly clean up texbuf!
|
||||||
|
struct TexbufDeleter
|
||||||
|
{
|
||||||
|
~TexbufDeleter()
|
||||||
|
{
|
||||||
|
if (texbuf) delete[] texbuf;
|
||||||
|
texbuf = NULL;
|
||||||
|
texbufsize = 0;
|
||||||
|
}
|
||||||
|
} texbufdeleter;
|
||||||
|
|
||||||
void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int width, unsigned int height, unsigned int pitch, DXGI_FORMAT fmt, PC_TexFormat pcfmt, unsigned int level, D3D11_USAGE usage)
|
void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int width, unsigned int height, unsigned int pitch, DXGI_FORMAT fmt, PC_TexFormat pcfmt, unsigned int level, D3D11_USAGE usage)
|
||||||
{
|
{
|
||||||
void* outptr;
|
u8* outptr;
|
||||||
unsigned int destPitch;
|
unsigned int destPitch;
|
||||||
bool bExpand = false;
|
bool bExpand = false;
|
||||||
|
|
||||||
@ -37,19 +48,18 @@ void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int
|
|||||||
if (level != 0) PanicAlert("Dynamic textures don't support mipmaps, but given level is not 0 at %s %d\n", __FILE__, __LINE__);
|
if (level != 0) PanicAlert("Dynamic textures don't support mipmaps, but given level is not 0 at %s %d\n", __FILE__, __LINE__);
|
||||||
D3D11_MAPPED_SUBRESOURCE map;
|
D3D11_MAPPED_SUBRESOURCE map;
|
||||||
D3D::context->Map(pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
D3D::context->Map(pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||||
outptr = map.pData;
|
outptr = (u8*)map.pData;
|
||||||
destPitch = map.RowPitch;
|
destPitch = map.RowPitch;
|
||||||
}
|
}
|
||||||
else if (usage == D3D11_USAGE_DEFAULT && pcfmt != PC_TEX_FMT_BGRA32)
|
else if (usage == D3D11_USAGE_DEFAULT && pcfmt != PC_TEX_FMT_BGRA32)
|
||||||
{
|
{
|
||||||
if (texbufsize < 4*width*height)
|
if (texbufsize < 4*width*height)
|
||||||
{
|
{
|
||||||
// TODO: This memory needs to be freed as well..
|
|
||||||
if (texbuf) delete[] texbuf;
|
if (texbuf) delete[] texbuf;
|
||||||
texbuf = new char[4*width*height];
|
texbuf = new u8[4*width*height];
|
||||||
texbufsize = 4*width*height;
|
texbufsize = 4*width*height;
|
||||||
}
|
}
|
||||||
outptr = (void*)texbuf;
|
outptr = texbuf;
|
||||||
destPitch = width * 4;
|
destPitch = width * 4;
|
||||||
}
|
}
|
||||||
else if (usage == D3D11_USAGE_DEFAULT && pcfmt == PC_TEX_FMT_BGRA32)
|
else if (usage == D3D11_USAGE_DEFAULT && pcfmt == PC_TEX_FMT_BGRA32)
|
||||||
@ -73,12 +83,12 @@ void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int
|
|||||||
for (unsigned int y = 0; y < height; y++)
|
for (unsigned int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
u16* in = (u16*)buffer + y * pitch;
|
u16* in = (u16*)buffer + y * pitch;
|
||||||
u32* pBits = (u32*)((u8*)outptr + y * destPitch);
|
u32* pBits = (u32*)(outptr + y * destPitch);
|
||||||
for (unsigned int x = 0; x < width; x++)
|
for (unsigned int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
const u8 I = (*in & 0xFF);
|
const u8 I = (*in & 0xFF);
|
||||||
const u8 A = (*in & 0xFF00) >> 8;
|
const u8 A = (*in & 0xFF00) >> 8;
|
||||||
*(pBits++) = (A << 24) | (I << 16) | (I << 8) | I;
|
*pBits++ = (A << 24) | (I << 16) | (I << 8) | I;
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,32 +97,26 @@ void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int
|
|||||||
case PC_TEX_FMT_I4_AS_I8:
|
case PC_TEX_FMT_I4_AS_I8:
|
||||||
for (unsigned int y = 0; y < height; y++)
|
for (unsigned int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
const u8* in = buffer + (y * pitch);
|
const u8* in = buffer + y * pitch;
|
||||||
u32* pBits = (u32*)((u8*)outptr + (y * destPitch));
|
u32* pBits = (u32*)(outptr + y * destPitch);
|
||||||
for(unsigned int i = 0; i < width; i++)
|
for(unsigned int i = 0; i < width; i++)
|
||||||
{
|
memset( pBits++, *in++, 4 );
|
||||||
const u8 I = *(in++);
|
|
||||||
memset( pBits++, I, 4 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PC_TEX_FMT_BGRA32:
|
case PC_TEX_FMT_BGRA32:
|
||||||
for (unsigned int y = 0; y < height; y++)
|
for (unsigned int y = 0; y < height; y++)
|
||||||
{
|
memcpy( outptr + y * destPitch, (u32*)buffer + y * pitch, destPitch );
|
||||||
u32* in = (u32*)buffer + y * pitch;
|
|
||||||
u32* pBits = (u32*)((u8*)outptr + y * destPitch);
|
|
||||||
memcpy( pBits, in, destPitch );
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PC_TEX_FMT_RGB565:
|
case PC_TEX_FMT_RGB565:
|
||||||
for (unsigned int y = 0; y < height; y++)
|
for (unsigned int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
u16* in = (u16*)buffer + y * pitch;
|
u16* in = (u16*)buffer + y * pitch;
|
||||||
u32* pBits = (u32*)((u8*)outptr + y * destPitch);
|
u32* pBits = (u32*)(outptr + y * destPitch);
|
||||||
for (unsigned int x = 0; x < width; x++)
|
for (unsigned int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
// we can't simply shift here, since e.g. 11111 must map to 11111111 and not 11111000
|
// we can't simply shift here, since e.g. 11111 must map to 11111111 and not 11111000
|
||||||
const u16 col = *(in++);
|
const u16 col = *in++;
|
||||||
*(pBits++) = 0xFF000000 | // alpha
|
*(pBits++) = 0xFF000000 | // alpha
|
||||||
((((col&0xF800) << 5) * 255 / 31) & 0xFF0000) | // red
|
((((col&0xF800) << 5) * 255 / 31) & 0xFF0000) | // red
|
||||||
((((col& 0x7e0) << 3) * 255 / 63) & 0xFF00) | // green
|
((((col& 0x7e0) << 3) * 255 / 63) & 0xFF00) | // green
|
||||||
|
@ -269,12 +269,11 @@ int CD3DFont::DrawTextScaled(float x, float y, float scale, float spacing, u32 d
|
|||||||
UINT stride = sizeof(FONT2DVERTEX);
|
UINT stride = sizeof(FONT2DVERTEX);
|
||||||
UINT bufoffset = 0;
|
UINT bufoffset = 0;
|
||||||
|
|
||||||
float sx = x;
|
// translate starting positions
|
||||||
float sy = y;
|
float sx = x / m_dwTexWidth - 1;
|
||||||
|
float sy = 1 - y / m_dwTexHeight;
|
||||||
|
char c;
|
||||||
|
|
||||||
float fStartX = sx;
|
|
||||||
|
|
||||||
float invLineHeight = 1.0f / ((m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight);
|
|
||||||
// fill vertex buffer
|
// fill vertex buffer
|
||||||
FONT2DVERTEX* pVertices;
|
FONT2DVERTEX* pVertices;
|
||||||
int dwNumTriangles = 0L;
|
int dwNumTriangles = 0L;
|
||||||
@ -284,42 +283,30 @@ int CD3DFont::DrawTextScaled(float x, float y, float scale, float spacing, u32 d
|
|||||||
if (FAILED(hr)) PanicAlert("Mapping vertex buffer failed, %s %d\n", __FILE__, __LINE__);
|
if (FAILED(hr)) PanicAlert("Mapping vertex buffer failed, %s %d\n", __FILE__, __LINE__);
|
||||||
pVertices = (D3D::FONT2DVERTEX*)vbmap.pData;
|
pVertices = (D3D::FONT2DVERTEX*)vbmap.pData;
|
||||||
|
|
||||||
const char* oldstrText = strText;
|
// if center was requested, set current position as centre
|
||||||
// first, let's measure the text
|
// this is currently never used
|
||||||
float tw=0;
|
|
||||||
float mx=0;
|
|
||||||
float maxx=0;
|
|
||||||
|
|
||||||
while (*strText)
|
|
||||||
{
|
|
||||||
char c = *strText++;
|
|
||||||
|
|
||||||
if (c == ('\n'))
|
|
||||||
mx = 0;
|
|
||||||
if (c < (' '))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
float tx1 = m_fTexCoords[c-32][0];
|
|
||||||
float tx2 = m_fTexCoords[c-32][2];
|
|
||||||
|
|
||||||
float w = (tx2-tx1)*m_dwTexWidth;
|
|
||||||
w *= scale*invLineHeight;
|
|
||||||
mx += w + spacing*scale;
|
|
||||||
if (mx > maxx) maxx = mx;
|
|
||||||
}
|
|
||||||
|
|
||||||
float offset = -maxx/2;
|
|
||||||
strText = oldstrText;
|
|
||||||
//Then let's draw it
|
|
||||||
if (center)
|
if (center)
|
||||||
{
|
{
|
||||||
sx += offset;
|
const char *oldText = strText;
|
||||||
fStartX += offset;
|
float mx=0;
|
||||||
|
float maxx=0;
|
||||||
|
|
||||||
|
while (c = *strText++)
|
||||||
|
{
|
||||||
|
if (c == ('\n'))
|
||||||
|
mx = 0;
|
||||||
|
if (c < (' '))
|
||||||
|
continue;
|
||||||
|
c -= 32;
|
||||||
|
mx += (m_fTexCoords[c][2]-m_fTexCoords[c][0])/(m_fTexCoords[0][3] - m_fTexCoords[0][1])
|
||||||
|
+ spacing;
|
||||||
|
if (mx > maxx) maxx = mx;
|
||||||
|
}
|
||||||
|
sx -= scale*maxx/(2*m_dwTexWidth);
|
||||||
|
strText = oldText;
|
||||||
}
|
}
|
||||||
|
// we now have a starting point
|
||||||
float wScale = scale*invLineHeight;
|
float fStartX = sx;
|
||||||
float hScale = scale*invLineHeight;
|
|
||||||
|
|
||||||
// set general pipeline state
|
// set general pipeline state
|
||||||
D3D::context->OMSetBlendState(m_blendstate, NULL, 0xFFFFFFFF);
|
D3D::context->OMSetBlendState(m_blendstate, NULL, 0xFFFFFFFF);
|
||||||
D3D::context->RSSetState(m_raststate);
|
D3D::context->RSSetState(m_raststate);
|
||||||
@ -330,33 +317,29 @@ int CD3DFont::DrawTextScaled(float x, float y, float scale, float spacing, u32 d
|
|||||||
D3D::context->IASetInputLayout(m_InputLayout);
|
D3D::context->IASetInputLayout(m_InputLayout);
|
||||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
D3D::context->PSSetShaderResources(0, 1, &m_pTexture);
|
D3D::context->PSSetShaderResources(0, 1, &m_pTexture);
|
||||||
|
while (c = *strText++)
|
||||||
while (*strText)
|
|
||||||
{
|
{
|
||||||
char c = *strText++;
|
|
||||||
|
|
||||||
if (c == ('\n'))
|
if (c == ('\n'))
|
||||||
{
|
{
|
||||||
sx = fStartX;
|
sx = fStartX;
|
||||||
sy += scale;
|
sy -= scale / m_dwTexHeight;
|
||||||
}
|
}
|
||||||
if (c < (' '))
|
if (c < (' '))
|
||||||
continue;
|
continue;
|
||||||
|
c -= 32;
|
||||||
c-=32;
|
|
||||||
float tx1 = m_fTexCoords[c][0];
|
float tx1 = m_fTexCoords[c][0];
|
||||||
float ty1 = m_fTexCoords[c][1];
|
float ty1 = m_fTexCoords[c][1];
|
||||||
float tx2 = m_fTexCoords[c][2];
|
float tx2 = m_fTexCoords[c][2];
|
||||||
float ty2 = m_fTexCoords[c][3];
|
float ty2 = m_fTexCoords[c][3];
|
||||||
|
|
||||||
float w = (tx2-tx1)*m_dwTexWidth/2;
|
float w = (tx2-tx1)/2;
|
||||||
float h = (ty2-ty1)*m_dwTexHeight/2;
|
float h = (ty1-ty2)/2;
|
||||||
|
|
||||||
FONT2DVERTEX v[6];
|
FONT2DVERTEX v[6];
|
||||||
v[0] = InitFont2DVertex( sx /m_dwTexWidth-1.f, 1-((sy+h)/m_dwTexHeight), dwColor, tx1, ty2);
|
v[0] = InitFont2DVertex( sx, h+sy, dwColor, tx1, ty2);
|
||||||
v[1] = InitFont2DVertex( sx /m_dwTexWidth-1.f, 1-( sy /m_dwTexHeight), dwColor, tx1, ty1);
|
v[1] = InitFont2DVertex( sx, sy, dwColor, tx1, ty1);
|
||||||
v[2] = InitFont2DVertex((sx+w)/m_dwTexWidth-1.f, 1-((sy+h)/m_dwTexHeight), dwColor, tx2, ty2);
|
v[2] = InitFont2DVertex(w+sx, h+sy, dwColor, tx2, ty2);
|
||||||
v[3] = InitFont2DVertex((sx+w)/m_dwTexWidth-1.f, 1-( sy /m_dwTexHeight), dwColor, tx2, ty1);
|
v[3] = InitFont2DVertex(w+sx, sy, dwColor, tx2, ty1);
|
||||||
v[4] = v[2];
|
v[4] = v[2];
|
||||||
v[5] = v[1];
|
v[5] = v[1];
|
||||||
|
|
||||||
@ -378,7 +361,7 @@ int CD3DFont::DrawTextScaled(float x, float y, float scale, float spacing, u32 d
|
|||||||
if (FAILED(hr)) PanicAlert("Mapping vertex buffer failed, %s %d\n", __FILE__, __LINE__);
|
if (FAILED(hr)) PanicAlert("Mapping vertex buffer failed, %s %d\n", __FILE__, __LINE__);
|
||||||
pVertices = (D3D::FONT2DVERTEX*)vbmap.pData;
|
pVertices = (D3D::FONT2DVERTEX*)vbmap.pData;
|
||||||
}
|
}
|
||||||
sx += w + spacing*scale;
|
sx += w + spacing*scale/m_dwTexWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock and render the vertex buffer
|
// Unlock and render the vertex buffer
|
||||||
|
@ -111,7 +111,7 @@ void TextureCache::Init()
|
|||||||
|
|
||||||
void TextureCache::Invalidate(bool shutdown)
|
void TextureCache::Invalidate(bool shutdown)
|
||||||
{
|
{
|
||||||
for (TexCache::iterator iter = textures.begin(); iter != textures.end(); iter++)
|
for (TexCache::iterator iter = textures.begin(); iter != textures.end(); ++iter)
|
||||||
iter->second.Destroy(shutdown);
|
iter->second.Destroy(shutdown);
|
||||||
textures.clear();
|
textures.clear();
|
||||||
HiresTextures::Shutdown();
|
HiresTextures::Shutdown();
|
||||||
@ -167,7 +167,7 @@ void TextureCache::Cleanup()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iter++;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user