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:
|
2017-05-26 16:30:48 +10:00
|
|
|
* 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"
|
2017-05-26 16:30:48 +10:00
|
|
|
|
2017-05-26 16:32:31 +10:00
|
|
|
#include "./instance.hpp"
|
|
|
|
|
|
|
|
#include "./physical_device.hpp"
|
|
|
|
|
|
|
|
#include <cruft/util/debug.hpp>
|
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
using cruft::vk::object;
|
|
|
|
using cruft::vk::enumerated;
|
2017-05-26 16:32:31 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-09-05 17:20:17 +10:00
|
|
|
#define DESCENDANT(T) template struct cruft::vk::descendant<cruft::vk::T>;
|
|
|
|
VK_DESCENDANT_TYPE_MAP (DESCENDANT)
|
2017-05-26 16:32:31 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T>
|
|
|
|
std::vector<T>
|
2017-09-06 13:46:52 +10:00
|
|
|
cruft::vk::enumerated<T>::find (const instance &parent) {
|
2017-09-01 13:12:11 +10:00
|
|
|
// find the total number of objects
|
2017-05-26 16:32:31 +10:00
|
|
|
uint32_t expected = 0;
|
2017-09-06 13:46:52 +10:00
|
|
|
error::try_code (enum_traits<T>::enumerate (parent.id (), &expected, nullptr));
|
2017-05-26 16:32:31 +10:00
|
|
|
|
2017-09-01 13:12:11 +10:00
|
|
|
// allocate an array of handles and fetch them
|
2017-05-26 16:32:31 +10:00
|
|
|
uint32_t found = expected;
|
|
|
|
typename T::id_t handles[expected];
|
2017-09-06 13:46:52 +10:00
|
|
|
error::try_code (enum_traits<T>::enumerate (parent.id (), &found, handles));
|
2017-05-26 16:32:31 +10:00
|
|
|
|
2017-09-01 13:12:11 +10:00
|
|
|
// return an collection of objects from the handles
|
2017-05-26 16:32:31 +10:00
|
|
|
return std::vector<T> (handles, handles + found);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#define ENUMERATED(T) template struct cruft::vk::enumerated<cruft::vk::T>;
|
|
|
|
VK_ENUMERATED_TYPE_MAP (ENUMERATED)
|