From 47be135221724f7e0ace603df1f0cef350a5b44e Mon Sep 17 00:00:00 2001 From: Diego Lopes Date: Sat, 21 Mar 2026 12:06:16 -0400 Subject: [PATCH] Refactor OpenGL bindings and clean up unused functions in lua.cpp and opengl.cpp Update video texture reference in test.lua and enhance .gitignore for media files --- .gitignore | 12 ++++++++ samples/test.lua | 2 +- src/lua.cpp | 75 +++++++++++------------------------------------- src/opengl.cpp | 68 ------------------------------------------- src/opengl.h | 29 ------------------- 5 files changed, 30 insertions(+), 156 deletions(-) diff --git a/.gitignore b/.gitignore index 912713d..c3f6db6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,15 @@ build/ compile_commands.json CMakeUserPresets.json cmake/ +*.mp4 +*.mkv +*.avi +*.mov +*.flv +*.wmv +*.mp3 +*.wav +*.ogg +*.flac +*.aac +*.opus diff --git a/samples/test.lua b/samples/test.lua index 3faefcb..682669d 100644 --- a/samples/test.lua +++ b/samples/test.lua @@ -2,7 +2,7 @@ effect = nil video = nil function _create() - video = Texture.FromGStreamer("filesrc location=" .. Resolve("sunset.mkv")) + video = Texture.FromGStreamer("filesrc location=" .. Resolve("video.mkv")) local fxSrc = [[uniform sampler2D uTexture; diff --git a/src/lua.cpp b/src/lua.cpp index 4e24290..c600671 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -384,70 +384,23 @@ static void RegisterOpenGL(sol::state& lua) { static_cast(&OpenGL::Clear), static_cast(&OpenGL::Clear) ); - gl["ClearDepth"] = &OpenGL::ClearDepth; - - // ── Viewport ──────────────────────────────────────────────────────── - gl["SetViewport"] = &OpenGL::SetViewport; // ── Blending ──────────────────────────────────────────────────────── gl["EnableBlending"] = &OpenGL::EnableBlending; gl["DisableBlending"] = &OpenGL::DisableBlending; gl["SetBlendFunc"] = &OpenGL::SetBlendFunc; - // ── Depth ─────────────────────────────────────────────────────────── - gl["EnableDepthTest"] = &OpenGL::EnableDepthTest; - gl["DisableDepthTest"] = &OpenGL::DisableDepthTest; - gl["SetDepthFunc"] = &OpenGL::SetDepthFunc; - gl["SetDepthMask"] = &OpenGL::SetDepthMask; - - // ── Culling ───────────────────────────────────────────────────────── - gl["EnableCullFace"] = &OpenGL::EnableCullFace; - gl["DisableCullFace"] = &OpenGL::DisableCullFace; - gl["SetCullFace"] = &OpenGL::SetCullFace; - - // ── Scissor ───────────────────────────────────────────────────────── - gl["EnableScissorTest"] = &OpenGL::EnableScissorTest; - gl["DisableScissorTest"] = &OpenGL::DisableScissorTest; - gl["SetScissor"] = &OpenGL::SetScissor; - - // ── Wireframe ─────────────────────────────────────────────────────── - gl["SetWireframe"] = &OpenGL::SetWireframe; - - // ── Color Mask ────────────────────────────────────────────────────── - gl["SetColorMask"] = &OpenGL::SetColorMask; - - // ── Textures ───────────────────────────────────────────────────────── - gl["ActiveTexture"] = &OpenGL::ActiveTexture; - - // ── GL enum constants ─────────────────────────────────────────────── - auto glEnum = lua.create_named_table("GL"); - // Blend factors - glEnum["ZERO"] = GL_ZERO; - glEnum["ONE"] = GL_ONE; - glEnum["SRC_COLOR"] = GL_SRC_COLOR; - glEnum["ONE_MINUS_SRC_COLOR"] = GL_ONE_MINUS_SRC_COLOR; - glEnum["DST_COLOR"] = GL_DST_COLOR; - glEnum["ONE_MINUS_DST_COLOR"] = GL_ONE_MINUS_DST_COLOR; - glEnum["SRC_ALPHA"] = GL_SRC_ALPHA; - glEnum["ONE_MINUS_SRC_ALPHA"] = GL_ONE_MINUS_SRC_ALPHA; - glEnum["DST_ALPHA"] = GL_DST_ALPHA; - glEnum["ONE_MINUS_DST_ALPHA"] = GL_ONE_MINUS_DST_ALPHA; - - // Depth functions - glEnum["NEVER"] = GL_NEVER; - glEnum["LESS"] = GL_LESS; - glEnum["EQUAL"] = GL_EQUAL; - glEnum["LEQUAL"] = GL_LEQUAL; - glEnum["GREATER"] = GL_GREATER; - glEnum["NOTEQUAL"] = GL_NOTEQUAL; - glEnum["GEQUAL"] = GL_GEQUAL; - glEnum["ALWAYS"] = GL_ALWAYS; - - // Cull face - glEnum["FRONT"] = GL_FRONT; - glEnum["BACK"] = GL_BACK; - glEnum["FRONT_AND_BACK"] = GL_FRONT_AND_BACK; + gl["ZERO"] = GL_ZERO; + gl["ONE"] = GL_ONE; + gl["SRC_COLOR"] = GL_SRC_COLOR; + gl["ONE_MINUS_SRC_COLOR"] = GL_ONE_MINUS_SRC_COLOR; + gl["DST_COLOR"] = GL_DST_COLOR; + gl["ONE_MINUS_DST_COLOR"] = GL_ONE_MINUS_DST_COLOR; + gl["SRC_ALPHA"] = GL_SRC_ALPHA; + gl["ONE_MINUS_SRC_ALPHA"] = GL_ONE_MINUS_SRC_ALPHA; + gl["DST_ALPHA"] = GL_DST_ALPHA; + gl["ONE_MINUS_DST_ALPHA"] = GL_ONE_MINUS_DST_ALPHA; } void RegisterLuaBindings(sol::state& lua) { @@ -464,4 +417,10 @@ void RegisterLuaBindings(sol::state& lua) { RegisterFrameBuffer(lua); RegisterEffect(lua); RegisterOpenGL(lua); -} + + // Globals + lua["DesktopSize"] = g_DesktopSize; + lua["Displays"] = sol::as_table(g_Displays); + lua["Mouse"] = g_Mouse; + lua["Time"] = &g_Time; +} \ No newline at end of file diff --git a/src/opengl.cpp b/src/opengl.cpp index 07f2acb..659c24e 100644 --- a/src/opengl.cpp +++ b/src/opengl.cpp @@ -16,16 +16,6 @@ void Clear(const Vector4& color) { Clear(color.x, color.y, color.z, color.w); } -void ClearDepth(float depth) { - glClearDepth(depth); - glClear(GL_DEPTH_BUFFER_BIT); -} - -// ── Viewport ──────────────────────────────────────────────────────────── -void SetViewport(int x, int y, int width, int height) { - glViewport(x, y, width, height); -} - // ── Blending ──────────────────────────────────────────────────────────── void EnableBlending() { glEnable(GL_BLEND); @@ -39,62 +29,4 @@ void SetBlendFunc(GLenum src, GLenum dst) { glBlendFunc(src, dst); } -// ── Depth ─────────────────────────────────────────────────────────────── -void EnableDepthTest() { - glEnable(GL_DEPTH_TEST); -} - -void DisableDepthTest() { - glDisable(GL_DEPTH_TEST); -} - -void SetDepthFunc(GLenum func) { - glDepthFunc(func); -} - -void SetDepthMask(bool write) { - glDepthMask(write ? GL_TRUE : GL_FALSE); -} - -// ── Culling ───────────────────────────────────────────────────────────── -void EnableCullFace() { - glEnable(GL_CULL_FACE); -} - -void DisableCullFace() { - glDisable(GL_CULL_FACE); -} - -void SetCullFace(GLenum face) { - glCullFace(face); -} - -// ── Scissor ───────────────────────────────────────────────────────────── -void EnableScissorTest() { - glEnable(GL_SCISSOR_TEST); -} - -void DisableScissorTest() { - glDisable(GL_SCISSOR_TEST); -} - -void SetScissor(int x, int y, int width, int height) { - glScissor(x, y, width, height); -} - -// ── Wireframe ─────────────────────────────────────────────────────────── -void SetWireframe(bool enabled) { - glPolygonMode(GL_FRONT_AND_BACK, enabled ? GL_LINE : GL_FILL); -} - -// ── Color Mask ────────────────────────────────────────────────────────── -void SetColorMask(bool r, bool g, bool b, bool a) { - glColorMask(r, g, b, a); -} - -void ActiveTexture(size_t textureUnit) -{ - glActiveTexture(GL_TEXTURE0 + static_cast(textureUnit)); -} - } // namespace OpenGL diff --git a/src/opengl.h b/src/opengl.h index daa1794..47d969b 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -9,39 +9,10 @@ namespace OpenGL { void Clear(float r, float g, float b, float a = 1.0f); void Clear(const Vector3& color); void Clear(const Vector4& color); -void ClearDepth(float depth = 1.0f); - -// ── Viewport ──────────────────────────────────────────────────────────── -void SetViewport(int x, int y, int width, int height); // ── Blending ──────────────────────────────────────────────────────────── void EnableBlending(); void DisableBlending(); void SetBlendFunc(GLenum src, GLenum dst); -// ── Depth ─────────────────────────────────────────────────────────────── -void EnableDepthTest(); -void DisableDepthTest(); -void SetDepthFunc(GLenum func); -void SetDepthMask(bool write); - -// ── Culling ───────────────────────────────────────────────────────────── -void EnableCullFace(); -void DisableCullFace(); -void SetCullFace(GLenum face); - -// ── Scissor ───────────────────────────────────────────────────────────── -void EnableScissorTest(); -void DisableScissorTest(); -void SetScissor(int x, int y, int width, int height); - -// ── Wireframe ─────────────────────────────────────────────────────────── -void SetWireframe(bool enabled); - -// ── Color Mask ────────────────────────────────────────────────────────── -void SetColorMask(bool r, bool g, bool b, bool a); - -// ── Textures ──────────────────────────────────────────────────────────── -void ActiveTexture(size_t textureUnit); - } // namespace OpenGL