2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/SetupUnit.h"
|
2016-09-24 09:16:52 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include <cstring>
|
2016-09-24 09:16:52 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/Clipper.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2021-04-30 21:57:12 +00:00
|
|
|
void SetupUnit::Init(OpcodeDecoder::Primitive primitive_type)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2021-04-30 21:57:12 +00:00
|
|
|
m_PrimType = primitive_type;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-02-26 04:49:24 +00:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertPointer[0] = &m_Vertices[0];
|
|
|
|
m_VertPointer[1] = &m_Vertices[1];
|
|
|
|
m_VertPointer[2] = &m_Vertices[2];
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-12-05 11:18:31 +00:00
|
|
|
OutputVertexData* SetupUnit::GetVertex()
|
|
|
|
{
|
2020-12-16 14:01:20 +00:00
|
|
|
memset(reinterpret_cast<u8*>(m_VertWritePointer), 0, sizeof(*m_VertWritePointer));
|
2015-12-05 11:18:31 +00:00
|
|
|
return m_VertWritePointer;
|
|
|
|
}
|
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupVertex()
|
|
|
|
{
|
2021-04-30 21:57:12 +00:00
|
|
|
using OpcodeDecoder::Primitive;
|
2014-03-10 11:30:55 +00:00
|
|
|
switch (m_PrimType)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_QUADS:
|
2014-05-17 18:55:32 +00:00
|
|
|
SetupQuad();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_QUADS_2:
|
2020-11-09 08:13:59 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "Non-standard primitive drawing command GL_DRAW_QUADS_2");
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupQuad();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_TRIANGLES:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupTriangle();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_TRIANGLE_STRIP:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupTriStrip();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_TRIANGLE_FAN:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupTriFan();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_LINES:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupLine();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_LINE_STRIP:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupLineStrip();
|
|
|
|
break;
|
2021-04-30 21:57:12 +00:00
|
|
|
case Primitive::GX_DRAW_POINTS:
|
2009-10-12 00:48:24 +00:00
|
|
|
SetupPoint();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-08-11 01:51:55 +00:00
|
|
|
void SetupUnit::SetupQuad()
|
|
|
|
{
|
2009-10-12 00:48:24 +00:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertexCounter &= 3;
|
|
|
|
m_VertWritePointer = &m_Vertices[m_VertexCounter & 1];
|
|
|
|
OutputVertexData* temp = m_VertPointer[1];
|
|
|
|
m_VertPointer[1] = m_VertPointer[2];
|
|
|
|
m_VertPointer[2] = temp;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupTriangle()
|
|
|
|
{
|
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupTriStrip()
|
|
|
|
{
|
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[2 - (m_VertexCounter & 1)] = m_VertPointer[0];
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertPointer[0] = &m_Vertices[(m_VertexCounter + 1) % 3];
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupTriFan()
|
|
|
|
{
|
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[1] = m_VertPointer[2];
|
|
|
|
m_VertPointer[2] = &m_Vertices[2 - (m_VertexCounter & 1)];
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
m_VertWritePointer = m_VertPointer[2];
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupLine()
|
2010-03-09 04:38:07 +00:00
|
|
|
{
|
|
|
|
if (m_VertexCounter < 1)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupLineStrip()
|
2010-03-09 04:38:07 +00:00
|
|
|
{
|
|
|
|
if (m_VertexCounter < 1)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
m_VertexCounter++;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-03-09 04:38:07 +00:00
|
|
|
m_VertPointer[0] = m_VertPointer[1];
|
|
|
|
m_VertPointer[1] = &m_Vertices[m_VertexCounter & 1];
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetupUnit::SetupPoint()
|
|
|
|
{
|
2020-12-22 23:00:40 +00:00
|
|
|
Clipper::ProcessPoint(m_VertPointer[0]);
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|