implement custom texture preload

This commit is contained in:
Khangaroo 2019-08-06 11:54:12 -04:00 committed by James Rowe
parent 657a129b60
commit 59b475a4b9
19 changed files with 139 additions and 126 deletions

View file

@ -84,6 +84,8 @@ add_library(common STATIC
swap.h
telemetry.cpp
telemetry.h
texture.cpp
texture.h
thread.cpp
thread.h
thread_queue_list.h

View file

@ -34,8 +34,7 @@ void DetachedTasks::AddTask(std::function<void()> task) {
std::unique_lock lock{instance->mutex};
--instance->count;
std::notify_all_at_thread_exit(instance->cv, std::move(lock));
})
.detach();
}).detach();
}
} // namespace Common

22
src/common/texture.cpp Normal file
View file

@ -0,0 +1,22 @@
#include <vector>
#include "common/assert.h"
#include "common/common_types.h"
namespace Common {
void FlipRGBA8Texture(std::vector<u8>& tex, u64 width, u64 height) {
ASSERT(tex.size() == width * height * 4);
const u64 line_size = width * 4;
u8* temp_row = new u8[line_size];
u32 offset_1;
u32 offset_2;
for (u64 line = 0; line < height / 2; line++) {
offset_1 = line * line_size;
offset_2 = (height - line - 1) * line_size;
// Swap lines
std::memcpy(temp_row, &tex[offset_1], line_size);
std::memcpy(&tex[offset_1], &tex[offset_2], line_size);
std::memcpy(&tex[offset_2], temp_row, line_size);
}
delete[] temp_row;
}
} // namespace Common

8
src/common/texture.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#include <vector>
#include "common/common_types.h"
namespace Common {
void FlipRGBA8Texture(std::vector<u8>& tex, u64 width, u64 height);
}