libcruft-vk/object.cpp

94 lines
2.6 KiB
C++

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright:
* 2016-2017, Danny Robson <danny@nerdcruft.net>
*/
#include "./object.hpp"
#include "./instance.hpp"
#include "./physical_device.hpp"
#include <cruft/util/debug.hpp>
using cruft::vk::object;
using cruft::vk::enumerated;
///////////////////////////////////////////////////////////////////////////////
template <typename T>
object<T>::object (id_t _id):
m_id (_id)
{
CHECK_NEQ (m_id, VK_NULL_HANDLE);
}
//-----------------------------------------------------------------------------
template <typename T>
object<T>::object (object &&rhs):
m_id (VK_NULL_HANDLE)
{
std::swap (m_id, rhs.m_id);
}
//-----------------------------------------------------------------------------
template <typename T>
const typename object<T>::id_t&
object<T>::id (void) const&
{
return m_id;
}
//-----------------------------------------------------------------------------
template <typename T>
typename object<T>::id_t&
object<T>::id (void) &
{
return m_id;
}
//-----------------------------------------------------------------------------
#define OBJECT(T) template struct cruft::vk::object<cruft::vk::T>;
VK_TYPE_MAP (OBJECT)
///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATED(T) template struct cruft::vk::instantiated<cruft::vk::T>;
VK_INSTANTIATED_TYPE_MAP (INSTANTIATED)
///////////////////////////////////////////////////////////////////////////////
template <typename T>
std::vector<T>
cruft::vk::enumerated<T>::find (const instance &inst) {
uint32_t expected = 0;
error::try_code (enum_traits<T>::enumerate (inst.id (), &expected, nullptr));
uint32_t found = expected;
typename T::id_t handles[expected];
error::try_code (enum_traits<T>::enumerate (inst.id (), &found, handles));
return std::vector<T> (handles, handles + found);
}
//-----------------------------------------------------------------------------
#define ENUMERATED(T) template struct cruft::vk::enumerated<cruft::vk::T>;
VK_ENUMERATED_TYPE_MAP (ENUMERATED)