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