Commit 623cbb87 authored by Shu's avatar Shu 🍠
Browse files

World pass VK and GL Mipmap load

parent 15f5b090
......@@ -22,7 +22,7 @@ public:
void beginFrame() override;
std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> beginWorldPass() override;
std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> beginEntityPass() override;
size_t drawIndicatorCube(glm::mat4 model) override;
std::function<size_t(glm::mat4)> beginIndicatorPass() override;
void postProcess() override;
void endFrame() override;
void swapBuffer(Window &) override;
......
......@@ -153,11 +153,25 @@ void WritableBuffer::read(data_ref ref, size_t offset) {
memory->read(ref.ptr, ref.size, memOffset + offset);
}
static std::vector<std::vector<std::unique_ptr<ShortIndexedVertexBuffer>>> usedVertexBuffers;
ShortIndexedVertexBuffer::~ShortIndexedVertexBuffer() {
if (lastUseImage == UINT32_MAX) {
vkDestroyBuffer(Allocator::GetDefault()->getDevice(), vertex, ALLOC);
vkDestroyBuffer(Allocator::GetDefault()->getDevice(), index, ALLOC);
//NOTE: memory_ptr self destroy
} else {
if (lastUseImage >= usedVertexBuffers.size()) {
usedVertexBuffers.resize(lastUseImage+1);
}
usedVertexBuffers.at(lastUseImage).emplace_back(new ShortIndexedVertexBuffer(vertex, index, std::move(memory)));
}
}
void ShortIndexedVertexBuffer::ClearUnused(uint32_t image) {
if (image < usedVertexBuffers.size()) {
usedVertexBuffers.at(image).clear();
}
}
std::unique_ptr<ShortIndexedVertexBuffer> ShortIndexedVertexBuffer::Create(const data_view vertices, const data_view indices) {
std::vector<vk::Buffer::info> tmp;
auto mem = createBuffers({{vertices.size, Usage::VERTEX, vertices}, {indices.size, Usage::INDEX, indices}}, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, tmp);
......
......@@ -57,17 +57,21 @@ public:
static std::unique_ptr<ShortIndexedVertexBuffer> Create(const data_view vertices, const data_view indices);
~ShortIndexedVertexBuffer();
static void ClearUnused(uint32_t image);
VkBuffer getVertex() const { return vertex; }
VkBuffer getIndex() const { return index; }
void setLastUse(uint32_t image) { lastUseImage = image; }
explicit operator bool() const { return vertex && index; }
protected:
ShortIndexedVertexBuffer(VkBuffer vertex, VkBuffer index, memory::ptr mem):
vertex(vertex), index(index), memory(std::move(mem)) { }
vertex(vertex), index(index), memory(std::move(mem)), lastUseImage(UINT32_MAX) { }
VkBuffer vertex;
VkBuffer index;
memory::ptr memory;
uint32_t lastUseImage;
};
class BufferGroup {
......
......@@ -35,8 +35,6 @@ memory::ptr createImage(const Image::requirement& req, VkMemoryPropertyFlags pro
info.flags = 0;
if (req.cube) {
info.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
} else if (req.layers > 1) {
info.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT;
}
if (!datas.empty()) {
......@@ -142,7 +140,7 @@ VkSampler createSampler(const Texture::sampling& props, uint32_t mipmapLevels) {
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
samplerInfo.mipmapMode = props.minLinear ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST;
samplerInfo.mipLodBias = 0.0f; //TODO:
samplerInfo.mipLodBias = std::min(Allocator::GetDefault()->getCapabilities().maxLodBias, props.mipmapLod);
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = props.mipmap ? mipmapLevels : 0.0f;
......@@ -220,20 +218,20 @@ std::unique_ptr<TextureCube> TextureCube::LoadFromFiles(const std::string& prefi
return LoadFromFiles(paths, props);
}
std::unique_ptr<TextureArray> TextureArray::LoadFromFiles(const std::vector<std::string>& paths, const sampling& props) {
std::unique_ptr<TextureArray> TextureArray::LoadFromFiles(const std::vector<std::string>& paths, const sampling& props, bool srgb) {
std::vector<std::vector<unsigned char>> datas;
std::vector<data_view> views;
datas.resize(paths.size());
views.reserve(paths.size());
auto header = [&] {
if (auto header = render::Image::Read(paths.at(0), datas.at(0))) {
if (auto header = render::Image::Read(paths.at(0), datas.at(0), srgb)) {
views.push_back(datas.at(0));
return header.value();
}
FATAL("Cannot read first texture");
}();
for (size_t i = 1; i < paths.size(); i++) {
if(!render::Image::Read(paths.at(i), datas.at(i)).has_value()) {
if(!render::Image::Read(paths.at(i), datas.at(i), srgb).has_value()) {
FATAL("Cannot read depth texture");
}
views.push_back(datas.at(i));
......
......@@ -57,7 +57,7 @@ protected:
class TextureArray: public render::TextureArray, public Texture {
public:
static std::unique_ptr<TextureArray> LoadFromFiles(const std::vector<std::string>&, const sampling&);
static std::unique_ptr<TextureArray> LoadFromFiles(const std::vector<std::string>&, const sampling&, bool srgb = true);
protected:
TextureArray(uint32_t size, VkSampler sampler, VkImageView view, VkImageLayout layout, VkImage ref, memory::ptr memory):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment