From f52db94b51e505c13ded001976590136bfadc04e Mon Sep 17 00:00:00 2001 From: touky Date: Tue, 22 Nov 2016 20:46:24 -0500 Subject: [PATCH] imgui extension small imgui extension scene palette shader crashfix --- src/lolimgui.cpp | 22 ++++++++++++++++++++++ src/lolimgui.h | 18 +++++++++++++++++- src/scene.cpp | 7 +++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index 10ad19bf..57d246b0 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -18,6 +18,28 @@ using namespace lol; +//Imgui extension --------------------------------------------------------------------------------- +namespace ImGui +{ + IMGUI_API void SetNextWindowSizeAndDock(const ImVec2& size, ImGuiSetDock dock, ImGuiSetCond cond) + { + vec2 video_size = vec2(Video::GetSize()); + ImVec2 pos = ImVec2(); + + switch (dock) + { + case ImGuiSetDock_TopLeft: pos = ImVec2(0, 0); break; + case ImGuiSetDock_TopRight: pos = ImVec2(video_size.x - size.x, 0); break; + case ImGuiSetDock_BottomLeft: pos = ImVec2(0, video_size.y - size.y); break; + case ImGuiSetDock_BottomRight: pos = ImVec2(video_size.x - size.x, video_size.y - size.y); break; + } + + ImGui::SetNextWindowPos(pos, cond); + ImGui::SetNextWindowSize(size, cond); + } +} + +//LolImGui ---------------------------------------------------------------------------------------- #define Line(s) ((s) + "\n") //----------------------------------------------------------------------------- diff --git a/src/lolimgui.h b/src/lolimgui.h index fb707b9d..379e0c82 100644 --- a/src/lolimgui.h +++ b/src/lolimgui.h @@ -14,10 +14,26 @@ #include "imgui.h" +//Imgui extension --------------------------------------------------------------------------------- +typedef int ImGuiSetDock; // condition flags for Set*() // enum ImGuiSetCond_ + +enum ImGuiSetDock_ +{ + ImGuiSetDock_TopLeft = 0, + ImGuiSetDock_TopRight = 1, + ImGuiSetDock_BottomLeft = 2, + ImGuiSetDock_BottomRight = 3, +}; + +namespace ImGui +{ + IMGUI_API void SetNextWindowSizeAndDock(const ImVec2& size, ImGuiSetDock dock, ImGuiSetCond cond = 0); +} + +//LolImGui ---------------------------------------------------------------------------------------- namespace lol { -//LolImGui -------------------------------------------------------------------- class LolImGui : public Entity { typedef Entity super; diff --git a/src/scene.cpp b/src/scene.cpp index bbfcc9e5..c33adef5 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -723,7 +723,7 @@ void Scene::render_tiles() // XXX: rename to Blit() if (!data->m_tile_api.m_shader) data->m_tile_api.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_tile)); - if (!data->m_tile_api.m_palette_shader) + if (!data->m_tile_api.m_palette_shader && data->m_tile_api.m_palettes.count()) data->m_tile_api.m_palette_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_palette)); for (int p = 0; p < 2; p++) @@ -749,7 +749,7 @@ void Scene::render_tiles() // XXX: rename to Blit() shader->SetUniform(uni_mat, mat4(1.f)); uni_tex = shader->GetUniformLocation("u_texture"); - uni_pal = data->m_tile_api.m_palette_shader->GetUniformLocation("u_palette"); + uni_pal = data->m_tile_api.m_palette_shader ? data->m_tile_api.m_palette_shader->GetUniformLocation("u_palette") : ShaderUniform(); uni_texsize = shader->GetUniformLocation("u_texsize"); for (int buf = 0, i = 0, n; i < tiles.count(); i = n, buf += 2) @@ -809,6 +809,9 @@ void Scene::render_tiles() // XXX: rename to Blit() tiles.empty(); shader->Unbind(); + + if (!data->m_tile_api.m_palette_shader) + break; } #if (defined LOL_USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X