#pragma once #include "Drawable.h" #include "IndexBuffer.h" template class DrawableBase : public Drawable { public: bool IsStaticInitialized() const noexcept { return !staticBinds.empty(); } void AddStaticBind(std::unique_ptr bind) noexcept { assert("*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer)); staticBinds.push_back(std::move(bind)); } void AddStaticIndexBuffer(std::unique_ptr ibuf) noexcept { assert("Attempting to add index buffer a second time" && pIndexBuffer == nullptr); pIndexBuffer = ibuf.get(); staticBinds.push_back(std::move(ibuf)); } void SetIndexFromStatic() noexcept { assert("Attempting to add index buffer a second time" && pIndexBuffer == nullptr); for (const auto& b : staticBinds) { if (const auto p = dynamic_cast(b.get())) { pIndexBuffer = p; return; } } assert("Failed to find index buffer in static binds" && pIndexBuffer != nullptr); } private: const std::vector>& GetStaticBinds() const noexcept override { return staticBinds; } private: static std::vector> staticBinds; }; template std::vector> DrawableBase::staticBinds;