mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Bit more d3d stuff. Can't get depth right, pretty sure it's the projection matrix calc.
This commit is contained in:
parent
a758917919
commit
1556234825
13 changed files with 132 additions and 228 deletions
|
@ -241,19 +241,6 @@ void FramebufferManagerDX9::DrawPixels(const u8 *framebuf, GEBufferFormat pixelF
|
|||
DrawActiveTexture(x, y, w, h, false, 480.0f / 512.0f);
|
||||
}
|
||||
|
||||
// Depth in ogl is between -1;1 we need between 0;1
|
||||
static void ConvertMatrices(Matrix4x4 & in) {
|
||||
/*
|
||||
in.zz *= 0.5f;
|
||||
in.wz += 1.f;
|
||||
*/
|
||||
Matrix4x4 s;
|
||||
Matrix4x4 t;
|
||||
s.setScaling(Vec3(1, 1, 0.5f));
|
||||
t.setTranslation(Vec3(0, 0, 0.5f));
|
||||
in = in * s;
|
||||
in = in * t;
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::DrawActiveTexture(float x, float y, float w, float h, bool flip, float uscale, float vscale) {
|
||||
float u2 = uscale;
|
||||
|
@ -269,9 +256,9 @@ void FramebufferManagerDX9::DrawActiveTexture(float x, float y, float w, float h
|
|||
};
|
||||
|
||||
Matrix4x4 ortho;
|
||||
ConvertMatrices(ortho);
|
||||
|
||||
ortho.setOrtho(0, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, 0, -1, 1);
|
||||
ConvertProjMatrixToD3D(ortho);
|
||||
|
||||
//pD3Ddevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
|
||||
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
|
@ -635,6 +622,7 @@ void FramebufferManagerDX9::CopyDisplayToOutput() {
|
|||
dxstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
||||
DEBUG_LOG(SCEGE, "Displaying FBO %08x", vfb->fb_address);
|
||||
DisableState();
|
||||
|
||||
fbo_bind_color_as_texture(vfb->fbo, 0);
|
||||
|
||||
// These are in the output display coordinates
|
||||
|
|
|
@ -268,26 +268,17 @@ void LinkedShaderDX9::SetColorUniform3ExtraFloat(D3DXHANDLE uniform, u32 color,
|
|||
void LinkedShaderDX9::SetMatrix4x3(D3DXHANDLE uniform, const float *m4x3) {
|
||||
float m4x4[16];
|
||||
ConvertMatrix4x3To4x4(m4x4, m4x3);
|
||||
|
||||
if (m_vs->constant->SetMatrix(pD3Ddevice, uniform, (D3DXMATRIX*)m4x4) == D3D_OK);
|
||||
else
|
||||
m_fs->constant->SetMatrix(pD3Ddevice, uniform, (D3DXMATRIX*)m4x4);
|
||||
m_vs->constant->SetMatrix(pD3Ddevice, uniform, (D3DXMATRIX*)m4x4);
|
||||
}
|
||||
|
||||
void LinkedShaderDX9::SetMatrix(D3DXHANDLE uniform, const float* pMatrix) {
|
||||
D3DXMATRIX * pDxMat = (D3DXMATRIX*)pMatrix;
|
||||
|
||||
if (m_vs->constant->SetMatrix(pD3Ddevice, uniform, pDxMat) == D3D_OK);
|
||||
else
|
||||
m_fs->constant->SetMatrix(pD3Ddevice, uniform, pDxMat);
|
||||
m_vs->constant->SetMatrix(pD3Ddevice, uniform, pDxMat);
|
||||
}
|
||||
|
||||
// Depth in ogl is between -1;1 we need between 0;1
|
||||
static void ConvertMatrices(Matrix4x4 & in) {
|
||||
/*
|
||||
in.zz *= 0.5f;
|
||||
in.wz += 1.f;
|
||||
*/
|
||||
// Pretty sure this is wrong, our Z buffer is screwed up anyhow..
|
||||
void ConvertProjMatrixToD3D(Matrix4x4 & in) {
|
||||
Matrix4x4 s;
|
||||
Matrix4x4 t;
|
||||
s.setScaling(Vec3(1, 1, 0.5f));
|
||||
|
@ -297,7 +288,6 @@ static void ConvertMatrices(Matrix4x4 & in) {
|
|||
}
|
||||
|
||||
void LinkedShaderDX9::use() {
|
||||
|
||||
updateUniforms();
|
||||
|
||||
pD3Ddevice->SetPixelShader(m_fs->shader);
|
||||
|
@ -325,7 +315,7 @@ void LinkedShaderDX9::updateUniforms() {
|
|||
flippedMatrix[12] = -flippedMatrix[12];
|
||||
}
|
||||
// Convert matrices !
|
||||
ConvertMatrices(flippedMatrix);
|
||||
ConvertProjMatrixToD3D(flippedMatrix);
|
||||
|
||||
SetMatrix(u_proj, flippedMatrix.getReadPtr());
|
||||
}
|
||||
|
@ -335,7 +325,7 @@ void LinkedShaderDX9::updateUniforms() {
|
|||
proj_through.setOrtho(0.0f, gstate_c.curRTWidth, gstate_c.curRTHeight, 0, 0, 1);
|
||||
|
||||
// Convert matrices !
|
||||
ConvertMatrices(proj_through);
|
||||
ConvertProjMatrixToD3D(proj_through);
|
||||
|
||||
SetMatrix(u_proj_through, proj_through.getReadPtr());
|
||||
}
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
#include <map>
|
||||
#include "GPU/Directx9/VertexShaderGeneratorDX9.h"
|
||||
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
|
||||
#include "thin3d/d3dx9_loader.h"
|
||||
#include "math/lin/matrix4x4.h"
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
class PSShader;
|
||||
class VSShader;
|
||||
void ConvertProjMatrixToD3D(Matrix4x4 & in);
|
||||
|
||||
class LinkedShaderDX9
|
||||
{
|
||||
|
|
|
@ -77,6 +77,11 @@ static const D3DCMPFUNC ztests[] = {
|
|||
D3DCMP_LESS, D3DCMP_LESSEQUAL, D3DCMP_GREATER, D3DCMP_GREATEREQUAL,
|
||||
};
|
||||
|
||||
static const D3DCMPFUNC ztests_backwards[] = {
|
||||
D3DCMP_NEVER, D3DCMP_ALWAYS, D3DCMP_EQUAL, D3DCMP_NOTEQUAL,
|
||||
D3DCMP_GREATER, D3DCMP_GREATEREQUAL, D3DCMP_LESS, D3DCMP_LESSEQUAL,
|
||||
};
|
||||
|
||||
static const D3DSTENCILOP stencilOps[] = {
|
||||
D3DSTENCILOP_KEEP,
|
||||
D3DSTENCILOP_ZERO,
|
||||
|
@ -229,7 +234,6 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
|
|||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Set cull
|
||||
bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
|
||||
dxstate.cullMode.set(wantCull, gstate.getCullMode());
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "GPU/GPUState.h"
|
||||
#include "GPU/Directx9/TextureCacheDX9.h"
|
||||
#include "GPU/Directx9/FramebufferDX9.h"
|
||||
#include "GPU/Directx9/helper/dx_state.h"
|
||||
#include "GPU/Common/TextureDecoder.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/Host.h"
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include "ext/xxhash.h"
|
||||
#include "math/math_util.h"
|
||||
|
||||
|
||||
extern int g_iNumVideos;
|
||||
|
||||
namespace DX9 {
|
||||
|
@ -75,12 +77,14 @@ void TextureCacheDX9::Clear(bool delete_them) {
|
|||
lastBoundTexture = INVALID_TEX;
|
||||
if (delete_them) {
|
||||
for (TexCache::iterator iter = cache.begin(); iter != cache.end(); ++iter) {
|
||||
DEBUG_LOG(G3D, "Deleting texture %i", iter->second.texture);
|
||||
iter->second.texture->Release();
|
||||
DEBUG_LOG(G3D, "Deleting texture %p", iter->second.texture);
|
||||
if (iter->second.texture)
|
||||
iter->second.texture->Release();
|
||||
}
|
||||
for (TexCache::iterator iter = secondCache.begin(); iter != secondCache.end(); ++iter) {
|
||||
DEBUG_LOG(G3D, "Deleting texture %i", iter->second.texture);
|
||||
iter->second.texture->Release();
|
||||
DEBUG_LOG(G3D, "Deleting texture %p", iter->second.texture);
|
||||
if (iter->second.texture)
|
||||
iter->second.texture->Release();
|
||||
}
|
||||
}
|
||||
if (cache.size() + secondCache.size()) {
|
||||
|
@ -103,7 +107,8 @@ void TextureCacheDX9::Decimate() {
|
|||
int killAge = lowMemoryMode_ ? TEXTURE_KILL_AGE_LOWMEM : TEXTURE_KILL_AGE;
|
||||
for (TexCache::iterator iter = cache.begin(); iter != cache.end(); ) {
|
||||
if (iter->second.lastFrame + killAge < gpuStats.numFlips) {
|
||||
iter->second.texture->Release();
|
||||
if (iter->second.texture)
|
||||
iter->second.texture->Release();
|
||||
cache.erase(iter++);
|
||||
} else {
|
||||
++iter;
|
||||
|
@ -114,7 +119,8 @@ void TextureCacheDX9::Decimate() {
|
|||
for (TexCache::iterator iter = secondCache.begin(); iter != secondCache.end(); ) {
|
||||
// In low memory mode, we kill them all.
|
||||
if (lowMemoryMode_ || iter->second.lastFrame + TEXTURE_KILL_AGE < gpuStats.numFlips) {
|
||||
iter->second.texture->Release();
|
||||
if (iter->second.texture)
|
||||
iter->second.texture->Release();
|
||||
secondCache.erase(iter++);
|
||||
} else {
|
||||
++iter;
|
||||
|
@ -451,7 +457,7 @@ D3DFORMAT getClutDestFormat(GEPaletteFormat format) {
|
|||
|
||||
static const u8 texByteAlignMap[] = {2, 2, 2, 4};
|
||||
|
||||
static const u32 MinFilt[8] = {
|
||||
static const u8 MinFilt[8] = {
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_POINT,
|
||||
|
@ -462,7 +468,7 @@ static const u32 MinFilt[8] = {
|
|||
D3DTEXF_LINEAR, // GL_LINEAR_MIPMAP_LINEAR,
|
||||
};
|
||||
|
||||
static const u32 MipFilt[8] = {
|
||||
static const u8 MipFilt[8] = {
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_POINT,
|
||||
|
@ -473,13 +479,11 @@ static const u32 MipFilt[8] = {
|
|||
D3DTEXF_LINEAR, // GL_LINEAR_MIPMAP_LINEAR,
|
||||
};
|
||||
|
||||
static const u32 MagFilt[2] = {
|
||||
static const u8 MagFilt[2] = {
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR
|
||||
};
|
||||
|
||||
// This should not have to be done per texture! OpenGL is silly yo
|
||||
// TODO: Dirty-check this against the current texture.
|
||||
void TextureCacheDX9::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
|
||||
int minFilt = gstate.texfilter & 0x7;
|
||||
int magFilt = (gstate.texfilter>>8) & 1;
|
||||
|
@ -517,23 +521,11 @@ void TextureCacheDX9::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
|
|||
minFilt &= 1;
|
||||
}
|
||||
|
||||
if (force || entry.minFilt != minFilt) {
|
||||
pD3Ddevice->SetSamplerState(0, D3DSAMP_MINFILTER, MinFilt[minFilt]);
|
||||
pD3Ddevice->SetSamplerState(0, D3DSAMP_MIPFILTER, MipFilt[minFilt]);
|
||||
entry.minFilt = minFilt;
|
||||
}
|
||||
if (force || entry.magFilt != magFilt) {
|
||||
pD3Ddevice->SetSamplerState(0, D3DSAMP_MAGFILTER, MagFilt[magFilt]);
|
||||
entry.magFilt = magFilt;
|
||||
}
|
||||
if (force || entry.sClamp != sClamp) {
|
||||
pD3Ddevice->SetSamplerState(0, D3DSAMP_ADDRESSU, sClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
|
||||
entry.sClamp = sClamp;
|
||||
}
|
||||
if (force || entry.tClamp != tClamp) {
|
||||
pD3Ddevice->SetSamplerState(0, D3DSAMP_ADDRESSV, tClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
|
||||
entry.tClamp = tClamp;
|
||||
}
|
||||
dxstate.texMinFilter.set(MinFilt[minFilt]);
|
||||
dxstate.texMipFilter.set(MipFilt[minFilt]);
|
||||
dxstate.texMagFilter.set(MagFilt[magFilt]);
|
||||
dxstate.texAddressU.set(sClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
|
||||
dxstate.texAddressV.set(tClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
|
||||
|
||||
#ifdef _XBOX
|
||||
pD3Ddevice->SetRenderState(D3DRS_HALFPIXELOFFSET, TRUE );
|
||||
|
@ -570,7 +562,7 @@ static void ClutConvertColors(void *dstBuf, const void *srcBuf, u32 dstFmt, int
|
|||
u16_le *dst = (u16_le *)dstBuf;
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
u16 rgb = src[i];
|
||||
dst[i] = rgb; // (rgb & 0xF) | (rgb & 0xF0) << 8 | (rgb & 0xF00) | ((rgb & 0xF000) >> 8);
|
||||
dst[i] = ((rgb & 0xF) << 8) | (rgb & 0xF0F0) | ((rgb & 0xF00) >> 8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -580,7 +572,7 @@ static void ClutConvertColors(void *dstBuf, const void *srcBuf, u32 dstFmt, int
|
|||
u16 *dst = (u16 *)dstBuf;
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
u16 rgb = src[i];
|
||||
dst[i] = ((rgb & 0x1f) << 11) | ( rgb & 0x7e0) | ((rgb & 0xF800) >>11 );
|
||||
dst[i] = ((rgb & 0x1f) << 11) | (rgb & 0x7e0) | ((rgb & 0xF800) >> 11);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -725,7 +717,7 @@ void TextureCacheDX9::UpdateCurrentClut() {
|
|||
break;
|
||||
}
|
||||
// Alpha 0 doesn't matter.
|
||||
if (i != 0 && (clut[i] & 0xFFF0) != clutAlphaLinearColor_) {
|
||||
if (i != 0 && (clut[i] >> 12) != clutAlphaLinearColor_) {
|
||||
clutAlphaLinear_ = false;
|
||||
break;
|
||||
}
|
||||
|
@ -1304,21 +1296,12 @@ void TextureCacheDX9::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, u32 dstFm
|
|||
{
|
||||
const u32 *p = pixelData;
|
||||
for (int i = 0; i < (w * h + 1) / 2; ++i) {
|
||||
#ifndef BIG_ENDIAN
|
||||
u32 a = p[i] & 0x000F000F;
|
||||
hitZeroAlpha |= a ^ 0x000F000F;
|
||||
if (a != 0x000F000F && a != 0x0000000F && a != 0x000F0000 && a != 0) {
|
||||
hitSomeAlpha = 1;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
u32 a = p[i] & 0xF000F000;
|
||||
hitZeroAlpha |= a ^ 0xF000F000;
|
||||
if (a != 0xF000F000 && a != 0x0000F000 && a != 0xF0000000 && a != 0) {
|
||||
hitSomeAlpha = 1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1326,13 +1309,8 @@ void TextureCacheDX9::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, u32 dstFm
|
|||
{
|
||||
const u32 *p = pixelData;
|
||||
for (int i = 0; i < (w * h + 1) / 2; ++i) {
|
||||
#ifndef BIG_ENDIAN
|
||||
u32 a = p[i] & 0x00010001;
|
||||
hitZeroAlpha |= a ^ 0x00010001;
|
||||
#else
|
||||
u32 a = p[i] & 0x10001000;
|
||||
hitZeroAlpha |= a ^ 0x10001000;
|
||||
#endif
|
||||
u32 a = p[i] & 0x80008000;
|
||||
hitZeroAlpha |= a ^ 0x80008000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1442,16 +1420,20 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, bool rep
|
|||
} else {
|
||||
// Create texture
|
||||
#ifdef _XBOX
|
||||
pD3Ddevice->CreateTexture(w, h, 1, 0, (D3DFORMAT)D3DFMT(dstFmt), NULL, &entry.texture, NULL);
|
||||
HRESULT hr = pD3Ddevice->CreateTexture(w, h, 1, 0, (D3DFORMAT)D3DFMT(dstFmt), NULL, &entry.texture, NULL);
|
||||
#else
|
||||
pD3Ddevice->CreateTexture(w, h, 1, 0, (D3DFORMAT)D3DFMT(dstFmt), D3DPOOL_MANAGED, &entry.texture, NULL);
|
||||
HRESULT hr = pD3Ddevice->CreateTexture(w, h, 1, 0, (D3DFORMAT)D3DFMT(dstFmt), D3DPOOL_MANAGED, &entry.texture, NULL);
|
||||
#endif
|
||||
D3DLOCKED_RECT rect;
|
||||
entry.texture->LockRect(level, &rect, NULL, 0);
|
||||
if (FAILED(hr)) {
|
||||
INFO_LOG(G3D, "Failed to create D3D texture");
|
||||
} else {
|
||||
D3DLOCKED_RECT rect;
|
||||
entry.texture->LockRect(level, &rect, NULL, 0);
|
||||
|
||||
copyTexture(0, 0, w, h, rect.Pitch, entry.format, dstFmt, pixelData, rect.pBits);
|
||||
copyTexture(0, 0, w, h, rect.Pitch, entry.format, dstFmt, pixelData, rect.pBits);
|
||||
|
||||
entry.texture->UnlockRect(level);
|
||||
entry.texture->UnlockRect(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,13 +106,6 @@ private:
|
|||
int maxLevel;
|
||||
float lodBias;
|
||||
|
||||
// Cache the current filter settings so we can avoid setting it again.
|
||||
// (OpenGL madness where filter settings are attached to each texture).
|
||||
u8 magFilt;
|
||||
u8 minFilt;
|
||||
bool sClamp;
|
||||
bool tClamp;
|
||||
|
||||
bool Matches(u16 dim2, u8 format2, int maxLevel2);
|
||||
};
|
||||
|
||||
|
|
|
@ -283,9 +283,9 @@ void VertexDecoderDX9::Step_Color8888() const
|
|||
{
|
||||
u8 *c = (u8*)(decoded_ + decFmt.c0off);
|
||||
const u8 *cdata = (const u8*)(ptr_ + coloff);
|
||||
c[0] = cdata[0];
|
||||
c[0] = cdata[2];
|
||||
c[1] = cdata[1];
|
||||
c[2] = cdata[2];
|
||||
c[2] = cdata[0];
|
||||
c[3] = cdata[3];
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ void DirectxState::Initialize() {
|
|||
|
||||
void DirectxState::Restore() {
|
||||
int count = 0;
|
||||
|
||||
blend.restore(); count++;
|
||||
blendEquation.restore(); count++;
|
||||
blendFunc.restore(); count++;
|
||||
|
@ -37,7 +38,8 @@ void DirectxState::Restore() {
|
|||
depthWrite.restore(); count++;
|
||||
|
||||
colorMask.restore(); count++;
|
||||
viewport.restore(); count++;
|
||||
|
||||
// viewport.restore(); count++;
|
||||
|
||||
stencilTest.restore(); count++;
|
||||
stencilOp.restore(); count++;
|
||||
|
@ -45,7 +47,14 @@ void DirectxState::Restore() {
|
|||
|
||||
dither.restore(); count++;
|
||||
|
||||
assert(count == state_count && "DirectxState::Restore is missing some states");
|
||||
texMinFilter.restore(); count++;
|
||||
texMagFilter.restore(); count++;
|
||||
texMipFilter.restore(); count++;
|
||||
texAddressU.restore(); count++;
|
||||
texAddressV.restore(); count++;
|
||||
|
||||
|
||||
//assert(count == state_count && "DirectxState::Restore is missing some states");
|
||||
}
|
||||
|
||||
void CheckGLExtensions() {
|
||||
|
|
|
@ -55,6 +55,24 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
template<D3DSAMPLERSTATETYPE state1, DWORD p1def>
|
||||
class DxSampler0State1 {
|
||||
D3DSAMPLERSTATETYPE _state1;
|
||||
DWORD p1;
|
||||
public:
|
||||
DxSampler0State1() : _state1(state1), p1(p1def) {
|
||||
DirectxState::state_count++;
|
||||
}
|
||||
|
||||
inline void set(DWORD newp1) {
|
||||
p1 = newp1;
|
||||
pD3Ddevice->SetSamplerState(0, _state1, p1);
|
||||
}
|
||||
void restore() {
|
||||
pD3Ddevice->SetSamplerState(0, _state1, p1);
|
||||
}
|
||||
};
|
||||
|
||||
template<D3DRENDERSTATETYPE state1, DWORD p1def, D3DRENDERSTATETYPE state2, DWORD p2def>
|
||||
class DxState2 {
|
||||
D3DRENDERSTATETYPE _state1;
|
||||
|
@ -101,9 +119,9 @@ private:
|
|||
pD3Ddevice->SetRenderState(_state3, p3);
|
||||
}
|
||||
void restore() {
|
||||
// pD3Ddevice->SetRenderState(_state1, p1);
|
||||
// pD3Ddevice->SetRenderState(_state2, p2);
|
||||
// pD3Ddevice->SetRenderState(_state3, p3);
|
||||
pD3Ddevice->SetRenderState(_state1, p1);
|
||||
pD3Ddevice->SetRenderState(_state2, p2);
|
||||
pD3Ddevice->SetRenderState(_state3, p3);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -134,10 +152,10 @@ private:
|
|||
pD3Ddevice->SetRenderState(_state4, p4);
|
||||
}
|
||||
void restore() {
|
||||
// pD3Ddevice->SetRenderState(_state1, p1);
|
||||
// pD3Ddevice->SetRenderState(_state2, p2);
|
||||
// pD3Ddevice->SetRenderState(_state3, p3);
|
||||
// pD3Ddevice->SetRenderState(_state3, p4);
|
||||
pD3Ddevice->SetRenderState(_state1, p1);
|
||||
pD3Ddevice->SetRenderState(_state2, p2);
|
||||
pD3Ddevice->SetRenderState(_state3, p3);
|
||||
pD3Ddevice->SetRenderState(_state3, p4);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -222,15 +240,6 @@ private:
|
|||
viewport.Y=y;
|
||||
viewport.Width=w;
|
||||
viewport.Height=h;
|
||||
/*
|
||||
if (f > n) {
|
||||
viewport.MinZ=n;
|
||||
viewport.MaxZ=f;
|
||||
} else {
|
||||
viewport.MinZ=f;
|
||||
viewport.MaxZ=n;
|
||||
}
|
||||
*/
|
||||
viewport.MinZ=n;
|
||||
viewport.MaxZ=f;
|
||||
|
||||
|
@ -263,12 +272,10 @@ private:
|
|||
cull = D3DCULL_NONE;
|
||||
} else {
|
||||
// add front face ...
|
||||
cull = cullmode==0?D3DCULL_CW:D3DCULL_CCW;
|
||||
cull = cullmode==0 ? D3DCULL_CW:D3DCULL_CCW;
|
||||
}
|
||||
|
||||
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, cull);
|
||||
}
|
||||
|
||||
inline void restore() {
|
||||
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, cull);
|
||||
}
|
||||
|
@ -309,6 +316,12 @@ public:
|
|||
DxState3<D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP> stencilOp;
|
||||
DxState3<D3DRS_STENCILFUNC, D3DCMP_ALWAYS, D3DRS_STENCILREF, 0, D3DRS_STENCILMASK, 0xFFFFFFFF> stencilFunc;
|
||||
|
||||
DxSampler0State1<D3DSAMP_MINFILTER, D3DTEXF_POINT> texMinFilter;
|
||||
DxSampler0State1<D3DSAMP_MAGFILTER, D3DTEXF_POINT> texMagFilter;
|
||||
DxSampler0State1<D3DSAMP_MIPFILTER, D3DTEXF_NONE> texMipFilter;
|
||||
DxSampler0State1<D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP> texAddressU;
|
||||
DxSampler0State1<D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP> texAddressV;
|
||||
|
||||
// Only works on Win32, all other platforms are "force-vsync"
|
||||
void SetVSyncInterval(int interval); // one of the above VSYNC, or a higher number for multi-frame waits (could be useful for 30hz games)
|
||||
};
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
namespace DX9 {
|
||||
|
||||
static LPDIRECT3DSURFACE9 currentRtt;
|
||||
static LPDIRECT3DSURFACE9 workingRtt;
|
||||
static LPDIRECT3DSURFACE9 deviceRTsurf;
|
||||
static LPDIRECT3DSURFACE9 deviceDSsurf;
|
||||
|
||||
|
@ -19,10 +17,6 @@ struct FBO {
|
|||
LPDIRECT3DSURFACE9 surf;
|
||||
LPDIRECT3DSURFACE9 depthstencil;
|
||||
LPDIRECT3DTEXTURE9 tex;
|
||||
uint32_t color_texture;
|
||||
uint32_t z_stencil_buffer; // Either this is set, or the two below.
|
||||
uint32_t z_buffer;
|
||||
uint32_t stencil_buffer;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
@ -32,8 +26,11 @@ struct FBO {
|
|||
void fbo_init() {
|
||||
pD3Ddevice->GetRenderTarget(0, &deviceRTsurf);
|
||||
pD3Ddevice->GetDepthStencilSurface(&deviceDSsurf);
|
||||
}
|
||||
|
||||
//pD3Ddevice->CreateRenderTarget(1280/FB_DIV, 720/FB_DIV, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &workingRtt, NULL);
|
||||
void fbo_shutdown() {
|
||||
deviceRTsurf->Release();
|
||||
deviceDSsurf->Release();
|
||||
}
|
||||
|
||||
FBO * current_fbo = NULL;
|
||||
|
@ -47,91 +44,49 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil, F
|
|||
fbo->height = height;
|
||||
fbo->colorDepth = colorDepth;
|
||||
|
||||
// only support 32bit surfaces
|
||||
//pD3Ddevice->CreateRenderTarget(fbo->width/4, fbo->height/4, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->surf, NULL);
|
||||
|
||||
/*
|
||||
// Create depth + stencil target | forced to 24-bit Z, 8-bit stencil
|
||||
pD3Ddevice->CreateDepthStencilSurface(fbo->width, fbo->height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->depthstencil, NULL);
|
||||
*/
|
||||
// Only needed on xbox
|
||||
#ifdef _XBOX
|
||||
pD3Ddevice->CreateTexture(fbo->width/FB_DIV, fbo->height/FB_DIV, 1, 0, D3DFMT_A8R8G8B8, 0, &fbo->tex, NULL);
|
||||
if (workingRtt == NULL) {
|
||||
pD3Ddevice->CreateRenderTarget(fbo->width/FB_DIV, fbo->height/FB_DIV, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &workingRtt, NULL);
|
||||
}
|
||||
#else
|
||||
HRESULT rtResult = pD3Ddevice->CreateRenderTarget(fbo->width/4, fbo->height/4, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->surf, NULL);
|
||||
HRESULT rtResult = pD3Ddevice->CreateTexture(fbo->width, fbo->height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fbo->tex, NULL);
|
||||
if (FAILED(rtResult)) {
|
||||
ELOG("Failed to create render target");
|
||||
delete fbo;
|
||||
return NULL;
|
||||
}
|
||||
fbo->tex->GetSurfaceLevel(0, &fbo->surf);
|
||||
|
||||
HRESULT dsResult = pD3Ddevice->CreateDepthStencilSurface(fbo->width, fbo->height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->depthstencil, NULL);
|
||||
if (FAILED(dsResult)) {
|
||||
ELOG("Failed to create depth buffer");
|
||||
fbo->surf->Release();
|
||||
fbo->tex->Release();
|
||||
delete fbo;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
fbo->stencil_buffer = 8;
|
||||
fbo->z_buffer = 24;
|
||||
fbo->id = id++;
|
||||
return fbo;
|
||||
}
|
||||
|
||||
void fbo_destroy(FBO *fbo) {
|
||||
fbo->tex->Release();
|
||||
fbo->surf->Release();
|
||||
fbo->depthstencil->Release();
|
||||
delete fbo;
|
||||
}
|
||||
|
||||
void * fbo_get_rtt(FBO *fbo) {
|
||||
return fbo->tex;
|
||||
}
|
||||
|
||||
void fbo_unbind() {
|
||||
if (current_fbo != NULL) {
|
||||
|
||||
#ifdef _XBOX
|
||||
D3DVECTOR4 White = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS|D3DRESOLVE_CLEARRENDERTARGET|D3DRESOLVE_CLEARDEPTHSTENCIL, NULL,
|
||||
current_fbo->tex, NULL, 0, 0, &White, 0.0f, 0, NULL );
|
||||
#else
|
||||
// TODO?
|
||||
#endif
|
||||
/*
|
||||
pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS, NULL,
|
||||
current_fbo->tex, NULL, 0, 0, 0, 0.0f, 0, NULL );
|
||||
*/
|
||||
//pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 0, 0);
|
||||
}
|
||||
|
||||
//pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 0, 0);
|
||||
current_fbo = NULL;
|
||||
|
||||
pD3Ddevice->SetRenderTarget(0, deviceRTsurf);
|
||||
//pD3Ddevice->SetDepthStencilSurface(deviceDSsurf);
|
||||
|
||||
currentRtt = deviceRTsurf;
|
||||
pD3Ddevice->SetDepthStencilSurface(deviceDSsurf);
|
||||
}
|
||||
|
||||
void fbo_resolve(FBO *fbo) {
|
||||
if (fbo && fbo->tex) {
|
||||
#ifdef _XBOX
|
||||
pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS, NULL, fbo->tex, NULL, 0, 0, NULL, 0.0f, 0, NULL );
|
||||
#else
|
||||
// TODO?
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
// Hack save to disk ...
|
||||
char fname[256];
|
||||
static int f = 0;
|
||||
sprintf(fname, "game:\\rtt.%08x.%d.png", fbo->id, f++);
|
||||
D3DXSaveTextureToFile(fname, D3DXIFF_PNG, fbo->tex, NULL);
|
||||
//strcat(fname, "\n");
|
||||
OutputDebugString(fname);
|
||||
#endif
|
||||
}
|
||||
|
||||
void fbo_bind_as_render_target(FBO *fbo) {
|
||||
current_fbo = fbo;
|
||||
pD3Ddevice->SetRenderTarget(0, workingRtt);
|
||||
currentRtt = workingRtt;
|
||||
//pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 0, 0);
|
||||
//pD3Ddevice->SetDepthStencilSurface(fbo->depthstencil);
|
||||
pD3Ddevice->SetRenderTarget(0, fbo->surf);
|
||||
pD3Ddevice->SetDepthStencilSurface(fbo->depthstencil);
|
||||
}
|
||||
|
||||
void fbo_bind_for_read(FBO *fbo) {
|
||||
|
@ -139,37 +94,7 @@ void fbo_bind_for_read(FBO *fbo) {
|
|||
}
|
||||
|
||||
void fbo_bind_color_as_texture(FBO *fbo, int color) {
|
||||
|
||||
#if 0
|
||||
// Hack save to disk ...
|
||||
char fname[256];
|
||||
static int f = 0;
|
||||
sprintf(fname, "game:\\rtt.%08x.%d.png", fbo->id, f++);
|
||||
D3DXSaveTextureToFile(fname, D3DXIFF_PNG, fbo->tex, NULL);
|
||||
//strcat(fname, "\n");
|
||||
OutputDebugString(fname);
|
||||
#endif
|
||||
//pD3Ddevice->SetRenderTarget(0, workingRtt);
|
||||
//pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS, NULL, fbo->tex, NULL, 0, 0, NULL, 0.0f, 0, NULL );
|
||||
//pD3Ddevice->SetRenderTarget(0, currentRtt);
|
||||
|
||||
//OutputDebugStringA("fbo_bind_color_as_texture: Fix me\r\n");
|
||||
pD3Ddevice->SetTexture(0, fbo->tex);
|
||||
//pD3Ddevice->SetTexture(0, NULL);
|
||||
}
|
||||
|
||||
void fbo_destroy(FBO *fbo) {
|
||||
/*
|
||||
fbo->depthstencil->Release();
|
||||
*/
|
||||
//fbo->surf->Release();
|
||||
#ifdef _XBOX
|
||||
fbo->tex->Release();
|
||||
#else
|
||||
fbo->depthstencil->Release();
|
||||
fbo->surf->Release();
|
||||
#endif
|
||||
delete fbo;
|
||||
}
|
||||
|
||||
void fbo_get_dimensions(FBO *fbo, int *w, int *h) {
|
||||
|
@ -177,11 +102,4 @@ void fbo_get_dimensions(FBO *fbo, int *w, int *h) {
|
|||
*h = fbo->height;
|
||||
}
|
||||
|
||||
void SwapBuffer() {
|
||||
pD3Ddevice->Present(0, 0, 0, 0);
|
||||
|
||||
// :s
|
||||
//pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0 ,0), 0, 0);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
|
@ -10,7 +10,8 @@
|
|||
#endif
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
struct ID3DXConstantTable;
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
|
@ -23,8 +24,8 @@ extern IDirect3DVertexDeclaration9* pFramebufferVertexDecl;
|
|||
extern IDirect3DVertexDeclaration9* pSoftVertexDecl;
|
||||
|
||||
void CompileShaders();
|
||||
bool CompilePixelShader(const char * code, LPDIRECT3DPIXELSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable);
|
||||
bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable);
|
||||
bool CompilePixelShader(const char * code, LPDIRECT3DPIXELSHADER9 * pShader, ID3DXConstantTable **pShaderTable);
|
||||
bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, ID3DXConstantTable **pShaderTable);
|
||||
void DirectxInit(HWND window);
|
||||
|
||||
#define D3DBLEND_UNK D3DSTENCILOP_FORCE_DWORD
|
||||
|
|
|
@ -83,7 +83,9 @@
|
|||
#include "EmuScreen.h"
|
||||
#include "GameInfoCache.h"
|
||||
#include "HostTypes.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "GPU/Directx9/helper/dx_state.h"
|
||||
#endif
|
||||
#include "UI/OnScreenDisplay.h"
|
||||
#include "UI/MiscScreens.h"
|
||||
#include "UI/TiltEventProcessor.h"
|
||||
|
@ -686,7 +688,9 @@ void NativeRender() {
|
|||
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glstate.Restore();
|
||||
} else {
|
||||
// DirectxState::Restore();
|
||||
DX9::dxstate.depthWrite.set(true);
|
||||
DX9::dxstate.colorMask.set(true, true, true, true);
|
||||
DX9::dxstate.Restore();
|
||||
}
|
||||
|
||||
thin3d->Clear(T3DClear::COLOR | T3DClear::DEPTH | T3DClear::STENCIL, 0xFF000000, 0.0f, 0);
|
||||
|
@ -703,8 +707,6 @@ void NativeRender() {
|
|||
ui_draw2d.SetDrawMatrix(ortho);
|
||||
ui_draw2d_front.SetDrawMatrix(ortho);
|
||||
|
||||
// glsl_bind(UIShader_Get());
|
||||
|
||||
screenManager->render();
|
||||
if (screenManager->getUIContext()->Text()) {
|
||||
screenManager->getUIContext()->Text()->OncePerFrame();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "util/text/utf8.h"
|
||||
#include "i18n/i18n.h"
|
||||
|
||||
#include "Core/Config.h"
|
||||
#include "Windows/D3D9Base.h"
|
||||
#include "thin3d/thin3d.h"
|
||||
#include "thin3d/d3dx9_loader.h"
|
||||
|
@ -89,7 +90,7 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) {
|
|||
pp.hDeviceWindow = hWnd;
|
||||
pp.EnableAutoDepthStencil = true;
|
||||
pp.AutoDepthStencilFormat = D3DFMT_D24S8;
|
||||
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
||||
pp.PresentationInterval = (g_Config.bVSync) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
hr = d3d->CreateDevice(adapter, D3DDEVTYPE_HAL, hWnd, dwBehaviorFlags, &pp, &device);
|
||||
if (FAILED(hr)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue