シェーダーコンパイラー

守矢諏訪子 <suwako@076.moe>、2026-06-25 02:49
コミット a43d6c355464f38f56fb38515fe0d674345df969 ・親 aaa1d9b ・ファイルを見る

5個のファイル、+52 -4

@@ -61,6 +61,7 @@
6161
6262 LuaMesh &GetMesh() { return m_Mesh; };
6363 const LuaMesh &GetMesh() const { return m_Mesh; };
64+ void Reload(const string &code);
6465
6566 private:
6667 void BindGraphics();
@@ -53,6 +53,7 @@
5353 GLuint GetProgram() { return id; }
5454
5555 void Use();
56+ void Reload(const string &vert, const string &frag);
5657 void ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
5758 void Clear(GLbitfield mask = GL_COLOR_BUFFER_BIT);
5859 GLint GetUniformLocation(string var);
変更 main.cc
@@ -168,12 +168,41 @@
168168 if (ImGui::Button("コンパイル(F5)")) {
169169 VERT = vertEditor.Get().GetText();
170170 FRAG = fragEditor.Get().GetText();
171- //LUA = luaEditor.Get().GetText();
171+ LUA = luaEditor.Get().GetText();
172172
173173 try {
174- Shader newVert(VERT, GL_VERTEX_SHADER);
175- Shader newFrag(FRAG, GL_FRAGMENT_SHADER);
176- shaderProgram = Program(newVert, newFrag);
174+ shaderProgram.Reload(VERT, FRAG);
175+ luaEngine.Reload(LUA);
176+ {
177+ //lua::LuaEngine newLua(LUA);
178+ lua::LuaMesh newMesh = luaEngine.GetMesh();
179+
180+ VAO.BindVertexArray();
181+
182+ VBO.BindBuffer();
183+ VBO.BufferData(
184+ newMesh.vertices.data(),
185+ newMesh.vertices.size() * sizeof(f32)
186+ );
187+
188+ EBO.BindBuffer();
189+ EBO.BufferData(
190+ newMesh.indices.data(),
191+ newMesh.indices.size() * sizeof(f32)
192+ );
193+
194+ for (const auto &a : newMesh.attr) {
195+ glVertexAttribPointer(
196+ a.location,
197+ a.size,
198+ GL_FLOAT,
199+ GL_FALSE,
200+ a.stride,
201+ (any)(uintptr_t)a.offset
202+ );
203+ glEnableVertexAttribArray(a.location);
204+ }
205+ }
177206 } catch (const std::exception &e) {
178207 std::cerr << e.what() << std::endl;
179208 }
@@ -33,6 +33,7 @@
3333 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434 */
3535 #include <lua/luaengine.hh>
36+//#include <utility>
3637
3738 namespace lua {
3839 LuaEngine::LuaEngine(const string &code) : m_Code(code) {
@@ -48,6 +49,12 @@
4849 }
4950
5051 LuaEngine::~LuaEngine() {
52+ }
53+
54+ void LuaEngine::Reload(const string &code) {
55+ m_Code = code;
56+ //BindGraphics();
57+ Execute();
5158 }
5259
5360 void LuaEngine::BindGraphics() {
@@ -34,6 +34,7 @@
3434 */
3535 #include <shader/shader.hh>
3636 #include <stdexcept>
37+#include <utility>
3738
3839 Shader::Shader(const string &src, GLenum type) {
3940 id = glCreateShader(type);
@@ -73,6 +74,15 @@
7374
7475 Program::~Program() {
7576 glDeleteProgram(id);
77+}
78+
79+void Program::Reload(const string &vert, const string &frag) {
80+ Program newProg(
81+ Shader(vert, GL_VERTEX_SHADER),
82+ Shader(frag, GL_FRAGMENT_SHADER)
83+ );
84+
85+ std::swap(id, newProg.id);
7686 }
7787
7888 void Program::Use() {