-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampler.cpp
More file actions
59 lines (45 loc) · 1.65 KB
/
Copy pathSampler.cpp
File metadata and controls
59 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "Sampler.h"
#include <new>
#include "Device.h"
#include "Internal/Error.h"
extern "C" {
GPU_API VkResult GPU_CALL gpuSamplerCreate(
GPUDevice device,
const VkSamplerCreateInfo* createInfo,
const VkAllocationCallbacks* allocator,
GPUSampler* sampler) {
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || sampler == nullptr) {
gpu::internal::setLastError("Device, create info, and sampler output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*sampler = nullptr;
VkSampler handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateSampler(device->handle, createInfo, allocator, &handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create sampler.");
return result;
}
GPUSampler wrapper = new (std::nothrow) GPUSampler_T{device, handle, allocator};
if (wrapper == nullptr) {
gpuDestroySampler(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate Sampler.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
*sampler = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuSamplerDestroy(GPUSampler sampler) {
if (sampler == nullptr) {
return;
}
gpuDestroySampler(sampler->device->handle, sampler->handle, sampler->allocator);
delete sampler;
}
GPU_API VkSampler GPU_CALL gpuSamplerGetVkHandle(GPUSampler sampler) {
return sampler != nullptr ? sampler->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuSamplerGetDevice(GPUSampler sampler) {
return sampler != nullptr ? sampler->device : nullptr;
}
} // extern "C"