libcruft-vk/object.cpp

97 lines
2.8 KiB
C++
Raw Normal View History

2016-02-26 13:39:01 +11:00
/*
* 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>
2016-02-26 13:39:01 +11:00
*/
2016-02-24 11:11:41 +11:00
#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>
2017-09-08 17:11:35 +10:00
object<T>::object (native_t _native):
m_native (_native)
{
2017-09-08 17:11:35 +10:00
CHECK_NEQ (m_native, VK_NULL_HANDLE);
}
//-----------------------------------------------------------------------------
template <typename T>
object<T>::object (object &&rhs):
2017-09-08 17:11:35 +10:00
m_native (VK_NULL_HANDLE)
{
2017-09-08 17:11:35 +10:00
std::swap (m_native, rhs.m_native);
}
//-----------------------------------------------------------------------------
template <typename T>
2017-09-08 17:11:35 +10:00
const typename object<T>::native_t&
object<T>::native (void) const&
{
2017-09-08 17:11:35 +10:00
return m_native;
}
//-----------------------------------------------------------------------------
template <typename T>
2017-09-08 17:11:35 +10:00
typename object<T>::native_t&
object<T>::native (void) &
{
2017-09-08 17:11:35 +10:00
return m_native;
}
//-----------------------------------------------------------------------------
#define OBJECT(T) template struct cruft::vk::object<cruft::vk::T>;
VK_TYPE_MAP (OBJECT)
///////////////////////////////////////////////////////////////////////////////
2017-09-05 17:20:17 +10:00
#define DESCENDANT(T) template struct cruft::vk::descendant<cruft::vk::T>;
VK_DESCENDANT_TYPE_MAP (DESCENDANT)
///////////////////////////////////////////////////////////////////////////////
template <typename T>
std::vector<T>
cruft::vk::enumerated<T>::find (const instance &parent) {
// find the total number of objects
uint32_t expected = 0;
2017-09-08 17:11:35 +10:00
error::try_code (enum_traits<T>::enumerate (parent.native (), &expected, nullptr));
// allocate an array of handles and fetch them
uint32_t found = expected;
2017-09-08 17:11:35 +10:00
typename T::native_t handles[expected];
error::try_code (enum_traits<T>::enumerate (parent.native (), &found, handles));
// return an collection of objects from the handles
return std::vector<T> (handles, handles + found);
}
//-----------------------------------------------------------------------------
#define ENUMERATED(T) template struct cruft::vk::enumerated<cruft::vk::T>;
VK_ENUMERATED_TYPE_MAP (ENUMERATED)