2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "VideoBackends/Software/SetupUnit.h"
|
2014-07-29 18:55:07 -06:00
|
|
|
#include "Common/ChunkFile.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/Software/Clipper.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2015-10-09 12:50:36 -06:00
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
void SetupUnit::Init(u8 primitiveType)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
m_PrimType = primitiveType;
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06: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];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
2015-12-05 04:18:31 -07:00
|
|
|
OutputVertexData* SetupUnit::GetVertex()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
memset(m_VertWritePointer, 0, sizeof(*m_VertWritePointer));
|
|
|
|
return m_VertWritePointer;
|
2015-12-05 04:18:31 -07:00
|
|
|
}
|
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
void SetupUnit::SetupVertex()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
switch (m_PrimType)
|
|
|
|
{
|
|
|
|
case GX_DRAW_QUADS:
|
|
|
|
SetupQuad();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_QUADS_2:
|
|
|
|
WARN_LOG(VIDEO, "Non-standard primitive drawing command GL_DRAW_QUADS_2");
|
|
|
|
SetupQuad();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_TRIANGLES:
|
|
|
|
SetupTriangle();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_TRIANGLE_STRIP:
|
|
|
|
SetupTriStrip();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_TRIANGLE_FAN:
|
|
|
|
SetupTriFan();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_LINES:
|
|
|
|
SetupLine();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_LINE_STRIP:
|
|
|
|
SetupLineStrip();
|
|
|
|
break;
|
|
|
|
case GX_DRAW_POINTS:
|
|
|
|
SetupPoint();
|
|
|
|
break;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
2014-08-10 19:51:55 -06:00
|
|
|
void SetupUnit::SetupQuad()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
|
|
|
|
|
|
|
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;
|
2013-04-13 21:54:02 -06:00
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
void SetupUnit::SetupTriangle()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupTriStrip()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[2 - (m_VertexCounter & 1)] = m_VertPointer[0];
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertPointer[0] = &m_Vertices[(m_VertexCounter + 1) % 3];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupTriFan()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[1] = m_VertPointer[2];
|
|
|
|
m_VertPointer[2] = &m_Vertices[2 - (m_VertexCounter & 1)];
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertWritePointer = m_VertPointer[2];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupLine()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 1)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupLineStrip()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_VertexCounter < 1)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertexCounter++;
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
m_VertPointer[0] = m_VertPointer[1];
|
|
|
|
m_VertPointer[1] = &m_Vertices[m_VertexCounter & 1];
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupPoint()
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
}
|