From d43508ba4843801cbbf1f42a27af260d4eef5701 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Sun, 17 Apr 2022 20:08:57 -0700 Subject: Initial work on sprites and texture system --- source/EditorCore.cpp | 169 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 132 insertions(+), 37 deletions(-) (limited to 'source/EditorCore.cpp') diff --git a/source/EditorCore.cpp b/source/EditorCore.cpp index 1846962..0c2e6a2 100644 --- a/source/EditorCore.cpp +++ b/source/EditorCore.cpp @@ -97,6 +97,7 @@ void EditorInstance::Show() { case ITT_GameObject: ShowInspector(static_cast(mSelectedItPtr)); break; case ITT_Shader: ShowInspector(static_cast(mSelectedItPtr)); break; case ITT_Material: ShowInspector(static_cast(mSelectedItPtr)); break; + case ITT_Ires: ShowInspector("", static_cast(mSelectedItPtr)); break; // TODO case ITT_None: break; } ImGui::End(); @@ -104,6 +105,8 @@ void EditorInstance::Show() { if (mEdContentBrowserVisible) { mEdContentBrowser.Show(&mEdContentBrowserVisible); } + + ShowSpriteViewer(); } void EditorInstance::SelectIt(void* ptr, InspectorTargetType itt) { @@ -129,50 +132,37 @@ void EditorInstance::ShowInspector(Shader* shader) { shader->SetEditorAttachment(attachment); } - auto info = shader->GetInfo(); - if (!info) { - ImGui::TextUnformatted("No info present for this shader."); - if (ImGui::Button("Create empty info")) { - shader->CreateEmptyInfoIfAbsent(); - } - if (ImGui::Button("Gather info")) { - shader->GatherInfoIfAbsent(); - } - return; - } - + auto& info = shader->GetInfo(); auto& name = shader->GetName(); bool isAnnoymous = name.empty(); ShowShaderName(shader); - if (ImGui::Button("Reimport metadata", isAnnoymous)) { - info->LoadFromFile(shader->GetDesignatedMetadataPath()); + if (ImGui::Button("Reload metadata", isAnnoymous)) { + shader->LoadMetadataFromFile(shader->GetDesignatedMetadataPath()); + } + ImGui::SameLine(); + if (ImGui::Button("Save metadata", isAnnoymous)) { + shader->SaveMetadataToFile(shader->GetDesignatedMetadataPath()); } ImGui::SameLine(); - if (ImGui::Button("Export metadata", isAnnoymous)) { - info->SaveToFile(shader->GetDesignatedMetadataPath()); + if (ImGui::Button("Gather info")) { + shader->GatherInfoShaderIntrospection(); } - auto ShowThing = [&](const std::vector& things) { - for (auto& thing : things) { - ImGui::BulletText("Location %d\nName: %s\nSemantic: %s\nType: %s %dx%d", - thing.variable.location, - thing.variable.name.c_str(), - Tags::NameOf(thing.semantic).data(), - Tags::NameOfGLType(thing.variable.scalarType).data(), - thing.variable.width, - thing.variable.height); - } - }; if (ImGui::CollapsingHeader("Inputs")) { - ShowThing(info->inputs); + for (auto& input : info.inputs) { + input.ShowInfo(); + } } if (ImGui::CollapsingHeader("Outputs")) { - ShowThing(info->outputs); + for (auto& output : info.outputs) { + output.ShowInfo(); + } } if (ImGui::CollapsingHeader("Uniforms")) { - } - if (ImGui::CollapsingHeader("Uniform blocks")) { + for (auto& uniform : info.uniforms) { + uniform->ShowInfo(); + } } } @@ -190,8 +180,6 @@ void EditorInstance::ShowInspector(Material* material) { auto& name = material->GetName(); bool isAnnoymous = name.empty(); - auto shader = material->GetShader(); - if (isAnnoymous) { ImGui::Text("", (void*)(&material)); } else { @@ -210,8 +198,6 @@ void EditorInstance::ShowInspector(Material* material) { if (ImGui::Button("Cancel")) { attachment->isEditingName = false; } - - ImGui::Text("%s", attachment->editingScratch.c_str()); } else { // NOTE: ReadOnly shouldn't write any data into the buffer ImGui::InputText("##", material->mName.data(), name.size() + 1, ImGuiInputTextFlags_ReadOnly); @@ -223,6 +209,7 @@ void EditorInstance::ShowInspector(Material* material) { } } + auto shader = material->GetShader(); ShowShaderName(shader); if (ImGui::BeginDragDropTarget()) { if (auto payload = ImGui::AcceptDragDropPayload(BRUSSEL_DRAG_DROP_SHADER)) { @@ -237,6 +224,9 @@ void EditorInstance::ShowInspector(Material* material) { mSelectedItPtr = shader; } + if (!shader) return; + auto& info = shader->GetInfo(); + if (ImGui::Button("Reload", isAnnoymous)) { material->LoadFromFile(material->GetDesignatedPath()); } @@ -246,19 +236,112 @@ void EditorInstance::ShowInspector(Material* material) { } for (auto& field : material->mBoundScalars) { - // TODO + auto& decl = static_cast(*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::max()); break; + default: ImGui::TextUnformatted("Unsupported scalar type"); break; + } + ImGui::Unindent(); } for (auto& field : material->mBoundVectors) { - // TODO + auto& decl = static_cast(*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(*info.uniforms[field.infoUniformIndex]); + decl.ShowInfo(); + // TODO } for (auto& field : material->mBoundTextures) { + auto& decl = static_cast(*info.uniforms[field.infoUniformIndex]); + decl.ShowInfo(); + // TODO } } +void EditorInstance::ShowInspector(const std::string& path, IresObject* genericIres) { + ImGui::Text("%s", path.c_str()); + + switch (genericIres->GetKind()) { + case IresObject::KD_Texture: { + ImGui::TextUnformatted("Texture"); + ImGui::Separator(); + + // TODO + ImGui::TextUnformatted("Unimplemented"); + } break; + + case IresObject::KD_SpriteFiles: { + ImGui::TextUnformatted("Sprite Files"); + ImGui::Separator(); + + // TODO + ImGui::TextUnformatted("Unimplemented"); + } break; + + case IresObject::KD_Spritesheet: { + ImGui::TextUnformatted("Spritesheet"); + ImGui::Separator(); + + auto& ires = *static_cast(genericIres); + auto instance = ires.GetInstance(); // NOTE: may be null + + if (ImGui::Button("View Sprite", instance == nullptr)) { + OpenSpriteViewer(instance); + } + + bool doInvalidateInstance = false; + if (ImGui::InputText("Spritesheet", &ires.spritesheetFile)) { + doInvalidateInstance = true; + } + if (ImGui::InputInt("Horizontal Split", &ires.sheetWSplit)) { + if (instance) IresSpritesheet::ResplitSpritesheet(instance, ires.sheetWSplit, ires.sheetHSplit); + } + if (ImGui::InputInt("Vertical Split", &ires.sheetHSplit)) { + if (instance) IresSpritesheet::ResplitSpritesheet(instance, ires.sheetWSplit, ires.sheetHSplit); + } + + if (instance) { + auto atlas = instance->GetAtlas(); + auto aspectRatio = (float)atlas->GetInfo().size.y / atlas->GetInfo().size.x; + ImVec2 size; + size.x = ImGui::GetContentRegionAvail().x; + size.y = aspectRatio * size.x; + ImGui::Image((ImTextureID)(uintptr_t)atlas->GetHandle(), size); + } else { + ImGui::TextUnformatted("Sprite configuration invalid"); + } + + if (doInvalidateInstance) { + ires.InvalidateInstance(); + } + } break; + + case IresObject::KD_COUNT: break; + } +} + void EditorInstance::ShowInspector(GameObject* object) { using namespace Tags; using namespace ProjectBrussel_UNITY_ID; @@ -367,3 +450,15 @@ void EditorInstance::ShowGameObjectInTree(GameObject* object) { ImGui::TreePop(); } } + +void EditorInstance::OpenSpriteViewer(Sprite* sprite) { + mSpriteView_Instance.Attach(sprite); + ImGui::OpenPopup("Sprite Viewer"); +} + +void EditorInstance::ShowSpriteViewer() { + if (ImGui::BeginPopup("Sprite Viewer")) { + // TODO + ImGui::EndPopup(); + } +} -- cgit v1.2.3-70-g09d2