diff --git a/src/framework/textureid.cpp b/src/framework/textureid.cpp index 499dabf..1bf1763 100644 --- a/src/framework/textureid.cpp +++ b/src/framework/textureid.cpp @@ -1,4 +1,35 @@ #include "textureid.h" +#include "filesystem.h" +#include "picopng/picopng.h" FTextureManager TexMan; + +FGameTexture::FGameTexture(FString name) : Name(name) +{ + int lump = fileSystem.CheckNumForFullName(name); + if (lump < 0) + { + // Not found - should we mark it as invalid or use a dummy texture? + DisplayWidth = 64.0f; + DisplayHeight = 64.0f; + } + else + { + // To do: figure out what type of data we got here instead of assuming it is a png. + + FileData filedata = fileSystem.ReadFile(lump); + int result = decodePNG(Pixels, Width, Height, (const unsigned char*)filedata.GetMem(), fileSystem.FileLength(lump), true); + if (result == 0) + { + DisplayWidth = (float)Width; + DisplayHeight = (float)Height; + } + else + { + // Not a png. + DisplayWidth = 64.0f; + DisplayHeight = 64.0f; + } + } +} diff --git a/src/framework/textureid.h b/src/framework/textureid.h index 585bb40..77c0df3 100644 --- a/src/framework/textureid.h +++ b/src/framework/textureid.h @@ -75,14 +75,28 @@ public: class FGameTexture { public: + FGameTexture() { Name = "-"; Valid = false; } + FGameTexture(FString name); + bool isValid() const { return Valid; } - float GetDisplayWidth() const { return 64.0f; } - float GetDisplayHeight() const { return 64.0f; } - float GetScaleY() const { return 1.0f; } + float GetDisplayWidth() const { return DisplayWidth; } + float GetDisplayHeight() const { return DisplayHeight; } + float GetScaleY() const { return ScaleY; } + + const void* GetImagePixels() const { return Pixels.data(); } + int GetImageWidth() const { return Width; } + int GetImageHeight() const { return Height; } private: FString Name; bool Valid = true; + float DisplayWidth = 0.0f; + float DisplayHeight = 0.0f; + float ScaleY = 1.0f; + + std::vector Pixels; + unsigned long Width = 0; + unsigned long Height = 0; friend class FTextureManager; }; @@ -93,8 +107,6 @@ public: FTextureManager() { Textures.Push(std::make_unique()); - Textures.Last()->Name = "-"; - Textures.Last()->Valid = false; } FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) @@ -140,8 +152,7 @@ public: return FTextureID(it->second); int id = Textures.Size(); - Textures.Push(std::make_unique()); - Textures.Last()->Name = name; + Textures.Push(std::make_unique(name)); NameToID[name] = id; return FTextureID(id); diff --git a/src/lightmapper/gpuraytracer.cpp b/src/lightmapper/gpuraytracer.cpp index 5d82933..63fe0e8 100644 --- a/src/lightmapper/gpuraytracer.cpp +++ b/src/lightmapper/gpuraytracer.cpp @@ -54,6 +54,7 @@ void GPURaytracer::Raytrace(DoomLevelMesh* mesh) { levelmesh->BeginFrame(); lightmapper->BeginFrame(); + mDevice->GetDescriptorSetManager()->UpdateBindlessDescriptorSet(); TArray tiles; for (unsigned int i = 0, count = mesh->LightmapTiles.Size(); i < count; i++) diff --git a/src/lightmapper/vk_renderdevice.cpp b/src/lightmapper/vk_renderdevice.cpp index 3fb5bd6..913f824 100644 --- a/src/lightmapper/vk_renderdevice.cpp +++ b/src/lightmapper/vk_renderdevice.cpp @@ -81,7 +81,6 @@ VulkanRenderDevice::VulkanRenderDevice(LevelMeshViewer* viewer) levelmesh = std::make_unique(this); lightmapper = std::make_unique(this); - descriptors->AddBindlessTextureIndex(GetTextureManager()->GetNullTextureView(), GetSamplerManager()->Get()); descriptors->AddBindlessTextureIndex(GetTextureManager()->GetNullTextureView(), GetSamplerManager()->Get()); descriptors->UpdateBindlessDescriptorSet(); @@ -93,6 +92,25 @@ VulkanRenderDevice::~VulkanRenderDevice() vkDeviceWaitIdle(device->device); } +int VulkanRenderDevice::GetBindlessTextureIndex(FTextureID textureID) +{ + if (!textureID.isValid()) + return 0; + + FGameTexture* tex = TexMan.GetGameTexture(textureID); + int& textureIndex = TextureIndexes[tex]; + if (textureIndex != 0) + return textureIndex; + + // To do: upload image + + VulkanImageView* view = GetTextureManager()->GetNullTextureView(); + VulkanSampler* sampler = GetSamplerManager()->Get(); + + textureIndex = GetDescriptorSetManager()->AddBindlessTextureIndex(view, sampler); + return textureIndex; +} + void VulkanRenderDevice::DrawViewer(const FVector3& cameraPos, const VSMatrix& viewToWorld, float fovy, float aspect, const FVector3& sundir, const FVector3& suncolor, float sunintensity) { int imageIndex = GetCommands()->AcquireImage(); diff --git a/src/lightmapper/vk_renderdevice.h b/src/lightmapper/vk_renderdevice.h index 48d2a18..c33593a 100644 --- a/src/lightmapper/vk_renderdevice.h +++ b/src/lightmapper/vk_renderdevice.h @@ -32,7 +32,7 @@ public: VkLevelMesh* GetLevelMesh() { return levelmesh.get(); } VkLightmapper* GetLightmapper() { return lightmapper.get(); } - int GetBindlessTextureIndex(FTextureID texture) { return texture.isValid() ? 1 : 0; } + int GetBindlessTextureIndex(FTextureID texture); bool IsRayQueryEnabled() const { return useRayQuery; } @@ -68,6 +68,7 @@ private: int CurrentWidth = 0; int CurrentHeight = 0; std::vector> Framebuffers; + std::unordered_map TextureIndexes; }; class VkCommandBufferManager