Do some things

This commit is contained in:
Bailey Harrison 2022-11-15 13:59:43 +00:00
parent ecab0acbf4
commit ceaa2c30f5
5 changed files with 32 additions and 7 deletions

View File

@ -30,6 +30,11 @@ namespace engine::gfx {
VEC3,
};
enum class TextureFilter {
LINEAR,
NEAREST,
};
struct VertexBufferDesc {
uint64_t size;
};

View File

@ -37,7 +37,7 @@ namespace engine {
gfx::Buffer* createBuffer(gfx::BufferType type, uint64_t size, const void* data);
void destroyBuffer(const gfx::Buffer* buffer);
gfx::Texture* createTexture(const void* imageData, uint32_t w, uint32_t h);
gfx::Texture* createTexture(const void* imageData, uint32_t w, uint32_t h, gfx::TextureFilter minFilter, gfx::TextureFilter magFilter);
void destroyTexture(const gfx::Texture* texture);
// wait until all the active GPU queues have finished working

View File

@ -20,4 +20,4 @@ private:
gfx::Texture* m_gpuTexture;
};
}
}

View File

@ -154,6 +154,17 @@ namespace engine {
throw std::runtime_error("Unknown buffer type");
}
static VkFilter getTextureFilter(gfx::TextureFilter filter)
{
switch(filter) {
case gfx::TextureFilter::LINEAR:
return VK_FILTER_LINEAR;
case gfx::TextureFilter::NEAREST:
return VK_FILTER_NEAREST;
}
throw std::runtime_error("Unknown texture filter");
}
}
// functions
@ -1922,7 +1933,7 @@ namespace engine {
delete buffer;
}
gfx::Texture* GFXDevice::createTexture(const void* imageData, uint32_t w, uint32_t h)
gfx::Texture* GFXDevice::createTexture(const void* imageData, uint32_t w, uint32_t h, gfx::TextureFilter minFilter, gfx::TextureFilter magFilter)
{
auto out = new gfx::Texture;
@ -2031,9 +2042,13 @@ namespace engine {
// create texture sampler
{
VkFilter minFilterInternal = vkinternal::getTextureFilter(minFilter);
VkFilter magFilterInternal = vkinternal::getTextureFilter(magFilter);
VkSamplerCreateInfo samplerInfo{ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;

View File

@ -85,7 +85,12 @@ Texture::Texture(const std::filesystem::path& resPath) : Resource(resPath, "text
throw std::runtime_error("Currently, only RGBA textures are supported. Size: " + std::to_string(texbuf->size()));
}
m_gpuTexture = gfxdev->createTexture(texbuf->data(), (uint32_t)width, (uint32_t)height);
gfx::TextureFilter filter = gfx::TextureFilter::LINEAR;
if (width <= 8 || height <= 8) {
filter = gfx::TextureFilter::NEAREST;
}
m_gpuTexture = gfxdev->createTexture(texbuf->data(), (uint32_t)width, (uint32_t)height, gfx::TextureFilter::LINEAR, filter);
DEBUG("loaded texture {} width: {} height: {} size: {}", resPath.filename().string(), width, height, texbuf->size());
@ -101,4 +106,4 @@ gfx::Texture* Texture::getHandle()
return m_gpuTexture;
}
}
}