Minor DX9 code cleanup

This commit is contained in:
Henrik Rydgard committed 2017-02-05 19:38:52 +01:00
1 parent 837ce9085c
commit 0b3ebbddf4
5 files changed
+22 -22

No files matched your search

+15 -1
View File
@@ -78,6 +78,14 @@ enum {
enum { VAI_KILL_AGE = 120, VAI_UNRELIABLE_KILL_AGE = 240, VAI_UNRELIABLE_KILL_MAX = 4 };
static const D3DVERTEXELEMENT9 TransformedVertexElements[] = {
{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 28, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 32, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1 },
D3DDECL_END()
};
DrawEngineDX9::DrawEngineDX9()
: decodedVerts_(0),
prevPrim_(GE_PRIM_INVALID),
@@ -109,9 +117,15 @@ DrawEngineDX9::DrawEngineDX9()
InitDeviceObjects();
tessDataTransfer = new TessellationDataTransferDX9();
pD3Ddevice->CreateVertexDeclaration(TransformedVertexElements, &transformedVertexDecl_);
}
DrawEngineDX9::~DrawEngineDX9() {
if (transformedVertexDecl_) {
transformedVertexDecl_->Release();
}
DestroyDeviceObjects();
FreeMemoryPages(decoded, DECODED_VERTEX_BUFFER_SIZE);
FreeMemoryPages(decIndex, DECODED_INDEX_BUFFER_SIZE);
@@ -833,7 +847,7 @@ rotateVBO:
// these spam the gDebugger log.
const int vertexSize = sizeof(transformed[0]);
pD3Ddevice->SetVertexDeclaration(pSoftVertexDecl);
pD3Ddevice->SetVertexDeclaration(transformedVertexDecl_);
if (drawIndexed) {
pD3Ddevice->DrawIndexedPrimitiveUP(glprim[prim], 0, maxIndex, D3DPrimCount(glprim[prim], numTrans), inds, D3DFMT_INDEX16, drawBuffer, sizeof(TransformedVertex));
} else {
+4 -1
View File
@@ -196,7 +196,10 @@ private:
std::unordered_map<u32, VertexArrayInfoDX9 *> vai_;
std::unordered_map<u32, IDirect3DVertexDeclaration9 *> vertexDeclMap_;
// SimpleVertex
IDirect3DVertexDeclaration9* transformedVertexDecl_;
// Other
ShaderManagerDX9 *shaderManager_;
TextureCacheDX9 *textureCache_;
+3 -15
View File
@@ -59,16 +59,6 @@ static const D3DVERTEXELEMENT9 VertexElements[] = {
D3DDECL_END()
};
IDirect3DVertexDeclaration9* pSoftVertexDecl = NULL;
static const D3DVERTEXELEMENT9 SoftTransVertexElements[] = {
{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 28, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 32, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1 },
D3DDECL_END()
};
LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader = NULL; // Vertex Shader
LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader = NULL; // Pixel Shader
@@ -168,23 +158,21 @@ bool CompileShaders(std::string &errorMsg) {
pD3Ddevice->CreateVertexDeclaration(VertexElements, &pFramebufferVertexDecl);
pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
pD3Ddevice->CreateVertexDeclaration(SoftTransVertexElements, &pSoftVertexDecl);
return true;
}
void DestroyShaders() {
if (pFramebufferVertexShader) {
pFramebufferVertexShader->Release();
pFramebufferVertexShader = nullptr;
}
if (pFramebufferPixelShader) {
pFramebufferPixelShader->Release();
pFramebufferPixelShader = nullptr;
}
if (pFramebufferVertexDecl) {
pFramebufferVertexDecl->Release();
}
if (pSoftVertexDecl) {
pSoftVertexDecl->Release();
pFramebufferVertexDecl = nullptr;
}
}
-2
View File
@@ -11,13 +11,11 @@ namespace DX9 {
extern LPDIRECT3DDEVICE9 pD3Ddevice;
extern LPDIRECT3DDEVICE9EX pD3DdeviceEx;
extern LPDIRECT3D9 pD3D;
extern LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader; // Vertex Shader
extern LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader; // Pixel Shader
extern IDirect3DVertexDeclaration9* pFramebufferVertexDecl;
extern IDirect3DVertexDeclaration9* pSoftVertexDecl;
bool CompileShaders(std::string &errorMessage);
bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage);
-3
View File
@@ -164,7 +164,6 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
device->BeginScene();
DX9::pD3Ddevice = device;
DX9::pD3DdeviceEx = deviceEx;
DX9::pD3D = d3d;
if (!DX9::CompileShaders(*error_message)) {
*error_message = "Unable to compile shaders: " + *error_message;
@@ -173,7 +172,6 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
d3d->Release();
DX9::pD3Ddevice = nullptr;
DX9::pD3DdeviceEx = nullptr;
DX9::pD3D = nullptr;
device = nullptr;
UnloadD3DXDynamic();
return false;
@@ -221,7 +219,6 @@ void D3D9Context::Shutdown() {
UnloadD3DXDynamic();
DX9::pD3Ddevice = nullptr;
DX9::pD3DdeviceEx = nullptr;
DX9::pD3D = nullptr;
device = nullptr;
hWnd = nullptr;
FreeLibrary(hD3D9);