// Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once

#include "Api.h"
#include "DrawBuffer.h"

#include <array>

OMNIUI_SCENE_NAMESPACE_OPEN_SCOPE

/**
 * @brief A simple array with BufferType::eCount elements. Every transform can
 * match to several types of bufferrs (Line and Point for example). We use this
 * object to track the index of each type.
 */
class DrawBufferIndex
{
public:
    DrawBufferIndex()
    {
        this->clear();
    }

    size_t& operator[](size_t i)
    {
        return m_index[i];
    }

    const size_t& operator[](size_t i) const
    {
        return m_index[i];
    }

    constexpr size_t size() const
    {
        return static_cast<size_t>(DrawBuffer::BufferType::eCount);
    }

    void clear()
    {
        // Default is SIZE_MAX which means "no buffer"
        std::fill(m_index.begin(), m_index.end(), SIZE_MAX);
    }

    bool empty() const
    {
        for (size_t i = 0, n = this->size(); i < n; ++i)
        {
            if ((*this)[i] != SIZE_MAX)
            {
                return false;
            }
        }

        return true;
    }

private:
    typedef std::array<size_t, static_cast<size_t>(DrawBuffer::BufferType::eCount)> _BufferIndexArray;
    _BufferIndexArray m_index;
};

OMNIUI_SCENE_NAMESPACE_CLOSE_SCOPE
