mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 21:35:28 +00:00
Merge pull request #6045 from lioncash/sw-vertloader
SWVertexLoader: Minor cleanup
This commit is contained in:
commit
432117047b
@ -39,7 +39,8 @@ SWVertexLoader::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_de
|
||||
return std::make_unique<NullNativeVertexFormat>(vtx_decl);
|
||||
}
|
||||
|
||||
SWVertexLoader::SWVertexLoader() : LocalVBuffer(MAXVBUFFERSIZE), LocalIBuffer(MAXIBUFFERSIZE)
|
||||
SWVertexLoader::SWVertexLoader()
|
||||
: m_local_vertex_buffer(MAXVBUFFERSIZE), m_local_index_buffer(MAXIBUFFERSIZE)
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,9 +50,9 @@ SWVertexLoader::~SWVertexLoader()
|
||||
|
||||
void SWVertexLoader::ResetBuffer(u32 stride)
|
||||
{
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = LocalVBuffer.data();
|
||||
m_end_buffer_pointer = m_cur_buffer_pointer + LocalVBuffer.size();
|
||||
IndexGenerator::Start(GetIndexBuffer());
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = m_local_vertex_buffer.data();
|
||||
m_end_buffer_pointer = m_cur_buffer_pointer + m_local_vertex_buffer.size();
|
||||
IndexGenerator::Start(m_local_index_buffer.data());
|
||||
}
|
||||
|
||||
void SWVertexLoader::vFlush()
|
||||
@ -74,7 +75,7 @@ void SWVertexLoader::vFlush()
|
||||
break;
|
||||
}
|
||||
|
||||
m_SetupUnit.Init(primitiveType);
|
||||
m_setup_unit.Init(primitiveType);
|
||||
|
||||
// set all states with are stored within video sw
|
||||
for (int i = 0; i < 4; i++)
|
||||
@ -87,37 +88,37 @@ void SWVertexLoader::vFlush()
|
||||
|
||||
for (u32 i = 0; i < IndexGenerator::GetIndexLen(); i++)
|
||||
{
|
||||
u16 index = LocalIBuffer[i];
|
||||
const u16 index = m_local_index_buffer[i];
|
||||
|
||||
if (index == 0xffff)
|
||||
{
|
||||
// primitive restart
|
||||
m_SetupUnit.Init(primitiveType);
|
||||
m_setup_unit.Init(primitiveType);
|
||||
continue;
|
||||
}
|
||||
memset(&m_Vertex, 0, sizeof(m_Vertex));
|
||||
memset(&m_vertex, 0, sizeof(m_vertex));
|
||||
|
||||
// Super Mario Sunshine requires those to be zero for those debug boxes.
|
||||
m_Vertex.color = {};
|
||||
m_vertex.color = {};
|
||||
|
||||
// parse the videocommon format to our own struct format (m_Vertex)
|
||||
// parse the videocommon format to our own struct format (m_vertex)
|
||||
SetFormat(g_main_cp_state.last_id, primitiveType);
|
||||
ParseVertex(VertexLoaderManager::GetCurrentVertexFormat()->GetVertexDeclaration(), index);
|
||||
|
||||
// transform this vertex so that it can be used for rasterization (outVertex)
|
||||
OutputVertexData* outVertex = m_SetupUnit.GetVertex();
|
||||
TransformUnit::TransformPosition(&m_Vertex, outVertex);
|
||||
OutputVertexData* outVertex = m_setup_unit.GetVertex();
|
||||
TransformUnit::TransformPosition(&m_vertex, outVertex);
|
||||
outVertex->normal = {};
|
||||
if (VertexLoaderManager::g_current_components & VB_HAS_NRM0)
|
||||
{
|
||||
TransformUnit::TransformNormal(
|
||||
&m_Vertex, (VertexLoaderManager::g_current_components & VB_HAS_NRM2) != 0, outVertex);
|
||||
&m_vertex, (VertexLoaderManager::g_current_components & VB_HAS_NRM2) != 0, outVertex);
|
||||
}
|
||||
TransformUnit::TransformColor(&m_Vertex, outVertex);
|
||||
TransformUnit::TransformTexCoord(&m_Vertex, outVertex, m_TexGenSpecialCase);
|
||||
TransformUnit::TransformColor(&m_vertex, outVertex);
|
||||
TransformUnit::TransformTexCoord(&m_vertex, outVertex, m_tex_gen_special_case);
|
||||
|
||||
// assemble and rasterize the primitive
|
||||
m_SetupUnit.SetupVertex();
|
||||
m_setup_unit.SetupVertex();
|
||||
|
||||
INCSTAT(stats.thisFrame.numVerticesLoaded)
|
||||
}
|
||||
@ -141,20 +142,20 @@ void SWVertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType)
|
||||
ERROR_LOG(VIDEO, "Matrix indices don't match");
|
||||
}
|
||||
|
||||
m_Vertex.posMtx = xfmem.MatrixIndexA.PosNormalMtxIdx;
|
||||
m_Vertex.texMtx[0] = xfmem.MatrixIndexA.Tex0MtxIdx;
|
||||
m_Vertex.texMtx[1] = xfmem.MatrixIndexA.Tex1MtxIdx;
|
||||
m_Vertex.texMtx[2] = xfmem.MatrixIndexA.Tex2MtxIdx;
|
||||
m_Vertex.texMtx[3] = xfmem.MatrixIndexA.Tex3MtxIdx;
|
||||
m_Vertex.texMtx[4] = xfmem.MatrixIndexB.Tex4MtxIdx;
|
||||
m_Vertex.texMtx[5] = xfmem.MatrixIndexB.Tex5MtxIdx;
|
||||
m_Vertex.texMtx[6] = xfmem.MatrixIndexB.Tex6MtxIdx;
|
||||
m_Vertex.texMtx[7] = xfmem.MatrixIndexB.Tex7MtxIdx;
|
||||
m_vertex.posMtx = xfmem.MatrixIndexA.PosNormalMtxIdx;
|
||||
m_vertex.texMtx[0] = xfmem.MatrixIndexA.Tex0MtxIdx;
|
||||
m_vertex.texMtx[1] = xfmem.MatrixIndexA.Tex1MtxIdx;
|
||||
m_vertex.texMtx[2] = xfmem.MatrixIndexA.Tex2MtxIdx;
|
||||
m_vertex.texMtx[3] = xfmem.MatrixIndexA.Tex3MtxIdx;
|
||||
m_vertex.texMtx[4] = xfmem.MatrixIndexB.Tex4MtxIdx;
|
||||
m_vertex.texMtx[5] = xfmem.MatrixIndexB.Tex5MtxIdx;
|
||||
m_vertex.texMtx[6] = xfmem.MatrixIndexB.Tex6MtxIdx;
|
||||
m_vertex.texMtx[7] = xfmem.MatrixIndexB.Tex7MtxIdx;
|
||||
|
||||
// special case if only pos and tex coord 0 and tex coord input is AB11
|
||||
// http://libogc.devkitpro.org/gx_8h.html#a55a426a3ff796db584302bddd829f002
|
||||
m_TexGenSpecialCase = VertexLoaderManager::g_current_components == VB_HAS_UV0 &&
|
||||
xfmem.texMtxInfo[0].projection == XF_TEXPROJ_ST;
|
||||
m_tex_gen_special_case = VertexLoaderManager::g_current_components == VB_HAS_UV0 &&
|
||||
xfmem.texMtxInfo[0].projection == XF_TEXPROJ_ST;
|
||||
}
|
||||
|
||||
template <typename T, typename I>
|
||||
@ -214,31 +215,32 @@ static void ReadVertexAttribute(T* dst, DataReader src, const AttributeFormat& f
|
||||
|
||||
void SWVertexLoader::ParseVertex(const PortableVertexDeclaration& vdec, int index)
|
||||
{
|
||||
DataReader src(LocalVBuffer.data(), LocalVBuffer.data() + LocalVBuffer.size());
|
||||
DataReader src(m_local_vertex_buffer.data(),
|
||||
m_local_vertex_buffer.data() + m_local_vertex_buffer.size());
|
||||
src.Skip(index * vdec.stride);
|
||||
|
||||
ReadVertexAttribute<float>(&m_Vertex.position[0], src, vdec.position, 0, 3, false);
|
||||
ReadVertexAttribute<float>(&m_vertex.position[0], src, vdec.position, 0, 3, false);
|
||||
|
||||
for (std::size_t i = 0; i < m_Vertex.normal.size(); i++)
|
||||
for (std::size_t i = 0; i < m_vertex.normal.size(); i++)
|
||||
{
|
||||
ReadVertexAttribute<float>(&m_Vertex.normal[i][0], src, vdec.normals[i], 0, 3, false);
|
||||
ReadVertexAttribute<float>(&m_vertex.normal[i][0], src, vdec.normals[i], 0, 3, false);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_Vertex.color.size(); i++)
|
||||
for (std::size_t i = 0; i < m_vertex.color.size(); i++)
|
||||
{
|
||||
ReadVertexAttribute<u8>(m_Vertex.color[i].data(), src, vdec.colors[i], 0, 4, true);
|
||||
ReadVertexAttribute<u8>(m_vertex.color[i].data(), src, vdec.colors[i], 0, 4, true);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_Vertex.texCoords.size(); i++)
|
||||
for (std::size_t i = 0; i < m_vertex.texCoords.size(); i++)
|
||||
{
|
||||
ReadVertexAttribute<float>(m_Vertex.texCoords[i].data(), src, vdec.texcoords[i], 0, 2, false);
|
||||
ReadVertexAttribute<float>(m_vertex.texCoords[i].data(), src, vdec.texcoords[i], 0, 2, false);
|
||||
|
||||
// the texmtr is stored as third component of the texCoord
|
||||
if (vdec.texcoords[i].components >= 3)
|
||||
{
|
||||
ReadVertexAttribute<u8>(&m_Vertex.texMtx[i], src, vdec.texcoords[i], 2, 1, false);
|
||||
ReadVertexAttribute<u8>(&m_vertex.texMtx[i], src, vdec.texcoords[i], 2, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
ReadVertexAttribute<u8>(&m_Vertex.posMtx, src, vdec.posmtx, 0, 1, false);
|
||||
ReadVertexAttribute<u8>(&m_vertex.posMtx, src, vdec.posmtx, 0, 1, false);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
|
||||
class SWVertexLoader : public VertexManagerBase
|
||||
class SWVertexLoader final : public VertexManagerBase
|
||||
{
|
||||
public:
|
||||
SWVertexLoader();
|
||||
@ -23,22 +23,18 @@ public:
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vdec) override;
|
||||
|
||||
protected:
|
||||
void ResetBuffer(u32 stride) override;
|
||||
u16* GetIndexBuffer() { return &LocalIBuffer[0]; }
|
||||
private:
|
||||
void ResetBuffer(u32 stride) override;
|
||||
void vFlush() override;
|
||||
std::vector<u8> LocalVBuffer;
|
||||
std::vector<u16> LocalIBuffer;
|
||||
|
||||
InputVertexData m_Vertex;
|
||||
|
||||
void SetFormat(u8 attributeIndex, u8 primitiveType);
|
||||
void ParseVertex(const PortableVertexDeclaration& vdec, int index);
|
||||
|
||||
SetupUnit m_SetupUnit;
|
||||
std::vector<u8> m_local_vertex_buffer;
|
||||
std::vector<u16> m_local_index_buffer;
|
||||
|
||||
bool m_TexGenSpecialCase;
|
||||
InputVertexData m_vertex;
|
||||
SetupUnit m_setup_unit;
|
||||
|
||||
public:
|
||||
void SetFormat(u8 attributeIndex, u8 primitiveType);
|
||||
bool m_tex_gen_special_case;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user