From c70a4725228c30e1cfaa4b165426d846ce83013d Mon Sep 17 00:00:00 2001 From: hrydgard Date: Tue, 10 Mar 2009 22:51:17 +0000 Subject: [PATCH] A fix to D3D NativeVertexFormat. Might not fix much, but should be a step in the right direction. Other misc bits and bobs. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2644 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/NativeVertexFormat.h | 2 +- Source/Core/VideoCommon/Src/VertexLoader.cpp | 13 ++++--- Source/Core/VideoCommon/Src/VideoCommon.h | 8 +++++ .../Plugin_VideoDX9/Plugin_VideoDX9.vcproj | 10 +++--- .../Src/NativeVertexFormat.cpp | 34 ++++++++++++++----- Source/Plugins/Plugin_VideoOGL/Src/Config.cpp | 2 +- .../Plugins/Plugin_VideoOGL/Src/Globals.cpp | 1 - Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 2 ++ Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 1 + 9 files changed, 53 insertions(+), 20 deletions(-) diff --git a/Source/Core/VideoCommon/Src/NativeVertexFormat.h b/Source/Core/VideoCommon/Src/NativeVertexFormat.h index f99d033a6c..edc7b76123 100644 --- a/Source/Core/VideoCommon/Src/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/Src/NativeVertexFormat.h @@ -76,7 +76,7 @@ struct PortableVertexDeclaration VarType color_gl_type; // always GL_UNSIGNED_BYTE int color_offset[2]; VarType texcoord_gl_type[8]; - int texcoord_gl_size[8]; + //int texcoord_gl_size[8]; int texcoord_offset[8]; int texcoord_size[8]; int posmtx_offset; diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index 114783c546..ab1b42dee4 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -102,11 +102,12 @@ void LOADERDECL TexMtx_Write_Float2() VertexManager::s_pCurBufferPointer += 8; } -void LOADERDECL TexMtx_Write_Short3() +void LOADERDECL TexMtx_Write_Short4() { ((s16*)VertexManager::s_pCurBufferPointer)[0] = 0; ((s16*)VertexManager::s_pCurBufferPointer)[1] = 0; ((s16*)VertexManager::s_pCurBufferPointer)[2] = s_curtexmtx[s_texmtxwrite++]; + ((s16*)VertexManager::s_pCurBufferPointer)[3] = 0; // Just to fill out with 0. VertexManager::s_pCurBufferPointer += 8; } @@ -260,6 +261,9 @@ void VertexLoader::CompileVertexTranslator() WriteCall(pFunc); vtx_decl.num_normals = vtx_attr.NormalElements ? 3 : 1; + vtx_decl.normal_offset[0] = -1; + vtx_decl.normal_offset[1] = -1; + vtx_decl.normal_offset[2] = -1; switch (vtx_attr.NormalFormat) { case FORMAT_UBYTE: case FORMAT_BYTE: @@ -310,6 +314,8 @@ void VertexLoader::CompileVertexTranslator() } vtx_decl.color_gl_type = VAR_UNSIGNED_BYTE; + vtx_decl.color_offset[0] = -1; + vtx_decl.color_offset[1] = -1; for (int i = 0; i < 2; i++) { m_NativeFmt->m_components |= VB_HAS_COL0 << i; switch (col[i]) @@ -366,6 +372,7 @@ void VertexLoader::CompileVertexTranslator() // Texture matrix indices (remove if corresponding texture coordinate isn't enabled) for (int i = 0; i < 8; i++) { + vtx_decl.texcoord_offset[i] = -1; m_NativeFmt->m_components |= VB_HAS_UV0 << i; int elements = m_VtxAttr.texCoord[i].Elements; switch (tc[i]) @@ -425,7 +432,7 @@ void VertexLoader::CompileVertexTranslator() vtx_decl.texcoord_gl_type[i] = VAR_SHORT; vtx_decl.texcoord_size[i] = 4; nat_offset += 8; // still include the texture coordinate, but this time as 6 + 2 bytes - WriteCall(TexMtx_Write_Short3); + WriteCall(TexMtx_Write_Short4); } } else { @@ -434,8 +441,6 @@ void VertexLoader::CompileVertexTranslator() vtx_decl.texcoord_gl_type[i] = VAR_FLOAT; vtx_decl.texcoord_size[i] = vtx_attr.texCoord[i].Elements ? 2 : 1; nat_offset += 4 * (vtx_attr.texCoord[i].Elements ? 2 : 1); - } else { - vtx_decl.texcoord_offset[i] = -1; } } diff --git a/Source/Core/VideoCommon/Src/VideoCommon.h b/Source/Core/VideoCommon/Src/VideoCommon.h index 3b2cafc22a..64662b73d5 100644 --- a/Source/Core/VideoCommon/Src/VideoCommon.h +++ b/Source/Core/VideoCommon/Src/VideoCommon.h @@ -128,6 +128,14 @@ struct TRectangle dest->top = (int)(factor_y * top); dest->bottom = (int)(factor_y * bottom); } + + void Clamp(int x1, int y1, int x2, int y2) + { + if (left < x1) left = x1; + if (right > x2) right = x2; + if (top < y1) top = y1; + if (bottom > y2) bottom = y2; + } }; // Logging diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj index fdcb0ca4ee..d027695bb5 100644 --- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj +++ b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj @@ -1,7 +1,7 @@ - - + + diff --git a/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp index 6f8b3fceb3..34381fd0fd 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp @@ -57,13 +57,31 @@ D3DVertexFormat::~D3DVertexFormat() } } -D3DDECLTYPE VarToD3D(VarType t) +D3DDECLTYPE VarToD3D(VarType t, int size) { - static const D3DDECLTYPE lookup[5] = - { - D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4, D3DDECLTYPE_SHORT4N, D3DDECLTYPE_USHORT4N, D3DDECLTYPE_FLOAT3, + static const D3DDECLTYPE lookup1[5] = { + D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_FLOAT1, }; - return lookup[t]; + static const D3DDECLTYPE lookup2[5] = { + D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_SHORT2N, D3DDECLTYPE_USHORT2N, D3DDECLTYPE_FLOAT2, + }; + static const D3DDECLTYPE lookup3[5] = { + D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_FLOAT3, + }; + static const D3DDECLTYPE lookup4[5] = { + D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4, D3DDECLTYPE_SHORT4N, D3DDECLTYPE_USHORT4N, D3DDECLTYPE_FLOAT4, + }; + D3DDECLTYPE retval = D3DDECLTYPE_UNUSED; + switch (size) { + case 1: retval = lookup1[t]; break; + case 2: retval = lookup2[t]; break; + case 3: retval = lookup3[t]; break; + case 4: retval = lookup4[t]; break; + } + if (retval == D3DDECLTYPE_UNUSED) { + PanicAlert("VarToD3D: Invalid type/size combo %i , %i", (int)t, size); + } + return retval; } // TODO: Ban signed bytes as normals - not likely that ATI supports them natively. @@ -91,7 +109,7 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) if (_vtx_decl.normal_offset[i] > 0) { elems[elem_idx].Offset = _vtx_decl.normal_offset[i]; - elems[elem_idx].Type = VarToD3D(_vtx_decl.normal_gl_type); + elems[elem_idx].Type = VarToD3D(_vtx_decl.normal_gl_type, _vtx_decl.normal_gl_size); elems[elem_idx].Usage = D3DDECLUSAGE_NORMAL; elems[elem_idx].UsageIndex = i; ++elem_idx; @@ -103,7 +121,7 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) if (_vtx_decl.color_offset[i] > 0) { elems[elem_idx].Offset = _vtx_decl.color_offset[i]; - elems[elem_idx].Type = VarToD3D(_vtx_decl.color_gl_type); + elems[elem_idx].Type = VarToD3D(_vtx_decl.color_gl_type, 4); elems[elem_idx].Usage = D3DDECLUSAGE_COLOR; elems[elem_idx].UsageIndex = i; ++elem_idx; @@ -115,7 +133,7 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) if (_vtx_decl.texcoord_offset[i] > 0) { elems[elem_idx].Offset = _vtx_decl.texcoord_offset[i]; - elems[elem_idx].Type = VarToD3D(_vtx_decl.texcoord_gl_type[i]); + elems[elem_idx].Type = VarToD3D(_vtx_decl.texcoord_gl_type[i], _vtx_decl.texcoord_size[i]); elems[elem_idx].Usage = D3DDECLUSAGE_TEXCOORD; elems[elem_idx].UsageIndex = i; ++elem_idx; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Config.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Config.cpp index 4274489122..c2cae22822 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Config.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Config.cpp @@ -72,7 +72,7 @@ void Config::Load() iniFile.Get("Enhancements", "MaxAnisotropy", &iMaxAnisotropy, 3); // NOTE - this is x in (1 << x) iniFile.Get("Hacks", "EFBCopyDisable", &bEFBCopyDisable, 0); - iniFile.Get("Hacks", "EFBCopyDisableHotKey", &bEFBCopyDisableHotKey, 0); + iniFile.Get("Hacks", "EFBCopyDisableHotKey", &bEFBCopyDisableHotKey, 0); iniFile.Get("Hacks", "ProjectionHax1", &bProjectionHax1, 0); iniFile.Get("Hacks", "EFBToTextureEnable", &bCopyEFBToRAM, 0); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp index 936f758b20..f97c14b135 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp @@ -84,7 +84,6 @@ void __Log(const char *fmt, ...) fwrite(Msg, strlen(Msg), 1, pfLog); Console::Print(Msg); - } void __Log(int type, const char *fmt, ...) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 7d91021790..df9c09a652 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -587,6 +587,7 @@ GLuint Renderer::ResolveAndGetRenderTarget(const TRectangle &source_rect) TRectangle flipped_rect; source_rect.FlipYPosition(GetTargetHeight(), &flipped_rect); + flipped_rect.Clamp(0, 0, GetTargetWidth(), GetTargetHeight()); // Do the resolve. glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, s_uFramebuffer); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, s_uResolvedFramebuffer); @@ -612,6 +613,7 @@ GLuint Renderer::ResolveAndGetFakeZTarget(const TRectangle &source_rect) TRectangle flipped_rect; source_rect.FlipYPosition(GetTargetHeight(), &flipped_rect); + flipped_rect.Clamp(0, 0, GetTargetWidth(), GetTargetHeight()); // Do the resolve. We resolve both color channels, not very necessary. glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, s_uFramebuffer); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, s_uResolvedFramebuffer); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 1758abd0bd..c6efe420d7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -284,6 +284,7 @@ void Video_Prepare(void) GL_REPORT_ERRORD(); VertexLoaderManager::Init(); TextureConverter::Init(); + INFO_LOG(VIDEO, "Video plugin initialized."); } void Shutdown(void)