summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/entities.cpp17
-rw-r--r--src/entities.hpp8
-rw-r--r--src/static/missing-texture.hpp24
-rw-r--r--src/window.cpp17
5 files changed, 45 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0900da7..a71a249 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,6 +58,7 @@ set(PKE_SOURCE_FILES
src/project-settings.cpp
src/static/cube.hpp
src/static/cube.cpp
+ src/static/missing-texture.hpp
src/thread_pool.hpp
src/thread_pool.cpp
src/vendor/cgltf-include.hpp
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
diff --git a/src/entities.hpp b/src/entities.hpp
index bdcb3eb..41ae7fd 100644
--- a/src/entities.hpp
+++ b/src/entities.hpp
@@ -27,10 +27,10 @@ struct EntityType {
VkDescriptorPool vkDescriptorPool = VK_NULL_HANDLE;
uint32_t startingInstanceCount = 1024;
struct Importer_GLTF {
- int16_t AccessorIndexVertex = -1;
- int16_t AccessorIndexNormal = -1;
- int16_t AccessorIndexUV = -1;
- int16_t AccessorIndexIndex = -1;
+ int16_t AccessorIndexVertex = 0;
+ int16_t AccessorIndexNormal = 1;
+ int16_t AccessorIndexUV = 2;
+ int16_t AccessorIndexIndex = 3;
} Importer_GLTF;
struct {
btCollisionShape *shape = nullptr;
diff --git a/src/static/missing-texture.hpp b/src/static/missing-texture.hpp
new file mode 100644
index 0000000..83f7162
--- /dev/null
+++ b/src/static/missing-texture.hpp
@@ -0,0 +1,24 @@
+#ifndef PKE_STATIC_MISSING_TEXTURE_HPP
+#define PKE_STATIC_MISSING_TEXTURE_HPP
+
+/*
+ * 0: #373b3e (55,59,62) // dark grey (desaturated light blue)
+ * 1: #bec8d1 (190,200,209) // light grey (desaturated light blue)
+ * 2: #86cecb (134,206,203) // light cyan
+ * 3: #137a7f (19,122,127) // dark cyan
+ * 4: #e12885 (225,40,133) // magenta
+ */
+
+const unsigned long PKE_MISSING_TEXTURE_BYTE_COUNT = 16;
+const unsigned char PKE_MISSING_TEXTURE_DATA[PKE_MISSING_TEXTURE_BYTE_COUNT] = {
+ // top left : color 0
+ 0x37, 0x3b, 0x3e, 0xff,
+ // top right : color 2
+ 0x86, 0xce, 0xcb, 0xff,
+ // bottom left : color 3
+ 0x13, 0x7a, 0x7f, 0xff,
+ // bottom right : color 4
+ 0xe1, 0x28, 0x85, 0xff,
+};
+
+#endif /* PKE_STATIC_MISSING_TEXTURE_HPP */
diff --git a/src/window.cpp b/src/window.cpp
index 8aa241d..5816041 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,3 +1,4 @@
+#include "static/missing-texture.hpp"
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
@@ -1800,25 +1801,11 @@ void CreateGraphicsPipelines() {
result = vkCreateImageView(vkDevice, &dbgImageViewCI, vkAllocator, &pkeDebugHitbox.vkImageView);
assert(result == VK_SUCCESS);
- /*
- * 0: #373b3e (55,59,62) // dark grey (desaturated light blue)
- * 1: #bec8d1 (190,200,209) // light grey (desaturated light blue)
- * 2: #86cecb (134,206,203) // light cyan
- * 3: #137a7f (19,122,127) // dark cyan
- * 4: #e12885 (225,40,133) // magenta
- */
- // transition image layout and copy to buffer
- const uint8_t pixels[] = {
- 0x37, 0x3b, 0x3e, 0xff, // 0
- 0x86, 0xce, 0xcb, 0xff, // 2
- 0x13, 0x7a, 0x7f, 0xff, // 3
- 0xe1, 0x28, 0x85, 0xff, // 4
- };
VkBuffer transferImageBuffer;
VkDeviceMemory transferImageMemory;
void *deviceData;
BeginTransferBuffer(4 * 4, transferImageBuffer, transferImageMemory, deviceData);
- memcpy(deviceData, pixels, 4 * 4);
+ memcpy(deviceData, PKE_MISSING_TEXTURE_DATA, 4 * 4);
{
VkImageMemoryBarrier vkImageMemoryBarrier;
vkImageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;