diff --git a/src/main.cc b/src/main.cc index 9bbb597..cf5a021 100644 --- a/src/main.cc +++ b/src/main.cc @@ -142,6 +142,7 @@ int main(void) imguiCreate(); GuiInputState gui_input_state; gGuiInputState = &gui_input_state; + ImGui::InitDockContext(); // Timer Timer timer; @@ -169,6 +170,7 @@ int main(void) // Start the imgui frame such that widgets can be submitted handle_mouse(); glfwGetWindowSize(gWindow, &width, &height); + imguiBeginFrame (gGuiInputState->mouseX, gGuiInputState->mouseY, gGuiInputState->mouseButton, diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 4c33dc3..f059d1a 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -127,10 +127,24 @@ static bool module_step(struct module_state *state, float dt) { assert (gWindow != nullptr); glfwGetWindowSize(gWindow, &width, &height); state->renderer->updateShaders(); - state->renderer->resize (width, height); + + bgfx::reset (width, height); + + int dock_top_offset = 20.0f; + int dock_width = 400; + ImGui::RootDock( + ImVec2(width - dock_width, dock_top_offset), + ImVec2(dock_width, height - dock_top_offset) + ); +// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.5f)); + + state->renderer->resize (0, 20.0f, width - dock_width, height - 20.0f); +// state->renderer->resize (0, 20.0f, width, height - 20.0f); state->renderer->paintGL(); +// ImGui::PopStyleColor(); + return true; } @@ -1165,14 +1179,14 @@ namespace bgfx { void Renderer::initialize(int width, int height) { - this->width = width; - this->height = height; + this->view_width = width; + this->view_height = height; uint32_t debug = BGFX_DEBUG_TEXT; uint32_t reset = BGFX_RESET_VSYNC; reset = BGFX_RESET_VSYNC | BGFX_RESET_MAXANISOTROPY | BGFX_RESET_MSAA_X16; - bgfx::reset(width, height, reset); + bgfx::reset(view_width, view_height, reset); bgfx::setViewClear(0 , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH @@ -1180,7 +1194,7 @@ void Renderer::initialize(int width, int height) { , 1.0f , 0 ); - bgfx::setViewRect(0, 0, 0, width, height); + bgfx::setViewRect(0, view_offset_x, view_offset_y, view_width, view_height); bgfx::RendererType::Enum renderer = bgfx::getRendererType(); flipV = false @@ -1206,7 +1220,7 @@ void Renderer::initialize(int width, int height) { mCurrentLightProbe = LightProbe::Bolonga; initialized = true; - resize (width, height); + resize (view_offset_x, view_offset_y, view_width, view_height); bgfx::frame(); } @@ -1264,12 +1278,12 @@ void Renderer::shutdown() { cameras.clear(); } -void Renderer::resize (int width, int height) { +void Renderer::resize (int x, int y, int width, int height) { if (initialized) { - bgfx::reset (width, height); - - this->width = width; - this->height = height; + this->view_offset_x = x; + this->view_offset_y = y; + this->view_width = width; + this->view_height = height; for (uint32_t i = 0; i < cameras.size(); i++) { cameras[i].width = static_cast(width); @@ -1280,7 +1294,7 @@ void Renderer::resize (int width, int height) { void Renderer::paintGLSimple() { // Set view 0 default viewport. - bgfx::setViewRect(0, 0, 0, width, height); + bgfx::setViewRect(0, view_offset_x, view_offset_y, view_width, view_height); // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. @@ -1319,7 +1333,7 @@ void Renderer::paintGL() { bgfx::dbgTextClear(); // debug font is 8 pixels wide - int num_chars = width / 8; + int num_chars = view_width / 8; bgfx::dbgTextPrintf(num_chars - 18, 0, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); // This dummy draw call is here to make sure that view 0 is cleared @@ -1384,26 +1398,27 @@ void Renderer::paintGL() { float proj[16]; bx::mtxIdentity(view); bx::mtxOrthoRh(proj, 0.f, 1.f, 1.f, 0.f, 0.f, 100.0f); - bgfx::setViewRect(RenderState::Skybox, 0, 0, width, height); + + bgfx::setViewRect(RenderState::Skybox, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::Skybox, view, proj); bgfx::setViewRect(RenderState::ShadowMap, 0, 0, lights[0].shadowMapSize, lights[0].shadowMapSize); bgfx::setViewFrameBuffer(RenderState::ShadowMap, lights[0].shadowMapFB); bgfx::setViewTransform(RenderState::ShadowMap, lights[0].mtxView, lights[0].mtxProj); - bgfx::setViewRect(RenderState::Scene, 0, 0, width, height); + bgfx::setViewRect(RenderState::Scene, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::Scene, cameras[activeCameraIndex].mtxView, cameras[activeCameraIndex].mtxProj); - bgfx::setViewRect(RenderState::SceneTextured, 0, 0, width, height); + bgfx::setViewRect(RenderState::SceneTextured, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::SceneTextured, cameras[activeCameraIndex].mtxView, cameras[activeCameraIndex].mtxProj); - bgfx::setViewRect(RenderState::Lines, 0, 0, width, height); + bgfx::setViewRect(RenderState::Lines, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::Lines, cameras[activeCameraIndex].mtxView, cameras[activeCameraIndex].mtxProj); - bgfx::setViewRect(RenderState::LinesOccluded, 0, 0, width, height); + bgfx::setViewRect(RenderState::LinesOccluded, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::LinesOccluded, cameras[activeCameraIndex].mtxView, cameras[activeCameraIndex].mtxProj); - bgfx::setViewRect(RenderState::Debug, 0, 0, width, height); + bgfx::setViewRect(RenderState::Debug, view_offset_x, view_offset_y, view_width, view_height); bgfx::setViewTransform(RenderState::Debug, cameras[activeCameraIndex].mtxView, cameras[activeCameraIndex].mtxProj); @@ -1641,7 +1656,7 @@ void Renderer::paintGL() { float thickness = 0.143f; float miter = 0.0f; - float aspect = static_cast(width) / height; + float aspect = static_cast(view_width) / static_cast(view_height); Vector4f params (thickness, miter, aspect, 0.0f); @@ -1670,43 +1685,44 @@ void Renderer::paintGL() { // process submitted rendering primitives. bgfx::frame(); - ImGui::SetNextWindowSize (ImVec2(400.f, 300.0f), ImGuiSetCond_Once); - ImGui::SetNextWindowPos (ImVec2(10.f, 300.0f), ImGuiSetCond_Once); +// ImGui::SetNextWindowSize (ImVec2(400.f, 300.0f), ImGuiSetCond_Once); +// ImGui::SetNextWindowPos (ImVec2(10.f, 300.0f), ImGuiSetCond_Once); +// + if (ImGui::BeginDock("Render Settings")) { - ImGui::Begin("Render Settings"); + if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos.data(), 1.0f, -10.0f, 10.0f)) { + } - if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos, 1.0f, -10.0f, 10.0f)) { + if(ImGui::DragFloat3 ("Light0 Dir", lights[0].dir.data(), 1.0f, -10.0f, 10.0f)) { + } + + float light_at[3]; + light_at[0] = lights[0].dir[0] - lights[0].pos[0]; + light_at[1] = lights[0].dir[1] - lights[0].pos[1]; + light_at[2] = lights[0].dir[2] - lights[0].pos[2]; + + if(ImGui::DragFloat3 ("Light0 At", light_at, 1.0f, -10.0f, 10.0f)) { + lights[0].dir[0] = lights[0].pos[0]- light_at[0]; + lights[0].dir[1] = lights[0].pos[1]- light_at[1]; + lights[0].dir[2] = lights[0].pos[2]- light_at[2]; + } + + assert (lights.size() == 1); + + ImGui::Checkbox("Draw Floor", &drawFloor); + ImGui::Checkbox("Draw Skybox", &drawSkybox); + ImGui::Checkbox("Draw Debug", &drawDebug); + + for (int i = 0; i < lights.size(); i++) { + ImGui::SliderFloat("Bias", + &lights[i].shadowMapBias, + 0.0001f, + 0.10f + ); + } } - if(ImGui::DragFloat3 ("Light0 Dir", lights[0].dir, 1.0f, -10.0f, 10.0f)) { - } - - float light_at[3]; - light_at[0] = lights[0].dir[0] - lights[0].pos[0]; - light_at[1] = lights[0].dir[1] - lights[0].pos[1]; - light_at[2] = lights[0].dir[2] - lights[0].pos[2]; - - if(ImGui::DragFloat3 ("Light0 At", light_at, 1.0f, -10.0f, 10.0f)) { - lights[0].dir[0] = lights[0].pos[0]- light_at[0]; - lights[0].dir[1] = lights[0].pos[1]- light_at[1]; - lights[0].dir[2] = lights[0].pos[2]- light_at[2]; - } - - assert (lights.size() == 1); - - ImGui::Checkbox("Draw Floor", &drawFloor); - ImGui::Checkbox("Draw Skybox", &drawSkybox); - ImGui::Checkbox("Draw Debug", &drawDebug); - - for (int i = 0; i < lights.size(); i++) { - ImGui::SliderFloat("Bias", - &lights[i].shadowMapBias, - 0.0001f, - 0.10f - ); - } - - ImGui::End(); + ImGui::EndDock(); // clear debug commands as they have to be issued every frame debugCommands.clear(); diff --git a/src/modules/RenderModule.h b/src/modules/RenderModule.h index f9e8d0b..6111ccc 100644 --- a/src/modules/RenderModule.h +++ b/src/modules/RenderModule.h @@ -332,8 +332,10 @@ struct Renderer { bool drawDebug; bool drawFloor = true; bool drawSkybox = true; - uint32_t width; - uint32_t height; + uint32_t view_offset_x = 0; + uint32_t view_offset_y = 0; + uint32_t view_width = 1; + uint32_t view_height = 1; bgfx::UniformHandle sceneDefaultTextureSampler; bgfx::TextureHandle sceneDefaultTexture; @@ -372,7 +374,7 @@ struct Renderer { void shutdown(); void paintGL(); void paintGLSimple(); - void resize (int width, int height); + void resize (int x, int y, int width, int height); // check whether shader files were modified and reload them. Returns // true on success, otherwise false diff --git a/src/modules/TestModule.cc b/src/modules/TestModule.cc index de37689..9b8d248 100644 --- a/src/modules/TestModule.cc +++ b/src/modules/TestModule.cc @@ -231,59 +231,63 @@ static void module_unload(struct module_state *state, void* write_serializer) { } void ShowModulesWindow(struct module_state *state) { - ImGui::SetNextWindowSize (ImVec2(400.f, 300.0f), ImGuiSetCond_Once); - ImGui::SetNextWindowPos (ImVec2(400.f, 16.0f), ImGuiSetCond_Once); - ImGui::Begin("Modules"); +// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.8f)); + if (ImGui::BeginDock("Modules")) { + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.0f, 0.0f, 1.f)); + // ImGui::Columns(2); + int selected = state->modules_window_selected_index; + for (int i = 0; i < gModuleManager->mModules.size(); i++) { + ImGuiTreeNodeFlags node_flags = + ImGuiTreeNodeFlags_Leaf + | ((i == selected) ? ImGuiTreeNodeFlags_Selected : 0) + ; -// ImGui::Columns(2); - int selected = state->modules_window_selected_index; - for (int i = 0; i < gModuleManager->mModules.size(); i++) { - ImGuiTreeNodeFlags node_flags = - ImGuiTreeNodeFlags_Leaf - | ((i == selected) ? ImGuiTreeNodeFlags_Selected : 0) - ; + bool node_open = ImGui::TreeNodeEx( + gModuleManager->mModules[i]->name.c_str(), + node_flags); - bool node_open = ImGui::TreeNodeEx( - gModuleManager->mModules[i]->name.c_str(), - node_flags); + if (ImGui::IsItemClicked()) { + selected = i; + } - if (ImGui::IsItemClicked()) { - selected = i; + if (node_open) { + ImGui::TreePop(); + } + } + state->modules_window_selected_index = selected; + + ImGui::Separator(); + + RuntimeModule* selected_module = nullptr; + if (selected != -1) { + selected_module = gModuleManager->mModules[selected]; } - if (node_open) { - ImGui::TreePop(); - } - } - state->modules_window_selected_index = selected; + if (selected_module) { + static char time_buf[32]; + memset (time_buf, 0, 32); - ImGui::Separator(); + ImGui::LabelText("File", "%s", selected_module->name.c_str()); + ImGui::LabelText("Handle", "0x%p", selected_module->handle); + ImGui::LabelText("id", "%ld", selected_module->id); + ImGui::LabelText("mtime", "%ld", selected_module->mtime); + ImGui::LabelText("mtimensec", "%ld", selected_module->mtimensec); - RuntimeModule* selected_module = nullptr; - if (selected != -1) { - selected_module = gModuleManager->mModules[selected]; - } + // ImGui::LabelText("mtime", "%s", ctime((time_t*)&selected_module->mtime)); + // cout << "time_buf = " << ctime((time_t*)&selected_module->mtime) << endl; - if (selected_module) { - static char time_buf[32]; - memset (time_buf, 0, 32); - - ImGui::LabelText("File", "%s", selected_module->name.c_str()); - ImGui::LabelText("Handle", "0x%p", selected_module->handle); - ImGui::LabelText("id", "%ld", selected_module->id); - ImGui::LabelText("mtime", "%ld", selected_module->mtime); - ImGui::LabelText("mtimensec", "%ld", selected_module->mtimensec); - -// ImGui::LabelText("mtime", "%s", ctime((time_t*)&selected_module->mtime)); -// cout << "time_buf = " << ctime((time_t*)&selected_module->mtime) << endl; - - if (ImGui::Button ("Force Reload")) { - selected_module->mtime = 0; - selected_module->id = 0; + if (ImGui::Button ("Force Reload")) { + selected_module->mtime = 0; + selected_module->id = 0; + } } } - ImGui::End(); + ImGui::PopStyleColor(); + ImGui::EndDock(); + +// ImGui::PopStyleColor (); + } static bool module_step(struct module_state *state, float dt) {