FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
handles.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLBASE_HANDLES_H
16 #define FPLBASE_HANDLES_H
17 
18 #include <cstdint>
19 
20 namespace fplbase {
21 namespace internal {
22 
23 // Internally-defined. Holds handle from OpenGL, Vulkan, etc.
24 struct OpaqueHandle {
25  uint64_t handle;
26  bool operator==(OpaqueHandle rhs) const { return handle == rhs.handle; }
27  bool operator!=(OpaqueHandle rhs) const { return !operator==(rhs); }
28 };
29 
30 } // namespace internal
31 
32 /// @brief Backend agnostic handles to various resources.
33 ///
34 /// These typedefs are capible of holding OpenGL and Vulkan equivalents.
35 /// We abstract the handles so that we can present a uniform interface,
36 /// regardless of which backend is used.
37 ///
38 /// This is also required for when we allow OpenGL or Vulkan to be selected
39 /// at runtime, instead of compile time.
46 
47 // The following functions are backend agnostic.
48 // Call from any code to get an invalid handle from the current backend.
49 TextureHandle InvalidTextureHandle();
50 TextureTarget InvalidTextureTarget();
51 ShaderHandle InvalidShaderHandle();
52 UniformHandle InvalidUniformHandle();
53 BufferHandle InvalidBufferHandle();
54 DeviceMemoryHandle InvalidDeviceMemoryHandle();
55 
56 // The following functions are backend agnostic.
57 // Call from any code to check the validity of a target.
58 bool ValidTextureHandle(TextureHandle handle);
59 bool ValidTextureTarget(TextureTarget target);
60 bool ValidShaderHandle(ShaderHandle handle);
61 bool ValidUniformHandle(UniformHandle handle);
62 bool ValidBufferHandle(BufferHandle handle);
63 bool ValidDeviceMemoryHandle(DeviceMemoryHandle handle);
64 
65 } // namespace fplbase
66 
67 #endif // FPLBASE_HANDLES_H
internal::OpaqueHandle TextureHandle
Backend agnostic handles to various resources.
Definition: handles.h:40
Definition: handles.h:24