Skip to content

Commit

Permalink
Update dynamic blending sample
Browse files Browse the repository at this point in the history
Add blend equadion extension support
Add blend advanced extension support
  • Loading branch information
Krzysztof-Dmitruk-Mobica authored and kdmitruk committed Jul 15, 2023
1 parent 9e29c42 commit 0776cc0
Show file tree
Hide file tree
Showing 9 changed files with 788 additions and 490 deletions.
55 changes: 48 additions & 7 deletions framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,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 Expand Up @@ -1245,16 +1254,48 @@ void Drawer::text(const char *formatstr, ...)
va_end(args);
}

bool Drawer::color_picker(const char *caption, float *color, ImGuiColorEditFlags flags, uint16_t width)
bool Drawer::color_picker(const char *caption, std::array<float, 3> &color, float width, ImGuiColorEditFlags flags)
{
bool res = ImGui::ColorEdit4(caption, color, flags);
if (res)
{
dirty = true;
};
return res;
bool res;
ImGui::PushItemWidth(width);
res = ImGui::ColorPicker3(caption, color.data(), flags);
ImGui::PopItemWidth();
if (res)
dirty = true;
return res;
}

bool Drawer::color_picker(const char *caption, std::array<float, 4> &color, float width, ImGuiColorEditFlags flags)
{
bool res;
ImGui::PushItemWidth(width);
res = ImGui::ColorPicker4(caption, color.data(), flags);
ImGui::PopItemWidth();
if (res)
dirty = true;
return res;
}

bool Drawer::color_edit(const char *caption, std::array<float, 3> &color, float width, ImGuiColorEditFlags flags)
{
bool res;
ImGui::PushItemWidth(width);
res = ImGui::ColorEdit3(caption, color.data(), flags);
ImGui::PopItemWidth();
if (res)
dirty = true;
return res;
}

bool Drawer::color_edit(const char *caption, std::array<float, 4> &color, float width, ImGuiColorEditFlags flags)
{
bool res;
ImGui::PushItemWidth(width);
res = ImGui::ColorEdit4(caption, color.data(), flags);
ImGui::PopItemWidth();
if (res)
dirty = true;
return res;
}

} // namespace vkb
38 changes: 37 additions & 1 deletion framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class Drawer
*/
bool checkbox(const char *caption, int32_t *value);

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 Expand Up @@ -173,7 +175,41 @@ class Drawer
*/
void text(const char *formatstr, ...);

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
* @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);

private:
bool dirty{false};
Expand Down
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set(ORDER_LIST
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"dynamic_blending"

#Performance Samples
"swapchain_images"
Expand Down
4 changes: 4 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ Demonstrate how to create multiple color blend attachments and then toggle them
**Extension:** [```VK_EXT_mesh_shader```](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_mesh_shader.html)<br/>
Demonstrates how a mesh shader can be used to achieve the same results as with geometry shader, it loads model from a file and visualizes its normals.

### [Dynamic blending](./extensions/dynamic_blending)<br/>
**Extension**: [```VK_EXT_extended_dynamic_state3```](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state.html)<br/>

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

## Tooling Samples

Expand Down
51 changes: 51 additions & 0 deletions samples/extensions/dynamic_blending/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
- 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.
-
-->

# Color write enable
## 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 extensions `VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME` and `VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME` need to be enabled.
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 and array of VkColorBlendEquationEXT objectswhich determine operators and factors for color and alpha blending.
The `vkCmdSetColorBlendAdvancedEXT` function expects and array of VkColorBlendAdvancedEXT objects, which determine blending operators and premultiplication for color blending.
The `vkCmdSetColorWriteMaskEXT` function expects and array of VkColorComponentFlags objects. These objects can be created by combining the desired color bit flags using bitwise addition.

## 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/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/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/vkCmdSetColorBlendAdvancedEXT.html)

[https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorWriteMaskEXT.html](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetColorWriteMaskEXT.html)

Loading

0 comments on commit 0776cc0

Please sign in to comment.