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