primitive_assembly.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <functional>
  6. #include "video_core/pica.h"
  7. namespace Pica {
  8. /*
  9. * Utility class to build triangles from a series of vertices,
  10. * according to a given triangle topology.
  11. */
  12. template <typename VertexType>
  13. struct PrimitiveAssembler {
  14. using TriangleHandler =
  15. std::function<void(const VertexType& v0, const VertexType& v1, const VertexType& v2)>;
  16. PrimitiveAssembler(Regs::TriangleTopology topology = Regs::TriangleTopology::List);
  17. /*
  18. * Queues a vertex, builds primitives from the vertex queue according to the given
  19. * triangle topology, and calls triangle_handler for each generated primitive.
  20. * NOTE: We could specify the triangle handler in the constructor, but this way we can
  21. * keep event and handler code next to each other.
  22. */
  23. void SubmitVertex(const VertexType& vtx, TriangleHandler triangle_handler);
  24. /**
  25. * Resets the internal state of the PrimitiveAssembler.
  26. */
  27. void Reset();
  28. /**
  29. * Reconfigures the PrimitiveAssembler to use a different triangle topology.
  30. */
  31. void Reconfigure(Regs::TriangleTopology topology);
  32. private:
  33. Regs::TriangleTopology topology;
  34. int buffer_index;
  35. VertexType buffer[2];
  36. bool strip_ready = false;
  37. };
  38. } // namespace