citra/src/video_core/primitive_assembly.cpp

88 lines
2.5 KiB
C++
Raw Normal View History

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.
#include "common/logging/log.h"
#include "video_core/primitive_assembly.h"
#include "video_core/regs_pipeline.h"
#include "video_core/shader/shader.h"
2014-07-27 18:28:30 +05:30
namespace Pica {
2014-07-27 18:28:30 +05:30
template <typename VertexType>
PrimitiveAssembler<VertexType>::PrimitiveAssembler(PipelineRegs::TriangleTopology topology)
: topology(topology), buffer_index(0) {}
2014-07-27 18:28:30 +05:30
template <typename VertexType>
void PrimitiveAssembler<VertexType>::SubmitVertex(const VertexType& vtx,
TriangleHandler triangle_handler) {
switch (topology) {
case PipelineRegs::TriangleTopology::List:
case PipelineRegs::TriangleTopology::Shader:
if (buffer_index < 2) {
buffer[buffer_index++] = vtx;
} else {
buffer_index = 0;
if (topology == PipelineRegs::TriangleTopology::Shader && winding) {
triangle_handler(buffer[1], buffer[0], vtx);
winding = false;
} else {
triangle_handler(buffer[0], buffer[1], vtx);
}
}
break;
2014-07-27 18:28:30 +05:30
case PipelineRegs::TriangleTopology::Strip:
case PipelineRegs::TriangleTopology::Fan:
if (strip_ready)
triangle_handler(buffer[0], buffer[1], vtx);
buffer[buffer_index] = vtx;
2014-07-27 18:28:30 +05:30
strip_ready |= (buffer_index == 1);
if (topology == PipelineRegs::TriangleTopology::Strip)
buffer_index = !buffer_index;
else if (topology == PipelineRegs::TriangleTopology::Fan)
buffer_index = 1;
break;
2014-07-27 18:28:30 +05:30
default:
2018-06-29 16:48:07 +05:30
LOG_ERROR(HW_GPU, "Unknown triangle topology {:x}:", (int)topology);
break;
2014-07-27 18:28:30 +05:30
}
}
template <typename VertexType>
void PrimitiveAssembler<VertexType>::SetWinding() {
winding = true;
}
template <typename VertexType>
2016-03-03 08:46:38 +05:30
void PrimitiveAssembler<VertexType>::Reset() {
buffer_index = 0;
strip_ready = false;
winding = false;
2016-03-03 08:46:38 +05:30
}
template <typename VertexType>
void PrimitiveAssembler<VertexType>::Reconfigure(PipelineRegs::TriangleTopology topology) {
2016-03-03 08:46:38 +05:30
Reset();
this->topology = topology;
}
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;
}
// explicitly instantiate use cases
template struct PrimitiveAssembler<Shader::OutputVertex>;
2014-07-27 18:28:30 +05:30
} // namespace Pica