summaryrefslogtreecommitdiff
path: root/src/entities.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-12-28 16:05:02 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-12-28 16:05:02 -0500
commit499206dcb39e9ed0c3e21e3c580f556218e0c693 (patch)
treeff5424e4678f5f83f224c99f2d469573a5e720f6 /src/entities.cpp
parent2aa963fc37dbf61a008031d82e2aac87bf89f9db (diff)
EntityType falls back to a default texture if not provided
Diffstat (limited to 'src/entities.cpp')
-rw-r--r--src/entities.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 9553a89..ab4f731 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -3,6 +3,7 @@
#include "math-helpers.hpp"
#include "physics.hpp"
+#include "static/missing-texture.hpp"
#include "window.hpp"
#include <BulletCollision/CollisionShapes/btConvexHullShape.h>
@@ -102,12 +103,20 @@ void EntityType_Load(EntityType &et) {
gltfPath.replace_filename(gltfData->buffers[0].uri);
AssetHandle modelBinHandle = AM_Register(gltfPath.c_str(), PKE_ASSET_TYPE_UNSET);
+ int pixelWidth, pixelHeight, pixelChannels;
+ stbi_uc *pixels = nullptr;
if (textureAssetHandle != AssetHandle_MAX) {
const Asset *textureAsset = AM_Get(textureAssetHandle);
- int pixelWidth, pixelHeight, pixelChannels;
- auto *pixels = stbi_load_from_memory(static_cast<stbi_uc *>(textureAsset->ptr), textureAsset->size, &pixelWidth, &pixelHeight, &pixelChannels, STBI_rgb_alpha);
+ pixels = stbi_load_from_memory(static_cast<stbi_uc *>(textureAsset->ptr), textureAsset->size, &pixelWidth, &pixelHeight, &pixelChannels, STBI_rgb_alpha);
assert(pixels != nullptr && "sbti_load failed to load image.");
+ } else {
+ pixelWidth = 2;
+ pixelHeight = 2;
+ pixelChannels = 4;
+ pixels = const_cast<unsigned char *>(&PKE_MISSING_TEXTURE_DATA[0]);
+ }
+ {
uint32_t imageSizeBytes = pixelWidth * pixelHeight * pixelChannels;
VkFormat imageFormat = VK_FORMAT_R8G8B8A8_SRGB;
@@ -310,7 +319,9 @@ void EntityType_Load(EntityType &et) {
// TODO double-check this?
// stbi_image_free(pixels);
- AM_Release(textureAssetHandle);
+ if (textureAssetHandle != AssetHandle_MAX) {
+ AM_Release(textureAssetHandle);
+ }
// descriptor pool & sets