2014-07-27 14:58:30 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-27 14:58:30 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-01-21 02:16:47 +01:00
|
|
|
#include "common/logging/log.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/primitive_assembly.h"
|
2017-01-28 21:34:31 +01:00
|
|
|
#include "video_core/regs_pipeline.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "video_core/shader/shader.h"
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
namespace Pica {
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
template <typename VertexType>
|
2017-01-28 21:34:31 +01:00
|
|
|
PrimitiveAssembler<VertexType>::PrimitiveAssembler(PipelineRegs::TriangleTopology topology)
|
2016-09-19 03:01:46 +02:00
|
|
|
: topology(topology), buffer_index(0) {}
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
template <typename VertexType>
|
2017-01-28 03:10:54 +01:00
|
|
|
void PrimitiveAssembler<VertexType>::SubmitVertex(const VertexType& vtx,
|
2016-09-18 02:38:01 +02:00
|
|
|
TriangleHandler triangle_handler) {
|
2014-08-17 17:44:55 +02:00
|
|
|
switch (topology) {
|
2017-01-28 21:34:31 +01:00
|
|
|
case PipelineRegs::TriangleTopology::List:
|
|
|
|
case PipelineRegs::TriangleTopology::Shader:
|
2016-09-18 02:38:01 +02:00
|
|
|
if (buffer_index < 2) {
|
|
|
|
buffer[buffer_index++] = vtx;
|
|
|
|
} else {
|
|
|
|
buffer_index = 0;
|
2017-07-26 14:07:13 +02:00
|
|
|
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 02:38:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2017-01-28 21:34:31 +01:00
|
|
|
case PipelineRegs::TriangleTopology::Strip:
|
|
|
|
case PipelineRegs::TriangleTopology::Fan:
|
2016-09-18 02:38:01 +02:00
|
|
|
if (strip_ready)
|
|
|
|
triangle_handler(buffer[0], buffer[1], vtx);
|
2015-03-09 21:49:49 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
buffer[buffer_index] = vtx;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
strip_ready |= (buffer_index == 1);
|
2015-12-06 16:17:47 +01:00
|
|
|
|
2017-01-28 21:34:31 +01:00
|
|
|
if (topology == PipelineRegs::TriangleTopology::Strip)
|
2016-09-18 02:38:01 +02:00
|
|
|
buffer_index = !buffer_index;
|
2017-01-28 21:34:31 +01:00
|
|
|
else if (topology == PipelineRegs::TriangleTopology::Fan)
|
2016-09-18 02:38:01 +02:00
|
|
|
buffer_index = 1;
|
|
|
|
break;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
default:
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(HW_GPU, "Unknown triangle topology {:x}:", (int)topology);
|
2016-09-18 02:38:01 +02:00
|
|
|
break;
|
2014-07-27 14:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 14:07:13 +02:00
|
|
|
template <typename VertexType>
|
|
|
|
void PrimitiveAssembler<VertexType>::SetWinding() {
|
|
|
|
winding = true;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
template <typename VertexType>
|
2016-03-03 04:16:38 +01:00
|
|
|
void PrimitiveAssembler<VertexType>::Reset() {
|
|
|
|
buffer_index = 0;
|
|
|
|
strip_ready = false;
|
2017-07-26 14:07:13 +02:00
|
|
|
winding = false;
|
2016-03-03 04:16:38 +01:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
template <typename VertexType>
|
2017-01-28 21:34:31 +01:00
|
|
|
void PrimitiveAssembler<VertexType>::Reconfigure(PipelineRegs::TriangleTopology topology) {
|
2016-03-03 04:16:38 +01:00
|
|
|
Reset();
|
|
|
|
this->topology = topology;
|
|
|
|
}
|
|
|
|
|
2017-12-27 14:02:34 +01:00
|
|
|
template <typename VertexType>
|
|
|
|
bool PrimitiveAssembler<VertexType>::IsEmpty() const {
|
|
|
|
return buffer_index == 0 && strip_ready == false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename VertexType>
|
|
|
|
PipelineRegs::TriangleTopology PrimitiveAssembler<VertexType>::GetTopology() const {
|
|
|
|
return topology;
|
|
|
|
}
|
|
|
|
|
2014-08-17 17:44:55 +02:00
|
|
|
// explicitly instantiate use cases
|
2016-09-18 02:38:01 +02:00
|
|
|
template struct PrimitiveAssembler<Shader::OutputVertex>;
|
2014-07-27 14:58:30 +02:00
|
|
|
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Pica
|