Add a bit more of the texture loading

This commit is contained in:
dpjudas 2024-03-23 04:17:28 +01:00
parent 4d37a89070
commit ff91b34939
5 changed files with 71 additions and 9 deletions

View file

@ -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;
}
}
}

View file

@ -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<unsigned char> Pixels;
unsigned long Width = 0;
unsigned long Height = 0;
friend class FTextureManager;
};
@ -93,8 +107,6 @@ public:
FTextureManager()
{
Textures.Push(std::make_unique<FGameTexture>());
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<FGameTexture>());
Textures.Last()->Name = name;
Textures.Push(std::make_unique<FGameTexture>(name));
NameToID[name] = id;
return FTextureID(id);

View file

@ -54,6 +54,7 @@ void GPURaytracer::Raytrace(DoomLevelMesh* mesh)
{
levelmesh->BeginFrame();
lightmapper->BeginFrame();
mDevice->GetDescriptorSetManager()->UpdateBindlessDescriptorSet();
TArray<LightmapTile*> tiles;
for (unsigned int i = 0, count = mesh->LightmapTiles.Size(); i < count; i++)

View file

@ -81,7 +81,6 @@ VulkanRenderDevice::VulkanRenderDevice(LevelMeshViewer* viewer)
levelmesh = std::make_unique<VkLevelMesh>(this);
lightmapper = std::make_unique<VkLightmapper>(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();

View file

@ -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<std::unique_ptr<VulkanFramebuffer>> Framebuffers;
std::unordered_map<FGameTexture*, int> TextureIndexes;
};
class VkCommandBufferManager