// Copyright 2017 The NXT Authors // // 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. #ifndef BACKEND_TOBACKEND_H_ #define BACKEND_TOBACKEND_H_ #include "backend/Forward.h" namespace backend { // ToBackendTraits implements the mapping from base type to member type of BackendTraits template struct ToBackendTraits; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BufferViewType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::CommandBufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::DepthStencilStateType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::DeviceType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::FramebufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::InputStateType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::PipelineType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::PipelineLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::QueueType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::RenderPassType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::SamplerType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ShaderModuleType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::TextureType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::TextureViewType; }; // ToBackendBase implements conversion to the given BackendTraits // To use it in a backend, use the following: // template // auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { // return ToBackendBase(common); // } template Ref::BackendType>& ToBackendBase(Ref& common) { return reinterpret_cast::BackendType>&>(common); } template const Ref::BackendType>& ToBackendBase(const Ref& common) { return reinterpret_cast::BackendType>&>(common); } template typename ToBackendTraits::BackendType* ToBackendBase(T* common) { return reinterpret_cast::BackendType*>(common); } template const typename ToBackendTraits::BackendType* ToBackendBase(const T* common) { return reinterpret_cast::BackendType*>(common); } } #endif // BACKEND_TOBACKEND_H_