This commit is contained in:
alessandro bason 2026-03-03 16:57:56 +01:00
commit 7f37187c92
46 changed files with 62931 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
build/
*.pdb

BIN
bin/sokol-shdc.exe Normal file

Binary file not shown.

14
data/batch_frag.hlsl Normal file
View file

@ -0,0 +1,14 @@
Texture2D tex : register(t0);
SamplerState smp : register(s0);
struct input_t {
float4 pos : SV_Position;
float2 uv : TEXCOORD1;
float4 col : TEXCOORD2;
};
float4 main(input_t input) : SV_Target0 {
float4 col = input.col;
float4 spr = tex.Sample(smp, input.uv);
return spr * col;
}

72
data/batch_vert.hlsl Normal file
View file

@ -0,0 +1,72 @@
cbuffer renderer_data : register(b0) {
float2 one_over_window_size;
//float2 one_over_texture_size;
float zoom;
float padding;
};
struct input_t {
uint vtx_index : SV_VertexID;
float4 quad : BATCH_QUAD;
float4 tex_quad : BATCH_TEX_QUAD;
float4 colour : BATCH_COLOUR;
};
struct output_t {
float4 pos : SV_Position;
float2 uv : TEXCOORD1;
float4 col : TEXCOORD2;
};
static const int indices[6] = {
0, 1, 2, 2, 3, 0,
};
static const float3 positions[4] = {
float3(0, 0, 0),
float3(0, 1, 0),
float3(1, 1, 0),
float3(1, 0, 0),
};
static const float2 uvs[4] = {
float2(0.0f, 0.0f),
float2(0.0f, 1.0f),
float2(1.0f, 1.0f),
float2(1.0f, 0.0f),
};
output_t main(input_t input) {
output_t output;
int vtx = indices[input.vtx_index];
float3 pos = positions[vtx];
pos.xy = ((pos.xy * input.quad.zw) + input.quad.xy) * zoom;
pos.xy = (pos.xy * one_over_window_size) * 2.0 - 1.0;
pos.y = -pos.y;
/*
x = ((x * ovws.x) * zoom * quad.w) - 1 + (quad.x * ovws.x * zoom);
*/
// pos.xy *= one_over_window_size;
// pos.xy *= zoom;
// pos.xy *= input.quad.zw;
// pos.x -= 1.0;
// pos.y += 1.0;
// pos.xy += float2(input.quad.x, -input.quad.y) * one_over_window_size * zoom;
float2 uv = uvs[vtx];
uv *= input.tex_quad.zw;
uv += input.tex_quad.xy;
output.pos = float4(pos, 1.0);
output.uv = uv;
output.col = input.colour;
return output;
}

BIN
data/berkeley-mono.otf Normal file

Binary file not shown.

BIN
data/font.ttf Normal file

Binary file not shown.

BIN
data/metro.glb Normal file

Binary file not shown.

38
data/obj.glsl Normal file
View file

@ -0,0 +1,38 @@
@ctype mat4 mat4
@vs vs
layout(binding=0) uniform vs_params {
mat4 mvp;
};
in vec4 position;
in vec3 norm;
in vec2 uv;
out vec3 fs_norm;
out vec2 fs_uv;
void main() {
gl_Position = mvp * position;
fs_norm = norm;
fs_uv = uv;
}
@end
@fs fs
layout(binding=0) uniform texture2D tex;
layout(binding=0) uniform sampler smp;
in vec3 fs_norm;
in vec2 fs_uv;
out vec4 frag_color;
void main() {
frag_color = texture(sampler2D(tex, smp), fs_uv);
// frag_color = vec4(fs_norm * 0.5 + 0.5, 1.0);
// vec2 uv = fs_uv * 0.5 + 0.5;
// frag_color = vec4(uv, 0.0, 1.0);
}
@end
@program obj vs fs

BIN
data/textures/Chair.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
data/textures/Door.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
data/textures/Door_01.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/textures/Floor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

BIN
data/textures/Tiles.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

BIN
data/textures/Trains.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

BIN
data/textures/Trains_01.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
data/textures/metal.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
data/textures/metal_01.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
data/textures/metal_02.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
data/textures/metal_03.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
data/textures/metal_04.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
data/textures/metal_05.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,011 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
data/textures/seats.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
data/textures/tile_tile.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
data/textures/trash_can.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

22
data/triangle.glsl Normal file
View file

@ -0,0 +1,22 @@
@vs vs
in vec4 position;
in vec4 color0;
out vec4 color;
void main() {
gl_Position = position;
color = color0;
}
@end
@fs fs
in vec4 color;
out vec4 frag_color;
void main() {
frag_color = color;
}
@end
@program triangle vs fs

11
gen.nu Normal file
View file

@ -0,0 +1,11 @@
# grab all shaders
mkdir src/gen
ls data/*.glsl
| get name
| each { |s|
let outname = $s | path parse | $'src/gen/($in.stem).h'
bin/sokol-shdc -i $s -o $outname -l hlsl5:spirv_vk -f sokol
}

93
src/camera.c Normal file
View file

@ -0,0 +1,93 @@
#include "colla/colla.h"
#include "libs/handmademath.h"
#include "libs/sokol_gfx.h"
#include "utils.h"
#define WORLD_UP HMM_V3(0, 1, 0)
#define NEAR_Z (0.1f)
#define FAR_Z (1000.f)
typedef struct camera_t camera_t;
struct camera_t {
HMM_Vec3 pos;
HMM_Vec3 fwd;
HMM_Vec3 up;
float yaw, pitch;
HMM_Mat4 lookat;
float speed, mov_speed, look_speed;
float fov;
};
camera_t cam_init(void) {
camera_t cam = {
.fwd = { 0, 0, -1 },
.up = { 0, 1, 0 },
.pos = { 0, 0, 0 },
.look_speed = 0.3f,
.mov_speed = 15.f,
.fov = HMM_DegToRad * 60.f,
};
return cam;
}
void cam_update(camera_t *cam, float dt) {
float strafe = (float)((int)is_key_down(SAPP_KEYCODE_D) - (int)is_key_down(SAPP_KEYCODE_A));
float forward = (float)((int)is_key_down(SAPP_KEYCODE_W) - (int)is_key_down(SAPP_KEYCODE_S));
float movup = (float)((int)is_key_down(SAPP_KEYCODE_Q) - (int)is_key_down(SAPP_KEYCODE_E));
float move_speed = cam->mov_speed * dt;
float look_speed = cam->look_speed * dt;
HMM_Vec2 delta = mouse_delta();
cam->yaw += delta.X * look_speed;
cam->pitch -= delta.Y * look_speed;
float max_angle = HMM_DegToRad * 89.f;
cam->pitch = HMM_Clamp(-max_angle, cam->pitch, max_angle);
float yc = cosf(cam->yaw);
float ys = sinf(cam->yaw);
float pc = cosf(cam->pitch);
float ps = sinf(cam->pitch);
cam->fwd = HMM_Norm(HMM_V3(
pc * ys,
ps,
-pc * yc
));
HMM_Vec3 right = HMM_Norm(HMM_Cross(cam->fwd, WORLD_UP));
cam->up = HMM_Cross(right, cam->fwd);
cam->pos = HMM_Add(
cam->pos,
HMM_Mul(
HMM_Add(
HMM_Add(
HMM_Mul(cam->fwd, forward),
HMM_Mul(right, strafe)
),
HMM_Mul(cam->up, movup)
),
move_speed
)
);
}
HMM_Mat4 cam_view(camera_t *cam) {
HMM_Mat4 view = HMM_LookAt_RH(cam->pos, HMM_Add(cam->pos, cam->fwd), cam->up);
return view;
}
HMM_Mat4 cam_proj(camera_t *cam) {
float aspect = sapp_widthf() / sapp_heightf();
HMM_Mat4 proj = HMM_Perspective_RH_ZO(cam->fov, aspect, NEAR_Z, FAR_Z);
return proj;
}

1
src/colla Submodule

@ -0,0 +1 @@
Subproject commit c7291ead23083a3a38fc8831ce22418fb8b4c211

486
src/gen/obj.h Normal file
View file

@ -0,0 +1,486 @@
#pragma once
/*
#version:1# (machine generated, don't edit!)
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
Cmdline:
sokol-shdc -i data\obj.glsl -o src/gen/obj.h -l hlsl5:spirv_vk -f sokol
Overview:
=========
Shader program: 'obj':
Get shader desc: obj_shader_desc(sg_query_backend());
Vertex Shader: vs
Fragment Shader: fs
Attributes:
ATTR_obj_position => 0
ATTR_obj_norm => 1
ATTR_obj_uv => 2
Bindings:
Uniform block 'vs_params':
C struct: vs_params_t
Bind slot: UB_vs_params => 0
Texture 'tex':
Image type: SG_IMAGETYPE_2D
Sample type: SG_IMAGESAMPLETYPE_FLOAT
Multisampled: false
Bind slot: VIEW_tex => 0
Sampler 'smp':
Type: SG_SAMPLERTYPE_FILTERING
Bind slot: SMP_smp => 0
*/
#if !defined(SOKOL_GFX_INCLUDED)
#error "Please include sokol_gfx.h before obj.h"
#endif
#if !defined(SOKOL_SHDC_ALIGN)
#if defined(_MSC_VER)
#define SOKOL_SHDC_ALIGN(a) __declspec(align(a))
#else
#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a)))
#endif
#endif
#define ATTR_obj_position (0)
#define ATTR_obj_norm (1)
#define ATTR_obj_uv (2)
#define UB_vs_params (0)
#define VIEW_tex (0)
#define SMP_smp (0)
#pragma pack(push,1)
SOKOL_SHDC_ALIGN(16) typedef struct vs_params_t {
mat4 mvp;
} vs_params_t;
#pragma pack(pop)
/*
cbuffer vs_params : register(b0)
{
row_major float4x4 _19_mvp : packoffset(c0);
};
static float4 gl_Position;
static float4 position;
static float3 fs_norm;
static float3 norm;
static float2 fs_uv;
static float2 uv;
struct SPIRV_Cross_Input
{
float4 position : TEXCOORD0;
float3 norm : TEXCOORD1;
float2 uv : TEXCOORD2;
};
struct SPIRV_Cross_Output
{
float3 fs_norm : TEXCOORD0;
float2 fs_uv : TEXCOORD1;
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = mul(position, _19_mvp);
fs_norm = norm;
fs_uv = uv;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
position = stage_input.position;
norm = stage_input.norm;
uv = stage_input.uv;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output.fs_norm = fs_norm;
stage_output.fs_uv = fs_uv;
return stage_output;
}
*/
static const uint8_t vs_source_hlsl5[917] = {
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,
0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,
0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x39,0x5f,0x6d,0x76,
0x70,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,
0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,
0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,
0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,
0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,
0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x73,0x5f,0x6e,0x6f,0x72,
0x6d,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
0x20,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x32,0x20,0x66,0x73,0x5f,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,
0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x73,
0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,
0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,
0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x6f,0x72,0x6d,0x20,0x3a,0x20,0x54,0x45,0x58,
0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
0x74,0x32,0x20,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,
0x32,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,
0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x73,
0x5f,0x6e,0x6f,0x72,0x6d,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,
0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x66,0x73,
0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,
0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,
0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,
0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
0x6d,0x75,0x6c,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x5f,0x31,
0x39,0x5f,0x6d,0x76,0x70,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x73,0x5f,0x6e,
0x6f,0x72,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,
0x66,0x73,0x5f,0x75,0x76,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x69,
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,
0x75,0x74,0x2e,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,
0x20,0x6e,0x6f,0x72,0x6d,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
0x70,0x75,0x74,0x2e,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,
0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x75,
0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,
0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,
0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,
0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x20,0x3d,0x20,
0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x73,0x5f,0x75,0x76,0x20,
0x3d,0x20,0x66,0x73,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,
0x3b,0x0a,0x7d,0x0a,0x00,
};
/*
Texture2D<float4> tex : register(t0);
SamplerState smp : register(s0);
static float4 frag_color;
static float2 fs_uv;
static float3 fs_norm;
struct SPIRV_Cross_Input
{
float3 fs_norm : TEXCOORD0;
float2 fs_uv : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 frag_color : SV_Target0;
};
void frag_main()
{
frag_color = tex.Sample(smp, fs_uv);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
fs_uv = stage_input.fs_uv;
fs_norm = stage_input.fs_norm;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.frag_color = frag_color;
return stage_output;
}
*/
static const uint8_t fs_source_hlsl5[614] = {
0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,
0x3e,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,
0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,
0x74,0x65,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,
0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,
0x66,0x73,0x5f,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x33,0x20,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x0a,0x73,
0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,
0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x33,0x20,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x20,0x3a,0x20,0x54,
0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x32,0x20,0x66,0x73,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,
0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,
0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,
0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,
0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,
0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,
0x6d,0x70,0x2c,0x20,0x66,0x73,0x5f,0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x73,0x5f,0x75,
0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,
0x66,0x73,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x73,0x5f,0x6e,0x6f,
0x72,0x6d,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,
0x2e,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,
0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,
0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,
0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,
0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
0x74,0x3b,0x0a,0x7d,0x0a,0x00,
};
/*
#version 460
layout(set = 0, binding = 0, std140) uniform vs_params
{
mat4 mvp;
} _19;
layout(location = 0) in vec4 position;
layout(location = 0) out vec3 fs_norm;
layout(location = 1) in vec3 norm;
layout(location = 1) out vec2 fs_uv;
layout(location = 2) in vec2 uv;
void main()
{
gl_Position = _19.mvp * position;
fs_norm = norm;
fs_uv = uv;
}
*/
static const uint8_t vs_bytecode_spirv_vk[1348] = {
0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x29,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x0f,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
0x00,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
0x1f,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x27,0x00,0x00,0x00,
0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0xcc,0x01,0x00,0x00,0x05,0x00,0x04,0x00,
0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x05,0x00,0x06,0x00,
0x0b,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x65,0x72,0x56,0x65,0x72,0x74,0x65,0x78,
0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x06,0x00,0x07,0x00,
0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x6f,0x69,0x6e,0x74,
0x53,0x69,0x7a,0x65,0x00,0x00,0x00,0x00,0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x67,0x6c,0x5f,0x43,0x6c,0x69,0x70,0x44,0x69,0x73,0x74,0x61,
0x6e,0x63,0x65,0x00,0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x67,0x6c,0x5f,0x43,0x75,0x6c,0x6c,0x44,0x69,0x73,0x74,0x61,0x6e,0x63,0x65,0x00,
0x05,0x00,0x03,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x05,0x00,
0x11,0x00,0x00,0x00,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x00,0x00,0x00,
0x06,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6d,0x76,0x70,0x00,
0x05,0x00,0x03,0x00,0x13,0x00,0x00,0x00,0x5f,0x31,0x39,0x00,0x05,0x00,0x05,0x00,
0x18,0x00,0x00,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x00,0x00,
0x05,0x00,0x04,0x00,0x1f,0x00,0x00,0x00,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x00,
0x05,0x00,0x04,0x00,0x21,0x00,0x00,0x00,0x6e,0x6f,0x72,0x6d,0x00,0x00,0x00,0x00,
0x05,0x00,0x04,0x00,0x25,0x00,0x00,0x00,0x66,0x73,0x5f,0x75,0x76,0x00,0x00,0x00,
0x05,0x00,0x03,0x00,0x27,0x00,0x00,0x00,0x75,0x76,0x00,0x00,0x47,0x00,0x03,0x00,
0x0b,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,
0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x0b,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x11,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x11,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x13,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x13,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x18,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x1f,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x21,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x25,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x27,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x13,0x00,0x02,0x00,
0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,
0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x15,0x00,0x04,0x00,
0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,
0x08,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x04,0x00,
0x0a,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x1e,0x00,0x06,0x00,
0x0b,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,
0x0a,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x0b,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x0e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x0e,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x00,0x04,0x00,0x10,0x00,0x00,0x00,0x07,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x11,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x17,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x17,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x1b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00,
0x17,0x00,0x04,0x00,0x1d,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x1e,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1d,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x1e,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1d,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x20,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x17,0x00,0x04,0x00,0x23,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x24,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x23,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x24,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x26,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x26,0x00,0x00,0x00,0x27,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0x41,0x00,0x05,0x00,
0x14,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,
0x3d,0x00,0x04,0x00,0x10,0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x15,0x00,0x00,0x00,
0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
0x91,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
0x19,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x1b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,
0x0d,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x1c,0x00,0x00,0x00,
0x1a,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x1d,0x00,0x00,0x00,0x22,0x00,0x00,0x00,
0x21,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x1f,0x00,0x00,0x00,0x22,0x00,0x00,0x00,
0x3d,0x00,0x04,0x00,0x23,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x27,0x00,0x00,0x00,
0x3e,0x00,0x03,0x00,0x25,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,
0x38,0x00,0x01,0x00,
};
/*
#version 460
layout(set = 1, binding = 0) uniform texture2D tex;
layout(set = 1, binding = 32) uniform sampler smp;
layout(location = 0) out vec4 frag_color;
layout(location = 1) in vec2 fs_uv;
layout(location = 0) in vec3 fs_norm;
void main()
{
frag_color = texture(sampler2D(tex, smp), fs_uv);
}
*/
static const uint8_t fs_bytecode_spirv_vk[764] = {
0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x1c,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x0f,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x16,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x10,0x00,0x03,0x00,0x04,0x00,0x00,0x00,
0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0xcc,0x01,0x00,0x00,
0x05,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,
0x05,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,
0x6f,0x72,0x00,0x00,0x05,0x00,0x03,0x00,0x0c,0x00,0x00,0x00,0x74,0x65,0x78,0x00,
0x05,0x00,0x03,0x00,0x10,0x00,0x00,0x00,0x73,0x6d,0x70,0x00,0x05,0x00,0x04,0x00,
0x16,0x00,0x00,0x00,0x66,0x73,0x5f,0x75,0x76,0x00,0x00,0x00,0x05,0x00,0x04,0x00,
0x1b,0x00,0x00,0x00,0x66,0x73,0x5f,0x6e,0x6f,0x72,0x6d,0x00,0x47,0x00,0x04,0x00,
0x09,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x0c,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x0c,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x10,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x10,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x16,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,
0x1b,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x02,0x00,
0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,
0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x20,0x00,0x04,0x00,
0x08,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,
0x08,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x19,0x00,0x09,0x00,
0x0a,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x00,0x04,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,
0x3b,0x00,0x04,0x00,0x0b,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1a,0x00,0x02,0x00,0x0e,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0f,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0e,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0f,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x03,0x00,0x12,0x00,0x00,0x00,
0x0a,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x14,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x19,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x1a,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x19,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x1a,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,
0x3d,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,
0x3d,0x00,0x04,0x00,0x0e,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x56,0x00,0x05,0x00,0x12,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,
0x11,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
0x16,0x00,0x00,0x00,0x57,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
0x13,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x09,0x00,0x00,0x00,
0x18,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
};
static inline const sg_shader_desc* obj_shader_desc(sg_backend backend) {
if (backend == SG_BACKEND_D3D11) {
static sg_shader_desc desc;
static bool valid;
if (!valid) {
valid = true;
desc.vertex_func.source = (const char*)vs_source_hlsl5;
desc.vertex_func.d3d11_target = "vs_5_0";
desc.vertex_func.entry = "main";
desc.fragment_func.source = (const char*)fs_source_hlsl5;
desc.fragment_func.d3d11_target = "ps_5_0";
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[0].hlsl_sem_name = "TEXCOORD";
desc.attrs[0].hlsl_sem_index = 0;
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[1].hlsl_sem_name = "TEXCOORD";
desc.attrs[1].hlsl_sem_index = 1;
desc.attrs[2].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[2].hlsl_sem_name = "TEXCOORD";
desc.attrs[2].hlsl_sem_index = 2;
desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX;
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
desc.uniform_blocks[0].size = 64;
desc.uniform_blocks[0].hlsl_register_b_n = 0;
desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT;
desc.views[0].texture.image_type = SG_IMAGETYPE_2D;
desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT;
desc.views[0].texture.multisampled = false;
desc.views[0].texture.hlsl_register_t_n = 0;
desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT;
desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
desc.samplers[0].hlsl_register_s_n = 0;
desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
desc.texture_sampler_pairs[0].view_slot = 0;
desc.texture_sampler_pairs[0].sampler_slot = 0;
desc.label = "obj_shader";
}
return &desc;
}
if (backend == SG_BACKEND_VULKAN) {
static sg_shader_desc desc;
static bool valid;
if (!valid) {
valid = true;
desc.vertex_func.bytecode.ptr = vs_bytecode_spirv_vk;
desc.vertex_func.bytecode.size = 1348;
desc.vertex_func.entry = "main";
desc.fragment_func.bytecode.ptr = fs_bytecode_spirv_vk;
desc.fragment_func.bytecode.size = 764;
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[2].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX;
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
desc.uniform_blocks[0].size = 64;
desc.uniform_blocks[0].spirv_set0_binding_n = 0;
desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT;
desc.views[0].texture.image_type = SG_IMAGETYPE_2D;
desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT;
desc.views[0].texture.multisampled = false;
desc.views[0].texture.spirv_set1_binding_n = 0;
desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT;
desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
desc.samplers[0].spirv_set1_binding_n = 32;
desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
desc.texture_sampler_pairs[0].view_slot = 0;
desc.texture_sampler_pairs[0].sampler_slot = 0;
desc.label = "obj_shader";
}
return &desc;
}
return 0;
}

316
src/gen/triangle.h Normal file
View file

@ -0,0 +1,316 @@
#pragma once
/*
#version:1# (machine generated, don't edit!)
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
Cmdline:
sokol-shdc -i data\triangle.glsl -o src/gen/triangle.h -l hlsl5:spirv_vk -f sokol
Overview:
=========
Shader program: 'triangle':
Get shader desc: triangle_shader_desc(sg_query_backend());
Vertex Shader: vs
Fragment Shader: fs
Attributes:
ATTR_triangle_position => 0
ATTR_triangle_color0 => 1
Bindings:
*/
#if !defined(SOKOL_GFX_INCLUDED)
#error "Please include sokol_gfx.h before triangle.h"
#endif
#if !defined(SOKOL_SHDC_ALIGN)
#if defined(_MSC_VER)
#define SOKOL_SHDC_ALIGN(a) __declspec(align(a))
#else
#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a)))
#endif
#endif
#define ATTR_triangle_position (0)
#define ATTR_triangle_color0 (1)
/*
static float4 gl_Position;
static float4 position;
static float4 color;
static float4 color0;
struct SPIRV_Cross_Input
{
float4 position : TEXCOORD0;
float4 color0 : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 color : TEXCOORD0;
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = position;
color = color0;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
position = stage_input.position;
color0 = stage_input.color0;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output.color = color;
return stage_output;
}
*/
static const uint8_t vs_source_hlsl5[645] = {
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,
0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,
0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x73,
0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,
0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,
0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x54,
0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,
0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,
0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,
0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,
0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,
0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,
0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,
0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,
0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,
0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,
0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,
0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x70,0x6f,0x73,0x69,
0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,
0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x63,
0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,
0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,
0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,
0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,
0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,
0x3b,0x0a,0x7d,0x0a,0x00,
};
/*
static float4 frag_color;
static float4 color;
struct SPIRV_Cross_Input
{
float4 color : TEXCOORD0;
};
struct SPIRV_Cross_Output
{
float4 frag_color : SV_Target0;
};
void frag_main()
{
frag_color = color;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
color = stage_input.color;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.frag_color = frag_color;
return stage_output;
}
*/
static const uint8_t fs_source_hlsl5[435] = {
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,
0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,
0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,
0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,
0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,
0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,
0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,
0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,
0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,
0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,
0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,
0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72,
0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f,
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
0x7d,0x0a,0x00,
};
/*
#version 460
layout(location = 0) in vec4 position;
layout(location = 0) out vec4 color;
layout(location = 1) in vec4 color0;
void main()
{
gl_Position = position;
color = color0;
}
*/
static const uint8_t vs_bytecode_spirv_vk[840] = {
0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x0f,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
0x00,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x15,0x00,0x00,0x00,
0x16,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0xcc,0x01,0x00,0x00,
0x05,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,
0x05,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x65,0x72,0x56,0x65,
0x72,0x74,0x65,0x78,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,
0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,
0x6f,0x69,0x6e,0x74,0x53,0x69,0x7a,0x65,0x00,0x00,0x00,0x00,0x06,0x00,0x07,0x00,
0x0b,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x67,0x6c,0x5f,0x43,0x6c,0x69,0x70,0x44,
0x69,0x73,0x74,0x61,0x6e,0x63,0x65,0x00,0x06,0x00,0x07,0x00,0x0b,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x67,0x6c,0x5f,0x43,0x75,0x6c,0x6c,0x44,0x69,0x73,0x74,0x61,
0x6e,0x63,0x65,0x00,0x05,0x00,0x03,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0x00,0x05,0x00,0x11,0x00,0x00,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,
0x00,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x63,0x6f,0x6c,0x6f,
0x72,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x16,0x00,0x00,0x00,0x63,0x6f,0x6c,0x6f,
0x72,0x30,0x00,0x00,0x47,0x00,0x03,0x00,0x0b,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x48,0x00,0x05,0x00,
0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x47,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x47,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x47,0x00,0x04,0x00,0x16,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
0x17,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x15,0x00,0x04,0x00,0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x2b,0x00,0x04,0x00,0x08,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x1c,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x09,0x00,0x00,0x00,
0x1e,0x00,0x06,0x00,0x0b,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
0x0a,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,
0x0d,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x0e,0x00,0x00,0x00,
0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x0e,0x00,0x00,0x00,
0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x10,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x10,0x00,0x00,0x00,
0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x13,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x13,0x00,0x00,0x00,
0x15,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x10,0x00,0x00,0x00,
0x16,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,
0x05,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x12,0x00,0x00,0x00,
0x11,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x13,0x00,0x00,0x00,0x14,0x00,0x00,0x00,
0x0d,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x14,0x00,0x00,0x00,
0x12,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
0x16,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x15,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
};
/*
#version 460
layout(location = 0) out vec4 frag_color;
layout(location = 0) in vec4 color;
void main()
{
frag_color = color;
}
*/
static const uint8_t fs_bytecode_spirv_vk[376] = {
0x03,0x02,0x23,0x07,0x00,0x04,0x01,0x00,0x0b,0x00,0x08,0x00,0x0d,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x0f,0x00,0x07,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x10,0x00,0x03,0x00,
0x04,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x02,0x00,0x00,0x00,
0xcc,0x01,0x00,0x00,0x05,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
0x00,0x00,0x00,0x00,0x05,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x66,0x72,0x61,0x67,
0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x05,0x00,0x04,0x00,0x0b,0x00,0x00,0x00,
0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x09,0x00,0x00,0x00,
0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x0b,0x00,0x00,0x00,
0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00,
0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00,
0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x07,0x00,0x00,0x00,
0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x08,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x08,0x00,0x00,0x00,
0x09,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,
0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,
0x05,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,
0x0b,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x09,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,
0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
};
static inline const sg_shader_desc* triangle_shader_desc(sg_backend backend) {
if (backend == SG_BACKEND_D3D11) {
static sg_shader_desc desc;
static bool valid;
if (!valid) {
valid = true;
desc.vertex_func.source = (const char*)vs_source_hlsl5;
desc.vertex_func.d3d11_target = "vs_5_0";
desc.vertex_func.entry = "main";
desc.fragment_func.source = (const char*)fs_source_hlsl5;
desc.fragment_func.d3d11_target = "ps_5_0";
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[0].hlsl_sem_name = "TEXCOORD";
desc.attrs[0].hlsl_sem_index = 0;
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[1].hlsl_sem_name = "TEXCOORD";
desc.attrs[1].hlsl_sem_index = 1;
desc.label = "triangle_shader";
}
return &desc;
}
if (backend == SG_BACKEND_VULKAN) {
static sg_shader_desc desc;
static bool valid;
if (!valid) {
valid = true;
desc.vertex_func.bytecode.ptr = vs_bytecode_spirv_vk;
desc.vertex_func.bytecode.size = 840;
desc.vertex_func.entry = "main";
desc.fragment_func.bytecode.ptr = fs_bytecode_spirv_vk;
desc.fragment_func.bytecode.size = 376;
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
desc.label = "triangle_shader";
}
return &desc;
}
return 0;
}

7240
src/libs/cgltf.h Normal file

File diff suppressed because it is too large Load diff

3939
src/libs/handmademath.h Normal file

File diff suppressed because it is too large Load diff

14621
src/libs/sokol_app.h Normal file

File diff suppressed because it is too large Load diff

26670
src/libs/sokol_gfx.h Normal file

File diff suppressed because it is too large Load diff

207
src/libs/sokol_glue.h Normal file
View file

@ -0,0 +1,207 @@
#if defined(SOKOL_IMPL) && !defined(SOKOL_GLUE_IMPL)
#define SOKOL_GLUE_IMPL
#endif
#ifndef SOKOL_GLUE_INCLUDED
/*
sokol_glue.h -- glue helper functions for sokol headers
Project URL: https://github.com/floooh/sokol
Do this:
#define SOKOL_IMPL or
#define SOKOL_GLUE_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
...optionally provide the following macros to override defaults:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_GLUE_API_DECL - public function declaration prefix (default: extern)
SOKOL_API_DECL - same as SOKOL_GLUE_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_glue.h is compiled as a DLL, define the following before
including the declaration or implementation:
SOKOL_DLL
On Windows, SOKOL_DLL will define SOKOL_GLUE_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
OVERVIEW
========
sokol_glue.h provides glue helper functions between sokol_gfx.h and sokol_app.h,
so that sokol_gfx.h doesn't need to depend on sokol_app.h but can be
used with different window system glue libraries.
PROVIDED FUNCTIONS
==================
sg_environment sglue_environment(void)
Returns an sg_environment struct initialized by calling sokol_app.h
functions. Use this in the sg_setup() call like this:
sg_setup(&(sg_desc){
.environment = sglue_environment(),
...
});
sg_swapchain sglue_swapchain(void)
Returns an sg_swapchain struct initialized by calling sokol_app.h
functions. Use this in sg_begin_pass() for a 'swapchain pass' like
this:
sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain(), ... });
LICENSE
=======
zlib/libpng license
Copyright (c) 2018 Andre Weissflog
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.
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:
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.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#define SOKOL_GLUE_INCLUDED
#if defined(SOKOL_API_DECL) && !defined(SOKOL_GLUE_API_DECL)
#define SOKOL_GLUE_API_DECL SOKOL_API_DECL
#endif
#ifndef SOKOL_GLUE_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GLUE_IMPL)
#define SOKOL_GLUE_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
#define SOKOL_GLUE_API_DECL __declspec(dllimport)
#else
#define SOKOL_GLUE_API_DECL extern
#endif
#endif
#ifndef SOKOL_GFX_INCLUDED
#error "Please include sokol_gfx.h before sokol_glue.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
SOKOL_GLUE_API_DECL sg_environment sglue_environment(void);
SOKOL_GLUE_API_DECL sg_swapchain sglue_swapchain(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SOKOL_GLUE_INCLUDED */
/*-- IMPLEMENTATION ----------------------------------------------------------*/
#ifdef SOKOL_GLUE_IMPL
#define SOKOL_GLUE_IMPL_INCLUDED (1)
#include <string.h> /* memset */
#ifndef SOKOL_APP_INCLUDED
#error "Please include sokol_app.h before the sokol_glue.h implementation"
#endif
#ifndef SOKOL_API_IMPL
#define SOKOL_API_IMPL
#endif
#ifndef _SOKOL_PRIVATE
#if defined(__GNUC__) || defined(__clang__)
#define _SOKOL_PRIVATE __attribute__((unused)) static
#else
#define _SOKOL_PRIVATE static
#endif
#endif
#ifndef SOKOL_ASSERT
#include <assert.h>
#define SOKOL_ASSERT(c) assert(c)
#endif
#ifndef SOKOL_UNREACHABLE
#define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
#endif
_SOKOL_PRIVATE sg_pixel_format _sglue_to_sgpixelformat(sapp_pixel_format fmt) {
switch (fmt) {
case SAPP_PIXELFORMAT_NONE: return SG_PIXELFORMAT_NONE;
case SAPP_PIXELFORMAT_RGBA8: return SG_PIXELFORMAT_RGBA8;
case SAPP_PIXELFORMAT_SRGB8A8: return SG_PIXELFORMAT_SRGB8A8;
case SAPP_PIXELFORMAT_BGRA8: return SG_PIXELFORMAT_BGRA8;
case SAPP_PIXELFORMAT_DEPTH_STENCIL: return SG_PIXELFORMAT_DEPTH_STENCIL;
case SAPP_PIXELFORMAT_DEPTH: return SG_PIXELFORMAT_DEPTH;
case SAPP_PIXELFORMAT_SBGRA8: // FIXME!
default:
SOKOL_UNREACHABLE;
return SG_PIXELFORMAT_NONE;
}
}
SOKOL_API_IMPL sg_environment sglue_environment(void) {
sg_environment res;
memset(&res, 0, sizeof(res));
const sapp_environment env = sapp_get_environment();
res.defaults.color_format = _sglue_to_sgpixelformat(env.defaults.color_format);
res.defaults.depth_format = _sglue_to_sgpixelformat(env.defaults.depth_format);
res.defaults.sample_count = env.defaults.sample_count;
res.metal.device = env.metal.device;
res.d3d11.device = env.d3d11.device;
res.d3d11.device_context = env.d3d11.device_context;
res.wgpu.device = env.wgpu.device;
res.vulkan.instance = env.vulkan.instance;
res.vulkan.physical_device = env.vulkan.physical_device;
res.vulkan.device = env.vulkan.device;
res.vulkan.queue = env.vulkan.queue;
res.vulkan.queue_family_index = env.vulkan.queue_family_index;
return res;
}
SOKOL_API_IMPL sg_swapchain sglue_swapchain(void) {
sg_swapchain res;
memset(&res, 0, sizeof(res));
const sapp_swapchain sc = sapp_get_swapchain();
res.width = sc.width;
res.height = sc.height;
res.sample_count = sc.sample_count;
res.color_format = _sglue_to_sgpixelformat(sc.color_format);
res.depth_format = _sglue_to_sgpixelformat(sc.depth_format);
res.metal.current_drawable = sc.metal.current_drawable;
res.metal.depth_stencil_texture = sc.metal.depth_stencil_texture;
res.metal.msaa_color_texture = sc.metal.msaa_color_texture;
res.d3d11.render_view = sc.d3d11.render_view;
res.d3d11.resolve_view = sc.d3d11.resolve_view;
res.d3d11.depth_stencil_view = sc.d3d11.depth_stencil_view;
res.wgpu.render_view = sc.wgpu.render_view;
res.wgpu.resolve_view = sc.wgpu.resolve_view;
res.wgpu.depth_stencil_view = sc.wgpu.depth_stencil_view;
res.vulkan.render_image = sc.vulkan.render_image;
res.vulkan.render_view = sc.vulkan.render_view;
res.vulkan.resolve_image = sc.vulkan.resolve_image;
res.vulkan.resolve_view = sc.vulkan.resolve_view;
res.vulkan.depth_stencil_image = sc.vulkan.depth_stencil_image;
res.vulkan.depth_stencil_view = sc.vulkan.depth_stencil_view;
res.vulkan.render_finished_semaphore = sc.vulkan.render_finished_semaphore;
res.vulkan.present_complete_semaphore = sc.vulkan.present_complete_semaphore;
res.gl.framebuffer = sc.gl.framebuffer;
return res;
}
#endif /* SOKOL_GLUE_IMPL */

319
src/libs/sokol_time.h Normal file
View file

@ -0,0 +1,319 @@
#if defined(SOKOL_IMPL) && !defined(SOKOL_TIME_IMPL)
#define SOKOL_TIME_IMPL
#endif
#ifndef SOKOL_TIME_INCLUDED
/*
sokol_time.h -- simple cross-platform time measurement
Project URL: https://github.com/floooh/sokol
Do this:
#define SOKOL_IMPL or
#define SOKOL_TIME_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
Optionally provide the following defines with your own implementations:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_TIME_API_DECL - public function declaration prefix (default: extern)
SOKOL_API_DECL - same as SOKOL_TIME_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_time.h is compiled as a DLL, define the following before
including the declaration or implementation:
SOKOL_DLL
On Windows, SOKOL_DLL will define SOKOL_TIME_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
void stm_setup();
Call once before any other functions to initialize sokol_time
(this calls for instance QueryPerformanceFrequency on Windows)
uint64_t stm_now();
Get current point in time in unspecified 'ticks'. The value that
is returned has no relation to the 'wall-clock' time and is
not in a specific time unit, it is only useful to compute
time differences.
uint64_t stm_diff(uint64_t new, uint64_t old);
Computes the time difference between new and old. This will always
return a positive, non-zero value.
uint64_t stm_since(uint64_t start);
Takes the current time, and returns the elapsed time since start
(this is a shortcut for "stm_diff(stm_now(), start)")
uint64_t stm_laptime(uint64_t* last_time);
This is useful for measuring frame time and other recurring
events. It takes the current time, returns the time difference
to the value in last_time, and stores the current time in
last_time for the next call. If the value in last_time is 0,
the return value will be zero (this usually happens on the
very first call).
uint64_t stm_round_to_common_refresh_rate(uint64_t duration)
This oddly named function takes a measured frame time and
returns the closest "nearby" common display refresh rate frame duration
in ticks. If the input duration isn't close to any common display
refresh rate, the input duration will be returned unchanged as a fallback.
The main purpose of this function is to remove jitter/inaccuracies from
measured frame times, and instead use the display refresh rate as
frame duration.
NOTE: for more robust frame timing, consider using the
sokol_app.h function sapp_frame_duration()
Use the following functions to convert a duration in ticks into
useful time units:
double stm_sec(uint64_t ticks);
double stm_ms(uint64_t ticks);
double stm_us(uint64_t ticks);
double stm_ns(uint64_t ticks);
Converts a tick value into seconds, milliseconds, microseconds
or nanoseconds. Note that not all platforms will have nanosecond
or even microsecond precision.
Uses the following time measurement functions under the hood:
Windows: QueryPerformanceFrequency() / QueryPerformanceCounter()
MacOS/iOS: mach_absolute_time()
emscripten: emscripten_get_now()
Linux+others: clock_gettime(CLOCK_MONOTONIC)
zlib/libpng license
Copyright (c) 2018 Andre Weissflog
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.
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:
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.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#define SOKOL_TIME_INCLUDED (1)
#include <stdint.h>
#if defined(SOKOL_API_DECL) && !defined(SOKOL_TIME_API_DECL)
#define SOKOL_TIME_API_DECL SOKOL_API_DECL
#endif
#ifndef SOKOL_TIME_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_TIME_IMPL)
#define SOKOL_TIME_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
#define SOKOL_TIME_API_DECL __declspec(dllimport)
#else
#define SOKOL_TIME_API_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
SOKOL_TIME_API_DECL void stm_setup(void);
SOKOL_TIME_API_DECL uint64_t stm_now(void);
SOKOL_TIME_API_DECL uint64_t stm_diff(uint64_t new_ticks, uint64_t old_ticks);
SOKOL_TIME_API_DECL uint64_t stm_since(uint64_t start_ticks);
SOKOL_TIME_API_DECL uint64_t stm_laptime(uint64_t* last_time);
SOKOL_TIME_API_DECL uint64_t stm_round_to_common_refresh_rate(uint64_t frame_ticks);
SOKOL_TIME_API_DECL double stm_sec(uint64_t ticks);
SOKOL_TIME_API_DECL double stm_ms(uint64_t ticks);
SOKOL_TIME_API_DECL double stm_us(uint64_t ticks);
SOKOL_TIME_API_DECL double stm_ns(uint64_t ticks);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif // SOKOL_TIME_INCLUDED
/*-- IMPLEMENTATION ----------------------------------------------------------*/
#ifdef SOKOL_TIME_IMPL
#define SOKOL_TIME_IMPL_INCLUDED (1)
#include <string.h> /* memset */
#ifndef SOKOL_API_IMPL
#define SOKOL_API_IMPL
#endif
#ifndef SOKOL_ASSERT
#include <assert.h>
#define SOKOL_ASSERT(c) assert(c)
#endif
#ifndef _SOKOL_PRIVATE
#if defined(__GNUC__) || defined(__clang__)
#define _SOKOL_PRIVATE __attribute__((unused)) static
#else
#define _SOKOL_PRIVATE static
#endif
#endif
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
typedef struct {
uint32_t initialized;
LARGE_INTEGER freq;
LARGE_INTEGER start;
} _stm_state_t;
#elif defined(__APPLE__) && defined(__MACH__)
#include <mach/mach_time.h>
typedef struct {
uint32_t initialized;
mach_timebase_info_data_t timebase;
uint64_t start;
} _stm_state_t;
#elif defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
typedef struct {
uint32_t initialized;
double start;
} _stm_state_t;
#else /* anything else, this will need more care for non-Linux platforms */
#ifdef ESP8266
// On the ESP8266, clock_gettime ignores the first argument and CLOCK_MONOTONIC isn't defined
#define CLOCK_MONOTONIC 0
#endif
#include <time.h>
typedef struct {
uint32_t initialized;
uint64_t start;
} _stm_state_t;
#endif
static _stm_state_t _stm;
/* prevent 64-bit overflow when computing relative timestamp
see https://gist.github.com/jspohr/3dc4f00033d79ec5bdaf67bc46c813e3
*/
#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__))
_SOKOL_PRIVATE int64_t _stm_int64_muldiv(int64_t value, int64_t numer, int64_t denom) {
int64_t q = value / denom;
int64_t r = value % denom;
return q * numer + r * numer / denom;
}
#endif
SOKOL_API_IMPL void stm_setup(void) {
memset(&_stm, 0, sizeof(_stm));
_stm.initialized = 0xABCDABCD;
#if defined(_WIN32)
QueryPerformanceFrequency(&_stm.freq);
QueryPerformanceCounter(&_stm.start);
#elif defined(__APPLE__) && defined(__MACH__)
mach_timebase_info(&_stm.timebase);
_stm.start = mach_absolute_time();
#elif defined(__EMSCRIPTEN__)
_stm.start = emscripten_get_now();
#else
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
_stm.start = (uint64_t)ts.tv_sec*1000000000 + (uint64_t)ts.tv_nsec;
#endif
}
SOKOL_API_IMPL uint64_t stm_now(void) {
SOKOL_ASSERT(_stm.initialized == 0xABCDABCD);
uint64_t now;
#if defined(_WIN32)
LARGE_INTEGER qpc_t;
QueryPerformanceCounter(&qpc_t);
now = (uint64_t) _stm_int64_muldiv(qpc_t.QuadPart - _stm.start.QuadPart, 1000000000, _stm.freq.QuadPart);
#elif defined(__APPLE__) && defined(__MACH__)
const uint64_t mach_now = mach_absolute_time() - _stm.start;
now = (uint64_t) _stm_int64_muldiv((int64_t)mach_now, (int64_t)_stm.timebase.numer, (int64_t)_stm.timebase.denom);
#elif defined(__EMSCRIPTEN__)
double js_now = emscripten_get_now() - _stm.start;
now = (uint64_t) (js_now * 1000000.0);
#else
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
now = ((uint64_t)ts.tv_sec*1000000000 + (uint64_t)ts.tv_nsec) - _stm.start;
#endif
return now;
}
SOKOL_API_IMPL uint64_t stm_diff(uint64_t new_ticks, uint64_t old_ticks) {
if (new_ticks > old_ticks) {
return new_ticks - old_ticks;
}
else {
return 1;
}
}
SOKOL_API_IMPL uint64_t stm_since(uint64_t start_ticks) {
return stm_diff(stm_now(), start_ticks);
}
SOKOL_API_IMPL uint64_t stm_laptime(uint64_t* last_time) {
SOKOL_ASSERT(last_time);
uint64_t dt = 0;
uint64_t now = stm_now();
if (0 != *last_time) {
dt = stm_diff(now, *last_time);
}
*last_time = now;
return dt;
}
// first number is frame duration in ns, second number is tolerance in ns,
// the resulting min/max values must not overlap!
static const uint64_t _stm_refresh_rates[][2] = {
{ 16666667, 1000000 }, // 60 Hz: 16.6667 +- 1ms
{ 13888889, 250000 }, // 72 Hz: 13.8889 +- 0.25ms
{ 13333333, 250000 }, // 75 Hz: 13.3333 +- 0.25ms
{ 11764706, 250000 }, // 85 Hz: 11.7647 +- 0.25
{ 11111111, 250000 }, // 90 Hz: 11.1111 +- 0.25ms
{ 10000000, 500000 }, // 100 Hz: 10.0000 +- 0.5ms
{ 8333333, 500000 }, // 120 Hz: 8.3333 +- 0.5ms
{ 6944445, 500000 }, // 144 Hz: 6.9445 +- 0.5ms
{ 4166667, 1000000 }, // 240 Hz: 4.1666 +- 1ms
{ 0, 0 }, // keep the last element always at zero
};
SOKOL_API_IMPL uint64_t stm_round_to_common_refresh_rate(uint64_t ticks) {
uint64_t ns;
int i = 0;
while (0 != (ns = _stm_refresh_rates[i][0])) {
uint64_t tol = _stm_refresh_rates[i][1];
if ((ticks > (ns - tol)) && (ticks < (ns + tol))) {
return ns;
}
i++;
}
// fallthrough: didn't fit into any buckets
return ticks;
}
SOKOL_API_IMPL double stm_sec(uint64_t ticks) {
return (double)ticks / 1000000000.0;
}
SOKOL_API_IMPL double stm_ms(uint64_t ticks) {
return (double)ticks / 1000000.0;
}
SOKOL_API_IMPL double stm_us(uint64_t ticks) {
return (double)ticks / 1000.0;
}
SOKOL_API_IMPL double stm_ns(uint64_t ticks) {
return (double)ticks;
}
#endif /* SOKOL_TIME_IMPL */

7988
src/libs/stb_image.h Normal file

File diff suppressed because it is too large Load diff

177
src/main.c Normal file
View file

@ -0,0 +1,177 @@
#include "colla/colla.c"
#if COLLA_WIN || COLLA_LINUX
#define SOKOL_D3D11
#elif COLLA_LINUX
#define SOKOL_VULKAN
#else
#error "unsupported os"
#endif
#include "libs/sokol_app.h"
#include "libs/sokol_gfx.h"
#include "libs/sokol_time.h"
#include "libs/sokol_glue.h"
#include "vecmath.h"
#include "gen/obj.h"
#include "utils.c"
#include "obj.c"
#include "camera.c"
////////////////////////////////
arena_t frame_arena = {0};
sg_pipeline pip = {0};
// sg_bindings binds = {0};
sg_pass_action pass_action = {0};
scene_t scene = {0};
camera_t camera = {0};
u64 time_last = 0;
////////////////////////////////
void sokol_log_cb(
const char *tag,
u32 log_level,
u32 log_item_id,
const char *message_or_null,
u32 line_nr,
const char *filename_or_null,
void *user_data
) {
os_log_level_e levels[] = {
LOG_FATAL,
LOG_ERR,
LOG_WARN,
LOG_INFO,
};
os_log_print(
filename_or_null,
line_nr,
levels[log_level],
"(%s): %s",
tag,
message_or_null
);
}
void app_init(void) {
sg_setup(&(sg_desc){
.environment = sglue_environment(),
.logger.func = sokol_log_cb,
});
stm_setup();
colla_init(COLLA_OS);
sapp_lock_mouse(true);
frame_arena = arena_make(ARENA_VIRTUAL, GB(1));
scene = obj_load_gltf(frame_arena, strv("data/metro.glb"));
camera = cam_init();
sg_shader shd = sg_make_shader(obj_shader_desc(sg_query_backend()));
pip = sg_make_pipeline(&(sg_pipeline_desc){
.shader = shd,
.index_type = SG_INDEXTYPE_UINT16,
// .cull_mode = SG_CULLMODE_BACK,
.depth = {
.compare = SG_COMPAREFUNC_LESS_EQUAL,
.write_enabled = true,
},
.layout = {
.attrs = {
[0].format = SG_VERTEXFORMAT_FLOAT3,
[1].format = SG_VERTEXFORMAT_FLOAT3,
[2].format = SG_VERTEXFORMAT_FLOAT2,
},
},
});
pass_action = (sg_pass_action){
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR,
.clear_value = { 0.1f, 0.1f, 0.1f, 1.f },
},
};
time_last = stm_now();
}
void app_frame(void) {
u64 dt_ticks = stm_laptime(&time_last);
float dt = (float)stm_sec(dt_ticks);
utils_update();
cam_update(&camera, dt);
float aspect_ratio = sapp_widthf() / sapp_heightf();
HMM_Mat4 view = cam_view(&camera);
HMM_Mat4 proj = cam_proj(&camera);
HMM_Mat4 model = HMM_Translate(HMM_V3(0, 0, -10));
// HMM_Mat4 vp = HMM_Mul(HMM_Mul(proj, view), model);
HMM_Mat4 vp = HMM_Mul(proj, view);
arena_rewind(&frame_arena, 0);
sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = sglue_swapchain() });
sg_apply_pipeline(pip);
sg_apply_uniforms(0, SG_RANGE_REF(vp));
for (int i = 0; i < scene.object_count; ++i) {
sg_apply_bindings(&scene.objects[i].bindings);
sg_draw(0, scene.objects[i].draw_count, 1);
}
sg_end_pass();
sg_commit();
}
void app_event(const sapp_event *e) {
switch (e->type) {
case SAPP_EVENTTYPE_KEY_UP:
case SAPP_EVENTTYPE_KEY_DOWN:
if (e->key_code == SAPP_KEYCODE_ESCAPE) {
sapp_quit();
return;
}
set_key_state(e->key_code, e->type == SAPP_EVENTTYPE_KEY_DOWN);
break;
case SAPP_EVENTTYPE_MOUSE_MOVE:
set_mouse_pos_and_delta(e->mouse_x, e->mouse_y, e->mouse_dx, e->mouse_dy);
break;
}
}
void app_cleanup(void) {
}
sapp_desc sokol_main(int argc, char* argv[]) {
return (sapp_desc) {
.width = 640,
.height = 480,
.window_title = "engine",
.logger.func = sokol_log_cb,
.init_cb = app_init,
.frame_cb = app_frame,
.cleanup_cb = app_cleanup,
.event_cb = app_event,
.win32 = {
.console_attach = true,
},
};
}
#define SOKOL_IMPL
#define STB_IMAGE_IMPLEMENTATION
#include "libs/sokol_app.h"
#include "libs/sokol_gfx.h"
#include "libs/sokol_time.h"
#include "libs/sokol_glue.h"
#include "libs/stb_image.h"

472
src/obj.c Normal file
View file

@ -0,0 +1,472 @@
#include "colla/colla.h"
#include "libs/sokol_gfx.h"
#include "libs/stb_image.h"
#define CGLTF_IMPLEMENTATION
#include "libs/cgltf.h"
#include "vecmath.h"
typedef struct vertex_t vertex_t;
struct vertex_t {
vec3 pos;
vec3 norm;
vec2 tex;
};
typedef struct material_t material_t;
struct material_t {
// texture
vec3 ambient_color;
vec3 diff_color;
/*
* (*) -> unused
* Ka: ambient color
* Kd: diffuse color
* Ks*: specular color
* Ns*: specular exponent
* d*: dissolve (opacity)
* Ni*: optical density (???)
* Ke*: emissive color
* illum*: illumination mode:
0. Color on and Ambient off
1. Color on and Ambient on
2. Highlight on
3. Reflection on and Ray trace on
4. Transparency: Glass on, Reflection: Ray trace on
5. Reflection: Fresnel on and Ray trace on
6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
8. Reflection on and Ray trace off
9. Transparency: Glass on, Reflection: Ray trace off
10. Casts shadows onto invisible surfaces
* */
};
typedef struct obj_t obj_t;
struct obj_t {
sg_bindings bindings;
u16 draw_count;
};
darr_define(f2_list_t, vec2);
darr_define(f3_list_t, vec3);
darr_define(i3_list_t, int3);
#define list_get(l, i) do { } while (0)
typedef struct {
f3_list_t *verts;
f3_list_t *norms;
f2_list_t *uvs;
i3_list_t *faces;
u32 vcount;
u32 ncount;
u32 tcount;
u32 fcount;
} obj_ctx_t;
#define READ_F2(arr, c) do { \
vec2 v = {0}; \
istr_skip_whitespace(in); istr_get_float(in, &v.x); \
istr_skip_whitespace(in); istr_get_float(in, &v.y); \
darr_push(arena, arr, v); \
++(c); \
} while (0)
#define READ_F3(arr, c) do { \
vec3 v = {0}; \
istr_skip_whitespace(in); istr_get_float(in, &v.x); \
istr_skip_whitespace(in); istr_get_float(in, &v.y); \
istr_skip_whitespace(in); istr_get_float(in, &v.z); \
darr_push(arena, arr, v); \
++(c); \
} while (0)
#define READ_I3(arr, c) do { \
int3 v = {0}; \
istr_skip_whitespace(in); istr_get_i32(in, &v.x); \
istr_skip_whitespace(in); istr_get_i32(in, &v.y); \
istr_skip_whitespace(in); istr_get_i32(in, &v.z); \
darr_push(arena, arr, v); \
++(c); \
} while (0)
void obj__parse_line(arena_t *arena, instream_t *in, obj_ctx_t *ctx) {
if (istr_peek(in) == '#') {
return;
}
switch (istr_peek(in)) {
// vertex stuff
case 'v':
istr_skip(in, 1);
switch (istr_get(in)) {
// vertex
case ' ':
READ_F3(ctx->verts, ctx->vcount);
break;
// normal
case 'n':
READ_F3(ctx->norms, ctx->ncount);
break;
// texture
case 't':
READ_F2(ctx->uvs, ctx->tcount);
break;
}
return;
// faces
case 'f':
READ_I3(ctx->faces, ctx->fcount);
return;
// smooth shading
case 's':
// not implemented
return;
// group
case 'g':
// not implemented
return;
// object
case 'o':
// not implemented
return;
case '#':
return;
}
strview_t word = istr_get_word(in);
if (strv_equals(word, strv("mtllib"))) {
// load mtl file
}
else if (strv_equals(word, strv("usemtl"))) {
// use material
}
}
obj_t obj_load(arena_t scratch, strview_t filename) {
obj_t out = {0};
str_t text = os_file_read_all_str(&scratch, filename);
instream_t in = istr_init(strv(text));
obj_ctx_t ctx = {0};
while (!istr_is_finished(&in)) {
instream_t line = istr_init(istr_get_line(&in));
obj__parse_line(&scratch, &line, &ctx);
}
debug("%u %u %u", ctx.vcount, ctx.ncount, ctx.tcount);
colla_assert(ctx.vcount == ctx.ncount && ctx.vcount == ctx.tcount);
// copy over vertex data
vertex_t *vertices = alloc(&scratch, vertex_t, ctx.vcount);
{
u32 i = 0;
for_each (v, ctx.verts) {
for (int k = 0; k < v->count; ++k) {
vertices[i++].pos = v->items[k];
}
}
}
{
u32 i = 0;
for_each (v, ctx.uvs) {
for (int k = 0; k < v->count; ++k) {
vertices[i++].tex = v->items[k];
}
}
}
{
u32 i = 0;
for_each (v, ctx.norms) {
for (int k = 0; k < v->count; ++k) {
vertices[i++].norm = v->items[k];
}
}
}
// copy over indices data
u32 icount = ctx.fcount * 3;
u16 *indices = alloc(&scratch, u16, icount);
{
u32 i = 0;
for_each (v, ctx.faces) {
for (int k = 0; k < v->count; ++k) {
indices[i++] = v->items[k].x - 1;
indices[i++] = v->items[k].y - 1;
indices[i++] = v->items[k].z - 1;
}
}
}
sg_buffer vertex_buffer = sg_make_buffer(&(sg_buffer_desc){
.data = {
.ptr = vertices,
.size = sizeof(vertex_t) * ctx.vcount,
},
.usage = {
.vertex_buffer = true,
.immutable = true,
},
});
sg_buffer index_buffer = sg_make_buffer(&(sg_buffer_desc){
.data = {
.ptr = indices,
.size = sizeof(u16) * ctx.fcount * 3,
},
.usage = {
.index_buffer = true,
.immutable = true,
},
});
return (obj_t){
.bindings = {
.vertex_buffers[0] = vertex_buffer,
.index_buffer = index_buffer,
// .views[0] = {0},
},
.draw_count = icount,
};
}
cgltf_result obj__cgltf_file_read_cb(
const cgltf_memory_options *m,
const cgltf_file_options *opt,
const char *path,
cgltf_size *size,
void **data
) {
debug("(cgltf) loading %s", path);
arena_t *arena = opt->user_data;
buffer_t buf = os_file_read_all(arena, strv(path));
if (!buf.data) {
return cgltf_result_io_error;
}
*data = buf.data;
*size = buf.len;
return cgltf_result_success;
}
void obj__cgltf_file_release_callback(
const cgltf_memory_options *m,
const cgltf_file_options *opt,
void *data,
cgltf_size size
) {
// no-op
}
#define MAX_SCENE_OBJECTS 64
typedef struct scene_t scene_t;
struct scene_t {
obj_t objects[MAX_SCENE_OBJECTS];
int object_count;
};
sg_image obj__load_texture(arena_t scratch, cgltf_texture *texture) {
if (!texture || !texture->image) {
return (sg_image){0};
}
cgltf_image *image = texture->image;
u8 *bytes = NULL;
usize size = 0;
if (image->uri) {
buffer_t buf = os_file_read_all(&scratch, strv(image->uri));
bytes = buf.data;
size = buf.len;
}
else if (image->buffer_view) {
cgltf_buffer_view *view = image->buffer_view;
bytes = (u8*)view->buffer->data + view->offset;
size = view->size;
}
else {
fatal("idk how do load this dog (%s)", texture->name);
}
int width, height, comp;
u8 *pixels = stbi_load_from_memory(bytes, (int)size, &width, &height, &comp, 4);
if (!pixels) {
fatal("(stbi) couldn't load image %s: %s", image->name, stbi_failure_reason());
}
sg_image out = sg_make_image(&(sg_image_desc){
.pixel_format = SG_PIXELFORMAT_RGBA8,
.width = width,
.height = height,
.data.mip_levels[0] = {
.ptr = pixels,
.size = width * height * 4,
},
});
stbi_image_free(pixels);
return out;
}
scene_t obj_load_gltf(arena_t scratch, strview_t filename) {
scene_t scene = {0};
str_t fname = str(&scratch, filename);
buffer_t buf = os_file_read_all(&scratch, filename);
cgltf_options options = {
.file = {
.read = obj__cgltf_file_read_cb,
.release = obj__cgltf_file_release_callback,
.user_data = &scratch,
},
};
cgltf_data *data = NULL;
cgltf_result result = cgltf_parse(
&options,
buf.data,
buf.len,
&data
);
if (result != cgltf_result_success) {
fatal("(cgltf) failed to load %v", filename);
return (scene_t){0};
}
result = cgltf_load_buffers(&options, data, fname.buf);
if (result != cgltf_result_success) {
fatal("(cgltf) failed to load %v's buffers", filename);
return (scene_t){0};
}
colla_assert(data->meshes_count == 1);
sg_sampler sampler = sg_make_sampler(&(sg_sampler_desc){
.min_filter = SG_FILTER_NEAREST,
.mag_filter = SG_FILTER_NEAREST,
});
u32 missing_texture[] = {
0xFFFF00FF, 0x00000000,
0x00000000, 0xFFFF00FF,
};
sg_image missing_img = sg_make_image(&(sg_image_desc){
.width = 2,
.height = 2,
.pixel_format = SG_PIXELFORMAT_RGBA8,
.data.mip_levels[0] = SG_RANGE(missing_texture),
});
for (usize i = 0; i < data->meshes_count; ++i) {
cgltf_mesh *mesh = &data->meshes[i];
colla_assert(MAX_SCENE_OBJECTS > mesh->primitives_count);
scene.object_count = mesh->primitives_count;
for (usize p = 0; p < mesh->primitives_count; ++p) {
cgltf_primitive *prim = &mesh->primitives[p];
obj_t *obj = &scene.objects[p];
// HACK: HELL!
usize vert_count = prim->attributes[0].data->count;
vertex_t *verts = alloc(&scratch, vertex_t, vert_count);
cgltf_accessor *in = prim->indices;
u16 *indices = alloc(&scratch, u16, in->count);
for (usize k = 0; k < in->count; ++k) {
indices[k] = (u16)cgltf_accessor_read_index(in, k);
}
cgltf_material *mat = prim->material;
cgltf_texture_view texture_view = mat->pbr_metallic_roughness.base_color_texture;
sg_image image = obj__load_texture(scratch, texture_view.texture);
if (image.id == 0) {
image = missing_img;
}
sg_view view = sg_make_view(&(sg_view_desc){
.texture.image = image,
});
obj->bindings.views[0] = view;
obj->bindings.samplers[0] = sampler;
for (usize a = 0; a < prim->attributes_count; ++a) {
cgltf_attribute *attr = &prim->attributes[a];
cgltf_accessor *acc = attr->data;
switch (attr->type) {
case cgltf_attribute_type_position:
{
for (usize k = 0; k < acc->count; ++k) {
cgltf_accessor_read_float(acc, k, verts[k].pos.data, 3);
}
break;
}
case cgltf_attribute_type_normal:
for (usize k = 0; k < acc->count; ++k) {
cgltf_accessor_read_float(acc, k, verts[k].norm.data, 3);
}
break;
case cgltf_attribute_type_texcoord:
for (usize k = 0; k < acc->count; ++k) {
cgltf_accessor_read_float(acc, k, verts[k].tex.data, 2);
}
break;
default: break;
}
}
sg_buffer vertex_buffer = sg_make_buffer(&(sg_buffer_desc){
.data = {
.ptr = verts,
.size = sizeof(vertex_t) * vert_count,
},
.usage = {
.vertex_buffer = true,
.immutable = true,
},
});
sg_buffer index_buffer = sg_make_buffer(&(sg_buffer_desc){
.data = {
.ptr = indices,
.size = sizeof(u16) * in->count,
},
.usage = {
.index_buffer = true,
.immutable = true,
},
});
obj->bindings.index_buffer = index_buffer;
obj->bindings.vertex_buffers[0] = vertex_buffer;
obj->draw_count = in->count;
}
}
cgltf_free(data);
return scene;
}

48
src/utils.c Normal file
View file

@ -0,0 +1,48 @@
#include "utils.h"
// memmove
#include <string.h>
#define KEY_COUNT (SAPP_KEYCODE_MENU + 1)
struct {
bool keys[KEY_COUNT];
bool prev_keys[KEY_COUNT];
HMM_Vec2 mouse_pos;
HMM_Vec2 mouse_delta;
int delta_frames_passed;
} utils_state = {0};
bool is_key_down(sapp_keycode k) {
return utils_state.keys[k];
}
bool is_key_pressed(sapp_keycode k) {
return !utils_state.prev_keys[k] && utils_state.keys[k];
}
void set_key_state(sapp_keycode k, bool is_down) {
utils_state.prev_keys[k] = utils_state.keys[k];
utils_state.keys[k] = is_down;
}
void utils_update(void) {
memmove(utils_state.prev_keys, utils_state.keys, sizeof(utils_state.keys));
if (utils_state.delta_frames_passed++ > 0) {
utils_state.mouse_delta = HMM_V2(0, 0);
}
}
HMM_Vec2 mouse_pos(void) {
return utils_state.mouse_pos;
}
HMM_Vec2 mouse_delta(void) {
return utils_state.mouse_delta;
}
void set_mouse_pos_and_delta(float x, float y, float dx, float dy) {
utils_state.mouse_pos = HMM_V2(x, y);
utils_state.mouse_delta = HMM_V2(dx, dy);
utils_state.delta_frames_passed = 0;
}

14
src/utils.h Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include "libs/sokol_app.h"
#include "libs/handmademath.h"
bool is_key_down(sapp_keycode k);
bool is_key_pressed(sapp_keycode k);
void set_key_state(sapp_keycode k, bool is_down);
HMM_Vec2 mouse_pos(void);
HMM_Vec2 mouse_delta(void);
void set_mouse_pos_and_delta(float x, float y, float dx, float dy);

181
src/vecmath.h Normal file
View file

@ -0,0 +1,181 @@
#pragma once
#include "colla/colla.h"
#include <math.h>
#include "libs/handmademath.h"
typedef union int2 {
int data[2];
struct { int x, y; };
} int2;
typedef union int3 {
int data[3];
struct { int x, y, z; };
} int3;
typedef union float2 {
HMM_Vec2 hm;
float data[2];
struct { float x, y; };
} vec2;
typedef union float3 {
HMM_Vec3 hm;
float data[3];
struct { float x, y, z; };
} vec3;
typedef union float4 {
HMM_Vec4 hm;
float data[4];
struct { float x, y, z, w; };
struct { float r, g, b, a; };
} vec4;
typedef union mat4 {
HMM_Mat4 hm;
float data[16];
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
};
} mat4;
#define clamp(val, vmin, vmax) \
_Generic((val), \
float: fclamp, \
float2: f2clamp, \
float3: f3clamp, \
float4: f4clamp \
)(val, vmin, vmax)
#define saturate(val) \
_Generic((val), \
float: fsaturate, \
float2: f2saturate, \
float3: f3saturate, \
float4: f4saturate \
)(val)
#define add(a, b) \
_Generic((a), \
float2: f2add, \
float3: f3add, \
float4: f4add \
)(a, b)
#define adds(v, s) \
_Generic((v), \
float2: f2adds, \
float3: f3adds, \
float4: f4adds \
)(v, s)
#define cross HMM_Cross
#define norm HMM_Norm
#define mul HMM_Mul
#define add HMM_Add
#define m4_lookat HMM_LookAt_LH
#define v3 HMM_V3
#define m4_proj HMM_Perspective_LH_ZO
#if 0
force_inline float fclamp(float val, float vmin, float vmax) {
return MIN(MAX(val, vmin), vmax);
}
force_inline float2 f2clamp(float2 val, float2 vmin, float2 vmax) {
return (float2) {
fclamp(val.x, vmin.x, vmax.x),
fclamp(val.y, vmin.y, vmax.y),
};
}
force_inline float3 f3clamp(float3 val, float3 vmin, float3 vmax) {
return (float3) {
fclamp(val.x, vmin.x, vmax.x),
fclamp(val.y, vmin.y, vmax.y),
fclamp(val.z, vmin.z, vmax.z),
};
}
force_inline float4 f4clamp(float4 val, float4 vmin, float4 vmax) {
return (float4) {
fclamp(val.x, vmin.x, vmax.x),
fclamp(val.y, vmin.y, vmax.y),
fclamp(val.z, vmin.z, vmax.z),
fclamp(val.w, vmin.w, vmax.w),
};
}
force_inline float2 f2add(float2 a, float2 b) {
return (float2) { a.x + b.x, a.y + b.y };
}
force_inline float3 f3add(float3 a, float3 b) {
return (float3) { a.x + b.x, a.y + b.y, a.z + b.z };
}
force_inline float4 f4add(float4 a, float4 b) {
return (float4) { a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w };
}
force_inline float2 f2adds(float2 v, float s) {
return (float2) { v.x + s, v.y + s };
}
force_inline float3 f3adds(float3 v, float s) {
return (float3) { v.x + s, v.y + s, v.z + s };
}
force_inline float4 f4adds(float4 v, float s) {
return (float4) { v.x + s, v.y + s, v.z + s, v.w + s };
}
force_inline float fsaturate(float v) {
return fclamp(v, 0, 1);
}
force_inline float2 f2saturate(float2 v) {
return f2clamp(v, (float2){0}, (float2){1,1});
}
force_inline float3 f3saturate(float3 v) {
return f3clamp(v, (float3){0}, (float3){1,1,1});
}
force_inline float4 f4saturate(float4 v) {
return f4clamp(v, (float4){0}, (float4){1,1,1,1});
}
force_inline float f3mag2(float3 v) {
return v.x * v.x + v.y * v.y + v.z * v.z;
}
force_inline float f3mag(float3 v) {
return sqrtf(f3mag2(v));
}
force_inline float3 f3muls(float3 v, float s) {
return (float3) {
.x = v.x * s,
.y = v.y * s,
.z = v.z * s,
};
}
force_inline float3 f3divs(float3 v, float s) {
s = 1.f / s;
return f3muls(v, s);
}
force_inline float3 f3norm(float3 v) {
float mag = f3mag(v);
if (mag == 0) return v;
return f3divs(v, mag);
}
#endif