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
This commit is contained in:
Diego Lopes
2026-03-21 12:06:16 -04:00
parent f60384c5c3
commit 47be135221
5 changed files with 30 additions and 156 deletions

12
.gitignore vendored
View File

@@ -3,3 +3,15 @@ build/
compile_commands.json compile_commands.json
CMakeUserPresets.json CMakeUserPresets.json
cmake/ cmake/
*.mp4
*.mkv
*.avi
*.mov
*.flv
*.wmv
*.mp3
*.wav
*.ogg
*.flac
*.aac
*.opus

View File

@@ -2,7 +2,7 @@ effect = nil
video = nil video = nil
function _create() function _create()
video = Texture.FromGStreamer("filesrc location=" .. Resolve("sunset.mkv")) video = Texture.FromGStreamer("filesrc location=" .. Resolve("video.mkv"))
local fxSrc = [[uniform sampler2D uTexture; local fxSrc = [[uniform sampler2D uTexture;

View File

@@ -384,70 +384,23 @@ static void RegisterOpenGL(sol::state& lua) {
static_cast<void(*)(const Vector3&)>(&OpenGL::Clear), static_cast<void(*)(const Vector3&)>(&OpenGL::Clear),
static_cast<void(*)(const Vector4&)>(&OpenGL::Clear) static_cast<void(*)(const Vector4&)>(&OpenGL::Clear)
); );
gl["ClearDepth"] = &OpenGL::ClearDepth;
// ── Viewport ────────────────────────────────────────────────────────
gl["SetViewport"] = &OpenGL::SetViewport;
// ── Blending ──────────────────────────────────────────────────────── // ── Blending ────────────────────────────────────────────────────────
gl["EnableBlending"] = &OpenGL::EnableBlending; gl["EnableBlending"] = &OpenGL::EnableBlending;
gl["DisableBlending"] = &OpenGL::DisableBlending; gl["DisableBlending"] = &OpenGL::DisableBlending;
gl["SetBlendFunc"] = &OpenGL::SetBlendFunc; 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 // Blend factors
glEnum["ZERO"] = GL_ZERO; gl["ZERO"] = GL_ZERO;
glEnum["ONE"] = GL_ONE; gl["ONE"] = GL_ONE;
glEnum["SRC_COLOR"] = GL_SRC_COLOR; gl["SRC_COLOR"] = GL_SRC_COLOR;
glEnum["ONE_MINUS_SRC_COLOR"] = GL_ONE_MINUS_SRC_COLOR; gl["ONE_MINUS_SRC_COLOR"] = GL_ONE_MINUS_SRC_COLOR;
glEnum["DST_COLOR"] = GL_DST_COLOR; gl["DST_COLOR"] = GL_DST_COLOR;
glEnum["ONE_MINUS_DST_COLOR"] = GL_ONE_MINUS_DST_COLOR; gl["ONE_MINUS_DST_COLOR"] = GL_ONE_MINUS_DST_COLOR;
glEnum["SRC_ALPHA"] = GL_SRC_ALPHA; gl["SRC_ALPHA"] = GL_SRC_ALPHA;
glEnum["ONE_MINUS_SRC_ALPHA"] = GL_ONE_MINUS_SRC_ALPHA; gl["ONE_MINUS_SRC_ALPHA"] = GL_ONE_MINUS_SRC_ALPHA;
glEnum["DST_ALPHA"] = GL_DST_ALPHA; gl["DST_ALPHA"] = GL_DST_ALPHA;
glEnum["ONE_MINUS_DST_ALPHA"] = GL_ONE_MINUS_DST_ALPHA; gl["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;
} }
void RegisterLuaBindings(sol::state& lua) { void RegisterLuaBindings(sol::state& lua) {
@@ -464,4 +417,10 @@ void RegisterLuaBindings(sol::state& lua) {
RegisterFrameBuffer(lua); RegisterFrameBuffer(lua);
RegisterEffect(lua); RegisterEffect(lua);
RegisterOpenGL(lua); RegisterOpenGL(lua);
// Globals
lua["DesktopSize"] = g_DesktopSize;
lua["Displays"] = sol::as_table(g_Displays);
lua["Mouse"] = g_Mouse;
lua["Time"] = &g_Time;
} }

View File

@@ -16,16 +16,6 @@ void Clear(const Vector4& color) {
Clear(color.x, color.y, color.z, color.w); 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 ──────────────────────────────────────────────────────────── // ── Blending ────────────────────────────────────────────────────────────
void EnableBlending() { void EnableBlending() {
glEnable(GL_BLEND); glEnable(GL_BLEND);
@@ -39,62 +29,4 @@ void SetBlendFunc(GLenum src, GLenum dst) {
glBlendFunc(src, 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<GLenum>(textureUnit));
}
} // namespace OpenGL } // namespace OpenGL

View File

@@ -9,39 +9,10 @@ namespace OpenGL {
void Clear(float r, float g, float b, float a = 1.0f); void Clear(float r, float g, float b, float a = 1.0f);
void Clear(const Vector3& color); void Clear(const Vector3& color);
void Clear(const Vector4& color); void Clear(const Vector4& color);
void ClearDepth(float depth = 1.0f);
// ── Viewport ────────────────────────────────────────────────────────────
void SetViewport(int x, int y, int width, int height);
// ── Blending ──────────────────────────────────────────────────────────── // ── Blending ────────────────────────────────────────────────────────────
void EnableBlending(); void EnableBlending();
void DisableBlending(); void DisableBlending();
void SetBlendFunc(GLenum src, GLenum dst); 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 } // namespace OpenGL