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

Add a dynamic blending sample for VK_EXT_extended_dynamic_state3 #746

Merged
merged 5 commits into from
Sep 25, 2023
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
9 changes: 9 additions & 0 deletions framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,15 @@ bool Drawer::checkbox(const char *caption, int32_t *value)
return res;
}

bool Drawer::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 Drawer::input_float(const char *caption, float *value, float step, uint32_t precision)
{
bool res = ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
Expand Down
36 changes: 9 additions & 27 deletions framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ 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);
Krzysztof-Dmitruk-Mobica marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Adds a number input field to the gui
* @param caption The text to display
Expand Down Expand Up @@ -179,33 +188,6 @@ class Drawer
*/
void text(const char *formatstr, ...);

/**
* @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.
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
6 changes: 6 additions & 0 deletions samples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ Demonstrates how a mesh shader can be used to achieve the same results as with g

Demonstrate how to use shader objects.

=== xref:./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.

=== xref:./extensions/dynamic_line_rasterization/README.adoc[Dynamic line rasterization]

*Extensions:* https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_line_rasterization.html[`VK_EXT_line_rasterization`], https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state3.html[`VK_EXT_extended_dynamic_state3`]
Expand Down
31 changes: 31 additions & 0 deletions samples/extensions/dynamic_blending/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.
#

get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)

add_sample(
ID ${FOLDER_NAME}
CATEGORY ${CATEGORY_NAME}
AUTHOR "Khronos"
NAME "dynamic_blending"
DESCRIPTION "Dynamic blending options available in the VK_EXT_extended_dynamic_state3 extension."
SHADER_FILES_GLSL
"dynamic_blending/blending.vert"
"dynamic_blending/blending.frag"
)
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 blending on 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
Loading
Loading