From 18f90eb722227bdc0e808bc8dfe7c714ab2b3030 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 10:43:36 -0800 Subject: [PATCH 1/8] Add `Graphics::Texture` --- Lib/Include/Tkge/Graphics/Texture.hpp | 24 ++++++++++++++++++++ Lib/Src/Graphics/Texture.cpp | 32 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Lib/Include/Tkge/Graphics/Texture.hpp create mode 100644 Lib/Src/Graphics/Texture.cpp diff --git a/Lib/Include/Tkge/Graphics/Texture.hpp b/Lib/Include/Tkge/Graphics/Texture.hpp new file mode 100644 index 0000000..ae34519 --- /dev/null +++ b/Lib/Include/Tkge/Graphics/Texture.hpp @@ -0,0 +1,24 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace Tkge::Graphics +{ + class Texture + { + public: + explicit Texture(gsl::not_null renderDevice); + + bool Create(const kvf::Bitmap& bitmap); + bool Decompress(std::span compressedImage); + + [[nodiscard]] const kvf::vma::Image& GetImage() const { return _image; } + [[nodiscard]] glm::ivec2 GetSize() const; + + private: + kvf::vma::Image _image{}; + }; +} // namespace Tkge::Graphics diff --git a/Lib/Src/Graphics/Texture.cpp b/Lib/Src/Graphics/Texture.cpp new file mode 100644 index 0000000..919a502 --- /dev/null +++ b/Lib/Src/Graphics/Texture.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +namespace Tkge::Graphics +{ + namespace + { + constexpr auto ImageCreateInfo = kvf::vma::ImageCreateInfo{ + .format = vk::Format::eR8G8B8A8Srgb, + }; + + } + + Texture::Texture(gsl::not_null 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 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(_image.get_extent()); } +} // namespace Tkge::Graphics From beda086ea7b36551b0ee2e487239b01b46fe8150 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 10:43:51 -0800 Subject: [PATCH 2/8] Add fallback texture in resource pool --- Lib/Include/Tkge/Graphics/ResourcePool.hpp | 3 +++ Lib/Src/Engine.cpp | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/Include/Tkge/Graphics/ResourcePool.hpp b/Lib/Include/Tkge/Graphics/ResourcePool.hpp index 7b7659d..56e304e 100644 --- a/Lib/Include/Tkge/Graphics/ResourcePool.hpp +++ b/Lib/Include/Tkge/Graphics/ResourcePool.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include namespace Tkge::Graphics @@ -21,5 +22,7 @@ namespace Tkge::Graphics /// \brief Allocate a Buffer for given usage and of given size. [[nodiscard]] virtual Buffer& AllocateBuffer(vk::BufferUsageFlags usage, vk::DeviceSize size) = 0; + + [[nodiscard]] virtual const Graphics::Texture& GetFallbackTexture() const = 0; }; } // namespace Tkge::Graphics diff --git a/Lib/Src/Engine.cpp b/Lib/Src/Engine.cpp index fc28f1e..aa84f6a 100644 --- a/Lib/Src/Engine.cpp +++ b/Lib/Src/Engine.cpp @@ -10,12 +10,22 @@ namespace Tkge { namespace { + struct PixelBitmap + { + [[nodiscard]] constexpr kvf::Bitmap ToBitmap() const { return kvf::Bitmap{.bytes = bytes, .size = {1, 1}}; } + + std::array bytes{}; + }; + + constexpr auto WhiteBitmap = std::bit_cast(kvf::white_v); + class ResourcePool : public Graphics::IResourcePool { public: explicit ResourcePool(gsl::not_null renderDevice, vk::SampleCountFlagBits framebufferSamples) - : _pipelinePool(renderDevice, framebufferSamples), _bufferPool(renderDevice) + : _pipelinePool(renderDevice, framebufferSamples), _bufferPool(renderDevice), _whiteTexture(renderDevice) { + _whiteTexture.Create(WhiteBitmap.ToBitmap()); } [[nodiscard]] vk::PipelineLayout PipelineLayout() const final { return _pipelinePool.PipelineLayout(); } @@ -32,11 +42,14 @@ namespace Tkge return _bufferPool.Allocate(usage, size); } + [[nodiscard]] const Graphics::Texture& GetFallbackTexture() const final { return _whiteTexture; } + void NextFrame() { _bufferPool.NextFrame(); } private: Detail::PipelinePool _pipelinePool; Detail::BufferPool _bufferPool; + Graphics::Texture _whiteTexture; }; } // namespace From e085f64a02b79a6cfbf9e74e45a21e4017b542f6 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:11:27 -0800 Subject: [PATCH 3/8] Add `TextureSampler` and its pooling machinery --- Lib/Include/Tkge/Graphics/ResourcePool.hpp | 1 + Lib/Include/Tkge/Graphics/Texture.hpp | 5 +++ Lib/Include/Tkge/Graphics/TextureSampler.hpp | 15 ++++++++ Lib/Src/Detail/SamplerPool.hpp | 37 ++++++++++++++++++++ Lib/Src/Engine.cpp | 5 ++- 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Lib/Include/Tkge/Graphics/TextureSampler.hpp create mode 100644 Lib/Src/Detail/SamplerPool.hpp diff --git a/Lib/Include/Tkge/Graphics/ResourcePool.hpp b/Lib/Include/Tkge/Graphics/ResourcePool.hpp index 56e304e..9311744 100644 --- a/Lib/Include/Tkge/Graphics/ResourcePool.hpp +++ b/Lib/Include/Tkge/Graphics/ResourcePool.hpp @@ -23,6 +23,7 @@ namespace Tkge::Graphics /// \brief Allocate a Buffer for given usage and of given size. [[nodiscard]] virtual Buffer& AllocateBuffer(vk::BufferUsageFlags usage, vk::DeviceSize size) = 0; + [[nodiscard]] virtual vk::Sampler GetSampler(const Graphics::TextureSampler& sampler) = 0; [[nodiscard]] virtual const Graphics::Texture& GetFallbackTexture() const = 0; }; } // namespace Tkge::Graphics diff --git a/Lib/Include/Tkge/Graphics/Texture.hpp b/Lib/Include/Tkge/Graphics/Texture.hpp index ae34519..8b92a70 100644 --- a/Lib/Include/Tkge/Graphics/Texture.hpp +++ b/Lib/Include/Tkge/Graphics/Texture.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -10,6 +11,8 @@ namespace Tkge::Graphics class Texture { public: + using Sampler = TextureSampler; + explicit Texture(gsl::not_null renderDevice); bool Create(const kvf::Bitmap& bitmap); @@ -18,6 +21,8 @@ namespace Tkge::Graphics [[nodiscard]] const kvf::vma::Image& GetImage() const { return _image; } [[nodiscard]] glm::ivec2 GetSize() const; + Sampler sampler{}; + private: kvf::vma::Image _image{}; }; diff --git a/Lib/Include/Tkge/Graphics/TextureSampler.hpp b/Lib/Include/Tkge/Graphics/TextureSampler.hpp new file mode 100644 index 0000000..129342f --- /dev/null +++ b/Lib/Include/Tkge/Graphics/TextureSampler.hpp @@ -0,0 +1,15 @@ +#pragma once +#include + +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 diff --git a/Lib/Src/Detail/SamplerPool.hpp b/Lib/Src/Detail/SamplerPool.hpp new file mode 100644 index 0000000..b2b16e6 --- /dev/null +++ b/Lib/Src/Detail/SamplerPool.hpp @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace Tkge::Detail +{ + class SamplerPool + { + public: + explicit SamplerPool(gsl::not_null 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 _renderDevice; + + std::unordered_map _samplers{}; + }; +} // namespace Tkge::Detail diff --git a/Lib/Src/Engine.cpp b/Lib/Src/Engine.cpp index aa84f6a..1e995c0 100644 --- a/Lib/Src/Engine.cpp +++ b/Lib/Src/Engine.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -23,7 +24,7 @@ namespace Tkge { public: explicit ResourcePool(gsl::not_null renderDevice, vk::SampleCountFlagBits framebufferSamples) - : _pipelinePool(renderDevice, framebufferSamples), _bufferPool(renderDevice), _whiteTexture(renderDevice) + : _pipelinePool(renderDevice, framebufferSamples), _bufferPool(renderDevice), _samplerPool(renderDevice), _whiteTexture(renderDevice) { _whiteTexture.Create(WhiteBitmap.ToBitmap()); } @@ -42,6 +43,7 @@ namespace Tkge return _bufferPool.Allocate(usage, size); } + [[nodiscard]] vk::Sampler GetSampler(const Graphics::TextureSampler& sampler) final { return _samplerPool.GetSampler(sampler); } [[nodiscard]] const Graphics::Texture& GetFallbackTexture() const final { return _whiteTexture; } void NextFrame() { _bufferPool.NextFrame(); } @@ -49,6 +51,7 @@ namespace Tkge private: Detail::PipelinePool _pipelinePool; Detail::BufferPool _bufferPool; + Detail::SamplerPool _samplerPool; Graphics::Texture _whiteTexture; }; } // namespace From cbd4954ce2c8dd11107c574856d69bbc1678527d Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:13:58 -0800 Subject: [PATCH 4/8] Add descriptor set binding for (main) texture --- Lib/Include/Tkge/Graphics/Renderer.hpp | 2 +- Lib/Src/Detail/PipelinePool.hpp | 5 +++-- Lib/Src/Graphics/Renderer.cpp | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Lib/Include/Tkge/Graphics/Renderer.hpp b/Lib/Include/Tkge/Graphics/Renderer.hpp index 5a1841d..9c137c8 100644 --- a/Lib/Include/Tkge/Graphics/Renderer.hpp +++ b/Lib/Include/Tkge/Graphics/Renderer.hpp @@ -41,7 +41,7 @@ namespace Tkge::Graphics }; void UpdateInstances(std::span instances); - [[nodiscard]] bool WriteSets() const; + [[nodiscard]] bool WriteSets(const Texture* texture) const; void BindVboAndDraw(const Primitive& primitive, std::uint32_t instances) const; kvf::RenderPass* _renderPass{}; diff --git a/Lib/Src/Detail/PipelinePool.hpp b/Lib/Src/Detail/PipelinePool.hpp index 6908fff..66af8eb 100644 --- a/Lib/Src/Detail/PipelinePool.hpp +++ b/Lib/Src/Detail/PipelinePool.hpp @@ -75,12 +75,13 @@ namespace Tkge::Detail { static constexpr auto StageFlags = vk::ShaderStageFlagBits::eAllGraphics; // set 0: builtin - auto set0 = std::array{}; + auto set0 = std::array{}; // set 0, binding 0: view set0[0].setBinding(0).setDescriptorCount(1).setDescriptorType(vk::DescriptorType::eUniformBuffer).setStageFlags(StageFlags); // set 0, binding 1: instances set0[1].setBinding(1).setDescriptorCount(1).setDescriptorType(vk::DescriptorType::eStorageBuffer).setStageFlags(StageFlags); - // TODO: texture bindings + // set0, binding 2: texture + set0[2].setBinding(2).setDescriptorCount(1).setDescriptorType(vk::DescriptorType::eCombinedImageSampler).setStageFlags(StageFlags); // TODO: set 1: user data diff --git a/Lib/Src/Graphics/Renderer.cpp b/Lib/Src/Graphics/Renderer.cpp index 08f11e3..debbcb8 100644 --- a/Lib/Src/Graphics/Renderer.cpp +++ b/Lib/Src/Graphics/Renderer.cpp @@ -57,7 +57,7 @@ namespace Tkge::Graphics } UpdateInstances(instances); - if (!WriteSets()) { return; } + if (!WriteSets(nullptr)) { return; } _renderPass->get_command_buffer().setViewport(0, _viewport); @@ -74,9 +74,10 @@ namespace Tkge::Graphics } } - bool Renderer::WriteSets() const + bool Renderer::WriteSets(const Texture* texture) const { auto& renderDevice = _renderPass->get_render_device(); + if (texture == nullptr) { texture = &_resourcePool->GetFallbackTexture(); } const auto setLayouts = _resourcePool->SetLayouts(); auto descriptorSets = std::array{}; @@ -84,6 +85,7 @@ namespace Tkge::Graphics if (!renderDevice.allocate_sets(descriptorSets, setLayouts)) { return false; } auto bufferInfos = klib::FlexArray{}; + auto imageInfos = klib::FlexArray{}; auto descriptorWrites = klib::FlexArray{}; const auto pushBufferWrite = [&](vk::DescriptorSet set, std::uint32_t binding, const Buffer& buffer, const vk::DescriptorType type) { @@ -95,6 +97,17 @@ namespace Tkge::Graphics descriptorWrites.push_back(wds); }; + const auto pushImageWrite = [&](vk::DescriptorSet set, std::uint32_t binding, const Texture& texture) + { + imageInfos.push_back({}); + auto& dii = imageInfos.back(); + dii.setImageView(texture.GetImage().get_view()) + .setImageLayout(vk::ImageLayout::eShaderReadOnlyOptimal) + .setSampler(_resourcePool->GetSampler(texture.sampler)); + auto wds = vk::WriteDescriptorSet{}; + wds.setImageInfo(dii).setDescriptorCount(1).setDescriptorType(vk::DescriptorType::eCombinedImageSampler).setDstSet(set).setDstBinding(binding); + }; + auto& ubo00 = _resourcePool->AllocateBuffer(vk::BufferUsageFlagBits::eUniformBuffer, sizeof(glm::mat4)); const auto halfRenderArea = 0.5f * glm::vec2{_viewport.width, -_viewport.height}; const auto matProj = glm::ortho(-halfRenderArea.x, halfRenderArea.x, -halfRenderArea.y, halfRenderArea.y); @@ -107,6 +120,8 @@ namespace Tkge::Graphics kvf::util::overwrite(ssbo01, instanceSpan); pushBufferWrite(descriptorSets[0], 1, ssbo01, vk::DescriptorType::eStorageBuffer); + pushImageWrite(descriptorSets[0], 2, *texture); + const auto writeSpan = std::span{descriptorWrites.data(), descriptorWrites.size()}; renderDevice.get_device().updateDescriptorSets(writeSpan, {}); From 99366703220e1a86045dd19b4a50663e8baf4b75 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:21:56 -0800 Subject: [PATCH 5/8] Add textures to `Primitive` and `BasicDrawable` --- Lib/Include/Tkge/Graphics/Drawable.hpp | 3 +++ Lib/Include/Tkge/Graphics/Primitive.hpp | 2 ++ Lib/Src/Graphics/Renderer.cpp | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/Include/Tkge/Graphics/Drawable.hpp b/Lib/Include/Tkge/Graphics/Drawable.hpp index ba2a037..2852d47 100644 --- a/Lib/Include/Tkge/Graphics/Drawable.hpp +++ b/Lib/Include/Tkge/Graphics/Drawable.hpp @@ -24,8 +24,11 @@ namespace Tkge::Graphics .vertices = this->GetVertices(), .indices = this->GetIndices(), .topology = this->GetTopology(), + .texture = texture, }; } + + const Texture* texture{nullptr}; }; template TGeometry> diff --git a/Lib/Include/Tkge/Graphics/Primitive.hpp b/Lib/Include/Tkge/Graphics/Primitive.hpp index 8939619..9a747a4 100644 --- a/Lib/Include/Tkge/Graphics/Primitive.hpp +++ b/Lib/Include/Tkge/Graphics/Primitive.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -10,5 +11,6 @@ namespace Tkge::Graphics std::span indices{}; vk::PrimitiveTopology topology{vk::PrimitiveTopology::eTriangleList}; + const Texture* texture{nullptr}; }; } // namespace Tkge::Graphics diff --git a/Lib/Src/Graphics/Renderer.cpp b/Lib/Src/Graphics/Renderer.cpp index debbcb8..14082a3 100644 --- a/Lib/Src/Graphics/Renderer.cpp +++ b/Lib/Src/Graphics/Renderer.cpp @@ -57,7 +57,7 @@ namespace Tkge::Graphics } UpdateInstances(instances); - if (!WriteSets(nullptr)) { return; } + if (!WriteSets(primitive.texture)) { return; } _renderPass->get_command_buffer().setViewport(0, _viewport); @@ -106,6 +106,7 @@ namespace Tkge::Graphics .setSampler(_resourcePool->GetSampler(texture.sampler)); auto wds = vk::WriteDescriptorSet{}; wds.setImageInfo(dii).setDescriptorCount(1).setDescriptorType(vk::DescriptorType::eCombinedImageSampler).setDstSet(set).setDstBinding(binding); + descriptorWrites.push_back(wds); }; auto& ubo00 = _resourcePool->AllocateBuffer(vk::BufferUsageFlagBits::eUniformBuffer, sizeof(glm::mat4)); From c6ae38c00cbf7e97b0c16e4ac6043ba4b8d5bb06 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:30:02 -0800 Subject: [PATCH 6/8] Sample texture in shaders --- Assets/Shaders/Default.frag | Bin 452 -> 732 bytes Assets/Shaders/Default.vert | Bin 2352 -> 2448 bytes Lib/Src/Glsl/Default.frag | 5 ++++- Lib/Src/Glsl/Default.vert | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Assets/Shaders/Default.frag b/Assets/Shaders/Default.frag index c7dfc5cdfe0f056d1172d9da1b193fd905b713d7..1539d01d3fdf980ae712bfcefc33b22c1be07499 100644 GIT binary patch delta 355 zcmYjNI|{-;6nvW)Kg3m|(L@5`uT3ckqOB(o5o|0hQkX^&I}7muA*I*x7#_k42+l|X zJ{b1RykYk3KFybc^H!Dz z-o(i~Za{wvC$p&2PtGl%r8gCB=g^qt0L&q$w++y@#yjyv(gEn9e$O-yeHGwrfj#+E J)ILa`0$&+^7773W delta 81 zcmcb^dW4ymnMs+Qfq{{Mn}L^scOtK;I6DIi0|OZ6CT8XVnGBpj%snx7_GA%8g~=(5 Y1(QRVbVTeJn86Y}K*_&A{T4tB0M2y_EC2ui diff --git a/Assets/Shaders/Default.vert b/Assets/Shaders/Default.vert index 59106298db39ebcf3fa8f47fbaf6a9c31f383144..99ed1c40fd192effcd3d4846345a95900f2dc569 100644 GIT binary patch delta 770 zcmZ8fO;5r=6nxu4!C(^uF~(pJ#GB!WUwkMQ1#d(nS3?XjO%M(gJ#zMD(?6o&=+UFU z!XM$ukT|n#J-Es6cIM5#_qNMx_9bVVMmZ&-BqO$TeY>hweW$dtFCqs(^Ud|uc0$M} zGwNwCCunI!f)C@z3Fj+7Q9uV3I6Jwaxhd?- zeHUlrNi*PFS_{6++&p$M!#QI&_tX+V2N}*2RtskZMcvRJ&x(&KYyY$|I2R}6{3Xr) zxFtIj7SD-yH7~+b1!HfXt3{kIL5+MDkvHY7*TIhvivZVN#E-FOeha*YXaUp;d^tqU zNsT#zeH$WIx(N+z1VQ*fY+S%EFPR2tK1Jlmphhow3!ujQS+q|tzO7F+Z$RRG4gviS zLpk1wyoIkwyQB9aSw#BTsvYU%ocSCm0zS@=UjXz_XPpXS2jJMO(?lO|TN{_6&``-Q DRLDTS delta 658 zcmXv~T}uK%6umP$u7OCQM1-|y^%BubV69oEY1m8POTLPP#DX7zR*%s?XxZNp6h8J7 z`T_lz2s&qHci?dEJ@?F=bLXx2QOG-bH!GqfCwaLF^Hr4#+m+0zh;%+Dp>kaDqiwyh z>4V|99}jx7d9Vm(Q*kAW?u{-fKMHhdK#gNH?Z@%B6U-OG>D@>&U^$T|BSz|o{b2OW z+6BX!XEI#$dx+GZ$BfN8$cML2(U1OJb%d{I;2JtVQl>Z|qkvoz;|_AF$k9{EF(+q$ zE;@YMPP4vHVy@MvzVJb^mU7XnDelu<1>oso7VDk3vNauhfL^|vFZHqxNfl)o;5kU@ zW8^fxh57{11;}~GxD+2I#~x9Ju7=1Z*smuwKbM@BEVP20+A~BfcNA|)F$sF*#uPM? zoEO;NL!@`LtYyE|LknL)$pye`g*Y0aya`y|#6DZ7%Rq=b^nD350rH%4h}Z_`m2(>K M%9^@AQP@YxKh2srhX4Qo diff --git a/Lib/Src/Glsl/Default.frag b/Lib/Src/Glsl/Default.frag index 2881601..a9e0c05 100644 --- a/Lib/Src/Glsl/Default.frag +++ b/Lib/Src/Glsl/Default.frag @@ -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); } diff --git a/Lib/Src/Glsl/Default.vert b/Lib/Src/Glsl/Default.vert index fce546a..ab94e9b 100644 --- a/Lib/Src/Glsl/Default.vert +++ b/Lib/Src/Glsl/Default.vert @@ -21,6 +21,7 @@ layout (set = 0, binding = 1) readonly buffer Instances }; layout (location = 0) out vec4 outColour; +layout (location = 1) out vec2 outUv; void main() { @@ -29,6 +30,7 @@ void main() const vec4 worldPos = instance.model * vec4(aPos, 0.0, 1.0); outColour = aColour * instance.tint; + outUv = aUv; gl_Position = matVP * worldPos; } From 1d63314362209129276c33606fbbffa5fc91f102 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:30:41 -0800 Subject: [PATCH 7/8] Demonstrate RGBM texture --- App/Src/Main.cpp | 12 +++++++++++- Lib/Include/Tkge/Engine.hpp | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/App/Src/Main.cpp b/App/Src/Main.cpp index deeb249..bb9b436 100644 --- a/App/Src/Main.cpp +++ b/App/Src/Main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,16 @@ namespace auto quad = Tkge::Graphics::Quad{}; quad.Create(glm::vec2{400.0f}); quad.transform.position.x = -250.0f; - quad.tint = kvf::magenta_v; + + auto colourBitmap = kvf::ColorBitmap{glm::ivec2{2, 2}}; + colourBitmap[0, 0] = kvf::red_v; + colourBitmap[0, 1] = kvf::green_v; + colourBitmap[1, 0] = kvf::blue_v; + colourBitmap[1, 1] = kvf::magenta_v; + auto texture = Tkge::Graphics::Texture{&engine.RenderDevice()}; + texture.Create(colourBitmap.bitmap()); + texture.sampler.filter = vk::Filter::eNearest; + quad.texture = &texture; auto instancedQuad = Tkge::Graphics::InstancedQuad{}; instancedQuad.Create(glm::vec2{150.0f}); diff --git a/Lib/Include/Tkge/Engine.hpp b/Lib/Include/Tkge/Engine.hpp index 9444b4e..7e1251b 100644 --- a/Lib/Include/Tkge/Engine.hpp +++ b/Lib/Include/Tkge/Engine.hpp @@ -25,6 +25,7 @@ namespace Tkge explicit Engine(const WindowSurface& surface = {}, vk::SampleCountFlagBits aa = AntiAliasing); [[nodiscard]] const kvf::RenderDevice& RenderDevice() const { return _renderDevice; } + [[nodiscard]] kvf::RenderDevice& RenderDevice() { return _renderDevice; } [[nodiscard]] glm::ivec2 FramebufferSize() const; [[nodiscard]] auto FramebufferFormat() const -> vk::Format { return _renderPass.get_color_format(); } From a953e0528ecd530d3ecdc72836cc79b825a7ab07 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Mon, 17 Feb 2025 11:43:27 -0800 Subject: [PATCH 8/8] RGBM ordering --- App/Src/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/App/Src/Main.cpp b/App/Src/Main.cpp index bb9b436..ff35718 100644 --- a/App/Src/Main.cpp +++ b/App/Src/Main.cpp @@ -60,8 +60,8 @@ namespace auto colourBitmap = kvf::ColorBitmap{glm::ivec2{2, 2}}; colourBitmap[0, 0] = kvf::red_v; - colourBitmap[0, 1] = kvf::green_v; - colourBitmap[1, 0] = kvf::blue_v; + colourBitmap[1, 0] = kvf::green_v; + colourBitmap[0, 1] = kvf::blue_v; colourBitmap[1, 1] = kvf::magenta_v; auto texture = Tkge::Graphics::Texture{&engine.RenderDevice()}; texture.Create(colourBitmap.bitmap());