This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Graphics::Texture
, demo 2x2 RGBM texture
#26
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
18f90eb
Add `Graphics::Texture`
karnkaul beda086
Add fallback texture in resource pool
karnkaul e085f64
Add `TextureSampler` and its pooling machinery
karnkaul cbd4954
Add descriptor set binding for (main) texture
karnkaul 9936670
Add textures to `Primitive` and `BasicDrawable`
karnkaul c6ae38c
Sample texture in shaders
karnkaul 1d63314
Demonstrate RGBM texture
karnkaul a953e05
RGBM ordering
karnkaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include <Tkge/Graphics/TextureSampler.hpp> | ||
#include <kvf/bitmap.hpp> | ||
#include <kvf/render_device.hpp> | ||
#include <kvf/vma.hpp> | ||
#include <cstddef> | ||
#include <span> | ||
|
||
namespace Tkge::Graphics | ||
{ | ||
class Texture | ||
{ | ||
public: | ||
using Sampler = TextureSampler; | ||
|
||
explicit Texture(gsl::not_null<kvf::RenderDevice*> renderDevice); | ||
|
||
bool Create(const kvf::Bitmap& bitmap); | ||
bool Decompress(std::span<const std::byte> compressedImage); | ||
|
||
[[nodiscard]] const kvf::vma::Image& GetImage() const { return _image; } | ||
[[nodiscard]] glm::ivec2 GetSize() const; | ||
|
||
Sampler sampler{}; | ||
|
||
private: | ||
kvf::vma::Image _image{}; | ||
}; | ||
} // namespace Tkge::Graphics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include <vulkan/vulkan.hpp> | ||
|
||
namespace Tkge::Graphics | ||
{ | ||
struct TextureSampler | ||
{ | ||
vk::SamplerAddressMode wrap{vk::SamplerAddressMode::eRepeat}; | ||
vk::Filter filter{vk::Filter::eLinear}; | ||
vk::SamplerMipmapMode mipMap{vk::SamplerMipmapMode::eNearest}; | ||
vk::BorderColor borderColour{vk::BorderColor::eFloatTransparentBlack}; | ||
|
||
bool operator==(const TextureSampler&) const = default; | ||
}; | ||
} // namespace Tkge::Graphics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include <Tkge/Graphics/TextureSampler.hpp> | ||
#include <klib/hash_combine.hpp> | ||
#include <kvf/render_device.hpp> | ||
#include <vulkan/vulkan_hash.hpp> | ||
#include <unordered_map> | ||
|
||
namespace Tkge::Detail | ||
{ | ||
class SamplerPool | ||
{ | ||
public: | ||
explicit SamplerPool(gsl::not_null<const kvf::RenderDevice*> renderDevice) : _renderDevice(renderDevice) {} | ||
|
||
[[nodiscard]] vk::Sampler GetSampler(const Graphics::TextureSampler& in) | ||
{ | ||
const auto key = GetHash(in); | ||
auto it = _samplers.find(key); | ||
if (it != _samplers.end()) { return *it->second; } | ||
|
||
auto sci = _renderDevice->sampler_info(in.wrap, in.filter); | ||
sci.setMipmapMode(in.mipMap).setBorderColor(in.borderColour); | ||
it = _samplers.insert({key, _renderDevice->get_device().createSamplerUnique(sci)}).first; | ||
return *it->second; | ||
} | ||
|
||
private: | ||
[[nodiscard]] static std::size_t GetHash(const Graphics::TextureSampler& sampler) | ||
{ | ||
return klib::make_combined_hash(sampler.wrap, sampler.filter, sampler.mipMap, sampler.borderColour); | ||
} | ||
|
||
gsl::not_null<const kvf::RenderDevice*> _renderDevice; | ||
|
||
std::unordered_map<std::size_t, vk::UniqueSampler> _samplers{}; | ||
}; | ||
} // namespace Tkge::Detail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
#version 450 core | ||
|
||
layout (set = 0, binding = 2) uniform sampler2D tex; | ||
|
||
layout (location = 0) in vec4 inColour; | ||
layout (location = 1) in vec2 inUv; | ||
|
||
layout (location = 0) out vec4 outColour; | ||
|
||
void main() | ||
{ | ||
outColour = inColour; | ||
outColour = inColour * texture(tex, inUv); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <Tkge/Graphics/Texture.hpp> | ||
#include <kvf/image_bitmap.hpp> | ||
#include <kvf/util.hpp> | ||
|
||
namespace Tkge::Graphics | ||
{ | ||
namespace | ||
{ | ||
constexpr auto ImageCreateInfo = kvf::vma::ImageCreateInfo{ | ||
.format = vk::Format::eR8G8B8A8Srgb, | ||
}; | ||
|
||
} | ||
|
||
Texture::Texture(gsl::not_null<kvf::RenderDevice*> renderDevice) : _image(renderDevice, ImageCreateInfo) {} | ||
|
||
bool Texture::Create(const kvf::Bitmap& bitmap) | ||
{ | ||
if (bitmap.bytes.empty()) { return false; } | ||
return kvf::util::write_to(_image, bitmap); | ||
} | ||
|
||
bool Texture::Decompress(std::span<const std::byte> compressedImage) | ||
{ | ||
if (compressedImage.empty()) { return false; } | ||
const auto image = kvf::ImageBitmap{compressedImage}; | ||
if (!image.is_loaded()) { return false; } | ||
return Create(image.bitmap()); | ||
} | ||
|
||
glm::ivec2 Texture::GetSize() const { return kvf::util::to_glm_vec<int>(_image.get_extent()); } | ||
} // namespace Tkge::Graphics |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.