From 8679932d7385b9c178d8b74ee7bb89fe8ab9d937 Mon Sep 17 00:00:00 2001 From: Jaby Blubb Date: Sat, 27 May 2023 16:40:59 +0200 Subject: [PATCH] Introduce is_render_primitive type_trait --- .../GPU/Primitives/primitive_line_types.hpp | 2 +- .../GPU/Primitives/primitive_poly_types.hpp | 28 +++++++++++++------ .../Primitives/primitive_support_types.hpp | 11 ++++++-- include/PSX/GPU/gpu.hpp | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/PSX/GPU/Primitives/primitive_line_types.hpp b/include/PSX/GPU/Primitives/primitive_line_types.hpp index 3ceabe6b..9c002124 100644 --- a/include/PSX/GPU/Primitives/primitive_line_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_line_types.hpp @@ -42,7 +42,7 @@ namespace JabyEngine { }; } - struct LINE_F : public internal::IsPrimitive, public internal::LineCodeInterface { + struct LINE_F : public internal::LineCodeInterface { struct Head { static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent); diff --git a/include/PSX/GPU/Primitives/primitive_poly_types.hpp b/include/PSX/GPU/Primitives/primitive_poly_types.hpp index 59b0965d..5a51786e 100644 --- a/include/PSX/GPU/Primitives/primitive_poly_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_poly_types.hpp @@ -51,7 +51,7 @@ namespace JabyEngine { / \ 3 - 2 */ - struct POLY_F3 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_F3 : public internal::PolyCodeInterface { static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent); Color24 color; // a @@ -69,7 +69,7 @@ namespace JabyEngine { } }; - struct POLY_FT3 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_FT3 : public internal::PolyCodeInterface { struct VertexEx { Vertex position; PagePosition page; @@ -100,7 +100,7 @@ namespace JabyEngine { vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {} }; - struct POLY_G3 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_G3 : public internal::PolyCodeInterface { struct VertexEx { Vertex position; Color24 color; @@ -128,7 +128,7 @@ namespace JabyEngine { color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {} }; - struct POLY_GT3 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_GT3 : public internal::PolyCodeInterface { struct VertexEx { Vertex position; PagePosition page; @@ -168,7 +168,7 @@ namespace JabyEngine { | | 3 - 4 */ - struct POLY_F4 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_F4 : public internal::PolyCodeInterface { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics); Color24 color; // a @@ -193,7 +193,7 @@ namespace JabyEngine { color) {} }; - struct POLY_FT4 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_FT4 : public internal::PolyCodeInterface { typedef POLY_FT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics); @@ -233,7 +233,7 @@ namespace JabyEngine { ) {} }; - struct POLY_G4 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_G4 : public internal::PolyCodeInterface { typedef POLY_G3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics); @@ -270,7 +270,7 @@ namespace JabyEngine { ) {} }; - struct POLY_GT4 : public internal::IsPrimitive, public internal::PolyCodeInterface { + struct POLY_GT4 : public internal::PolyCodeInterface { typedef POLY_GT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics); @@ -325,6 +325,18 @@ namespace JabyEngine { typedef POLY_G4 GouraudRectangle; typedef POLY_GT4 GouraudTexturedRectangle; + namespace internal { + __jaby_engine_declare_render_primitive(POLY_F3); + __jaby_engine_declare_render_primitive(POLY_FT3); + __jaby_engine_declare_render_primitive(POLY_G3); + __jaby_engine_declare_render_primitive(POLY_GT3); + + __jaby_engine_declare_render_primitive(POLY_F4); + __jaby_engine_declare_render_primitive(POLY_FT4); + __jaby_engine_declare_render_primitive(POLY_G4); + __jaby_engine_declare_render_primitive(POLY_GT4); + } + static_assert(sizeof(POLY_F3) == 16); static_assert(sizeof(POLY_FT3) == 28); static_assert(sizeof(POLY_G3) == 24); diff --git a/include/PSX/GPU/Primitives/primitive_support_types.hpp b/include/PSX/GPU/Primitives/primitive_support_types.hpp index a12a5c7d..98e47810 100644 --- a/include/PSX/GPU/Primitives/primitive_support_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_support_types.hpp @@ -35,9 +35,16 @@ namespace JabyEngine { T primitive; }; - struct IsPrimitive { - static constexpr bool is_primitive = true; + template + struct is_render_primitive { + static constexpr bool value = false; }; + + #define __jaby_engine_declare_render_primitive(type) \ + template<> \ + struct is_render_primitive { \ + static constexpr bool value = true; \ + } } // Reexport for easier use diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index 75344e05..f11e449a 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -41,7 +41,7 @@ namespace JabyEngine { } template - static enable_if::type render(const T& primitive) { + static enable_if::value>::type render(const T& primitive) { internal::render(reinterpret_cast(&primitive), sizeof(T)/sizeof(uint32_t)); }