Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic support for sRGB framebuffer usage #71

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.7)

project(vsgImGui
VERSION 0.6.0
VERSION 0.7.0
DESCRIPTION "VulkanSceneGraph, ImGui and ImPlot integration library"
LANGUAGES CXX
)
Expand All @@ -22,7 +22,7 @@ if (VULKAN_SDK)
set(ENV{VULKAN_SDK} ${VULKAN_SDK})
endif()

find_package(vsg 1.0.5)
find_package(vsg 1.1.10)

vsg_setup_dir_vars()
vsg_setup_build_vars()
Expand Down
21 changes: 21 additions & 0 deletions include/vsgImGui/Export.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <vulkan/vulkan.h>
#define ImTextureID VkDescriptorSet

#include <vsg/maths/vec2.h>
#include <vsg/maths/vec4.h>

#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(const vsg::vec2& v) : x(v.x), y(v.y) \
{ \
} \
operator vsg::vec2() const \
{ \
return vsg::vec2(x, y); \
}

#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const vsg::vec4& v) : x(v.x), y(v.y), z(v.z), w(v.w) \
{ \
} \
operator vsg::vec4() const \
{ \
return vsg::vec4(x, y, z, w); \
}
3 changes: 3 additions & 0 deletions include/vsgImGui/RenderImGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace vsgImGui
void _uploadFonts();
};

// temporary workaround for Dear ImGui's nonexistent sRGB awareness
extern VSGIMGUI_DECLSPEC void ImGuiStyle_sRGB_to_linear(ImGuiStyle& style);

} // namespace vsgImGui

EVSG_type_name(vsgImGui::RenderImGui);
35 changes: 34 additions & 1 deletion src/vsgImGui/RenderImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "../imgui/backends/imgui_impl_vulkan.h"

#include <vsg/io/Logger.h>
#include <vsg/maths/color.h>
#include <vsg/utils/CoordinateSpace.h>
#include <vsg/vk/State.h>
#include <vsg/vk/SubmitCommands.h>

Expand Down Expand Up @@ -55,6 +57,15 @@ namespace vsgImGui
}
};

void ImGuiStyle_sRGB_to_linear(ImGuiStyle& style)
{
for (size_t i = 0; i < ImGuiCol_COUNT; ++i)
{
ImVec4& color = style.Colors[i];
color = vsg::sRGB_to_linear<float>(color);
}
}

} // namespace vsgImGui

RenderImGui::RenderImGui(const vsg::ref_ptr<vsg::Window>& window, bool useClearAttachments)
Expand Down Expand Up @@ -118,7 +129,29 @@ void RenderImGui::_init(
VkExtent2D imageSize, bool useClearAttachments)
{
IMGUI_CHECKVERSION();
if (!ImGui::GetCurrentContext()) ImGui::CreateContext();

if (!ImGui::GetCurrentContext())
{
ImGui::CreateContext();
}

bool sRGB = false;
for (auto& attachment : renderPass->attachments)
{
if (attachment.finalLayout==VK_IMAGE_LAYOUT_PRESENT_SRC_KHR || attachment.finalLayout==VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
{
if (attachment.format == VK_FORMAT_B8G8R8_SRGB ||
attachment.format == VK_FORMAT_B8G8R8A8_SRGB ||
attachment.format == VK_FORMAT_R8G8B8_SRGB ||
attachment.format == VK_FORMAT_R8G8B8A8_SRGB) sRGB = true;
}
}

if (sRGB)
{
ImGuiStyle_sRGB_to_linear(ImGui::GetStyle());
}

if (!ImPlot::GetCurrentContext()) ImPlot::CreateContext();

VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
Expand Down