Skip to content

Commit

Permalink
Fix according to the review
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Dmitruk-Mobica committed Aug 21, 2023
1 parent 8a68e42 commit a3558e4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 42 deletions.
59 changes: 21 additions & 38 deletions framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ class Drawer
*/
bool checkbox(const char *caption, int32_t *value);

/**
* @brief Adds a radio button to the gui
* @param caption The text to display
* @param selectedOption The pointer to the variable set using the radio button.
* @param elementOption Value set to the selectedOption when the button is selected.
* @returns True if adding item was successful
*/
bool radio_button(const char *caption, int32_t *selectedOption, const int32_t elementOption);

/**
Expand Down Expand Up @@ -181,51 +188,27 @@ class Drawer
*/
void text(const char *formatstr, ...);

<<<<<<< HEAD
/**
* @brief Adds a color picker to the gui
* @param caption The text to display
* @param color Color channel array on which the picker works. It contains values ranging from 0 to 1.
* @param flags Flags for modifying the appearance and behavior of the element. A zero value will result in a width determined by ImGui.
*/
bool color_picker(const char *caption, float *color, ImGuiColorEditFlags flags, uint16_t width = 0);
=======
/**
* @brief Adds a color picker to the gui
* @param caption The text to display
* @param color Color channel array on which the picker works. It contains values ranging from 0 to 1.
* @param width Element width. Zero is a special value for the default element width.
* @param flags Flags to modify the appearance and behavior of the element.
*/
bool color_picker(const char *caption, std::array<float, 3> &color, float width = 0.0f, ImGuiColorEditFlags flags = 0);

/**
* @brief Adds a color picker to the gui
* @param caption The text to display
* @param color Color channel array on which the picker works. It contains values ranging from 0 to 1.
* @param width Element width. Zero is a special value for the default element width.
* @param flags Flags to modify the appearance and behavior of the element.
*/
bool color_picker(const char *caption, std::array<float, 4> &color, float width = 0.0f, ImGuiColorEditFlags flags = 0);

/**
* @brief Adds a color edit to the gui
* @param caption The text to display
* @param color Color channel array on which the picker works. It contains values ranging from 0 to 1.
* @param width Element width. Zero is a special value for the default element width.
* @param flags Flags to modify the appearance and behavior of the element.
*/
bool color_edit(const char *caption, std::array<float, 3> &color, float width = 0.0f, ImGuiColorEditFlags flags = 0);

/**
* @brief Adds a color edit to the gui
* @tparam OP Mode of the color element.
* @tparam N Color channel count. Must be 3 or 4.
* @param caption The text to display
* @param color Color channel array on which the picker works. It contains values ranging from 0 to 1.
* @param width Element width. Zero is a special value for the default element width.
* @param flags Flags to modify the appearance and behavior of the element.
*/
bool color_edit(const char *caption, std::array<float, 4> &color, float width = 0.0f, ImGuiColorEditFlags flags = 0);
>>>>>>> 0d71460 (Update dynamic blending sample)
template <ColorOp OP, size_t N>
bool color_op(const std::string &caption, std::array<float, N> &color, float width = 0.0f, ImGuiColorEditFlags flags = 0)
{
static_assert((N == 3) || (N == 4), "The channel count must be 3 or 4.");

ImGui::PushItemWidth(width);
bool res = color_op_impl<OP, N>(caption.c_str(), color.data(), flags);
ImGui::PopItemWidth();
if (res)
dirty = true;
return res;
}

private:
template <ColorOp OP, size_t N>
Expand Down
9 changes: 9 additions & 0 deletions framework/hpp_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,15 @@ bool HPPDrawer::checkbox(const std::string &caption, int32_t *value)
return res;
}

bool HPPDrawer::radio_button(const char *caption, int32_t *selectedOption, const int32_t elementOption)
{
bool res = ImGui::RadioButton(caption, selectedOption, elementOption);
if (res)
dirty = true;

return res;
}

bool HPPDrawer::input_float(const std::string &caption, float *value, float step, uint32_t precision)
{
bool res = ImGui::InputFloat(caption.c_str(), value, step, step * 10.0f, precision);
Expand Down
9 changes: 9 additions & 0 deletions framework/hpp_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ class HPPDrawer
*/
bool checkbox(const std::string &caption, int32_t *value);

/**
* @brief Adds a radio button to the gui
* @param caption The text to display
* @param selectedOption The pointer to the variable set using the radio button.
* @param elementOption Value set to the selectedOption when the button is selected.
* @returns True if adding item was successful
*/
bool radio_button(const char *caption, int32_t *selectedOption, const int32_t elementOption);

/**
* @brief Adds a number input field to the gui
* @param caption The text to display
Expand Down
5 changes: 5 additions & 0 deletions samples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ Demonstrate how to create multiple color blend attachments and then toggle them

Demonstrate how to use shader objects.

=== link:./extensions/dynamic_blending[Dynamic blending]
*Extension:* https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state.html[`VK_EXT_extended_dynamic_state3`]

Demonstrate how to use the blending related functions available in the VK_EXT_extended_dynamic_state3 extension.

== Tooling Samples

The goal of these samples is to demonstrate usage of tooling functions and libraries that are not directly part of the api.
Expand Down
4 changes: 2 additions & 2 deletions samples/extensions/dynamic_blending/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019, Arm Limited and Contributors
# Copyright (c) 2023, Mobica Limited
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -24,7 +24,7 @@ add_sample(
CATEGORY ${CATEGORY_NAME}
AUTHOR "Khronos"
NAME "dynamic_blending"
DESCRIPTION "Sample description"
DESCRIPTION "Dynamic blending options available in the VK_EXT_extended_dynamic_state3 extension."
SHADER_FILES_GLSL
"dynamic_blending/blending.vert"
"dynamic_blending/blending.frag"
Expand Down
67 changes: 67 additions & 0 deletions samples/extensions/dynamic_blending/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
////
- Copyright (c) 2023, Mobica Limited
-
- SPDX-License-Identifier: Apache-2.0
-
- Licensed under the Apache License, Version 2.0 the "License";
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
////
== Dynamic blending

=== Overview

This sample demonstrates the functionality of VK_EXT_extended_dynamic_state3 related to blending. It includes the
following features:

* `+vkCmdSetColorBlendEnableEXT+`: toggles blendingon and off.
* `+vkCmdSetColorBlendEquationEXT+`: modifies blending operators and factors.
* `+vkCmdSetColorBlendAdvancedEXT+`: utilizes more complex blending operators.
* `+vkCmdSetColorWriteMaskEXT+`: toggles individual channels on and off.

=== How to use in Vulkan

To utilize this feature, the device extension `+VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME+` need to be enabled.
The extension `+VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME+` is required for the advanced blend equations.
All presented functions take an array of objects defining their action for subsequent color attachments:

* The `+vkCmdSetColorBlendEnableEXT+`
function expects an array of booleans to toggle blending.
* The `+vkCmdSetColorBlendEquationEXT+` function expects an array of
`+VkColorBlendEquationEXT+` objects which determine operators and factors for
color and alpha blending.
* The `+vkCmdSetColorBlendAdvancedEXT+` function expects an array of `+VkColorBlendAdvancedEXT+` objects, which determine
blending operators and premultiplication for color blending.
* The `+vkCmdSetColorWriteMaskEXT+` function expects an array of
`+VkColorComponentFlags+` objects. These objects can be created by combining
the desired color bit flags using bitwise oring.

=== The sample

The sample demonstrates how to set up an application to work with this
extension:

* Enabling the extension.
* Setting parameters for the presented methods.

The sample demonstrates how the use of each operator affects color blending.

=== Documentation links

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorBlendEnableEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorBlendEquationEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorBlendAdvancedEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorWriteMaskEXT.html
5 changes: 3 additions & 2 deletions samples/extensions/dynamic_blending/dynamic_blending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void DynamicBlending::setup_descriptor_pool()
vkb::initializers::descriptor_pool_create_info(
static_cast<uint32_t>(pool_sizes.size()),
pool_sizes.data(),
pool_sizes.size());
static_cast<uint32_t>(pool_sizes.size()));
VK_CHECK(vkCreateDescriptorPool(get_device().get_handle(), &descriptor_pool_create_info, nullptr, &descriptor_pool));
}

Expand Down Expand Up @@ -477,7 +477,8 @@ void DynamicBlending::on_update_ui_overlay(vkb::Drawer &drawer)
ImGuiColorEditFlags flags = ImGuiColorEditFlags_None | ImGuiColorEditFlags_Float;
float color_edit_width = 200;
ImGui::PushID(++item_id);
if (drawer.color_edit(caption, color, color_edit_width, flags))
if (drawer.color_op<vkb::Drawer::ColorOp::Edit>(caption, color, color_edit_width, flags))
// if (drawer.color_edit(caption, color, color_edit_width, flags))
{
update_color_uniform();
}
Expand Down

0 comments on commit a3558e4

Please sign in to comment.