Shader Playgroundについてウィンドウ、レイアウト、ビューポート

守矢諏訪子 <suwako@076.moe>、2026-06-26 04:37
コミット a28100b5241912838d1e68efc64a34866cc2ab48 ・親 d917edd ・ファイルを見る

17個のファイル、+422 -105

バイナリファイル

バイナリファイル

@@ -0,0 +1,11 @@
1+#pragma once
2+
3+#include <util/types.hh>
4+#include <util/structs.hh>
5+
6+namespace gui {
7+ class About {
8+ public:
9+ void Draw(GlfwInfo &glfw);
10+ }; // class About
11+} // namespace gui
@@ -0,0 +1,6 @@
1+#pragma once
2+
3+#include <util/types.hh>
4+
5+namespace gui {
6+} // namespace gui
@@ -0,0 +1,6 @@
1+#pragma once
2+
3+#include <util/types.hh>
4+
5+namespace gui {
6+} // namespace gui
削除 include/gui/view.hh
@@ -1,40 +0,0 @@
1-/*
2-Copyright (c) テクニカル諏訪子
3-
4-Permission is hereby granted to any person obtaining a copy of the software
5-Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
6-sublicense, and/or sell copies of the Software, subject to the following conditions:
7-
8- 1. **Origin Attribution**:
9- - You must not misrepresent the origin of the Software; you must not claim
10- you created the original Software.
11- - If the Software is used in a product, you must either:
12- a. Provide clear attribution in the product's documentation, user interface,
13- or other visible areas, **OR**
14- b. Pay the original developers a fee they specify in writing.
15- 2. **Usage Restriction**:
16- - The Software, or any derivative works, dependencies, or libraries
17- incorporating it, must not be used for censorship or to suppress freedom of
18- speech, expression, or creativity. Prohibited uses include, but are not
19- limited to:
20- - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21- ideas, or objective reality.
22- - Tools or systems designed to restrict access to information or
23- artistic works.
24- 3. **Notice Preservation**:
25- - This license and the above copyright notice must remain intact in all copies
26- of the source code.
27-
28-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30-PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32-CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33-OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34-*/
35-#pragma once
36-
37-#include <util/types.hh>
38-
39-namespace gui {
40-} // namespace gui
@@ -0,0 +1,60 @@
1+/*
2+Copyright (c) テクニカル諏訪子
3+
4+Permission is hereby granted to any person obtaining a copy of the software
5+Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
6+sublicense, and/or sell copies of the Software, subject to the following conditions:
7+
8+ 1. **Origin Attribution**:
9+ - You must not misrepresent the origin of the Software; you must not claim
10+ you created the original Software.
11+ - If the Software is used in a product, you must either:
12+ a. Provide clear attribution in the product's documentation, user interface,
13+ or other visible areas, **OR**
14+ b. Pay the original developers a fee they specify in writing.
15+ 2. **Usage Restriction**:
16+ - The Software, or any derivative works, dependencies, or libraries
17+ incorporating it, must not be used for censorship or to suppress freedom of
18+ speech, expression, or creativity. Prohibited uses include, but are not
19+ limited to:
20+ - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21+ ideas, or objective reality.
22+ - Tools or systems designed to restrict access to information or
23+ artistic works.
24+ 3. **Notice Preservation**:
25+ - This license and the above copyright notice must remain intact in all copies
26+ of the source code.
27+
28+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34+*/
35+#pragma once
36+
37+#include <util/types.hh>
38+#include <util/structs.hh>
39+
40+namespace gui {
41+ class ViewPort {
42+ public:
43+ void Init();
44+ void Resize(i32 width, i32 height);
45+ void Draw(GlfwInfo &glfw);
46+
47+ u32 GetFBO() const { return m_FBO; }
48+ u32 GetTexture() const { return m_Texture; }
49+ i32 GetWidth() const { return m_Width; }
50+ i32 GetHeight() const { return m_Height; }
51+
52+ private:
53+ u32 m_FBO = 0;
54+ u32 m_Texture = 0;
55+ u32 m_RBO = 0;
56+
57+ i32 m_Width = 1280;
58+ i32 m_Height = 720;
59+ }; // class View
60+} // namespace gui
@@ -35,12 +35,19 @@
3535 #pragma once
3636
3737 #include <util/glfwpp.hh>
38+#include <version.hh>
3839 #include <functional>
40+#include <string>
3941
4042 struct GlfwInfo {
4143 glfwpp::Instance *instance;
4244 glfwpp::Window *window;
45+
4346 bool isRunning = true;
47+ bool isAbout = false;
48+
49+ std::string version = version::full;
50+
4451 std::function<void()> compile;
4552 std::function<void()> save;
4653 };
変更 main.cc
@@ -48,6 +48,8 @@
4848 #include <gui/guiengine.hh>
4949 #include <gui/titlebar.hh>
5050 #include <gui/editor.hh>
51+#include <gui/viewport.hh>
52+#include <gui/about.hh>
5153 #include <gui/consolelog.hh>
5254
5355 #include <imgui.h>
@@ -77,7 +79,7 @@
7779 window.MakeContextCurrent();
7880 glfw.SwapInterval(1);
7981
80- GlfwInfo glfwInfo = { &glfw, &window, true };
82+ GlfwInfo glfwInfo = { &glfw, &window, true, false };
8183
8284 #ifndef PRODUCTION_BUILD
8385 bool showDemo = true;
@@ -97,11 +99,20 @@
9799
98100 // データベースが未だ存在しなければ、初期設定
99101 sqlite::Instance db;
100- db::Initialize(db);
102+ try {
103+ db::Initialize(db);
104+ } catch (const std::exception &e) {
105+ std::cerr << e.what() << std::endl;
106+ return -1;
107+ }
101108
102109 // コンソール
103110 gui::ConsoleLog cmd;
104111
112+ // ビューポート
113+ gui::ViewPort viewport;
114+ viewport.Init();
115+
105116 // データベースからシェーダーとLuaコードの受け取り
106117 vector<db::ShaderData> codeMap = db::GetAllShaders(db);
107118 u32 shaderId;
@@ -119,13 +130,13 @@
119130 }
120131
121132 string title = shaderName + "(頂点シェーダー)";
122- gui::Editor vertEditor(title, "VertexEditor", VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
133+ gui::Editor vertEditor((title + "###VertexEditor").c_str(), "VertexEditor", VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
123134
124135 title = shaderName + "(フラグメントシェーダー)";
125- gui::Editor fragEditor(title, "FragmentEditor", FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
136+ gui::Editor fragEditor((title + "###FragmentEditor").c_str(), "FragmentEditor", FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
126137
127138 title = shaderName + "(Luaエディター)";
128- gui::Editor luaEditor(title, "LuaEditor", LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont());
139+ gui::Editor luaEditor((title + "###LuaEditor").c_str(), "LuaEditor", LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont());
129140
130141 // シェーダーをコンパイル
131142 Shader vertexShader(VERT.code, GL_VERTEX_SHADER);
@@ -155,6 +166,7 @@
155166 }
156167
157168 bool isHold = false;
169+ gui::About about;
158170
159171 // メインレンダリングループ
160172 while (!window.ShouldClose() && glfwInfo.isRunning) {
@@ -267,12 +279,17 @@
267279 bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
268280 bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod);
269281 bool isQuitKey = (window.GetKey(GLFW_KEY_Q) == GLFW_PRESS && ctrlMod);
282+ bool isAboutKey = (window.GetKey(GLFW_KEY_H) == GLFW_PRESS && ctrlMod);
270283
271284 if (!isHold) {
272285 if (isCompileKey) {
273286 glfwInfo.compile();
274287 }
275288
289+ if (isAboutKey) {
290+ glfwInfo.isAbout = true;
291+ }
292+
276293 if (isSaveKey) {
277294 glfwInfo.save();
278295 }
@@ -282,7 +299,7 @@
282299 }
283300 }
284301
285- isHold = isSaveKey || isCompileKey;
302+ isHold = isSaveKey || isCompileKey || isAboutKey || isQuitKey;
286303
287304 if (window.GetAttrib(glfwpp::Attributes::Iconified) != 0) {
288305 ImGui_ImplGlfw_Sleep(10);
@@ -299,30 +316,15 @@
299316 fragEditor.Render();
300317 luaEditor.Render();
301318 cmd.Draw();
319+ about.Draw(glfwInfo);
302320
303- {
304- static float f = 0.0f;
305- static int counter = 0;
321+ viewport.Draw(glfwInfo);
306322
307- ImGui::Begin("コントロール");
308-
309- if (ImGui::Button("コンパイル(F5)")) {
310- glfwInfo.compile();
311- }
312-
313- ImGui::SameLine();
314-
315- if (ImGui::Button("保存(CTRL + S)")) {
316- glfwInfo.save();
317- }
318-
319- ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ge.GetIO().Framerate, ge.GetIO().Framerate);
320- ImGui::End();
321- }
322-
323323 ImGui::Render();
324324
325325 // 画面をクリア
326+ glBindFramebuffer(GL_FRAMEBUFFER, viewport.GetFBO());
327+ glViewport(0, 0, viewport.GetWidth(), viewport.GetHeight());
326328 shaderProgram.ClearColor(0.f, 0.f, 0.f, 1.f);
327329 shaderProgram.Clear();
328330
@@ -333,9 +335,19 @@
333335 // クアッドを描画
334336 VAO.BindVertexArray();
335337 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
338+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
336339
337340 // バッファをスワップし、イベントを処理
338341 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
342+ if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
343+ GLFWwindow *backup_current_context = glfwGetCurrentContext();
344+
345+ ImGui::UpdatePlatformWindows();
346+ ImGui::RenderPlatformWindowsDefault();
347+
348+ glfwMakeContextCurrent(backup_current_context);
349+ }
350+
339351 window.SwapBuffers();
340352 }
341353
@@ -0,0 +1,70 @@
1+/*
2+Copyright (c) テクニカル諏訪子
3+
4+Permission is hereby granted to any person obtaining a copy of the software
5+Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
6+sublicense, and/or sell copies of the Software, subject to the following conditions:
7+
8+ 1. **Origin Attribution**:
9+ - You must not misrepresent the origin of the Software; you must not claim
10+ you created the original Software.
11+ - If the Software is used in a product, you must either:
12+ a. Provide clear attribution in the product's documentation, user interface,
13+ or other visible areas, **OR**
14+ b. Pay the original developers a fee they specify in writing.
15+ 2. **Usage Restriction**:
16+ - The Software, or any derivative works, dependencies, or libraries
17+ incorporating it, must not be used for censorship or to suppress freedom of
18+ speech, expression, or creativity. Prohibited uses include, but are not
19+ limited to:
20+ - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21+ ideas, or objective reality.
22+ - Tools or systems designed to restrict access to information or
23+ artistic works.
24+ 3. **Notice Preservation**:
25+ - This license and the above copyright notice must remain intact in all copies
26+ of the source code.
27+
28+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34+*/
35+#include <gui/about.hh>
36+#include <imgui.h>
37+
38+namespace gui {
39+ void About::Draw(GlfwInfo &glfw) {
40+ if (!glfw.isAbout) return;
41+
42+ ImGuiWindowFlags flags = 0;
43+ ImGui::SetNextWindowSize({800, 600}, ImGuiCond_FirstUseEver);
44+ ImGui::Begin("Shader Playgroundについて", &glfw.isAbout, flags);
45+ string name = "Shader Playground " + glfw.version;
46+ string copyright = "© 2026 - 076スタジオ合同会社";
47+ string developer = "開発者:テクニカル諏訪子";
48+
49+ ImGui::SetWindowFontScale(1.8f);
50+ ImGui::Text(name.c_str());
51+ ImGui::SetWindowFontScale(1.2f);
52+ ImGui::Separator();
53+ ImGui::Text(copyright.c_str());
54+ ImGui::Text(developer.c_str());
55+
56+ f32 btnW = 80.f;
57+ f32 btnH = 0.f;
58+
59+ ImVec2 winSize = ImGui::GetWindowSize();
60+ ImVec2 cursorPos = ImGui::GetCursorPos();
61+
62+ ImGui::SetCursorPos({
63+ (winSize.x - btnW) * .5f,
64+ winSize.y - 40.f
65+ });
66+
67+ if (ImGui::Button("OK", { btnW, btnH })) glfw.isAbout = false;
68+ ImGui::End();
69+ }
70+} // namespace gui
@@ -41,7 +41,7 @@
4141 }
4242
4343 void ConsoleLog::Draw(cstr title) {
44- ImGui::Begin(title);
44+ ImGui::Begin((string(title) + "###Console").c_str());
4545 if (ImGui::Button("消す")) Clear();
4646 ImGui::Separator();
4747 for (const auto &line : m_Lines) {
@@ -46,6 +46,8 @@
4646 m_MonoFont = io.Fonts->AddFontFromFileTTF("NotoMono-Regular.ttf", 16.f, nullptr, io.Fonts->GetGlyphRangesJapanese());
4747 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
4848 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
49+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
50+ io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
4951
5052 ImGui::StyleColorsDark();
5153
@@ -0,0 +1,4 @@
1+#include <gui/manual.hh>
2+
3+namespace gui {
4+} // namespace gui
@@ -0,0 +1,4 @@
1+#include <gui/settings.hh>
2+
3+namespace gui {
4+} // namespace gui
@@ -33,10 +33,13 @@
3333 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434 */
3535 #include <gui/titlebar.hh>
36+#include <gui/about.hh>
3637
3738 #include <imgui.h>
39+#include <imgui_internal.h>
3840 #include <backends/imgui_impl_glfw.h>
3941 #include <backends/imgui_impl_opengl3.h>
42+#include <ctime>
4043
4144 namespace gui {
4245 void showTitleBar(GlfwInfo &glfw) {
@@ -44,6 +47,75 @@
4447 ImGui_ImplGlfw_NewFrame();
4548 ImGui::NewFrame();
4649
50+ ImGuiWindowFlags window_flags =
51+ ImGuiWindowFlags_MenuBar |
52+ ImGuiWindowFlags_NoDocking;
53+
54+ const ImGuiViewport *viewport = ImGui::GetMainViewport();
55+ ImGui::SetNextWindowPos(viewport->WorkPos);
56+ ImGui::SetNextWindowSize(viewport->WorkSize);
57+ ImGui::SetNextWindowViewport(viewport->ID);
58+
59+ window_flags |= ImGuiWindowFlags_NoTitleBar;
60+ window_flags |= ImGuiWindowFlags_NoCollapse;
61+ window_flags |= ImGuiWindowFlags_NoResize;
62+ window_flags |= ImGuiWindowFlags_NoMove;
63+ window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
64+ window_flags |= ImGuiWindowFlags_NoNavFocus;
65+
66+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
67+ ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
68+
69+ ImGui::Begin("MainDockSpace", nullptr, window_flags);
70+
71+ ImGui::PopStyleVar(2);
72+
73+ ImGuiID dockspace_id = ImGui::GetID("DockSpace");
74+ ImGui::DockSpace(dockspace_id);
75+
76+ static bool firstLayout = true;
77+ if (firstLayout) {
78+ firstLayout = false;
79+
80+ ImGui::DockBuilderRemoveNode(dockspace_id);
81+ ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);
82+
83+ const ImGuiViewport *viewport = ImGui::GetMainViewport();
84+ ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
85+
86+ ImGuiID dock_main = dockspace_id;
87+ ImGuiID dock_right = 0;
88+ ImGuiID dock_bottom = 0;
89+
90+ dock_bottom = ImGui::DockBuilderSplitNode(
91+ dock_main,
92+ ImGuiDir_Down,
93+ 0.25f,
94+ nullptr,
95+ &dock_main
96+ );
97+
98+ dock_right = ImGui::DockBuilderSplitNode(
99+ dock_main,
100+ ImGuiDir_Right,
101+ 0.45f,
102+ nullptr,
103+ &dock_main
104+ );
105+
106+ ImGui::DockBuilderDockWindow("View", dock_main);
107+
108+ ImGui::DockBuilderDockWindow("VertexEditor", dock_right);
109+ ImGui::DockBuilderDockWindow("FragmentEditor", dock_right);
110+ ImGui::DockBuilderDockWindow("LuaEditor", dock_right);
111+
112+ ImGui::DockBuilderDockWindow("Console", dock_bottom);
113+
114+ ImGui::DockBuilderFinish(dockspace_id);
115+ }
116+
117+ ImGui::End();
118+
47119 if (ImGui::BeginMainMenuBar()) {
48120 if (ImGui::BeginMenu("ファイル")) {
49121 if (ImGui::MenuItem("新しいファイル", "CTRL+N", false, false)) {}
@@ -92,7 +164,9 @@
92164
93165 if (ImGui::BeginMenu("ヘルプ")) {
94166 if (ImGui::MenuItem("マニュアル", "F1")) {}
95- if (ImGui::MenuItem("Shader Playgroundについて", "F12")) {}
167+ if (ImGui::MenuItem("Shader Playgroundについて", "CTRL+H")) {
168+ glfw.isAbout = true;
169+ }
96170 ImGui::EndMenu();
97171 }
98172
@@ -101,6 +175,20 @@
101175 if (ImGui::MenuItem("English")) {}
102176 ImGui::EndMenu();
103177 }
178+
179+ ImGui::SameLine();
180+
181+ f32 rightW = ImGui::GetContentRegionAvail().x;
182+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + rightW - 400.f);
183+ ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
184+
185+ ImGui::SameLine();
186+ char timeBuf[64];
187+ time_t now = time(nullptr);
188+ tm *local = localtime(&now);
189+ strftime(timeBuf, sizeof(timeBuf), "%Y年%m月日%d日 %H:%M:%S", local);
190+ ImGui::Text(" | %s", timeBuf);
191+
104192 ImGui::EndMainMenuBar();
105193 }
106194 }
削除 src/gui/view.cc
@@ -1,38 +0,0 @@
1-/*
2-Copyright (c) テクニカル諏訪子
3-
4-Permission is hereby granted to any person obtaining a copy of the software
5-Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
6-sublicense, and/or sell copies of the Software, subject to the following conditions:
7-
8- 1. **Origin Attribution**:
9- - You must not misrepresent the origin of the Software; you must not claim
10- you created the original Software.
11- - If the Software is used in a product, you must either:
12- a. Provide clear attribution in the product's documentation, user interface,
13- or other visible areas, **OR**
14- b. Pay the original developers a fee they specify in writing.
15- 2. **Usage Restriction**:
16- - The Software, or any derivative works, dependencies, or libraries
17- incorporating it, must not be used for censorship or to suppress freedom of
18- speech, expression, or creativity. Prohibited uses include, but are not
19- limited to:
20- - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21- ideas, or objective reality.
22- - Tools or systems designed to restrict access to information or
23- artistic works.
24- 3. **Notice Preservation**:
25- - This license and the above copyright notice must remain intact in all copies
26- of the source code.
27-
28-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30-PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32-CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33-OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34-*/
35-#include <gui/view.hh>
36-
37-namespace gui {
38-} // namespace gui
@@ -0,0 +1,125 @@
1+/*
2+Copyright (c) テクニカル諏訪子
3+
4+Permission is hereby granted to any person obtaining a copy of the software
5+Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
6+sublicense, and/or sell copies of the Software, subject to the following conditions:
7+
8+ 1. **Origin Attribution**:
9+ - You must not misrepresent the origin of the Software; you must not claim
10+ you created the original Software.
11+ - If the Software is used in a product, you must either:
12+ a. Provide clear attribution in the product's documentation, user interface,
13+ or other visible areas, **OR**
14+ b. Pay the original developers a fee they specify in writing.
15+ 2. **Usage Restriction**:
16+ - The Software, or any derivative works, dependencies, or libraries
17+ incorporating it, must not be used for censorship or to suppress freedom of
18+ speech, expression, or creativity. Prohibited uses include, but are not
19+ limited to:
20+ - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21+ ideas, or objective reality.
22+ - Tools or systems designed to restrict access to information or
23+ artistic works.
24+ 3. **Notice Preservation**:
25+ - This license and the above copyright notice must remain intact in all copies
26+ of the source code.
27+
28+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34+*/
35+#include <glad/glad.h>
36+#include <gui/viewport.hh>
37+#include <imgui.h>
38+
39+namespace gui {
40+ void ViewPort::Init() {
41+ glGenFramebuffers(1, &m_FBO);
42+ glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
43+
44+ glGenTextures(1, &m_Texture);
45+ glBindTexture(GL_TEXTURE_2D, m_Texture);
46+ glTexImage2D(
47+ GL_TEXTURE_2D,
48+ 0,
49+ GL_RGB,
50+ m_Width,
51+ m_Height,
52+ 0,
53+ GL_RGB,
54+ GL_UNSIGNED_BYTE,
55+ nullptr
56+ );
57+
58+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
59+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
60+
61+ glFramebufferTexture2D(
62+ GL_FRAMEBUFFER,
63+ GL_COLOR_ATTACHMENT0,
64+ GL_TEXTURE_2D,
65+ m_Texture,
66+ 0
67+ );
68+
69+ glGenRenderbuffers(1, &m_RBO);
70+ glBindRenderbuffer(GL_RENDERBUFFER, m_RBO);
71+ glRenderbufferStorage(
72+ GL_RENDERBUFFER,
73+ GL_DEPTH24_STENCIL8,
74+ m_Width,
75+ m_Height
76+ );
77+
78+ glFramebufferRenderbuffer(
79+ GL_FRAMEBUFFER,
80+ GL_DEPTH_STENCIL_ATTACHMENT,
81+ GL_RENDERBUFFER,
82+ m_RBO
83+ );
84+
85+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
86+ }
87+
88+ void ViewPort::Resize(i32 width, i32 height) {
89+ m_Width = width;
90+ m_Height = height;
91+
92+ glBindTexture(GL_TEXTURE_2D, m_Texture);
93+ glTexImage2D(
94+ GL_TEXTURE_2D,
95+ 0,
96+ GL_RGB,
97+ width,
98+ height,
99+ 0,
100+ GL_RGB,
101+ GL_UNSIGNED_BYTE,
102+ nullptr
103+ );
104+
105+ glBindRenderbuffer(GL_RENDERBUFFER, m_RBO);
106+ glRenderbufferStorage(
107+ GL_RENDERBUFFER,
108+ GL_DEPTH24_STENCIL8,
109+ width,
110+ height
111+ );
112+ }
113+
114+ void ViewPort::Draw(GlfwInfo &glfw) {
115+ ImGui::Begin("ビューポート###View");
116+
117+ ImVec2 avail = ImGui::GetContentRegionAvail();
118+ if ((i32)avail.x != m_Width || (i32)avail.y != m_Height) {
119+ Resize((i32)avail.x, (i32)avail.y);
120+ }
121+
122+ ImGui::Image((ImTextureID)(intptr_t)m_Texture, avail, ImVec2(0, 1), ImVec2(1, 0));
123+ ImGui::End();
124+ }
125+} // namespace gui