diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b2c2a9..e047be3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,7 @@ jobs: run: | dub build :clear dub build :sgl_context + dub build :sgl_points dub build :debugtext_print # dub build :cube # dub build :blend diff --git a/README.md b/README.md index ca166ae..0886feb 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ zig build run-debugtext_print -Doptimize=ReleaseFast zig build run-mrt -Doptimize=ReleaseFast zig build run-saudio -Doptimize=ReleaseFast zig build run-sgl_context -Doptimize=ReleaseFast +zig build run-sgl_points -Doptimize=ReleaseFast zig build run-user_data -Doptimize=ReleaseFast zig build run-triangle -Doptimize=ReleaseFast diff --git a/build.zig b/build.zig index bef76f6..fb6fffc 100644 --- a/build.zig +++ b/build.zig @@ -226,6 +226,7 @@ pub fn build(b: *Build) !void { "imgui", "saudio", "sgl_context", + "sgl_points", "debugtext_print", "user_data", // Need GC for user data [associative array] }; @@ -360,10 +361,10 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep { var objpath: []const u8 = undefined; // needed for wasm build if (b.cache_root.path) |path| { // immutable state hash - objpath = b.pathJoin(&.{ path, "o", &b.cache.hash.peek() }); + objpath = b.pathJoin(&.{ path, "o", &b.graph.cache.hash.peek() }); try cmds.append(b.fmt("-od={s}", .{objpath})); // mutable state hash (ldc2 cache - llvm-ir2obj) - try cmds.append(b.fmt("-cache={s}", .{b.pathJoin(&.{ path, "o", &b.cache.hash.final() })})); + try cmds.append(b.fmt("-cache={s}", .{b.pathJoin(&.{ path, "o", &b.graph.cache.hash.final() })})); } // name object files uniquely (so the files don't collide) try cmds.append("-oq"); @@ -722,6 +723,8 @@ pub fn emLinkStep(b: *Build, options: EmLinkOptions) !*Build.Step.Run { try emcc_cmd.append(emcc_path); if (options.optimize == .Debug) { try emcc_cmd.append("-Og"); + try emcc_cmd.append("-sSAFE_HEAP=1"); + try emcc_cmd.append("-sSTACK_OVERFLOW_CHECK=1"); } else { try emcc_cmd.append("-sASSERTIONS=0"); if (options.optimize == .ReleaseSmall) { diff --git a/build.zig.zon b/build.zig.zon index 18fe736..a75a4e4 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -18,8 +18,8 @@ .hash = "12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d", }, .emsdk = .{ - .url = "git+https://github.com/emscripten-core/emsdk#2aa74907151b2caa9da865fd0d36436fdce792f0", - .hash = "1220500fe26858fc95f2a1166df2ba1a419ab9af3219383b0e57026b0928739c8e57", + .url = "git+https://github.com/emscripten-core/emsdk#c18280c8f3f8f088b4337f0f6a5fdb2be0d67179", + .hash = "12203d61e8947f25993a86b4d73e2d91b4c1d96f1aa07c581b7dffba7cb5ca91bc35", }, .wasmd = .{ .url = "git+https://github.com/kassane/wasmd#067e21e29aea24ec936d6c6b859f7c9a79894f78", diff --git a/dub.sdl b/dub.sdl index 5a60256..edcc0bf 100644 --- a/dub.sdl +++ b/dub.sdl @@ -36,7 +36,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -47,7 +47,18 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" +} +subPackage { + name "sgl_points" + targetType "executable" + targetPath "build" + sourceFiles "src/examples/sgl_points.d" + libs "sokol" + lflags "-Lzig-out/lib" platform="posix" + lflags "/LIBPATH:zig-out/lib" platform="windows" + excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_context.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -58,7 +69,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/saudio.d" "src/examples/clear.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/clear.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -69,7 +80,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -80,7 +91,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/triangle.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -91,7 +102,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/triangle.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -102,7 +113,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -113,7 +124,7 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/user_data.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -124,6 +135,6 @@ subPackage { libs "sokol" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/cube.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/cube.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } diff --git a/src/examples/clear.d b/src/examples/clear.d index 633fed5..cd3bccc 100644 --- a/src/examples/clear.d +++ b/src/examples/clear.d @@ -16,10 +16,8 @@ __gshared sg.PassAction pass_action; void init() { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.slog_func} - }; + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.slog_func}}; sg.setup(gfx); pass_action.colors[0].load_action = sg.LoadAction.Clear; @@ -28,11 +26,17 @@ void init() pass_action.colors[0].clear_value.b = 0; pass_action.colors[0].clear_value.a = 1; - debug { + debug + { import std.stdio : writeln; - try { + + try + { writeln("Backend: ", sg.queryBackend()); - } catch (Exception) {} + } + catch (Exception) + { + } } } diff --git a/src/examples/cube.d b/src/examples/cube.d index 9a34cdc..56afc8b 100644 --- a/src/examples/cube.d +++ b/src/examples/cube.d @@ -13,7 +13,7 @@ import sgapp = sokol.glue; import shd = shaders.cube; import sgutil = sokol.utils : asRange; -extern(C): +extern (C): @safe: struct State @@ -43,57 +43,53 @@ static State state; void init() @trusted { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.func} - }; + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.func}}; sg.setup(gfx); float[168] vertices = [ - -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, - 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, - 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, - -1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, - - -1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, - 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, - 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, - -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, - - -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 1.0, - -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0, - -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, - -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, - - 1.0, -1.0, -1.0, 1.0, 0.5, 0.0, 1.0, - 1.0, 1.0, -1.0, 1.0, 0.5, 0.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 1.0, - 1.0, -1.0, 1.0, 1.0, 0.5, 0.0, 1.0, - - -1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, - -1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, - 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, - 1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, - - -1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, - -1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, - 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, - 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0 + -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, + 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, + 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, + -1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, + + -1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, + 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, + -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, + + -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 1.0, + -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0, + -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, + -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, + + 1.0, -1.0, -1.0, 1.0, 0.5, 0.0, 1.0, + 1.0, 1.0, -1.0, 1.0, 0.5, 0.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 1.0, + 1.0, -1.0, 1.0, 1.0, 0.5, 0.0, 1.0, + + -1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, + -1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, + 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, + 1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, + + -1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, + -1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, + 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, + 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0 ]; // Create vertex buffer - sg.BufferDesc vbuffer = { - data: sgutil.asRange(&vertices[0]) - }; + sg.BufferDesc vbuffer = {data: sgutil.asRange(&vertices[0])}; state.bind.vertex_buffers[0] = sg.makeBuffer(vbuffer); double[36] indices = [ - 0, 1, 2, 0, 2, 3, - 6, 5, 4, 7, 6, 4, - 8, 9, 10, 8, 10, 11, - 14, 13, 12, 15, 14, 12, - 16, 17, 18, 16, 18, 19, - 22, 21, 20, 23, 22, 20, + 0, 1, 2, 0, 2, 3, + 6, 5, 4, 7, 6, 4, + 8, 9, 10, 8, 10, 11, + 14, 13, 12, 15, 14, 12, + 16, 17, 18, 16, 18, 19, + 22, 21, 20, 23, 22, 20, ]; sg.BufferDesc ibuffer = { @@ -117,7 +113,7 @@ void init() @trusted void frame() { - immutable float t = cast(float) (app.frameDuration() * 60.0); + immutable float t = cast(float)(app.frameDuration() * 60.0); state.rx += 1.0 * t; state.ry += 2.0 * t; @@ -140,7 +136,7 @@ void cleanup() sg.shutdown(); } -Mat4 computeVsParams(float rx, float ry) +Mat4 computeVsParams(float rx, float ry) { immutable proj = Mat4.perspective(60.0, app.widthf() / app.heightf(), 0.01, 10.0); immutable rxm = Mat4.rotate(rx, Vec3(1.0, 0.0, 0.0)); @@ -165,4 +161,4 @@ void main() logger: {func: &log.func} }; app.run(runner); -} \ No newline at end of file +} diff --git a/src/examples/debugtext_print.d b/src/examples/debugtext_print.d index b991e2a..31b28f0 100644 --- a/src/examples/debugtext_print.d +++ b/src/examples/debugtext_print.d @@ -39,10 +39,8 @@ struct State void init() { - sg.Desc gfx = { - context: sglue.context(), - logger: {func: &log.func} - }; + sg.Desc gfx = {context: sglue.context(), + logger: {func: &log.func}}; sg.setup(gfx); sdtx.Desc desc = { @@ -59,14 +57,17 @@ void init() sdtx.setup(desc); } -void print_font(uint font_index, string title, ubyte r, ubyte g, ubyte b) { +void print_font(uint font_index, string title, ubyte r, ubyte g, ubyte b) +{ sdtx.font(font_index); sdtx.color3b(r, g, b); sdtx.puts(&title[0]); - foreach (c; 32 .. 255) { - sdtx.putc(cast(char)c); - if ( ((c + 1) & 63) == 0) { + foreach (c; 32 .. 255) + { + sdtx.putc(cast(char) c); + if (((c + 1) & 63) == 0) + { sdtx.crlf(); } } diff --git a/src/examples/mrt.d b/src/examples/mrt.d index a67e389..2dbd213 100644 --- a/src/examples/mrt.d +++ b/src/examples/mrt.d @@ -24,7 +24,8 @@ extern (C): enum OFFSCREEN_SAMPLE_COUNT = 1; -struct Offscreen { +struct Offscreen +{ sg.PassAction pass_action; sg.PassDesc pass_desc; sg.Pass pass; @@ -32,21 +33,25 @@ struct Offscreen { sg.Bindings bind; } -struct Fsq { +struct Fsq +{ sg.Pipeline pip; sg.Bindings bind; } -struct Dbg { +struct Dbg +{ sg.Pipeline pip; sg.Bindings bind; } -struct Dflt { +struct Dflt +{ sg.PassAction pass_action; } -struct State { +struct State +{ Offscreen offscreen; Fsq fsq; Dbg dbg; @@ -60,13 +65,11 @@ static State state; void init() @trusted { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.slog_func} - }; + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.slog_func}}; sg.setup(gfx); - - // setup pass action for default render pass + + // setup pass action for default render pass state.dflt.pass_action.colors[0].load_action = sg.LoadAction.Dontcare; state.dflt.pass_action.depth.load_action = sg.LoadAction.Dontcare; state.dflt.pass_action.stencil.load_action = sg.LoadAction.Dontcare; @@ -96,48 +99,48 @@ void init() @trusted float[96] VERTICES = [ // positions brightness - -1.0, -1.0, -1.0, 1.0, - 1.0, -1.0, -1.0, 1.0, - 1.0, 1.0, -1.0, 1.0, - -1.0, 1.0, -1.0, 1.0, - - -1.0, -1.0, 1.0, 0.8, - 1.0, -1.0, 1.0, 0.8, - 1.0, 1.0, 1.0, 0.8, - -1.0, 1.0, 1.0, 0.8, - - -1.0, -1.0, -1.0, 0.6, - -1.0, 1.0, -1.0, 0.6, - -1.0, 1.0, 1.0, 0.6, - -1.0, -1.0, 1.0, 0.6, - - 1.0, -1.0, -1.0, 0.0, - 1.0, 1.0, -1.0, 0.0, - 1.0, 1.0, 1.0, 0.0, - 1.0, -1.0, 1.0, 0.0, - - -1.0, -1.0, -1.0, 0.5, - -1.0, -1.0, 1.0, 0.5, - 1.0, -1.0, 1.0, 0.5, - 1.0, -1.0, -1.0, 0.5, - - -1.0, 1.0, -1.0, 0.7, - -1.0, 1.0, 1.0, 0.7, - 1.0, 1.0, 1.0, 0.7, - 1.0, 1.0, -1.0, 0.7, + -1.0, -1.0, -1.0, 1.0, + 1.0, -1.0, -1.0, 1.0, + 1.0, 1.0, -1.0, 1.0, + -1.0, 1.0, -1.0, 1.0, + + -1.0, -1.0, 1.0, 0.8, + 1.0, -1.0, 1.0, 0.8, + 1.0, 1.0, 1.0, 0.8, + -1.0, 1.0, 1.0, 0.8, + + -1.0, -1.0, -1.0, 0.6, + -1.0, 1.0, -1.0, 0.6, + -1.0, 1.0, 1.0, 0.6, + -1.0, -1.0, 1.0, 0.6, + + 1.0, -1.0, -1.0, 0.0, + 1.0, 1.0, -1.0, 0.0, + 1.0, 1.0, 1.0, 0.0, + 1.0, -1.0, 1.0, 0.0, + + -1.0, -1.0, -1.0, 0.5, + -1.0, -1.0, 1.0, 0.5, + 1.0, -1.0, 1.0, 0.5, + 1.0, -1.0, -1.0, 0.5, + + -1.0, 1.0, -1.0, 0.7, + -1.0, 1.0, 1.0, 0.7, + 1.0, 1.0, 1.0, 0.7, + 1.0, 1.0, -1.0, 0.7, ]; // create vertex buffer for a cube - sg.BufferDesc buf = { data: sgutil.asRange(&VERTICES[0]) }; + sg.BufferDesc buf = {data: sgutil.asRange(&VERTICES[0])}; auto cube_vbuf = sg.makeBuffer(buf); double[36] INDICES = [ - 0, 1, 2, 0, 2, 3, - 6, 5, 4, 7, 6, 4, - 8, 9, 10, 8, 10, 11, - 14, 13, 12, 15, 14, 12, - 16, 17, 18, 16, 18, 19, - 22, 21, 20, 23, 22, 20, + 0, 1, 2, 0, 2, 3, + 6, 5, 4, 7, 6, 4, + 8, 9, 10, 8, 10, 11, + 14, 13, 12, 15, 14, 12, + 16, 17, 18, 16, 18, 19, + 22, 21, 20, 23, 22, 20, ]; // index buffer for a cube @@ -171,7 +174,7 @@ void init() @trusted float[8] QUAD_VERTICES = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]; // a vertex buffer to render a fullscreen quad - sg.BufferDesc quad_buf = { data: sgutil.asRange(&QUAD_VERTICES[0]) }; + sg.BufferDesc quad_buf = {data: sgutil.asRange(&QUAD_VERTICES[0])}; const quad_vbuf = sg.makeBuffer(quad_buf); // shader and pipeline object to render a fullscreen quad which composes @@ -196,7 +199,8 @@ void init() @trusted // resource bindings to render the fullscreen quad (composed from the // offscreen render target textures state.fsq.bind.vertex_buffers[0] = quad_vbuf; - foreach (i;[0,1,2]) { + foreach (i; [0, 1, 2]) + { state.fsq.bind.fs.images[i] = state.offscreen.pass_desc.color_attachments[i].image; } state.fsq.bind.fs.samplers[0] = smp; @@ -218,12 +222,12 @@ void init() @trusted void frame() { - immutable (float) dt = (app.frameDuration() * 60.0); + immutable(float) dt = (app.frameDuration() * 60.0); state.rx += 1.0 * dt; state.ry += 2.0 * dt; // compute shader uniform data - shd.OffscreenParams offscreen_params = { mvp: compute_mvp(state.rx, state.ry) }; + shd.OffscreenParams offscreen_params = {mvp: compute_mvp(state.rx, state.ry)}; shd.FsqParams fsq_params = { offset: Vec2(sin(state.rx * 0.01) * 0.1, cos(state.ry * 0.01) * 0.1), }; @@ -250,7 +254,8 @@ void frame() sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, fsq_rg); sg.draw(0, 4, 1); sg.applyPipeline(state.dbg.pip); - foreach(i;[0,1,2]) { + foreach (i; [0, 1, 2]) + { sg.applyViewport(i * 100, 0, 100, 100, false); state.dbg.bind.fs.images[0] = state.offscreen.pass_desc.color_attachments[i].image; sg.applyBindings(state.dbg.bind); @@ -262,7 +267,7 @@ void frame() void event(const app.Event* ev) { - if(ev.type == app.EventType.Resized) + if (ev.type == app.EventType.Resized) { createOffscreenPass(ev.framebuffer_width, ev.framebuffer_height); } @@ -294,7 +299,8 @@ void createOffscreenPass(int width, int height) { // destroy previous resources (can be called with invalid ids) sg.destroyPass(state.offscreen.pass); - foreach (att; state.offscreen.pass_desc.color_attachments) { + foreach (att; state.offscreen.pass_desc.color_attachments) + { sg.destroyImage(att.image); } sg.destroyImage(state.offscreen.pass_desc.depth_stencil_attachment.image); @@ -309,20 +315,22 @@ void createOffscreenPass(int width, int height) sg.ImageDesc depth_img_desc = color_img_desc; depth_img_desc.pixel_format = sg.PixelFormat.Depth; - foreach (i; [0, 1, 2]) { + foreach (i; [0, 1, 2]) + { state.offscreen.pass_desc.color_attachments[i].image = sg.makeImage(color_img_desc); } state.offscreen.pass_desc.depth_stencil_attachment.image = sg.makeImage(depth_img_desc); state.offscreen.pass = sg.makePass(state.offscreen.pass_desc); // update the fullscreen-quad texture bindings - foreach (i; [0, 1, 2]) { + foreach (i; [0, 1, 2]) + { state.fsq.bind.fs.images[i] = state.offscreen.pass_desc.color_attachments[i].image; } } -Mat4 compute_mvp(float rx, float ry) +Mat4 compute_mvp(float rx, float ry) { immutable proj = Mat4.perspective(60.0, app.widthf() / app.heightf(), 0.01, 10.0); immutable view = Mat4.lookAt(Vec3(0.0, 1.5, 6.0), Vec3.zero, Vec3.up); @@ -332,4 +340,4 @@ Mat4 compute_mvp(float rx, float ry) immutable view_proj = Mat4.mul(proj, view); return Mat4.mul(view_proj, model); -} \ No newline at end of file +} diff --git a/src/examples/saudio.d b/src/examples/saudio.d index bf2febf..b704887 100644 --- a/src/examples/saudio.d +++ b/src/examples/saudio.d @@ -15,12 +15,15 @@ extern (C): enum NUM_SAMPLES = 32; -struct State { +struct State +{ sg.PassAction pass_action = { - colors: [{ - load_action: sg.LoadAction.Clear, - clear_value: { r: 1.0, g: 0.5, b: 0.0, a: 1.0 }, - }] + colors: [ + { + load_action: sg.LoadAction.Clear, + clear_value: {r: 1.0, g: 0.5, b: 0.0, a: 1.0}, + } + ] }; int even_odd; size_t sample_pos; @@ -31,23 +34,24 @@ static State state; void init() { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.slog_func} - }; + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.slog_func}}; sg.setup(gfx); saudio.Desc audio = {logger: {func: &log.slog_func}}; saudio.setup(audio); } -void frame(){ +void frame() +{ immutable num_frames = saudio.expect(); - foreach (_; 0..num_frames) { + foreach (_; 0 .. num_frames) + { state.even_odd += 1; state.sample_pos += 1; - if (state.sample_pos == NUM_SAMPLES) { + if (state.sample_pos == NUM_SAMPLES) + { state.sample_pos = 0; saudio.push(&state.samples[0], NUM_SAMPLES); } @@ -79,4 +83,4 @@ void main() logger: {func: &log.func} }; app.run(runner); -} \ No newline at end of file +} diff --git a/src/examples/sgl_context.d b/src/examples/sgl_context.d index 81cd193..4166aed 100644 --- a/src/examples/sgl_context.d +++ b/src/examples/sgl_context.d @@ -42,13 +42,10 @@ enum offscreen_sample_count = 1; enum offscreen_width = 32; enum offscreen_height = 32; - void init() { - sg.Desc gfxd = { - context: sgapp.context(), - logger: {func: &slog.func} - }; + sg.Desc gfxd = {context: sgapp.context(), + logger: {func: &slog.func}}; sg.setup(gfxd); // setup sokol-gl with the default context compatible with the default @@ -138,7 +135,7 @@ void frame() sgl.loadPipeline(state.display.sgl_pip); sgl.matrixModeProjection(); sgl.perspective(sgl.asRadians(45.0), sapp.widthf() / sapp.heightf(), 0.1, 100.0); - immutable (float)[3] eye = [sin(a) * 6.0, sin(a) * 3.0, cos(a) * 6.0]; + immutable(float)[3] eye = [sin(a) * 6.0, sin(a) * 3.0, cos(a) * 6.0]; sgl.matrixModeModelview(); sgl.lookat(eye[0], eye[1], eye[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); draw_cube(); diff --git a/src/examples/sgl_points.d b/src/examples/sgl_points.d new file mode 100644 index 0000000..a6b5858 --- /dev/null +++ b/src/examples/sgl_points.d @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// sgl_points.d +// +// Test sokol-gl point rendering. +// +// (port of this C sample: https://floooh.github.io/sokol-html5/sgl-points-sapp.html) +//------------------------------------------------------------------------------ + +module examples.sgl_points; + +import sg = sokol.gfx; +import sgapp = sokol.glue; +import sapp = sokol.app; +import slog = sokol.log; +import sgl = sokol.gl; +import handmade.math : sin, cos, floor; + +extern (C): +@safe: + +struct RGB +{ + float r = 0.0, g = 0.0, b = 0.0; +} + +struct State +{ + static sg.PassAction pass_action = { + colors: [ + { + load_action: sg.LoadAction.Clear, + clear_value: {r: 0.0, g: 0.0, b: 0.0, a: 1.0}, + } + ] + }; +} + +immutable float[3][16] pallete = [ + [0.957, 0.263, 0.212], + [0.914, 0.118, 0.388], + [0.612, 0.153, 0.690], + [0.404, 0.227, 0.718], + [0.247, 0.318, 0.710], + [0.129, 0.588, 0.953], + [0.012, 0.663, 0.957], + [0.000, 0.737, 0.831], + [0.000, 0.588, 0.533], + [0.298, 0.686, 0.314], + [0.545, 0.765, 0.290], + [0.804, 0.863, 0.224], + [1.000, 0.922, 0.231], + [1.000, 0.757, 0.027], + [1.000, 0.596, 0.000], + [1.000, 0.341, 0.133], +]; + +void init() +{ + sg.Desc gfxd = {context: sgapp.context(), + logger: {func: &slog.func}}; + sg.setup(gfxd); + + sgl.Desc gld = {logger: {func: &slog.func}}; + sgl.setup(gld); +} + +void frame() +{ + immutable float angle = sapp.frameCount() % 360.0; + State state; + + sgl.defaults(); + sgl.beginPoints(); + float psize = 5.0; + foreach (i; 0 .. 360) + { + auto a = sgl.asRadians(angle + i); + auto color = computeColor(((sapp.frameCount() + i) % 300) / 300.0); + auto r = sin(a * 4.0); + auto s = sin(a); + auto c = cos(a); + auto x = s * r; + auto y = c * r; + sgl.c3f(color.r, color.g, color.b); + sgl.pointSize(psize); + sgl.v2f(x, y); + psize *= 1.005; + } + sgl.end(); + + sg.beginDefaultPass(state.pass_action, sapp.width, sapp.height); + sgl.draw(); + sg.endPass(); + sg.commit(); +} + +void cleanup() +{ + sgl.shutdown(); + sg.shutdown(); +} + +void main() +{ + sapp.Desc runner = { + window_title: "sgl-points.d", + init_cb: &init, + frame_cb: &frame, + cleanup_cb: &cleanup, + width: 512, + height: 512, + logger: {func: &slog.func}, + icon: {sokol_default: true} + }; + sapp.run(runner); +} + +RGB computeColor(float t) +{ + const(size_t) idx0 = cast(size_t)(t * 16) % 16; + const(size_t) idx1 = cast(size_t)(idx0 + 1) % 16; + const l = (t * 16) - floor(t * 16); + const c0 = pallete[idx0]; + const c1 = pallete[idx1]; + RGB rgb = { + r: (c0[0] * (1 - l)) + (c1[0] * l), + g: (c0[1] * (1 - l)) + (c1[1] * l), + b: (c0[2] * (1 - l)) + (c1[2] * l), + }; + return rgb; +} diff --git a/src/examples/triangle.d b/src/examples/triangle.d index 5577701..41f853c 100644 --- a/src/examples/triangle.d +++ b/src/examples/triangle.d @@ -14,79 +14,80 @@ import sgutil = sokol.utils; extern (C): @safe: -struct State { - sg.Bindings bind; - sg.Pipeline pip; +struct State +{ + static sg.Bindings bind; + static sg.Pipeline pip; } -static State state; - void init() @trusted { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.slog_func} - }; - sg.setup(gfx); + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.slog_func}}; + sg.setup(gfx); + State state; - // create vertex buffer with triangle vertices - float[21] vertices = [ - // positions colors - 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, - 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, - -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, - ]; - sg.BufferDesc buff = {data: sgutil.asRange(&vertices[0])}; - state.bind.vertex_buffers[0] = sg.makeBuffer(buff); + // create vertex buffer with triangle vertices + float[21] vertices = [ + // positions colors + 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, + 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, + -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, + ]; + sg.BufferDesc buff = {data: sgutil.asRange(&vertices[0])}; + state.bind.vertex_buffers[0] = sg.makeBuffer(buff); - // create a shader and pipeline object - sg.ShaderDesc shader = shaderDesc(); - const shd = sg.makeShader(shader); - sg.PipelineDesc pip_desc = { shader: shd }; - pip_desc.layout.attrs[0].format = sg.VertexFormat.Float3; - pip_desc.layout.attrs[1].format = sg.VertexFormat.Float4; - state.pip = sg.makePipeline(pip_desc); + // create a shader and pipeline object + sg.ShaderDesc shader = shaderDesc(); + const shd = sg.makeShader(shader); + sg.PipelineDesc pip_desc = {shader: shd}; + pip_desc.layout.attrs[0].format = sg.VertexFormat.Float3; + pip_desc.layout.attrs[1].format = sg.VertexFormat.Float4; + state.pip = sg.makePipeline(pip_desc); } void frame() { - // default pass-action clears to grey - sg.PassAction pass_action; - sg.beginDefaultPass(pass_action, sapp.width(), sapp.height()); - sg.applyPipeline(state.pip); - sg.applyBindings(state.bind); - sg.draw(0, 3, 1); - sg.endPass(); - sg.commit(); + State state; + // default pass-action clears to grey + sg.PassAction pass_action; + sg.beginDefaultPass(pass_action, sapp.width(), sapp.height()); + sg.applyPipeline(state.pip); + sg.applyBindings(state.bind); + sg.draw(0, 3, 1); + sg.endPass(); + sg.commit(); } void cleanup() { - sg.shutdown(); + sg.shutdown(); } void main() { - sapp.Desc runner = { - window_title: "triangle.d", - init_cb: &init, - frame_cb: &frame, - cleanup_cb: &cleanup, - width: 800, - height: 600, - icon: {sokol_default: true}, - logger: {func: &log.func} - }; - sapp.run(runner); + sapp.Desc runner = { + window_title: "triangle.d", + init_cb: &init, + frame_cb: &frame, + cleanup_cb: &cleanup, + width: 800, + height: 600, + icon: {sokol_default: true}, + logger: {func: &log.func} + }; + sapp.run(runner); } -sg.ShaderDesc shaderDesc() @trusted nothrow @nogc { - sg.ShaderDesc desc; - switch (sg.queryBackend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = " +sg.ShaderDesc shaderDesc() @trusted nothrow @nogc +{ + sg.ShaderDesc desc; + switch (sg.queryBackend) + { + case sg.Backend.Glcore33: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = " #version 330 in vec4 position; in vec4 color0; @@ -95,18 +96,18 @@ sg.ShaderDesc shaderDesc() @trusted nothrow @nogc { gl_Position = position; color = color0; }"; - desc.fs.source = " + desc.fs.source = " #version 330 in vec4 color; out vec4 frag_color; void main() { frag_color = color; }"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "POS"; - desc.attrs[1].sem_name = "COLOR"; - desc.vs.source = " + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "POS"; + desc.attrs[1].sem_name = "COLOR"; + desc.vs.source = " struct vs_in { float4 pos: POS; float4 color: COLOR; @@ -122,14 +123,14 @@ sg.ShaderDesc shaderDesc() @trusted nothrow @nogc { return outp; } "; - desc.fs.source = " + desc.fs.source = " float4 main(float4 color: COLOR0): SV_Target0 { return color; } "; - break; - case sg.Backend.Metal_macos: - desc.vs.source = " + break; + case sg.Backend.Metal_macos: + desc.vs.source = " #include using namespace metal; struct vs_in { @@ -147,16 +148,16 @@ sg.ShaderDesc shaderDesc() @trusted nothrow @nogc { return outp; } "; - desc.fs.source = " + desc.fs.source = " #include using namespace metal; fragment float4 _main(float4 color [[stage_in]]) { return color; }; "; - break; - default: - break; - } - return desc; + break; + default: + break; + } + return desc; } diff --git a/src/examples/user_data.d b/src/examples/user_data.d index 4671a23..f16582e 100644 --- a/src/examples/user_data.d +++ b/src/examples/user_data.d @@ -7,43 +7,51 @@ import sgapp = sokol.glue; extern (C): -struct ExampleUserData { - ubyte data; +struct ExampleUserData +{ + ubyte data; int[ubyte] map; // need druntime } void init() @safe { - sg.Desc gfx = { - context: sgapp.context(), - logger: {func: &log.slog_func} - }; + sg.Desc gfx = {context: sgapp.context(), + logger: {func: &log.slog_func}}; sg.setup(gfx); } void frame_userdata(scope void* userdata) @trusted { auto state = cast(ExampleUserData*) userdata; - + state.data++; - - version(WebAssembly){ + + version (WebAssembly) + { // TODO support } else { - if (state.data % 13 == 0) { - state.map[state.data] = state.data * 13 / 3; + if (state.data % 13 == 0) + { + state.map[state.data] = state.data * 13 / 3; } - if (state.data % 12 == 0 && state.data % 15 == 0) { + if (state.data % 12 == 0 && state.data % 15 == 0) + { state.map.clear(); - } + } } - debug { + debug + { import std.stdio : writeln; - try { + + try + { writeln(*state); - } catch (Exception) {} + } + catch (Exception) + { + } } sg.PassAction pass_action = {}; @@ -72,7 +80,6 @@ void main() sample_count: 4, win32_console_attach: true, icon: {sokol_default: true}, - logger: {func: &log.func} - }; - sapp.run(runner); -} + logger: {func: &log.func}}; + sapp.run(runner); + } diff --git a/src/handmade/math.d b/src/handmade/math.d index 41268c0..552e67b 100644 --- a/src/handmade/math.d +++ b/src/handmade/math.d @@ -16,12 +16,14 @@ version (WebAssembly) { // zig stdlib no-libc math functions enum PI = 3.14159265358979323846264338327950288419716939937510; - double zig_sqrt(size_t value) @nogc nothrow @trusted; - double zig_sqrtf(double value) @nogc nothrow @trusted; double zig_cos(double value) @nogc nothrow @trusted; + double zig_floor(double value) @nogc nothrow @trusted; double zig_sin(double value) @nogc nothrow @trusted; + double zig_sqrt(size_t value) @nogc nothrow @trusted; + double zig_sqrtf(double value) @nogc nothrow @trusted; double zig_tan(double value) @nogc nothrow @trusted; alias cos = zig_cos; + alias floor = zig_floor; alias sin = zig_sin; alias tan = zig_tan; @@ -39,7 +41,7 @@ version (WebAssembly) } else { - public import core.stdc.math : sqrt, cos, sin, tan; + public import core.stdc.math : sqrt, cos, sin, tan, floor; public import std.math : PI; } diff --git a/src/handmade/math.zig b/src/handmade/math.zig index 775f026..26ad6fa 100644 --- a/src/handmade/math.zig +++ b/src/handmade/math.zig @@ -17,3 +17,6 @@ export fn zig_sin(x: f64) callconv(.C) f64 { export fn zig_tan(x: f64) callconv(.C) f64 { return std.math.tan(x); } +export fn zig_floor(x: f64) callconv(.C) f64 { + return std.math.floor(x); +} diff --git a/src/sokol/c/sokol_app.h b/src/sokol/c/sokol_app.h index c4fde9d..064a72f 100644 --- a/src/sokol/c/sokol_app.h +++ b/src/sokol/c/sokol_app.h @@ -1622,7 +1622,7 @@ typedef struct sapp_allocator { _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_DONE, "NativeActivity done") \ _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_ONCREATE, "NativeActivity onCreate") \ _SAPP_LOGITEM_XMACRO(ANDROID_CREATE_THREAD_PIPE_FAILED, "failed to create thread pipe") \ - _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_CREATE_SUCCESS, "NativeActivity sucessfully created") \ + _SAPP_LOGITEM_XMACRO(ANDROID_NATIVE_ACTIVITY_CREATE_SUCCESS, "NativeActivity successfully created") \ _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_SURFACE_FAILED, "wgpu: failed to create surface for swapchain") \ _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_SWAPCHAIN_FAILED, "wgpu: failed to create swapchain object") \ _SAPP_LOGITEM_XMACRO(WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_TEXTURE_FAILED, "wgpu: failed to create depth-stencil texture for swapchain") \ @@ -1810,7 +1810,7 @@ SOKOL_APP_API_DECL sapp_desc sapp_query_desc(void); SOKOL_APP_API_DECL void sapp_request_quit(void); /* cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received) */ SOKOL_APP_API_DECL void sapp_cancel_quit(void); -/* initiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED) */ +/* initiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUESTED) */ SOKOL_APP_API_DECL void sapp_quit(void); /* call from inside event callback to consume the current event (don't forward to platform) */ SOKOL_APP_API_DECL void sapp_consume_event(void); diff --git a/src/sokol/c/sokol_debugtext.h b/src/sokol/c/sokol_debugtext.h index 6859159..cec0694 100644 --- a/src/sokol/c/sokol_debugtext.h +++ b/src/sokol/c/sokol_debugtext.h @@ -148,7 +148,7 @@ - to render characters at 16x16 physical pixels: - sdtx_canvas(sapp_width()/2.0f, sapp_heigth()/2.0f); + sdtx_canvas(sapp_width()/2.0f, sapp_height()/2.0f); Do *not* use integer math here, since this will not look nice when the render target size isn't divisible by 2. @@ -4135,7 +4135,7 @@ static void _sdtx_render_char(_sdtx_context_t* ctx, uint8_t c) { const float x1 = x0 + ctx->glyph_size.x; const float y1 = y0 + ctx->glyph_size.y; - // glyph width and heigth in font texture space + // glyph width and height in font texture space // NOTE: the '+1' and '-2' fixes texture bleeding into the neighboring font texture cell const uint16_t uvw = 0x10000 / 0x100; const uint16_t uvh = 0x10000 / SDTX_MAX_FONTS; diff --git a/src/sokol/c/sokol_gfx.h b/src/sokol/c/sokol_gfx.h index 328b3b9..cec6af4 100644 --- a/src/sokol/c/sokol_gfx.h +++ b/src/sokol/c/sokol_gfx.h @@ -720,7 +720,7 @@ texture-sample-type with the correct sampler-type). For GLSL an additional 'combined-image-sampler name' must be provided because 'OpenGL style GLSL' cannot handle separate texture and sampler objects, but still - groups them into a tradtional GLSL 'sampler object'. + groups them into a traditional GLSL 'sampler object'. Compatibility rules for image-sample-type vs sampler-type are as follows: @@ -2883,7 +2883,7 @@ typedef struct sg_pipeline_desc { sg_make_pass() function. A pass object contains 1..4 color attachments, 0..4 msaa-resolve - attachemnts, and none or one depth-stencil attachment. + attachments, and none or one depth-stencil attachment. Each attachment consists of an image, and two additional indices describing which subimage the pass will render into: one mipmap index, and if the image @@ -3585,7 +3585,7 @@ typedef enum sg_log_item { the more likely are cache slot collisions which will cause a BindGroups object to be destroyed and a new one created. Use the information returned by sg_query_stats() to check - if this is a frequent occurence, and increase the cache size as + if this is a frequent occurrence, and increase the cache size as needed (the default is 1024). NOTE: wgpu_bindgroups_cache_size must be a power-of-2 number! .context.wgpu.device @@ -3879,7 +3879,7 @@ typedef struct sg_d3d11_sampler_info { typedef struct sg_d3d11_shader_info { const void* vs_cbufs[SG_MAX_SHADERSTAGE_UBS]; // ID3D11Buffer* (vertex stage constant buffers) - const void* fs_cbufs[SG_MAX_SHADERSTAGE_UBS]; // ID3D11BUffer* (fragment stage constant buffers) + const void* fs_cbufs[SG_MAX_SHADERSTAGE_UBS]; // ID3D11Buffer* (fragment stage constant buffers) const void* vs; // ID3D11VertexShader* const void* fs; // ID3D11PixelShader* } sg_d3d11_shader_info; @@ -4015,7 +4015,7 @@ SOKOL_GFX_API_DECL const void* sg_wgpu_device(void); SOKOL_GFX_API_DECL const void* sg_wgpu_queue(void); // WebGPU: return this frame's WGPUCommandEncoder SOKOL_GFX_API_DECL const void* sg_wgpu_command_encoder(void); -// WebGPU: return WGPURenderPassEncoder of currrent pass +// WebGPU: return WGPURenderPassEncoder of current pass SOKOL_GFX_API_DECL const void* sg_wgpu_render_pass_encoder(void); // WebGPU: get internal buffer resource objects SOKOL_GFX_API_DECL sg_wgpu_buffer_info sg_wgpu_query_buffer_info(sg_buffer buf); @@ -5373,7 +5373,7 @@ typedef struct { } _sg_mtl_context_t; typedef _sg_mtl_context_t _sg_context_t; -// resouce binding state cache +// resource binding state cache typedef struct { const _sg_pipeline_t* cur_pipeline; sg_pipeline cur_pipeline_id; @@ -6540,8 +6540,13 @@ _SOKOL_PRIVATE void _sg_dummy_update_image(_sg_image_t* img, const sg_image_data // optional GL loader for win32 #if defined(_SOKOL_USE_WIN32_GL_LOADER) +#ifndef SG_GL_FUNCS_EXT +#define SG_GL_FUNCS_EXT +#endif + // X Macro list of GL function names and signatures #define _SG_GL_FUNCS \ + SG_GL_FUNCS_EXT \ _SG_XMACRO(glBindVertexArray, void, (GLuint array)) \ _SG_XMACRO(glFramebufferTextureLayer, void, (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)) \ _SG_XMACRO(glGenFramebuffers, void, (GLsizei n, GLuint * framebuffers)) \ @@ -8381,7 +8386,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_gl_create_pass(_sg_pass_t* pass, _sg_image_ _sg_gl_fb_attach_texture(&pass->gl.color_atts[i], &pass->cmn.color_atts[i], gl_att_type); } } - // attach depth-stencil attachement + // attach depth-stencil attachment if (pass->gl.ds_att.image) { const GLenum gl_att = _sg_gl_depth_stencil_attachment_type(&pass->gl.ds_att); const _sg_image_t* ds_img = pass->gl.ds_att.image; @@ -11945,7 +11950,7 @@ _SOKOL_PRIVATE void _sg_mtl_copy_image_data(const _sg_image_t* img, __unsafe_unr } } -// initialize MTLTextureDescritor with common attributes +// initialize MTLTextureDescriptor with common attributes _SOKOL_PRIVATE bool _sg_mtl_init_texdesc_common(MTLTextureDescriptor* mtl_desc, _sg_image_t* img) { mtl_desc.textureType = _sg_mtl_texture_type(img->cmn.type); mtl_desc.pixelFormat = _sg_mtl_pixel_format(img->cmn.pixel_format); @@ -11976,7 +11981,7 @@ _SOKOL_PRIVATE bool _sg_mtl_init_texdesc_common(MTLTextureDescriptor* mtl_desc, return true; } -// initialize MTLTextureDescritor with rendertarget attributes +// initialize MTLTextureDescriptor with rendertarget attributes _SOKOL_PRIVATE void _sg_mtl_init_texdesc_rt(MTLTextureDescriptor* mtl_desc, _sg_image_t* img) { SOKOL_ASSERT(img->cmn.render_target); _SOKOL_UNUSED(img); @@ -11984,7 +11989,7 @@ _SOKOL_PRIVATE void _sg_mtl_init_texdesc_rt(MTLTextureDescriptor* mtl_desc, _sg_ mtl_desc.resourceOptions = MTLResourceStorageModePrivate; } -// initialize MTLTextureDescritor with MSAA attributes +// initialize MTLTextureDescriptor with MSAA attributes _SOKOL_PRIVATE void _sg_mtl_init_texdesc_rt_msaa(MTLTextureDescriptor* mtl_desc, _sg_image_t* img) { SOKOL_ASSERT(img->cmn.sample_count > 1); mtl_desc.usage = MTLTextureUsageRenderTarget; diff --git a/src/sokol/c/sokol_gl.h b/src/sokol/c/sokol_gl.h index 88a62ba..997ddea 100644 --- a/src/sokol/c/sokol_gl.h +++ b/src/sokol/c/sokol_gl.h @@ -453,7 +453,7 @@ sgl_set_context(ctx); - The currently active context will implicitely be used by most sokol-gl functions + The currently active context will implicitly be used by most sokol-gl functions which don't take an explicit context handle as argument. To switch back to the default context, pass the global constant SGL_DEFAULT_CONTEXT: diff --git a/src/sokol/c/sokol_time.h b/src/sokol/c/sokol_time.h index 2d4d456..fd766d8 100644 --- a/src/sokol/c/sokol_time.h +++ b/src/sokol/c/sokol_time.h @@ -296,7 +296,7 @@ SOKOL_API_IMPL uint64_t stm_round_to_common_refresh_rate(uint64_t ticks) { } i++; } - // fallthough: didn't fit into any buckets + // fallthrough: didn't fit into any buckets return ticks; }