D3D: some cleanup and a crashfix on shutdown

This commit is contained in:
Henrik Rydgard 2014-09-09 00:29:01 +02:00
parent 338c7668be
commit ef0ae77e98
3 changed files with 15 additions and 13 deletions

View file

@ -328,13 +328,8 @@ void LinkedShaderDX9::updateUniforms() {
flippedMatrix[0] = -flippedMatrix[0];
flippedMatrix[12] = -flippedMatrix[12];
}
bool invert = false;
if (gstate_c.vpDepth < 0) {
invert = true;
//flippedMatrix[9] = -flippedMatrix[9];
//flippedMatrix[14] = -flippedMatrix[14];
}
// Convert matrices !
bool invert = gstate_c.vpDepth < 0;
ConvertProjMatrixToD3D(flippedMatrix, invert);
SetMatrix(u_proj, flippedMatrix.getReadPtr());
@ -344,7 +339,6 @@ void LinkedShaderDX9::updateUniforms() {
Matrix4x4 proj_through;
proj_through.setOrtho(0.0f, gstate_c.curRTWidth, gstate_c.curRTHeight, 0, 0, 1);
// Convert matrices !
ConvertProjMatrixToD3D(proj_through, false);
SetMatrix(u_proj_through, proj_through.getReadPtr());

View file

@ -393,7 +393,6 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
// Flip vpY0 to match the OpenGL coordinate system.
vpY0 = renderHeight - (vpYb - offsetY + fabsf(vpYa)) * renderHeightFactor;
// Sadly, as glViewport takes integers, we will not be able to support sub pixel offsets this way. But meh.
// shaderManager_->DirtyUniform(DIRTY_PROJMATRIX);
float zScale = getFloat24(gstate.viewportz1) / 65535.0f;
@ -404,7 +403,14 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
gstate_c.vpDepth = zScale * 2;
dxstate.viewport.set(vpX0 + renderX, vpY0 + renderY, vpWidth, vpHeight, depthRangeMin, depthRangeMax);
// D3D doesn't like viewports partially outside the target. Clamp the viewport for now. Should also adjust
// the projection matrix to compensate, really.
float left = std::max(0.0f, vpX0 + renderX);
float top = std::max(0.0f, vpY0 + renderY);
float right = std::min(left + vpWidth, renderWidth);
float bottom = std::min(top + vpHeight, renderHeight);
dxstate.viewport.set(left, top, right - left, bottom - top, depthRangeMin, depthRangeMax);
}
}

View file

@ -152,8 +152,8 @@ TransformDrawEngineDX9::TransformDrawEngineDX9()
decIndex = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE);
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE);
transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
quadIndices_ = new u16[6 * QUAD_INDICES_MAX];
quadIndices_ = new u16[6 * QUAD_INDICES_MAX];
for (int i = 0; i < QUAD_INDICES_MAX; i++) {
quadIndices_[i * 6 + 0] = i * 4;
quadIndices_[i * 6 + 1] = i * 4 + 2;
@ -178,7 +178,9 @@ TransformDrawEngineDX9::~TransformDrawEngineDX9() {
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
for (auto decl = vertexDeclMap_.begin(); decl != vertexDeclMap_.end(); ++decl) {
decl->second->Release();
if (decl->second) {
decl->second->Release();
}
}
delete [] quadIndices_;
@ -321,7 +323,7 @@ IDirect3DVertexDeclaration9 *TransformDrawEngineDX9::SetupDecFmtForDraw(LinkedSh
memcpy(VertexElement, &end, sizeof(D3DVERTEXELEMENT9));
// Create declaration
IDirect3DVertexDeclaration9 *pHardwareVertexDecl;
IDirect3DVertexDeclaration9 *pHardwareVertexDecl = nullptr;
HRESULT hr = pD3Ddevice->CreateVertexDeclaration( VertexElements, &pHardwareVertexDecl );
if (FAILED(hr)) {
// Log