feat(gl): OpenGL 4.1 and the ludic.render3d renderer
Some checks failed
ci / build-and-test (push) Waiting to run
commit-lint / conventional-commits (push) Waiting to run
bootstrap / cfree-fixpoint (push) Has been cancelled
docs / build-and-deploy (push) Successful in 34s

`Gl.*` binds the whole OpenGL 4.1 core API — every entry point of the
platform gl3.h with every GL_* constant, generated by `ludic-dev glgen`
with per-call ABI thunks. Windowed builds get an NSOpenGLContext on the
existing window at Retina resolution; headless builds render into an
offscreen CGL context, so a program that uses Gl.* renders and
screenshots identically under the test harness. It links gl.ll, the
thunks and OpenGL.framework only when used; every other build stays
byte-identical.

packages/ludic.render3d is a physically based renderer written on that
surface: HDRI image-based lighting, GPU-generated terrain with scanned
PBR materials, CDLOD, cascaded shadows, glTF with skinning, instanced
vegetation with impostors, procedural grass, water, SSAO, and an HDR
pipeline with bloom, auto-exposure and ACES.

It also carries this session's work on it: the terrain at half its cost
(10.3 -> 5.4 ms of frame), the streaming hitch that got worse the longer
you played, a resize that emptied the world, and the packaging that lets
a game use the renderer from its own repository — `ludic assets`, the
material manifest shipping with the package, and shader lookup falling
back to the install root. See changes/ for each, with its numbers.

The camping game that drove all of it has moved out to its own
repository, Maroon Lake; examples/rendering/smooth.ludic stays as the
renderer's example here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-10 03:31:12 +03:00
parent 470971bf70
commit f25289db20
90 changed files with 35316 additions and 19853 deletions

View file

@ -0,0 +1,49 @@
# gl_triangle.ludic — the smallest Gl.* program: one shaded triangle through a
# real OpenGL 4.1 core context. Windowed it draws to the screen each frame;
# headless it renders into an offscreen framebuffer and screenshots it, so the
# test harness can look at the result without a display.
# bin/ludic build examples/rendering/gl_triangle.ludic --headless && echo q | build/gl_triangle_headless
program GlTriangle {
property Marker { on: int = 1 }
model Anchor { Marker }
var prog: int = 0
var vao: int = 0
var frame: int = 0
const VS: string = "#version 410 core\nlayout(location=0) in vec2 p; layout(location=1) in vec3 c; out vec3 vc;\nvoid main(){ vc = c; gl_Position = vec4(p, 0.0, 1.0); }\n"
const FS: string = "#version 410 core\nin vec3 vc; out vec4 o;\nvoid main(){ o = vec4(vc, 1.0); }\n"
handler Boot phase Start {
spawn Anchor {}
if not Gl.open(width: 640, height: 360, title: "Ludic GL") { print("no GL context"); quit() }
print(Gl.get_string(name: GL_VERSION))
prog = Gl.program(vs: VS, fs: FS)
vao = Gl.vao()
let vbo = Gl.buffer()
Gl.bind_buffer(target: GL_ARRAY_BUFFER, buffer: vbo)
let v = Gl.floats(15)
Gl.put(v, 0, -0.8); Gl.put(v, 1, -0.8); Gl.put(v, 2, 1.0); Gl.put(v, 3, 0.2); Gl.put(v, 4, 0.1)
Gl.put(v, 5, 0.8); Gl.put(v, 6, -0.8); Gl.put(v, 7, 0.1); Gl.put(v, 8, 1.0); Gl.put(v, 9, 0.2)
Gl.put(v, 10, 0.0); Gl.put(v, 11, 0.8); Gl.put(v, 12, 0.2); Gl.put(v, 13, 0.3); Gl.put(v, 14, 1.0)
Gl.buffer_data(target: GL_ARRAY_BUFFER, size: Gl.bytes_of(15), data: v, usage: GL_STATIC_DRAW)
Gl.enable_vertex_attrib_array(index: 0)
Gl.vertex_attrib_pointer(index: 0, size: 2, type: GL_FLOAT, normalized: 0, stride: 20, offset: null)
Gl.enable_vertex_attrib_array(index: 1)
Gl.vertex_attrib_pointer(index: 1, size: 3, type: GL_FLOAT, normalized: 0, stride: 20, offset: Gl.ptr(null, 8))
Gl.check(tag: "boot")
}
handler Draw phase Render {
Gl.bind_framebuffer(target: GL_FRAMEBUFFER, framebuffer: Gl.screen_fbo())
Gl.viewport(x: 0, y: 0, width: Gl.width(), height: Gl.height())
Gl.clear_color(red: 0.1, green: 0.12, blue: 0.18, alpha: 1.0)
Gl.clear(mask: GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Gl.use_program(prog: prog)
Gl.bind_vertex_array(array: vao)
Gl.draw_arrays(mode: GL_TRIANGLES, first: 0, count: 3)
frame += 1
if frame == 1 { Gl.screenshot(path: "build/gl_triangle.ppm") }
Gl.swap()
}
}