3#include "InspectorGuiHelper.h"
5#include "Resources/MaterialManager.h"
7#include "Resources/MaterialInstance.h"
8#include "Resources/Texture.h"
17 auto& buffer = material->constantBuffers.
buffers[prop.
buffer];
19 case MaterialDataType::Float:
21 float value = buffer.getValue<
float>(prop.
descriptor.offset);
22 if (ImGui::DragFloat(prop.
name.c_str(), &value, 0.01f, 0.0f, 1.0f)) {
23 buffer.setValue(prop.
descriptor.offset, value);
28 case MaterialDataType::Int:
30 int32_t value = buffer.getValue<int32_t>(prop.
descriptor.offset);
31 if (ImGui::DragInt(prop.
name.c_str(), &value, 1.0f, 0, 100)) {
32 buffer.setValue(prop.
descriptor.offset, value);
37 case MaterialDataType::Bool:
39 bool value = buffer.getValue<
bool>(prop.
descriptor.offset);
40 if (ImGui::Checkbox(prop.
name.c_str(), &value)) {
41 buffer.setValue(prop.
descriptor.offset, value);
46 case MaterialDataType::Float2:
48 glm::vec2 value = buffer.getValue<glm::vec2>(prop.
descriptor.offset);
49 if (ImGui::DragFloat2(prop.
name.c_str(), glm::value_ptr(value))) {
50 buffer.setValue(prop.
descriptor.offset, value);
55 case MaterialDataType::Float3:
57 glm::vec3 value = buffer.getValue<glm::vec3>(prop.
descriptor.offset);
58 if (ImGui::DragFloat3(prop.
name.c_str(), glm::value_ptr(value))) {
59 buffer.setValue(prop.
descriptor.offset, value);
64 case MaterialDataType::Float4:
66 glm::vec4 value = buffer.getValue<glm::vec4>(prop.
descriptor.offset);
67 if (ImGui::DragFloat4(prop.
name.c_str(), glm::value_ptr(value))) {
68 buffer.setValue(prop.
descriptor.offset, value);
73 case MaterialDataType::Float4x4:
75 auto value = buffer.getValue<glm::mat4>(prop.
descriptor.offset);
76 if (showMatrix(prop.
name, value)) {
77 buffer.setValue(prop.
descriptor.offset, value);
82 case MaterialDataType::UInt:
84 int32_t value = (int32_t)buffer.getValue<uint32_t>(prop.
descriptor.offset);
85 if (ImGui::DragInt(prop.
name.c_str(), &value, 1.0f, 0, 100)) {
86 buffer.setValue(prop.
descriptor.offset, (uint32_t)value);
92 ImGui::Text(
"Unsupported: %d",
static_cast<int>(prop.
type));
98void showMaterial(
Context * context,
Material * material,
const std::string & header)
100 ImGui::PushID(material);
102 if (ImGui::TreeNode(header.c_str())) {
105 if (!material->constantBuffers.
variables.empty()) {
106 if (ImGui::TreeNode(
"Properties")) {
107 for (
auto & prop : material->constantBuffers.
variables) {
108 ShowPropertiy(material, prop);
113 ImGui::Text(
"Properties: Empty");
116 if (!material->textureProperties.empty() && ImGui::TreeNode(
"Textures")) {
118 for (
auto & prop : material->textureProperties) {
119 if (!prop.texture.handle) {
120 ImGui::Text(
"%s: Empty", prop.
name.c_str());
122 if (ImGui::TreeNode(prop.
name.c_str())) {
135 bool hasSharedVariants =
false;
136 if (!material->definition.variants.empty()) {
139 hasSharedVariants =
true;
144 if (hasSharedVariants && ImGui::TreeNode(
"Variants")) {
146 if (!v.isShared)
continue;
147 size_t value = v.defaultValue;
150 case ShaderVariantType::Enum:
152 std::vector<const char*> enumNames(v.values.size());
154 for (
size_t i = 0; i < v.values.size(); ++i) {
155 enumNames[i] = v.values[i].key.c_str();
158 int currentIndex =
static_cast<int>(value);
159 if (ImGui::Combo(v.name.c_str(), ¤tIndex, enumNames.data(),
static_cast<int>(enumNames.size()))) {
165 case ShaderVariantType::Bool:
166 if (
bool boolean = value != 0; ImGui::Checkbox(v.name.c_str(), &
boolean)) {
171 case ShaderVariantType::Int:
172 if (
int integer =
static_cast<int>(value); ImGui::InputInt(v.name.c_str(), &integer, 1)) {
173 material->setVariant(v.name, integer);
178 case ShaderVariantType::Format:
182 ImGui::Text(
"Unsupported: %s", v.name.c_str());
190 if (!material->constantBuffers.
buffers.empty()) {
191 if (ImGui::TreeNode(
"Buffers")) {
193 for (
auto & buffer : material->constantBuffers.
buffers) {
194 ImGui::Text(
"%s", buffer.name.c_str());
195 ImGui::Text(
" Size: %zu", buffer.size); ImGui::SameLine();
196 ImGui::Text(
" Shared: %s", buffer.isPerInstance ?
"false" :
"true"); ImGui::SameLine();
197 ImGui::Text(
" Gen: %zu", buffer.generation);
199 ImGui::PushID(&buffer);
200 if (!material->constantBuffers.
variables.empty() && ImGui::TreeNode(
"Properties")) {
201 for (
auto& prop : material->constantBuffers.
variables) {
202 if (prop.
buffer != buffer.index)
continue;
203 ShowPropertiy(material, prop);
213 showMaterialOptions(context, &material->
options,
"Options");
221void Cogs::Core::materialInspector(
Context * context,
bool * show)
224 ImGui::SetNextWindowSize(ImVec2(600, 1000), ImGuiCond_Once);
226 std::vector<Cogs::Core::ResourceBase*> materials = context->materialManager->getAllocatedResources();
227 guiBegin(
"Materials " + std::to_string(materials.size()), show);
230 for (
auto & m : materials) {
231 auto material =
static_cast<Material *
>(m);
232 std::string header = (!material->
getName().
empty() ? std::string(material->
getName()) :
"Material " +
std::to_string(id++));
233 showMaterial(context, material, header);
241void Cogs::Core::materialInstanceInspector(
Context* context,
bool* show)
244 ImGui::SetNextWindowSize(ImVec2(600, 1000), ImGuiCond_Once);
246 std::vector<Cogs::Core::ResourceBase*> materials = context->materialInstanceManager->getAllocatedResources();
247 guiBegin(
"Material Instances " + std::to_string(materials.size()), show);
250 for (
auto& m : materials) {
252 std::string header = (!material->
getName().
empty() ? std::string(material->
getName()) :
"Material " +
std::to_string(id++));
253 showMaterialInstance(context, material, header);
A Context instance contains all the services, systems and runtime components needed to use Cogs.
class IRenderer * renderer
Renderer.
constexpr bool empty() const noexcept
Check if the string is empty.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
std::vector< MaterialPropertyBuffer > buffers
Constant buffer instances.
std::vector< MaterialProperty > variables
Individual variables from all buffer instances.
Material instances represent a specialized Material combined with state for all its buffers and prope...
Defines a single material property.
MaterialPropertyDescriptor descriptor
Property descriptor.
ConstantBufferKey buffer
Key to the buffer the property value is stored in.
PropertyName name
Name of the property, used to reference named uniforms of constant buffer members in shaders.
MaterialDataType type
Type of data held by property.
Material resources define the how of geometry rendering (the what is defined by Mesh and Texture reso...
MaterialOptions options
Material rendering options.
StringView getName() const
Get the name of the resource.