From 527e27c8808fd2b4c8ea9b8aa1a558521beb5303 Mon Sep 17 00:00:00 2001 From: touky Date: Thu, 20 Oct 2016 23:02:15 -0400 Subject: [PATCH] - ImGUI is now operational again - Most recent version is in with index buffer support --- doc/tutorial/02_cube.cpp | 6 ++--- doc/tutorial/07_input.cpp | 6 ++--- doc/tutorial/15_lolimgui.cpp | 20 +++++++++++++- doc/tutorial/imgui.ini | 9 +++++-- src/easymesh/easymeshrender.cpp | 2 +- src/gpu/vertexbuffer.cpp | 33 +++++++---------------- src/lol/gpu/vertexbuffer.h | 4 +-- src/lolimgui.cpp | 48 ++++++++++++++++++--------------- src/mesh/mesh.cpp | 3 +-- 9 files changed, 69 insertions(+), 62 deletions(-) diff --git a/doc/tutorial/02_cube.cpp b/doc/tutorial/02_cube.cpp index f873dfb2..c500d3af 100644 --- a/doc/tutorial/02_cube.cpp +++ b/doc/tutorial/02_cube.cpp @@ -103,14 +103,12 @@ public: m_shader->SetUniform(m_mvp, m_matrix); m_lines_ibo->Bind(); - m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, 0, 0, - m_mesh.count(), 0, m_lines_indices.count()); + m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, m_lines_indices.count()); m_lines_ibo->Unbind(); m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); m_faces_ibo->Bind(); - m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, - m_mesh.count(), 0, m_faces_indices.count()); + m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_faces_indices.count()); m_faces_ibo->Unbind(); m_vdecl->Unbind(); diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index f755bfd9..6d37bd7e 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -199,14 +199,12 @@ public: m_shader->SetUniform(m_mvp, m_matrix); m_lines_ibo->Bind(); - m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, 0, 0, - m_mesh.count(), 0, m_lines_indices.count()); + m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, m_lines_indices.count()); m_lines_ibo->Unbind(); m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); m_faces_ibo->Bind(); - m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, - m_mesh.count(), 0, m_faces_indices.count()); + m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_faces_indices.count()); m_faces_ibo->Unbind(); m_vdecl->Unbind(); diff --git a/doc/tutorial/15_lolimgui.cpp b/doc/tutorial/15_lolimgui.cpp index 1f6a36a6..10824603 100644 --- a/doc/tutorial/15_lolimgui.cpp +++ b/doc/tutorial/15_lolimgui.cpp @@ -44,6 +44,14 @@ public: ImGui::SetNextWindowFocus(); ImGui::Begin("testature"); { + if (ImGui::IsWindowHovered()) + ImGui::Text("Hovered: true"); + else + ImGui::Text("Hovered: false"); + if (ImGui::IsWindowFocused()) + ImGui::Text("Focused: true"); + else + ImGui::Text("Focused: false"); ImGui::Text("Hello, world!"); ImGui::Text("prout!"); ImGui::Text("prout!%i", 100); @@ -58,10 +66,20 @@ public: ImGui::Text("Ctrl: %s", io.KeyCtrl ? "true" : "false"); ImGui::Text("Clipboard %s", LolImGui::GetClipboard()); ImGui::InputText("base input", buf, 512); - if (ImGui::IsItemActive()) + } + ImGui::End(); + ImGui::Begin("SO FUN !!"); + { + if (ImGui::IsWindowHovered()) + ImGui::Text("Hovered: true"); + else + ImGui::Text("Hovered: false"); + if (ImGui::IsWindowFocused()) ImGui::Text("Focused: true"); else ImGui::Text("Focused: false"); + ImGui::Text("poucka!"); + ImGui::Text(" poucka!"); } ImGui::End(); } diff --git a/doc/tutorial/imgui.ini b/doc/tutorial/imgui.ini index d24a4f98..c39d8823 100644 --- a/doc/tutorial/imgui.ini +++ b/doc/tutorial/imgui.ini @@ -4,7 +4,12 @@ Size=400,400 Collapsed=0 [testature] -Pos=140,75 -Size=197,287 +Pos=266,15 +Size=494,359 +Collapsed=0 + +[SO FUN !!] +Pos=30,24 +Size=113,99 Collapsed=0 diff --git a/src/easymesh/easymeshrender.cpp b/src/easymesh/easymeshrender.cpp index b9c124ea..4ea1cd44 100644 --- a/src/easymesh/easymeshrender.cpp +++ b/src/easymesh/easymeshrender.cpp @@ -454,7 +454,7 @@ void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode) vdecl->SetStream(vbo, Attribs[0], Attribs[1], Attribs[2], Attribs[3]); m_ibo->Bind(); - vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, m_vertexcount, 0, m_indexcount); + vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_indexcount); m_ibo->Unbind(); vdecl->Unbind(); } diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index 31629446..9112258f 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -103,45 +103,30 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) } } -void VertexDeclaration::DrawIndexedElements_(MeshPrimitive type, int count, const short* skip) -{ - glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, skip); -} - -void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, - int vskip, int vcount, - int skip, int count) +void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int count, const short* skip, short typeSize) { if (count <= 0) return; + uint32_t elementType = typeSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; + /* FIXME: this has nothing to do here! */ switch (type.ToScalar()) { case MeshPrimitive::Triangles: - /* FIXME: ignores most of the arguments! */ - UNUSED(vbase, vskip, vcount, skip); - glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0); + glDrawElements(GL_TRIANGLES, count, elementType, skip); break; case MeshPrimitive::TriangleStrips: - /* FIXME: ignores most of the arguments! */ - UNUSED(vbase, vskip, vcount, skip); - glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_SHORT, 0); - break; + glDrawElements(GL_TRIANGLE_STRIP, count, elementType, skip); + break; case MeshPrimitive::TriangleFans: - /* FIXME: ignores most of the arguments! */ - UNUSED(vbase, vskip, vcount, skip); - glDrawElements(GL_TRIANGLE_FAN, count, GL_UNSIGNED_SHORT, 0); + glDrawElements(GL_TRIANGLE_FAN, count, elementType, skip); break; case MeshPrimitive::Points: - /* FIXME: ignores most of the arguments! */ - UNUSED(vbase, vskip, vcount, skip); - glDrawElements(GL_POINTS, count, GL_UNSIGNED_SHORT, 0); + glDrawElements(GL_POINTS, count, elementType, skip); break; case MeshPrimitive::Lines: - /* FIXME: ignores most of the arguments! */ - UNUSED(vbase, vskip, vcount, skip); - glDrawElements(GL_LINES, count, GL_UNSIGNED_SHORT, 0); + glDrawElements(GL_LINES, count, elementType, skip); break; } } diff --git a/src/lol/gpu/vertexbuffer.h b/src/lol/gpu/vertexbuffer.h index c00b56ef..8de50094 100644 --- a/src/lol/gpu/vertexbuffer.h +++ b/src/lol/gpu/vertexbuffer.h @@ -212,9 +212,7 @@ public: /* Draw elements. See MeshPrimitive for a list of all available * types. Both skip and count are numbers of indices, not primitives. */ - void DrawIndexedElements_(MeshPrimitive type, int count, const short* skip); - void DrawIndexedElements(MeshPrimitive type, int vbase, int vskip, - int vcount, int skip, int count); + void DrawIndexedElements(MeshPrimitive type, int count, const short* skip = nullptr, short typeSize = 2); void Unbind(); void SetStream(VertexBuffer *vb, ShaderAttrib attr1, diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index 021181b7..9cea9de0 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -78,7 +78,6 @@ LolImGui::LolImGui() Ticker::Ref(m_controller = new Controller("ImGui_Controller")); m_controller->Init(m_profile); - //InputDevice::CaptureMouse(true); m_mouse = InputDevice::GetMouse(); m_keyboard = InputDevice::GetKeyboard(); @@ -234,7 +233,7 @@ void LolImGui::TickGame(float seconds) cursor.y = 1.f - cursor.y; cursor *= video_size; io.MousePos = ImVec2(cursor.x, cursor.y); - msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y); + //msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y); io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll); for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) @@ -247,11 +246,13 @@ void LolImGui::TickGame(float seconds) case LolImGuiKey::Focus: if (m_controller->IsKeyReleased(i)) { - msg::debug("Not focused .....\n"); + //msg::debug("Not focused .....\n"); io.MousePos = ImVec2(-1.f, -1.f); } else - msg::debug("Focused !!\n"); + { + //msg::debug("Focused !!\n"); + } break; } } @@ -309,10 +310,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) String code; m_builder.Build(code); - msg::debug("\nCREATED SHADER:\n%s\n", code.C()); m_shader = Shader::Create(m_builder.GetName(), code); ASSERT(m_shader); - msg::debug("\nPATCHED SHADER:\n%s\n", code.C()); m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var); m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var); @@ -359,8 +358,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) vbo->Unlock(); IndexBuffer *ibo = new IndexBuffer(cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); - uint16_t *indices = (uint16_t *)ibo->Lock(0, 0); - memcpy(vert, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); + ImDrawIdx *indices = (ImDrawIdx *)ibo->Lock(0, 0); + memcpy(indices, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); ibo->Unlock(); m_font->Bind(); @@ -371,12 +370,16 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) const ImDrawIdx* idx_buffer_offset = 0; for (size_t cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; #ifdef SHOW_IMGUI_DEBUG //----------------------------------------------------------------- // -------------------------------------------------- //----------------------------------------------------------------- + //Doesn't work anymore ...... + static uint32_t idx_buffer_offset_i = 0; + if (cmd_i == 0) + idx_buffer_offset_i = 0; + float mod = -200.f; vec3 off = vec3(vec2(-size.x, -size.y), 0.f); vec3 pos[4] = { @@ -387,29 +390,32 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) }; for (int i = 0; i < 4; ++i) Debug::DrawLine(pos[i], pos[(i + 1) % 4], Color::white); - ImDrawVert* buf = (ImDrawVert*)(vtx_buffer + vtx_offset); + ImDrawVert* buf = vert; for (uint16_t i = 0; i < pcmd->ElemCount; i += 3) { + uint16_t ib = indices[idx_buffer_offset_i + i]; vec2 pos[3]; - pos[0] = vec2(buf[i + 0].pos.x, buf[i + 0].pos.y); - pos[1] = vec2(buf[i + 1].pos.x, buf[i + 1].pos.y); - pos[2] = vec2(buf[i + 2].pos.x, buf[i + 2].pos.y); + pos[0] = vec2(buf[ib + 0].pos.x, buf[ib + 0].pos.y); + pos[1] = vec2(buf[ib + 1].pos.x, buf[ib + 1].pos.y); + pos[2] = vec2(buf[ib + 2].pos.x, buf[ib + 2].pos.y); vec4 col[3]; - col[0] = vec4(Color::FromRGBA32(buf[i + 0].col).arg, 1.f); - col[1] = vec4(Color::FromRGBA32(buf[i + 1].col).arg, 1.f); - col[2] = vec4(Color::FromRGBA32(buf[i + 2].col).arg, 1.f); + col[0] = vec4(Color::FromRGBA32(buf[ib + 0].col).arg, 1.f); + col[1] = vec4(Color::FromRGBA32(buf[ib + 1].col).arg, 1.f); + col[2] = vec4(Color::FromRGBA32(buf[ib + 2].col).arg, 1.f); Debug::DrawLine((off + vec3(pos[0], 0.f)) / mod, (off + vec3(pos[1], 0.f)) / mod, col[0]); Debug::DrawLine((off + vec3(pos[1], 0.f)) / mod, (off + vec3(pos[2], 0.f)) / mod, col[1]); Debug::DrawLine((off + vec3(pos[2], 0.f)) / mod, (off + vec3(pos[0], 0.f)) / mod, col[2]); } - //----------------------------------------------------------------- + idx_buffer_offset_i += pcmd->ElemCount; + + //----------------------------------------------------------------- //<\Debug render> ------------------------------------------------- //----------------------------------------------------------------- #endif //SHOW_IMGUI_DEBUG + Debug::DrawLine(vec2::zero, vec2::axis_x, Color::green); + + m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); - m_vdecl->DrawIndexedElements_(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); - //m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, 0, 0, pcmd->ElemCount); - //m_vdecl->DrawElements(MeshPrimitive::Triangles, (int)idx_buffer_offset, pcmd->ElemCount); idx_buffer_offset += pcmd->ElemCount; } diff --git a/src/mesh/mesh.cpp b/src/mesh/mesh.cpp index b32c8b26..c87d31a8 100644 --- a/src/mesh/mesh.cpp +++ b/src/mesh/mesh.cpp @@ -146,8 +146,7 @@ void SubMesh::Render() m_ibo->Bind(); m_vdecl->Bind(); - m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, vertex_count, - 0, m_ibo->GetSize() / sizeof(uint16_t)); + m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_ibo->GetSize() / sizeof(uint16_t)); m_vdecl->Unbind(); m_ibo->Unbind(); }