From ca40e7c7b6de98f2e229037875a47f10367d78b2 Mon Sep 17 00:00:00 2001 From: Sergey Kosarevsky Date: Sun, 23 Jul 2023 01:29:32 -0700 Subject: [PATCH] Added lvk::Span --- lvk/LVK.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lvk/LVK.h b/lvk/LVK.h index 63820ad133..58f4826816 100644 --- a/lvk/LVK.h +++ b/lvk/LVK.h @@ -514,6 +514,50 @@ enum ShaderStage : uint8_t { Stage_Comp, }; +template +class Span { + public: + Span() = default; + Span(T* data, size_t numElements) : data_(data), numElements_(numElements) {} + const T& operator[](size_t idx) const { + return data_[idx]; + }; + T& operator[](size_t idx) { + return data_[idx]; + }; + size_t size() const { + return numElements_; + } + size_t size_bytes() const { + return sizeof(T) * numElements_; + } + bool empty() const { + return numElements_ == 0; + } + T* data() { + return data_; + } + const T* data() const { + return data_; + } + T* begin() { + return data_; + } + const T* begin() const { + return data_; + } + T* end() { + return data_ + numElements_; + } + const T* end() const { + return data_ + numElements_; + } + + private: + T* data_ = nullptr; + size_t numElements_ = 0; +}; + struct VertexInput final { enum { LVK_VERTEX_ATTRIBUTES_MAX = 16 }; enum { LVK_VERTEX_BUFFER_MAX = 16 };