diff options
author | rtk0c <[email protected]> | 2022-04-18 20:59:57 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-18 20:59:57 -0700 |
commit | 07e8754e4d799e44678b595177e79e6eaa621268 (patch) | |
tree | 6d9d4470259776ef01e814191ba0440f83505933 /source/EditorCore.cpp | |
parent | 7f871b04470766f0f5266cf949b65a54b7a6f79e (diff) |
Changeset: 11 Migrate Material to Ires
Diffstat (limited to 'source/EditorCore.cpp')
-rw-r--r-- | source/EditorCore.cpp | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/source/EditorCore.cpp b/source/EditorCore.cpp index 11eea8a..1be6418 100644 --- a/source/EditorCore.cpp +++ b/source/EditorCore.cpp @@ -69,9 +69,6 @@ void EditorContentBrowser::Show(bool* open) { if (ImGui::Selectable("Shaders", mPane == P_Shader)) { mPane = P_Shader; } - if (ImGui::Selectable("Materials", mPane == P_Material)) { - mPane = P_Material; - } if (ImGui::Selectable("Ires", mPane == P_Ires)) { mPane = P_Ires; } @@ -117,49 +114,6 @@ void EditorContentBrowser::Show(bool* open) { } } break; - case P_Material: { - if (ImGui::Button("New")) { - int n = std::rand(); - auto mat = new Material("Unnamed Material " + std::to_string(n)); - auto guard = GuardDeletion(mat); - auto [DISCARD, inserted] = MaterialManager::instance->SaveMaterial(mat); - if (inserted) { - guard.Dismiss(); - } else { - ImGui::AddNotification(ImGuiToast(ImGuiToastType_Error, "Failed to create material.")); - } - } - ImGui::SameLine(); - if (ImGui::Button("Refresh")) { - // TODO - } - ImGui::SameLine(); - if (ImGui::Button("Save all")) { - auto& mats = MaterialManager::instance->GetMaterials(); - for (auto&& [DISCARD, mat] : mats) { - mat->SaveToFile(mat->GetDesignatedPath()); - } - } - - auto& mats = MaterialManager::instance->GetMaterials(); - for (auto it = mats.begin(); it != mats.end(); ++it) { - auto mat = it->second.Get(); - auto& name = mat->GetName(); - - bool selected = mInspector->selectedItPtr == mat; - if (ImGui::Selectable(name.c_str(), selected)) { - mInspector->SelectTarget(EditorInspector::ITT_Material, mat); - } - - if (ImGui::BeginDragDropSource()) { - // Reason: intentionally using pointer as payload - ImGui::SetDragDropPayload(BRUSSEL_TAG_Material, &mat, sizeof(mat)); // NOLINT(bugprone-sizeof-expression) - ImGui::Text("Material '%s'", name.c_str()); - ImGui::EndDragDropSource(); - } - } - } break; - case P_Ires: { auto itt = mInspector->selectedItt; auto itPtr = mInspector->selectedItPtr; @@ -311,20 +265,6 @@ void ShowShaderName(const Shader* shader) { ImGui::TextUnformatted("Shader: <null>"); } } - -void ShowMaterialName(const Material* material) { - if (material) { - auto& name = material->GetName(); - bool isAnnoymous = name.empty(); - if (isAnnoymous) { - ImGui::Text("Material: <annoymous at %p>", (void*)material); - } else { - ImGui::Text("Material: %s", name.c_str()); - } - } else { - ImGui::TextUnformatted("Material: <null>"); - } -} } // namespace ProjectBrussel_UNITY_ID EditorInstance::EditorInstance(App* app, GameWorld* world) @@ -361,10 +301,6 @@ void EditorInstance::Show() { ShowInspector(static_cast<Shader*>(mEdInspector.selectedItPtr)); } break; - case EditorInspector::ITT_Material: { - ShowInspector(static_cast<Material*>(mEdInspector.selectedItPtr)); - } break; - case EditorInspector::ITT_Ires: { auto ires = static_cast<IresObject*>(mEdInspector.selectedItPtr); ShowInspector(ires); @@ -433,119 +369,6 @@ void EditorInstance::ShowInspector(Shader* shader) { } } -void EditorInstance::ShowInspector(Material* material) { - using namespace Tags; - using namespace ProjectBrussel_UNITY_ID; - - EaMaterial* attachment; - if (auto ea = material->GetEditorAttachment()) { - attachment = static_cast<EaMaterial*>(ea); - } else { - attachment = new EaMaterial(); - material->SetEditorAttachment(attachment); - } - - auto& name = material->GetName(); - bool isAnnoymous = name.empty(); - if (isAnnoymous) { - ImGui::Text("<Annoymous Material at %p>", (void*)(&material)); - } else { - if (attachment->isEditingName) { - bool save = false; - save |= ImGui::InputText("##", &attachment->editingScratch, ImGuiInputTextFlags_EnterReturnsTrue); - ImGui::SameLine(); - save |= ImGui::Button("Save"); - if (save) { - bool success = MaterialManager::instance->RenameMaterial(material, attachment->editingScratch); - if (success) { - attachment->isEditingName = false; - } - } - ImGui::SameLine(); - if (ImGui::Button("Cancel")) { - attachment->isEditingName = false; - } - } else { - // NOTE: ReadOnly shouldn't write any data into the buffer - ImGui::InputText("##", material->mName.data(), name.size() + 1, ImGuiInputTextFlags_ReadOnly); - ImGui::SameLine(); - if (ImGui::Button("Edit")) { - attachment->editingScratch = name; // Copy - attachment->isEditingName = true; - } - } - } - - auto shader = material->GetShader(); - ShowShaderName(shader); - if (ImGui::BeginDragDropTarget()) { - if (auto payload = ImGui::AcceptDragDropPayload(BRUSSEL_TAG_Shader)) { - auto shader = *static_cast<Shader* const*>(payload->Data); - material->SetShader(shader); - } - ImGui::EndDragDropTarget(); - } - ImGui::SameLine(); - if (ImGui::Button("GoTo", shader == nullptr)) { - mEdInspector.SelectTarget(EditorInspector::ITT_Shader, shader); - } - - if (!shader) return; - auto& info = shader->GetInfo(); - - if (ImGui::Button("Reload", isAnnoymous)) { - material->LoadFromFile(material->GetDesignatedPath()); - } - ImGui::SameLine(); - if (ImGui::Button("Save", isAnnoymous)) { - material->SaveToFile(material->GetDesignatedPath()); - } - - for (auto& field : material->mBoundScalars) { - auto& decl = static_cast<ShaderMathVariable&>(*info.uniforms[field.infoUniformIndex]); - decl.ShowInfo(); - - ImGui::Indent(); - switch (decl.scalarType) { - case GL_FLOAT: ImGui::InputFloat("##", &field.floatValue); break; - case GL_INT: ImGui::InputInt("##", &field.intValue); break; - // TODO proper uint edit? - case GL_UNSIGNED_INT: ImGui::InputInt("##", (int32_t*)(&field.uintValue), 0, std::numeric_limits<int32_t>::max()); break; - default: ImGui::TextUnformatted("Unsupported scalar type"); break; - } - ImGui::Unindent(); - } - for (auto& field : material->mBoundVectors) { - auto& decl = static_cast<ShaderMathVariable&>(*info.uniforms[field.infoUniformIndex]); - decl.ShowInfo(); - - ImGui::Indent(); - switch (decl.semantic) { - case VES_Color1: - case VES_Color2: { - ImGui::ColorEdit4("##", field.value); - } break; - - default: { - ImGui::InputFloat4("##", field.value); - } break; - } - ImGui::Unindent(); - } - for (auto& field : material->mBoundMatrices) { - auto& decl = static_cast<ShaderMathVariable&>(*info.uniforms[field.infoUniformIndex]); - decl.ShowInfo(); - - // TODO - } - for (auto& field : material->mBoundTextures) { - auto& decl = static_cast<ShaderSamplerVariable&>(*info.uniforms[field.infoUniformIndex]); - decl.ShowInfo(); - - // TODO - } -} - void EditorInstance::ShowInspector(IresObject* ires) { ires->ShowEditor(*this); } |