mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-28 10:51:06 +00:00
D3d cleanups and improvements
This commit is contained in:
parent
00d5793f7d
commit
a758917919
@ -192,8 +192,8 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
|
||||
}
|
||||
|
||||
// At this point, through all paths above, glBlendFuncA and glBlendFuncB will be set right somehow.
|
||||
dxstate.blendFunc.set(glBlendFuncA, glBlendFuncB);
|
||||
dxstate.blendEquation.set(eqLookup[blendFuncEq]);
|
||||
dxstate.blendFunc.set(glBlendFuncA, glBlendFuncB, D3DBLEND_ONE, D3DBLEND_ZERO);
|
||||
dxstate.blendEquation.set(eqLookup[blendFuncEq], D3DBLENDOP_ADD);
|
||||
}
|
||||
|
||||
// Set Dither
|
||||
|
@ -569,9 +569,8 @@ static void ClutConvertColors(void *dstBuf, const void *srcBuf, u32 dstFmt, int
|
||||
const u16_le *src = (const u16_le *)srcBuf;
|
||||
u16_le *dst = (u16_le *)dstBuf;
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
// Already good format
|
||||
u16 rgb = src[i];
|
||||
dst[i] = (rgb & 0xF) | (rgb & 0xF0)<<8 | ( rgb & 0xF00) | ((rgb & 0xF000)>>8);
|
||||
dst[i] = rgb; // (rgb & 0xF) | (rgb & 0xF0) << 8 | (rgb & 0xF00) | ((rgb & 0xF000) >> 8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -721,7 +720,7 @@ void TextureCacheDX9::UpdateCurrentClut() {
|
||||
clutAlphaLinear_ = true;
|
||||
clutAlphaLinearColor_ = clut[15] & 0xFFF0;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if ((clut[i] & 0xf) != i) {
|
||||
if ((clut[i] >> 12) != i) {
|
||||
clutAlphaLinear_ = false;
|
||||
break;
|
||||
}
|
||||
@ -745,48 +744,6 @@ inline u32 TextureCacheDX9::GetCurrentClutHash() {
|
||||
return clutHash_;
|
||||
}
|
||||
|
||||
// #define DEBUG_TEXTURES
|
||||
|
||||
#ifdef DEBUG_TEXTURES
|
||||
bool SetDebugTexture() {
|
||||
static const int highlightFrames = 30;
|
||||
|
||||
static int numTextures = 0;
|
||||
static int lastFrames = 0;
|
||||
static int mostTextures = 1;
|
||||
|
||||
if (lastFrames != gpuStats.numFlips) {
|
||||
mostTextures = std::max(mostTextures, numTextures);
|
||||
numTextures = 0;
|
||||
lastFrames = gpuStats.numFlips;
|
||||
}
|
||||
|
||||
static GLuint solidTexture = 0;
|
||||
|
||||
bool changed = false;
|
||||
if (((gpuStats.numFlips / highlightFrames) % mostTextures) == numTextures) {
|
||||
if (gpuStats.numFlips % highlightFrames == 0) {
|
||||
NOTICE_LOG(G3D, "Highlighting texture # %d / %d", numTextures, mostTextures);
|
||||
}
|
||||
static const u32 solidTextureData[] = {0x99AA99FF};
|
||||
|
||||
if (solidTexture == 0) {
|
||||
glGenTextures(1, &solidTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, solidTexture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, solidTextureData);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, solidTexture);
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
++numTextures;
|
||||
return changed;
|
||||
}
|
||||
#endif
|
||||
|
||||
void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry)
|
||||
{
|
||||
entry->framebuffer->usageFlags |= FB_USAGE_TEXTURE;
|
||||
@ -1409,12 +1366,13 @@ void TextureCacheDX9::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, u32 dstFm
|
||||
|
||||
static inline void copyTexture(int xoffset, int yoffset, int w, int h, int pitch, int srcfmt, int fmt, void * pSrc, void * pDst) {
|
||||
// Swap color
|
||||
int y;
|
||||
switch(fmt) {
|
||||
case D3DFMT_R5G6B5:
|
||||
case D3DFMT_A4R4G4B4:
|
||||
case D3DFMT_A1R5G5B5:
|
||||
// Really needed ?
|
||||
for(int y = 0; y < h; y++) {
|
||||
for(y = 0; y < h; y++) {
|
||||
const u16 *src = (const u16 *)((u8*)pSrc + (w*2) * y);
|
||||
u16 *dst = (u16*)((u8*)pDst + pitch * y);
|
||||
memcpy(dst, src, w * sizeof(u16));
|
||||
@ -1423,23 +1381,13 @@ static inline void copyTexture(int xoffset, int yoffset, int w, int h, int pitch
|
||||
|
||||
// 32 bit texture
|
||||
case D3DFMT_A8R8G8B8:
|
||||
for(int y = 0; y < h; y++) {
|
||||
for(y = 0; y < h; y++) {
|
||||
const u32 *src = (const u32 *)((u8*)pSrc + (w*4) * y);
|
||||
u32 *dst = (u32*)((u8*)pDst + pitch * y);
|
||||
|
||||
/*
|
||||
// todo use memcpy
|
||||
for(int x = 0; x < w; x++) {
|
||||
unsigned int rgb = src[x];
|
||||
dst[x] = rgb;
|
||||
}
|
||||
*/
|
||||
memcpy(dst, src, w * sizeof(u32));
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, bool replaceImages) {
|
||||
@ -1505,37 +1453,9 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, bool rep
|
||||
|
||||
entry.texture->UnlockRect(level);
|
||||
}
|
||||
|
||||
//#ifdef _DEBUG
|
||||
#if 0
|
||||
// Hack save to disk ...
|
||||
char fname[256];
|
||||
int fmt = 0;
|
||||
static int ipic = 0;
|
||||
switch(dstFmt) {
|
||||
case D3DFMT_A4R4G4B4:
|
||||
fmt = 0x4444;
|
||||
break;
|
||||
case D3DFMT_A1R5G5B5:
|
||||
fmt = 0x5551;
|
||||
break;
|
||||
case D3DFMT_R5G6B5:
|
||||
fmt = 0x5650;
|
||||
break;
|
||||
case D3DFMT_A8R8G8B8:
|
||||
fmt = 0x8888;
|
||||
break;
|
||||
default:
|
||||
fmt = 0xDEAD;
|
||||
break;
|
||||
}
|
||||
sprintf(fname, "game:\\pic\\pic.%02x.%04x.%08x.%08x.png", ipic++, fmt, entry.format, clutformat);
|
||||
D3DXSaveTextureToFile(fname, D3DXIFF_PNG, entry.texture, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Only used by Qt UI?
|
||||
bool TextureCacheDX9::DecodeTexture(u8* output, GPUgstate state)
|
||||
{
|
||||
OutputDebugStringA("TextureCache::DecodeTexture : FixMe\r\n");
|
||||
|
@ -273,21 +273,20 @@ void VertexDecoderDX9::Step_Color4444() const
|
||||
{
|
||||
u8 *c = decoded_ + decFmt.c0off;
|
||||
u16 cdata = (u16)(*(u16_le*)(ptr_ + coloff));
|
||||
c[0] = Convert4To8((cdata >> (12)) & 0xF);
|
||||
c[1] = Convert4To8((cdata >> (0)) & 0xF);
|
||||
c[2] = Convert4To8((cdata >> (4)) & 0xF);
|
||||
c[3] = Convert4To8((cdata >> (8)) & 0xF);
|
||||
c[0] = Convert4To8((cdata >> (0)) & 0xF);
|
||||
c[1] = Convert4To8((cdata >> (4)) & 0xF);
|
||||
c[2] = Convert4To8((cdata >> (8)) & 0xF);
|
||||
c[3] = Convert4To8((cdata >> (12)) & 0xF);
|
||||
}
|
||||
|
||||
void VertexDecoderDX9::Step_Color8888() const
|
||||
{
|
||||
// Directx want ARGB
|
||||
u8 *c = (u8*)(decoded_ + decFmt.c0off);
|
||||
const u8 *cdata = (const u8*)(ptr_ + coloff);
|
||||
c[0] = cdata[3];
|
||||
c[1] = cdata[0];
|
||||
c[2] = cdata[1];
|
||||
c[3] = cdata[2];
|
||||
c[0] = cdata[0];
|
||||
c[1] = cdata[1];
|
||||
c[2] = cdata[2];
|
||||
c[3] = cdata[3];
|
||||
}
|
||||
|
||||
void VertexDecoderDX9::Step_Color565Morph() const
|
||||
@ -864,7 +863,7 @@ void VertexDecoderDX9::SetVertexType(u32 fmt) {
|
||||
// The normal formats match the gl formats perfectly, let's use 'em.
|
||||
switch (nrm) {
|
||||
//case GE_VTYPE_NRM_8BIT >> GE_VTYPE_NRM_SHIFT: decFmt.nrmfmt = DEC_S8_3; break;
|
||||
case GE_VTYPE_NRM_8BIT >> GE_VTYPE_NRM_SHIFT: decFmt.nrmfmt = DEC_FLOAT_3; break;
|
||||
case GE_VTYPE_NRM_8BIT >> GE_VTYPE_NRM_SHIFT: decFmt.nrmfmt = DEC_FLOAT_3; break;
|
||||
case GE_VTYPE_NRM_16BIT >> GE_VTYPE_NRM_SHIFT: decFmt.nrmfmt = DEC_S16_3; break;
|
||||
case GE_VTYPE_NRM_FLOAT >> GE_VTYPE_NRM_SHIFT: decFmt.nrmfmt = DEC_FLOAT_3; break;
|
||||
}
|
||||
|
@ -103,10 +103,44 @@ private:
|
||||
void restore() {
|
||||
// pD3Ddevice->SetRenderState(_state1, p1);
|
||||
// pD3Ddevice->SetRenderState(_state2, p2);
|
||||
// pD3Ddevice->SetRenderState(_state3, p2);
|
||||
// pD3Ddevice->SetRenderState(_state3, p3);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<D3DRENDERSTATETYPE state1, DWORD p1def, D3DRENDERSTATETYPE state2, DWORD p2def, D3DRENDERSTATETYPE state3, DWORD p3def, D3DRENDERSTATETYPE state4, DWORD p4def>
|
||||
class DxState4 {
|
||||
D3DRENDERSTATETYPE _state1;
|
||||
D3DRENDERSTATETYPE _state2;
|
||||
D3DRENDERSTATETYPE _state3;
|
||||
D3DRENDERSTATETYPE _state4;
|
||||
DWORD p1;
|
||||
DWORD p2;
|
||||
DWORD p3;
|
||||
DWORD p4;
|
||||
public:
|
||||
DxState4() : _state1(state1), _state2(state2), _state3(state3), _state4(state4),
|
||||
p1(p1def), p2(p2def), p3(p3def), p4(p4def) {
|
||||
// DirectxState::state_count++;
|
||||
}
|
||||
|
||||
inline void set(DWORD newp1, DWORD newp2, DWORD newp3, DWORD newp4) {
|
||||
p1 = newp1;
|
||||
p2 = newp2;
|
||||
p3 = newp3;
|
||||
p4 = newp4;
|
||||
pD3Ddevice->SetRenderState(_state1, p1);
|
||||
pD3Ddevice->SetRenderState(_state2, p2);
|
||||
pD3Ddevice->SetRenderState(_state3, p3);
|
||||
pD3Ddevice->SetRenderState(_state4, p4);
|
||||
}
|
||||
void restore() {
|
||||
// pD3Ddevice->SetRenderState(_state1, p1);
|
||||
// pD3Ddevice->SetRenderState(_state2, p2);
|
||||
// pD3Ddevice->SetRenderState(_state3, p3);
|
||||
// pD3Ddevice->SetRenderState(_state3, p4);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SavedBlendFactor {
|
||||
DWORD c;
|
||||
@ -250,8 +284,8 @@ public:
|
||||
|
||||
// When adding a state here, don't forget to add it to DirectxState::Restore() too
|
||||
BoolState<D3DRS_ALPHABLENDENABLE, false> blend;
|
||||
DxState2<D3DRS_SRCBLEND, D3DBLEND_SRCALPHA, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA> blendFunc;
|
||||
DxState1<D3DRS_BLENDOP, D3DBLENDOP_ADD> blendEquation;
|
||||
DxState4<D3DRS_SRCBLEND, D3DBLEND_SRCALPHA, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA, D3DRS_SRCBLENDALPHA, D3DBLEND_ONE, D3DRS_DESTBLENDALPHA, D3DBLEND_ZERO> blendFunc;
|
||||
DxState2<D3DRS_BLENDOP, D3DBLENDOP_ADD, D3DRS_BLENDOPALPHA, D3DBLENDOP_ADD> blendEquation;
|
||||
SavedBlendFactor blendColor;
|
||||
|
||||
BoolState<D3DRS_SCISSORTESTENABLE, false> scissorTest;
|
||||
|
Loading…
Reference in New Issue
Block a user