2014-07-27 14:58:30 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-27 14:58:30 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "pica.h"
|
|
|
|
#include "primitive_assembly.h"
|
2015-07-22 01:04:05 +02:00
|
|
|
#include "shader_interpreter.h"
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2015-01-21 02:16:47 +01:00
|
|
|
#include "common/logging/log.h"
|
2014-08-17 17:44:55 +02:00
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
namespace Pica {
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
template<typename VertexType>
|
|
|
|
PrimitiveAssembler<VertexType>::PrimitiveAssembler(Regs::TriangleTopology topology)
|
|
|
|
: topology(topology), buffer_index(0) {
|
|
|
|
}
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
template<typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::SubmitVertex(VertexType& vtx, TriangleHandler triangle_handler)
|
2014-07-27 14:58:30 +02:00
|
|
|
{
|
2014-08-17 17:44:55 +02:00
|
|
|
switch (topology) {
|
2015-03-22 00:31:40 +01:00
|
|
|
// TODO: Figure out what's different with TriangleTopology::Shader.
|
2014-07-27 14:58:30 +02:00
|
|
|
case Regs::TriangleTopology::List:
|
2015-03-22 00:31:40 +01:00
|
|
|
case Regs::TriangleTopology::Shader:
|
2014-07-27 14:58:30 +02:00
|
|
|
if (buffer_index < 2) {
|
|
|
|
buffer[buffer_index++] = vtx;
|
|
|
|
} else {
|
|
|
|
buffer_index = 0;
|
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
2014-07-27 14:58:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-12-07 00:26:48 +01:00
|
|
|
case Regs::TriangleTopology::Strip:
|
2014-07-27 14:58:30 +02:00
|
|
|
case Regs::TriangleTopology::Fan:
|
2015-03-09 21:49:49 +01:00
|
|
|
if (strip_ready)
|
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
|
|
|
|
2014-12-07 00:26:48 +01:00
|
|
|
buffer[buffer_index] = vtx;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2014-12-07 00:26:48 +01:00
|
|
|
if (topology == Regs::TriangleTopology::Strip) {
|
|
|
|
strip_ready |= (buffer_index == 1);
|
|
|
|
buffer_index = !buffer_index;
|
|
|
|
} else if (topology == Regs::TriangleTopology::Fan) {
|
|
|
|
buffer_index = 1;
|
|
|
|
strip_ready = true;
|
2014-07-27 14:58:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-12-07 00:26:48 +01:00
|
|
|
LOG_ERROR(HW_GPU, "Unknown triangle topology %x:", (int)topology);
|
2014-07-27 14:58:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
// explicitly instantiate use cases
|
|
|
|
template
|
2015-07-22 01:04:05 +02:00
|
|
|
struct PrimitiveAssembler<Shader::OutputVertex>;
|
2014-08-17 17:44:55 +02:00
|
|
|
template
|
|
|
|
struct PrimitiveAssembler<DebugUtils::GeometryDumper::Vertex>;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
|
|
|
} // namespace
|