新しいシェーダー関数
守矢諏訪子 <suwako@076.moe>、2026-06-27 02:44
コミット 8ac2f6391e7cc49247d231fb805081a346008d52
・親 fb7bf68
・ファイルを見る
25個のファイル、+577 -152
| @@ -43,4 +43,7 @@ | ||
| 43 | 43 | #include <gui/about.hh> |
| 44 | 44 | #include <gui/consolelog.hh> |
| 45 | 45 | #include <gui/manual.hh> |
| 46 | - #include <gui/settings.hh> | |
| 46 | +#include <gui/settings.hh> | |
| 47 | +#include <gui/newshader.hh> | |
| 48 | +//#include <gui/openshader.hh> | |
| 49 | +//#include <gui/saveasshader.hh> |
| @@ -42,6 +42,6 @@ | ||
| 42 | 42 | namespace gui { |
| 43 | 43 | class About { |
| 44 | 44 | public: |
| 45 | - void Draw(GlfwInfo &glfw); | |
| 45 | + void Draw(Info &info); | |
| 46 | 46 | }; // class About |
| 47 | 47 | } // namespace gui |
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | |
| 39 | 39 | #include <util/types.hh> |
| 40 | 40 | |
| 41 | -struct GlfwInfo; | |
| 41 | +struct Info; | |
| 42 | 42 | namespace db { |
| 43 | 43 | class Locale; |
| 44 | 44 | } // namespace db |
| @@ -59,7 +59,7 @@ | ||
| 59 | 59 | class ConsoleLog { |
| 60 | 60 | public: |
| 61 | 61 | void Add(LogEntry entry); |
| 62 | - void Draw(GlfwInfo &info, cstr title = "コンソール"); | |
| 62 | + void Draw(Info &info, cstr title = "コンソール"); | |
| 63 | 63 | void Clear(); |
| 64 | 64 | |
| 65 | 65 | private: |
| @@ -53,9 +53,13 @@ | ||
| 53 | 53 | Editor(string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont); |
| 54 | 54 | ~Editor(); |
| 55 | 55 | |
| 56 | - TextEditor Get() const { return m_Editor; } | |
| 56 | + TextEditor &Get() { return m_Editor; } | |
| 57 | + const TextEditor &Get() const { return m_Editor; } | |
| 57 | 58 | void Render(); |
| 58 | - void SetCode(string code); | |
| 59 | + void SetCode(const string &code) { | |
| 60 | + m_Code = code; | |
| 61 | + m_Editor.SetText(code); | |
| 62 | + } | |
| 59 | 63 | void RenderStatusBar(TextEditor editor); |
| 60 | 64 | |
| 61 | 65 | void SetTitle(const string &title) { m_Title = title; } |
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | namespace gui { |
| 43 | 43 | class Manual { |
| 44 | 44 | public: |
| 45 | - void Draw(GlfwInfo &glfw); | |
| 45 | + void Draw(Info &info); | |
| 46 | 46 | |
| 47 | 47 | private: |
| 48 | 48 | void renderMarkdown(cstr text); |
| @@ -0,0 +1,58 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#pragma once | |
| 38 | + | |
| 39 | +#include <util/types.hh> | |
| 40 | +#include <util/structs.hh> | |
| 41 | + | |
| 42 | +namespace gui { | |
| 43 | + class NewShader { | |
| 44 | + public: | |
| 45 | + NewShader(Info *info); | |
| 46 | + ~NewShader(); | |
| 47 | + | |
| 48 | + db::ShaderData Make(); | |
| 49 | + | |
| 50 | + private: | |
| 51 | + string getDefaultVert(); | |
| 52 | + string getDefaultFrag(); | |
| 53 | + string getDefaultLua(); | |
| 54 | + | |
| 55 | + private: | |
| 56 | + Info *m_Info; | |
| 57 | + }; // class NewShader | |
| 58 | +} // namespace gui |
| @@ -0,0 +1,43 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#pragma once | |
| 38 | + | |
| 39 | +#include <util/types.hh> | |
| 40 | +#include <util/structs.hh> | |
| 41 | + | |
| 42 | +namespace gui { | |
| 43 | +} // namespace gui |
| @@ -0,0 +1,43 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#pragma once | |
| 38 | + | |
| 39 | +#include <util/types.hh> | |
| 40 | +#include <util/structs.hh> | |
| 41 | + | |
| 42 | +namespace gui { | |
| 43 | +} // namespace gui |
| @@ -42,6 +42,6 @@ | ||
| 42 | 42 | namespace gui { |
| 43 | 43 | class Settings { |
| 44 | 44 | public: |
| 45 | - void Draw(GlfwInfo &glfw); | |
| 45 | + void Draw(Info &info); | |
| 46 | 46 | }; // class Settings |
| 47 | 47 | } // namespace gui |
| @@ -40,5 +40,5 @@ | ||
| 40 | 40 | #include <util/structs.hh> |
| 41 | 41 | |
| 42 | 42 | namespace gui { |
| 43 | - void showTitleBar(GlfwInfo &glfw); | |
| 43 | + void showTitleBar(Info &info); | |
| 44 | 44 | } // namespace gui |
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | public: |
| 45 | 45 | void Init(); |
| 46 | 46 | void Resize(i32 width, i32 height); |
| 47 | - void Draw(GlfwInfo &glfw); | |
| 47 | + void Draw(Info &info); | |
| 48 | 48 | |
| 49 | 49 | u32 GetFBO() const { return m_FBO; } |
| 50 | 50 | u32 GetTexture() const { return m_Texture; } |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | |
| 66 | 66 | class LuaEngine { |
| 67 | 67 | public: |
| 68 | - LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo); | |
| 68 | + LuaEngine(const string &code, Program *prog, Info *info); | |
| 69 | 69 | ~LuaEngine(); |
| 70 | 70 | |
| 71 | 71 | public: |
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | sol::state m_Lua; |
| 97 | 97 | string m_Code; |
| 98 | 98 | Program *m_Program = nullptr; |
| 99 | - GlfwInfo *m_GlfwInfo = {}; | |
| 99 | + Info *m_Info = {}; | |
| 100 | 100 | string m_ApiVersion = "1.0.0"; |
| 101 | 101 | f32 m_LastTime = 0.f; |
| 102 | 102 | }; |
| @@ -40,6 +40,8 @@ | ||
| 40 | 40 | #include <version.hh> |
| 41 | 41 | #include <functional> |
| 42 | 42 | #include <string> |
| 43 | +#include <cstdint> | |
| 44 | +#include <database/shaderdata.hh> | |
| 43 | 45 | |
| 44 | 46 | namespace gui { |
| 45 | 47 | class ConsoleLog; |
| @@ -47,9 +49,10 @@ | ||
| 47 | 49 | |
| 48 | 50 | namespace db { |
| 49 | 51 | class Locale; |
| 52 | + struct CodeData; | |
| 50 | 53 | } // namespace db |
| 51 | 54 | |
| 52 | -struct GlfwInfo { | |
| 55 | +struct Info { | |
| 53 | 56 | glfwpp::Instance *instance; |
| 54 | 57 | glfwpp::Window *window; |
| 55 | 58 | |
| @@ -58,12 +61,20 @@ | ||
| 58 | 61 | bool isManual = false; |
| 59 | 62 | bool isSettings = false; |
| 60 | 63 | bool isLangChange = false; |
| 64 | + bool isNewShader = false; | |
| 61 | 65 | |
| 62 | 66 | std::string version = version::full; |
| 67 | + uint32_t shaderId = 0; | |
| 68 | + std::string shaderName = ""; | |
| 69 | + db::CodeData VERT = {}; | |
| 70 | + db::CodeData FRAG = {}; | |
| 71 | + db::CodeData LUA = {}; | |
| 72 | + std::string currentFile = ""; | |
| 63 | 73 | |
| 64 | 74 | gui::ConsoleLog *cmd; |
| 65 | 75 | db::Locale *i18n; |
| 66 | 76 | |
| 67 | 77 | std::function<void()> compile; |
| 68 | 78 | std::function<void()> save; |
| 79 | + std::function<void()> create; | |
| 69 | 80 | }; |
変更
main.cc
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | window.MakeContextCurrent(); |
| 76 | 76 | glfw.SwapInterval(1); |
| 77 | 77 | |
| 78 | - GlfwInfo glfwInfo = { &glfw, &window, true, false, false, false }; | |
| 78 | + Info info = { &glfw, &window, true, false, false, false }; | |
| 79 | 79 | |
| 80 | 80 | #ifndef PRODUCTION_BUILD |
| 81 | 81 | bool showDemo = true; |
| @@ -104,11 +104,11 @@ | ||
| 104 | 104 | |
| 105 | 105 | // 言語 |
| 106 | 106 | db::Locale i18n(&db); |
| 107 | - glfwInfo.i18n = &i18n; | |
| 107 | + info.i18n = &i18n; | |
| 108 | 108 | |
| 109 | 109 | // コンソール |
| 110 | 110 | gui::ConsoleLog cmd; |
| 111 | - glfwInfo.cmd = &cmd; | |
| 111 | + info.cmd = &cmd; | |
| 112 | 112 | |
| 113 | 113 | // ビューポート |
| 114 | 114 | gui::ViewPort viewport; |
| @@ -119,38 +119,38 @@ | ||
| 119 | 119 | |
| 120 | 120 | // データベースからシェーダーとLuaコードの受け取り |
| 121 | 121 | vector<db::ShaderData> codeMap = db::GetAllShaders(db); |
| 122 | - u32 shaderId; | |
| 123 | - string shaderName; | |
| 124 | - db::CodeData VERT = {}; | |
| 125 | - db::CodeData FRAG = {}; | |
| 126 | - db::CodeData LUA = {}; | |
| 122 | + info.shaderId; | |
| 123 | + info.shaderName; | |
| 124 | + info.VERT = {}; | |
| 125 | + info.FRAG = {}; | |
| 126 | + info.LUA = {}; | |
| 127 | 127 | |
| 128 | 128 | for (const auto &c : codeMap) { |
| 129 | - shaderId = c.id; | |
| 130 | - shaderName = c.name; | |
| 131 | - VERT = c.vertexShader; | |
| 132 | - FRAG = c.fragmentShader; | |
| 133 | - LUA = c.luaCode; | |
| 129 | + info.shaderId = c.id; | |
| 130 | + info.shaderName = c.name; | |
| 131 | + info.VERT = c.vertexShader; | |
| 132 | + info.FRAG = c.fragmentShader; | |
| 133 | + info.LUA = c.luaCode; | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - string title = shaderName + "(" + glfwInfo.i18n->GetWord("editorvertshader") + ")"; | |
| 137 | - gui::Editor vertEditor((title + "###VertexEditor").c_str(), "VertexEditor", VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 136 | + string title = info.shaderName + "(" + info.i18n->GetWord("editorvertshader") + ")"; | |
| 137 | + gui::Editor vertEditor((title + "###VertexEditor").c_str(), "VertexEditor", info.VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 138 | 138 | |
| 139 | - title = shaderName + "(" + glfwInfo.i18n->GetWord("editorfragshader") + ")"; | |
| 140 | - gui::Editor fragEditor((title + "###FragmentEditor").c_str(), "FragmentEditor", FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 139 | + title = info.shaderName + "(" + info.i18n->GetWord("editorfragshader") + ")"; | |
| 140 | + gui::Editor fragEditor((title + "###FragmentEditor").c_str(), "FragmentEditor", info.FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 141 | 141 | |
| 142 | - title = shaderName + "(" + glfwInfo.i18n->GetWord("editorlua") + ")"; | |
| 143 | - gui::Editor luaEditor((title + "###LuaEditor").c_str(), "LuaEditor", LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 142 | + title = info.shaderName + "(" + info.i18n->GetWord("editorlua") + ")"; | |
| 143 | + gui::Editor luaEditor((title + "###LuaEditor").c_str(), "LuaEditor", info.LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 144 | 144 | |
| 145 | 145 | // シェーダーをコンパイル |
| 146 | - Shader vertexShader(VERT.code, GL_VERTEX_SHADER); | |
| 147 | - Shader fragmentShader(FRAG.code, GL_FRAGMENT_SHADER); | |
| 146 | + Shader vertexShader(info.VERT.code, GL_VERTEX_SHADER); | |
| 147 | + Shader fragmentShader(info.FRAG.code, GL_FRAGMENT_SHADER); | |
| 148 | 148 | |
| 149 | 149 | // シェーダープログラムをリンク |
| 150 | 150 | Program shaderProgram(vertexShader, fragmentShader); |
| 151 | 151 | |
| 152 | 152 | // 頂点データはLuaから受け取る |
| 153 | - lua::LuaEngine luaEngine(LUA.code, &shaderProgram, &glfwInfo); | |
| 153 | + lua::LuaEngine luaEngine(info.LUA.code, &shaderProgram, &info); | |
| 154 | 154 | auto &mesh = luaEngine.GetMesh(); |
| 155 | 155 | |
| 156 | 156 | VertexArrays VAO(1); |
| @@ -174,19 +174,20 @@ | ||
| 174 | 174 | gui::Settings settings; |
| 175 | 175 | |
| 176 | 176 | // メインレンダリングループ |
| 177 | - while (!window.ShouldClose() && glfwInfo.isRunning) { | |
| 178 | - glfwInfo.compile = [&]() { | |
| 179 | - VERT.code = vertEditor.Get().GetText(); | |
| 180 | - FRAG.code = fragEditor.Get().GetText(); | |
| 181 | - LUA.code = luaEditor.Get().GetText(); | |
| 177 | + while (!window.ShouldClose() && info.isRunning) { | |
| 178 | +#pragma region Lambda | |
| 179 | + info.compile = [&]() { | |
| 180 | + info.VERT.code = vertEditor.Get().GetText(); | |
| 181 | + info.FRAG.code = fragEditor.Get().GetText(); | |
| 182 | + info.LUA.code = luaEditor.Get().GetText(); | |
| 182 | 183 | |
| 183 | 184 | try { |
| 184 | 185 | try { |
| 185 | - if (!luaEngine.Validate(LUA.code)) { | |
| 186 | + if (!luaEngine.Validate(info.LUA.code)) { | |
| 186 | 187 | gui::LogEntry entry; |
| 187 | 188 | entry.type = gui::LogType::Error; |
| 188 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 189 | - glfwInfo.cmd->Add(entry); | |
| 189 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 190 | + info.cmd->Add(entry); | |
| 190 | 191 | std::cerr << entry.text << std::endl; |
| 191 | 192 | return; |
| 192 | 193 | } |
| @@ -194,17 +195,17 @@ | ||
| 194 | 195 | gui::LogEntry entry; |
| 195 | 196 | entry.type = gui::LogType::Error; |
| 196 | 197 | entry.text = e.what(); |
| 197 | - glfwInfo.cmd->Add(entry); | |
| 198 | + info.cmd->Add(entry); | |
| 198 | 199 | std::cerr << entry.text << std::endl; |
| 199 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 200 | - glfwInfo.cmd->Add(entry); | |
| 200 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 201 | + info.cmd->Add(entry); | |
| 201 | 202 | std::cerr << entry.text << std::endl; |
| 202 | 203 | return; |
| 203 | 204 | } |
| 204 | 205 | |
| 205 | - shaderProgram.Reload(VERT.code, FRAG.code); | |
| 206 | + shaderProgram.Reload(info.VERT.code, info.FRAG.code); | |
| 206 | 207 | luaEngine.SetProgram(&shaderProgram); |
| 207 | - luaEngine.Reload(LUA.code); | |
| 208 | + luaEngine.Reload(info.LUA.code); | |
| 208 | 209 | { |
| 209 | 210 | lua::LuaMesh newMesh = luaEngine.GetMesh(); |
| 210 | 211 | |
| @@ -237,33 +238,43 @@ | ||
| 237 | 238 | |
| 238 | 239 | gui::LogEntry entry; |
| 239 | 240 | entry.type = gui::LogType::Info; |
| 240 | - entry.text = glfwInfo.i18n->GetWord("consoleloginfocompileok"); | |
| 241 | - glfwInfo.cmd->Add(entry); | |
| 241 | + entry.text = info.i18n->GetWord("consoleloginfocompileok"); | |
| 242 | + info.cmd->Add(entry); | |
| 242 | 243 | std::cout << entry.text << std::endl; |
| 243 | 244 | } catch (const std::exception &e) { |
| 244 | 245 | gui::LogEntry entry; |
| 245 | 246 | entry.type = gui::LogType::Error; |
| 246 | 247 | entry.text = e.what(); |
| 247 | - glfwInfo.cmd->Add(entry); | |
| 248 | + info.cmd->Add(entry); | |
| 248 | 249 | std::cerr << entry.text << std::endl; |
| 249 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 250 | - glfwInfo.cmd->Add(entry); | |
| 250 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidcomp"); | |
| 251 | + info.cmd->Add(entry); | |
| 251 | 252 | std::cerr << entry.text << std::endl; |
| 252 | 253 | } |
| 253 | 254 | }; |
| 254 | 255 | |
| 255 | - glfwInfo.save = [&]() { | |
| 256 | - VERT.code = vertEditor.Get().GetText(); | |
| 257 | - FRAG.code = fragEditor.Get().GetText(); | |
| 258 | - LUA.code = luaEditor.Get().GetText(); | |
| 256 | + info.save = [&]() { | |
| 257 | + if (info.shaderId == 0) { | |
| 258 | + gui::LogEntry entry; | |
| 259 | + entry.type = gui::LogType::Warning; | |
| 260 | + std::cout << entry.text << std::endl; | |
| 261 | + entry.text = "TODO: 保存ダイアログボックス関数は開発中・・・"; | |
| 262 | + info.cmd->Add(entry); | |
| 263 | + std::cout << entry.text << std::endl; | |
| 264 | + return; | |
| 265 | + } | |
| 259 | 266 | |
| 267 | + info.VERT.code = vertEditor.Get().GetText(); | |
| 268 | + info.FRAG.code = fragEditor.Get().GetText(); | |
| 269 | + info.LUA.code = luaEditor.Get().GetText(); | |
| 270 | + | |
| 260 | 271 | try { |
| 261 | 272 | try { |
| 262 | - if (!luaEngine.Validate(LUA.code)) { | |
| 273 | + if (!luaEngine.Validate(info.LUA.code)) { | |
| 263 | 274 | gui::LogEntry entry; |
| 264 | 275 | entry.type = gui::LogType::Error; |
| 265 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 266 | - glfwInfo.cmd->Add(entry); | |
| 276 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 277 | + info.cmd->Add(entry); | |
| 267 | 278 | std::cout << entry.text << std::endl; |
| 268 | 279 | return; |
| 269 | 280 | } |
| @@ -271,81 +282,133 @@ | ||
| 271 | 282 | gui::LogEntry entry; |
| 272 | 283 | entry.type = gui::LogType::Error; |
| 273 | 284 | entry.text = e.what(); |
| 274 | - glfwInfo.cmd->Add(entry); | |
| 285 | + info.cmd->Add(entry); | |
| 275 | 286 | std::cout << entry.text << std::endl; |
| 276 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 277 | - glfwInfo.cmd->Add(entry); | |
| 287 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 288 | + info.cmd->Add(entry); | |
| 278 | 289 | std::cout << entry.text << std::endl; |
| 279 | 290 | return; |
| 280 | 291 | } |
| 281 | 292 | |
| 282 | - db::SaveCode(db, VERT); | |
| 283 | - db::SaveCode(db, FRAG); | |
| 284 | - db::SaveCode(db, LUA); | |
| 293 | + db::SaveCode(db, info.VERT); | |
| 294 | + db::SaveCode(db, info.FRAG); | |
| 295 | + db::SaveCode(db, info.LUA); | |
| 285 | 296 | |
| 286 | 297 | gui::LogEntry entry; |
| 287 | 298 | entry.type = gui::LogType::Info; |
| 288 | - entry.text = glfwInfo.i18n->GetWord("consoleloginfosaveok"); | |
| 289 | - glfwInfo.cmd->Add(entry); | |
| 299 | + entry.text = info.i18n->GetWord("consoleloginfosaveok"); | |
| 300 | + info.cmd->Add(entry); | |
| 290 | 301 | std::cout << entry.text << std::endl; |
| 291 | 302 | } catch (const std::exception &e) { |
| 292 | 303 | gui::LogEntry entry; |
| 293 | 304 | entry.type = gui::LogType::Error; |
| 294 | 305 | entry.text = e.what(); |
| 295 | - glfwInfo.cmd->Add(entry); | |
| 306 | + info.cmd->Add(entry); | |
| 296 | 307 | std::cout << entry.text << std::endl; |
| 297 | - entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 298 | - glfwInfo.cmd->Add(entry); | |
| 308 | + entry.text = info.i18n->GetWord("consolelogerrorluainvalidsave"); | |
| 309 | + info.cmd->Add(entry); | |
| 299 | 310 | std::cout << entry.text << std::endl; |
| 300 | 311 | } |
| 301 | 312 | }; |
| 302 | 313 | |
| 314 | + info.create = [&]() { | |
| 315 | + gui::NewShader newShader(&info); | |
| 316 | + auto shdr = newShader.Make(); | |
| 317 | + | |
| 318 | + info.shaderId = shdr.id; | |
| 319 | + info.shaderName = shdr.name; | |
| 320 | + info.VERT = shdr.vertexShader; | |
| 321 | + info.FRAG = shdr.fragmentShader; | |
| 322 | + info.LUA = shdr.luaCode; | |
| 323 | + | |
| 324 | + vertEditor.SetCode(info.VERT.code); | |
| 325 | + string nTit = info.shaderName + "(" + info.i18n->GetWord("editorvertshader") + ")"; | |
| 326 | + vertEditor.SetTitle(nTit + "###VertexEditor"); | |
| 327 | + | |
| 328 | + fragEditor.SetCode(info.FRAG.code); | |
| 329 | + nTit = info.shaderName + "(" + info.i18n->GetWord("editorfragshader") + ")"; | |
| 330 | + fragEditor.SetTitle(nTit + "###FragmentEditor"); | |
| 331 | + | |
| 332 | + luaEditor.SetCode(info.LUA.code); | |
| 333 | + nTit = info.shaderName + "(" + info.i18n->GetWord("editorlua") + ")"; | |
| 334 | + luaEditor.SetTitle(nTit + "###LuaEditor"); | |
| 335 | + | |
| 336 | + info.compile(); | |
| 337 | + | |
| 338 | + gui::LogEntry entry; | |
| 339 | + entry.type = gui::LogType::Info; | |
| 340 | + entry.text = info.i18n->GetWord("consoleloginfocreateok") + ", ID: " + std::to_string(info.shaderId); | |
| 341 | + info.cmd->Add(entry); | |
| 342 | + std::cout << entry.text << std::endl; | |
| 343 | + }; | |
| 344 | +#pragma endregion | |
| 345 | + | |
| 303 | 346 | glfw.PollEvents(); |
| 304 | 347 | |
| 305 | 348 | bool isManualKey = window.GetKey(GLFW_KEY_F1); |
| 306 | 349 | bool isCompileKey = window.GetKey(GLFW_KEY_F5); |
| 350 | + | |
| 307 | 351 | bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 352 | + bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS); | |
| 353 | + //bool altMod = (window.GetKey(GLFW_KEY_LEFT_ALT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_ALT) == GLFW_PRESS); | |
| 354 | + | |
| 355 | + bool isNewKey = (window.GetKey(GLFW_KEY_N) == GLFW_PRESS && ctrlMod); | |
| 356 | + bool isOpenKey = (window.GetKey(GLFW_KEY_O) == GLFW_PRESS && ctrlMod); | |
| 308 | 357 | bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod); |
| 358 | + bool isSaveAsKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod && shiftMod); | |
| 309 | 359 | bool isQuitKey = (window.GetKey(GLFW_KEY_Q) == GLFW_PRESS && ctrlMod); |
| 310 | 360 | bool isAboutKey = (window.GetKey(GLFW_KEY_H) == GLFW_PRESS && ctrlMod); |
| 311 | 361 | bool isSettingsKey = (window.GetKey(GLFW_KEY_COMMA) == GLFW_PRESS && ctrlMod); |
| 312 | 362 | |
| 313 | 363 | if (!isHold) { |
| 314 | 364 | if (isCompileKey) { |
| 315 | - glfwInfo.compile(); | |
| 365 | + info.compile(); | |
| 316 | 366 | } |
| 317 | 367 | |
| 368 | + if (isNewKey) { | |
| 369 | + info.create(); | |
| 370 | + } | |
| 371 | + | |
| 372 | + if (isOpenKey) {} | |
| 373 | + | |
| 318 | 374 | if (isManualKey) { |
| 319 | - glfwInfo.isManual = true; | |
| 375 | + info.isManual = true; | |
| 320 | 376 | } |
| 321 | 377 | |
| 322 | 378 | if (isSettingsKey) { |
| 323 | - glfwInfo.isSettings = true; | |
| 379 | + info.isSettings = true; | |
| 324 | 380 | } |
| 325 | 381 | |
| 326 | 382 | if (isAboutKey) { |
| 327 | - glfwInfo.isAbout = true; | |
| 383 | + info.isAbout = true; | |
| 328 | 384 | } |
| 329 | 385 | |
| 330 | 386 | if (isSaveKey) { |
| 331 | - glfwInfo.save(); | |
| 387 | + info.save(); | |
| 332 | 388 | } |
| 333 | 389 | |
| 334 | 390 | if (isQuitKey) { |
| 335 | - glfwInfo.isRunning = false; | |
| 391 | + info.isRunning = false; | |
| 336 | 392 | } |
| 337 | 393 | } |
| 338 | 394 | |
| 339 | - isHold = isSaveKey || isCompileKey || isAboutKey || isQuitKey || isManualKey || isSettingsKey; | |
| 395 | + isHold = isSaveKey || | |
| 396 | + isCompileKey || | |
| 397 | + isAboutKey || | |
| 398 | + isQuitKey || | |
| 399 | + isManualKey || | |
| 400 | + isSettingsKey || | |
| 401 | + isNewKey || | |
| 402 | + isOpenKey; | |
| 340 | 403 | |
| 341 | - if (glfwInfo.isLangChange) { | |
| 342 | - string nTit = shaderName + "(" + glfwInfo.i18n->GetWord("editorvertshader") + ")"; | |
| 404 | + if (info.isLangChange) { | |
| 405 | + string nTit = info.shaderName + "(" + info.i18n->GetWord("editorvertshader") + ")"; | |
| 343 | 406 | vertEditor.SetTitle(nTit + "###VertexEditor"); |
| 344 | - nTit = shaderName + "(" + glfwInfo.i18n->GetWord("editorfragshader") + ")"; | |
| 407 | + nTit = info.shaderName + "(" + info.i18n->GetWord("editorfragshader") + ")"; | |
| 345 | 408 | fragEditor.SetTitle(nTit + "###FragmentEditor"); |
| 346 | - nTit = shaderName + "(" + glfwInfo.i18n->GetWord("editorlua") + ")"; | |
| 409 | + nTit = info.shaderName + "(" + info.i18n->GetWord("editorlua") + ")"; | |
| 347 | 410 | luaEditor.SetTitle(nTit + "###LuaEditor"); |
| 348 | - glfwInfo.isLangChange = false; | |
| 411 | + info.isLangChange = false; | |
| 349 | 412 | } |
| 350 | 413 | |
| 351 | 414 | if (window.GetAttrib(glfwpp::Attributes::Iconified) != 0) { |
| @@ -353,7 +416,7 @@ | ||
| 353 | 416 | continue; |
| 354 | 417 | } |
| 355 | 418 | |
| 356 | - gui::showTitleBar(glfwInfo); | |
| 419 | + gui::showTitleBar(info); | |
| 357 | 420 | |
| 358 | 421 | #ifndef PRODUCTION_BUILD |
| 359 | 422 | if (showDemo) ImGui::ShowDemoWindow(&showDemo); |
| @@ -362,12 +425,12 @@ | ||
| 362 | 425 | vertEditor.Render(); |
| 363 | 426 | fragEditor.Render(); |
| 364 | 427 | luaEditor.Render(); |
| 365 | - glfwInfo.cmd->Draw(glfwInfo, glfwInfo.i18n->GetWord("editorconsole").c_str()); | |
| 366 | - about.Draw(glfwInfo); | |
| 367 | - settings.Draw(glfwInfo); | |
| 368 | - manual.Draw(glfwInfo); | |
| 428 | + info.cmd->Draw(info, info.i18n->GetWord("editorconsole").c_str()); | |
| 429 | + about.Draw(info); | |
| 430 | + settings.Draw(info); | |
| 431 | + manual.Draw(info); | |
| 369 | 432 | |
| 370 | - viewport.Draw(glfwInfo); | |
| 433 | + viewport.Draw(info); | |
| 371 | 434 | |
| 372 | 435 | ImGui::Render(); |
| 373 | 436 |
| @@ -244,6 +244,8 @@ | ||
| 244 | 244 | createWord(db, 2, "consoleloginfosaveok", "Shaders and Lua have been saved."); |
| 245 | 245 | createWord(db, 1, "consoleloginfolangchangeok", "言語を変更しました。"); |
| 246 | 246 | createWord(db, 2, "consoleloginfolangchangeok", "Language has been changed."); |
| 247 | + createWord(db, 1, "consoleloginfocreateok", "新しいシェーダーを作成しました。保存するには、「CTRL + S」を押して下さい。"); | |
| 248 | + createWord(db, 2, "consoleloginfocreateok", "New shader has been created. In order to save, press \"CTRL + S\"."); | |
| 247 | 249 | } |
| 248 | 250 | |
| 249 | 251 | i64 shaderId = 0; |
| @@ -39,16 +39,16 @@ | ||
| 39 | 39 | #include <database/locale.hh> |
| 40 | 40 | |
| 41 | 41 | namespace gui { |
| 42 | - void About::Draw(GlfwInfo &glfw) { | |
| 43 | - if (!glfw.isAbout) return; | |
| 42 | + void About::Draw(Info &info) { | |
| 43 | + if (!info.isAbout) return; | |
| 44 | 44 | |
| 45 | 45 | ImGuiWindowFlags flags = 0; |
| 46 | 46 | ImGui::SetNextWindowSize({400, 300}, ImGuiCond_Appearing); |
| 47 | - ImGui::Begin(glfw.i18n->GetWord("helpabout").c_str(), &glfw.isAbout, flags); | |
| 48 | - string name = "Shader Playground " + glfw.version; | |
| 47 | + ImGui::Begin(info.i18n->GetWord("helpabout").c_str(), &info.isAbout, flags); | |
| 48 | + string name = "Shader Playground " + info.version; | |
| 49 | 49 | string copyright; |
| 50 | 50 | string developer; |
| 51 | - if (glfw.i18n->GetCurrentLanguage().code == "ja_JP") { | |
| 51 | + if (info.i18n->GetCurrentLanguage().code == "ja_JP") { | |
| 52 | 52 | copyright = "© 2026 - 076スタジオ合同会社"; |
| 53 | 53 | developer = "開発者:テクニカル諏訪子"; |
| 54 | 54 | } else { |
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | winSize.y - 40.f |
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | - if (ImGui::Button("OK", { btnW, btnH })) glfw.isAbout = false; | |
| 77 | + if (ImGui::Button("OK", { btnW, btnH })) info.isAbout = false; | |
| 78 | 78 | ImGui::End(); |
| 79 | 79 | } |
| 80 | 80 | } // namespace gui |
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | m_Lines.push_back(entry); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - void ConsoleLog::Draw(GlfwInfo &info, cstr title) { | |
| 47 | + void ConsoleLog::Draw(Info &info, cstr title) { | |
| 48 | 48 | ImGui::Begin((string(title) + "###Console").c_str()); |
| 49 | 49 | if (ImGui::Button(info.i18n->GetWord("editorconsoleclear").c_str())) Clear(); |
| 50 | 50 | ImGui::Separator(); |
| @@ -39,31 +39,31 @@ | ||
| 39 | 39 | #include <database/locale.hh> |
| 40 | 40 | |
| 41 | 41 | namespace gui { |
| 42 | - void Manual::Draw(GlfwInfo &glfw) { | |
| 43 | - if (!glfw.isManual) return; | |
| 42 | + void Manual::Draw(Info &info) { | |
| 43 | + if (!info.isManual) return; | |
| 44 | 44 | |
| 45 | 45 | ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse; |
| 46 | 46 | |
| 47 | 47 | ImGui::SetNextWindowSize({ 600, 700 }, ImGuiCond_Appearing); |
| 48 | - ImGui::Begin(glfw.i18n->GetWord("helpmanual").c_str(), &glfw.isManual, flags); | |
| 48 | + ImGui::Begin(info.i18n->GetWord("helpmanual").c_str(), &info.isManual, flags); | |
| 49 | 49 | |
| 50 | 50 | if (ImGui::BeginTabBar("ManualTabs")) { |
| 51 | - if (ImGui::BeginTabItem(glfw.i18n->GetWord("helpmanualoverview").c_str())) { | |
| 51 | + if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualoverview").c_str())) { | |
| 52 | 52 | m_CurPage = "index"; |
| 53 | 53 | ImGui::EndTabItem(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if (ImGui::BeginTabItem(glfw.i18n->GetWord("helpmanualshader").c_str())) { | |
| 56 | + if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualshader").c_str())) { | |
| 57 | 57 | m_CurPage = "shader"; |
| 58 | 58 | ImGui::EndTabItem(); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if (ImGui::BeginTabItem(glfw.i18n->GetWord("helpmanuallua").c_str())) { | |
| 61 | + if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanuallua").c_str())) { | |
| 62 | 62 | m_CurPage = "lua"; |
| 63 | 63 | ImGui::EndTabItem(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if (ImGui::BeginTabItem(glfw.i18n->GetWord("helpmanualhotkey").c_str())) { | |
| 66 | + if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualhotkey").c_str())) { | |
| 67 | 67 | m_CurPage = "hotkeys"; |
| 68 | 68 | ImGui::EndTabItem(); |
| 69 | 69 | } |
| @@ -76,7 +76,7 @@ | ||
| 76 | 76 | ImGui::BeginChild("ManualContent", ImVec2(0, 0), 0, ImGuiWindowFlags_HorizontalScrollbar); |
| 77 | 77 | |
| 78 | 78 | if (m_CurPage == "index") { |
| 79 | - if (glfw.i18n->GetCurrentLanguage().code == "ja_JP") { | |
| 79 | + if (info.i18n->GetCurrentLanguage().code == "ja_JP") { | |
| 80 | 80 | ImGui::TextWrapped("Shader Playgroundへようこそ!"); |
| 81 | 81 | ImGui::Dummy(ImVec2(0, 10)); |
| 82 | 82 | renderMarkdown(R"(# 基本操作 |
| @@ -0,0 +1,116 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#include <gui/newshader.hh> | |
| 38 | +#include <database/locale.hh> | |
| 39 | + | |
| 40 | +namespace gui { | |
| 41 | + NewShader::NewShader(Info *info) : m_Info(info) {} | |
| 42 | + NewShader::~NewShader() {} | |
| 43 | + | |
| 44 | + db::ShaderData NewShader::Make() { | |
| 45 | + db::ShaderData newShader = {}; | |
| 46 | + auto curLang = m_Info->i18n->GetCurrentLanguage().code; | |
| 47 | + newShader.id = 0; | |
| 48 | + if (curLang == "ja_JP") newShader.name = "(名無し)"; | |
| 49 | + else newShader.name = "(Unnamed)"; | |
| 50 | + newShader.description = ""; | |
| 51 | + | |
| 52 | + newShader.vertexShader.id = 0; | |
| 53 | + newShader.vertexShader.type = db::ShaderCodeType::GlslVertex; | |
| 54 | + newShader.vertexShader.code = getDefaultVert(); | |
| 55 | + newShader.vertexShader.filename = ""; | |
| 56 | + | |
| 57 | + newShader.fragmentShader.id = 0; | |
| 58 | + newShader.fragmentShader.type = db::ShaderCodeType::GlslFragment; | |
| 59 | + newShader.fragmentShader.code = getDefaultFrag(); | |
| 60 | + newShader.fragmentShader.filename = ""; | |
| 61 | + | |
| 62 | + newShader.luaCode.id = 0; | |
| 63 | + newShader.luaCode.type = db::ShaderCodeType::Lua; | |
| 64 | + newShader.luaCode.code = getDefaultLua(); | |
| 65 | + newShader.luaCode.filename = ""; | |
| 66 | + | |
| 67 | + return newShader; | |
| 68 | + } | |
| 69 | + | |
| 70 | + /////////////////////////// | |
| 71 | + | |
| 72 | + string NewShader::getDefaultVert() { | |
| 73 | + return R"(#version 460 core | |
| 74 | + | |
| 75 | +layout(location = 0) in vec2 aPosition; | |
| 76 | +layout(location = 1) in vec3 aColor; | |
| 77 | +out vec3 vColor; | |
| 78 | + | |
| 79 | +void main() { | |
| 80 | + vColor = aColor; | |
| 81 | + gl_Position = vec4(aPosition, 0.0, 1.0); | |
| 82 | +})"; | |
| 83 | + } | |
| 84 | + | |
| 85 | + string NewShader::getDefaultFrag() { | |
| 86 | + return R"(#version 460 core | |
| 87 | + | |
| 88 | +in vec3 vColor; | |
| 89 | +out vec4 out_color; | |
| 90 | + | |
| 91 | +void main() { | |
| 92 | + out_color = vec4(vColor, 1.0); | |
| 93 | +})"; | |
| 94 | + } | |
| 95 | + | |
| 96 | + string NewShader::getDefaultLua() { | |
| 97 | + return R"(local mesh = { | |
| 98 | + vertices = { | |
| 99 | + 0, .5, 1, 0, 0, | |
| 100 | + -.5, -.5, 0, 1, 0, | |
| 101 | + .5, -.5, 0, 0, 1 | |
| 102 | + }, | |
| 103 | + indices = { 0, 1, 2 }, | |
| 104 | + | |
| 105 | + attributes = { | |
| 106 | + { location = 0, size = 2, stride = 20, offset = 0 }, -- position | |
| 107 | + { location = 1, size = 3, stride = 20, offset = 8 } -- uv | |
| 108 | + } | |
| 109 | +} | |
| 110 | + | |
| 111 | +le.gfx.set_mesh(mesh) | |
| 112 | + | |
| 113 | +function update() | |
| 114 | +end)"; | |
| 115 | + } | |
| 116 | +} // namespace gui |
| @@ -0,0 +1,40 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#include <gui/openshader.hh> | |
| 38 | + | |
| 39 | +namespace gui { | |
| 40 | +} // namespace gui |
| @@ -0,0 +1,40 @@ | ||
| 1 | +/* | |
| 2 | +# 076 License | |
| 3 | + | |
| 4 | +Copyright (c) テクニカル諏訪子 | |
| 5 | + | |
| 6 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 7 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 8 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 9 | + | |
| 10 | + 1. **Origin Attribution**: | |
| 11 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 12 | + you created the original Software. | |
| 13 | + - If the Software is used in a product, you must either: | |
| 14 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 15 | + or other visible areas, **OR** | |
| 16 | + b. Pay the original developers a fee they specify in writing. | |
| 17 | + 2. **Usage Restriction**: | |
| 18 | + - The Software, or any derivative works, dependencies, or libraries | |
| 19 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 20 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 21 | + limited to: | |
| 22 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 23 | + ideas, or objective reality. | |
| 24 | + - Tools or systems designed to restrict access to information or | |
| 25 | + artistic works. | |
| 26 | + 3. **Notice Preservation**: | |
| 27 | + - This license and the above copyright notice must remain intact in all copies | |
| 28 | + of the source code. | |
| 29 | + | |
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 31 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 32 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 33 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 34 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 35 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 36 | +*/ | |
| 37 | +#include <gui/saveasshader.hh> | |
| 38 | + | |
| 39 | +namespace gui { | |
| 40 | +} // namespace gui |
| @@ -41,18 +41,18 @@ | ||
| 41 | 41 | #include <imgui.h> |
| 42 | 42 | |
| 43 | 43 | namespace gui { |
| 44 | - void Settings::Draw(GlfwInfo &glfw) { | |
| 45 | - if (!glfw.isSettings) return; | |
| 44 | + void Settings::Draw(Info &info) { | |
| 45 | + if (!info.isSettings) return; | |
| 46 | 46 | |
| 47 | 47 | ImGuiWindowFlags flags = 0; |
| 48 | 48 | ImGui::SetNextWindowSize({ 400, 300 }, ImGuiCond_Appearing); |
| 49 | - ImGui::Begin(glfw.i18n->GetWord("settings").c_str(), &glfw.isSettings, flags); | |
| 49 | + ImGui::Begin(info.i18n->GetWord("settings").c_str(), &info.isSettings, flags); | |
| 50 | 50 | |
| 51 | 51 | ImGui::Text("言語 / Language"); |
| 52 | 52 | ImGui::SameLine(); |
| 53 | 53 | cstr items[] = { "日本語 (ja_JP)", "English (en_US)" }; |
| 54 | 54 | const i32 itemCount = IM_COUNTOF(items); |
| 55 | - i32 curId = glfw.i18n->GetCurrentLanguage().id; | |
| 55 | + i32 curId = info.i18n->GetCurrentLanguage().id; | |
| 56 | 56 | static i32 sel = (curId >= 1) ? curId - 1 : 0; |
| 57 | 57 | |
| 58 | 58 | sel = (curId >= 1 && curId <= itemCount) ? curId - 1 : 0; |
| @@ -63,11 +63,11 @@ | ||
| 63 | 63 | const bool isSel = (sel == n); |
| 64 | 64 | if (ImGui::Selectable(items[n], isSel)) { |
| 65 | 65 | sel = n; |
| 66 | - glfw.i18n->SetLanguage(n + 1); | |
| 66 | + info.i18n->SetLanguage(n + 1); | |
| 67 | 67 | gui::LogEntry entry; |
| 68 | 68 | entry.type = gui::LogType::Info; |
| 69 | - entry.text = glfw.i18n->GetWord("consoleloginfolangchangeok"); | |
| 70 | - glfw.cmd->Add(entry); | |
| 69 | + entry.text = info.i18n->GetWord("consoleloginfolangchangeok"); | |
| 70 | + info.cmd->Add(entry); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | if (isSel) { |
| @@ -88,7 +88,7 @@ | ||
| 88 | 88 | winSize.y - 40.f |
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | - if (ImGui::Button("OK", { btnW, btnH })) glfw.isSettings = false; | |
| 91 | + if (ImGui::Button("OK", { btnW, btnH })) info.isSettings = false; | |
| 92 | 92 | ImGui::End(); |
| 93 | 93 | } |
| 94 | 94 | } // namespace gui |
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | #include <ctime> |
| 45 | 45 | |
| 46 | 46 | namespace gui { |
| 47 | - void showTitleBar(GlfwInfo &glfw) { | |
| 47 | + void showTitleBar(Info &info) { | |
| 48 | 48 | ImGui_ImplOpenGL3_NewFrame(); |
| 49 | 49 | ImGui_ImplGlfw_NewFrame(); |
| 50 | 50 | ImGui::NewFrame(); |
| @@ -123,9 +123,11 @@ | ||
| 123 | 123 | ImGui::End(); |
| 124 | 124 | |
| 125 | 125 | if (ImGui::BeginMainMenuBar()) { |
| 126 | - if (ImGui::BeginMenu(glfw.i18n->GetWord("file").c_str())) { | |
| 127 | - if (ImGui::MenuItem(glfw.i18n->GetWord("filenew").c_str(), "CTRL+N", false, false)) {} | |
| 128 | - if (ImGui::MenuItem(glfw.i18n->GetWord("fileopen").c_str(), "Ctrl+O", false, false)) {} | |
| 126 | + if (ImGui::BeginMenu(info.i18n->GetWord("file").c_str())) { | |
| 127 | + if (ImGui::MenuItem(info.i18n->GetWord("filenew").c_str(), "CTRL+N")) { | |
| 128 | + info.create(); | |
| 129 | + } | |
| 130 | + if (ImGui::MenuItem(info.i18n->GetWord("fileopen").c_str(), "Ctrl+O", false, false)) {} | |
| 129 | 131 | //if (ImGui::BeginMenu("最近使った物")) { |
| 130 | 132 | // ImGui::MenuItem("fish_hat.c"); |
| 131 | 133 | // ImGui::MenuItem("fish_hat.inl"); |
| @@ -137,45 +139,45 @@ | ||
| 137 | 139 | // } |
| 138 | 140 | // ImGui::EndMenu(); |
| 139 | 141 | //} |
| 140 | - if (ImGui::MenuItem(glfw.i18n->GetWord("filesave").c_str(), "Ctrl+S")) { | |
| 141 | - glfw.save(); | |
| 142 | + if (ImGui::MenuItem(info.i18n->GetWord("filesave").c_str(), "Ctrl+S")) { | |
| 143 | + info.save(); | |
| 142 | 144 | } |
| 143 | 145 | |
| 144 | 146 | ImGui::Separator(); |
| 145 | - if (ImGui::MenuItem(glfw.i18n->GetWord("quit").c_str(), "CTRL+Q")) { | |
| 146 | - glfw.isRunning = false; | |
| 147 | + if (ImGui::MenuItem(info.i18n->GetWord("quit").c_str(), "CTRL+Q")) { | |
| 148 | + info.isRunning = false; | |
| 147 | 149 | } |
| 148 | 150 | ImGui::EndMenu(); |
| 149 | 151 | } |
| 150 | 152 | |
| 151 | - if (ImGui::BeginMenu(glfw.i18n->GetWord("edit").c_str())) { | |
| 152 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editundo").c_str(), "Ctrl+Z", false, false)) {} | |
| 153 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editredo").c_str(), "Ctrl+Y", false, false)) {} | |
| 153 | + if (ImGui::BeginMenu(info.i18n->GetWord("edit").c_str())) { | |
| 154 | + if (ImGui::MenuItem(info.i18n->GetWord("editundo").c_str(), "Ctrl+Z", false, false)) {} | |
| 155 | + if (ImGui::MenuItem(info.i18n->GetWord("editredo").c_str(), "Ctrl+Y", false, false)) {} | |
| 154 | 156 | ImGui::Separator(); |
| 155 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editcut").c_str(), "Ctrl+X", false, false)) {} | |
| 156 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editcopy").c_str(), "Ctrl+C", false, false)) {} | |
| 157 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, false)) {} | |
| 158 | - if (ImGui::MenuItem(glfw.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, false)) {} | |
| 157 | + if (ImGui::MenuItem(info.i18n->GetWord("editcut").c_str(), "Ctrl+X", false, false)) {} | |
| 158 | + if (ImGui::MenuItem(info.i18n->GetWord("editcopy").c_str(), "Ctrl+C", false, false)) {} | |
| 159 | + if (ImGui::MenuItem(info.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, false)) {} | |
| 160 | + if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, false)) {} | |
| 159 | 161 | ImGui::Separator(); |
| 160 | - if (ImGui::MenuItem(glfw.i18n->GetWord("settings").c_str(), "Ctrl+,")) { | |
| 161 | - glfw.isSettings = true; | |
| 162 | + if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) { | |
| 163 | + info.isSettings = true; | |
| 162 | 164 | } |
| 163 | 165 | ImGui::EndMenu(); |
| 164 | 166 | } |
| 165 | 167 | |
| 166 | - if (ImGui::BeginMenu(glfw.i18n->GetWord("build").c_str())) { | |
| 167 | - if (ImGui::MenuItem(glfw.i18n->GetWord("buildcompile").c_str(), "F5")) { | |
| 168 | - glfw.compile(); | |
| 168 | + if (ImGui::BeginMenu(info.i18n->GetWord("build").c_str())) { | |
| 169 | + if (ImGui::MenuItem(info.i18n->GetWord("buildcompile").c_str(), "F5")) { | |
| 170 | + info.compile(); | |
| 169 | 171 | } |
| 170 | 172 | ImGui::EndMenu(); |
| 171 | 173 | } |
| 172 | 174 | |
| 173 | - if (ImGui::BeginMenu(glfw.i18n->GetWord("help").c_str())) { | |
| 174 | - if (ImGui::MenuItem(glfw.i18n->GetWord("helpmanual").c_str(), "F1")) { | |
| 175 | - glfw.isManual = true; | |
| 175 | + if (ImGui::BeginMenu(info.i18n->GetWord("help").c_str())) { | |
| 176 | + if (ImGui::MenuItem(info.i18n->GetWord("helpmanual").c_str(), "F1")) { | |
| 177 | + info.isManual = true; | |
| 176 | 178 | } |
| 177 | - if (ImGui::MenuItem(glfw.i18n->GetWord("helpabout").c_str(), "CTRL+H")) { | |
| 178 | - glfw.isAbout = true; | |
| 179 | + if (ImGui::MenuItem(info.i18n->GetWord("helpabout").c_str(), "CTRL+H")) { | |
| 180 | + info.isAbout = true; | |
| 179 | 181 | } |
| 180 | 182 | ImGui::EndMenu(); |
| 181 | 183 | } |
| @@ -183,12 +185,12 @@ | ||
| 183 | 185 | ImGui::SameLine(); |
| 184 | 186 | |
| 185 | 187 | f32 side; |
| 186 | - if (glfw.i18n->GetCurrentLanguage().code == "ja_JP") side = 379.f; | |
| 188 | + if (info.i18n->GetCurrentLanguage().code == "ja_JP") side = 379.f; | |
| 187 | 189 | else side = 380.f; |
| 188 | 190 | |
| 189 | 191 | ImGui::SetCursorPosX(ImGui::GetWindowWidth() - side); |
| 190 | 192 | |
| 191 | - string fmt = glfw.i18n->GetWord("currentfps") + ": %.3f ms/frame (%.1f FPS)"; | |
| 193 | + string fmt = info.i18n->GetWord("currentfps") + ": %.3f ms/frame (%.1f FPS)"; | |
| 192 | 194 | ImGui::Text(fmt.c_str(), 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); |
| 193 | 195 | |
| 194 | 196 | ImGui::SameLine(); |
| @@ -114,8 +114,8 @@ | ||
| 114 | 114 | ); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - void ViewPort::Draw(GlfwInfo &glfw) { | |
| 118 | - string tit = glfw.i18n->GetWord("editorviewport") + "###View"; | |
| 117 | + void ViewPort::Draw(Info &info) { | |
| 118 | + string tit = info.i18n->GetWord("editorviewport") + "###View"; | |
| 119 | 119 | ImGui::Begin(tit.c_str()); |
| 120 | 120 | |
| 121 | 121 | ImVec2 avail = ImGui::GetContentRegionAvail(); |
| @@ -45,10 +45,10 @@ | ||
| 45 | 45 | #include <gui/consolelog.hh> |
| 46 | 46 | |
| 47 | 47 | namespace lua { |
| 48 | - LuaEngine::LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo) | |
| 48 | + LuaEngine::LuaEngine(const string &code, Program *prog, Info *info) | |
| 49 | 49 | : m_Code(code) |
| 50 | 50 | , m_Program(prog) |
| 51 | - , m_GlfwInfo(glfwInfo) | |
| 51 | + , m_Info(info) | |
| 52 | 52 | { |
| 53 | 53 | m_Lua = MakeAPI(); |
| 54 | 54 | Execute(m_Lua); |
| @@ -105,7 +105,7 @@ | ||
| 105 | 105 | gui::LogEntry entry = {}; |
| 106 | 106 | entry.type = gui::LogType::Error; |
| 107 | 107 | entry.text = err.what(); |
| 108 | - m_GlfwInfo->cmd->Add(entry); | |
| 108 | + m_Info->cmd->Add(entry); | |
| 109 | 109 | std::cerr << err.what() << std::endl; |
| 110 | 110 | } |
| 111 | 111 | |
| @@ -113,7 +113,7 @@ | ||
| 113 | 113 | gui::LogEntry entry = {}; |
| 114 | 114 | entry.type = gui::LogType::Error; |
| 115 | 115 | entry.text = err.what(); |
| 116 | - m_GlfwInfo->cmd->Add(entry); | |
| 116 | + m_Info->cmd->Add(entry); | |
| 117 | 117 | std::cerr << err.what() << std::endl; |
| 118 | 118 | } |
| 119 | 119 | |
| @@ -402,7 +402,7 @@ | ||
| 402 | 402 | gui::LogEntry entry = {}; |
| 403 | 403 | entry.type = gui::LogType::Normal; |
| 404 | 404 | entry.text = out; |
| 405 | - m_GlfwInfo->cmd->Add(entry); (entry); | |
| 405 | + m_Info->cmd->Add(entry); (entry); | |
| 406 | 406 | std::cerr << entry.text << std::endl; |
| 407 | 407 | }; |
| 408 | 408 | } |
| @@ -411,11 +411,11 @@ | ||
| 411 | 411 | lua["le"]["sys"] = lua.create_table(); |
| 412 | 412 | |
| 413 | 413 | lua["le"]["sys"]["get_time"] = [&]() -> f32 { |
| 414 | - return (f32)m_GlfwInfo->instance->GetTime(); | |
| 414 | + return (f32)m_Info->instance->GetTime(); | |
| 415 | 415 | }; |
| 416 | 416 | |
| 417 | 417 | lua["le"]["sys"]["get_delta_time"] = [&]() -> f32 { |
| 418 | - f32 now = (f32)m_GlfwInfo->instance->GetTime(); | |
| 418 | + f32 now = (f32)m_Info->instance->GetTime(); | |
| 419 | 419 | f32 delta = now - m_LastTime; |
| 420 | 420 | m_LastTime = now; |
| 421 | 421 | if (delta > 1.f / 5) delta = 1.f / 5; |
| @@ -423,12 +423,12 @@ | ||
| 423 | 423 | }; |
| 424 | 424 | |
| 425 | 425 | lua["le"]["sys"]["get_timer_frequency"] = [&]() -> u64 { |
| 426 | - return m_GlfwInfo->instance->GetTimerFrequency(); | |
| 426 | + return m_Info->instance->GetTimerFrequency(); | |
| 427 | 427 | }; |
| 428 | 428 | |
| 429 | 429 | lua["le"]["sys"]["get_resolution"] = [&]() -> Vector2i { |
| 430 | 430 | Vector2i size = {}; |
| 431 | - m_GlfwInfo->window->GetSize(&size.pos.x, &size.pos.y); | |
| 431 | + m_Info->window->GetSize(&size.pos.x, &size.pos.y); | |
| 432 | 432 | return size; |
| 433 | 433 | }; |
| 434 | 434 | |
| @@ -442,12 +442,12 @@ | ||
| 442 | 442 | |
| 443 | 443 | lua["le"]["io"]["get_mouse"] = [&]() -> Vector2d { |
| 444 | 444 | Vector2d cursor{}; |
| 445 | - m_GlfwInfo->window->GetCursorPos(&cursor.pos.x, &cursor.pos.y); | |
| 445 | + m_Info->window->GetCursorPos(&cursor.pos.x, &cursor.pos.y); | |
| 446 | 446 | return cursor; |
| 447 | 447 | }; |
| 448 | 448 | |
| 449 | 449 | lua["le"]["io"]["is_key_down"] = [&](int key) -> bool { |
| 450 | - return m_GlfwInfo->window->GetKey(key) == GLFW_PRESS; | |
| 450 | + return m_Info->window->GetKey(key) == GLFW_PRESS; | |
| 451 | 451 | }; |
| 452 | 452 | } |
| 453 | 453 |