Bindless VBO.
This commit is contained in:
parent
6c15f599aa
commit
93981bca4c
|
|
@ -19,10 +19,9 @@ Image::Destroy(const Device *device)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Texture::Init(const Device *device, const vk::Extent2D extent, const bool isMipmapped, const cstr name)
|
Texture::Init(const Device *device, const vk::Extent2D extent, vk::Format imageFormat, const bool isMipmapped,
|
||||||
|
const cstr name)
|
||||||
{
|
{
|
||||||
constexpr vk::Format imageFormat = vk::Format::eR8G8B8A8Srgb;
|
|
||||||
|
|
||||||
const u32 mipLevels = isMipmapped ? 1 + Cast<u32>(floor(log2(eastl::max(extent.width, extent.height)))) : 1;
|
const u32 mipLevels = isMipmapped ? 1 + Cast<u32>(floor(log2(eastl::max(extent.width, extent.height)))) : 1;
|
||||||
vk::ImageCreateInfo imageCreateInfo = {
|
vk::ImageCreateInfo imageCreateInfo = {
|
||||||
.imageType = vk::ImageType::e2D,
|
.imageType = vk::ImageType::e2D,
|
||||||
|
|
@ -76,7 +75,7 @@ Texture::Init(const Device *device, const vk::Extent2D extent, const bool isMipm
|
||||||
void
|
void
|
||||||
DepthImage::Init(const Device *device, vk::Extent2D extent, cstr name)
|
DepthImage::Init(const Device *device, vk::Extent2D extent, cstr name)
|
||||||
{
|
{
|
||||||
constexpr vk::Format imageFormat = vk::Format::eD32Sfloat;
|
constexpr vk::Format imageFormat = vk::Format::eD24UnormS8Uint;
|
||||||
vk::ImageCreateInfo imageCreateInfo = {
|
vk::ImageCreateInfo imageCreateInfo = {
|
||||||
.imageType = vk::ImageType::e2D,
|
.imageType = vk::ImageType::e2D,
|
||||||
.format = imageFormat,
|
.format = imageFormat,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ struct Image
|
||||||
|
|
||||||
struct Texture : Image
|
struct Texture : Image
|
||||||
{
|
{
|
||||||
void Init(const Device *device, vk::Extent2D extent, bool isMipmapped, cstr name = nullptr);
|
void Init(const Device *device, vk::Extent2D extent, vk::Format imageFormat, bool isMipmapped, cstr name = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DepthImage : Image
|
struct DepthImage : Image
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ Frame::Present(const vk::Queue commandQueue, Swapchain *swapchain, const Window
|
||||||
break;
|
break;
|
||||||
case vk::Result::eErrorOutOfDateKHR:
|
case vk::Result::eErrorOutOfDateKHR:
|
||||||
case vk::Result::eSuboptimalKHR:
|
case vk::Result::eSuboptimalKHR:
|
||||||
INFO("Recreating Swapchain. Cause: {}", result);
|
DEBUG("Recreating Swapchain. Cause: {}", result);
|
||||||
swapchain->Create(window);
|
swapchain->Create(window);
|
||||||
break; // Present failed. We do nothing. Frame is skipped.
|
break; // Present failed. We do nothing. Frame is skipped.
|
||||||
default:
|
default:
|
||||||
|
|
@ -116,7 +116,7 @@ FrameManager::GetNextFrame(Swapchain *swapchain, const Window *window)
|
||||||
imageAcquired = true;
|
imageAcquired = true;
|
||||||
break; // Image acquired. Break out of loop.
|
break; // Image acquired. Break out of loop.
|
||||||
case vk::Result::eErrorOutOfDateKHR:
|
case vk::Result::eErrorOutOfDateKHR:
|
||||||
INFO("Recreating Swapchain. Cause: {}", result);
|
DEBUG("Recreating Swapchain. Cause: {}", result);
|
||||||
swapchain->Create(window);
|
swapchain->Create(window);
|
||||||
break; // Image acquire has failed. We move to the next frame.
|
break; // Image acquire has failed. We move to the next frame.
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ Pipeline CreatePipeline(const Device *device, const Swapchain *swapchain);
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
vec3 m_Position;
|
vec3 m_Position;
|
||||||
vec2 m_UV0;
|
vec2 m_TexCoord0;
|
||||||
|
|
||||||
constexpr static vk::VertexInputBindingDescription
|
constexpr static vk::VertexInputBindingDescription
|
||||||
GetBinding(const u32 binding)
|
GetBinding(const u32 binding)
|
||||||
|
|
@ -97,7 +97,7 @@ struct Vertex
|
||||||
.location = 1,
|
.location = 1,
|
||||||
.binding = binding,
|
.binding = binding,
|
||||||
.format = vk::Format::eR32G32Sfloat,
|
.format = vk::Format::eR32G32Sfloat,
|
||||||
.offset = offsetof(Vertex, m_UV0),
|
.offset = offsetof(Vertex, m_TexCoord0),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -185,47 +185,47 @@ main(int, char **)
|
||||||
}
|
}
|
||||||
|
|
||||||
eastl::array vertices = {
|
eastl::array vertices = {
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageFile imageFile;
|
ImageFile imageFile;
|
||||||
|
|
@ -236,7 +236,7 @@ main(int, char **)
|
||||||
VertexBuffer vbo;
|
VertexBuffer vbo;
|
||||||
Texture crate;
|
Texture crate;
|
||||||
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
|
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
|
||||||
crate.Init(&device, {imageFile.m_Width, imageFile.m_Height}, false, "Crate Texture");
|
crate.Init(&device, {imageFile.m_Width, imageFile.m_Height}, vk::Format::eR8G8B8A8Srgb, false, "Crate Texture");
|
||||||
{
|
{
|
||||||
StagingBuffer vertexStaging, imageStaging;
|
StagingBuffer vertexStaging, imageStaging;
|
||||||
vertexStaging.Init(&device, vertices.size() * sizeof vertices[0], "Vertex Staging");
|
vertexStaging.Init(&device, vertices.size() * sizeof vertices[0], "Vertex Staging");
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ add_executable(model_render model_render.cpp
|
||||||
pipeline_utils.cpp
|
pipeline_utils.cpp
|
||||||
pipeline_utils.h
|
pipeline_utils.h
|
||||||
render_resource_manager.cpp
|
render_resource_manager.cpp
|
||||||
render_resource_manager.h)
|
render_resource_manager.h
|
||||||
|
model_loader.cpp
|
||||||
|
model_loader.h)
|
||||||
add_shader(model_render shader/model.vert.glsl)
|
add_shader(model_render shader/model.vert.glsl)
|
||||||
add_shader(model_render shader/model.frag.glsl)
|
add_shader(model_render shader/model.frag.glsl)
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,44 @@
|
||||||
|
// =============================================
|
||||||
|
// Aster: model_loader.cpp
|
||||||
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
#define TINYGLTF_NOEXCEPTION
|
||||||
|
#define JSON_NOEXCEPTION
|
||||||
|
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
#include "model_loader.h"
|
||||||
|
|
||||||
|
Model
|
||||||
|
LoadModel(RenderResourceManager *resourceManager, cstr path)
|
||||||
|
{
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
tinygltf::Model model;
|
||||||
|
tinygltf::TinyGLTF loader;
|
||||||
|
|
||||||
|
const auto fsPath = fs::absolute(path);
|
||||||
|
const auto ext = fsPath.extension();
|
||||||
|
if (ext.c_str() == GLTF_ASCII_FILE_EXTENSION)
|
||||||
|
{
|
||||||
|
std::string err;
|
||||||
|
std::string warn;
|
||||||
|
if (loader.LoadASCIIFromFile(&model, &err, &warn, fsPath.generic_string()))
|
||||||
|
{
|
||||||
|
ERROR_IF(!err.empty(), "{}", err)
|
||||||
|
ELSE_IF_WARN(!warn.empty(), "{}", warn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ext.c_str() == GLTF_BINARY_FILE_EXTENSION)
|
||||||
|
{
|
||||||
|
std::string err;
|
||||||
|
std::string warn;
|
||||||
|
if (loader.LoadBinaryFromFile(&model, &err, &warn, fsPath.generic_string()))
|
||||||
|
{
|
||||||
|
ERROR_IF(!err.empty(), "{}", err)
|
||||||
|
ELSE_IF_WARN(!warn.empty(), "{}", warn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
// =============================================
|
||||||
|
// Aster: model_loader.h
|
||||||
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
#include <EASTL/vector.h>
|
||||||
|
#include <tiny_gltf.h>
|
||||||
|
|
||||||
|
struct RenderResourceManager;
|
||||||
|
struct Texture;
|
||||||
|
constexpr auto GLTF_ASCII_FILE_EXTENSION = ".gltf";
|
||||||
|
constexpr auto GLTF_BINARY_FILE_EXTENSION = ".glb";
|
||||||
|
|
||||||
|
constexpr static auto NORMAL = "NORMAL";
|
||||||
|
constexpr static auto POSITION = "POSITION";
|
||||||
|
constexpr static auto TANGENT = "TANGENT";
|
||||||
|
constexpr static auto TEXCOORD_0 = "TEXCOORD_0";
|
||||||
|
constexpr static auto TEXCOORD_1 = "TEXCOORD_1";
|
||||||
|
constexpr static auto JOINTS_0 = "JOINTS_0";
|
||||||
|
constexpr static auto WEIGHTS_0 = "WEIGHTS_0";
|
||||||
|
|
||||||
|
struct Model
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
Model LoadModel(RenderResourceManager *resourceManager, cstr path);
|
||||||
|
|
@ -3,13 +3,6 @@
|
||||||
// Copyright (c) 2020-2024 Anish Bhobe
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
#define TINYGLTF_NOEXCEPTION
|
|
||||||
#define JSON_NOEXCEPTION
|
|
||||||
|
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
@ -24,10 +17,12 @@
|
||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
#include "model_loader.h"
|
||||||
#include "pipeline_utils.h"
|
#include "pipeline_utils.h"
|
||||||
#include "render_resource_manager.h"
|
#include "render_resource_manager.h"
|
||||||
|
|
||||||
#include <EASTL/array.h>
|
#include <EASTL/array.h>
|
||||||
|
#include <stb_image.h>
|
||||||
#include <tiny_gltf.h>
|
#include <tiny_gltf.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
|
@ -55,47 +50,13 @@ struct Camera
|
||||||
mat4 m_Perspective;
|
mat4 m_Perspective;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto GLTF_ASCII_FILE_EXTENSION = ".gltf";
|
|
||||||
constexpr auto GLTF_BINARY_FILE_EXTENSION = ".glb";
|
|
||||||
|
|
||||||
void
|
|
||||||
LoadModel(cstr path)
|
|
||||||
{
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
tinygltf::Model model;
|
|
||||||
tinygltf::TinyGLTF loader;
|
|
||||||
|
|
||||||
const auto fsPath = fs::absolute(path);
|
|
||||||
const auto ext = fsPath.extension();
|
|
||||||
if (ext.c_str() == GLTF_ASCII_FILE_EXTENSION)
|
|
||||||
{
|
|
||||||
std::string err;
|
|
||||||
std::string warn;
|
|
||||||
if (loader.LoadASCIIFromFile(&model, &err, &warn, fsPath.generic_string()))
|
|
||||||
{
|
|
||||||
ERROR_IF(!err.empty(), "{}", err)
|
|
||||||
ELSE_IF_WARN(!warn.empty(), "{}", warn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ext.c_str() == GLTF_BINARY_FILE_EXTENSION)
|
|
||||||
{
|
|
||||||
std::string err;
|
|
||||||
std::string warn;
|
|
||||||
if (loader.LoadBinaryFromFile(&model, &err, &warn, fsPath.generic_string()))
|
|
||||||
{
|
|
||||||
ERROR_IF(!err.empty(), "{}", err)
|
|
||||||
ELSE_IF_WARN(!warn.empty(), "{}", warn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int, char **)
|
main(int, char **)
|
||||||
{
|
{
|
||||||
MIN_LOG_LEVEL(Logger::LogType::eInfo);
|
MIN_LOG_LEVEL(Logger::LogType::eInfo);
|
||||||
|
|
||||||
Context context = {"Box", VERSION};
|
Context context = {"ModelRender [WIP]", VERSION};
|
||||||
Window window = {"Box (Aster)", &context, {640, 480}};
|
Window window = {"ModelRender [WIP] (Aster)", &context, {640, 480}};
|
||||||
|
|
||||||
PhysicalDevices physicalDevices = {&window, &context};
|
PhysicalDevices physicalDevices = {&window, &context};
|
||||||
PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices);
|
PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices);
|
||||||
|
|
@ -182,47 +143,47 @@ main(int, char **)
|
||||||
}
|
}
|
||||||
|
|
||||||
eastl::array vertices = {
|
eastl::array vertices = {
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, -0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
|
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_UV0 = vec2(1.0f, 0.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(1.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_UV0 = vec2(0.0f, 0.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, -0.5f), .m_TexCoord0 = vec2(0.0f, 0.0f)},
|
||||||
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_UV0 = vec2(0.0f, 1.0f)},
|
Vertex{.m_Position = vec3(-0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(0.0f, 1.0f)},
|
||||||
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_UV0 = vec2(1.0f, 1.0f)},
|
Vertex{.m_Position = vec3(0.5f, 0.5f, 0.5f), .m_TexCoord0 = vec2(1.0f, 1.0f)},
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageFile crateImageFile;
|
ImageFile crateImageFile;
|
||||||
|
|
@ -231,20 +192,22 @@ main(int, char **)
|
||||||
INFO("Image {}x{} : {} channels", crateImageFile.m_Width, crateImageFile.m_Height, crateImageFile.m_NumChannels);
|
INFO("Image {}x{} : {} channels", crateImageFile.m_Width, crateImageFile.m_Height, crateImageFile.m_NumChannels);
|
||||||
assert(plainImageFile.Load({0.7f, 0.4f, 0.1f, 1.0f}));
|
assert(plainImageFile.Load({0.7f, 0.4f, 0.1f, 1.0f}));
|
||||||
|
|
||||||
VertexBuffer vbo;
|
UniformStorageBuffer pvbo;
|
||||||
Texture crateTexture;
|
Texture crateTexture;
|
||||||
Texture plainTexture;
|
Texture plainTexture;
|
||||||
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
|
crateTexture.Init(&device, {crateImageFile.m_Width, crateImageFile.m_Height}, vk::Format::eR8G8B8A8Srgb, false,
|
||||||
crateTexture.Init(&device, {crateImageFile.m_Width, crateImageFile.m_Height}, false, "Crate Texture");
|
"Crate Texture");
|
||||||
plainTexture.Init(&device, {crateImageFile.m_Width, crateImageFile.m_Height}, false, "Plain Texture");
|
plainTexture.Init(&device, {crateImageFile.m_Width, crateImageFile.m_Height}, vk::Format::eR8G8B8A8Srgb, false,
|
||||||
|
"Plain Texture");
|
||||||
|
pvbo.Init(&device, vertices.size() * sizeof vertices[0], "Pull VBO");
|
||||||
|
pvbo.Write(&device, 0, pvbo.GetSize(), vertices.data());
|
||||||
|
|
||||||
auto crateTextureId = resourceManager.Commit(&crateTexture);
|
auto crateTextureId = resourceManager.Commit(&crateTexture);
|
||||||
auto plainTextureId = resourceManager.Commit(&plainTexture);
|
auto plainTextureId = resourceManager.Commit(&plainTexture);
|
||||||
|
auto pvboBufferId = resourceManager.Commit(&pvbo);
|
||||||
|
|
||||||
{
|
{
|
||||||
StagingBuffer vertexStaging, imageStaging1, imageStaging2;
|
StagingBuffer imageStaging1, imageStaging2;
|
||||||
vertexStaging.Init(&device, vertices.size() * sizeof vertices[0], "Vertex Staging");
|
|
||||||
vertexStaging.Write(&device, 0, vertices.size() * sizeof vertices[0], vertices.data());
|
|
||||||
|
|
||||||
imageStaging1.Init(&device, crateImageFile.GetSize(), "Image Staging 1");
|
imageStaging1.Init(&device, crateImageFile.GetSize(), "Image Staging 1");
|
||||||
imageStaging1.Write(&device, 0, crateImageFile.GetSize(), crateImageFile.m_Data);
|
imageStaging1.Write(&device, 0, crateImageFile.GetSize(), crateImageFile.m_Data);
|
||||||
|
|
@ -327,9 +290,6 @@ main(int, char **)
|
||||||
copyBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eTransfer, {}, 0,
|
copyBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eTransfer, {}, 0,
|
||||||
nullptr, 0, nullptr, Cast<u32>(imageReadyToWrite.size()), imageReadyToWrite.data());
|
nullptr, 0, nullptr, Cast<u32>(imageReadyToWrite.size()), imageReadyToWrite.data());
|
||||||
|
|
||||||
vk::BufferCopy bufferCopy = {.srcOffset = 0, .dstOffset = 0, .size = vertexStaging.GetSize()};
|
|
||||||
copyBuffer.copyBuffer(vertexStaging.m_Buffer, vbo.m_Buffer, 1, &bufferCopy);
|
|
||||||
|
|
||||||
vk::BufferImageCopy imageCopy = {
|
vk::BufferImageCopy imageCopy = {
|
||||||
.bufferOffset = 0,
|
.bufferOffset = 0,
|
||||||
.bufferRowLength = crateImageFile.m_Width,
|
.bufferRowLength = crateImageFile.m_Width,
|
||||||
|
|
@ -368,7 +328,6 @@ main(int, char **)
|
||||||
AbortIfFailedM(device.m_Device.resetCommandPool(copyPool, {}), "Couldn't reset command pool.");
|
AbortIfFailedM(device.m_Device.resetCommandPool(copyPool, {}), "Couldn't reset command pool.");
|
||||||
|
|
||||||
device.m_Device.destroy(fence, nullptr);
|
device.m_Device.destroy(fence, nullptr);
|
||||||
vertexStaging.Destroy(&device);
|
|
||||||
imageStaging1.Destroy(&device);
|
imageStaging1.Destroy(&device);
|
||||||
imageStaging2.Destroy(&device);
|
imageStaging2.Destroy(&device);
|
||||||
}
|
}
|
||||||
|
|
@ -442,52 +401,22 @@ main(int, char **)
|
||||||
|
|
||||||
FrameManager frameManager = {&device, queueAllocation.m_Family, MAX_FRAMES_IN_FLIGHT};
|
FrameManager frameManager = {&device, queueAllocation.m_Family, MAX_FRAMES_IN_FLIGHT};
|
||||||
eastl::fixed_vector<DepthImage, MAX_FRAMES_IN_FLIGHT> depthImages(frameManager.m_FramesInFlight);
|
eastl::fixed_vector<DepthImage, MAX_FRAMES_IN_FLIGHT> depthImages(frameManager.m_FramesInFlight);
|
||||||
eastl::fixed_vector<vk::ImageView, MAX_FRAMES_IN_FLIGHT> depthViews(frameManager.m_FramesInFlight);
|
|
||||||
|
|
||||||
vk::ImageSubresourceRange depthSubresourceRange = {
|
|
||||||
.aspectMask = vk::ImageAspectFlagBits::eDepth,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 index = 0;
|
|
||||||
for (auto &depthImage : depthImages)
|
|
||||||
{
|
{
|
||||||
auto name = fmt::format("Depth image {}", index);
|
u32 depthImageIdx = 0;
|
||||||
depthImage.Init(&device, swapchain.m_Extent, name.c_str());
|
|
||||||
vk::ImageViewCreateInfo imageViewCreateInfo = {
|
|
||||||
.image = depthImage.m_Image,
|
|
||||||
.viewType = vk::ImageViewType::e2D,
|
|
||||||
.format = vk::Format::eD32Sfloat,
|
|
||||||
.components = vk::ComponentMapping{.r = vk::ComponentSwizzle::eIdentity},
|
|
||||||
.subresourceRange = depthSubresourceRange,
|
|
||||||
};
|
|
||||||
AbortIfFailed(device.m_Device.createImageView(&imageViewCreateInfo, nullptr, &depthViews[index]));
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto fnRecreateDepthBuffers = [&device, &depthImages, &depthViews, depthSubresourceRange](vk::Extent2D extent) {
|
|
||||||
for (const auto &depthView : depthViews)
|
|
||||||
{
|
|
||||||
device.m_Device.destroy(depthView, nullptr);
|
|
||||||
}
|
|
||||||
u32 index = 0;
|
|
||||||
for (auto &depthImage : depthImages)
|
for (auto &depthImage : depthImages)
|
||||||
{
|
{
|
||||||
|
auto name = fmt::format("Depth {}", depthImageIdx++);
|
||||||
|
depthImage.Init(&device, swapchain.m_Extent, name.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fnRecreateDepthBuffers = [&device, &depthImages](vk::Extent2D extent) {
|
||||||
|
u32 depthImageIdx = 0;
|
||||||
|
for (auto &depthImage : depthImages)
|
||||||
|
{
|
||||||
|
auto name = fmt::format("Depth {}", depthImageIdx++);
|
||||||
depthImage.Destroy(&device);
|
depthImage.Destroy(&device);
|
||||||
depthImage.Init(&device, extent, "Depth");
|
depthImage.Init(&device, extent, name.c_str());
|
||||||
vk::ImageViewCreateInfo imageViewCreateInfo = {
|
|
||||||
.image = depthImage.m_Image,
|
|
||||||
.viewType = vk::ImageViewType::e2D,
|
|
||||||
.format = vk::Format::eD32Sfloat,
|
|
||||||
.components = vk::ComponentMapping{.r = vk::ComponentSwizzle::eIdentity},
|
|
||||||
.subresourceRange = depthSubresourceRange,
|
|
||||||
};
|
|
||||||
AbortIfFailed(device.m_Device.createImageView(&imageViewCreateInfo, nullptr, &depthViews[index]));
|
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
swapchain.RegisterResizeCallback(fnRecreateDepthBuffers);
|
swapchain.RegisterResizeCallback(fnRecreateDepthBuffers);
|
||||||
|
|
@ -499,8 +428,8 @@ main(int, char **)
|
||||||
|
|
||||||
bool prevPressed = false;
|
bool prevPressed = false;
|
||||||
auto isSpaceJustPressed = [&prevPressed, &window] {
|
auto isSpaceJustPressed = [&prevPressed, &window] {
|
||||||
bool pressed = glfwGetKey(window.m_Window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
const bool pressed = glfwGetKey(window.m_Window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
||||||
bool justPressed = pressed & !prevPressed;
|
const bool justPressed = pressed & !prevPressed;
|
||||||
prevPressed = pressed;
|
prevPressed = pressed;
|
||||||
return justPressed;
|
return justPressed;
|
||||||
};
|
};
|
||||||
|
|
@ -524,7 +453,7 @@ main(int, char **)
|
||||||
vk::ImageView currentImageView = swapchain.m_ImageViews[imageIndex];
|
vk::ImageView currentImageView = swapchain.m_ImageViews[imageIndex];
|
||||||
vk::Image currentImage = swapchain.m_Images[imageIndex];
|
vk::Image currentImage = swapchain.m_Images[imageIndex];
|
||||||
vk::CommandBuffer cmd = currentFrame->m_CommandBuffer;
|
vk::CommandBuffer cmd = currentFrame->m_CommandBuffer;
|
||||||
vk::ImageView currentDepthImageView = depthViews[currentFrame->m_FrameIdx];
|
vk::ImageView currentDepthImageView = depthImages[currentFrame->m_FrameIdx].m_View;
|
||||||
|
|
||||||
topOfThePipeBarrier.image = currentImage;
|
topOfThePipeBarrier.image = currentImage;
|
||||||
renderToPresentBarrier.image = currentImage;
|
renderToPresentBarrier.image = currentImage;
|
||||||
|
|
@ -570,11 +499,11 @@ main(int, char **)
|
||||||
cmd.setScissor(0, 1, &scissor);
|
cmd.setScissor(0, 1, &scissor);
|
||||||
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
||||||
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, 0, sizeof *pushData, pushData);
|
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, 0, sizeof *pushData, pushData);
|
||||||
|
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, sizeof *pushData, sizeof pvboBufferId,
|
||||||
|
&pvboBufferId);
|
||||||
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1,
|
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1,
|
||||||
&resourceManager.m_DescriptorSet, 0, nullptr);
|
&resourceManager.m_DescriptorSet, 0, nullptr);
|
||||||
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 1, 1, &descriptorSet, 0, nullptr);
|
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 1, 1, &descriptorSet, 0, nullptr);
|
||||||
usize offsets = 0;
|
|
||||||
cmd.bindVertexBuffers(0, 1, &vbo.m_Buffer, &offsets);
|
|
||||||
cmd.draw(Cast<u32>(vertices.size()), 1, 0, 0);
|
cmd.draw(Cast<u32>(vertices.size()), 1, 0, 0);
|
||||||
|
|
||||||
cmd.endRendering();
|
cmd.endRendering();
|
||||||
|
|
@ -601,10 +530,6 @@ main(int, char **)
|
||||||
|
|
||||||
AbortIfFailed(device.m_Device.waitIdle());
|
AbortIfFailed(device.m_Device.waitIdle());
|
||||||
|
|
||||||
for (auto &depthView : depthViews)
|
|
||||||
{
|
|
||||||
device.m_Device.destroy(depthView, nullptr);
|
|
||||||
}
|
|
||||||
for (auto &depthImage : depthImages)
|
for (auto &depthImage : depthImages)
|
||||||
{
|
{
|
||||||
depthImage.Destroy(&device);
|
depthImage.Destroy(&device);
|
||||||
|
|
@ -614,7 +539,7 @@ main(int, char **)
|
||||||
device.m_Device.destroy(copyPool, nullptr);
|
device.m_Device.destroy(copyPool, nullptr);
|
||||||
crateTexture.Destroy(&device);
|
crateTexture.Destroy(&device);
|
||||||
plainTexture.Destroy(&device);
|
plainTexture.Destroy(&device);
|
||||||
vbo.Destroy(&device);
|
pvbo.Destroy(&device);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -625,8 +550,8 @@ ImageFile::Load(vec4 color)
|
||||||
constexpr usize size = 512llu * 512llu * 4llu;
|
constexpr usize size = 512llu * 512llu * 4llu;
|
||||||
u8 *pData = new u8[size];
|
u8 *pData = new u8[size];
|
||||||
|
|
||||||
vec4 color255 = 255.999f * color;
|
const vec4 color255 = 255.999f * color;
|
||||||
glm::vec<4, u8> color8 = color255;
|
const glm::vec<4, u8> color8 = color255;
|
||||||
|
|
||||||
for (usize i = 0; i < size; i += 4)
|
for (usize i = 0; i < size; i += 4)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -73,15 +73,7 @@ CreatePipeline(const Device *device, const Swapchain *swapchain, const RenderRes
|
||||||
|
|
||||||
descriptorSetLayouts[0] = nullptr; // Not owned.
|
descriptorSetLayouts[0] = nullptr; // Not owned.
|
||||||
|
|
||||||
vk::VertexInputBindingDescription inputBindingDescription = Vertex::GetBinding(0);
|
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = {};
|
||||||
auto inputAttributeDescription = Vertex::GetAttributes(0);
|
|
||||||
|
|
||||||
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = {
|
|
||||||
.vertexBindingDescriptionCount = 1,
|
|
||||||
.pVertexBindingDescriptions = &inputBindingDescription,
|
|
||||||
.vertexAttributeDescriptionCount = Cast<u32>(inputAttributeDescription.size()),
|
|
||||||
.pVertexAttributeDescriptions = inputAttributeDescription.data(),
|
|
||||||
};
|
|
||||||
vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = {
|
vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = {
|
||||||
.topology = vk::PrimitiveTopology::eTriangleList,
|
.topology = vk::PrimitiveTopology::eTriangleList,
|
||||||
.primitiveRestartEnable = false,
|
.primitiveRestartEnable = false,
|
||||||
|
|
@ -141,7 +133,7 @@ CreatePipeline(const Device *device, const Swapchain *swapchain, const RenderRes
|
||||||
.viewMask = 0,
|
.viewMask = 0,
|
||||||
.colorAttachmentCount = 1,
|
.colorAttachmentCount = 1,
|
||||||
.pColorAttachmentFormats = &swapchain->m_Format,
|
.pColorAttachmentFormats = &swapchain->m_Format,
|
||||||
.depthAttachmentFormat = vk::Format::eD32Sfloat,
|
.depthAttachmentFormat = vk::Format::eD24UnormS8Uint,
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
|
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
|
||||||
|
|
|
||||||
|
|
@ -19,32 +19,7 @@ constexpr auto FRAGMENT_SHADER_FILE = "shader/model.frag.glsl.spv";
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
vec3 m_Position;
|
vec3 m_Position;
|
||||||
vec2 m_UV0;
|
vec2 m_TexCoord0;
|
||||||
|
|
||||||
constexpr static vk::VertexInputBindingDescription
|
|
||||||
GetBinding(const u32 binding)
|
|
||||||
{
|
|
||||||
return {.binding = binding, .stride = sizeof(Vertex), .inputRate = vk::VertexInputRate::eVertex};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr static eastl::array<vk::VertexInputAttributeDescription, 2>
|
|
||||||
GetAttributes(const u32 binding)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
vk::VertexInputAttributeDescription{
|
|
||||||
.location = 0,
|
|
||||||
.binding = binding,
|
|
||||||
.format = vk::Format::eR32G32B32Sfloat,
|
|
||||||
.offset = offsetof(Vertex, m_Position),
|
|
||||||
},
|
|
||||||
vk::VertexInputAttributeDescription{
|
|
||||||
.location = 1,
|
|
||||||
.binding = binding,
|
|
||||||
.format = vk::Format::eR32G32Sfloat,
|
|
||||||
.offset = offsetof(Vertex, m_UV0),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
|
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,18 @@ RenderResourceManager::Commit(const UniformStorageBuffer *storageBuffer)
|
||||||
return {handle};
|
return {handle};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RenderResourceManager::Release(BufferHandle handle)
|
||||||
|
{
|
||||||
|
m_BufferFreeList.Free(handle.m_Index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RenderResourceManager::Release(TextureHandle handle)
|
||||||
|
{
|
||||||
|
m_TextureFreeList.Free(handle.m_Index);
|
||||||
|
}
|
||||||
|
|
||||||
TextureHandle
|
TextureHandle
|
||||||
RenderResourceManager::Commit(const Texture *texture)
|
RenderResourceManager::Commit(const Texture *texture)
|
||||||
{
|
{
|
||||||
|
|
@ -76,12 +88,10 @@ RenderResourceManager::Commit(const Texture *texture)
|
||||||
void
|
void
|
||||||
RenderResourceManager::Update()
|
RenderResourceManager::Update()
|
||||||
{
|
{
|
||||||
usize count = Cast<usize>(m_Writes.size());
|
if (m_Writes.empty())
|
||||||
vk::WriteDescriptorSet *pData = m_Writes.data();
|
return;
|
||||||
if (count > 0)
|
|
||||||
{
|
m_Device->m_Device.updateDescriptorSets(m_Writes.size(), m_Writes.data(), 0, nullptr);
|
||||||
m_Device->m_Device.updateDescriptorSets(count, pData, 0, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Writes.clear();
|
m_Writes.clear();
|
||||||
m_WriteInfos.clear();
|
m_WriteInfos.clear();
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,9 @@ struct RenderResourceManager
|
||||||
vk::DescriptorSet m_DescriptorSet;
|
vk::DescriptorSet m_DescriptorSet;
|
||||||
|
|
||||||
BufferHandle Commit(const UniformStorageBuffer *storageBuffer);
|
BufferHandle Commit(const UniformStorageBuffer *storageBuffer);
|
||||||
|
void Release(BufferHandle handle);
|
||||||
TextureHandle Commit(const Texture *texture);
|
TextureHandle Commit(const Texture *texture);
|
||||||
|
void Release(TextureHandle handle);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ layout (location = 0) out vec4 outColor;
|
||||||
layout(set = 0, binding = 1) uniform sampler2D textures[];
|
layout(set = 0, binding = 1) uniform sampler2D textures[];
|
||||||
|
|
||||||
layout(push_constant) uniform Block {
|
layout(push_constant) uniform Block {
|
||||||
uint handle;
|
uint textureHandle;
|
||||||
|
uint vertexBufferHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outColor = vec4(texture(textures[handle], inUV).rgb, 1.0f);
|
outColor = vec4(texture(textures[textureHandle], inUV).rgb, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,32 @@
|
||||||
#version 450
|
#version 460 core
|
||||||
#pragma shader_stage(vertex)
|
#pragma shader_stage(vertex)
|
||||||
#extension GL_EXT_nonuniform_qualifier : enable
|
#extension GL_EXT_nonuniform_qualifier : enable
|
||||||
|
|
||||||
layout(location = 0) in vec4 position;
|
|
||||||
layout(location = 1) in vec2 uv0;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 outUV;
|
layout(location = 0) out vec2 outUV;
|
||||||
|
|
||||||
//layout(std140, set=0, binding=0) readonly buffer buffers;
|
struct VertexData {
|
||||||
//layout(set = 0, binding = 1) uniform texture2D textures[];
|
float position[3];
|
||||||
|
float uv[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std430, set = 0, binding = 0) readonly buffer Vertices {
|
||||||
|
VertexData data[];
|
||||||
|
} vertexBuffer[];
|
||||||
|
|
||||||
|
vec3 GetPosition(uint bufferId, uint vertexIdx) {
|
||||||
|
return vec3(
|
||||||
|
vertexBuffer[bufferId].data[vertexIdx].position[0],
|
||||||
|
vertexBuffer[bufferId].data[vertexIdx].position[1],
|
||||||
|
vertexBuffer[bufferId].data[vertexIdx].position[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 GetUV(uint bufferId, uint vertexIdx) {
|
||||||
|
return vec2(
|
||||||
|
vertexBuffer[bufferId].data[vertexIdx].uv[0],
|
||||||
|
vertexBuffer[bufferId].data[vertexIdx].uv[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform Camera {
|
layout(set = 1, binding = 0) uniform Camera {
|
||||||
mat4 model;
|
mat4 model;
|
||||||
|
|
@ -16,8 +34,12 @@ layout(set = 1, binding = 0) uniform Camera {
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
|
layout(push_constant) uniform Block {
|
||||||
|
uint textureHandle;
|
||||||
|
uint vertexBufferHandle;
|
||||||
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outUV = uv0;
|
outUV = GetUV(vertexBufferHandle, gl_VertexIndex);
|
||||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position.xyz, 1.0f);
|
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(GetPosition(vertexBufferHandle, gl_VertexIndex), 1.0f);
|
||||||
// outColor = vec3(0.5f, 0.3f, 0.1f);
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue