Added skeletal animations and other fixes
This commit is contained in:
@@ -129,18 +129,36 @@ void GfxDevice::init(SDL_Window* window, const std::string& appName, bool vSync)
|
||||
auto& mainCommandBuffer = frames[i].commandBuffer;
|
||||
VK_CHECK(vkAllocateCommandBuffers(device, &cmdAllocInfo, &mainCommandBuffer));
|
||||
}
|
||||
//
|
||||
// { // create white texture
|
||||
// std::uint32_t pixel = 0xFFFFFFFF;
|
||||
// whiteImageId = createImage(
|
||||
// {
|
||||
// .format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
// .usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||
// .extent = VkExtent3D{1, 1, 1},
|
||||
// },
|
||||
// "white texture",
|
||||
// &pixel);
|
||||
// }
|
||||
|
||||
{ // create white texture
|
||||
std::uint32_t pixel = 0xFFFFFFFF;
|
||||
whiteImageId = createImage(
|
||||
{
|
||||
.format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||
.extent = VkExtent3D{1, 1, 1},
|
||||
},
|
||||
"white texture",
|
||||
&pixel);
|
||||
}
|
||||
|
||||
{ // create error texture (black/magenta checker)
|
||||
constexpr auto black = 0xFF000000;
|
||||
constexpr auto magenta = 0xFFFF00FF;
|
||||
|
||||
std::array<std::uint32_t, 4> pixels{black, magenta, magenta, black};
|
||||
errorImageId = createImage(
|
||||
{
|
||||
.format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
|
||||
.extent = VkExtent3D{2, 2, 1},
|
||||
},
|
||||
"error texture",
|
||||
pixels.data());
|
||||
imageCache.setErrorImageId(errorImageId);
|
||||
}
|
||||
|
||||
GameState::GetInstance().SetGfxDevice(this);
|
||||
}
|
||||
|
||||
@@ -495,25 +513,14 @@ GPUImage GfxDevice::createImageRaw(
|
||||
return image;
|
||||
}
|
||||
|
||||
GPUImage GfxDevice::loadImageFromFileRaw(
|
||||
const std::filesystem::path& path,
|
||||
VkImageUsageFlags usage,
|
||||
bool mipMap,
|
||||
TextureIntent intent) const {
|
||||
// 1) Decode file to CPU pixels (stb for png/jpg/hdr, tinyexr for exr)
|
||||
// IMPORTANT: util::loadImage should fill:
|
||||
// - width/height/channels(=4)
|
||||
// - hdr + (pixels OR hdrPixels)
|
||||
// - vkFormat (RGBA8_SRGB or RGBA8_UNORM or RGBA32F)
|
||||
// - byteSize (exact bytes to upload)
|
||||
GPUImage GfxDevice::loadImageFromFileRaw(const std::filesystem::path& path, VkImageUsageFlags usage, bool mipMap, TextureIntent intent) const {
|
||||
const auto data = util::loadImage(path, intent);
|
||||
if (data.vkFormat == VK_FORMAT_UNDEFINED || data.byteSize == 0 ||
|
||||
(data.hdr ? (data.hdrPixels == nullptr) : (data.pixels == nullptr))) {
|
||||
|
||||
if (data.vkFormat == VK_FORMAT_UNDEFINED || data.byteSize == 0 || (data.hdr ? (data.hdrPixels == nullptr) : (data.pixels == nullptr))) {
|
||||
spdlog::error("Failed to load image '{}'", path.string());
|
||||
return getImage(errorImageId);
|
||||
}
|
||||
|
||||
// 2) Create GPU image using the format the loader chose (matches CPU memory layout)
|
||||
auto image = createImageRaw({
|
||||
.format = data.vkFormat,
|
||||
.usage = usage |
|
||||
@@ -527,15 +534,10 @@ GPUImage GfxDevice::loadImageFromFileRaw(
|
||||
.mipMap = mipMap,
|
||||
});
|
||||
|
||||
// 3) Upload *exactly* byteSize bytes from the correct pointer
|
||||
const void* src = data.hdr
|
||||
? static_cast<const void*>(data.hdrPixels)
|
||||
: static_cast<const void*>(data.pixels);
|
||||
const void* src = data.hdr ? static_cast<const void*>(data.hdrPixels) : static_cast<const void*>(data.pixels);
|
||||
|
||||
// Use the "sized" upload to avoid BytesPerTexel mismatches
|
||||
uploadImageDataSized(image, src, data.byteSize, 0);
|
||||
|
||||
// 4) Debug label
|
||||
image.debugName = path.string();
|
||||
vkutil::addDebugLabel(device, image.image, path.string().c_str());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user