├── .gitattributes ├── .gitignore ├── .gitmodules ├── .vscode ├── launch.json └── tasks.json ├── README.md ├── build.zig ├── build.zig.zon ├── docs ├── cube.png ├── imgui.png ├── instancing.png └── triangle.png └── src ├── LICENSE.txt ├── c.zig ├── compile_sokol.c ├── emscripten.zig ├── example_cube.zig ├── example_imgui.zig ├── example_instancing.zig ├── example_sound.zig ├── example_triangle.zig ├── math3d.zig ├── shaders ├── build_shaders.py ├── cube.glsl ├── cube.glsl.h ├── cube_compile.c ├── instancing.glsl ├── instancing.glsl.h ├── instancing_compile.c ├── triangle.glsl ├── triangle.glsl.h └── triangle_compile.c └── web └── shell.html /.gitattributes: -------------------------------------------------------------------------------- 1 | *.zig -crlf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .zig-cache 2 | zig-out/ 3 | .vscode/settings.json -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/sokol"] 2 | path = src/sokol 3 | url = https://github.com/floooh/sokol.git 4 | [submodule "src/cimgui"] 5 | path = src/cimgui 6 | url = https://github.com/cimgui/cimgui.git 7 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | // Builds all examples and runs configured example 5 | // TODO: Need a way to forward input to prelaunchtask to build only one at a time: 6 | // https://github.com/microsoft/vscode/issues/27157 7 | { 8 | "environment": [], 9 | "stopAtEntry": false, 10 | "program": "${workspaceRoot}/zig-out/bin/${input:example}.exe", 11 | "name": "Build Run Example", 12 | "console": "integratedTerminal", 13 | "preLaunchTask": "zig_build", 14 | "request": "launch", 15 | "args": [], 16 | "type": "cppvsdbg", 17 | "cwd": "${workspaceRoot}" 18 | }, 19 | ], 20 | "inputs": [ 21 | { 22 | "id": "example", 23 | "description": "Run Example:", 24 | "default": "example_cube", 25 | "type": "pickString", 26 | "options": [ 27 | "example_cube", 28 | "example_imgui", 29 | "example_instancing", 30 | "example_sound", 31 | "example_triangle", 32 | ], 33 | }, 34 | ], 35 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "group": "build", 5 | "problemMatcher": [ 6 | "$msCompile" 7 | ], 8 | "command": "zig build", 9 | "label": "zig_build", 10 | "options": { 11 | "cwd": "${workspaceRoot}" 12 | }, 13 | }, 14 | ], 15 | 16 | "presentation": { 17 | "reveal": "always", 18 | "clear": true 19 | }, 20 | "version": "2.0.0", 21 | "type": "shell" 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sokol-zig-examples 2 | 3 | Some of the Sokol examples running in Zig 0.13.0 (June 2024). Intended to be used as a reference or starting point for anyone looking to use Zig make games. Working platforms: 4 | - Windows (OpenGL) 5 | - Web (GLES3) 6 | - MacOS (OpenGL) [Not recently tested, may not work] 7 | 8 | With some modifications to the build.zig script it could be modified to target other platforms. 9 | 10 | See 11 | - https://github.com/floooh/sokol 12 | - https://github.com/floooh/sokol-samples 13 | - https://github.com/floooh/sokol-zig 14 | - https://github.com/ziglang/zig 15 | 16 | ## Building 17 | 18 | Clone 19 | 20 | git clone --recurse-submodules https://github.com/jeffkdev/sokol-zig-examples.git 21 | 22 | 23 | Navigate to the root directory and run application using: 24 | 25 | zig build run 26 | 27 | This will build all examples and run the first valid example defined 28 | 29 | To build and run a specific example use the `-Dmain=` argument: 30 | ``` 31 | zig build -Dmain=example_cube run 32 | zig build -Dmain=example_imgui run 33 | zig build -Dmain=example_instancing run 34 | zig build -Dmain=example_sound run 35 | zig build -Dmain=example_triangle run 36 | ``` 37 | This will skip building any other examples 38 | 39 | Use the standard release options to specify mode. Ex: 40 | `zig build -Dmain=example_cube -Doptimize=ReleaseFast run` 41 | 42 | 43 | valid files are: 44 | example_imgui.zig 45 | ![example_imgui.zig](docs/imgui.png) 46 | 47 | example_instancing.zig 48 | ![example_instancing.zig](docs/instancing.png) 49 | 50 | example_cube.zig 51 | ![example_cube.zig](docs/cube.png) 52 | 53 | example_triangle.zig 54 | ![example_triangle.zig](docs/triangle.png) 55 | 56 | example_sound.zig 57 | (plays beeping sound, blank screen) 58 | 59 | ## WASM 60 | All examples should work in the web browser using: 61 | ``` 62 | zig build -Dtarget=wasm32-emscripten run 63 | ``` 64 | 65 | This repo shows how to support web assembly builds using the sokol c code directly without the zig wrapper. The code was migrated from https://github.com/floooh/sokol-zig. See the source repo for more details. It will download the emscripten version defined in build.zig.zon automatically so the first compile will take longer. 66 | 67 | ### WASM multi-threading 68 | 69 | A multi-threading example is not yet included in this repo, but if you want to support multi-threading you should be able to get it working by adding additional arguments to th emLinkStep: 70 | ```zig 71 | // Required for LTO while bug exists: https://github.com/emscripten-core/emscripten/issues/16836 72 | "-Wl,-u,_emscripten_run_callback_on_thread", 73 | "-pthread", 74 | "-satomics=1", 75 | // Set to whatever pool size 76 | "-sPTHREAD_POOL_SIZE=8", 77 | // -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 78 | "-Wpthreads-mem-growth", 79 | ``` 80 | 81 | If you are using the standard thread pool (Pool.zig) in Zig 0.13.0 it will give you an error using `std.Thread.getCpuCount()` on WASM. You can work around this by checking if `@import("builtin").target.isWasm()` and providing an explicit thread pool count and then compiling in release mode so it will be compiled away. 82 | ```zig 83 | const thread_count = options.n_jobs orelse @max(1, std.Thread.getCpuCount() catch 1); 84 | ``` 85 | 86 | Then when you compile include atomics in the zig build CPU arguments: `zig build -Dtarget=wasm32-emscripten -Dcpu=bleeding_edge+atomics -Doptimize=ReleaseFast run` 87 | 88 | The std.heap.GeneralPurposeAllocator looks like it might have some issues with WASM. Switching to std.heap.c_allocator fixed the issue. 89 | 90 | Also if you upload your game to itch.io you will need to enable the `SharedArrayBuffer support` option for multi-threading. 91 | 92 | ## Shaders 93 | 94 | The "glsl.h" shader files are generates from the ".glsl" files using. [sokol-shdc](https://github.com/floooh/sokol-tools). Since the glsl.h files are not created automatically when building right now they are checked in as well. If you modify the files, they can be re-generated using the command: 95 | 96 | ``` 97 | sokol-shdc.exe --input cube.glsl --output cube.glsl.h --slang glsl430:metal_macos:hlsl5:glsl300es:wgsl --format sokol_impl 98 | ``` 99 | A python file build_shaders.py is included for convenience that will create the required glsl.h files and the *_compile.c files which calls the above command for each listed file (requires sokol-shdc.exe in the environment paths). 100 | 101 | The "--format sokol_impl" is important, otherwise they will be generated with inline declarations which caused issues using them in Zig. See the [documentation](https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md) for more command line references. 102 | 103 | ## Debugging 104 | 105 | 106 | Debugging and breakpoints are working in Visual Studio Code. Run and Debug (F5) will prompt for a file to run and build. 107 | ## License 108 | 109 | Example files are based on the sokol-examples so they are probably considered a derivate work, so the MIT license will carry on to those as well. 110 | -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const builtin = @import("builtin"); 3 | const Build = std.Build; 4 | const build_root = "../build/"; 5 | const OptimizeMode = std.builtin.OptimizeMode; 6 | const Step = Build.Step; 7 | const emscripten = @import("src/emscripten.zig"); 8 | 9 | pub fn build(b: *std.Build) anyerror!void { 10 | const target = b.standardTargetOptions(.{}); 11 | // Include release mode in build argmuents for non-Debug builds. For example: -Doptimize=ReleaseFast 12 | const optimize = b.standardOptimizeOption(.{}); 13 | 14 | // Choose the example with the -Dmain parameter. Ex: zig build -Dmain=example_imgui run 15 | // Omit argument to build all example 16 | // If using VS code the examples need to manually added to launch.json input options 17 | const examples = [_][]const u8{ 18 | "example_cube", 19 | "example_imgui", 20 | "example_instancing", 21 | "example_sound", 22 | "example_triangle", 23 | }; 24 | var main_file_maybe: ?[]const u8 = null; 25 | if (b.option([]const u8, "main", "Build specific example")) |result| { 26 | main_file_maybe = result; 27 | } 28 | 29 | // Validate main file string is included in the list 30 | if (main_file_maybe) |main_file| { 31 | blk: { 32 | for (examples) |example| { 33 | if (std.mem.eql(u8, main_file, example)) { 34 | break :blk; 35 | } 36 | } 37 | std.debug.panic("Main file '{s}' not found. Use one of the following: {s}", .{ main_file, examples }); 38 | break :blk; 39 | } 40 | } 41 | 42 | inline for (examples, 0..) |example, i| { 43 | // If building specific example then add run option that one, otherwise if building all examples with a run step arbitrarily run the first one 44 | const include_run_step = main_file_maybe != null or (main_file_maybe == null and i == 0); 45 | if (main_file_maybe == null or std.mem.eql(u8, main_file_maybe.?, example)) { 46 | if (!target.result.isWasm()) { 47 | try buildDefault(b, target, optimize, example, include_run_step); 48 | } else { 49 | try buildWeb(b, target, optimize, example, include_run_step); 50 | } 51 | } 52 | } 53 | } 54 | 55 | fn buildDefault(b: *Build, target: Build.ResolvedTarget, optimize: OptimizeMode, comptime name: []const u8, include_run_step: bool) !void { 56 | const file_with_extension = name ++ ".zig"; 57 | const root_source_file = "src/" ++ file_with_extension; 58 | 59 | var exe = b.addExecutable( 60 | .{ 61 | .name = name, 62 | .root_source_file = b.path(root_source_file), 63 | .optimize = optimize, 64 | .target = std.Build.resolveTargetQuery(b, std.Target.Query{}), 65 | }, 66 | ); 67 | try addImports(b, target, exe, null); 68 | if (include_run_step) { 69 | const run_cmd = b.addRunArtifact(exe); 70 | const run_step = b.step("run", "Run the app"); 71 | run_step.dependOn(&run_cmd.step); 72 | } 73 | 74 | b.default_step.dependOn(&exe.step); 75 | b.installArtifact(exe); 76 | } 77 | 78 | // for web builds, the Zig code needs to be built into a library and linked with the Emscripten linker 79 | fn buildWeb(b: *Build, target: Build.ResolvedTarget, optimize: OptimizeMode, comptime name: []const u8, include_run_step: bool) !void { 80 | const file_with_extension = name ++ ".zig"; 81 | const root_source_file = "src/" ++ file_with_extension; 82 | 83 | const game = b.addStaticLibrary(.{ 84 | .name = name, 85 | .target = target, 86 | .optimize = optimize, 87 | .root_source_file = b.path(root_source_file), 88 | }); 89 | const emsdk = b.dependency("emsdk", .{}); 90 | 91 | try addImports(b, target, game, emsdk); 92 | // create a build step which invokes the Emscripten linker 93 | // const emsdk = dep_sokol.builder.dependency("emsdk", .{}); 94 | const link_step = try emscripten.emLinkStep(b, .{ 95 | .lib_main = game, 96 | .target = target, 97 | .optimize = optimize, 98 | .emsdk = emsdk, 99 | .use_webgl2 = true, 100 | .use_emmalloc = true, 101 | .use_filesystem = false, 102 | .shell_file_path = b.path("src/web/shell.html"), 103 | .extra_args = &.{ 104 | // Zig allocators use the @returnAddress builtin, which isn't supported in the Emscripten runtime out of the box 105 | // (you'll get a runtime error in the browser's Javascript console looking like this: Cannot use convertFrameToPC 106 | // (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER. To make it work, do as the error message says, 107 | // to add the -sUSE_OFFSET_CONVERTER arg to the Emscripten linker step in your build.zig file: 108 | "-sUSE_OFFSET_CONVERTER=1", 109 | // Allow memory growth 110 | "-sALLOW_MEMORY_GROWTH=1", 111 | // 1 MB stack to match windows default 112 | "-sSTACK_SIZE= 1048576", 113 | }, 114 | }); 115 | if (include_run_step) { 116 | // ...and a special run step to start the web build output via 'emrun' 117 | const run = emscripten.emRunStep(b, .{ .name = name, .emsdk = emsdk }); 118 | run.step.dependOn(&link_step.step); 119 | b.step("run", "Run game").dependOn(&run.step); 120 | } 121 | } 122 | 123 | fn addImports(b: *std.Build, target: Build.ResolvedTarget, exe: *Step.Compile, emsdk: ?*Build.Dependency) !void { 124 | exe.addIncludePath(b.path("src/")); 125 | const c_module = b.createModule(.{ .root_source_file = .{ .src_path = .{ .sub_path = "src/c.zig", .owner = b } } }); 126 | 127 | exe.root_module.addImport("c", c_module); 128 | 129 | const render_backend_flag = targetToBackendFlag(target.result); 130 | 131 | const c_flags = if (target.result.os.tag == .macos) &[_][]const u8{ "-std=c99", "-ObjC", "-fobjc-arc", render_backend_flag } else &[_][]const u8{ "-std=c99", render_backend_flag }; 132 | exe.addCSourceFile(.{ .file = .{ .src_path = .{ .owner = b, .sub_path = "src/compile_sokol.c" } }, .flags = c_flags }); 133 | 134 | const cpp_args = [_][]const u8{ "-Wno-deprecated-declarations", "-Wno-return-type-c-linkage", "-fno-exceptions", "-fno-threadsafe-statics" }; 135 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/imgui/imgui.cpp"), .flags = &cpp_args }); 136 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/imgui/imgui_tables.cpp"), .flags = &cpp_args }); 137 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/imgui/imgui_demo.cpp"), .flags = &cpp_args }); 138 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/imgui/imgui_draw.cpp"), .flags = &cpp_args }); 139 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/imgui/imgui_widgets.cpp"), .flags = &cpp_args }); 140 | exe.addCSourceFile(.{ .file = b.path("src/cimgui/cimgui.cpp"), .flags = &cpp_args }); 141 | 142 | // Shaders 143 | const shader_flags = [_][]const u8{"-std=c99"}; 144 | exe.addCSourceFile(.{ .file = b.path("src/shaders/cube_compile.c"), .flags = &shader_flags }); 145 | exe.addCSourceFile(.{ .file = b.path("src/shaders/triangle_compile.c"), .flags = &shader_flags }); 146 | exe.addCSourceFile(.{ .file = b.path("src/shaders/instancing_compile.c"), .flags = &shader_flags }); 147 | exe.linkLibC(); 148 | 149 | switch (target.result.os.tag) { 150 | .windows => { 151 | //See https://github.com/ziglang/zig/issues/8531 only matters in release mode 152 | exe.want_lto = false; 153 | exe.linkSystemLibrary("user32"); 154 | exe.linkSystemLibrary("gdi32"); 155 | exe.linkSystemLibrary("ole32"); // For Sokol audio 156 | }, 157 | .macos => { 158 | exe.linkFramework("Foundation"); 159 | exe.linkFramework("Cocoa"); 160 | exe.linkFramework("Quartz"); 161 | exe.linkFramework("QuartzCore"); 162 | exe.linkFramework("Metal"); 163 | exe.linkFramework("MetalKit"); 164 | exe.linkFramework("OpenGL"); 165 | exe.linkFramework("Audiotoolbox"); 166 | exe.linkFramework("CoreAudio"); 167 | exe.linkSystemLibrary("c++"); 168 | }, 169 | .emscripten => { 170 | // make sure we're building for the wasm32-emscripten target, not wasm32-freestanding 171 | if (exe.rootModuleTarget().os.tag != .emscripten) { 172 | std.log.err("Please build with 'zig build -Dtarget=wasm32-emscripten", .{}); 173 | return error.Wasm32EmscriptenExpected; 174 | } 175 | // one-time setup of Emscripten SDK 176 | if (try emscripten.emSdkSetupStep(b, emsdk.?)) |emsdk_setup| { 177 | exe.step.dependOn(&emsdk_setup.step); 178 | } 179 | // add the Emscripten system include seach path 180 | exe.addSystemIncludePath(emscripten.emSdkLazyPath(b, emsdk.?, &.{ "upstream", "emscripten", "cache", "sysroot", "include" })); 181 | }, 182 | else => { 183 | // Not tested 184 | exe.linkSystemLibrary("GL"); 185 | exe.linkSystemLibrary("GLEW"); 186 | @panic("OS not supported. Try removing panic in build.zig if you want to test this"); 187 | }, 188 | } 189 | } 190 | 191 | fn targetToBackendFlag(target: std.Target) []const u8 { 192 | if (target.isDarwin()) { 193 | return "-DSOKOL_METAL"; 194 | } else if (target.isWasm() or target.isAndroid()) { 195 | return "-DSOKOL_GLES3"; 196 | } else { 197 | return "-DSOKOL_GLCORE"; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = "sokol-zig-examples", 3 | .version = "0.1.0", 4 | .paths = .{ 5 | "src", 6 | "build.zig", 7 | "build.zig.zon", 8 | }, 9 | .dependencies = .{ 10 | .emsdk = .{ 11 | .url = "git+https://github.com/emscripten-core/emsdk#3.1.61", 12 | .hash = "12200ba39d83227f5de08287b043b011a2eb855cdb077f4b165edce30564ba73400e", 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /docs/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffkdev/sokol-zig-examples/f99a2cf7476f70924370cefb89531434fb4bff34/docs/cube.png -------------------------------------------------------------------------------- /docs/imgui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffkdev/sokol-zig-examples/f99a2cf7476f70924370cefb89531434fb4bff34/docs/imgui.png -------------------------------------------------------------------------------- /docs/instancing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffkdev/sokol-zig-examples/f99a2cf7476f70924370cefb89531434fb4bff34/docs/instancing.png -------------------------------------------------------------------------------- /docs/triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffkdev/sokol-zig-examples/f99a2cf7476f70924370cefb89531434fb4bff34/docs/triangle.png -------------------------------------------------------------------------------- /src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | example_*.zig and shader .glsl files based on sokol-examples which are under the MIT lisense below. 2 | 3 | MIT License 4 | 5 | Copyright (c) 2017 Andre Weissflog 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/c.zig: -------------------------------------------------------------------------------- 1 | pub usingnamespace @cImport({ 2 | @cInclude("sokol/sokol_app.h"); 3 | @cInclude("sokol/sokol_gfx.h"); 4 | @cInclude("sokol/sokol_time.h"); 5 | @cInclude("sokol/sokol_audio.h"); 6 | @cDefine("CIMGUI_DEFINE_ENUMS_AND_STRUCTS", ""); 7 | @cInclude("cimgui/cimgui.h"); 8 | @cInclude("sokol/util/sokol_imgui.h"); 9 | @cInclude("sokol/sokol_glue.h"); 10 | }); 11 | -------------------------------------------------------------------------------- /src/compile_sokol.c: -------------------------------------------------------------------------------- 1 | #define SOKOL_IMPL 2 | #define SOKOL_NO_ENTRY 3 | #define SOKOL_NO_DEPRECATED 4 | #include "sokol/sokol_app.h" 5 | #include "sokol/sokol_gfx.h" 6 | #include "sokol/sokol_time.h" 7 | #include "sokol/sokol_audio.h" 8 | #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS 9 | #include "cimgui/cimgui.h" 10 | #define SOKOL_IMGUI_IMPL 11 | #include "sokol/util/sokol_imgui.h" 12 | #include "sokol/sokol_glue.h" -------------------------------------------------------------------------------- /src/emscripten.zig: -------------------------------------------------------------------------------- 1 | // Emscripten building copied from: https://github.com/floooh/sokol-zig 2 | 3 | // zlib/libpng license 4 | 5 | // Copyright (c) 2020 Andre Weissflog 6 | 7 | // This software is provided 'as-is', without any express or implied warranty. 8 | // In no event will the authors be held liable for any damages arising from the 9 | // use of this software. 10 | 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software in a 17 | // product, an acknowledgment in the product documentation would be 18 | // appreciated but is not required. 19 | 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | 26 | const std = @import("std"); 27 | const builtin = @import("builtin"); 28 | const Build = std.Build; 29 | const OptimizeMode = std.builtin.OptimizeMode; 30 | 31 | pub const SokolBackend = enum { 32 | auto, // Windows: D3D11, macOS/iOS: Metal, otherwise: GL 33 | d3d11, 34 | metal, 35 | gl, 36 | gles3, 37 | wgpu, 38 | }; 39 | 40 | // build the sokol C headers into a static library 41 | pub const LibSokolOptions = struct { 42 | target: Build.ResolvedTarget, 43 | optimize: OptimizeMode, 44 | backend: SokolBackend = .auto, 45 | use_egl: bool = false, 46 | use_x11: bool = true, 47 | use_wayland: bool = false, 48 | emsdk: ?*Build.Dependency = null, 49 | with_sokol_imgui: bool = false, 50 | }; 51 | 52 | // for wasm32-emscripten, need to run the Emscripten linker from the Emscripten SDK 53 | // NOTE: ideally this would go into a separate emsdk-zig package 54 | pub const EmLinkOptions = struct { 55 | target: Build.ResolvedTarget, 56 | optimize: OptimizeMode, 57 | lib_main: *Build.Step.Compile, // the actual Zig code must be compiled to a static link library 58 | emsdk: *Build.Dependency, 59 | release_use_closure: bool = true, 60 | release_use_lto: bool = true, 61 | use_webgpu: bool = false, 62 | use_webgl2: bool = false, 63 | use_emmalloc: bool = false, 64 | use_filesystem: bool = true, 65 | shell_file_path: ?Build.LazyPath, 66 | extra_args: []const []const u8 = &.{}, 67 | }; 68 | pub fn emLinkStep(b: *Build, options: EmLinkOptions) !*Build.Step.InstallDir { 69 | const emcc_path = emSdkLazyPath(b, options.emsdk, &.{ "upstream", "emscripten", "emcc" }).getPath(b); 70 | const emcc = b.addSystemCommand(&.{emcc_path}); 71 | emcc.setName("emcc"); // hide emcc path 72 | if (options.optimize == .Debug) { 73 | emcc.addArgs(&.{ "-Og", "-sSAFE_HEAP=1", "-sSTACK_OVERFLOW_CHECK=1" }); 74 | } else { 75 | emcc.addArg("-sASSERTIONS=0"); 76 | if (options.optimize == .ReleaseSmall) { 77 | emcc.addArg("-Oz"); 78 | } else { 79 | emcc.addArg("-O3"); 80 | } 81 | if (options.release_use_lto) { 82 | emcc.addArg("-flto"); 83 | } 84 | if (options.release_use_closure) { 85 | emcc.addArgs(&.{ "--closure", "1" }); 86 | } 87 | } 88 | if (options.use_webgpu) { 89 | emcc.addArg("-sUSE_WEBGPU=1"); 90 | } 91 | if (options.use_webgl2) { 92 | emcc.addArg("-sUSE_WEBGL2=1"); 93 | } 94 | if (!options.use_filesystem) { 95 | emcc.addArg("-sNO_FILESYSTEM=1"); 96 | } 97 | if (options.use_emmalloc) { 98 | emcc.addArg("-sMALLOC='emmalloc'"); 99 | } 100 | if (options.shell_file_path) |shell_file_path| { 101 | emcc.addPrefixedFileArg("--shell-file=", shell_file_path); 102 | } 103 | for (options.extra_args) |arg| { 104 | emcc.addArg(arg); 105 | } 106 | 107 | // add the main lib, and then scan for library dependencies and add those too 108 | emcc.addArtifactArg(options.lib_main); 109 | var it = options.lib_main.root_module.iterateDependencies(options.lib_main, false); 110 | while (it.next()) |item| { 111 | for (item.module.link_objects.items) |link_object| { 112 | switch (link_object) { 113 | .other_step => |compile_step| { 114 | switch (compile_step.kind) { 115 | .lib => { 116 | emcc.addArtifactArg(compile_step); 117 | }, 118 | else => {}, 119 | } 120 | }, 121 | else => {}, 122 | } 123 | } 124 | } 125 | emcc.addArg("-o"); 126 | const out_file = emcc.addOutputFileArg(b.fmt("{s}.html", .{options.lib_main.name})); 127 | 128 | // the emcc linker creates 3 output files (.html, .wasm and .js) 129 | const install = b.addInstallDirectory(.{ 130 | .source_dir = out_file.dirname(), 131 | .install_dir = .prefix, 132 | .install_subdir = "web", 133 | }); 134 | install.step.dependOn(&emcc.step); 135 | 136 | // get the emcc step to run on 'zig build' 137 | b.getInstallStep().dependOn(&install.step); 138 | return install; 139 | } 140 | 141 | // build a run step which uses the emsdk emrun command to run a build target in the browser 142 | // NOTE: ideally this would go into a separate emsdk-zig package 143 | pub const EmRunOptions = struct { 144 | name: []const u8, 145 | emsdk: *Build.Dependency, 146 | }; 147 | pub fn emRunStep(b: *Build, options: EmRunOptions) *Build.Step.Run { 148 | const emrun_path = b.findProgram(&.{"emrun"}, &.{}) catch emSdkLazyPath(b, options.emsdk, &.{ "upstream", "emscripten", "emrun" }).getPath(b); 149 | const emrun = b.addSystemCommand(&.{ emrun_path, b.fmt("{s}/web/{s}.html", .{ b.install_path, options.name }) }); 150 | return emrun; 151 | } 152 | 153 | // helper function to build a LazyPath from the emsdk root and provided path components 154 | pub fn emSdkLazyPath(b: *Build, emsdk: *Build.Dependency, subPaths: []const []const u8) Build.LazyPath { 155 | return emsdk.path(b.pathJoin(subPaths)); 156 | } 157 | 158 | fn createEmsdkStep(b: *Build, emsdk: *Build.Dependency) *Build.Step.Run { 159 | if (builtin.os.tag == .windows) { 160 | return b.addSystemCommand(&.{emSdkLazyPath(b, emsdk, &.{"emsdk.bat"}).getPath(b)}); 161 | } else { 162 | const step = b.addSystemCommand(&.{"bash"}); 163 | step.addArg(emSdkLazyPath(b, emsdk, &.{"emsdk"}).getPath(b)); 164 | return step; 165 | } 166 | } 167 | 168 | // One-time setup of the Emscripten SDK (runs 'emsdk install + activate'). If the 169 | // SDK had to be setup, a run step will be returned which should be added 170 | // as dependency to the sokol library (since this needs the emsdk in place), 171 | // if the emsdk was already setup, null will be returned. 172 | // NOTE: ideally this would go into a separate emsdk-zig package 173 | // NOTE 2: the file exists check is a bit hacky, it would be cleaner 174 | // to build an on-the-fly helper tool which takes care of the SDK 175 | // setup and just does nothing if it already happened 176 | // NOTE 3: this code works just fine when the SDK version is updated in build.zig.zon 177 | // since this will be cloned into a new zig cache directory which doesn't have 178 | // an .emscripten file yet until the one-time setup. 179 | pub fn emSdkSetupStep(b: *Build, emsdk: *Build.Dependency) !?*Build.Step.Run { 180 | const dot_emsc_path = emSdkLazyPath(b, emsdk, &.{".emscripten"}).getPath(b); 181 | const dot_emsc_exists = !std.meta.isError(std.fs.accessAbsolute(dot_emsc_path, .{})); 182 | if (!dot_emsc_exists) { 183 | const emsdk_install = createEmsdkStep(b, emsdk); 184 | emsdk_install.addArgs(&.{ "install", "latest" }); 185 | const emsdk_activate = createEmsdkStep(b, emsdk); 186 | emsdk_activate.addArgs(&.{ "activate", "latest" }); 187 | emsdk_activate.step.dependOn(&emsdk_install.step); 188 | return emsdk_activate; 189 | } else { 190 | return null; 191 | } 192 | } 193 | 194 | // a separate step to compile shaders, expects the shader compiler in ../sokol-tools-bin/ 195 | // TODO: install sokol-shdc via package manager 196 | fn buildShaders(b: *Build, target: Build.ResolvedTarget) void { 197 | const sokol_tools_bin_dir = "../sokol-tools-bin/bin/"; 198 | const shaders_dir = "src/examples/shaders/"; 199 | const shaders = .{ 200 | "bufferoffsets.glsl", 201 | "cube.glsl", 202 | "instancing.glsl", 203 | "mrt.glsl", 204 | "noninterleaved.glsl", 205 | "offscreen.glsl", 206 | "quad.glsl", 207 | "shapes.glsl", 208 | "texcube.glsl", 209 | "blend.glsl", 210 | "vertexpull.glsl", 211 | "triangle.glsl", 212 | }; 213 | const optional_shdc: ?[:0]const u8 = comptime switch (builtin.os.tag) { 214 | .windows => "win32/sokol-shdc.exe", 215 | .linux => "linux/sokol-shdc", 216 | .macos => if (builtin.cpu.arch.isX86()) "osx/sokol-shdc" else "osx_arm64/sokol-shdc", 217 | else => null, 218 | }; 219 | if (optional_shdc == null) { 220 | std.log.warn("unsupported host platform, skipping shader compiler step", .{}); 221 | return; 222 | } 223 | const shdc_path = sokol_tools_bin_dir ++ optional_shdc.?; 224 | const shdc_step = b.step("shaders", "Compile shaders (needs ../sokol-tools-bin)"); 225 | const glsl = if (target.result.isDarwin()) "glsl410" else "glsl430"; 226 | const slang = glsl ++ ":metal_macos:hlsl5:glsl300es:wgsl"; 227 | inline for (shaders) |shader| { 228 | const cmd = b.addSystemCommand(&.{ 229 | shdc_path, 230 | "-i", 231 | shaders_dir ++ shader, 232 | "-o", 233 | shaders_dir ++ shader ++ ".zig", 234 | "-l", 235 | slang, 236 | "-f", 237 | "sokol_zig", 238 | }); 239 | shdc_step.dependOn(&cmd.step); 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /src/example_cube.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const c = @import("c.zig"); 3 | const Mat4 = @import("math3d.zig").Mat4; 4 | const Vec3 = @import("math3d.zig").Vec3; 5 | const glsl = @cImport({ 6 | @cInclude("sokol/sokol_gfx.h"); 7 | @cInclude("shaders/cube.glsl.h"); 8 | }); 9 | 10 | const SampleCount = 4; 11 | 12 | const State = struct { 13 | pass_action: c.sg_pass_action, 14 | main_pipeline: c.sg_pipeline, 15 | main_bindings: c.sg_bindings, 16 | }; 17 | 18 | var rx: f32 = 0.0; 19 | var ry: f32 = 0.0; 20 | var state: State = undefined; 21 | 22 | export fn init() void { 23 | var desc = std.mem.zeroes(c.sg_desc); 24 | desc.environment = c.sglue_environment(); 25 | c.sg_setup(&desc); 26 | 27 | c.stm_setup(); 28 | 29 | state.pass_action.colors[0].load_action = c.SG_LOADACTION_CLEAR; 30 | state.pass_action.colors[0].clear_value = c.sg_color{ .r = 0.2, .g = 0.2, .b = 0.2, .a = 1.0 }; 31 | const vertices = [_]f32{ 32 | // positions // colors 33 | -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 34 | 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 35 | 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 36 | -1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 37 | 38 | -1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 39 | 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 40 | 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 41 | -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 42 | 43 | -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 1.0, 44 | -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0, 45 | -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 46 | -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 47 | 48 | 1.0, -1.0, -1.0, 1.0, 0.5, 0.0, 1.0, 49 | 1.0, 1.0, -1.0, 1.0, 0.5, 0.0, 1.0, 50 | 1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 1.0, 51 | 1.0, -1.0, 1.0, 1.0, 0.5, 0.0, 1.0, 52 | 53 | -1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, 54 | -1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, 55 | 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 1.0, 56 | 1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, 57 | 58 | -1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 59 | -1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, 60 | 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, 61 | 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, 62 | }; 63 | 64 | const indices = [_]u16{ 65 | 0, 1, 2, 0, 2, 3, 66 | 6, 5, 4, 7, 6, 4, 67 | 8, 9, 10, 8, 10, 11, 68 | 14, 13, 12, 15, 14, 12, 69 | 16, 17, 18, 16, 18, 19, 70 | 22, 21, 20, 23, 22, 20, 71 | }; 72 | 73 | var buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 74 | buffer_desc.size = vertices.len * @sizeOf(f32); 75 | buffer_desc.data = .{ .ptr = &vertices[0], .size = buffer_desc.size }; 76 | state.main_bindings.vertex_buffers[0] = c.sg_make_buffer(&buffer_desc); 77 | 78 | buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 79 | buffer_desc.type = c.SG_BUFFERTYPE_INDEXBUFFER; 80 | buffer_desc.size = indices.len * @sizeOf(u16); 81 | buffer_desc.data = .{ .ptr = &indices[0], .size = buffer_desc.size }; 82 | state.main_bindings.index_buffer = c.sg_make_buffer(&buffer_desc); 83 | 84 | const shader = c.sg_make_shader(@ptrCast(glsl.cube_shader_desc(glsl.sg_query_backend()))); 85 | var pipeline_desc = std.mem.zeroes(c.sg_pipeline_desc); 86 | pipeline_desc.layout.attrs[glsl.ATTR_cube_position].format = c.SG_VERTEXFORMAT_FLOAT3; 87 | pipeline_desc.layout.attrs[glsl.ATTR_cube_color0].format = c.SG_VERTEXFORMAT_FLOAT4; 88 | pipeline_desc.layout.buffers[0].stride = 28; 89 | pipeline_desc.shader = shader; 90 | pipeline_desc.index_type = c.SG_INDEXTYPE_UINT16; 91 | pipeline_desc.depth.compare = c.SG_COMPAREFUNC_LESS_EQUAL; 92 | pipeline_desc.depth.write_enabled = true; 93 | pipeline_desc.cull_mode = c.SG_CULLMODE_BACK; 94 | state.main_pipeline = c.sg_make_pipeline(&pipeline_desc); 95 | } 96 | 97 | export fn update() void { 98 | const width = c.sapp_width(); 99 | const height = c.sapp_height(); 100 | const w: f32 = @floatFromInt(width); 101 | const h: f32 = @floatFromInt(height); 102 | const radians: f32 = 1.0472; //60 degrees 103 | const proj: Mat4 = Mat4.createPerspective(radians, w / h, 0.01, 100.0); 104 | const view: Mat4 = Mat4.createLookAt(Vec3.new(2.0, 3.5, 2.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 1.0, 0.0)); 105 | const view_proj = Mat4.mul(proj, view); 106 | 107 | rx += 1.0 / 220.0; 108 | ry += 2.0 / 220.0; 109 | const rxm = Mat4.createAngleAxis(Vec3.new(1, 0, 0), rx); 110 | const rym = Mat4.createAngleAxis(Vec3.new(0, 1, 0), ry); 111 | 112 | const model = Mat4.mul(rxm, rym); 113 | var mvp = Mat4.mul(view_proj, model); 114 | var vs_params = glsl.vs_params_t{ 115 | .mvp = mvp.toArray(), 116 | }; 117 | 118 | c.sg_begin_pass(&(c.sg_pass){ .action = state.pass_action, .swapchain = c.sglue_swapchain() }); 119 | c.sg_apply_pipeline(state.main_pipeline); 120 | c.sg_apply_bindings(&state.main_bindings); 121 | c.sg_apply_uniforms(0, &c.sg_range{ .ptr = &vs_params, .size = @sizeOf(glsl.vs_params_t) }); 122 | c.sg_draw(0, 36, 1); 123 | c.sg_end_pass(); 124 | c.sg_commit(); 125 | } 126 | 127 | export fn cleanup() void { 128 | c.sg_shutdown(); 129 | } 130 | 131 | pub fn main() void { 132 | var app_desc = std.mem.zeroes(c.sapp_desc); 133 | app_desc.width = 1280; 134 | app_desc.height = 720; 135 | app_desc.init_cb = init; 136 | app_desc.frame_cb = update; 137 | app_desc.cleanup_cb = cleanup; 138 | app_desc.sample_count = SampleCount; 139 | app_desc.window_title = "Cube (sokol-zig)"; 140 | _ = c.sapp_run(&app_desc); 141 | } 142 | -------------------------------------------------------------------------------- /src/example_imgui.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const c = @import("c.zig"); 3 | 4 | const State = struct { 5 | pass_action: c.sg_pass_action, 6 | main_pipeline: c.sg_pipeline, 7 | main_bindings: c.sg_bindings, 8 | }; 9 | 10 | var state: State = undefined; 11 | var last_time: u64 = 0; 12 | var show_test_window: bool = false; 13 | var show_another_window: bool = false; 14 | var display_menu: bool = false; 15 | var f: f32 = 0.0; 16 | var clear_color: [3]f32 = .{ 0.2, 0.2, 0.2 }; 17 | 18 | export fn init() void { 19 | var desc = std.mem.zeroes(c.sg_desc); 20 | desc.environment = c.sglue_environment(); 21 | c.sg_setup(&desc); 22 | c.stm_setup(); 23 | 24 | var imgui_desc = std.mem.zeroes(c.simgui_desc_t); 25 | c.simgui_setup(&imgui_desc); 26 | 27 | state.pass_action.colors[0].load_action = c.SG_LOADACTION_CLEAR; 28 | state.pass_action.colors[0].clear_value = c.sg_color{ .r = clear_color[0], .g = clear_color[1], .b = clear_color[2], .a = 1.0 }; 29 | } 30 | 31 | export fn update() void { 32 | const width = c.sapp_width(); 33 | const height = c.sapp_height(); 34 | 35 | const dt = c.stm_sec(c.stm_laptime(&last_time)); 36 | c.simgui_new_frame(&c.simgui_frame_desc_t{ .width = width, .height = height, .delta_time = dt, .dpi_scale = 0.0 }); 37 | 38 | c.igText("Hello, world!"); 39 | _ = c.igSliderFloat("float", &f, 0.0, 1.0, "%.3f", 1.0); 40 | if (c.igColorEdit3("clear color", &clear_color[0], 0)) { 41 | state.pass_action.colors[0].clear_value.r = clear_color[0]; 42 | state.pass_action.colors[0].clear_value.g = clear_color[1]; 43 | state.pass_action.colors[0].clear_value.b = clear_color[2]; 44 | } 45 | if (c.igButton("Test Window", c.ImVec2{ .x = 0.0, .y = 0.0 })) show_test_window = !show_test_window; 46 | if (c.igButton("Another Window", c.ImVec2{ .x = 0.0, .y = 0.0 })) show_another_window = !show_another_window; 47 | c.igText("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / c.igGetIO().*.Framerate, c.igGetIO().*.Framerate); 48 | 49 | if (show_another_window) { 50 | c.igSetNextWindowSize(c.ImVec2{ .x = 200, .y = 100 }, c.ImGuiCond_FirstUseEver); 51 | _ = c.igBegin("Another Window", &show_another_window, 0); 52 | c.igText("Hello"); 53 | c.igEnd(); 54 | } 55 | // If you want to try testing in imgui 1.80+, add this block of code: 56 | //const ig_context: *c.ImGuiContext = c.igGetCurrentContext(); 57 | //const window: *c.ImGuiWindow = ig_context.*.CurrentWindow.?; 58 | //if (!window.SkipItems) { 59 | // c.igText( 60 | // \\ Translate-c converts c.ImGuiWindow to an opaque type 61 | // \\ in imgui 1.80+ causing this to not compile 62 | // ); 63 | //} 64 | 65 | if (show_test_window) { 66 | c.igSetNextWindowPos(c.ImVec2{ .x = 460, .y = 20 }, c.ImGuiCond_FirstUseEver, c.ImVec2{ .x = 0, .y = 0 }); 67 | c.igShowDemoWindow(0); 68 | } 69 | 70 | c.sg_begin_pass(&(c.sg_pass){ .action = state.pass_action, .swapchain = c.sglue_swapchain() }); 71 | c.simgui_render(); 72 | c.sg_end_pass(); 73 | c.sg_commit(); 74 | } 75 | 76 | export fn cleanup() void { 77 | c.simgui_shutdown(); 78 | c.sg_shutdown(); 79 | } 80 | 81 | export fn event(e: [*c]const c.sapp_event) void { 82 | _ = c.simgui_handle_event(e); 83 | } 84 | 85 | pub fn main() void { 86 | var app_desc = std.mem.zeroes(c.sapp_desc); 87 | app_desc.width = 1280; 88 | app_desc.height = 720; 89 | app_desc.init_cb = init; 90 | app_desc.frame_cb = update; 91 | app_desc.cleanup_cb = cleanup; 92 | app_desc.event_cb = event; 93 | app_desc.enable_clipboard = true; 94 | app_desc.window_title = "IMGUI (sokol-zig)"; 95 | _ = c.sapp_run(&app_desc); 96 | } 97 | -------------------------------------------------------------------------------- /src/example_instancing.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const c = @import("c.zig"); 3 | const Mat4 = @import("math3d.zig").Mat4; 4 | const Vec3 = @import("math3d.zig").Vec3; 5 | const glsl = @cImport({ 6 | @cInclude("sokol/sokol_gfx.h"); 7 | @cInclude("shaders/instancing.glsl.h"); 8 | }); 9 | const rand = @import("std").rand; 10 | 11 | const SampleCount = 4; 12 | const NumParticlesEmittedPerFrame = 10; 13 | const MaxParticles: u32 = 512 * 2014; 14 | 15 | const State = struct { 16 | pass_action: c.sg_pass_action, 17 | main_pipeline: c.sg_pipeline, 18 | main_bindings: c.sg_bindings, 19 | }; 20 | var rndgen = rand.DefaultPrng.init(42); 21 | var ry: f32 = 0.0; 22 | var state: State = undefined; 23 | var cur_num_particles: u32 = 0; 24 | var pos: [MaxParticles]Vec3 = undefined; 25 | var vel: [MaxParticles]Vec3 = undefined; 26 | 27 | fn frnd(range: f32) f32 { 28 | return rndgen.random().float(f32) * range; 29 | } 30 | 31 | export fn init() void { 32 | var desc = std.mem.zeroes(c.sg_desc); 33 | desc.environment = c.sglue_environment(); 34 | c.sg_setup(&desc); 35 | c.stm_setup(); 36 | 37 | state.pass_action.colors[0].load_action = c.SG_LOADACTION_CLEAR; 38 | state.pass_action.colors[0].clear_value = c.sg_color{ .r = 0.2, .g = 0.2, .b = 0.2, .a = 1.0 }; 39 | const r = 0.05; 40 | const vertices = [_]f32{ 41 | // positions colors 42 | 0.0, -r, 0.0, 1.0, 0.0, 0.0, 1.0, 43 | r, 0.0, r, 0.0, 1.0, 0.0, 1.0, 44 | r, 0.0, -r, 0.0, 0.0, 1.0, 1.0, 45 | -r, 0.0, -r, 1.0, 1.0, 0.0, 1.0, 46 | -r, 0.0, r, 0.0, 1.0, 1.0, 1.0, 47 | 0.0, r, 0.0, 1.0, 0.0, 1.0, 1.0, 48 | }; 49 | 50 | const indices = [_]u16{ 51 | 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1, 52 | 5, 1, 2, 5, 2, 3, 5, 3, 4, 5, 4, 1, 53 | }; 54 | 55 | var vertex_buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 56 | vertex_buffer_desc.size = vertices.len * @sizeOf(f32); 57 | vertex_buffer_desc.data = .{ .ptr = &vertices[0], .size = vertex_buffer_desc.size }; 58 | state.main_bindings.vertex_buffers[0] = c.sg_make_buffer(&vertex_buffer_desc); 59 | 60 | var index_buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 61 | index_buffer_desc.type = c.SG_BUFFERTYPE_INDEXBUFFER; 62 | index_buffer_desc.size = indices.len * @sizeOf(u16); 63 | index_buffer_desc.data = .{ .ptr = &indices[0], .size = index_buffer_desc.size }; 64 | state.main_bindings.index_buffer = c.sg_make_buffer(&index_buffer_desc); 65 | 66 | var instance_buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 67 | instance_buffer_desc.size = MaxParticles * @sizeOf(Vec3); 68 | instance_buffer_desc.usage = c.SG_USAGE_STREAM; 69 | state.main_bindings.vertex_buffers[1] = c.sg_make_buffer(&instance_buffer_desc); 70 | 71 | const shader = c.sg_make_shader(@ptrCast(glsl.instancing_shader_desc(glsl.sg_query_backend()))); 72 | 73 | var pipeline_desc = std.mem.zeroes(c.sg_pipeline_desc); 74 | pipeline_desc.layout.attrs[glsl.ATTR_instancing_pos].format = c.SG_VERTEXFORMAT_FLOAT3; 75 | pipeline_desc.layout.attrs[glsl.ATTR_instancing_color0].format = c.SG_VERTEXFORMAT_FLOAT4; 76 | pipeline_desc.layout.attrs[glsl.ATTR_instancing_inst_pos].format = c.SG_VERTEXFORMAT_FLOAT3; 77 | pipeline_desc.layout.attrs[glsl.ATTR_instancing_inst_pos].buffer_index = 1; 78 | pipeline_desc.layout.buffers[1].step_func = c.SG_VERTEXSTEP_PER_INSTANCE; 79 | pipeline_desc.shader = shader; 80 | pipeline_desc.index_type = c.SG_INDEXTYPE_UINT16; 81 | pipeline_desc.depth.compare = c.SG_COMPAREFUNC_LESS_EQUAL; 82 | pipeline_desc.depth.write_enabled = true; 83 | pipeline_desc.cull_mode = c.SG_CULLMODE_BACK; 84 | state.main_pipeline = c.sg_make_pipeline(&pipeline_desc); 85 | } 86 | 87 | export fn update() void { 88 | const width = c.sapp_width(); 89 | const height = c.sapp_height(); 90 | const w: f32 = @floatFromInt(width); 91 | const h: f32 = @floatFromInt(height); 92 | const radians: f32 = 1.0472; //60 degrees 93 | const frame_time = 1.0 / 60.0; 94 | 95 | // See git history for what this code *should* look like. This was modified to take a reference 96 | // of the arrays to avoid copies to the stack on due to Zig compiler issues on 0.11.0-dev.3771+128fd7dd0 97 | // Without taking a reference this will stack overflow. 98 | 99 | // emit new particles 100 | var i: u32 = 0; 101 | while (i < NumParticlesEmittedPerFrame) : (i += 1) { 102 | if (cur_num_particles < MaxParticles) { 103 | (&pos)[cur_num_particles] = Vec3.new(0, 0, 0); 104 | (&vel)[cur_num_particles] = Vec3.new(frnd(1) - 0.5, frnd(1) * 0.5 + 2.0, frnd(1) - 0.5); 105 | cur_num_particles += 1; 106 | } else { 107 | break; 108 | } 109 | } 110 | i = 0; 111 | // update particle positions 112 | while (i < cur_num_particles) : (i += 1) { 113 | (&vel)[i].y -= 1.0 * frame_time; 114 | (&pos)[i].x += (&vel)[i].x * frame_time; 115 | (&pos)[i].y += (&vel)[i].y * frame_time; 116 | (&pos)[i].z += (&vel)[i].z * frame_time; 117 | // bounce back from 'ground' 118 | if ((&pos)[i].y < -2.0) { 119 | (&pos)[i].y = -1.8; 120 | (&vel)[i].y = -(&vel)[i].y; 121 | (&vel)[i].x *= 0.8; 122 | (&vel)[i].y *= 0.8; 123 | (&vel)[i].z *= 0.8; 124 | } 125 | } 126 | 127 | // update instance data 128 | c.sg_update_buffer(state.main_bindings.vertex_buffers[1], &c.sg_range{ 129 | .ptr = &pos[0], 130 | .size = cur_num_particles * @sizeOf(Vec3), 131 | }); 132 | 133 | const proj: Mat4 = Mat4.createPerspective(radians, w / h, 0.01, 100.0); 134 | const view: Mat4 = Mat4.createLookAt(Vec3.new(0.0, 1.5, 12.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 1.0, 0.0)); 135 | const view_proj = Mat4.mul(proj, view); 136 | ry += 2.0 / 400.0; 137 | var vs_params = glsl.vs_params_t{ 138 | .mvp = Mat4.mul(view_proj, Mat4.createAngleAxis(Vec3.new(0, 1, 0), ry)).toArray(), 139 | }; 140 | 141 | c.sg_begin_pass(&(c.sg_pass){ .action = state.pass_action, .swapchain = c.sglue_swapchain() }); 142 | c.sg_apply_pipeline(state.main_pipeline); 143 | c.sg_apply_bindings(&state.main_bindings); 144 | c.sg_apply_uniforms(glsl.UB_vs_params, &c.sg_range{ .ptr = &vs_params, .size = @sizeOf(glsl.vs_params_t) }); 145 | c.sg_draw(0, 24, @intCast(cur_num_particles)); 146 | c.sg_end_pass(); 147 | c.sg_commit(); 148 | } 149 | 150 | export fn cleanup() void { 151 | c.sg_shutdown(); 152 | } 153 | 154 | pub fn main() void { 155 | var app_desc = std.mem.zeroes(c.sapp_desc); 156 | app_desc.width = 1280; 157 | app_desc.height = 720; 158 | app_desc.init_cb = init; 159 | app_desc.frame_cb = update; 160 | app_desc.cleanup_cb = cleanup; 161 | app_desc.sample_count = SampleCount; 162 | app_desc.window_title = "Instancing (sokol-zig)"; 163 | _ = c.sapp_run(&app_desc); 164 | } 165 | -------------------------------------------------------------------------------- /src/example_sound.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const c = @import("c.zig"); 3 | 4 | const NumSamples = 32; 5 | var pass_action: c.sg_pass_action = undefined; 6 | var sample_pos: usize = 0; 7 | var samples: [NumSamples]f32 = undefined; 8 | var even_odd: u32 = 0; 9 | 10 | export fn init() void { 11 | var desc = std.mem.zeroes(c.sg_desc); 12 | desc.environment = c.sglue_environment(); 13 | c.sg_setup(&desc); 14 | 15 | pass_action = std.mem.zeroes(c.sg_pass_action); 16 | 17 | pass_action.colors[0].load_action = c.SG_LOADACTION_CLEAR; 18 | pass_action.colors[0].clear_value = c.sg_color{ .r = 1.0, .g = 0.5, .b = 0.0, .a = 1.0 }; 19 | 20 | const audio_desc = std.mem.zeroes(c.saudio_desc); 21 | c.saudio_setup(&audio_desc); 22 | } 23 | 24 | export fn update() void { 25 | c.sg_begin_pass(&(c.sg_pass){ .action = pass_action, .swapchain = c.sglue_swapchain() }); 26 | const num_frames: u32 = @intCast(c.saudio_expect()); 27 | var s: f32 = 0.0; 28 | var i: u32 = 0; 29 | while (i < num_frames) { 30 | if (even_odd & (1 << 5) != 0) { 31 | s = 0.05; 32 | } else { 33 | s = -0.05; 34 | } 35 | even_odd += 1; 36 | samples[sample_pos] = s; 37 | sample_pos += 1; 38 | if (sample_pos == NumSamples) { 39 | sample_pos = 0; 40 | _ = c.saudio_push(&samples[0], NumSamples); 41 | } 42 | i += 1; 43 | } 44 | c.sg_end_pass(); 45 | c.sg_commit(); 46 | } 47 | 48 | export fn cleanup() void { 49 | c.saudio_shutdown(); 50 | c.sg_shutdown(); 51 | } 52 | 53 | pub fn main() void { 54 | var app_desc = std.mem.zeroes(c.sapp_desc); 55 | app_desc.width = 1280; 56 | app_desc.height = 720; 57 | app_desc.init_cb = init; 58 | app_desc.frame_cb = update; 59 | app_desc.cleanup_cb = cleanup; 60 | app_desc.window_title = "Sound (sokol-zig)"; 61 | _ = c.sapp_run(&app_desc); 62 | } 63 | -------------------------------------------------------------------------------- /src/example_triangle.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const c = @import("c.zig"); 3 | const glsl = @cImport({ 4 | @cInclude("sokol/sokol_gfx.h"); 5 | @cInclude("shaders/triangle.glsl.h"); 6 | }); 7 | 8 | const State = struct { 9 | pass_action: c.sg_pass_action, 10 | main_pipeline: c.sg_pipeline, 11 | main_bindings: c.sg_bindings, 12 | }; 13 | 14 | var state: State = undefined; 15 | 16 | export fn init() void { 17 | var desc = std.mem.zeroes(c.sg_desc); 18 | desc.environment = c.sglue_environment(); 19 | c.sg_setup(&desc); 20 | 21 | state.pass_action.colors[0].load_action = c.SG_LOADACTION_CLEAR; 22 | state.pass_action.colors[0].clear_value = c.sg_color{ .r = 0.2, .g = 0.2, .b = 0.2, .a = 1.0 }; 23 | const vertices = [_]f32{ 24 | // positions // colors 25 | 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 26 | 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 27 | -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 28 | }; 29 | 30 | var buffer_desc = std.mem.zeroes(c.sg_buffer_desc); 31 | buffer_desc.size = vertices.len * @sizeOf(f32); 32 | buffer_desc.data = .{ .ptr = &vertices[0], .size = buffer_desc.size }; 33 | buffer_desc.type = c.SG_BUFFERTYPE_VERTEXBUFFER; 34 | state.main_bindings.vertex_buffers[0] = c.sg_make_buffer(&buffer_desc); 35 | 36 | const shader = c.sg_make_shader(@ptrCast(glsl.triangle_shader_desc(glsl.sg_query_backend()))); 37 | 38 | var pipeline_desc = std.mem.zeroes(c.sg_pipeline_desc); 39 | pipeline_desc.layout.attrs[glsl.ATTR_triangle_position].format = c.SG_VERTEXFORMAT_FLOAT3; 40 | pipeline_desc.layout.attrs[glsl.ATTR_triangle_color0].format = c.SG_VERTEXFORMAT_FLOAT4; 41 | pipeline_desc.shader = shader; 42 | state.main_pipeline = c.sg_make_pipeline(&pipeline_desc); 43 | } 44 | 45 | export fn update() void { 46 | c.sg_begin_pass(&(c.sg_pass){ .action = state.pass_action, .swapchain = c.sglue_swapchain() }); 47 | c.sg_apply_pipeline(state.main_pipeline); 48 | c.sg_apply_bindings(&state.main_bindings); 49 | c.sg_draw(0, 3, 1); 50 | c.sg_end_pass(); 51 | c.sg_commit(); 52 | } 53 | 54 | export fn cleanup() void { 55 | c.sg_shutdown(); 56 | } 57 | 58 | pub fn main() void { 59 | var app_desc = std.mem.zeroes(c.sapp_desc); 60 | app_desc.width = 1280; 61 | app_desc.height = 720; 62 | app_desc.init_cb = init; 63 | app_desc.frame_cb = update; 64 | app_desc.cleanup_cb = cleanup; 65 | app_desc.window_title = "Triangle (sokol-zig)"; 66 | _ = c.sapp_run(&app_desc); 67 | } 68 | -------------------------------------------------------------------------------- /src/math3d.zig: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Felix Queißner 2 | // This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 3 | // Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 4 | // 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 5 | // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 6 | // 3. This notice may not be removed or altered from any source distribution. 7 | 8 | // Altered source. Added: toArray. Altered: lookAt, perspective. Made column major. Removed Vec2/Vec4. Only kept necessary methods for examples. removed tests 9 | 10 | const std = @import("std"); 11 | 12 | pub const Vec3 = extern struct { 13 | const Self = @This(); 14 | x: f32, 15 | y: f32, 16 | z: f32, 17 | 18 | pub fn length2(a: Self) f32 { 19 | return Self.dot(a, a); 20 | } 21 | pub fn length(a: Self) f32 { 22 | return std.math.sqrt(a.length2()); 23 | } 24 | pub fn dot(a: Self, b: Self) f32 { 25 | var result: f32 = 0; 26 | inline for (@typeInfo(Self).Struct.fields) |fld| { 27 | result += @field(a, fld.name) * @field(b, fld.name); 28 | } 29 | return result; 30 | } 31 | pub fn new(x: f32, y: f32, z: f32) Vec3 { 32 | return Vec3{ 33 | .x = x, 34 | .y = y, 35 | .z = z, 36 | }; 37 | } 38 | pub fn scale(a: Self, b: f32) Self { 39 | var result: Self = undefined; 40 | inline for (@typeInfo(Self).Struct.fields) |fld| { 41 | @field(result, fld.name) = @field(a, fld.name) * b; 42 | } 43 | return result; 44 | } 45 | 46 | pub fn cross(a: Self, b: Self) Self { 47 | return Self{ 48 | .x = a.y * b.z - a.z * b.y, 49 | .y = a.z * b.x - a.x * b.z, 50 | .z = a.x * b.y - a.y * b.x, 51 | }; 52 | } 53 | 54 | pub fn normalize(vec: Self) Self { 55 | return vec.scale(1.0 / vec.length()); 56 | } 57 | 58 | pub fn sub(a: Self, b: Self) Self { 59 | var result: Self = undefined; 60 | inline for (@typeInfo(Self).Struct.fields) |fld| { 61 | @field(result, fld.name) = @field(a, fld.name) - @field(b, fld.name); 62 | } 63 | return result; 64 | } 65 | }; 66 | 67 | pub const Mat4 = extern struct { 68 | pub const Self = @This(); 69 | fields: [4][4]f32, // [col][row] 70 | 71 | pub const zero = Self{ 72 | .fields = [4][4]f32{ 73 | [4]f32{ 0, 0, 0, 0 }, 74 | [4]f32{ 0, 0, 0, 0 }, 75 | [4]f32{ 0, 0, 0, 0 }, 76 | [4]f32{ 0, 0, 0, 0 }, 77 | }, 78 | }; 79 | 80 | pub const identity = Self{ 81 | .fields = [4][4]f32{ 82 | [4]f32{ 1, 0, 0, 0 }, 83 | [4]f32{ 0, 1, 0, 0 }, 84 | [4]f32{ 0, 0, 1, 0 }, 85 | [4]f32{ 0, 0, 0, 1 }, 86 | }, 87 | }; 88 | 89 | pub fn mul(a: Self, b: Self) Self { 90 | var result: Self = undefined; 91 | inline for ([_]comptime_int{ 0, 1, 2, 3 }) |col| { 92 | inline for ([_]comptime_int{ 0, 1, 2, 3 }) |row| { 93 | var sum: f32 = 0.0; 94 | inline for ([_]comptime_int{ 0, 1, 2, 3 }) |i| { 95 | sum += a.fields[i][row] * b.fields[col][i]; 96 | } 97 | result.fields[col][row] = sum; 98 | } 99 | } 100 | return result; 101 | } 102 | // taken from GLM implementation 103 | pub fn createLook(eye: Vec3, direction: Vec3, up: Vec3) Self { 104 | const f = direction.normalize(); 105 | const s = Vec3.cross(up, f).normalize(); 106 | const u = Vec3.cross(f, s); 107 | 108 | var result = Self.identity; 109 | result.fields[0][0] = s.x; 110 | result.fields[1][0] = s.y; 111 | result.fields[2][0] = s.z; 112 | result.fields[0][1] = u.x; 113 | result.fields[1][1] = u.y; 114 | result.fields[2][1] = u.z; 115 | result.fields[0][2] = f.x; 116 | result.fields[1][2] = f.y; 117 | result.fields[2][2] = f.z; 118 | result.fields[3][0] = -Vec3.dot(s, eye); 119 | result.fields[3][1] = -Vec3.dot(u, eye); 120 | result.fields[3][2] = -Vec3.dot(f, eye); 121 | return result; 122 | } 123 | 124 | pub fn createLookAt(eye: Vec3, center: Vec3, up: Vec3) Self { 125 | return createLook(eye, Vec3.sub(eye, center), up); 126 | } 127 | 128 | // taken from GLM implementation 129 | pub fn createPerspective(fov: f32, aspect: f32, near: f32, far: f32) Self { 130 | std.debug.assert(@abs(aspect - 0.001) > 0); 131 | std.debug.assert(far > near); 132 | const tanHalfFov = std.math.tan(fov / 2); 133 | 134 | var result = Self.zero; 135 | result.fields[0][0] = 1.0 / (aspect * tanHalfFov); 136 | result.fields[1][1] = 1.0 / (tanHalfFov); 137 | result.fields[2][2] = -(far + near) / (far - near); 138 | result.fields[2][3] = -1.0; 139 | result.fields[3][2] = -(2.0 * far * near) / (far - near); 140 | return result; 141 | } 142 | 143 | pub fn createAngleAxis(axis: Vec3, angle: f32) Self { 144 | const cos = std.math.cos(angle); 145 | const sin = std.math.sin(angle); 146 | const x = axis.x; 147 | const y = axis.y; 148 | const z = axis.z; 149 | 150 | return Self{ 151 | .fields = [4][4]f32{ 152 | [4]f32{ cos + x * x * (1 - cos), x * y * (1 - cos) - z * sin, x * z * (1 - cos) + y * sin, 0 }, 153 | [4]f32{ y * x * (1 - cos) + z * sin, cos + y * y * (1 - cos), y * z * (1 - cos) - x * sin, 0 }, 154 | [4]f32{ z * x * (1 * cos) - y * sin, z * y * (1 - cos) + x * sin, cos + z * z * (1 - cos), 0 }, 155 | [4]f32{ 0, 0, 0, 1 }, 156 | }, 157 | }; 158 | } 159 | 160 | pub fn createOrthogonal(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) Self { 161 | var result = Self.identity; 162 | result.fields[0][0] = 2 / (right - left); 163 | result.fields[1][1] = 2 / (top - bottom); 164 | result.fields[2][2] = 1 / (far - near); 165 | result.fields[3][0] = -(right + left) / (right - left); 166 | result.fields[3][1] = -(top + bottom) / (top - bottom); 167 | result.fields[3][2] = -near / (far - near); 168 | return result; 169 | } 170 | 171 | pub fn toArray(m: Self) [16]f32 { 172 | var result: [16]f32 = undefined; 173 | var i: usize = 0; 174 | inline for ([_]comptime_int{ 0, 1, 2, 3 }) |col| { 175 | inline for ([_]comptime_int{ 0, 1, 2, 3 }) |row| { 176 | result[i] = m.fields[col][row]; 177 | i += 1; 178 | } 179 | } 180 | return result; 181 | } 182 | }; 183 | -------------------------------------------------------------------------------- /src/shaders/build_shaders.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import subprocess 4 | exe_path = "sokol-shdc.exe" 5 | src_path = "./" 6 | out_path = src_path 7 | 8 | 9 | def main(): 10 | shaders = ["cube","triangle","instancing"] 11 | print("Add to build.zig:") 12 | for shader in shaders: 13 | # Build shaders for all backends 14 | config = " --input " + src_path + shader + ".glsl" +" --output " + out_path + shader +".glsl.h" + " --slang glsl430:metal_macos:hlsl5:glsl300es:wgsl --format sokol_impl" 15 | # Can also just target specific backend 16 | #config = " --input " + src_path + shader + ".glsl" +" --output " + out_path + shader +".glsl.h" + " --slang glsl430 --format sokol_impl" 17 | cmd = exe_path + config 18 | subprocess.check_call(cmd) 19 | cfile = shader + "_compile.c" 20 | with open(cfile, 'w') as filetowrite: 21 | filetowrite.write('#define SOKOL_SHDC_IMPL\n') 22 | filetowrite.write('#include "sokol/sokol_gfx.h"\n') 23 | filetowrite.write('#include "shaders/' + shader + '.glsl.h"\n') 24 | print(' exe.addCSourceFile("src/shaders/' + cfile +'", [_][]const u8{"-std=c99"});') 25 | 26 | if __name__== "__main__": 27 | main() -------------------------------------------------------------------------------- /src/shaders/cube.glsl: -------------------------------------------------------------------------------- 1 | @vs vs 2 | layout(binding=0) uniform vs_params { 3 | mat4 mvp; 4 | }; 5 | 6 | in vec4 position; 7 | in vec4 color0; 8 | 9 | out vec4 color; 10 | 11 | void main() { 12 | gl_Position = mvp * position; 13 | color = color0; 14 | } 15 | @end 16 | 17 | @fs fs 18 | in vec4 color; 19 | out vec4 frag_color; 20 | 21 | void main() { 22 | frag_color = color; 23 | } 24 | @end 25 | 26 | @program cube vs fs 27 | -------------------------------------------------------------------------------- /src/shaders/cube.glsl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | #version:1# (machine generated, don't edit!) 4 | 5 | Generated by sokol-shdc (https://github.com/floooh/sokol-tools) 6 | 7 | Cmdline: 8 | sokol-shdc --input ./cube.glsl --output ./cube.glsl.h --slang glsl430:metal_macos:hlsl5:glsl300es:wgsl --format sokol_impl 9 | 10 | Overview: 11 | ========= 12 | Shader program: 'cube': 13 | Get shader desc: cube_shader_desc(sg_query_backend()); 14 | Vertex Shader: vs 15 | Fragment Shader: fs 16 | Attributes: 17 | ATTR_cube_position => 0 18 | ATTR_cube_color0 => 1 19 | Bindings: 20 | Uniform block 'vs_params': 21 | C struct: vs_params_t 22 | Bind slot: UB_vs_params => 0 23 | */ 24 | #if !defined(SOKOL_GFX_INCLUDED) 25 | #error "Please include sokol_gfx.h before cube.glsl.h" 26 | #endif 27 | #if !defined(SOKOL_SHDC_ALIGN) 28 | #if defined(_MSC_VER) 29 | #define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) 30 | #else 31 | #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) 32 | #endif 33 | #endif 34 | const sg_shader_desc* cube_shader_desc(sg_backend backend); 35 | #define ATTR_cube_position (0) 36 | #define ATTR_cube_color0 (1) 37 | #define UB_vs_params (0) 38 | #pragma pack(push,1) 39 | SOKOL_SHDC_ALIGN(16) typedef struct vs_params_t { 40 | float mvp[16]; 41 | } vs_params_t; 42 | #pragma pack(pop) 43 | #if defined(SOKOL_SHDC_IMPL) 44 | /* 45 | #version 430 46 | 47 | uniform vec4 vs_params[4]; 48 | layout(location = 0) in vec4 position; 49 | layout(location = 0) out vec4 color; 50 | layout(location = 1) in vec4 color0; 51 | 52 | void main() 53 | { 54 | gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; 55 | color = color0; 56 | } 57 | 58 | */ 59 | static const uint8_t vs_source_glsl430[284] = { 60 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 61 | 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 62 | 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 63 | 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 64 | 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, 65 | 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, 66 | 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, 67 | 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, 68 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, 69 | 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, 70 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, 71 | 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, 72 | 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73, 73 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, 74 | 0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, 75 | 0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69, 76 | 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, 77 | 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 78 | }; 79 | /* 80 | #version 430 81 | 82 | layout(location = 0) out vec4 frag_color; 83 | layout(location = 0) in vec4 color; 84 | 85 | void main() 86 | { 87 | frag_color = color; 88 | } 89 | 90 | */ 91 | static const uint8_t fs_source_glsl430[135] = { 92 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 93 | 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 94 | 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, 95 | 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 96 | 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, 97 | 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, 98 | 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 99 | 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 100 | 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 101 | }; 102 | /* 103 | #version 300 es 104 | 105 | uniform vec4 vs_params[4]; 106 | layout(location = 0) in vec4 position; 107 | out vec4 color; 108 | layout(location = 1) in vec4 color0; 109 | 110 | void main() 111 | { 112 | gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; 113 | color = color0; 114 | } 115 | 116 | */ 117 | static const uint8_t vs_source_glsl300es[266] = { 118 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 119 | 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73, 120 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, 121 | 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, 122 | 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, 123 | 0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f, 124 | 0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, 125 | 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, 126 | 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, 127 | 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, 128 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73, 129 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, 130 | 0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, 131 | 0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, 132 | 0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, 133 | 0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f, 134 | 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 135 | }; 136 | /* 137 | #version 300 es 138 | precision mediump float; 139 | precision highp int; 140 | 141 | layout(location = 0) out highp vec4 frag_color; 142 | in highp vec4 color; 143 | 144 | void main() 145 | { 146 | frag_color = color; 147 | } 148 | 149 | */ 150 | static const uint8_t fs_source_glsl300es[175] = { 151 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 152 | 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 153 | 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 154 | 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, 155 | 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 156 | 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, 157 | 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, 158 | 0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, 159 | 0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, 160 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 161 | 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 162 | }; 163 | /* 164 | cbuffer vs_params : register(b0) 165 | { 166 | row_major float4x4 _19_mvp : packoffset(c0); 167 | }; 168 | 169 | 170 | static float4 gl_Position; 171 | static float4 position; 172 | static float4 color; 173 | static float4 color0; 174 | 175 | struct SPIRV_Cross_Input 176 | { 177 | float4 position : TEXCOORD0; 178 | float4 color0 : TEXCOORD1; 179 | }; 180 | 181 | struct SPIRV_Cross_Output 182 | { 183 | float4 color : TEXCOORD0; 184 | float4 gl_Position : SV_Position; 185 | }; 186 | 187 | void vert_main() 188 | { 189 | gl_Position = mul(position, _19_mvp); 190 | color = color0; 191 | } 192 | 193 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 194 | { 195 | position = stage_input.position; 196 | color0 = stage_input.color0; 197 | vert_main(); 198 | SPIRV_Cross_Output stage_output; 199 | stage_output.gl_Position = gl_Position; 200 | stage_output.color = color; 201 | return stage_output; 202 | } 203 | */ 204 | static const uint8_t vs_source_hlsl5[748] = { 205 | 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, 206 | 0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29, 207 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72, 208 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x39,0x5f,0x6d,0x76, 209 | 0x70,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, 210 | 0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, 211 | 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, 212 | 0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, 213 | 0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74, 214 | 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b, 215 | 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, 216 | 0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, 217 | 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, 218 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f, 219 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, 220 | 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, 221 | 0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, 222 | 0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, 223 | 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, 224 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f, 225 | 0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b, 226 | 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, 227 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73, 228 | 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, 229 | 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, 230 | 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 231 | 0x6d,0x75,0x6c,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x5f,0x31, 232 | 0x39,0x5f,0x6d,0x76,0x70,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, 233 | 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, 234 | 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, 235 | 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 236 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, 237 | 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x69, 238 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, 239 | 0x75,0x74,0x2e,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, 240 | 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, 241 | 0x69,0x6e,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20, 242 | 0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20, 243 | 0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, 244 | 0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, 245 | 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, 246 | 0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, 247 | 0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, 248 | 0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, 249 | 0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 250 | 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, 251 | 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, 252 | }; 253 | /* 254 | static float4 frag_color; 255 | static float4 color; 256 | 257 | struct SPIRV_Cross_Input 258 | { 259 | float4 color : TEXCOORD0; 260 | }; 261 | 262 | struct SPIRV_Cross_Output 263 | { 264 | float4 frag_color : SV_Target0; 265 | }; 266 | 267 | void frag_main() 268 | { 269 | frag_color = color; 270 | } 271 | 272 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 273 | { 274 | color = stage_input.color; 275 | frag_main(); 276 | SPIRV_Cross_Output stage_output; 277 | stage_output.frag_color = frag_color; 278 | return stage_output; 279 | } 280 | */ 281 | static const uint8_t fs_source_hlsl5[435] = { 282 | 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, 283 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, 284 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, 285 | 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 286 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 287 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, 288 | 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, 289 | 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, 290 | 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, 291 | 0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a, 292 | 0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a, 293 | 0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, 294 | 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, 295 | 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, 296 | 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, 297 | 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 298 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, 299 | 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, 300 | 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, 301 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, 302 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, 303 | 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, 304 | 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, 305 | 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72, 306 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f, 307 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 308 | 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, 309 | 0x7d,0x0a,0x00, 310 | }; 311 | /* 312 | #include 313 | #include 314 | 315 | using namespace metal; 316 | 317 | struct vs_params 318 | { 319 | float4x4 mvp; 320 | }; 321 | 322 | struct main0_out 323 | { 324 | float4 color [[user(locn0)]]; 325 | float4 gl_Position [[position]]; 326 | }; 327 | 328 | struct main0_in 329 | { 330 | float4 position [[attribute(0)]]; 331 | float4 color0 [[attribute(1)]]; 332 | }; 333 | 334 | vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) 335 | { 336 | main0_out out = {}; 337 | out.gl_Position = _19.mvp * in.position; 338 | out.color = in.color0; 339 | return out; 340 | } 341 | 342 | */ 343 | static const uint8_t vs_source_metal_macos[509] = { 344 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 345 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 346 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 347 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 348 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76, 349 | 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 350 | 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6d,0x76,0x70,0x3b,0x0a,0x7d,0x3b,0x0a, 351 | 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, 352 | 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, 353 | 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, 354 | 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, 355 | 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70, 356 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, 357 | 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, 358 | 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69, 359 | 0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, 360 | 0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, 361 | 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69, 362 | 0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76, 363 | 0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20, 364 | 0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69, 365 | 0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20, 366 | 0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, 367 | 0x6d,0x73,0x26,0x20,0x5f,0x31,0x39,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72, 368 | 0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69, 369 | 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b, 370 | 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, 371 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x31,0x39,0x2e,0x6d,0x76,0x70,0x20,0x2a, 372 | 0x20,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, 373 | 0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e, 374 | 0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, 375 | 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 376 | }; 377 | /* 378 | #include 379 | #include 380 | 381 | using namespace metal; 382 | 383 | struct main0_out 384 | { 385 | float4 frag_color [[color(0)]]; 386 | }; 387 | 388 | struct main0_in 389 | { 390 | float4 color [[user(locn0)]]; 391 | }; 392 | 393 | fragment main0_out main0(main0_in in [[stage_in]]) 394 | { 395 | main0_out out = {}; 396 | out.frag_color = in.color; 397 | return out; 398 | } 399 | 400 | */ 401 | static const uint8_t fs_source_metal_macos[315] = { 402 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 403 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 404 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 405 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 406 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 407 | 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 408 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 409 | 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, 410 | 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, 411 | 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, 412 | 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, 413 | 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d, 414 | 0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, 415 | 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, 416 | 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, 417 | 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, 418 | 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, 419 | 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e, 420 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 421 | 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 422 | }; 423 | /* 424 | diagnostic(off, derivative_uniformity); 425 | 426 | struct vs_params { 427 | /_ @offset(0) _/ 428 | mvp : mat4x4f, 429 | } 430 | 431 | @group(0) @binding(0) var x_19 : vs_params; 432 | 433 | var position_1 : vec4f; 434 | 435 | var color : vec4f; 436 | 437 | var color0 : vec4f; 438 | 439 | var gl_Position : vec4f; 440 | 441 | fn main_1() { 442 | let x_22 : mat4x4f = x_19.mvp; 443 | let x_25 : vec4f = position_1; 444 | gl_Position = (x_22 * x_25); 445 | let x_31 : vec4f = color0; 446 | color = x_31; 447 | return; 448 | } 449 | 450 | struct main_out { 451 | @builtin(position) 452 | gl_Position : vec4f, 453 | @location(0) 454 | color_1 : vec4f, 455 | } 456 | 457 | @vertex 458 | fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { 459 | position_1 = position_1_param; 460 | color0 = color0_param; 461 | main_1(); 462 | return main_out(gl_Position, color); 463 | } 464 | 465 | */ 466 | static const uint8_t vs_source_wgsl[766] = { 467 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 468 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 469 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, 470 | 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x7b,0x0a,0x20,0x20,0x2f,0x2a, 471 | 0x20,0x40,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x30,0x29,0x20,0x2a,0x2f,0x0a,0x20, 472 | 0x20,0x6d,0x76,0x70,0x20,0x3a,0x20,0x6d,0x61,0x74,0x34,0x78,0x34,0x66,0x2c,0x0a, 473 | 0x7d,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x30,0x29,0x20,0x40,0x62,0x69, 474 | 0x6e,0x64,0x69,0x6e,0x67,0x28,0x30,0x29,0x20,0x76,0x61,0x72,0x3c,0x75,0x6e,0x69, 475 | 0x66,0x6f,0x72,0x6d,0x3e,0x20,0x78,0x5f,0x31,0x39,0x20,0x3a,0x20,0x76,0x73,0x5f, 476 | 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 477 | 0x76,0x61,0x74,0x65,0x3e,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31, 478 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, 479 | 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, 480 | 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76, 481 | 0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x76,0x65, 482 | 0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74, 483 | 0x65,0x3e,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, 484 | 0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e, 485 | 0x5f,0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x32, 486 | 0x32,0x20,0x3a,0x20,0x6d,0x61,0x74,0x34,0x78,0x34,0x66,0x20,0x3d,0x20,0x78,0x5f, 487 | 0x31,0x39,0x2e,0x6d,0x76,0x70,0x3b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f, 488 | 0x32,0x35,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x70,0x6f,0x73, 489 | 0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x3b,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, 490 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x28,0x78,0x5f,0x32,0x32,0x20,0x2a, 491 | 0x20,0x78,0x5f,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f, 492 | 0x33,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x63,0x6f,0x6c, 493 | 0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x78, 494 | 0x5f,0x33,0x31,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x7d, 495 | 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75, 496 | 0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x62,0x75,0x69,0x6c,0x74,0x69,0x6e,0x28,0x70, 497 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x29,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, 498 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a, 499 | 0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x0a,0x20, 500 | 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 501 | 0x2c,0x0a,0x7d,0x0a,0x0a,0x40,0x76,0x65,0x72,0x74,0x65,0x78,0x0a,0x66,0x6e,0x20, 502 | 0x6d,0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30, 503 | 0x29,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72, 504 | 0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x20,0x40,0x6c,0x6f,0x63, 505 | 0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x5f, 506 | 0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x29,0x20,0x2d, 507 | 0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x70, 508 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69, 509 | 0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20, 510 | 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x5f, 511 | 0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x31,0x28, 512 | 0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61,0x69,0x6e, 513 | 0x5f,0x6f,0x75,0x74,0x28,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, 514 | 0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 515 | }; 516 | /* 517 | diagnostic(off, derivative_uniformity); 518 | 519 | var frag_color : vec4f; 520 | 521 | var color : vec4f; 522 | 523 | fn main_1() { 524 | let x_12 : vec4f = color; 525 | frag_color = x_12; 526 | return; 527 | } 528 | 529 | struct main_out { 530 | @location(0) 531 | frag_color_1 : vec4f, 532 | } 533 | 534 | @fragment 535 | fn main(@location(0) color_param : vec4f) -> main_out { 536 | color = color_param; 537 | main_1(); 538 | return main_out(frag_color); 539 | } 540 | 541 | */ 542 | static const uint8_t fs_source_wgsl[376] = { 543 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 544 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 545 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 546 | 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 547 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, 548 | 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, 549 | 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, 550 | 0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x32, 551 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, 552 | 0x3b,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 553 | 0x20,0x78,0x5f,0x31,0x32,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, 554 | 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f, 555 | 0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 556 | 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 557 | 0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a, 558 | 0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69, 559 | 0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x63, 560 | 0x6f,0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63, 561 | 0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20, 562 | 0x7b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 563 | 0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f, 564 | 0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61, 565 | 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 566 | 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 567 | }; 568 | const sg_shader_desc* cube_shader_desc(sg_backend backend) { 569 | if (backend == SG_BACKEND_GLCORE) { 570 | static sg_shader_desc desc; 571 | static bool valid; 572 | if (!valid) { 573 | valid = true; 574 | desc.vertex_func.source = (const char*)vs_source_glsl430; 575 | desc.vertex_func.entry = "main"; 576 | desc.fragment_func.source = (const char*)fs_source_glsl430; 577 | desc.fragment_func.entry = "main"; 578 | desc.attrs[0].glsl_name = "position"; 579 | desc.attrs[1].glsl_name = "color0"; 580 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 581 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 582 | desc.uniform_blocks[0].size = 64; 583 | desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; 584 | desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; 585 | desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; 586 | desc.label = "cube_shader"; 587 | } 588 | return &desc; 589 | } 590 | if (backend == SG_BACKEND_GLES3) { 591 | static sg_shader_desc desc; 592 | static bool valid; 593 | if (!valid) { 594 | valid = true; 595 | desc.vertex_func.source = (const char*)vs_source_glsl300es; 596 | desc.vertex_func.entry = "main"; 597 | desc.fragment_func.source = (const char*)fs_source_glsl300es; 598 | desc.fragment_func.entry = "main"; 599 | desc.attrs[0].glsl_name = "position"; 600 | desc.attrs[1].glsl_name = "color0"; 601 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 602 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 603 | desc.uniform_blocks[0].size = 64; 604 | desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; 605 | desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; 606 | desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; 607 | desc.label = "cube_shader"; 608 | } 609 | return &desc; 610 | } 611 | if (backend == SG_BACKEND_D3D11) { 612 | static sg_shader_desc desc; 613 | static bool valid; 614 | if (!valid) { 615 | valid = true; 616 | desc.vertex_func.source = (const char*)vs_source_hlsl5; 617 | desc.vertex_func.d3d11_target = "vs_5_0"; 618 | desc.vertex_func.entry = "main"; 619 | desc.fragment_func.source = (const char*)fs_source_hlsl5; 620 | desc.fragment_func.d3d11_target = "ps_5_0"; 621 | desc.fragment_func.entry = "main"; 622 | desc.attrs[0].hlsl_sem_name = "TEXCOORD"; 623 | desc.attrs[0].hlsl_sem_index = 0; 624 | desc.attrs[1].hlsl_sem_name = "TEXCOORD"; 625 | desc.attrs[1].hlsl_sem_index = 1; 626 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 627 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 628 | desc.uniform_blocks[0].size = 64; 629 | desc.uniform_blocks[0].hlsl_register_b_n = 0; 630 | desc.label = "cube_shader"; 631 | } 632 | return &desc; 633 | } 634 | if (backend == SG_BACKEND_METAL_MACOS) { 635 | static sg_shader_desc desc; 636 | static bool valid; 637 | if (!valid) { 638 | valid = true; 639 | desc.vertex_func.source = (const char*)vs_source_metal_macos; 640 | desc.vertex_func.entry = "main0"; 641 | desc.fragment_func.source = (const char*)fs_source_metal_macos; 642 | desc.fragment_func.entry = "main0"; 643 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 644 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 645 | desc.uniform_blocks[0].size = 64; 646 | desc.uniform_blocks[0].msl_buffer_n = 0; 647 | desc.label = "cube_shader"; 648 | } 649 | return &desc; 650 | } 651 | if (backend == SG_BACKEND_WGPU) { 652 | static sg_shader_desc desc; 653 | static bool valid; 654 | if (!valid) { 655 | valid = true; 656 | desc.vertex_func.source = (const char*)vs_source_wgsl; 657 | desc.vertex_func.entry = "main"; 658 | desc.fragment_func.source = (const char*)fs_source_wgsl; 659 | desc.fragment_func.entry = "main"; 660 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 661 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 662 | desc.uniform_blocks[0].size = 64; 663 | desc.uniform_blocks[0].wgsl_group0_binding_n = 0; 664 | desc.label = "cube_shader"; 665 | } 666 | return &desc; 667 | } 668 | return 0; 669 | } 670 | #endif // SOKOL_SHDC_IMPL -------------------------------------------------------------------------------- /src/shaders/cube_compile.c: -------------------------------------------------------------------------------- 1 | #define SOKOL_SHDC_IMPL 2 | #include "sokol/sokol_gfx.h" 3 | #include "shaders/cube.glsl.h" 4 | -------------------------------------------------------------------------------- /src/shaders/instancing.glsl: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // shaders for instancing-sapp sample 3 | //------------------------------------------------------------------------------ 4 | @vs vs 5 | layout(binding=0) uniform vs_params { 6 | mat4 mvp; 7 | }; 8 | 9 | in vec3 pos; 10 | in vec4 color0; 11 | in vec3 inst_pos; 12 | 13 | out vec4 color; 14 | 15 | void main() { 16 | vec4 pos = vec4(pos + inst_pos, 1.0); 17 | gl_Position = mvp * pos; 18 | color = color0; 19 | } 20 | @end 21 | 22 | @fs fs 23 | in vec4 color; 24 | out vec4 frag_color; 25 | void main() { 26 | frag_color = color; 27 | } 28 | @end 29 | 30 | @program instancing vs fs 31 | 32 | -------------------------------------------------------------------------------- /src/shaders/instancing.glsl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | #version:1# (machine generated, don't edit!) 4 | 5 | Generated by sokol-shdc (https://github.com/floooh/sokol-tools) 6 | 7 | Cmdline: 8 | sokol-shdc --input ./instancing.glsl --output ./instancing.glsl.h --slang glsl430:metal_macos:hlsl5:glsl300es:wgsl --format sokol_impl 9 | 10 | Overview: 11 | ========= 12 | Shader program: 'instancing': 13 | Get shader desc: instancing_shader_desc(sg_query_backend()); 14 | Vertex Shader: vs 15 | Fragment Shader: fs 16 | Attributes: 17 | ATTR_instancing_pos => 0 18 | ATTR_instancing_color0 => 1 19 | ATTR_instancing_inst_pos => 2 20 | Bindings: 21 | Uniform block 'vs_params': 22 | C struct: vs_params_t 23 | Bind slot: UB_vs_params => 0 24 | */ 25 | #if !defined(SOKOL_GFX_INCLUDED) 26 | #error "Please include sokol_gfx.h before instancing.glsl.h" 27 | #endif 28 | #if !defined(SOKOL_SHDC_ALIGN) 29 | #if defined(_MSC_VER) 30 | #define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) 31 | #else 32 | #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) 33 | #endif 34 | #endif 35 | const sg_shader_desc* instancing_shader_desc(sg_backend backend); 36 | #define ATTR_instancing_pos (0) 37 | #define ATTR_instancing_color0 (1) 38 | #define ATTR_instancing_inst_pos (2) 39 | #define UB_vs_params (0) 40 | #pragma pack(push,1) 41 | SOKOL_SHDC_ALIGN(16) typedef struct vs_params_t { 42 | float mvp[16]; 43 | } vs_params_t; 44 | #pragma pack(pop) 45 | #if defined(SOKOL_SHDC_IMPL) 46 | /* 47 | #version 430 48 | 49 | uniform vec4 vs_params[4]; 50 | layout(location = 0) in vec3 pos; 51 | layout(location = 2) in vec3 inst_pos; 52 | layout(location = 0) out vec4 color; 53 | layout(location = 1) in vec4 color0; 54 | 55 | void main() 56 | { 57 | gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); 58 | color = color0; 59 | } 60 | 61 | */ 62 | static const uint8_t vs_source_glsl430[335] = { 63 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 64 | 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 65 | 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 66 | 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 67 | 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, 68 | 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20, 69 | 0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73, 70 | 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 71 | 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20, 72 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, 73 | 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76, 74 | 0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69, 75 | 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67, 76 | 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74, 77 | 0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20, 78 | 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73, 79 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, 80 | 0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34, 81 | 0x28,0x70,0x6f,0x73,0x20,0x2b,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c, 82 | 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72, 83 | 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 84 | }; 85 | /* 86 | #version 430 87 | 88 | layout(location = 0) out vec4 frag_color; 89 | layout(location = 0) in vec4 color; 90 | 91 | void main() 92 | { 93 | frag_color = color; 94 | } 95 | 96 | */ 97 | static const uint8_t fs_source_glsl430[135] = { 98 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 99 | 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 100 | 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, 101 | 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 102 | 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, 103 | 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, 104 | 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 105 | 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 106 | 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 107 | }; 108 | /* 109 | #version 300 es 110 | 111 | uniform vec4 vs_params[4]; 112 | layout(location = 0) in vec3 pos; 113 | layout(location = 2) in vec3 inst_pos; 114 | out vec4 color; 115 | layout(location = 1) in vec4 color0; 116 | 117 | void main() 118 | { 119 | gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); 120 | color = color0; 121 | } 122 | 123 | */ 124 | static const uint8_t vs_source_glsl300es[317] = { 125 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 126 | 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73, 127 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, 128 | 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, 129 | 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61, 130 | 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 131 | 0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x73,0x74,0x5f, 132 | 0x70,0x6f,0x73,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, 133 | 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, 134 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, 135 | 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, 136 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, 137 | 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, 138 | 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73, 139 | 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, 140 | 0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, 141 | 0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x70, 142 | 0x6f,0x73,0x20,0x2b,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, 143 | 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 144 | 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 145 | }; 146 | /* 147 | #version 300 es 148 | precision mediump float; 149 | precision highp int; 150 | 151 | layout(location = 0) out highp vec4 frag_color; 152 | in highp vec4 color; 153 | 154 | void main() 155 | { 156 | frag_color = color; 157 | } 158 | 159 | */ 160 | static const uint8_t fs_source_glsl300es[175] = { 161 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 162 | 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 163 | 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 164 | 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, 165 | 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 166 | 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, 167 | 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, 168 | 0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, 169 | 0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, 170 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 171 | 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 172 | }; 173 | /* 174 | cbuffer vs_params : register(b0) 175 | { 176 | row_major float4x4 _33_mvp : packoffset(c0); 177 | }; 178 | 179 | 180 | static float4 gl_Position; 181 | static float3 pos; 182 | static float3 inst_pos; 183 | static float4 color; 184 | static float4 color0; 185 | 186 | struct SPIRV_Cross_Input 187 | { 188 | float3 pos : TEXCOORD0; 189 | float4 color0 : TEXCOORD1; 190 | float3 inst_pos : TEXCOORD2; 191 | }; 192 | 193 | struct SPIRV_Cross_Output 194 | { 195 | float4 color : TEXCOORD0; 196 | float4 gl_Position : SV_Position; 197 | }; 198 | 199 | void vert_main() 200 | { 201 | gl_Position = mul(float4(pos + inst_pos, 1.0f), _33_mvp); 202 | color = color0; 203 | } 204 | 205 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 206 | { 207 | pos = stage_input.pos; 208 | inst_pos = stage_input.inst_pos; 209 | color0 = stage_input.color0; 210 | vert_main(); 211 | SPIRV_Cross_Output stage_output; 212 | stage_output.gl_Position = gl_Position; 213 | stage_output.color = color; 214 | return stage_output; 215 | } 216 | */ 217 | static const uint8_t vs_source_hlsl5[842] = { 218 | 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, 219 | 0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29, 220 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72, 221 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x33,0x33,0x5f,0x6d,0x76, 222 | 0x70,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, 223 | 0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, 224 | 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, 225 | 0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, 226 | 0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, 227 | 0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73, 228 | 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c, 229 | 0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, 230 | 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, 231 | 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, 232 | 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, 233 | 0x20,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30, 234 | 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c, 235 | 0x6f,0x72,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b, 236 | 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x73,0x74, 237 | 0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32, 238 | 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, 239 | 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a, 240 | 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c, 241 | 0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a, 242 | 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, 243 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69, 244 | 0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76, 245 | 0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, 246 | 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d, 247 | 0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x70,0x6f,0x73,0x20,0x2b,0x20, 248 | 0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c, 249 | 0x20,0x5f,0x33,0x33,0x5f,0x6d,0x76,0x70,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63, 250 | 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d, 251 | 0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, 252 | 0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, 253 | 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67, 254 | 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70, 255 | 0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, 256 | 0x2e,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70, 257 | 0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, 258 | 0x2e,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63, 259 | 0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, 260 | 0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, 261 | 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20, 262 | 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, 263 | 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, 264 | 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, 265 | 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, 266 | 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20, 267 | 0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63, 268 | 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, 269 | 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, 270 | 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, 271 | }; 272 | /* 273 | static float4 frag_color; 274 | static float4 color; 275 | 276 | struct SPIRV_Cross_Input 277 | { 278 | float4 color : TEXCOORD0; 279 | }; 280 | 281 | struct SPIRV_Cross_Output 282 | { 283 | float4 frag_color : SV_Target0; 284 | }; 285 | 286 | void frag_main() 287 | { 288 | frag_color = color; 289 | } 290 | 291 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 292 | { 293 | color = stage_input.color; 294 | frag_main(); 295 | SPIRV_Cross_Output stage_output; 296 | stage_output.frag_color = frag_color; 297 | return stage_output; 298 | } 299 | */ 300 | static const uint8_t fs_source_hlsl5[435] = { 301 | 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, 302 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, 303 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, 304 | 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 305 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 306 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, 307 | 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, 308 | 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, 309 | 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, 310 | 0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a, 311 | 0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a, 312 | 0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, 313 | 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, 314 | 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, 315 | 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, 316 | 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 317 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, 318 | 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, 319 | 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, 320 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, 321 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, 322 | 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, 323 | 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, 324 | 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72, 325 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f, 326 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 327 | 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, 328 | 0x7d,0x0a,0x00, 329 | }; 330 | /* 331 | #include 332 | #include 333 | 334 | using namespace metal; 335 | 336 | struct vs_params 337 | { 338 | float4x4 mvp; 339 | }; 340 | 341 | struct main0_out 342 | { 343 | float4 color [[user(locn0)]]; 344 | float4 gl_Position [[position]]; 345 | }; 346 | 347 | struct main0_in 348 | { 349 | float3 pos [[attribute(0)]]; 350 | float4 color0 [[attribute(1)]]; 351 | float3 inst_pos [[attribute(2)]]; 352 | }; 353 | 354 | vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _33 [[buffer(0)]]) 355 | { 356 | main0_out out = {}; 357 | out.gl_Position = _33.mvp * float4(in.pos + in.inst_pos, 1.0); 358 | out.color = in.color0; 359 | return out; 360 | } 361 | 362 | */ 363 | static const uint8_t vs_source_metal_macos[564] = { 364 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 365 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 366 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 367 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 368 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76, 369 | 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 370 | 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6d,0x76,0x70,0x3b,0x0a,0x7d,0x3b,0x0a, 371 | 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, 372 | 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, 373 | 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, 374 | 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, 375 | 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70, 376 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, 377 | 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, 378 | 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x6f,0x73,0x20, 379 | 0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d, 380 | 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c, 381 | 0x6f,0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28, 382 | 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, 383 | 0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72, 384 | 0x69,0x62,0x75,0x74,0x65,0x28,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, 385 | 0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, 386 | 0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20, 387 | 0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c, 388 | 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, 389 | 0x61,0x6d,0x73,0x26,0x20,0x5f,0x33,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, 390 | 0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61, 391 | 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d, 392 | 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73, 393 | 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x76,0x70,0x20, 394 | 0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x20, 395 | 0x2b,0x20,0x69,0x6e,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, 396 | 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c, 397 | 0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a, 398 | 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, 399 | 0x7d,0x0a,0x0a,0x00, 400 | }; 401 | /* 402 | #include 403 | #include 404 | 405 | using namespace metal; 406 | 407 | struct main0_out 408 | { 409 | float4 frag_color [[color(0)]]; 410 | }; 411 | 412 | struct main0_in 413 | { 414 | float4 color [[user(locn0)]]; 415 | }; 416 | 417 | fragment main0_out main0(main0_in in [[stage_in]]) 418 | { 419 | main0_out out = {}; 420 | out.frag_color = in.color; 421 | return out; 422 | } 423 | 424 | */ 425 | static const uint8_t fs_source_metal_macos[315] = { 426 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 427 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 428 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 429 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 430 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 431 | 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 432 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 433 | 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, 434 | 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, 435 | 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, 436 | 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, 437 | 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d, 438 | 0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, 439 | 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, 440 | 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, 441 | 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, 442 | 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, 443 | 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e, 444 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 445 | 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 446 | }; 447 | /* 448 | diagnostic(off, derivative_uniformity); 449 | 450 | struct vs_params { 451 | /_ @offset(0) _/ 452 | mvp : mat4x4f, 453 | } 454 | 455 | var pos_1 : vec3f; 456 | 457 | var inst_pos : vec3f; 458 | 459 | @group(0) @binding(0) var x_33 : vs_params; 460 | 461 | var color : vec4f; 462 | 463 | var color0 : vec4f; 464 | 465 | var gl_Position : vec4f; 466 | 467 | fn main_1() { 468 | var pos : vec4f; 469 | let x_13 : vec3f = pos_1; 470 | let x_15 : vec3f = inst_pos; 471 | let x_16 : vec3f = (x_13 + x_15); 472 | pos = vec4f(x_16.x, x_16.y, x_16.z, 1.0f); 473 | let x_36 : mat4x4f = x_33.mvp; 474 | let x_37 : vec4f = pos; 475 | gl_Position = (x_36 * x_37); 476 | let x_44 : vec4f = color0; 477 | color = x_44; 478 | return; 479 | } 480 | 481 | struct main_out { 482 | @builtin(position) 483 | gl_Position : vec4f, 484 | @location(0) 485 | color_1 : vec4f, 486 | } 487 | 488 | @vertex 489 | fn main(@location(0) pos_1_param : vec3f, @location(2) inst_pos_param : vec3f, @location(1) color0_param : vec4f) -> main_out { 490 | pos_1 = pos_1_param; 491 | inst_pos = inst_pos_param; 492 | color0 = color0_param; 493 | main_1(); 494 | return main_out(gl_Position, color); 495 | } 496 | 497 | */ 498 | static const uint8_t vs_source_wgsl[996] = { 499 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 500 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 501 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, 502 | 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x7b,0x0a,0x20,0x20,0x2f,0x2a, 503 | 0x20,0x40,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x30,0x29,0x20,0x2a,0x2f,0x0a,0x20, 504 | 0x20,0x6d,0x76,0x70,0x20,0x3a,0x20,0x6d,0x61,0x74,0x34,0x78,0x34,0x66,0x2c,0x0a, 505 | 0x7d,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20, 506 | 0x70,0x6f,0x73,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x66,0x3b,0x0a,0x0a, 507 | 0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x69,0x6e,0x73, 508 | 0x74,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x66,0x3b,0x0a,0x0a, 509 | 0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x30,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69, 510 | 0x6e,0x67,0x28,0x30,0x29,0x20,0x76,0x61,0x72,0x3c,0x75,0x6e,0x69,0x66,0x6f,0x72, 511 | 0x6d,0x3e,0x20,0x78,0x5f,0x33,0x33,0x20,0x3a,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, 512 | 0x61,0x6d,0x73,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74, 513 | 0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 514 | 0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20, 515 | 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a, 516 | 0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x67,0x6c, 517 | 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x76,0x65,0x63,0x34, 518 | 0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x20, 519 | 0x7b,0x0a,0x20,0x20,0x76,0x61,0x72,0x20,0x70,0x6f,0x73,0x20,0x3a,0x20,0x76,0x65, 520 | 0x63,0x34,0x66,0x3b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x33,0x20, 521 | 0x3a,0x20,0x76,0x65,0x63,0x33,0x66,0x20,0x3d,0x20,0x70,0x6f,0x73,0x5f,0x31,0x3b, 522 | 0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x35,0x20,0x3a,0x20,0x76,0x65, 523 | 0x63,0x33,0x66,0x20,0x3d,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x3b,0x0a, 524 | 0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x36,0x20,0x3a,0x20,0x76,0x65,0x63, 525 | 0x33,0x66,0x20,0x3d,0x20,0x28,0x78,0x5f,0x31,0x33,0x20,0x2b,0x20,0x78,0x5f,0x31, 526 | 0x35,0x29,0x3b,0x0a,0x20,0x20,0x70,0x6f,0x73,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, 527 | 0x66,0x28,0x78,0x5f,0x31,0x36,0x2e,0x78,0x2c,0x20,0x78,0x5f,0x31,0x36,0x2e,0x79, 528 | 0x2c,0x20,0x78,0x5f,0x31,0x36,0x2e,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, 529 | 0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x33,0x36,0x20,0x3a,0x20,0x6d,0x61, 530 | 0x74,0x34,0x78,0x34,0x66,0x20,0x3d,0x20,0x78,0x5f,0x33,0x33,0x2e,0x6d,0x76,0x70, 531 | 0x3b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x33,0x37,0x20,0x3a,0x20,0x76, 532 | 0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x67,0x6c, 533 | 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x28,0x78,0x5f,0x33, 534 | 0x36,0x20,0x2a,0x20,0x78,0x5f,0x33,0x37,0x29,0x3b,0x0a,0x20,0x20,0x6c,0x65,0x74, 535 | 0x20,0x78,0x5f,0x34,0x34,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20, 536 | 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20, 537 | 0x3d,0x20,0x78,0x5f,0x34,0x34,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, 538 | 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, 539 | 0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x62,0x75,0x69,0x6c,0x74,0x69, 540 | 0x6e,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x29,0x0a,0x20,0x20,0x67,0x6c, 541 | 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x76,0x65,0x63,0x34, 542 | 0x66,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30, 543 | 0x29,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65, 544 | 0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a,0x40,0x76,0x65,0x72,0x74,0x65,0x78,0x0a, 545 | 0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 546 | 0x6e,0x28,0x30,0x29,0x20,0x70,0x6f,0x73,0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d, 547 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x66,0x2c,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74, 548 | 0x69,0x6f,0x6e,0x28,0x32,0x29,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x5f, 549 | 0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x33,0x66,0x2c,0x20,0x40, 550 | 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x20,0x63,0x6f,0x6c,0x6f, 551 | 0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 552 | 0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a, 553 | 0x20,0x20,0x70,0x6f,0x73,0x5f,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x5f,0x31,0x5f, 554 | 0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f, 555 | 0x73,0x20,0x3d,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x61,0x72, 556 | 0x61,0x6d,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x63, 557 | 0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d, 558 | 0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 559 | 0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x67,0x6c,0x5f,0x50,0x6f, 560 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a, 561 | 0x7d,0x0a,0x0a,0x00, 562 | }; 563 | /* 564 | diagnostic(off, derivative_uniformity); 565 | 566 | var frag_color : vec4f; 567 | 568 | var color : vec4f; 569 | 570 | fn main_1() { 571 | let x_12 : vec4f = color; 572 | frag_color = x_12; 573 | return; 574 | } 575 | 576 | struct main_out { 577 | @location(0) 578 | frag_color_1 : vec4f, 579 | } 580 | 581 | @fragment 582 | fn main(@location(0) color_param : vec4f) -> main_out { 583 | color = color_param; 584 | main_1(); 585 | return main_out(frag_color); 586 | } 587 | 588 | */ 589 | static const uint8_t fs_source_wgsl[376] = { 590 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 591 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 592 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 593 | 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 594 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, 595 | 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, 596 | 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, 597 | 0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x32, 598 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, 599 | 0x3b,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 600 | 0x20,0x78,0x5f,0x31,0x32,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, 601 | 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f, 602 | 0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 603 | 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 604 | 0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a, 605 | 0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69, 606 | 0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x63, 607 | 0x6f,0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63, 608 | 0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20, 609 | 0x7b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 610 | 0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f, 611 | 0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61, 612 | 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 613 | 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 614 | }; 615 | const sg_shader_desc* instancing_shader_desc(sg_backend backend) { 616 | if (backend == SG_BACKEND_GLCORE) { 617 | static sg_shader_desc desc; 618 | static bool valid; 619 | if (!valid) { 620 | valid = true; 621 | desc.vertex_func.source = (const char*)vs_source_glsl430; 622 | desc.vertex_func.entry = "main"; 623 | desc.fragment_func.source = (const char*)fs_source_glsl430; 624 | desc.fragment_func.entry = "main"; 625 | desc.attrs[0].glsl_name = "pos"; 626 | desc.attrs[1].glsl_name = "color0"; 627 | desc.attrs[2].glsl_name = "inst_pos"; 628 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 629 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 630 | desc.uniform_blocks[0].size = 64; 631 | desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; 632 | desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; 633 | desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; 634 | desc.label = "instancing_shader"; 635 | } 636 | return &desc; 637 | } 638 | if (backend == SG_BACKEND_GLES3) { 639 | static sg_shader_desc desc; 640 | static bool valid; 641 | if (!valid) { 642 | valid = true; 643 | desc.vertex_func.source = (const char*)vs_source_glsl300es; 644 | desc.vertex_func.entry = "main"; 645 | desc.fragment_func.source = (const char*)fs_source_glsl300es; 646 | desc.fragment_func.entry = "main"; 647 | desc.attrs[0].glsl_name = "pos"; 648 | desc.attrs[1].glsl_name = "color0"; 649 | desc.attrs[2].glsl_name = "inst_pos"; 650 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 651 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 652 | desc.uniform_blocks[0].size = 64; 653 | desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; 654 | desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; 655 | desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; 656 | desc.label = "instancing_shader"; 657 | } 658 | return &desc; 659 | } 660 | if (backend == SG_BACKEND_D3D11) { 661 | static sg_shader_desc desc; 662 | static bool valid; 663 | if (!valid) { 664 | valid = true; 665 | desc.vertex_func.source = (const char*)vs_source_hlsl5; 666 | desc.vertex_func.d3d11_target = "vs_5_0"; 667 | desc.vertex_func.entry = "main"; 668 | desc.fragment_func.source = (const char*)fs_source_hlsl5; 669 | desc.fragment_func.d3d11_target = "ps_5_0"; 670 | desc.fragment_func.entry = "main"; 671 | desc.attrs[0].hlsl_sem_name = "TEXCOORD"; 672 | desc.attrs[0].hlsl_sem_index = 0; 673 | desc.attrs[1].hlsl_sem_name = "TEXCOORD"; 674 | desc.attrs[1].hlsl_sem_index = 1; 675 | desc.attrs[2].hlsl_sem_name = "TEXCOORD"; 676 | desc.attrs[2].hlsl_sem_index = 2; 677 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 678 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 679 | desc.uniform_blocks[0].size = 64; 680 | desc.uniform_blocks[0].hlsl_register_b_n = 0; 681 | desc.label = "instancing_shader"; 682 | } 683 | return &desc; 684 | } 685 | if (backend == SG_BACKEND_METAL_MACOS) { 686 | static sg_shader_desc desc; 687 | static bool valid; 688 | if (!valid) { 689 | valid = true; 690 | desc.vertex_func.source = (const char*)vs_source_metal_macos; 691 | desc.vertex_func.entry = "main0"; 692 | desc.fragment_func.source = (const char*)fs_source_metal_macos; 693 | desc.fragment_func.entry = "main0"; 694 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 695 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 696 | desc.uniform_blocks[0].size = 64; 697 | desc.uniform_blocks[0].msl_buffer_n = 0; 698 | desc.label = "instancing_shader"; 699 | } 700 | return &desc; 701 | } 702 | if (backend == SG_BACKEND_WGPU) { 703 | static sg_shader_desc desc; 704 | static bool valid; 705 | if (!valid) { 706 | valid = true; 707 | desc.vertex_func.source = (const char*)vs_source_wgsl; 708 | desc.vertex_func.entry = "main"; 709 | desc.fragment_func.source = (const char*)fs_source_wgsl; 710 | desc.fragment_func.entry = "main"; 711 | desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; 712 | desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; 713 | desc.uniform_blocks[0].size = 64; 714 | desc.uniform_blocks[0].wgsl_group0_binding_n = 0; 715 | desc.label = "instancing_shader"; 716 | } 717 | return &desc; 718 | } 719 | return 0; 720 | } 721 | #endif // SOKOL_SHDC_IMPL -------------------------------------------------------------------------------- /src/shaders/instancing_compile.c: -------------------------------------------------------------------------------- 1 | #define SOKOL_SHDC_IMPL 2 | #include "sokol/sokol_gfx.h" 3 | #include "shaders/instancing.glsl.h" 4 | -------------------------------------------------------------------------------- /src/shaders/triangle.glsl: -------------------------------------------------------------------------------- 1 | @vs vs 2 | in vec4 position; 3 | in vec4 color0; 4 | out vec4 color; 5 | void main() { 6 | gl_Position = position; 7 | color = color0; 8 | } 9 | @end 10 | 11 | @fs fs 12 | in vec4 color; 13 | out vec4 frag_color; 14 | void main() { 15 | frag_color = color; 16 | } 17 | @end 18 | 19 | @program triangle vs fs -------------------------------------------------------------------------------- /src/shaders/triangle.glsl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | #version:1# (machine generated, don't edit!) 4 | 5 | Generated by sokol-shdc (https://github.com/floooh/sokol-tools) 6 | 7 | Cmdline: 8 | sokol-shdc --input ./triangle.glsl --output ./triangle.glsl.h --slang glsl430:metal_macos:hlsl5:glsl300es:wgsl --format sokol_impl 9 | 10 | Overview: 11 | ========= 12 | Shader program: 'triangle': 13 | Get shader desc: triangle_shader_desc(sg_query_backend()); 14 | Vertex Shader: vs 15 | Fragment Shader: fs 16 | Attributes: 17 | ATTR_triangle_position => 0 18 | ATTR_triangle_color0 => 1 19 | Bindings: 20 | */ 21 | #if !defined(SOKOL_GFX_INCLUDED) 22 | #error "Please include sokol_gfx.h before triangle.glsl.h" 23 | #endif 24 | #if !defined(SOKOL_SHDC_ALIGN) 25 | #if defined(_MSC_VER) 26 | #define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) 27 | #else 28 | #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) 29 | #endif 30 | #endif 31 | const sg_shader_desc* triangle_shader_desc(sg_backend backend); 32 | #define ATTR_triangle_position (0) 33 | #define ATTR_triangle_color0 (1) 34 | #if defined(SOKOL_SHDC_IMPL) 35 | /* 36 | #version 430 37 | 38 | layout(location = 0) in vec4 position; 39 | layout(location = 0) out vec4 color; 40 | layout(location = 1) in vec4 color0; 41 | 42 | void main() 43 | { 44 | gl_Position = position; 45 | color = color0; 46 | } 47 | 48 | */ 49 | static const uint8_t vs_source_glsl430[194] = { 50 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 51 | 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 52 | 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, 53 | 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, 54 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, 55 | 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 56 | 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, 57 | 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, 58 | 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, 59 | 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 60 | 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, 61 | 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a, 62 | 0x0a,0x00, 63 | }; 64 | /* 65 | #version 430 66 | 67 | layout(location = 0) out vec4 frag_color; 68 | layout(location = 0) in vec4 color; 69 | 70 | void main() 71 | { 72 | frag_color = color; 73 | } 74 | 75 | */ 76 | static const uint8_t fs_source_glsl430[135] = { 77 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 78 | 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 79 | 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, 80 | 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 81 | 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, 82 | 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, 83 | 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 84 | 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 85 | 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 86 | }; 87 | /* 88 | #version 300 es 89 | 90 | layout(location = 0) in vec4 position; 91 | out vec4 color; 92 | layout(location = 1) in vec4 color0; 93 | 94 | void main() 95 | { 96 | gl_Position = position; 97 | color = color0; 98 | } 99 | 100 | */ 101 | static const uint8_t vs_source_glsl300es[176] = { 102 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 103 | 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, 104 | 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f, 105 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, 106 | 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 107 | 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20, 108 | 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f, 109 | 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, 110 | 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f, 111 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, 112 | 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 113 | 114 | }; 115 | /* 116 | #version 300 es 117 | precision mediump float; 118 | precision highp int; 119 | 120 | layout(location = 0) out highp vec4 frag_color; 121 | in highp vec4 color; 122 | 123 | void main() 124 | { 125 | frag_color = color; 126 | } 127 | 128 | */ 129 | static const uint8_t fs_source_glsl300es[175] = { 130 | 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 131 | 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 132 | 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 133 | 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, 134 | 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 135 | 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, 136 | 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, 137 | 0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, 138 | 0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, 139 | 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 140 | 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 141 | }; 142 | /* 143 | static float4 gl_Position; 144 | static float4 position; 145 | static float4 color; 146 | static float4 color0; 147 | 148 | struct SPIRV_Cross_Input 149 | { 150 | float4 position : TEXCOORD0; 151 | float4 color0 : TEXCOORD1; 152 | }; 153 | 154 | struct SPIRV_Cross_Output 155 | { 156 | float4 color : TEXCOORD0; 157 | float4 gl_Position : SV_Position; 158 | }; 159 | 160 | void vert_main() 161 | { 162 | gl_Position = position; 163 | color = color0; 164 | } 165 | 166 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 167 | { 168 | position = stage_input.position; 169 | color0 = stage_input.color0; 170 | vert_main(); 171 | SPIRV_Cross_Output stage_output; 172 | stage_output.gl_Position = gl_Position; 173 | stage_output.color = color; 174 | return stage_output; 175 | } 176 | */ 177 | static const uint8_t vs_source_hlsl5[645] = { 178 | 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, 179 | 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, 180 | 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, 181 | 0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, 182 | 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, 183 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x73, 184 | 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, 185 | 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, 186 | 0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20, 187 | 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, 188 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x54, 189 | 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, 190 | 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, 191 | 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, 192 | 0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, 193 | 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, 194 | 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, 195 | 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, 196 | 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, 197 | 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, 198 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, 199 | 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, 200 | 0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, 201 | 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28, 202 | 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, 203 | 0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b, 204 | 0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 205 | 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x70,0x6f,0x73,0x69, 206 | 0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30, 207 | 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x63, 208 | 0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f, 209 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, 210 | 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, 211 | 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, 212 | 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c, 213 | 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50, 214 | 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, 215 | 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20, 216 | 0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, 217 | 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, 218 | 0x3b,0x0a,0x7d,0x0a,0x00, 219 | }; 220 | /* 221 | static float4 frag_color; 222 | static float4 color; 223 | 224 | struct SPIRV_Cross_Input 225 | { 226 | float4 color : TEXCOORD0; 227 | }; 228 | 229 | struct SPIRV_Cross_Output 230 | { 231 | float4 frag_color : SV_Target0; 232 | }; 233 | 234 | void frag_main() 235 | { 236 | frag_color = color; 237 | } 238 | 239 | SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) 240 | { 241 | color = stage_input.color; 242 | frag_main(); 243 | SPIRV_Cross_Output stage_output; 244 | stage_output.frag_color = frag_color; 245 | return stage_output; 246 | } 247 | */ 248 | static const uint8_t fs_source_hlsl5[435] = { 249 | 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, 250 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, 251 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, 252 | 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 253 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 254 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, 255 | 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, 256 | 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, 257 | 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, 258 | 0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a, 259 | 0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a, 260 | 0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, 261 | 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, 262 | 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, 263 | 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, 264 | 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, 265 | 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, 266 | 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, 267 | 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, 268 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, 269 | 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, 270 | 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, 271 | 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, 272 | 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72, 273 | 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f, 274 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 275 | 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, 276 | 0x7d,0x0a,0x00, 277 | }; 278 | /* 279 | #include 280 | #include 281 | 282 | using namespace metal; 283 | 284 | struct main0_out 285 | { 286 | float4 color [[user(locn0)]]; 287 | float4 gl_Position [[position]]; 288 | }; 289 | 290 | struct main0_in 291 | { 292 | float4 position [[attribute(0)]]; 293 | float4 color0 [[attribute(1)]]; 294 | }; 295 | 296 | vertex main0_out main0(main0_in in [[stage_in]]) 297 | { 298 | main0_out out = {}; 299 | out.gl_Position = in.position; 300 | out.color = in.color0; 301 | return out; 302 | } 303 | 304 | */ 305 | static const uint8_t vs_source_metal_macos[419] = { 306 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 307 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 308 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 309 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 310 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 311 | 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 312 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, 313 | 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, 314 | 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, 315 | 0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d, 316 | 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, 317 | 0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, 318 | 0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x61,0x74, 319 | 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, 320 | 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20, 321 | 0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d, 322 | 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69, 323 | 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, 324 | 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, 325 | 0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69, 326 | 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b, 327 | 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, 328 | 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x69,0x74,0x69, 329 | 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f, 330 | 0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20, 331 | 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d, 332 | 0x0a,0x0a,0x00, 333 | }; 334 | /* 335 | #include 336 | #include 337 | 338 | using namespace metal; 339 | 340 | struct main0_out 341 | { 342 | float4 frag_color [[color(0)]]; 343 | }; 344 | 345 | struct main0_in 346 | { 347 | float4 color [[user(locn0)]]; 348 | }; 349 | 350 | fragment main0_out main0(main0_in in [[stage_in]]) 351 | { 352 | main0_out out = {}; 353 | out.frag_color = in.color; 354 | return out; 355 | } 356 | 357 | */ 358 | static const uint8_t fs_source_metal_macos[315] = { 359 | 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 360 | 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 361 | 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 362 | 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 363 | 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 364 | 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 365 | 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 366 | 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, 367 | 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, 368 | 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, 369 | 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, 370 | 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d, 371 | 0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, 372 | 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, 373 | 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, 374 | 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, 375 | 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, 376 | 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e, 377 | 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 378 | 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 379 | }; 380 | /* 381 | diagnostic(off, derivative_uniformity); 382 | 383 | var position_1 : vec4f; 384 | 385 | var color : vec4f; 386 | 387 | var color0 : vec4f; 388 | 389 | var gl_Position : vec4f; 390 | 391 | fn main_1() { 392 | let x_18 : vec4f = position_1; 393 | gl_Position = x_18; 394 | let x_23 : vec4f = color0; 395 | color = x_23; 396 | return; 397 | } 398 | 399 | struct main_out { 400 | @builtin(position) 401 | gl_Position : vec4f, 402 | @location(0) 403 | color_1 : vec4f, 404 | } 405 | 406 | @vertex 407 | fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { 408 | position_1 = position_1_param; 409 | color0 = color0_param; 410 | main_1(); 411 | return main_out(gl_Position, color); 412 | } 413 | 414 | */ 415 | static const uint8_t vs_source_wgsl[612] = { 416 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 417 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 418 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 419 | 0x76,0x61,0x74,0x65,0x3e,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31, 420 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, 421 | 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, 422 | 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76, 423 | 0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x76,0x65, 424 | 0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74, 425 | 0x65,0x3e,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, 426 | 0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e, 427 | 0x5f,0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31, 428 | 0x38,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69, 429 | 0x74,0x69,0x6f,0x6e,0x5f,0x31,0x3b,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, 430 | 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x78,0x5f,0x31,0x38,0x3b,0x0a,0x20,0x20, 431 | 0x6c,0x65,0x74,0x20,0x78,0x5f,0x32,0x33,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 432 | 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c, 433 | 0x6f,0x72,0x20,0x3d,0x20,0x78,0x5f,0x32,0x33,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74, 434 | 0x75,0x72,0x6e,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 435 | 0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x62,0x75,0x69, 436 | 0x6c,0x74,0x69,0x6e,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x29,0x0a,0x20, 437 | 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x76, 438 | 0x65,0x63,0x34,0x66,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 439 | 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a, 440 | 0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a,0x40,0x76,0x65,0x72,0x74, 441 | 0x65,0x78,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61, 442 | 0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, 443 | 0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 444 | 0x2c,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x20,0x63, 445 | 0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65, 446 | 0x63,0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74, 447 | 0x20,0x7b,0x0a,0x20,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x20, 448 | 0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72, 449 | 0x61,0x6d,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x63, 450 | 0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d, 451 | 0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72, 452 | 0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x67,0x6c,0x5f,0x50,0x6f, 453 | 0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a, 454 | 0x7d,0x0a,0x0a,0x00, 455 | }; 456 | /* 457 | diagnostic(off, derivative_uniformity); 458 | 459 | var frag_color : vec4f; 460 | 461 | var color : vec4f; 462 | 463 | fn main_1() { 464 | let x_12 : vec4f = color; 465 | frag_color = x_12; 466 | return; 467 | } 468 | 469 | struct main_out { 470 | @location(0) 471 | frag_color_1 : vec4f, 472 | } 473 | 474 | @fragment 475 | fn main(@location(0) color_param : vec4f) -> main_out { 476 | color = color_param; 477 | main_1(); 478 | return main_out(frag_color); 479 | } 480 | 481 | */ 482 | static const uint8_t fs_source_wgsl[376] = { 483 | 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 484 | 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 485 | 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 486 | 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 487 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, 488 | 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, 489 | 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, 490 | 0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x32, 491 | 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, 492 | 0x3b,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 493 | 0x20,0x78,0x5f,0x31,0x32,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, 494 | 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f, 495 | 0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 496 | 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 497 | 0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a, 498 | 0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69, 499 | 0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x63, 500 | 0x6f,0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63, 501 | 0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20, 502 | 0x7b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 503 | 0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f, 504 | 0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61, 505 | 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 506 | 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 507 | }; 508 | const sg_shader_desc* triangle_shader_desc(sg_backend backend) { 509 | if (backend == SG_BACKEND_GLCORE) { 510 | static sg_shader_desc desc; 511 | static bool valid; 512 | if (!valid) { 513 | valid = true; 514 | desc.vertex_func.source = (const char*)vs_source_glsl430; 515 | desc.vertex_func.entry = "main"; 516 | desc.fragment_func.source = (const char*)fs_source_glsl430; 517 | desc.fragment_func.entry = "main"; 518 | desc.attrs[0].glsl_name = "position"; 519 | desc.attrs[1].glsl_name = "color0"; 520 | desc.label = "triangle_shader"; 521 | } 522 | return &desc; 523 | } 524 | if (backend == SG_BACKEND_GLES3) { 525 | static sg_shader_desc desc; 526 | static bool valid; 527 | if (!valid) { 528 | valid = true; 529 | desc.vertex_func.source = (const char*)vs_source_glsl300es; 530 | desc.vertex_func.entry = "main"; 531 | desc.fragment_func.source = (const char*)fs_source_glsl300es; 532 | desc.fragment_func.entry = "main"; 533 | desc.attrs[0].glsl_name = "position"; 534 | desc.attrs[1].glsl_name = "color0"; 535 | desc.label = "triangle_shader"; 536 | } 537 | return &desc; 538 | } 539 | if (backend == SG_BACKEND_D3D11) { 540 | static sg_shader_desc desc; 541 | static bool valid; 542 | if (!valid) { 543 | valid = true; 544 | desc.vertex_func.source = (const char*)vs_source_hlsl5; 545 | desc.vertex_func.d3d11_target = "vs_5_0"; 546 | desc.vertex_func.entry = "main"; 547 | desc.fragment_func.source = (const char*)fs_source_hlsl5; 548 | desc.fragment_func.d3d11_target = "ps_5_0"; 549 | desc.fragment_func.entry = "main"; 550 | desc.attrs[0].hlsl_sem_name = "TEXCOORD"; 551 | desc.attrs[0].hlsl_sem_index = 0; 552 | desc.attrs[1].hlsl_sem_name = "TEXCOORD"; 553 | desc.attrs[1].hlsl_sem_index = 1; 554 | desc.label = "triangle_shader"; 555 | } 556 | return &desc; 557 | } 558 | if (backend == SG_BACKEND_METAL_MACOS) { 559 | static sg_shader_desc desc; 560 | static bool valid; 561 | if (!valid) { 562 | valid = true; 563 | desc.vertex_func.source = (const char*)vs_source_metal_macos; 564 | desc.vertex_func.entry = "main0"; 565 | desc.fragment_func.source = (const char*)fs_source_metal_macos; 566 | desc.fragment_func.entry = "main0"; 567 | desc.label = "triangle_shader"; 568 | } 569 | return &desc; 570 | } 571 | if (backend == SG_BACKEND_WGPU) { 572 | static sg_shader_desc desc; 573 | static bool valid; 574 | if (!valid) { 575 | valid = true; 576 | desc.vertex_func.source = (const char*)vs_source_wgsl; 577 | desc.vertex_func.entry = "main"; 578 | desc.fragment_func.source = (const char*)fs_source_wgsl; 579 | desc.fragment_func.entry = "main"; 580 | desc.label = "triangle_shader"; 581 | } 582 | return &desc; 583 | } 584 | return 0; 585 | } 586 | #endif // SOKOL_SHDC_IMPL -------------------------------------------------------------------------------- /src/shaders/triangle_compile.c: -------------------------------------------------------------------------------- 1 | #define SOKOL_SHDC_IMPL 2 | #include "sokol/sokol_gfx.h" 3 | #include "shaders/triangle.glsl.h" 4 | -------------------------------------------------------------------------------- /src/web/shell.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Sokol 7 | 29 | 30 | 31 | 32 | 61 | {{{ SCRIPT }}} 62 | 63 | --------------------------------------------------------------------------------