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"
|
2016-09-21 12:22:38 +05:30
|
|
|
#include "video_core/primitive_assembly.h"
|
2017-01-29 02:04:31 +05:30
|
|
|
#include "video_core/regs_pipeline.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
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
template <typename VertexType>
|
2017-01-29 02:04:31 +05:30
|
|
|
PrimitiveAssembler<VertexType>::PrimitiveAssembler(PipelineRegs::TriangleTopology topology)
|
2016-09-19 06:31:46 +05:30
|
|
|
: topology(topology), buffer_index(0) {}
|
2014-07-27 18:28:30 +05:30
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
template <typename VertexType>
|
2017-01-28 07:40:54 +05:30
|
|
|
void PrimitiveAssembler<VertexType>::SubmitVertex(const VertexType& vtx,
|
2016-09-18 06:08:01 +05:30
|
|
|
TriangleHandler triangle_handler) {
|
2014-08-17 21:14:55 +05:30
|
|
|
switch (topology) {
|
2017-01-29 02:04:31 +05:30
|
|
|
case PipelineRegs::TriangleTopology::List:
|
|
|
|
case PipelineRegs::TriangleTopology::Shader:
|
2016-09-18 06:08:01 +05:30
|
|
|
if (buffer_index < 2) {
|
|
|
|
buffer[buffer_index++] = vtx;
|
|
|
|
} else {
|
|
|
|
buffer_index = 0;
|
2017-07-26 17:37:13 +05:30
|
|
|
if (topology == PipelineRegs::TriangleTopology::Shader && winding) {
|
|
|
|
triangle_handler(buffer[1], buffer[0], vtx);
|
|
|
|
winding = false;
|
|
|
|
} else {
|
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
|
|
|
}
|
2016-09-18 06:08:01 +05:30
|
|
|
}
|
|
|
|
break;
|
2014-07-27 18:28:30 +05:30
|
|
|
|
2017-01-29 02:04:31 +05:30
|
|
|
case PipelineRegs::TriangleTopology::Strip:
|
|
|
|
case PipelineRegs::TriangleTopology::Fan:
|
2016-09-18 06:08:01 +05:30
|
|
|
if (strip_ready)
|
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
2015-03-10 02:19:49 +05:30
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
buffer[buffer_index] = vtx;
|
2014-07-27 18:28:30 +05:30
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
strip_ready |= (buffer_index == 1);
|
2015-12-06 20:47:47 +05:30
|
|
|
|
2017-01-29 02:04:31 +05:30
|
|
|
if (topology == PipelineRegs::TriangleTopology::Strip)
|
2016-09-18 06:08:01 +05:30
|
|
|
buffer_index = !buffer_index;
|
2017-01-29 02:04:31 +05:30
|
|
|
else if (topology == PipelineRegs::TriangleTopology::Fan)
|
2016-09-18 06:08:01 +05:30
|
|
|
buffer_index = 1;
|
|
|
|
break;
|
2014-07-27 18:28:30 +05:30
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
default:
|
|
|
|
LOG_ERROR(HW_GPU, "Unknown triangle topology %x:", (int)topology);
|
|
|
|
break;
|
2014-07-27 18:28:30 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 17:37:13 +05:30
|
|
|
template <typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::SetWinding() {
|
|
|
|
winding = true;
|
|
|
|
}
|
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
template <typename VertexType>
|
2016-03-03 08:46:38 +05:30
|
|
|
void PrimitiveAssembler<VertexType>::Reset() {
|
|
|
|
buffer_index = 0;
|
|
|
|
strip_ready = false;
|
2017-07-26 17:37:13 +05:30
|
|
|
winding = false;
|
2016-03-03 08:46:38 +05:30
|
|
|
}
|
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
template <typename VertexType>
|
2017-01-29 02:04:31 +05:30
|
|
|
void PrimitiveAssembler<VertexType>::Reconfigure(PipelineRegs::TriangleTopology topology) {
|
2016-03-03 08:46:38 +05:30
|
|
|
Reset();
|
|
|
|
this->topology = topology;
|
|
|
|
}
|
|
|
|
|
2014-08-17 21:14:55 +05:30
|
|
|
// explicitly instantiate use cases
|
2016-09-18 06:08:01 +05:30
|
|
|
template struct PrimitiveAssembler<Shader::OutputVertex>;
|
2014-07-27 18:28:30 +05:30
|
|
|
|
|
|
|
} // namespace
|