| | @@ -47,6 +47,7 @@ |
| 47 | 47 | #include <gui/guiengine.hh> |
| 48 | 48 | #include <gui/titlebar.hh> |
| 49 | 49 | #include <gui/editor.hh> |
| 50 | +#include <gui/consolelog.hh> |
| 50 | 51 | |
| 51 | 52 | #include <imgui.h> |
| 52 | 53 | #include <backends/imgui_impl_glfw.h> |
| | @@ -95,6 +96,9 @@ |
| 95 | 96 | sqlite::Instance db; |
| 96 | 97 | db::Initialize(db); |
| 97 | 98 | |
| 99 | + // コンソール |
| 100 | + gui::ConsoleLog cmd; |
| 101 | + |
| 98 | 102 | // データベースからシェーダーとLuaコードの受け取り |
| 99 | 103 | vector<db::ShaderData> codeMap = db::GetAllShaders(db); |
| 100 | 104 | u32 shaderId; |
| | @@ -128,7 +132,7 @@ |
| 128 | 132 | Program shaderProgram(vertexShader, fragmentShader); |
| 129 | 133 | |
| 130 | 134 | // 頂点データはLuaから受け取る |
| 131 | | - lua::LuaEngine luaEngine(LUA, &shaderProgram); |
| 135 | + lua::LuaEngine luaEngine(LUA, &shaderProgram, &cmd); |
| 132 | 136 | auto &mesh = luaEngine.GetMesh(); |
| 133 | 137 | |
| 134 | 138 | VertexArrays VAO(1); |
| | @@ -147,9 +151,95 @@ |
| 147 | 151 | glEnableVertexAttribArray(a.location); |
| 148 | 152 | } |
| 149 | 153 | |
| 154 | + bool isHold = false; |
| 155 | + |
| 150 | 156 | // メインレンダリングループ |
| 151 | 157 | while (!window.ShouldClose()) { |
| 158 | + auto compileCommand = [&]() { |
| 159 | + VERT = vertEditor.Get().GetText(); |
| 160 | + FRAG = fragEditor.Get().GetText(); |
| 161 | + LUA = luaEditor.Get().GetText(); |
| 162 | + |
| 163 | + try { |
| 164 | + shaderProgram.Reload(VERT, FRAG); |
| 165 | + luaEngine.SetProgram(&shaderProgram); |
| 166 | + luaEngine.Reload(LUA); |
| 167 | + { |
| 168 | + lua::LuaMesh newMesh = luaEngine.GetMesh(); |
| 169 | + |
| 170 | + VAO.BindVertexArray(); |
| 171 | + |
| 172 | + VBO.BindBuffer(); |
| 173 | + VBO.BufferData( |
| 174 | + newMesh.vertices.data(), |
| 175 | + newMesh.vertices.size() * sizeof(f32) |
| 176 | + ); |
| 177 | + |
| 178 | + EBO.BindBuffer(); |
| 179 | + EBO.BufferData( |
| 180 | + newMesh.indices.data(), |
| 181 | + newMesh.indices.size() * sizeof(f32) |
| 182 | + ); |
| 183 | + |
| 184 | + for (const auto &a : newMesh.attr) { |
| 185 | + glVertexAttribPointer( |
| 186 | + a.location, |
| 187 | + a.size, |
| 188 | + GL_FLOAT, |
| 189 | + GL_FALSE, |
| 190 | + a.stride, |
| 191 | + (any)(uintptr_t)a.offset |
| 192 | + ); |
| 193 | + glEnableVertexAttribArray(a.location); |
| 194 | + } |
| 195 | + } |
| 196 | + } catch (const std::exception &e) { |
| 197 | + std::cerr << e.what() << std::endl; |
| 198 | + } |
| 199 | + |
| 200 | + gui::LogEntry entry; |
| 201 | + entry.type = gui::LogType::Info; |
| 202 | + entry.text = "シェーダーをコンパイルしました。"; |
| 203 | + cmd.Add(entry); |
| 204 | + std::cout << entry.text << std::endl; |
| 205 | + }; |
| 206 | + |
| 207 | + auto saveCommand = [&]() { |
| 208 | + VERT = vertEditor.Get().GetText(); |
| 209 | + FRAG = fragEditor.Get().GetText(); |
| 210 | + LUA = luaEditor.Get().GetText(); |
| 211 | + |
| 212 | + db::SaveCode(db, shaderId, VERT, "vertex_shader"); |
| 213 | + db::SaveCode(db, shaderId, FRAG, "fragment_shader"); |
| 214 | + db::SaveCode(db, shaderId, LUA, "lua_code"); |
| 215 | + |
| 216 | + gui::LogEntry entry; |
| 217 | + entry.type = gui::LogType::Info; |
| 218 | + entry.text = "シェーダー及びLuaファイルを保存しました。"; |
| 219 | + cmd.Add(entry); |
| 220 | + std::cout << entry.text << std::endl; |
| 221 | + }; |
| 222 | + |
| 152 | 223 | glfw.PollEvents(); |
| 224 | + |
| 225 | + bool isCompileKey = window.GetKey(GLFW_KEY_F5); |
| 226 | + bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 227 | + bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod); |
| 228 | + |
| 229 | + if (!isHold) { |
| 230 | + if (isCompileKey) { |
| 231 | + //isHold = true; |
| 232 | + compileCommand(); |
| 233 | + } |
| 234 | + |
| 235 | + if (isSaveKey) { |
| 236 | + //isHold = true; |
| 237 | + saveCommand(); |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + isHold = isSaveKey || isCompileKey; |
| 242 | + |
| 153 | 243 | if (window.GetAttrib(glfwpp::Attributes::Iconified) != 0) { |
| 154 | 244 | ImGui_ImplGlfw_Sleep(10); |
| 155 | 245 | continue; |
| | @@ -164,6 +254,7 @@ |
| 164 | 254 | vertEditor.Render(); |
| 165 | 255 | fragEditor.Render(); |
| 166 | 256 | luaEditor.Render(); |
| 257 | + cmd.Draw(); |
| 167 | 258 | |
| 168 | 259 | { |
| 169 | 260 | static float f = 0.0f; |
| | @@ -172,58 +263,13 @@ |
| 172 | 263 | ImGui::Begin("コントロール"); |
| 173 | 264 | |
| 174 | 265 | if (ImGui::Button("コンパイル(F5)")) { |
| 175 | | - VERT = vertEditor.Get().GetText(); |
| 176 | | - FRAG = fragEditor.Get().GetText(); |
| 177 | | - LUA = luaEditor.Get().GetText(); |
| 178 | | - |
| 179 | | - try { |
| 180 | | - shaderProgram.Reload(VERT, FRAG); |
| 181 | | - luaEngine.SetProgram(&shaderProgram); |
| 182 | | - luaEngine.Reload(LUA); |
| 183 | | - { |
| 184 | | - lua::LuaMesh newMesh = luaEngine.GetMesh(); |
| 185 | | - |
| 186 | | - VAO.BindVertexArray(); |
| 187 | | - |
| 188 | | - VBO.BindBuffer(); |
| 189 | | - VBO.BufferData( |
| 190 | | - newMesh.vertices.data(), |
| 191 | | - newMesh.vertices.size() * sizeof(f32) |
| 192 | | - ); |
| 193 | | - |
| 194 | | - EBO.BindBuffer(); |
| 195 | | - EBO.BufferData( |
| 196 | | - newMesh.indices.data(), |
| 197 | | - newMesh.indices.size() * sizeof(f32) |
| 198 | | - ); |
| 199 | | - |
| 200 | | - for (const auto &a : newMesh.attr) { |
| 201 | | - glVertexAttribPointer( |
| 202 | | - a.location, |
| 203 | | - a.size, |
| 204 | | - GL_FLOAT, |
| 205 | | - GL_FALSE, |
| 206 | | - a.stride, |
| 207 | | - (any)(uintptr_t)a.offset |
| 208 | | - ); |
| 209 | | - glEnableVertexAttribArray(a.location); |
| 210 | | - } |
| 211 | | - } |
| 212 | | - } catch (const std::exception &e) { |
| 213 | | - std::cerr << e.what() << std::endl; |
| 214 | | - } |
| 266 | + compileCommand(); |
| 215 | 267 | } |
| 216 | 268 | |
| 217 | 269 | ImGui::SameLine(); |
| 218 | 270 | |
| 219 | 271 | if (ImGui::Button("保存(CTRL + S)")) { |
| 220 | | - VERT = vertEditor.Get().GetText(); |
| 221 | | - FRAG = fragEditor.Get().GetText(); |
| 222 | | - LUA = luaEditor.Get().GetText(); |
| 223 | | - |
| 224 | | - db::SaveCode(db, shaderId, VERT, "vertex_shader"); |
| 225 | | - db::SaveCode(db, shaderId, FRAG, "fragment_shader"); |
| 226 | | - db::SaveCode(db, shaderId, LUA, "lua_code"); |
| 272 | + saveCommand(); |
| 227 | 273 | } |
| 228 | 274 | |
| 229 | 275 | ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ge.GetIO().Framerate, ge.GetIO().Framerate); |