Added helper functions, KRTexture::destroyHandles and KRTexture::destroyNewHandles
This commit is contained in:
@@ -53,27 +53,37 @@ KRTexture::~KRTexture()
|
|||||||
releaseHandles();
|
releaseHandles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRTexture::destroyHandles()
|
||||||
|
{
|
||||||
|
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
||||||
|
for (TextureHandle t : m_handles) {
|
||||||
|
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
||||||
|
VmaAllocator allocator = device->getAllocator();
|
||||||
|
vmaDestroyImage(allocator, t.image, t.allocation);
|
||||||
|
}
|
||||||
|
m_handles.clear();
|
||||||
|
m_textureMemUsed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRTexture::destroyNewHandles()
|
||||||
|
{
|
||||||
|
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
||||||
|
for (TextureHandle t : m_newHandles) {
|
||||||
|
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
||||||
|
VmaAllocator allocator = device->getAllocator();
|
||||||
|
vmaDestroyImage(allocator, t.image, t.allocation);
|
||||||
|
}
|
||||||
|
m_newHandles.clear();
|
||||||
|
m_newTextureMemUsed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void KRTexture::releaseHandles() {
|
void KRTexture::releaseHandles() {
|
||||||
long mem_size = getMemSize();
|
long mem_size = getMemSize();
|
||||||
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
|
||||||
|
|
||||||
while(m_handle_lock.test_and_set()); // Spin lock
|
while(m_handle_lock.test_and_set()); // Spin lock
|
||||||
|
|
||||||
for (TextureHandle t : m_newHandles) {
|
destroyNewHandles();
|
||||||
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
destroyHandles();
|
||||||
VmaAllocator allocator = device->getAllocator();
|
|
||||||
vmaDestroyImage(allocator, t.image, t.allocation);
|
|
||||||
}
|
|
||||||
m_newHandles.clear();
|
|
||||||
m_newTextureMemUsed = 0;
|
|
||||||
|
|
||||||
for (TextureHandle t : m_handles) {
|
|
||||||
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
|
||||||
VmaAllocator allocator = device->getAllocator();
|
|
||||||
vmaDestroyImage(allocator, t.image, t.allocation);
|
|
||||||
}
|
|
||||||
m_handles.clear();
|
|
||||||
m_textureMemUsed = 0;
|
|
||||||
|
|
||||||
m_current_lod_max_dim = 0;
|
m_current_lod_max_dim = 0;
|
||||||
m_new_lod_max_dim = 0;
|
m_new_lod_max_dim = 0;
|
||||||
@@ -225,17 +235,10 @@ void KRTexture::bind(GLuint texture_unit) {
|
|||||||
|
|
||||||
void KRTexture::_swapHandles()
|
void KRTexture::_swapHandles()
|
||||||
{
|
{
|
||||||
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
|
||||||
|
|
||||||
//while(m_handle_lock.test_and_set()); // Spin lock
|
//while(m_handle_lock.test_and_set()); // Spin lock
|
||||||
if(!m_handle_lock.test_and_set()) {
|
if(!m_handle_lock.test_and_set()) {
|
||||||
if(m_haveNewHandles) {
|
if(m_haveNewHandles) {
|
||||||
for (TextureHandle t : m_handles) {
|
destroyHandles();
|
||||||
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
|
||||||
VmaAllocator allocator = device->getAllocator();
|
|
||||||
vmaDestroyImage(allocator, t.image, t.allocation);
|
|
||||||
}
|
|
||||||
m_handles.clear();
|
|
||||||
m_handles.swap(m_newHandles);
|
m_handles.swap(m_newHandles);
|
||||||
m_textureMemUsed = (long)m_newTextureMemUsed;
|
m_textureMemUsed = (long)m_newTextureMemUsed;
|
||||||
m_newTextureMemUsed = 0;
|
m_newTextureMemUsed = 0;
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual bool createGPUTexture(int lod_max_dim) = 0;
|
virtual bool createGPUTexture(int lod_max_dim) = 0;
|
||||||
GLuint getHandle();
|
GLuint getHandle();
|
||||||
|
void destroyHandles();
|
||||||
|
void destroyNewHandles();
|
||||||
|
|
||||||
struct TextureHandle {
|
struct TextureHandle {
|
||||||
VkImage image;
|
VkImage image;
|
||||||
|
|||||||
Reference in New Issue
Block a user