From bf58c70e9b5a16c56113fe5114a845f8000d4a9d Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 4 Mar 2013 15:24:39 -0600 Subject: [PATCH] Move copy-pasted code into function. --- Source/Core/VideoCommon/Src/VertexLoader.cpp | 69 +++++--------------- Source/Core/VideoCommon/Src/VertexLoader.h | 2 + 2 files changed, 18 insertions(+), 53 deletions(-) diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index ca128b4f86..bbee1c0411 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -517,7 +517,7 @@ void VertexLoader::WriteSetVariable(int bits, void *address, OpArg value) #endif } -void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int const count) +int VertexLoader::SetupRunVertices(int vtx_attr_group, int primitive, int const count) { m_numLoadedVertices += count; @@ -536,7 +536,7 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int const coun { // if cull mode is none, ignore triangles and quads DataSkip(count * m_VertexSize); - return; + return 0; } m_NativeFmt->EnableComponents(m_NativeFmt->m_components); @@ -561,8 +561,15 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int const coun colElements[i] = m_VtxAttr.color[i].Elements; VertexManager::PrepareForAdditionalData(primitive, count, native_stride); - ConvertVertices(count); - VertexManager::AddVertices(primitive, count); + + return count; +} + +void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int const count) +{ + auto const new_count = SetupRunVertices(vtx_attr_group, primitive, count); + ConvertVertices(new_count); + VertexManager::AddVertices(primitive, new_count); } void VertexLoader::ConvertVertices ( int count ) @@ -585,59 +592,15 @@ void VertexLoader::ConvertVertices ( int count ) #endif } - - - void VertexLoader::RunCompiledVertices(int vtx_attr_group, int primitive, int const count, u8* Data) { - m_numLoadedVertices += count; - - // Flush if our vertex format is different from the currently set. - if (g_nativeVertexFmt != NULL && g_nativeVertexFmt != m_NativeFmt) - { - // We really must flush here. It's possible that the native representations - // of the two vtx formats are the same, but we have no way to easily check that - // now. - VertexManager::Flush(); - // Also move the Set() here? - } - g_nativeVertexFmt = m_NativeFmt; - - if (bpmem.genMode.cullmode == 3 && primitive < 5) - { - // if cull mode is none, ignore triangles and quads - DataSkip(count * m_VertexSize); - return; - } - - m_NativeFmt->EnableComponents(m_NativeFmt->m_components); - - // Load position and texcoord scale factors. - m_VtxAttr.PosFrac = g_VtxAttr[vtx_attr_group].g0.PosFrac; - m_VtxAttr.texCoord[0].Frac = g_VtxAttr[vtx_attr_group].g0.Tex0Frac; - m_VtxAttr.texCoord[1].Frac = g_VtxAttr[vtx_attr_group].g1.Tex1Frac; - m_VtxAttr.texCoord[2].Frac = g_VtxAttr[vtx_attr_group].g1.Tex2Frac; - m_VtxAttr.texCoord[3].Frac = g_VtxAttr[vtx_attr_group].g1.Tex3Frac; - m_VtxAttr.texCoord[4].Frac = g_VtxAttr[vtx_attr_group].g2.Tex4Frac; - m_VtxAttr.texCoord[5].Frac = g_VtxAttr[vtx_attr_group].g2.Tex5Frac; - m_VtxAttr.texCoord[6].Frac = g_VtxAttr[vtx_attr_group].g2.Tex6Frac; - m_VtxAttr.texCoord[7].Frac = g_VtxAttr[vtx_attr_group].g2.Tex7Frac; - - pVtxAttr = &m_VtxAttr; - posScale = fractionTable[m_VtxAttr.PosFrac]; - if (m_NativeFmt->m_components & VB_HAS_UVALL) - for (int i = 0; i < 8; i++) - tcScale[i] = fractionTable[m_VtxAttr.texCoord[i].Frac]; - for (int i = 0; i < 2; i++) - colElements[i] = m_VtxAttr.color[i].Elements; - - VertexManager::PrepareForAdditionalData(primitive, count, native_stride); + auto const new_count = SetupRunVertices(vtx_attr_group, primitive, count); - memcpy_gc(VertexManager::s_pCurBufferPointer, Data, native_stride * count); - VertexManager::s_pCurBufferPointer += native_stride * count; - DataSkip(count * m_VertexSize); + memcpy_gc(VertexManager::s_pCurBufferPointer, Data, native_stride * new_count); + VertexManager::s_pCurBufferPointer += native_stride * new_count; + DataSkip(new_count * m_VertexSize); - VertexManager::AddVertices(primitive, count); + VertexManager::AddVertices(primitive, new_count); } void VertexLoader::SetVAT(u32 _group0, u32 _group1, u32 _group2) diff --git a/Source/Core/VideoCommon/Src/VertexLoader.h b/Source/Core/VideoCommon/Src/VertexLoader.h index 4f4fc19e99..b7afbe4ba6 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.h +++ b/Source/Core/VideoCommon/Src/VertexLoader.h @@ -83,6 +83,8 @@ public: ~VertexLoader(); int GetVertexSize() const {return m_VertexSize;} + + int SetupRunVertices(int vtx_attr_group, int primitive, int const count); void RunVertices(int vtx_attr_group, int primitive, int count); void RunCompiledVertices(int vtx_attr_group, int primitive, int count, u8* Data);