This commit is contained in:
agra
2026-02-24 13:37:27 +02:00
parent 170e236764
commit b98711a1d3
13 changed files with 157 additions and 632 deletions

View File

@@ -70,45 +70,6 @@ mat4_translate :: (tx: f32, ty: f32, tz: f32) -> Matrix44 {
m;
}
// ---- Shader helpers ----
compile_shader :: (shader_type: u32, source: [:0]u8) -> u32 {
shader : u32 = glCreateShader(shader_type);
glShaderSource(shader, 1, source, null);
glCompileShader(shader);
status : s32 = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, status);
if status == GL_FALSE {
log_buf : [512]u8 = ---;
glGetShaderInfoLog(shader, 512, null, log_buf);
print("Shader compile error\n");
}
shader;
}
create_program :: (vert_src: [:0]u8, frag_src: [:0]u8) -> u32 {
vs : u32 = compile_shader(GL_VERTEX_SHADER, vert_src);
fs : u32 = compile_shader(GL_FRAGMENT_SHADER, frag_src);
prog : u32 = glCreateProgram();
glAttachShader(prog, vs);
glAttachShader(prog, fs);
glLinkProgram(prog);
status : s32 = 0;
glGetProgramiv(prog, GL_LINK_STATUS, status);
if status == GL_FALSE {
log_buf : [512]u8 = ---;
glGetProgramInfoLog(prog, 512, null, log_buf);
print("Program link error\n");
}
glDeleteShader(vs);
glDeleteShader(fs);
prog;
}
// ---- Main ----
main :: () {

View File

@@ -43,22 +43,23 @@ main :: () -> s32 {
print("listening on http://localhost:{}\n", PORT);
arena := arena_create(65536);
arena : Arena = ---;
arena_alloc := arena.create(context.allocator, 65536);
logger := Logger.{ prefix = "http", count = 0 };
while true {
client := accept(fd, null, null);
if client < 0 { continue; }
push Context.{ arena = @arena, data = xx @logger } {
push Context.{ allocator = arena_alloc, data = xx @logger } {
handle(client);
}
arena_reset(@arena);
arena.reset();
close(client);
}
arena_deinit(@arena);
arena.deinit();
close(fd);
0;
}

View File

@@ -1548,6 +1548,7 @@ END;
print("{}\n", pkg.add(3, 4)); // 7
print("{}\n", pkg.mul(5, 6)); // 30
print("{}\n", pkg.hello()); // hello from testpkg
print("{}\n", pkg.cwd_greet()); // cwd-import-ok
}
// --- Pipe operator ---

View File

@@ -96,3 +96,41 @@ load_gl :: (get_proc: ([:0]u8) -> *void) {
glDepthFunc = xx get_proc("glDepthFunc");
glUniform1f = xx get_proc("glUniform1f");
}
// --- Shader utilities ---
create_program :: (vert_src: [:0]u8, frag_src: [:0]u8) -> u32 {
vs := compile_shader(GL_VERTEX_SHADER, vert_src);
fs := compile_shader(GL_FRAGMENT_SHADER, frag_src);
prog := glCreateProgram();
glAttachShader(prog, vs);
glAttachShader(prog, fs);
glLinkProgram(prog);
status : s32 = 0;
glGetProgramiv(prog, GL_LINK_STATUS, @status);
if status == GL_FALSE {
log_buf: [512]u8 = ---;
glGetProgramInfoLog(prog, 512, null, log_buf);
}
glDeleteShader(vs);
glDeleteShader(fs);
return prog;
}
compile_shader :: (shader_type : u32, source: [:0]u8) -> u32 {
shader := glCreateShader(shader_type);
glShaderSource(shader, 1, source, null);
glCompileShader(shader);
status : s32 = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, @status);
if status == GL_FALSE {
log_buf : [512]u8 = ---;
glGetShaderInfoLog(shader, 512, null, log_buf);
}
return shader;
}

View File

@@ -0,0 +1,5 @@
// This file lives in modules/testpkg/ but imports modules/std.sx
// via cwd-relative path (not relative to this file's directory).
#import "modules/std.sx";
cwd_greet :: () -> string { format("cwd-import-ok"); }