シェーダーコンパイラー
守矢諏訪子 <suwako@076.moe>、2026-06-25 02:49
コミット a43d6c355464f38f56fb38515fe0d674345df969
・親 aaa1d9b
・ファイルを見る
5個のファイル、+52 -4
| @@ -61,6 +61,7 @@ | ||
| 61 | 61 | |
| 62 | 62 | LuaMesh &GetMesh() { return m_Mesh; }; |
| 63 | 63 | const LuaMesh &GetMesh() const { return m_Mesh; }; |
| 64 | + void Reload(const string &code); | |
| 64 | 65 | |
| 65 | 66 | private: |
| 66 | 67 | void BindGraphics(); |
| @@ -53,6 +53,7 @@ | ||
| 53 | 53 | GLuint GetProgram() { return id; } |
| 54 | 54 | |
| 55 | 55 | void Use(); |
| 56 | + void Reload(const string &vert, const string &frag); | |
| 56 | 57 | void ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); |
| 57 | 58 | void Clear(GLbitfield mask = GL_COLOR_BUFFER_BIT); |
| 58 | 59 | GLint GetUniformLocation(string var); |
変更
main.cc
| @@ -168,12 +168,41 @@ | ||
| 168 | 168 | if (ImGui::Button("コンパイル(F5)")) { |
| 169 | 169 | VERT = vertEditor.Get().GetText(); |
| 170 | 170 | FRAG = fragEditor.Get().GetText(); |
| 171 | - //LUA = luaEditor.Get().GetText(); | |
| 171 | + LUA = luaEditor.Get().GetText(); | |
| 172 | 172 | |
| 173 | 173 | 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 | + } | |
| 177 | 206 | } catch (const std::exception &e) { |
| 178 | 207 | std::cerr << e.what() << std::endl; |
| 179 | 208 | } |
| @@ -33,6 +33,7 @@ | ||
| 33 | 33 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 34 | 34 | */ |
| 35 | 35 | #include <lua/luaengine.hh> |
| 36 | +//#include <utility> | |
| 36 | 37 | |
| 37 | 38 | namespace lua { |
| 38 | 39 | LuaEngine::LuaEngine(const string &code) : m_Code(code) { |
| @@ -48,6 +49,12 @@ | ||
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | LuaEngine::~LuaEngine() { |
| 52 | + } | |
| 53 | + | |
| 54 | + void LuaEngine::Reload(const string &code) { | |
| 55 | + m_Code = code; | |
| 56 | + //BindGraphics(); | |
| 57 | + Execute(); | |
| 51 | 58 | } |
| 52 | 59 | |
| 53 | 60 | void LuaEngine::BindGraphics() { |
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | */ |
| 35 | 35 | #include <shader/shader.hh> |
| 36 | 36 | #include <stdexcept> |
| 37 | +#include <utility> | |
| 37 | 38 | |
| 38 | 39 | Shader::Shader(const string &src, GLenum type) { |
| 39 | 40 | id = glCreateShader(type); |
| @@ -73,6 +74,15 @@ | ||
| 73 | 74 | |
| 74 | 75 | Program::~Program() { |
| 75 | 76 | 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); | |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | void Program::Use() { |