primitive_assembly.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = std::function<void(VertexType& v0,
  15. VertexType& v1,
  16. VertexType& v2)>;
  17. PrimitiveAssembler(Regs::TriangleTopology topology);
  18. /*
  19. * Queues a vertex, builds primitives from the vertex queue according to the given
  20. * triangle topology, and calls triangle_handler for each generated primitive.
  21. * NOTE: We could specify the triangle handler in the constructor, but this way we can
  22. * keep event and handler code next to each other.
  23. */
  24. void SubmitVertex(VertexType& vtx, TriangleHandler triangle_handler);
  25. /**
  26. * Resets the internal state of the PrimitiveAssembler.
  27. */
  28. void Reset();
  29. /**
  30. * Reconfigures the PrimitiveAssembler to use a different triangle topology.
  31. */
  32. void Reconfigure(Regs::TriangleTopology topology);
  33. private:
  34. Regs::TriangleTopology topology;
  35. int buffer_index;
  36. VertexType buffer[2];
  37. bool strip_ready = false;
  38. };
  39. } // namespace