2013-04-18 05:29:41 +02:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:29:41 +02:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2014-07-30 02:55:07 +02:00
|
|
|
#include "Common/ChunkFile.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoBackends/Software/Clipper.h"
|
|
|
|
#include "VideoBackends/Software/CPMemLoader.h"
|
|
|
|
#include "VideoBackends/Software/OpcodeDecoder.h"
|
|
|
|
#include "VideoBackends/Software/SetupUnit.h"
|
|
|
|
#include "VideoBackends/Software/SWStatistics.h"
|
2010-06-09 03:37:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
void SetupUnit::Init(u8 primitiveType)
|
|
|
|
{
|
2013-02-26 05:49:24 +01:00
|
|
|
m_PrimType = primitiveType;
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertexCounter = 0;
|
2013-02-26 05:49:24 +01:00
|
|
|
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-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupVertex()
|
|
|
|
{
|
2014-03-10 12:30:55 +01:00
|
|
|
switch (m_PrimType)
|
2013-04-14 05:54:02 +02:00
|
|
|
{
|
|
|
|
case GX_DRAW_QUADS:
|
2014-05-17 20:55:32 +02:00
|
|
|
SetupQuad();
|
|
|
|
break;
|
2014-05-09 01:53:18 +02:00
|
|
|
case GX_DRAW_QUADS_2:
|
2014-05-17 20:55:32 +02:00
|
|
|
WARN_LOG(VIDEO, "Non-standard primitive drawing command GL_DRAW_QUADS_2");
|
2013-04-14 05:54:02 +02:00
|
|
|
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-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-11 03:51:55 +02:00
|
|
|
void SetupUnit::SetupQuad()
|
|
|
|
{
|
2013-04-14 05:54:02 +02:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02: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 03:37:08 +02:00
|
|
|
|
|
|
|
void SetupUnit::SetupTriangle()
|
|
|
|
{
|
2013-04-14 05:54:02 +02:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupTriStrip()
|
|
|
|
{
|
2013-04-14 05:54:02 +02:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[2 - (m_VertexCounter & 1)] = m_VertPointer[0];
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-10-29 06:23:17 +01:00
|
|
|
m_VertPointer[0] = &m_Vertices[(m_VertexCounter + 1) % 3];
|
2010-06-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupTriFan()
|
|
|
|
{
|
2013-04-14 05:54:02 +02:00
|
|
|
if (m_VertexCounter < 2)
|
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessTriangle(m_VertPointer[0], m_VertPointer[1], m_VertPointer[2]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertPointer[1] = m_VertPointer[2];
|
|
|
|
m_VertPointer[2] = &m_Vertices[2 - (m_VertexCounter & 1)];
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertWritePointer = m_VertPointer[2];
|
2010-06-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupLine()
|
|
|
|
{
|
|
|
|
if (m_VertexCounter < 1)
|
2013-04-14 05:54:02 +02:00
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
m_VertexCounter = 0;
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
2010-06-09 03:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupLineStrip()
|
|
|
|
{
|
|
|
|
if (m_VertexCounter < 1)
|
2013-04-14 05:54:02 +02:00
|
|
|
{
|
|
|
|
m_VertexCounter++;
|
2010-06-09 03:37:08 +02:00
|
|
|
m_VertWritePointer = m_VertPointer[m_VertexCounter];
|
2013-04-14 05:54:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-06-09 03:37:08 +02:00
|
|
|
|
|
|
|
m_VertexCounter++;
|
|
|
|
|
2013-04-14 05:54:02 +02:00
|
|
|
Clipper::ProcessLine(m_VertPointer[0], m_VertPointer[1]);
|
2010-06-09 03:37:08 +02:00
|
|
|
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
|
|
|
|
|
|
|
m_VertPointer[0] = m_VertPointer[1];
|
|
|
|
m_VertPointer[1] = &m_Vertices[m_VertexCounter & 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupUnit::SetupPoint()
|
|
|
|
{}
|
2013-02-26 02:05:02 +01:00
|
|
|
|
|
|
|
void SetupUnit::DoState(PointerWrap &p)
|
|
|
|
{
|
2015-01-11 06:17:29 +01:00
|
|
|
// TODO: some or all of this is making the save states stop working once Dolphin is closed...sometimes (usually)
|
2013-02-26 05:49:24 +01:00
|
|
|
// I have no idea what specifically is wrong, or if this is even important. Disabling it doesn't seem to make any noticible difference...
|
|
|
|
/* p.Do(m_PrimType);
|
2013-02-26 02:05:02 +01:00
|
|
|
p.Do(m_VertexCounter);
|
2013-02-26 05:49:24 +01:00
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
m_Vertices[i].DoState(p);
|
|
|
|
|
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
|
|
|
{
|
|
|
|
m_VertPointer[0] = &m_Vertices[0];
|
|
|
|
m_VertPointer[1] = &m_Vertices[1];
|
|
|
|
m_VertPointer[2] = &m_Vertices[2];
|
|
|
|
m_VertWritePointer = m_VertPointer[0];
|
|
|
|
}*/
|
|
|
|
}
|