2014-07-27 08:58:30 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "pica.h"
|
|
|
|
#include "primitive_assembly.h"
|
|
|
|
#include "vertex_shader.h"
|
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2014-07-27 08:58:30 -04:00
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
namespace Pica {
|
2014-07-27 08:58:30 -04:00
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
template<typename VertexType>
|
|
|
|
PrimitiveAssembler<VertexType>::PrimitiveAssembler(Regs::TriangleTopology topology)
|
|
|
|
: topology(topology), buffer_index(0) {
|
|
|
|
}
|
2014-07-27 08:58:30 -04:00
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
template<typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::SubmitVertex(VertexType& vtx, TriangleHandler triangle_handler)
|
2014-07-27 08:58:30 -04:00
|
|
|
{
|
2014-08-17 11:44:55 -04:00
|
|
|
switch (topology) {
|
2014-07-27 08:58:30 -04:00
|
|
|
case Regs::TriangleTopology::List:
|
|
|
|
case Regs::TriangleTopology::ListIndexed:
|
|
|
|
if (buffer_index < 2) {
|
|
|
|
buffer[buffer_index++] = vtx;
|
|
|
|
} else {
|
|
|
|
buffer_index = 0;
|
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
2014-07-27 08:58:30 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-12-06 18:26:48 -05:00
|
|
|
case Regs::TriangleTopology::Strip:
|
2014-07-27 08:58:30 -04:00
|
|
|
case Regs::TriangleTopology::Fan:
|
2014-12-06 18:26:48 -05:00
|
|
|
if (strip_ready) {
|
|
|
|
// TODO: Should be "buffer[0], buffer[1], vtx" instead!
|
|
|
|
// Not quite sure why we need this order for things to show up properly.
|
|
|
|
// Maybe a bug in the rasterizer?
|
|
|
|
triangle_handler(buffer[1], buffer[0], vtx);
|
|
|
|
}
|
|
|
|
buffer[buffer_index] = vtx;
|
2014-07-27 08:58:30 -04:00
|
|
|
|
2014-12-06 18:26:48 -05: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 08:58:30 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-12-06 18:26:48 -05:00
|
|
|
LOG_ERROR(HW_GPU, "Unknown triangle topology %x:", (int)topology);
|
2014-07-27 08:58:30 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
// explicitly instantiate use cases
|
|
|
|
template
|
|
|
|
struct PrimitiveAssembler<VertexShader::OutputVertex>;
|
|
|
|
template
|
|
|
|
struct PrimitiveAssembler<DebugUtils::GeometryDumper::Vertex>;
|
2014-07-27 08:58:30 -04:00
|
|
|
|
|
|
|
} // namespace
|