Skip to content

Commit

Permalink
Added IContext::getAspectRatio()
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Oct 6, 2024
1 parent c3a240b commit 53f5f00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lvk/LVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ class IContext {
virtual Result upload(TextureHandle handle, const TextureRangeDesc& range, const void* data) = 0;
virtual Result download(TextureHandle handle, const TextureRangeDesc& range, void* outData) = 0;
[[nodiscard]] virtual Dimensions getDimensions(TextureHandle handle) const = 0;
[[nodiscard]] virtual float getAspectRatio(TextureHandle handle) const = 0;
[[nodiscard]] virtual Format getFormat(TextureHandle handle) const = 0;
#pragma endregion

Expand Down
16 changes: 16 additions & 0 deletions lvk/vulkan/VulkanClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5102,6 +5102,22 @@ lvk::Dimensions lvk::VulkanContext::getDimensions(TextureHandle handle) const {
};
}

float lvk::VulkanContext::getAspectRatio(TextureHandle handle) const {
if (!handle) {
return 1.0f;
}

const lvk::VulkanImage* tex = texturesPool_.get(handle);

LVK_ASSERT(tex);

if (!tex) {
return 1.0f;
}

return static_cast<float>(tex->vkExtent_.width) / static_cast<float>(tex->vkExtent_.height);
}

void lvk::VulkanContext::generateMipmap(TextureHandle handle) const {
if (handle.empty()) {
return;
Expand Down
1 change: 1 addition & 0 deletions lvk/vulkan/VulkanClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ class VulkanContext final : public IContext {
Result upload(TextureHandle handle, const TextureRangeDesc& range, const void* data) override;
Result download(TextureHandle handle, const TextureRangeDesc& range, void* outData) override;
Dimensions getDimensions(TextureHandle handle) const override;
float getAspectRatio(TextureHandle handle) const override;
Format getFormat(TextureHandle handle) const override;

TextureHandle getCurrentSwapchainTexture() override;
Expand Down

0 comments on commit 53f5f00

Please sign in to comment.