2014-07-27 08:58:30 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-27 08:58:30 -04:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-01-20 20:16:47 -05:00
|
|
|
#include "common/logging/log.h"
|
2015-09-11 07:20:02 -04:00
|
|
|
|
|
|
|
#include "video_core/pica.h"
|
|
|
|
#include "video_core/primitive_assembly.h"
|
2016-04-30 11:34:51 -04:00
|
|
|
#include "video_core/shader/shader.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) {
|
2015-03-21 19:31:40 -04:00
|
|
|
// TODO: Figure out what's different with TriangleTopology::Shader.
|
2014-07-27 08:58:30 -04:00
|
|
|
case Regs::TriangleTopology::List:
|
2015-03-21 19:31:40 -04:00
|
|
|
case Regs::TriangleTopology::Shader:
|
2014-07-27 08:58:30 -04:00
|
|
|
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:
|
2015-03-09 16:49:49 -04:00
|
|
|
if (strip_ready)
|
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
|
|
|
|
2014-12-06 18:26:48 -05:00
|
|
|
buffer[buffer_index] = vtx;
|
2014-07-27 08:58:30 -04:00
|
|
|
|
2015-12-06 10:17:47 -05:00
|
|
|
strip_ready |= (buffer_index == 1);
|
|
|
|
|
|
|
|
if (topology == Regs::TriangleTopology::Strip)
|
2014-12-06 18:26:48 -05:00
|
|
|
buffer_index = !buffer_index;
|
2015-12-06 10:17:47 -05:00
|
|
|
else if (topology == Regs::TriangleTopology::Fan)
|
2014-12-06 18:26:48 -05:00
|
|
|
buffer_index = 1;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 22:16:38 -05:00
|
|
|
template<typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::Reset() {
|
|
|
|
buffer_index = 0;
|
|
|
|
strip_ready = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::Reconfigure(Regs::TriangleTopology topology) {
|
|
|
|
Reset();
|
|
|
|
this->topology = topology;
|
|
|
|
}
|
|
|
|
|
2014-08-17 11:44:55 -04:00
|
|
|
// explicitly instantiate use cases
|
|
|
|
template
|
2015-07-21 19:04:05 -04:00
|
|
|
struct PrimitiveAssembler<Shader::OutputVertex>;
|
2014-07-27 08:58:30 -04:00
|
|
|
|
|
|
|
} // namespace
|