Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6302d79dec | |||
| e59c83c8fb | |||
| 85699bba23 | |||
| 74a1ae3dee | |||
| 6859a56ad4 | |||
| e210e0d7f2 | |||
| 793987409f | |||
| 68ef854065 | |||
| d7e98f9464 | |||
| 0c40426500 | |||
| 0bb9be2d36 | |||
| d020f863ac | |||
| 0804e84ad4 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -55,3 +55,5 @@ dist/
|
|||||||
# Misc
|
# Misc
|
||||||
tags
|
tags
|
||||||
.cache/
|
.cache/
|
||||||
|
|
||||||
|
flake.lock
|
||||||
9
Makefile
9
Makefile
@ -1,19 +1,20 @@
|
|||||||
TARGET := main
|
TARGET := main
|
||||||
SRC_DIR := src
|
SRC_DIR := src
|
||||||
|
IMGUI_DIR := imgui
|
||||||
SHADER_DIR := shaders
|
SHADER_DIR := shaders
|
||||||
BUILD_DIR := build
|
BUILD_DIR := build
|
||||||
|
|
||||||
CXX := g++
|
CXX := g++
|
||||||
CXXFLAGS := -std=c++20 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Wno-unused-function
|
CXXFLAGS := -std=gnu++23 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Wno-unused-function # -fsanitize=address
|
||||||
LDFLAGS := -lSDL3
|
LDFLAGS := -lSDL3 -lSDL3_image
|
||||||
|
|
||||||
GLSLC := glslc
|
GLSLC := glslc
|
||||||
|
|
||||||
DEBUG ?= 0
|
DEBUG ?= 0
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
CXXFLAGS += -g -O0 -DDEBUG
|
CXXFLAGS += -g -O0 -DDEBUG -fsanitize=address
|
||||||
else
|
else
|
||||||
CXXFLAGS += -O2 -DNDEBUG
|
CXXFLAGS += -O3 -DNDEBUG
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
assets/bin/hl1.bin
Normal file
BIN
assets/bin/hl1.bin
Normal file
Binary file not shown.
BIN
assets/bin/hl1.bin.png
Normal file
BIN
assets/bin/hl1.bin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 MiB |
BIN
assets/bin/old.atlas.png
Normal file
BIN
assets/bin/old.atlas.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
assets/hl1.bsp
Normal file
BIN
assets/hl1.bsp
Normal file
Binary file not shown.
3901
assets/vox.obj
Normal file
3901
assets/vox.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
sdl3
|
sdl3
|
||||||
|
sdl3-image
|
||||||
|
imgui
|
||||||
glm
|
glm
|
||||||
gcc
|
gcc
|
||||||
shaderc
|
shaderc
|
||||||
|
|||||||
12
imgui.ini
Normal file
12
imgui.ini
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
|
||||||
|
[Window][Hello, World!]
|
||||||
|
Pos=92,127
|
||||||
|
Size=195,279
|
||||||
|
|
||||||
|
[Window][Kale Renderer]
|
||||||
|
Pos=60,60
|
||||||
|
Size=181,242
|
||||||
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
#version 450
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 uv;
|
|
||||||
layout(location = 0) out vec4 out_color;
|
|
||||||
layout(set = 2, binding = 0) uniform sampler2D screen;
|
|
||||||
|
|
||||||
layout(std140, set = 3, binding = 0) uniform UniformBlock {
|
|
||||||
mat4 model;
|
|
||||||
mat4 view;
|
|
||||||
mat4 projection;
|
|
||||||
float time;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
float road(float x) { return cos(x); }
|
|
||||||
|
|
||||||
vec3 backup(vec2 uv) {
|
|
||||||
float x_scale = time * 12.0;
|
|
||||||
float y_scale = uv.x;
|
|
||||||
|
|
||||||
uv.x *= x_scale;
|
|
||||||
uv.y *= 2.0;
|
|
||||||
uv.y -= 1.0;
|
|
||||||
uv.y /= 0.75;
|
|
||||||
uv.y /= y_scale;
|
|
||||||
|
|
||||||
float y = road(uv.x);
|
|
||||||
|
|
||||||
float dist = length(uv.y - y);
|
|
||||||
|
|
||||||
vec3 col = vec3(cos(time / 10.0)) - vec3(exp(-dist), cos(dist), sin(dist));
|
|
||||||
return (0.005 * (1.2 + abs(cos(time)))) / col;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int MAX_MARCH_STEPS = 64;
|
|
||||||
const float EPS_DIST = 1e-6;
|
|
||||||
|
|
||||||
float sdf(vec3 point) {
|
|
||||||
// return length(point - vec3(6.0 * sin(time), 8.0*abs(sin(time * 0.7)*cos(time)), 5.0 * cos(time * 1.2))) - 0.4;
|
|
||||||
float size = 8.0 + (3.0* sin(time));
|
|
||||||
vec3 s1_local = mod(point, vec3(size)) - vec3(size/2.0);
|
|
||||||
float s1 = length(s1_local) - 0.3;
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 getnormal(vec3 p) {
|
|
||||||
float e = EPS_DIST;
|
|
||||||
return normalize(vec3(
|
|
||||||
sdf(p + vec3(e, 0.0, 0.0)) - sdf(p - vec3(e, 0.0, 0.0)),
|
|
||||||
sdf(p + vec3(0.0, e, 0.0)) - sdf(p - vec3(0.0, e, 0.0)),
|
|
||||||
sdf(p + vec3(0.0, 0.0, e)) - sdf(p - vec3(0.0, 0.0, e))
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vec4 march(vec3 point, vec3 ray) {
|
|
||||||
float MAX_DEPTH = texture(screen, uv).w * 1000.0;
|
|
||||||
float totaldist = 0.0;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < MAX_MARCH_STEPS && totaldist < MAX_DEPTH; i += 1) {
|
|
||||||
float h = sdf(point);
|
|
||||||
point += h * ray;
|
|
||||||
if (h < EPS_DIST) {
|
|
||||||
return vec4(point, totaldist + h);
|
|
||||||
}
|
|
||||||
|
|
||||||
totaldist += h;
|
|
||||||
}
|
|
||||||
|
|
||||||
return vec4(-1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 camray() {
|
|
||||||
vec2 ndc = uv * 2.0 - 1.0;
|
|
||||||
ndc.y = -ndc.y;
|
|
||||||
vec4 clip = vec4(ndc, 1.0, 1.0);
|
|
||||||
vec4 view_pos = inverse(projection) * clip;
|
|
||||||
view_pos /= view_pos.w;
|
|
||||||
|
|
||||||
vec3 ray_dir_view = normalize(view_pos.xyz);
|
|
||||||
|
|
||||||
vec3 ray_dir_world = normalize((inverse(view) * vec4(ray_dir_view, 0.0)).xyz);
|
|
||||||
|
|
||||||
return ray_dir_world;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 camorigin() { return (inverse(view) * vec4(0, 0, 0, 1)).xyz; }
|
|
||||||
|
|
||||||
vec4 kernel() {
|
|
||||||
vec3 cam_pos = camorigin();
|
|
||||||
vec3 cam_ray = camray();
|
|
||||||
|
|
||||||
return march(cam_pos, cam_ray);
|
|
||||||
}
|
|
||||||
|
|
||||||
float t(float x, float y) { return length(texture(screen, vec2(x, y)).xyz); }
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
|
|
||||||
vec2 bg = (projection * view * vec4(uv, 1.0, 1.0)).xy;
|
|
||||||
vec3 b = backup(bg);
|
|
||||||
vec4 hit = kernel();
|
|
||||||
if (hit.w > 0.0 && ((t(uv.x, uv.y) < 0.01) || (hit.w < (texture(screen, uv).w * 1000.0)))) {
|
|
||||||
out_color = vec4(getnormal(hit.xyz), 1.0);
|
|
||||||
} else {
|
|
||||||
out_color = texture(screen, uv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,10 +5,15 @@ layout(location = 0) out vec4 out_color;
|
|||||||
layout(set = 2, binding = 0) uniform sampler2D screen;
|
layout(set = 2, binding = 0) uniform sampler2D screen;
|
||||||
|
|
||||||
layout(std140, set = 3, binding = 0) uniform UniformBlock {
|
layout(std140, set = 3, binding = 0) uniform UniformBlock {
|
||||||
mat4 model;
|
mat4 model;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
mat4 projection;
|
mat4 proj;
|
||||||
|
mat4 inv_view;
|
||||||
|
mat4 inv_proj;
|
||||||
|
vec4 cam_pos;
|
||||||
float time;
|
float time;
|
||||||
|
int post_mode;
|
||||||
|
vec2 atlas_adjust;
|
||||||
};
|
};
|
||||||
|
|
||||||
float t(float x, float y) { return length(texture(screen, vec2(x, y)).xyz); }
|
float t(float x, float y) { return length(texture(screen, vec2(x, y)).xyz); }
|
||||||
@ -36,11 +41,51 @@ float f(mat3 kernel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float brightness(vec3 color) {
|
||||||
|
return dot(color, vec3(0.299, 0.587, 0.114));
|
||||||
|
}
|
||||||
|
|
||||||
|
float dither() {
|
||||||
|
if(length(texture(screen, uv).xyz) == 0.0)
|
||||||
|
return 0.0;
|
||||||
|
vec2 coord = uv * textureSize(screen, 0).xy;
|
||||||
|
|
||||||
|
int x = int(mod(coord.x, 4.0));
|
||||||
|
int y = int(mod(coord.y, 4.0));
|
||||||
|
int index = x + y * 4;
|
||||||
|
|
||||||
|
float threshold[16] = float[](
|
||||||
|
0.0/16.0, 8.0/16.0, 2.0/16.0, 10.0/16.0,
|
||||||
|
12.0/16.0, 4.0/16.0, 14.0/16.0, 6.0/16.0,
|
||||||
|
3.0/16.0, 11.0/16.0, 1.0/16.0, 9.0/16.0,
|
||||||
|
15.0/16.0,7.0/16.0, 13.0/16.0, 5.0/16.0
|
||||||
|
);
|
||||||
|
|
||||||
|
vec3 color = texture(screen, uv).rgb;
|
||||||
|
|
||||||
|
return brightness(color) < threshold[index] ? 0.0 : 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const mat3 sobelx = mat3(-1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0);
|
const mat3 sobelx = mat3(-1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0);
|
||||||
|
|
||||||
const mat3 sobely = mat3(-1.0, 0.0, 1.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0);
|
const mat3 sobely = mat3(-1.0, 0.0, 1.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0);
|
||||||
|
|
||||||
out_color = texture(screen, uv) + ((t(uv.x, uv.y) > 0.01)?
|
switch(post_mode) {
|
||||||
vec4(abs(f(sobelx) + f(sobely)), 0.0, 0.0, 1.0) : vec4(0.0));
|
case 0:
|
||||||
|
out_color = texture(screen, uv);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
out_color = vec4(brightness(texture(screen, uv).xyz) < 0.5? 0.0 : 1.0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
out_color = vec4(dither());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
out_color = out_color * 0.9 +
|
||||||
|
0.1*((t(uv.x, uv.y) > 0.01)?
|
||||||
|
vec4(abs(f(sobelx) + f(sobely))) : vec4(0.0));
|
||||||
}
|
}
|
||||||
105
shaders/ray.frag
Normal file
105
shaders/ray.frag
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 uv;
|
||||||
|
layout(location = 0) out vec4 out_color;
|
||||||
|
layout(set = 2, binding = 0) uniform sampler2D screen;
|
||||||
|
layout(set = 2, binding = 1) uniform sampler2D depth_tex;
|
||||||
|
|
||||||
|
layout(std140, set = 3, binding = 0) uniform UniformBlock {
|
||||||
|
mat4 model;
|
||||||
|
mat4 view;
|
||||||
|
mat4 proj;
|
||||||
|
mat4 inv_view;
|
||||||
|
mat4 inv_proj;
|
||||||
|
vec4 cam_pos;
|
||||||
|
float time;
|
||||||
|
int post_mode;
|
||||||
|
vec2 atlas_adjust;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int MAX_MARCH_STEPS = 64;
|
||||||
|
const float EPS_DIST = 1e-6;
|
||||||
|
|
||||||
|
|
||||||
|
float sdf(vec3 point) {
|
||||||
|
vec3 p = point - cam_pos.xyz;
|
||||||
|
const float speed = 1.0 + exp(sin(time));
|
||||||
|
float t = speed * time;
|
||||||
|
const int N = 5;
|
||||||
|
float d = 1.0/EPS_DIST;
|
||||||
|
float orbit_radius = 0.4;
|
||||||
|
float radius = 0.03;
|
||||||
|
for(int i = 0; i < N; i++) {
|
||||||
|
float phase = ((3.14159 * 2.0) / float(N)) * float(i);
|
||||||
|
d = min(d, length(p - orbit_radius*vec3(sin(t + phase), 0.0, cos(t + phase))) - radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 getnormal(vec3 p) {
|
||||||
|
float e = EPS_DIST;
|
||||||
|
return normalize(vec3(
|
||||||
|
sdf(p + vec3(e, 0.0, 0.0)) - sdf(p - vec3(e, 0.0, 0.0)),
|
||||||
|
sdf(p + vec3(0.0, e, 0.0)) - sdf(p - vec3(0.0, e, 0.0)),
|
||||||
|
sdf(p + vec3(0.0, 0.0, e)) - sdf(p - vec3(0.0, 0.0, e))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 march(vec3 point, vec3 ray, float max_depth) {
|
||||||
|
float totaldist = 0.0;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < MAX_MARCH_STEPS && totaldist < max_depth; i += 1) {
|
||||||
|
float h = sdf(point);
|
||||||
|
|
||||||
|
if (h < EPS_DIST) {
|
||||||
|
totaldist += h;
|
||||||
|
return vec4(point, totaldist);
|
||||||
|
}
|
||||||
|
|
||||||
|
totaldist += h;
|
||||||
|
if (totaldist > max_depth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
point += h * ray;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vec4(-1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 camray() {
|
||||||
|
vec2 ndc = uv * 2.0 - 1.0;
|
||||||
|
ndc.y = -ndc.y;
|
||||||
|
vec4 view_pos = inv_proj * vec4(ndc, 1.0, 1.0);
|
||||||
|
view_pos /= view_pos.w;
|
||||||
|
return normalize((inv_view * vec4(normalize(view_pos.xyz), 0.0)).xyz);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 kernel(float max_depth) {
|
||||||
|
max_depth = (max_depth > 0.0)? max_depth : 1000.0;
|
||||||
|
vec3 cam_ray = camray();
|
||||||
|
|
||||||
|
return march(cam_pos.xyz, cam_ray, max_depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
float linearize_depth(vec2 uv) {
|
||||||
|
float d = texture(depth_tex, uv).r;
|
||||||
|
vec4 ndc = vec4(uv * 2.0 - 1.0, d * 2.0 - 1.0, 1.0);
|
||||||
|
vec4 view_pos = inv_proj * ndc;
|
||||||
|
view_pos /= view_pos.w;
|
||||||
|
return -view_pos.z; // view space, positive distance
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float max_depth = linearize_depth(uv);
|
||||||
|
vec4 hit = kernel(max_depth);
|
||||||
|
|
||||||
|
if (hit.w > 0.0) {
|
||||||
|
out_color = vec4(1.0);//out_color = vec4(getnormal(hit.xyz), 1.0);
|
||||||
|
} else {
|
||||||
|
out_color = texture(screen, uv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,10 +1,12 @@
|
|||||||
#version 460
|
#version 460
|
||||||
layout(location = 0) in vec4 v_color;
|
layout(location = 0) in vec4 v_color;
|
||||||
layout(location = 1) in float depth;
|
layout(location = 1) in vec2 v_uv;
|
||||||
layout(location = 2) in vec3 v_normal_vs;
|
layout(location = 2) in vec3 v_normal_vs;
|
||||||
|
|
||||||
layout(location = 0) out vec4 out_color;
|
layout(location = 0) out vec4 out_color;
|
||||||
|
|
||||||
|
layout(set = 2, binding = 0) uniform sampler2D atlas;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 light_dir = normalize(vec3(0.5, 1.0, 0.8));
|
vec3 light_dir = normalize(vec3(0.5, 1.0, 0.8));
|
||||||
|
|
||||||
@ -12,5 +14,11 @@ void main() {
|
|||||||
float diffuse = max(dot(v_normal_vs, light_dir), 0.0);
|
float diffuse = max(dot(v_normal_vs, light_dir), 0.0);
|
||||||
float lighting = ambient + (1.0 - ambient) * diffuse;
|
float lighting = ambient + (1.0 - ambient) * diffuse;
|
||||||
|
|
||||||
out_color = vec4(v_color.rgb * lighting, v_color.a);
|
vec2 uv = vec2(v_uv.x, 1.0-v_uv.y);
|
||||||
|
out_color = texture(atlas, uv);// + v_color;
|
||||||
|
//out_color = v_color * vec4(v_normal_vs,1.0);
|
||||||
|
//out_color = vec4(v_color.rgb * lighting, v_color.a);
|
||||||
|
//out_color = vec4(1.0);
|
||||||
|
//out_color = vec4(viz(v_normal_vs), 1.0);
|
||||||
|
//out_color = vec4(lighting);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,26 +1,29 @@
|
|||||||
#version 460
|
#version 460
|
||||||
layout(location = 0) in vec3 a_pos;
|
layout(location = 0) in vec3 a_pos;
|
||||||
layout(location = 1) in vec4 a_color;
|
layout(location = 1) in vec2 a_uv;
|
||||||
layout(location = 2) in vec3 a_normal;
|
layout(location = 2) in vec3 a_normal;
|
||||||
|
|
||||||
layout(location = 0) out vec4 v_color;
|
layout(location = 0) out vec4 v_color;
|
||||||
layout(location = 1) out float depth;
|
layout(location = 1) out vec2 v_uv;
|
||||||
layout(location = 2) out vec3 v_normal_vs; // view-space normal
|
layout(location = 2) out vec3 v_normal_vs; // view-space normal
|
||||||
|
|
||||||
layout(std140, set = 1, binding = 0) uniform UniformBlock {
|
layout(std140, set = 1, binding = 0) uniform UniformBlock {
|
||||||
mat4 model;
|
mat4 model;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
mat4 projection;
|
mat4 proj;
|
||||||
float time;
|
mat4 inv_view;
|
||||||
|
mat4 inv_proj;
|
||||||
|
vec4 cam_pos;
|
||||||
|
float time;
|
||||||
|
int post_mode;
|
||||||
|
vec2 atlas_adjust;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 view_pos = view * model * vec4(a_pos, 1.0);
|
vec4 view_pos = view * model * vec4(a_pos, 1.0);
|
||||||
depth = -view_pos.z / 1000.0;
|
gl_Position = proj * view_pos;
|
||||||
gl_Position = projection * view_pos;
|
v_color = vec4(a_uv, abs(sin(a_uv.x*a_uv.y)), 1.0);
|
||||||
v_color = a_color;
|
v_uv = a_uv*atlas_adjust;
|
||||||
|
|
||||||
// For uniform scale this shortcut is fine:
|
v_normal_vs = normalize(a_normal);
|
||||||
mat3 normal_mat = mat3(transpose(inverse(view * model)));
|
|
||||||
v_normal_vs = normalize(normal_mat * a_normal);
|
|
||||||
}
|
}
|
||||||
|
|||||||
270
src/BSP.cpp
Normal file
270
src/BSP.cpp
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
#include "bsp/BSP.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_iostream.h>
|
||||||
|
#include <SDL3/SDL_log.h>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
/* changes handedness by swapping z and y */
|
||||||
|
template<typename T>
|
||||||
|
static inline void change_swizzle(T& v) {
|
||||||
|
auto tmp = v.y;
|
||||||
|
v.y = v.z;
|
||||||
|
v.z = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace HLBSP;
|
||||||
|
|
||||||
|
static inline void copy_data(void* file_data, std::string& dst, Lump& lump) {
|
||||||
|
dst.resize(lump.len);
|
||||||
|
std::memcpy(dst.data(), (uint8_t*)file_data + (size_t)lump.offset, lump.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline void copy_data(void* file_data, std::vector<T>& dst, Lump& lump) {
|
||||||
|
dst.resize(lump.len / sizeof(T));
|
||||||
|
std::memcpy(dst.data(), ((uint8_t*)file_data) + lump.offset, lump.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline glm::vec2 calc_tex_coords(glm::vec3 v, const TexInfo& t) {
|
||||||
|
change_swizzle(v);
|
||||||
|
return glm::vec2(
|
||||||
|
t.shift_s + glm::dot(v, t.shift_s_dir),
|
||||||
|
t.shift_t + glm::dot(v, t.shift_t_dir)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BSP::load_vertices() {
|
||||||
|
SDL_Log("Loading vertices");
|
||||||
|
std::set<int> present_faces;
|
||||||
|
std::vector<Face> visible_faces;
|
||||||
|
// if (visibility_test) {
|
||||||
|
// auto leaf_idx = determine_leaf(cam_pos);
|
||||||
|
|
||||||
|
// auto fr_planes = frustum(view);
|
||||||
|
|
||||||
|
// if (leaf_idx == last_leaf)
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// last_leaf = leaf_idx;
|
||||||
|
// auto& cam_leaf = leaves[leaf_idx];
|
||||||
|
|
||||||
|
|
||||||
|
// std::vector<Leaf> visible_leafs;
|
||||||
|
// for (auto& leaf : leaves) {
|
||||||
|
|
||||||
|
// const auto min = leaf.bb_mins;
|
||||||
|
// const auto max = leaf.bb_maxes;
|
||||||
|
|
||||||
|
// const glm::vec3 bounding_planes[8] = {
|
||||||
|
// { min.x, min.y, min.z },
|
||||||
|
// { max.x, min.y, min.z },
|
||||||
|
// { max.x, max.y, min.z },
|
||||||
|
// { min.x, max.y, min.z },
|
||||||
|
// { min.x, min.y, max.z },
|
||||||
|
// { max.x, min.y, max.z },
|
||||||
|
// { max.x, max.y, max.z },
|
||||||
|
// { min.x, max.y, max.z },
|
||||||
|
// };
|
||||||
|
|
||||||
|
// if (determine_visibility(cam_leaf, leaf, fr_planes, bounding_planes))
|
||||||
|
// visible_leafs.push_back(leaf);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for (const auto& leaf : visible_leafs) {
|
||||||
|
// for (size_t i = 0; i < leaf.n_mark_surfaces; i++) {
|
||||||
|
// auto idx = mark_surfaces[leaf.first_mark_surface_idx + i];
|
||||||
|
// if (present_faces.contains(idx))
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// present_faces.insert(idx);
|
||||||
|
// visible_faces.push_back(faces[idx]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
visible_faces = faces;
|
||||||
|
// }
|
||||||
|
|
||||||
|
textured_vertices.clear();
|
||||||
|
|
||||||
|
for (auto& face : visible_faces) {
|
||||||
|
auto& tex_info = tex_infos[face.tex_info_idx];
|
||||||
|
|
||||||
|
for (int16_t i = 1, j = 2; j < face.n_surf_edges; i++, j++) {
|
||||||
|
vec3 pos[3] = {
|
||||||
|
processed_vertices[face.first_surf_edge_idx],
|
||||||
|
processed_vertices[face.first_surf_edge_idx+i],
|
||||||
|
processed_vertices[face.first_surf_edge_idx+j],
|
||||||
|
};
|
||||||
|
|
||||||
|
vec3 face_normal = glm::normalize(glm::cross(pos[1] - pos[0], pos[2] - pos[0]));
|
||||||
|
|
||||||
|
textured_vertices.push_back(Vertex{
|
||||||
|
.pos = pos[0],
|
||||||
|
.uv = calc_tex_coords(processed_vertices[face.first_surf_edge_idx], tex_info),
|
||||||
|
.norm = face_normal
|
||||||
|
});
|
||||||
|
textured_vertices.push_back(Vertex{
|
||||||
|
.pos = pos[1],
|
||||||
|
.uv = calc_tex_coords(processed_vertices[face.first_surf_edge_idx+i], tex_info),
|
||||||
|
.norm = face_normal
|
||||||
|
});
|
||||||
|
textured_vertices.push_back(Vertex{
|
||||||
|
.pos = pos[2],
|
||||||
|
.uv = calc_tex_coords(processed_vertices[face.first_surf_edge_idx+j], tex_info),
|
||||||
|
.norm = face_normal
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_Log("Done loading vertices");
|
||||||
|
}
|
||||||
|
|
||||||
|
int BSP::get_index_from_surfedge(int surfedge) {
|
||||||
|
int surf = surfedges[surfedge];
|
||||||
|
if(surf >= 0) {
|
||||||
|
return edges[surf].vertex_indices[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return edges[-surf].vertex_indices[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int BSP::determine_leaf(glm::vec3 cam_pos) {
|
||||||
|
/* use SDF of planes to determine relative position with respect to partitioning planes */
|
||||||
|
int idx = 0;
|
||||||
|
/* positive values are node indices, negative values are leaf indices */
|
||||||
|
while (idx >= 0) {
|
||||||
|
const auto& plane = planes[nodes[idx].plane];
|
||||||
|
const auto dist = glm::dot(plane.norm, cam_pos) - plane.dist;
|
||||||
|
|
||||||
|
if (dist >= 0)
|
||||||
|
idx = nodes[idx].children[0];
|
||||||
|
else
|
||||||
|
idx = nodes[idx].children[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return -idx - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool BSP::determine_visibility(const Leaf& cam_leaf, const Leaf& leaf, const std::array<glm::vec4, 6>& frustum, const glm::vec3 box_verts[8]) {
|
||||||
|
/* perform fustrum culling */
|
||||||
|
//return box_in_frustum(frustum, box_verts);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::map<std::string, std::string>> load_entities(const std::string& in) {
|
||||||
|
/* TODO */
|
||||||
|
return {
|
||||||
|
{{"test", "this"}},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<MipTexture> load_mip_textures(const u8* data, u32 offset) {
|
||||||
|
const TextureLump* lump = reinterpret_cast<const TextureLump*>(data + offset);
|
||||||
|
std::vector<MipTexture> ret;
|
||||||
|
ret.resize(lump->n_mip_textures);
|
||||||
|
|
||||||
|
for(size_t i = 0; i < ret.size(); i++) {
|
||||||
|
ret[i] = *reinterpret_cast<const MipTexture*>(data + lump->offsets[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
BSP::BSP(const std::string& fname) : filename(fname) {
|
||||||
|
size_t fsize;
|
||||||
|
uint8_t* fdata = (uint8_t*)SDL_LoadFile(fname.c_str(), &fsize);
|
||||||
|
if(!fdata) {
|
||||||
|
SDL_Log("Can't load bsp file: %s", fname.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_data.resize(fsize);
|
||||||
|
memcpy(file_data.data(), fdata, fsize);
|
||||||
|
header = reinterpret_cast<Header*>(file_data.data());
|
||||||
|
|
||||||
|
|
||||||
|
if(header->version != 30) {
|
||||||
|
SDL_Log("BSP file not expected version (Half Life has version 30)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Loading entities\n");
|
||||||
|
std::string entities_buff;
|
||||||
|
copy_data(file_data.data(), entities_buff, header->entities);
|
||||||
|
entities = load_entities(entities_buff);
|
||||||
|
|
||||||
|
SDL_Log("Loading planes\n");
|
||||||
|
copy_data(file_data.data(), planes, header->planes);
|
||||||
|
/* change swizzle */
|
||||||
|
for (auto& plane : planes) {
|
||||||
|
change_swizzle(plane.norm);
|
||||||
|
}
|
||||||
|
|
||||||
|
//SDL_Log("Loading textures\n");
|
||||||
|
//textures = load_mip_textures(file_data.data(), header->textures.offset);
|
||||||
|
|
||||||
|
SDL_Log("Loading vertices\n");
|
||||||
|
copy_data(file_data.data(), vertices, header->vertices);
|
||||||
|
for (auto& vertex : vertices) {
|
||||||
|
change_swizzle(vertex);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Loading nodes\n");
|
||||||
|
copy_data(file_data.data(), nodes, header->nodes);
|
||||||
|
for (auto& node : nodes) {
|
||||||
|
change_swizzle(node.bb_mins);
|
||||||
|
change_swizzle(node.bb_maxes);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Loading texinfo\n");
|
||||||
|
copy_data(file_data.data(), tex_infos, header->texinfo);
|
||||||
|
|
||||||
|
SDL_Log("Loading faces\n");
|
||||||
|
copy_data(file_data.data(), faces, header->faces);
|
||||||
|
|
||||||
|
SDL_Log("Loading lightmap\n");
|
||||||
|
lightmap.lights = reinterpret_cast<rgb*>(file_data.data()+header->lighting.offset);
|
||||||
|
|
||||||
|
SDL_Log("Loading clip nodes\n");
|
||||||
|
copy_data(file_data.data(), clip_nodes, header->clip_nodes);
|
||||||
|
|
||||||
|
SDL_Log("Loading leaves\n");
|
||||||
|
copy_data(file_data.data(), leaves, header->leaves);
|
||||||
|
for (auto& leaf : leaves) {
|
||||||
|
change_swizzle(leaf.bb_mins);
|
||||||
|
change_swizzle(leaf.bb_maxes);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Loading mark surfaces\n");
|
||||||
|
copy_data(file_data.data(), mark_surfaces, header->mark_surfaces);
|
||||||
|
|
||||||
|
SDL_Log("Loading edges\n");
|
||||||
|
copy_data(file_data.data(), edges, header->edges);
|
||||||
|
|
||||||
|
SDL_Log("Loading surfedges\n");
|
||||||
|
copy_data(file_data.data(), surfedges, header->surf_edges);
|
||||||
|
processed_vertices.reserve(surfedges.size());
|
||||||
|
/* use this to build our processed_vertices, idea thanks to gzalo's HalfMapper */
|
||||||
|
for(const auto& s : surfedges) {
|
||||||
|
processed_vertices.push_back(vertices[edges[s > 0? s : -s].vertex_indices[s<=0]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Loading models\n");
|
||||||
|
copy_data(file_data.data(), models, header->models);
|
||||||
|
for (auto& model : models) {
|
||||||
|
change_swizzle(model.bb_mins);
|
||||||
|
change_swizzle(model.bb_maxes);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t max_vertex_count = 0;
|
||||||
|
|
||||||
|
for (const auto& face : faces) {
|
||||||
|
max_vertex_count += (face.n_surf_edges - 2) * 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("Creating vertex buffer of size %zu\n", max_vertex_count);
|
||||||
|
textured_vertices.reserve(max_vertex_count);
|
||||||
|
}
|
||||||
207
src/bsp/BSP.h
Normal file
207
src/bsp/BSP.h
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_TEXTURE_NAME 16
|
||||||
|
#define MIP_LEVELS 4
|
||||||
|
|
||||||
|
struct SDL_GPUTexture;
|
||||||
|
|
||||||
|
#define MAX_MAP_HULLS 4
|
||||||
|
/* contains loading functions for Half Life BSPs */
|
||||||
|
namespace HLBSP {
|
||||||
|
|
||||||
|
struct Lump {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t len;
|
||||||
|
};
|
||||||
|
using rgb = glm::uvec3;
|
||||||
|
using rgba = glm::uvec4;
|
||||||
|
|
||||||
|
using vec3 = glm::vec3;
|
||||||
|
using vec2 = glm::vec2;
|
||||||
|
using ivec3 = glm::vec<3, int16_t>;
|
||||||
|
|
||||||
|
struct Header {
|
||||||
|
uint32_t version;
|
||||||
|
|
||||||
|
union {
|
||||||
|
Lump lumps[15];
|
||||||
|
struct {
|
||||||
|
Lump entities,
|
||||||
|
planes,
|
||||||
|
textures,
|
||||||
|
vertices,
|
||||||
|
visibility,
|
||||||
|
nodes,
|
||||||
|
texinfo,
|
||||||
|
faces,
|
||||||
|
lighting,
|
||||||
|
clip_nodes,
|
||||||
|
leaves,
|
||||||
|
mark_surfaces,
|
||||||
|
edges,
|
||||||
|
surf_edges,
|
||||||
|
models;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Plane {
|
||||||
|
vec3 norm;
|
||||||
|
float dist;
|
||||||
|
/* exists for certain optimizations (swaped y and z) */
|
||||||
|
enum PlaneType {
|
||||||
|
eX,
|
||||||
|
eZ,
|
||||||
|
eY,
|
||||||
|
eAnyX,
|
||||||
|
eAnyZ,
|
||||||
|
eAnyY,
|
||||||
|
} type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TextureLump {
|
||||||
|
uint32_t n_mip_textures;
|
||||||
|
int32_t offsets[];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MipTexture {
|
||||||
|
char name[MAX_TEXTURE_NAME];
|
||||||
|
uint32_t width, height;
|
||||||
|
/* is 0 if stored in WAD, otherwise, offset is from beginning of this struct */
|
||||||
|
uint32_t mip_offsets[MIP_LEVELS];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Vis {};
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
int32_t plane;
|
||||||
|
/* negative numbers are leaf indices */
|
||||||
|
int16_t children[2];
|
||||||
|
|
||||||
|
/* bounding box coords (integer) */
|
||||||
|
ivec3 bb_mins;
|
||||||
|
ivec3 bb_maxes;
|
||||||
|
|
||||||
|
int16_t first_face_idx;
|
||||||
|
int16_t n_faces;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TexInfo {
|
||||||
|
vec3 shift_s_dir;
|
||||||
|
float shift_s;
|
||||||
|
vec3 shift_t_dir;
|
||||||
|
float shift_t;
|
||||||
|
uint32_t mip_tex_idx;
|
||||||
|
/* seems to always be 0 */
|
||||||
|
uint32_t flags;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Face {
|
||||||
|
uint16_t plane_idx;
|
||||||
|
/* set if different normals orientation */
|
||||||
|
uint16_t plane_side;
|
||||||
|
uint32_t first_surf_edge_idx;
|
||||||
|
int16_t n_surf_edges;
|
||||||
|
int16_t tex_info_idx;
|
||||||
|
uint8_t lighting_styles[4];
|
||||||
|
uint32_t lightmap_offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Lightmap {
|
||||||
|
rgb* lights;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClipNode {
|
||||||
|
int32_t plane_idx;
|
||||||
|
/* negative numbers are contents */
|
||||||
|
int16_t children[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Leaf {
|
||||||
|
enum {
|
||||||
|
eEmpty = -1,
|
||||||
|
eSolid = -2,
|
||||||
|
eWater = -3,
|
||||||
|
eSlime = -4,
|
||||||
|
eLava = -5,
|
||||||
|
eSky = -6,
|
||||||
|
eOrigin = -7,
|
||||||
|
eClip = -8,
|
||||||
|
eCurrent0 = -9,
|
||||||
|
eCurrent90 = -10,
|
||||||
|
eCurrent180 = -11,
|
||||||
|
eCurrent270 = -12,
|
||||||
|
eCurrentUp = -13,
|
||||||
|
eCurrentDown = -14,
|
||||||
|
eTranslucent = -15,
|
||||||
|
} contents;
|
||||||
|
/* if this is -1, no VIS data */
|
||||||
|
int32_t vis_offset;
|
||||||
|
ivec3 bb_mins;
|
||||||
|
ivec3 bb_maxes;
|
||||||
|
uint16_t first_mark_surface_idx;
|
||||||
|
uint16_t n_mark_surfaces;
|
||||||
|
uint8_t ambient_sound_levels[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef uint16_t MarkSurface;
|
||||||
|
|
||||||
|
struct Edge {
|
||||||
|
uint16_t vertex_indices[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef int32_t Surfedge;
|
||||||
|
|
||||||
|
struct Model {
|
||||||
|
vec3 bb_mins;
|
||||||
|
vec3 bb_maxes;
|
||||||
|
vec3 origin;
|
||||||
|
int32_t head_node_indices[MAX_MAP_HULLS];
|
||||||
|
int32_t vis_leafs;
|
||||||
|
int32_t first_face_idx;
|
||||||
|
int32_t n_faces;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BSP {
|
||||||
|
BSP(const std::string& fname);
|
||||||
|
void load_vertices();
|
||||||
|
int determine_leaf(vec3 cam_pos);
|
||||||
|
bool determine_visibility(const Leaf& cam_leaf, const Leaf& leaf, const std::array<glm::vec4, 6>& frustum, const vec3 box_verts[8]);
|
||||||
|
int get_index_from_surfedge(int surfedge);
|
||||||
|
|
||||||
|
Header* header;
|
||||||
|
std::string filename;
|
||||||
|
std::vector<uint8_t> file_data;
|
||||||
|
|
||||||
|
std::vector<::std::map<::std::string, std::string>> entities;
|
||||||
|
std::vector<Plane> planes;
|
||||||
|
std::vector<MipTexture> textures;
|
||||||
|
std::vector<glm::vec3> vertices;
|
||||||
|
std::vector<glm::vec3> processed_vertices;
|
||||||
|
/* skipping vis for now */
|
||||||
|
std::vector<Node> nodes;
|
||||||
|
std::vector<TexInfo> tex_infos;
|
||||||
|
std::vector<Face> faces;
|
||||||
|
Lightmap lightmap;
|
||||||
|
std::vector<ClipNode> clip_nodes;
|
||||||
|
std::vector<Leaf> leaves;
|
||||||
|
std::vector<MarkSurface> mark_surfaces;
|
||||||
|
std::vector<Edge> edges;
|
||||||
|
std::vector<Surfedge> surfedges;
|
||||||
|
std::vector<Model> models;
|
||||||
|
|
||||||
|
std::vector<Vertex> textured_vertices;
|
||||||
|
/* to eliminate needless re-loading*/
|
||||||
|
int last_leaf = -0x1337;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1,4 +1,14 @@
|
|||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include <SDL3/SDL_gamepad.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
I bought a very cheap ps4 knockoff controller and for some reason
|
||||||
|
AXIS_RIGHTX and AXIS_RIGHTY are swapped with the triggers?
|
||||||
|
this should be defined as 0 for a working one
|
||||||
|
*/
|
||||||
|
#define WEIRD_JOYSTICK_BEHAVIOR 1
|
||||||
|
|
||||||
vec3 Camera::dir() const {
|
vec3 Camera::dir() const {
|
||||||
return normalize(vec3(
|
return normalize(vec3(
|
||||||
@ -18,6 +28,7 @@ void Camera::update() {
|
|||||||
vec3 d = dir();
|
vec3 d = dir();
|
||||||
vec3 right = normalize(cross(d, up));
|
vec3 right = normalize(cross(d, up));
|
||||||
target = pos + d;
|
target = pos + d;
|
||||||
|
|
||||||
float shift_speed = shifted? 10.0 : 1.0;
|
float shift_speed = shifted? 10.0 : 1.0;
|
||||||
float speed = move_speed * shift_speed;
|
float speed = move_speed * shift_speed;
|
||||||
|
|
||||||
@ -43,12 +54,79 @@ void Camera::on_key(SDL_Scancode scancode, bool pressed) {
|
|||||||
case SDL_SCANCODE_RIGHT: look_right = pressed; break;
|
case SDL_SCANCODE_RIGHT: look_right = pressed; break;
|
||||||
case SDL_SCANCODE_LSHIFT:
|
case SDL_SCANCODE_LSHIFT:
|
||||||
case SDL_SCANCODE_RSHIFT:
|
case SDL_SCANCODE_RSHIFT:
|
||||||
shifted |= pressed;
|
shifted = pressed;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WEIRD_JOYSTICK_BEHAVIOR
|
||||||
|
#define WEIRD_JOYSTICK_BEHAVIOR 0
|
||||||
|
#endif
|
||||||
|
static float normalize_stick(SDL_Gamepad* gamepad, SDL_GamepadAxis axis) {
|
||||||
|
if(axis == SDL_GAMEPAD_AXIS_COUNT || axis == SDL_GAMEPAD_AXIS_INVALID)
|
||||||
|
return 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
float d = static_cast<float>(SDL_GetGamepadAxis(gamepad, axis));
|
||||||
|
|
||||||
|
bool reported_trigger = (axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER || axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||||
|
bool really_trigger = (WEIRD_JOYSTICK_BEHAVIOR)? (axis == SDL_GAMEPAD_AXIS_RIGHTX || axis == SDL_GAMEPAD_AXIS_RIGHTY) : reported_trigger;
|
||||||
|
|
||||||
|
float min = (reported_trigger)? 0 : SDL_JOYSTICK_AXIS_MIN;
|
||||||
|
float max = SDL_JOYSTICK_AXIS_MAX;
|
||||||
|
float n = (d - min) / (max - min);
|
||||||
|
|
||||||
|
return really_trigger? n : ((n - 0.5) * 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::on_gamepad(SDL_Gamepad* gamepad) {
|
||||||
|
if (!gamepad) return;
|
||||||
|
|
||||||
|
float lx = normalize_stick(gamepad, SDL_GAMEPAD_AXIS_LEFTX);
|
||||||
|
float ly = normalize_stick(gamepad, SDL_GAMEPAD_AXIS_LEFTY);
|
||||||
|
float ry = normalize_stick(gamepad, (WEIRD_JOYSTICK_BEHAVIOR)? SDL_GAMEPAD_AXIS_RIGHT_TRIGGER : SDL_GAMEPAD_AXIS_RIGHTY);
|
||||||
|
float rx = normalize_stick(gamepad, (WEIRD_JOYSTICK_BEHAVIOR)? SDL_GAMEPAD_AXIS_LEFT_TRIGGER : SDL_GAMEPAD_AXIS_RIGHTX);
|
||||||
|
static uint8_t frame = 0;
|
||||||
|
if(frame++ == 64) {
|
||||||
|
std::cout << "lx: " << lx << " ly: " << ly << " rx: " << rx << " ry: " << ry << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//float lt = SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) / 32767.0f;
|
||||||
|
//float rt = SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) / 32767.0f;
|
||||||
|
|
||||||
|
const float dead = 0.1f;
|
||||||
|
if (abs(lx) < dead) lx = 0.0f;
|
||||||
|
if (abs(ly) < dead) ly = 0.0f;
|
||||||
|
if (abs(rx) < dead) rx = 0.0f;
|
||||||
|
if (abs(ry) < dead) ry = 0.0f;
|
||||||
|
// if (lt < dead) lt = 0.0f;
|
||||||
|
// if (rt < dead) rt = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
// look — right stick only
|
||||||
|
yaw += rx * look_speed;
|
||||||
|
pitch -= ry * look_speed;
|
||||||
|
pitch = clamp(pitch, -89.0f, 89.0f);
|
||||||
|
|
||||||
|
|
||||||
|
vec3 d = dir();
|
||||||
|
vec3 right = normalize(cross(d, up));
|
||||||
|
float speed = move_speed * (shifted ? 4.0f : 1.0f);
|
||||||
|
|
||||||
|
// move — left stick
|
||||||
|
pos += d * (-ly * speed);
|
||||||
|
pos += right * ( lx * speed);
|
||||||
|
|
||||||
|
// up/down — triggers
|
||||||
|
//pos += up * (rt - lt) * speed;
|
||||||
|
|
||||||
|
target = pos + d;
|
||||||
|
|
||||||
|
shifted = SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
|
||||||
|
}
|
||||||
|
|
||||||
void Camera::on_mouse_motion(float dx, float dy) {
|
void Camera::on_mouse_motion(float dx, float dy) {
|
||||||
yaw += dx * look_speed * 0.1f;
|
yaw += dx * look_speed * 0.1f;
|
||||||
pitch -= dy * look_speed * 0.1f;
|
pitch -= dy * look_speed * 0.1f;
|
||||||
@ -56,10 +134,15 @@ void Camera::on_mouse_motion(float dx, float dy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CameraUBO Camera::ubo(float aspect) const {
|
CameraUBO Camera::ubo(float aspect) const {
|
||||||
|
mat4 v = lookAt(pos, target, up);
|
||||||
|
mat4 p = perspective(radians(fov), aspect, 0.01f, 1000.0f);
|
||||||
return CameraUBO {
|
return CameraUBO {
|
||||||
.model = mat4(1.0f),
|
.model = mat4(1.0f),
|
||||||
.view = lookAt(pos, target, up),
|
.view = v,
|
||||||
.proj = perspective(radians(fov), aspect, 0.01f, 1000.0f),
|
.proj = p,
|
||||||
.time = (float)SDL_GetTicks() / 1000.0f,
|
.inv_view = inverse(v),
|
||||||
|
.inv_proj = inverse(p),
|
||||||
|
.cam_pos = vec4(pos, 1.0),
|
||||||
|
.time = (float)SDL_GetTicks() / 1000.0f,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ struct Camera {
|
|||||||
vec3 target = vec3(0.0f, 0.0f, 0.0f);
|
vec3 target = vec3(0.0f, 0.0f, 0.0f);
|
||||||
vec3 up = vec3(0.0f, 1.0f, 0.0f);
|
vec3 up = vec3(0.0f, 1.0f, 0.0f);
|
||||||
float fov = 60.0f;
|
float fov = 60.0f;
|
||||||
float move_speed = 0.05f;
|
float move_speed = 0.5f;
|
||||||
float look_speed = 1.0f;
|
float look_speed = 1.0f;
|
||||||
float pitch = 0.0f;
|
float pitch = 0.0f;
|
||||||
float yaw = -90.0f;
|
float yaw = -90.0f;
|
||||||
@ -28,6 +28,7 @@ struct Camera {
|
|||||||
void update();
|
void update();
|
||||||
void on_key(SDL_Scancode scancode, bool pressed);
|
void on_key(SDL_Scancode scancode, bool pressed);
|
||||||
void on_mouse_motion(float dx, float dy);
|
void on_mouse_motion(float dx, float dy);
|
||||||
|
void on_gamepad(SDL_Gamepad* gamepad);
|
||||||
CameraUBO ubo(float aspect) const;
|
CameraUBO ubo(float aspect) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
147
src/imconfig.h
Normal file
147
src/imconfig.h
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// DEAR IMGUI COMPILE-TIME OPTIONS
|
||||||
|
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||||
|
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||||
|
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||||
|
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||||
|
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||||
|
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---- Define assertion handler. Defaults to calling assert().
|
||||||
|
// - If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||||
|
// - Compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes.
|
||||||
|
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||||
|
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||||
|
|
||||||
|
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||||
|
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||||
|
// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||||
|
//#define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export
|
||||||
|
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
||||||
|
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
||||||
|
|
||||||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
|
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||||
|
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||||
|
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty.
|
||||||
|
|
||||||
|
//---- Don't implement some functions to reduce linkage requirements.
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||||
|
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
|
||||||
|
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||||
|
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FONT // Disable default embedded fonts (ProggyClean/ProggyForever), remove ~9 KB + ~14 KB from output binary. AddFontDefaultXXX() functions will assert.
|
||||||
|
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||||
|
|
||||||
|
//---- Enable Test Engine / Automation features.
|
||||||
|
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
||||||
|
|
||||||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||||
|
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
//#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h"
|
||||||
|
|
||||||
|
//---- Pack vertex colors as BGRA8 instead of RGBA8 (to avoid converting from one to another). Need dedicated backend support.
|
||||||
|
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||||
|
|
||||||
|
//---- Use legacy CRC32-adler tables (used before 1.91.6), in order to preserve old .ini data that you cannot afford to invalidate.
|
||||||
|
//#define IMGUI_USE_LEGACY_CRC32_ADLER
|
||||||
|
|
||||||
|
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||||
|
//#define IMGUI_USE_WCHAR32
|
||||||
|
|
||||||
|
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||||
|
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||||
|
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||||
|
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||||
|
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
|
||||||
|
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||||
|
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||||
|
//#define IMGUI_USE_STB_SPRINTF
|
||||||
|
|
||||||
|
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||||
|
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||||
|
// Note that imgui_freetype.cpp may be used _without_ this define, if you manually call ImFontAtlas::SetFontLoader(). The define is simply a convenience.
|
||||||
|
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE
|
||||||
|
|
||||||
|
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
|
||||||
|
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||||||
|
// - plutosvg is currently easier to install, as e.g. it is part of vcpkg. It will support more fonts and may load them faster. See misc/freetype/README for instructions.
|
||||||
|
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
|
||||||
|
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
|
||||||
|
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||||
|
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||||
|
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||||
|
|
||||||
|
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||||
|
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||||
|
/*
|
||||||
|
#define IM_VEC2_CLASS_EXTRA \
|
||||||
|
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||||
|
operator MyVec2() const { return MyVec2(x,y); }
|
||||||
|
|
||||||
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
|
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||||
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
|
*/
|
||||||
|
//---- ...Or use Dear ImGui's own very basic math operators.
|
||||||
|
//#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||||
|
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||||
|
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||||
|
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||||
|
//#define ImDrawIdx unsigned int
|
||||||
|
|
||||||
|
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||||
|
//struct ImDrawList;
|
||||||
|
//struct ImDrawCmd;
|
||||||
|
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||||
|
//#define ImDrawCallback MyImDrawCallback
|
||||||
|
|
||||||
|
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
|
||||||
|
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||||
|
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||||
|
//#define IM_DEBUG_BREAK __debugbreak()
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable highlight ID conflicts _before_ hovering items. When io.ConfigDebugHighlightIdConflicts is set.
|
||||||
|
// (THIS WILL SLOW DOWN DEAR IMGUI. Only use occasionally and disable after use)
|
||||||
|
//#define IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable slower asserts
|
||||||
|
//#define IMGUI_DEBUG_PARANOID
|
||||||
|
|
||||||
|
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
|
||||||
|
/*
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
void MyFunction(const char* name, MyMatrix44* mtx);
|
||||||
|
}
|
||||||
|
*/
|
||||||
18333
src/imgui.cpp
Normal file
18333
src/imgui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4232
src/imgui.h
Normal file
4232
src/imgui.h
Normal file
File diff suppressed because it is too large
Load Diff
11099
src/imgui_demo.cpp
Normal file
11099
src/imgui_demo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
6746
src/imgui_draw.cpp
Normal file
6746
src/imgui_draw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
887
src/imgui_impl_sdl3.cpp
Normal file
887
src/imgui_impl_sdl3.cpp
Normal file
@ -0,0 +1,887 @@
|
|||||||
|
// dear imgui: Platform Backend for SDL3
|
||||||
|
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||||
|
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
|
// [X] Platform: Gamepad support.
|
||||||
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
|
// [X] Platform: IME support.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// CHANGELOG
|
||||||
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL3_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235)
|
||||||
|
// 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168)
|
||||||
|
// 2025-11-05: Fixed an issue with missing characters events when an already active text field changes viewports. (#9054)
|
||||||
|
// 2025-10-22: Fixed Platform_OpenInShellFn() return value (unused in core).
|
||||||
|
// 2025-09-24: Skip using the SDL_GetGlobalMouseState() state when one of our window is hovered, as the SDL_EVENT_MOUSE_MOTION data is reliable. Fix macOS notch mouse coordinates issue in fullscreen mode + better perf on X11. (#7919, #7786)
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
|
// 2025-09-15: Use SDL_GetWindowDisplayScale() on Mac to output DisplayFrameBufferScale. The function is more reliable during resolution changes e.g. going fullscreen. (#8703, #4414)
|
||||||
|
// 2025-06-27: IME: avoid calling SDL_StartTextInput() again if already active. (#8727)
|
||||||
|
// 2025-04-22: IME: honor ImGuiPlatformImeData->WantTextInput as an alternative way to call SDL_StartTextInput(), without IME being necessarily visible.
|
||||||
|
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
|
||||||
|
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
|
||||||
|
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
||||||
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
|
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650)
|
||||||
|
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
||||||
|
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
||||||
|
// 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler.
|
||||||
|
// 2025-01-20: Made ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode_Manual) accept an empty array.
|
||||||
|
// 2024-10-24: Emscripten: SDL_EVENT_MOUSE_WHEEL event doesn't require dividing by 100.0f on Emscripten.
|
||||||
|
// 2024-09-03: Update for SDL3 api changes: SDL_GetGamepads() memory ownership revert. (#7918, #7898, #7807)
|
||||||
|
// 2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
|
||||||
|
// - io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn
|
||||||
|
// - io.SetClipboardTextFn -> platform_io.Platform_SetClipboardTextFn
|
||||||
|
// - io.PlatformSetImeDataFn -> platform_io.Platform_SetImeDataFn
|
||||||
|
// 2024-08-19: Storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
|
||||||
|
// 2024-08-19: ImGui_ImplSDL3_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
|
||||||
|
// 2024-07-22: Update for SDL3 api changes: SDL_GetGamepads() memory ownership change. (#7807)
|
||||||
|
// 2024-07-18: Update for SDL3 api changes: SDL_GetClipboardText() memory ownership change. (#7801)
|
||||||
|
// 2024-07-15: Update for SDL3 api changes: SDL_GetProperty() change to SDL_GetPointerProperty(). (#7794)
|
||||||
|
// 2024-07-02: Update for SDL3 api changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762).
|
||||||
|
// 2024-07-01: Update for SDL3 api changes: SDL_SetTextInputRect() changed to SDL_SetTextInputArea().
|
||||||
|
// 2024-06-26: Update for SDL3 api changes: SDL_StartTextInput()/SDL_StopTextInput()/SDL_SetTextInputRect() functions signatures.
|
||||||
|
// 2024-06-24: Update for SDL3 api changes: SDL_EVENT_KEY_DOWN/SDL_EVENT_KEY_UP contents.
|
||||||
|
// 2024-06-03; Update for SDL3 api changes: SDL_SYSTEM_CURSOR_ renames.
|
||||||
|
// 2024-05-15: Update for SDL3 api changes: SDLK_ renames.
|
||||||
|
// 2024-04-15: Inputs: Re-enable calling SDL_StartTextInput()/SDL_StopTextInput() as SDL3 no longer enables it by default and should play nicer with IME.
|
||||||
|
// 2024-02-13: Inputs: Fixed gamepad support. Handle gamepad disconnection. Added ImGui_ImplSDL3_SetGamepadMode().
|
||||||
|
// 2023-11-13: Updated for recent SDL3 API changes.
|
||||||
|
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
||||||
|
// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391)
|
||||||
|
// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
|
||||||
|
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
||||||
|
// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
|
||||||
|
// 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog.
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
|
||||||
|
// Clang warnings with -Weverything
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||||
|
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// SDL
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <stdio.h> // for snprintf()
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
||||||
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
||||||
|
#else
|
||||||
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME-LEGACY: remove when SDL 3.1.3 preview is released.
|
||||||
|
#ifndef SDLK_APOSTROPHE
|
||||||
|
#define SDLK_APOSTROPHE SDLK_QUOTE
|
||||||
|
#endif
|
||||||
|
#ifndef SDLK_GRAVE
|
||||||
|
#define SDLK_GRAVE SDLK_BACKQUOTE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// SDL Data
|
||||||
|
struct ImGui_ImplSDL3_Data
|
||||||
|
{
|
||||||
|
SDL_Window* Window;
|
||||||
|
SDL_WindowID WindowID;
|
||||||
|
SDL_Renderer* Renderer;
|
||||||
|
Uint64 Time;
|
||||||
|
char* ClipboardTextData;
|
||||||
|
char BackendPlatformName[48];
|
||||||
|
|
||||||
|
// IME handling
|
||||||
|
SDL_Window* ImeWindow;
|
||||||
|
ImGuiPlatformImeData ImeData;
|
||||||
|
bool ImeDirty;
|
||||||
|
|
||||||
|
// Mouse handling
|
||||||
|
Uint32 MouseWindowID;
|
||||||
|
int MouseButtonsDown;
|
||||||
|
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||||
|
SDL_Cursor* MouseLastCursor;
|
||||||
|
int MousePendingLeaveFrame;
|
||||||
|
bool MouseCanUseGlobalState;
|
||||||
|
ImGui_ImplSDL3_MouseCaptureMode MouseCaptureMode;
|
||||||
|
|
||||||
|
// Gamepad handling
|
||||||
|
ImVector<SDL_Gamepad*> Gamepads;
|
||||||
|
ImGui_ImplSDL3_GamepadMode GamepadMode;
|
||||||
|
bool WantUpdateGamepadsList;
|
||||||
|
|
||||||
|
ImGui_ImplSDL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||||
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||||
|
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||||
|
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||||
|
static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL3_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
static const char* ImGui_ImplSDL3_GetClipboardText(ImGuiContext*)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (bd->ClipboardTextData)
|
||||||
|
SDL_free(bd->ClipboardTextData);
|
||||||
|
if (SDL_HasClipboardText())
|
||||||
|
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
else
|
||||||
|
bd->ClipboardTextData = nullptr;
|
||||||
|
return bd->ClipboardTextData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_SetClipboardText(ImGuiContext*, const char* text)
|
||||||
|
{
|
||||||
|
SDL_SetClipboardText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImGuiViewport* ImGui_ImplSDL3_GetViewportForWindowID(SDL_WindowID window_id)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
return (window_id == bd->WindowID) ? ImGui::GetMainViewport() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport*, ImGuiPlatformImeData* data)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
bd->ImeData = *data;
|
||||||
|
bd->ImeDirty = true;
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We discard viewport passed via ImGuiPlatformImeData and always call SDL_StartTextInput() on SDL_GetKeyboardFocus().
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGuiPlatformImeData* data = &bd->ImeData;
|
||||||
|
SDL_Window* window = SDL_GetKeyboardFocus();
|
||||||
|
|
||||||
|
// Stop previous input
|
||||||
|
if ((!(data->WantVisible || data->WantTextInput) || bd->ImeWindow != window) && bd->ImeWindow != nullptr)
|
||||||
|
{
|
||||||
|
SDL_StopTextInput(bd->ImeWindow);
|
||||||
|
bd->ImeWindow = nullptr;
|
||||||
|
}
|
||||||
|
if ((!bd->ImeDirty && bd->ImeWindow == window) || (window == nullptr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Start/update current input
|
||||||
|
bd->ImeDirty = false;
|
||||||
|
if (data->WantVisible)
|
||||||
|
{
|
||||||
|
SDL_Rect r;
|
||||||
|
r.x = (int)data->InputPos.x;
|
||||||
|
r.y = (int)data->InputPos.y;
|
||||||
|
r.w = 1;
|
||||||
|
r.h = (int)data->InputLineHeight;
|
||||||
|
SDL_SetTextInputArea(window, &r, 0);
|
||||||
|
bd->ImeWindow = window;
|
||||||
|
}
|
||||||
|
if (!SDL_TextInputActive(window) && (data->WantVisible || data->WantTextInput))
|
||||||
|
SDL_StartTextInput(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not static to allow third-party code to use that if they want to (but undocumented)
|
||||||
|
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode);
|
||||||
|
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
|
||||||
|
{
|
||||||
|
// Keypad doesn't have individual key values in SDL3
|
||||||
|
switch (scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_KP_0: return ImGuiKey_Keypad0;
|
||||||
|
case SDL_SCANCODE_KP_1: return ImGuiKey_Keypad1;
|
||||||
|
case SDL_SCANCODE_KP_2: return ImGuiKey_Keypad2;
|
||||||
|
case SDL_SCANCODE_KP_3: return ImGuiKey_Keypad3;
|
||||||
|
case SDL_SCANCODE_KP_4: return ImGuiKey_Keypad4;
|
||||||
|
case SDL_SCANCODE_KP_5: return ImGuiKey_Keypad5;
|
||||||
|
case SDL_SCANCODE_KP_6: return ImGuiKey_Keypad6;
|
||||||
|
case SDL_SCANCODE_KP_7: return ImGuiKey_Keypad7;
|
||||||
|
case SDL_SCANCODE_KP_8: return ImGuiKey_Keypad8;
|
||||||
|
case SDL_SCANCODE_KP_9: return ImGuiKey_Keypad9;
|
||||||
|
case SDL_SCANCODE_KP_PERIOD: return ImGuiKey_KeypadDecimal;
|
||||||
|
case SDL_SCANCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||||
|
case SDL_SCANCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||||
|
case SDL_SCANCODE_KP_MINUS: return ImGuiKey_KeypadSubtract;
|
||||||
|
case SDL_SCANCODE_KP_PLUS: return ImGuiKey_KeypadAdd;
|
||||||
|
case SDL_SCANCODE_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||||
|
case SDL_SCANCODE_KP_EQUALS: return ImGuiKey_KeypadEqual;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
switch (keycode)
|
||||||
|
{
|
||||||
|
case SDLK_TAB: return ImGuiKey_Tab;
|
||||||
|
case SDLK_LEFT: return ImGuiKey_LeftArrow;
|
||||||
|
case SDLK_RIGHT: return ImGuiKey_RightArrow;
|
||||||
|
case SDLK_UP: return ImGuiKey_UpArrow;
|
||||||
|
case SDLK_DOWN: return ImGuiKey_DownArrow;
|
||||||
|
case SDLK_PAGEUP: return ImGuiKey_PageUp;
|
||||||
|
case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
|
||||||
|
case SDLK_HOME: return ImGuiKey_Home;
|
||||||
|
case SDLK_END: return ImGuiKey_End;
|
||||||
|
case SDLK_INSERT: return ImGuiKey_Insert;
|
||||||
|
case SDLK_DELETE: return ImGuiKey_Delete;
|
||||||
|
case SDLK_BACKSPACE: return ImGuiKey_Backspace;
|
||||||
|
case SDLK_SPACE: return ImGuiKey_Space;
|
||||||
|
case SDLK_RETURN: return ImGuiKey_Enter;
|
||||||
|
case SDLK_ESCAPE: return ImGuiKey_Escape;
|
||||||
|
//case SDLK_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||||
|
case SDLK_COMMA: return ImGuiKey_Comma;
|
||||||
|
//case SDLK_MINUS: return ImGuiKey_Minus;
|
||||||
|
case SDLK_PERIOD: return ImGuiKey_Period;
|
||||||
|
//case SDLK_SLASH: return ImGuiKey_Slash;
|
||||||
|
case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
|
||||||
|
//case SDLK_EQUALS: return ImGuiKey_Equal;
|
||||||
|
//case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||||
|
//case SDLK_BACKSLASH: return ImGuiKey_Backslash;
|
||||||
|
//case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||||
|
//case SDLK_GRAVE: return ImGuiKey_GraveAccent;
|
||||||
|
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
|
||||||
|
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
||||||
|
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
|
||||||
|
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
||||||
|
case SDLK_PAUSE: return ImGuiKey_Pause;
|
||||||
|
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
|
||||||
|
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
|
||||||
|
case SDLK_LALT: return ImGuiKey_LeftAlt;
|
||||||
|
case SDLK_LGUI: return ImGuiKey_LeftSuper;
|
||||||
|
case SDLK_RCTRL: return ImGuiKey_RightCtrl;
|
||||||
|
case SDLK_RSHIFT: return ImGuiKey_RightShift;
|
||||||
|
case SDLK_RALT: return ImGuiKey_RightAlt;
|
||||||
|
case SDLK_RGUI: return ImGuiKey_RightSuper;
|
||||||
|
case SDLK_APPLICATION: return ImGuiKey_Menu;
|
||||||
|
case SDLK_0: return ImGuiKey_0;
|
||||||
|
case SDLK_1: return ImGuiKey_1;
|
||||||
|
case SDLK_2: return ImGuiKey_2;
|
||||||
|
case SDLK_3: return ImGuiKey_3;
|
||||||
|
case SDLK_4: return ImGuiKey_4;
|
||||||
|
case SDLK_5: return ImGuiKey_5;
|
||||||
|
case SDLK_6: return ImGuiKey_6;
|
||||||
|
case SDLK_7: return ImGuiKey_7;
|
||||||
|
case SDLK_8: return ImGuiKey_8;
|
||||||
|
case SDLK_9: return ImGuiKey_9;
|
||||||
|
case SDLK_A: return ImGuiKey_A;
|
||||||
|
case SDLK_B: return ImGuiKey_B;
|
||||||
|
case SDLK_C: return ImGuiKey_C;
|
||||||
|
case SDLK_D: return ImGuiKey_D;
|
||||||
|
case SDLK_E: return ImGuiKey_E;
|
||||||
|
case SDLK_F: return ImGuiKey_F;
|
||||||
|
case SDLK_G: return ImGuiKey_G;
|
||||||
|
case SDLK_H: return ImGuiKey_H;
|
||||||
|
case SDLK_I: return ImGuiKey_I;
|
||||||
|
case SDLK_J: return ImGuiKey_J;
|
||||||
|
case SDLK_K: return ImGuiKey_K;
|
||||||
|
case SDLK_L: return ImGuiKey_L;
|
||||||
|
case SDLK_M: return ImGuiKey_M;
|
||||||
|
case SDLK_N: return ImGuiKey_N;
|
||||||
|
case SDLK_O: return ImGuiKey_O;
|
||||||
|
case SDLK_P: return ImGuiKey_P;
|
||||||
|
case SDLK_Q: return ImGuiKey_Q;
|
||||||
|
case SDLK_R: return ImGuiKey_R;
|
||||||
|
case SDLK_S: return ImGuiKey_S;
|
||||||
|
case SDLK_T: return ImGuiKey_T;
|
||||||
|
case SDLK_U: return ImGuiKey_U;
|
||||||
|
case SDLK_V: return ImGuiKey_V;
|
||||||
|
case SDLK_W: return ImGuiKey_W;
|
||||||
|
case SDLK_X: return ImGuiKey_X;
|
||||||
|
case SDLK_Y: return ImGuiKey_Y;
|
||||||
|
case SDLK_Z: return ImGuiKey_Z;
|
||||||
|
case SDLK_F1: return ImGuiKey_F1;
|
||||||
|
case SDLK_F2: return ImGuiKey_F2;
|
||||||
|
case SDLK_F3: return ImGuiKey_F3;
|
||||||
|
case SDLK_F4: return ImGuiKey_F4;
|
||||||
|
case SDLK_F5: return ImGuiKey_F5;
|
||||||
|
case SDLK_F6: return ImGuiKey_F6;
|
||||||
|
case SDLK_F7: return ImGuiKey_F7;
|
||||||
|
case SDLK_F8: return ImGuiKey_F8;
|
||||||
|
case SDLK_F9: return ImGuiKey_F9;
|
||||||
|
case SDLK_F10: return ImGuiKey_F10;
|
||||||
|
case SDLK_F11: return ImGuiKey_F11;
|
||||||
|
case SDLK_F12: return ImGuiKey_F12;
|
||||||
|
case SDLK_F13: return ImGuiKey_F13;
|
||||||
|
case SDLK_F14: return ImGuiKey_F14;
|
||||||
|
case SDLK_F15: return ImGuiKey_F15;
|
||||||
|
case SDLK_F16: return ImGuiKey_F16;
|
||||||
|
case SDLK_F17: return ImGuiKey_F17;
|
||||||
|
case SDLK_F18: return ImGuiKey_F18;
|
||||||
|
case SDLK_F19: return ImGuiKey_F19;
|
||||||
|
case SDLK_F20: return ImGuiKey_F20;
|
||||||
|
case SDLK_F21: return ImGuiKey_F21;
|
||||||
|
case SDLK_F22: return ImGuiKey_F22;
|
||||||
|
case SDLK_F23: return ImGuiKey_F23;
|
||||||
|
case SDLK_F24: return ImGuiKey_F24;
|
||||||
|
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
||||||
|
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to scancode
|
||||||
|
switch (scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_GRAVE: return ImGuiKey_GraveAccent;
|
||||||
|
case SDL_SCANCODE_MINUS: return ImGuiKey_Minus;
|
||||||
|
case SDL_SCANCODE_EQUALS: return ImGuiKey_Equal;
|
||||||
|
case SDL_SCANCODE_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||||
|
case SDL_SCANCODE_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||||
|
case SDL_SCANCODE_NONUSBACKSLASH: return ImGuiKey_Oem102;
|
||||||
|
case SDL_SCANCODE_BACKSLASH: return ImGuiKey_Backslash;
|
||||||
|
case SDL_SCANCODE_SEMICOLON: return ImGuiKey_Semicolon;
|
||||||
|
case SDL_SCANCODE_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||||
|
case SDL_SCANCODE_COMMA: return ImGuiKey_Comma;
|
||||||
|
case SDL_SCANCODE_PERIOD: return ImGuiKey_Period;
|
||||||
|
case SDL_SCANCODE_SLASH: return ImGuiKey_Slash;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return ImGuiKey_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
switch (event->type)
|
||||||
|
{
|
||||||
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->motion.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||||||
|
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_MOUSE_WHEEL:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->wheel.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
||||||
|
float wheel_x = -event->wheel.x;
|
||||||
|
float wheel_y = event->wheel.y;
|
||||||
|
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||||
|
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->button.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
int mouse_button = -1;
|
||||||
|
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
||||||
|
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
||||||
|
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
|
||||||
|
if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
|
||||||
|
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
|
||||||
|
if (mouse_button == -1)
|
||||||
|
break;
|
||||||
|
io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN));
|
||||||
|
bd->MouseButtonsDown = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_TEXT_INPUT:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->text.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
io.AddInputCharactersUTF8(event->text.text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
case SDL_EVENT_KEY_UP:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->key.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.mod);
|
||||||
|
//IMGUI_DEBUG_LOG("SDL_EVENT_KEY_%s : key=%d ('%s'), scancode=%d ('%s'), mod=%X\n",
|
||||||
|
// (event->type == SDL_EVENT_KEY_DOWN) ? "DOWN" : "UP ", event->key.key, SDL_GetKeyName(event->key.key), event->key.scancode, SDL_GetScancodeName(event->key.scancode), event->key.mod);
|
||||||
|
ImGuiKey key = ImGui_ImplSDL3_KeyEventToImGuiKey(event->key.key, event->key.scancode);
|
||||||
|
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
|
||||||
|
io.SetKeyEventNativeData(key, (int)event->key.key, (int)event->key.scancode, (int)event->key.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
bd->MouseWindowID = event->window.windowID;
|
||||||
|
bd->MousePendingLeaveFrame = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
||||||
|
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
|
||||||
|
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
|
||||||
|
// FIXME: Unconfirmed whether this is still needed with SDL3.
|
||||||
|
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
bd->MousePendingLeaveFrame = ImGui::GetFrameCount() + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||||
|
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
io.AddFocusEvent(event->type == SDL_EVENT_WINDOW_FOCUS_GAINED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_GAMEPAD_ADDED:
|
||||||
|
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||||
|
{
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window)
|
||||||
|
{
|
||||||
|
viewport->PlatformHandle = (void*)(intptr_t)SDL_GetWindowID(window);
|
||||||
|
viewport->PlatformHandleRaw = nullptr;
|
||||||
|
#if defined(_WIN32) && !defined(__WINRT__)
|
||||||
|
viewport->PlatformHandleRaw = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
viewport->PlatformHandleRaw = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, nullptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||||
|
IM_UNUSED(sdl_gl_context); // Unused in this branch
|
||||||
|
//SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
|
||||||
|
|
||||||
|
const int ver_linked = SDL_GetVersion();
|
||||||
|
|
||||||
|
// Setup backend capabilities flags
|
||||||
|
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
||||||
|
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl3 (%d.%d.%d; %d.%d.%d)",
|
||||||
|
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION, SDL_VERSIONNUM_MAJOR(ver_linked), SDL_VERSIONNUM_MINOR(ver_linked), SDL_VERSIONNUM_MICRO(ver_linked));
|
||||||
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
|
io.BackendPlatformName = bd->BackendPlatformName;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
|
|
||||||
|
bd->Window = window;
|
||||||
|
bd->WindowID = SDL_GetWindowID(window);
|
||||||
|
bd->Renderer = renderer;
|
||||||
|
|
||||||
|
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
||||||
|
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||||
|
bd->MouseCanUseGlobalState = false;
|
||||||
|
bd->MouseCaptureMode = ImGui_ImplSDL3_MouseCaptureMode_Disabled;
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
||||||
|
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||||
|
for (const char* item : capture_and_global_state_whitelist)
|
||||||
|
if (strncmp(sdl_backend, item, strlen(item)) == 0)
|
||||||
|
{
|
||||||
|
bd->MouseCanUseGlobalState = true;
|
||||||
|
bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL3_MouseCaptureMode_Enabled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
||||||
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
||||||
|
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL3_PlatformSetImeData;
|
||||||
|
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url); };
|
||||||
|
|
||||||
|
// Gamepad handling
|
||||||
|
bd->GamepadMode = ImGui_ImplSDL3_GamepadMode_AutoFirst;
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
|
||||||
|
// Load mouse cursors
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_MOVE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NESW_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NWSE_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Wait] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Progress] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_PROGRESS);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
|
||||||
|
|
||||||
|
// Set platform dependent data in viewport
|
||||||
|
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||||
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
|
ImGui_ImplSDL3_SetupPlatformHandles(main_viewport, window);
|
||||||
|
|
||||||
|
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
||||||
|
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
||||||
|
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
||||||
|
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
||||||
|
// you can ignore SDL_EVENT_MOUSE_BUTTON_DOWN events coming right after a SDL_EVENT_WINDOW_FOCUS_GAINED)
|
||||||
|
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||||
|
|
||||||
|
// From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
|
||||||
|
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should technically be a SDL_GLContext but due to typedef it is sane to keep it void* in public interface.
|
||||||
|
bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, sdl_gl_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window)
|
||||||
|
{
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
IM_ASSERT(0 && "Unsupported");
|
||||||
|
#endif
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, renderer, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForOther(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
if (bd->ClipboardTextData)
|
||||||
|
SDL_free(bd->ClipboardTextData);
|
||||||
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
|
SDL_DestroyCursor(bd->MouseCursors[cursor_n]);
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
|
||||||
|
io.BackendPlatformName = nullptr;
|
||||||
|
io.BackendPlatformUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (mode == ImGui_ImplSDL3_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL3_MouseCaptureMode_Disabled)
|
||||||
|
SDL_CaptureMouse(false);
|
||||||
|
bd->MouseCaptureMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateMouseData()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
||||||
|
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture.
|
||||||
|
if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_Enabled)
|
||||||
|
{
|
||||||
|
SDL_CaptureMouse(bd->MouseButtonsDown != 0);
|
||||||
|
}
|
||||||
|
else if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag)
|
||||||
|
{
|
||||||
|
bool want_capture = false;
|
||||||
|
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
||||||
|
if (ImGui::IsMouseDragging(button_n, 1.0f))
|
||||||
|
want_capture = true;
|
||||||
|
SDL_CaptureMouse(want_capture);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
||||||
|
const bool is_app_focused = (bd->Window == focused_window);
|
||||||
|
#else
|
||||||
|
SDL_Window* focused_window = bd->Window;
|
||||||
|
const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
|
||||||
|
#endif
|
||||||
|
if (is_app_focused)
|
||||||
|
{
|
||||||
|
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when io.ConfigNavMoveSetMousePos is enabled by user)
|
||||||
|
if (io.WantSetMousePos)
|
||||||
|
SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y);
|
||||||
|
|
||||||
|
// (Optional) Fallback to provide unclamped mouse position when focused but not hovered (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured)
|
||||||
|
// Note that SDL_GetGlobalMouseState() is in theory slow on X11, but this only runs on rather specific cases. If a problem we may provide a way to opt-out this feature.
|
||||||
|
SDL_Window* hovered_window = SDL_GetMouseFocus();
|
||||||
|
const bool is_relative_mouse_mode = SDL_GetWindowRelativeMouseMode(bd->Window);
|
||||||
|
if (hovered_window == nullptr && bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
||||||
|
{
|
||||||
|
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
||||||
|
float mouse_x, mouse_y;
|
||||||
|
int window_x, window_y;
|
||||||
|
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||||
|
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
||||||
|
mouse_x -= (float)window_x;
|
||||||
|
mouse_y -= (float)window_y;
|
||||||
|
io.AddMousePosEvent(mouse_x, mouse_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateMouseCursor()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||||
|
return;
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
|
||||||
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
|
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||||
|
{
|
||||||
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
|
SDL_HideCursor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Show OS mouse cursor
|
||||||
|
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
||||||
|
if (bd->MouseLastCursor != expected_cursor)
|
||||||
|
{
|
||||||
|
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
||||||
|
bd->MouseLastCursor = expected_cursor;
|
||||||
|
}
|
||||||
|
SDL_ShowCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_CloseGamepads()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
SDL_CloseGamepad(gamepad);
|
||||||
|
bd->Gamepads.resize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array, int manual_gamepads_count)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
if (mode == ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
{
|
||||||
|
IM_ASSERT(manual_gamepads_array != nullptr || manual_gamepads_count <= 0);
|
||||||
|
for (int n = 0; n < manual_gamepads_count; n++)
|
||||||
|
bd->Gamepads.push_back(manual_gamepads_array[n]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IM_ASSERT(manual_gamepads_array == nullptr && manual_gamepads_count <= 0);
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
}
|
||||||
|
bd->GamepadMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepadButton(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadButton button_no)
|
||||||
|
{
|
||||||
|
bool merged_value = false;
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
merged_value |= SDL_GetGamepadButton(gamepad, button_no) != 0;
|
||||||
|
io.AddKeyEvent(key, merged_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepadAnalog(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadAxis axis_no, float v0, float v1)
|
||||||
|
{
|
||||||
|
float merged_value = 0.0f;
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
{
|
||||||
|
float vn = Saturate((float)(SDL_GetGamepadAxis(gamepad, axis_no) - v0) / (float)(v1 - v0));
|
||||||
|
if (merged_value < vn)
|
||||||
|
merged_value = vn;
|
||||||
|
}
|
||||||
|
io.AddKeyAnalogEvent(key, merged_value > 0.1f, merged_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepads()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
|
||||||
|
// Update list of gamepads to use
|
||||||
|
if (bd->WantUpdateGamepadsList && bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
int sdl_gamepads_count = 0;
|
||||||
|
SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count);
|
||||||
|
for (int n = 0; n < sdl_gamepads_count; n++)
|
||||||
|
if (SDL_Gamepad* gamepad = SDL_OpenGamepad(sdl_gamepads[n]))
|
||||||
|
{
|
||||||
|
bd->Gamepads.push_back(gamepad);
|
||||||
|
if (bd->GamepadMode == ImGui_ImplSDL3_GamepadMode_AutoFirst)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bd->WantUpdateGamepadsList = false;
|
||||||
|
SDL_free(sdl_gamepads);
|
||||||
|
}
|
||||||
|
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||||
|
if (bd->Gamepads.Size == 0)
|
||||||
|
return;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
|
|
||||||
|
// Update gamepad inputs
|
||||||
|
const int thumb_dead_zone = 8000; // SDL_gamepad.h suggests using this value.
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadStart, SDL_GAMEPAD_BUTTON_START);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadBack, SDL_GAMEPAD_BUTTON_BACK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceLeft, SDL_GAMEPAD_BUTTON_WEST); // Xbox X, PS Square
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceRight, SDL_GAMEPAD_BUTTON_EAST); // Xbox B, PS Circle
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceUp, SDL_GAMEPAD_BUTTON_NORTH); // Xbox Y, PS Triangle
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceDown, SDL_GAMEPAD_BUTTON_SOUTH); // Xbox A, PS Cross
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadLeft, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadRight, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadUp, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadDown, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL1, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR1, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadL2, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 0.0f, 32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadR2, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, 0.0f, 32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL3, SDL_GAMEPAD_BUTTON_LEFT_STICK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR3, SDL_GAMEPAD_BUTTON_RIGHT_STICK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickLeft, SDL_GAMEPAD_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickRight, SDL_GAMEPAD_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickUp, SDL_GAMEPAD_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickDown, SDL_GAMEPAD_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickLeft, SDL_GAMEPAD_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickRight, SDL_GAMEPAD_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickUp, SDL_GAMEPAD_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickDown, SDL_GAMEPAD_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(SDL_Window* window, ImVec2* out_size, ImVec2* out_framebuffer_scale)
|
||||||
|
{
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
|
||||||
|
w = h = 0;
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
float fb_scale_x = SDL_GetWindowDisplayScale(window); // Seems more reliable during resolution change (#8703)
|
||||||
|
float fb_scale_y = fb_scale_x;
|
||||||
|
#else
|
||||||
|
int display_w, display_h;
|
||||||
|
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
|
||||||
|
float fb_scale_x = (w > 0) ? (float)display_w / (float)w : 1.0f;
|
||||||
|
float fb_scale_y = (h > 0) ? (float)display_h / (float)h : 1.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (out_size != nullptr)
|
||||||
|
*out_size = ImVec2((float)w, (float)h);
|
||||||
|
if (out_framebuffer_scale != nullptr)
|
||||||
|
*out_framebuffer_scale = ImVec2(fb_scale_x, fb_scale_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_NewFrame()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Setup main viewport size (every frame to accommodate for window resizing)
|
||||||
|
ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(bd->Window, &io.DisplaySize, &io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup time step (we could also use SDL_GetTicksNS() available since SDL3)
|
||||||
|
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
|
||||||
|
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||||
|
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||||
|
if (current_time <= bd->Time)
|
||||||
|
current_time = bd->Time + 1;
|
||||||
|
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / (double)frequency) : (float)(1.0f / 60.0f);
|
||||||
|
bd->Time = current_time;
|
||||||
|
|
||||||
|
if (bd->MousePendingLeaveFrame && bd->MousePendingLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||||||
|
{
|
||||||
|
bd->MouseWindowID = 0;
|
||||||
|
bd->MousePendingLeaveFrame = 0;
|
||||||
|
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplSDL3_UpdateMouseData();
|
||||||
|
ImGui_ImplSDL3_UpdateMouseCursor();
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
|
||||||
|
// Update game controllers (if enabled and available)
|
||||||
|
ImGui_ImplSDL3_UpdateGamepads();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
54
src/imgui_impl_sdl3.h
Normal file
54
src/imgui_impl_sdl3.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// dear imgui: Platform Backend for SDL3
|
||||||
|
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||||
|
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
|
// [X] Platform: Gamepad support.
|
||||||
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
|
// [X] Platform: IME support.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
struct SDL_Window;
|
||||||
|
struct SDL_Renderer;
|
||||||
|
struct SDL_Gamepad;
|
||||||
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOther(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame();
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
|
||||||
|
|
||||||
|
// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
|
||||||
|
// When using manual mode, caller is responsible for opening/closing gamepad.
|
||||||
|
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
||||||
|
|
||||||
|
// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it.
|
||||||
|
// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse.
|
||||||
|
// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650.
|
||||||
|
// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL3_MouseCaptureMode_Disabled.
|
||||||
|
enum ImGui_ImplSDL3_MouseCaptureMode { ImGui_ImplSDL3_MouseCaptureMode_Enabled, ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL3_MouseCaptureMode_Disabled };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode);
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
706
src/imgui_impl_sdlgpu3.cpp
Normal file
706
src/imgui_impl_sdlgpu3.cpp
Normal file
@ -0,0 +1,706 @@
|
|||||||
|
// dear imgui: Renderer Backend for SDL_GPU
|
||||||
|
// This needs to be used along with the SDL3 Platform Backend
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'SDL_GPUTexture*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef! **IMPORTANT** Before 2025/08/08, ImTextureID was a reference to a SDL_GPUTextureSamplerBinding struct.
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
|
||||||
|
// The aim of imgui_impl_sdlgpu3.h/.cpp is to be usable in your engine without any modification.
|
||||||
|
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// Important note to the reader who wish to integrate imgui_impl_sdlgpu3.cpp/.h in their own engine/app.
|
||||||
|
// - Unlike other backends, the user must call the function ImGui_ImplSDLGPU3_PrepareDrawData() BEFORE issuing a SDL_GPURenderPass containing ImGui_ImplSDLGPU3_RenderDrawData.
|
||||||
|
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
|
||||||
|
|
||||||
|
// CHANGELOG
|
||||||
|
// 2026-04-23: Added support for standard draw callbacks (in platform_io): DrawCallback_ResetRenderState, DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest. Obsoleting samplers from ImGui_ImplSDLGPU3_RenderState. (#9378)
|
||||||
|
// 2026-03-19: Fixed issue in ImGui_ImplSDLGPU3_DestroyTexture() if ImTextureID_Invalid is defined to be != 0, which became the default since 2026-03-12. (#9295, #9310)
|
||||||
|
// 2026-02-25: Removed unnecessary call to SDL_WaitForGPUIdle when releasing vertex/index buffers. (#9262)
|
||||||
|
// 2025-11-26: macOS version can use MSL shaders in order to support macOS 10.14+ (vs Metallib shaders requiring macOS 14+). Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL.
|
||||||
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
|
// 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created.
|
||||||
|
// 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988)
|
||||||
|
// 2025-08-08: Expose SamplerDefault and SamplerCurrent in ImGui_ImplSDLGPU3_RenderState. Allow callback to change sampler.
|
||||||
|
// 2025-06-25: Mapping transfer buffer for texture update use cycle=true. Fixes artifacts e.g. on Metal backend.
|
||||||
|
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLGPU3_CreateFontsTexture() and ImGui_ImplSDLGPU3_DestroyFontsTexture().
|
||||||
|
// 2025-04-28: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
||||||
|
// 2025-03-30: Made ImGui_ImplSDLGPU3_PrepareDrawData() reuse GPU Transfer Buffers which were unusually slow to recreate every frame. Much faster now.
|
||||||
|
// 2025-03-21: Fixed typo in function name Imgui_ImplSDLGPU3_PrepareDrawData() -> ImGui_ImplSDLGPU3_PrepareDrawData().
|
||||||
|
// 2025-01-16: Renamed ImGui_ImplSDLGPU3_InitInfo::GpuDevice to Device.
|
||||||
|
// 2025-01-09: SDL_GPU: Added the SDL_GPU3 backend.
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_impl_sdlgpu3.h"
|
||||||
|
#include "imgui_impl_sdlgpu3_shaders.h"
|
||||||
|
|
||||||
|
// SDL_GPU Data
|
||||||
|
|
||||||
|
// Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplSDLGPU3_RenderDrawData()
|
||||||
|
struct ImGui_ImplSDLGPU3_FrameData
|
||||||
|
{
|
||||||
|
SDL_GPUBuffer* VertexBuffer = nullptr;
|
||||||
|
SDL_GPUTransferBuffer* VertexTransferBuffer = nullptr;
|
||||||
|
uint32_t VertexBufferSize = 0;
|
||||||
|
SDL_GPUBuffer* IndexBuffer = nullptr;
|
||||||
|
SDL_GPUTransferBuffer* IndexTransferBuffer = nullptr;
|
||||||
|
uint32_t IndexBufferSize = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGui_ImplSDLGPU3_Data
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo InitInfo;
|
||||||
|
|
||||||
|
// Render state
|
||||||
|
ImGui_ImplSDLGPU3_RenderState* RenderState = nullptr; // == ImGui::GetPlatformIO().Renderer_RenderState during rendering.
|
||||||
|
SDL_GPUSampler* CurrentSampler = nullptr;
|
||||||
|
|
||||||
|
// Graphics pipeline & shaders
|
||||||
|
SDL_GPUShader* VertexShader = nullptr;
|
||||||
|
SDL_GPUShader* FragmentShader = nullptr;
|
||||||
|
SDL_GPUGraphicsPipeline* Pipeline = nullptr;
|
||||||
|
SDL_GPUSampler* TexSamplerLinear = nullptr;
|
||||||
|
SDL_GPUSampler* TexSamplerNearest = nullptr;
|
||||||
|
SDL_GPUTransferBuffer* TexTransferBuffer = nullptr;
|
||||||
|
uint32_t TexTransferBufferSize = 0;
|
||||||
|
|
||||||
|
// Frame data for main window
|
||||||
|
ImGui_ImplSDLGPU3_FrameData MainWindowFrameData;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
static void ImGui_ImplSDLGPU3_DestroyFrameData();
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// FUNCTIONS
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||||||
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||||
|
// FIXME: multi-context support has never been tested.
|
||||||
|
static ImGui_ImplSDLGPU3_Data* ImGui_ImplSDLGPU3_GetBackendData()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGraphicsPipeline* pipeline, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, ImGui_ImplSDLGPU3_FrameData* fd, uint32_t fb_width, uint32_t fb_height)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
bd->CurrentSampler = bd->TexSamplerLinear;
|
||||||
|
|
||||||
|
// Bind graphics pipeline
|
||||||
|
SDL_BindGPUGraphicsPipeline(render_pass, pipeline);
|
||||||
|
|
||||||
|
// Bind Vertex And Index Buffers
|
||||||
|
if (draw_data->TotalVtxCount > 0)
|
||||||
|
{
|
||||||
|
SDL_GPUBufferBinding vertex_buffer_binding = {};
|
||||||
|
vertex_buffer_binding.buffer = fd->VertexBuffer;
|
||||||
|
vertex_buffer_binding.offset = 0;
|
||||||
|
SDL_GPUBufferBinding index_buffer_binding = {};
|
||||||
|
index_buffer_binding.buffer = fd->IndexBuffer;
|
||||||
|
index_buffer_binding.offset = 0;
|
||||||
|
SDL_BindGPUVertexBuffers(render_pass,0, &vertex_buffer_binding, 1);
|
||||||
|
SDL_BindGPUIndexBuffer(render_pass, &index_buffer_binding, sizeof(ImDrawIdx) == 2 ? SDL_GPU_INDEXELEMENTSIZE_16BIT : SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup viewport
|
||||||
|
SDL_GPUViewport viewport = {};
|
||||||
|
viewport.x = 0;
|
||||||
|
viewport.y = 0;
|
||||||
|
viewport.w = (float)fb_width;
|
||||||
|
viewport.h = (float)fb_height;
|
||||||
|
viewport.min_depth = 0.0f;
|
||||||
|
viewport.max_depth = 1.0f;
|
||||||
|
SDL_SetGPUViewport(render_pass, &viewport);
|
||||||
|
|
||||||
|
// Setup scale and translation
|
||||||
|
// Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
||||||
|
struct UBO { float scale[2]; float translation[2]; } ubo;
|
||||||
|
ubo.scale[0] = 2.0f / draw_data->DisplaySize.x;
|
||||||
|
ubo.scale[1] = 2.0f / draw_data->DisplaySize.y;
|
||||||
|
ubo.translation[0] = -1.0f - draw_data->DisplayPos.x * ubo.scale[0];
|
||||||
|
ubo.translation[1] = -1.0f - draw_data->DisplayPos.y * ubo.scale[1];
|
||||||
|
SDL_PushGPUVertexUniformData(command_buffer, 0, &ubo, sizeof(UBO));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateOrResizeBuffers(SDL_GPUBuffer** buffer, SDL_GPUTransferBuffer** transferbuffer, uint32_t* old_size, uint32_t new_size, SDL_GPUBufferUsageFlags usage)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
// There is no need for calling SDL_WaitForGPUIdle here, as SDL3 will handle deferred buffer deletion automatically.
|
||||||
|
SDL_ReleaseGPUBuffer(v->Device, *buffer);
|
||||||
|
SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer);
|
||||||
|
|
||||||
|
SDL_GPUBufferCreateInfo buffer_info = {};
|
||||||
|
buffer_info.usage = usage;
|
||||||
|
buffer_info.size = new_size;
|
||||||
|
buffer_info.props = 0;
|
||||||
|
*buffer = SDL_CreateGPUBuffer(v->Device, &buffer_info);
|
||||||
|
*old_size = new_size;
|
||||||
|
IM_ASSERT(*buffer != nullptr && "Failed to create GPU Buffer, call SDL_GetError() for more information");
|
||||||
|
|
||||||
|
SDL_GPUTransferBufferCreateInfo transferbuffer_info = {};
|
||||||
|
transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
|
||||||
|
transferbuffer_info.size = new_size;
|
||||||
|
*transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info);
|
||||||
|
IM_ASSERT(*transferbuffer != nullptr && "Failed to create GPU Transfer Buffer, call SDL_GetError() for more information");
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GPU doesn't allow copy passes to occur while a render or compute pass is bound!
|
||||||
|
// The only way to allow a user to supply their own RenderPass (to render to a texture instead of the window for example),
|
||||||
|
// is to split the upload part of ImGui_ImplSDLGPU3_RenderDrawData() to another function that needs to be called by the user before rendering.
|
||||||
|
void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer)
|
||||||
|
{
|
||||||
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||||
|
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
||||||
|
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
||||||
|
if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Catch up with texture updates. Most of the times, the list will have 1 element with an OK status, aka nothing to do.
|
||||||
|
// (This almost always points to ImGui::GetPlatformIO().Textures[] but is part of ImDrawData to allow overriding or disabling texture updates).
|
||||||
|
if (draw_data->Textures != nullptr)
|
||||||
|
for (ImTextureData* tex : *draw_data->Textures)
|
||||||
|
if (tex->Status != ImTextureStatus_OK)
|
||||||
|
ImGui_ImplSDLGPU3_UpdateTexture(tex);
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
|
||||||
|
|
||||||
|
uint32_t vertex_size = (uint32_t)draw_data->TotalVtxCount * sizeof(ImDrawVert);
|
||||||
|
uint32_t index_size = (uint32_t)draw_data->TotalIdxCount * sizeof(ImDrawIdx);
|
||||||
|
if (fd->VertexBuffer == nullptr || fd->VertexBufferSize < vertex_size)
|
||||||
|
CreateOrResizeBuffers(&fd->VertexBuffer, &fd->VertexTransferBuffer, &fd->VertexBufferSize, vertex_size, SDL_GPU_BUFFERUSAGE_VERTEX);
|
||||||
|
if (fd->IndexBuffer == nullptr || fd->IndexBufferSize < index_size)
|
||||||
|
CreateOrResizeBuffers(&fd->IndexBuffer, &fd->IndexTransferBuffer, &fd->IndexBufferSize, index_size, SDL_GPU_BUFFERUSAGE_INDEX);
|
||||||
|
|
||||||
|
ImDrawVert* vtx_dst = (ImDrawVert*)SDL_MapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer, true);
|
||||||
|
ImDrawIdx* idx_dst = (ImDrawIdx*)SDL_MapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer, true);
|
||||||
|
for (const ImDrawList* draw_list : draw_data->CmdLists)
|
||||||
|
{
|
||||||
|
memcpy(vtx_dst, draw_list->VtxBuffer.Data, draw_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
||||||
|
memcpy(idx_dst, draw_list->IdxBuffer.Data, draw_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
||||||
|
vtx_dst += draw_list->VtxBuffer.Size;
|
||||||
|
idx_dst += draw_list->IdxBuffer.Size;
|
||||||
|
}
|
||||||
|
SDL_UnmapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer);
|
||||||
|
SDL_UnmapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer);
|
||||||
|
|
||||||
|
SDL_GPUTransferBufferLocation vertex_buffer_location = {};
|
||||||
|
vertex_buffer_location.offset = 0;
|
||||||
|
vertex_buffer_location.transfer_buffer = fd->VertexTransferBuffer;
|
||||||
|
SDL_GPUTransferBufferLocation index_buffer_location = {};
|
||||||
|
index_buffer_location.offset = 0;
|
||||||
|
index_buffer_location.transfer_buffer = fd->IndexTransferBuffer;
|
||||||
|
|
||||||
|
SDL_GPUBufferRegion vertex_buffer_region = {};
|
||||||
|
vertex_buffer_region.buffer = fd->VertexBuffer;
|
||||||
|
vertex_buffer_region.offset = 0;
|
||||||
|
vertex_buffer_region.size = vertex_size;
|
||||||
|
|
||||||
|
SDL_GPUBufferRegion index_buffer_region = {};
|
||||||
|
index_buffer_region.buffer = fd->IndexBuffer;
|
||||||
|
index_buffer_region.offset = 0;
|
||||||
|
index_buffer_region.size = index_size;
|
||||||
|
|
||||||
|
SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(command_buffer);
|
||||||
|
SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region, true);
|
||||||
|
SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region, true);
|
||||||
|
SDL_EndGPUCopyPass(copy_pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw callbacks
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} // Intentionally empty. Used as an identifier for rendering loop to call its code. Simpler to implement this way.
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerLinear; }
|
||||||
|
static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerNearest; }
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
|
||||||
|
{
|
||||||
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||||
|
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
||||||
|
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
||||||
|
if (fb_width <= 0 || fb_height <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
|
||||||
|
|
||||||
|
if (pipeline == nullptr)
|
||||||
|
pipeline = bd->Pipeline;
|
||||||
|
|
||||||
|
// Will project scissor/clipping rectangles into framebuffer space
|
||||||
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||||||
|
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
||||||
|
|
||||||
|
// Setup render state structure (for callbacks and custom texture bindings)
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
ImGui_ImplSDLGPU3_RenderState render_state;
|
||||||
|
render_state.Device = bd->InitInfo.Device;
|
||||||
|
platform_io.Renderer_RenderState = bd->RenderState = &render_state;
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
||||||
|
|
||||||
|
// Render command lists
|
||||||
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
||||||
|
int global_vtx_offset = 0;
|
||||||
|
int global_idx_offset = 0;
|
||||||
|
for (const ImDrawList* draw_list : draw_data->CmdLists)
|
||||||
|
{
|
||||||
|
for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
|
||||||
|
{
|
||||||
|
const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
|
||||||
|
if (pcmd->UserCallback != nullptr)
|
||||||
|
{
|
||||||
|
// User callback, registered via ImDrawList::AddCallback()
|
||||||
|
if (pcmd->UserCallback == ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState)
|
||||||
|
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
||||||
|
else
|
||||||
|
pcmd->UserCallback(draw_list, pcmd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Project scissor/clipping rectangles into framebuffer space
|
||||||
|
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||||
|
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||||
|
|
||||||
|
// Clamp to viewport as SDL_SetGPUScissor() won't accept values that are off bounds
|
||||||
|
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
||||||
|
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
||||||
|
if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
||||||
|
if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; }
|
||||||
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Apply scissor/clipping rectangle
|
||||||
|
SDL_Rect scissor_rect = {};
|
||||||
|
scissor_rect.x = (int)clip_min.x;
|
||||||
|
scissor_rect.y = (int)clip_min.y;
|
||||||
|
scissor_rect.w = (int)(clip_max.x - clip_min.x);
|
||||||
|
scissor_rect.h = (int)(clip_max.y - clip_min.y);
|
||||||
|
SDL_SetGPUScissor(render_pass,&scissor_rect);
|
||||||
|
|
||||||
|
// Bind DescriptorSet with font or user texture
|
||||||
|
SDL_GPUTextureSamplerBinding texture_sampler_binding;
|
||||||
|
texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID();
|
||||||
|
texture_sampler_binding.sampler = bd->CurrentSampler;
|
||||||
|
SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1);
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
// **IF YOU GET A CRASH HERE** In 1.92.2 on 2025/08/08 we have changed ImTextureID to store 'SDL_GPUTexture*' instead of storing 'SDL_GPUTextureSamplerBinding'.
|
||||||
|
// Any code loading custom texture using this backend needs to be updated.
|
||||||
|
SDL_DrawGPUIndexedPrimitives(render_pass, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
global_idx_offset += draw_list->IdxBuffer.Size;
|
||||||
|
global_vtx_offset += draw_list->VtxBuffer.Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: at this point both SDL_SetGPUViewport() and SDL_SetGPUScissor() have been called.
|
||||||
|
// Our last values will leak into user/application rendering if you forgot to call SDL_SetGPUViewport() and SDL_SetGPUScissor() yourself to explicitly set that state
|
||||||
|
// In theory we should aim to backup/restore those values but I am not sure this is possible.
|
||||||
|
// We perform a call to SDL_SetGPUScissor() to set back a full viewport which is likely to fix things for 99% users but technically this is not perfect. (See github #4644)
|
||||||
|
SDL_Rect scissor_rect { 0, 0, fb_width, fb_height };
|
||||||
|
SDL_SetGPUScissor(render_pass, &scissor_rect);
|
||||||
|
|
||||||
|
platform_io.Renderer_RenderState = bd->RenderState = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDLGPU3_DestroyTexture(ImTextureData* tex)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
if (tex->GetTexID() != ImTextureID_Invalid)
|
||||||
|
if (SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID())
|
||||||
|
SDL_ReleaseGPUTexture(bd->InitInfo.Device, raw_tex);
|
||||||
|
|
||||||
|
// Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
|
||||||
|
tex->SetTexID(ImTextureID_Invalid);
|
||||||
|
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
if (tex->Status == ImTextureStatus_WantCreate)
|
||||||
|
{
|
||||||
|
// Create and upload new texture to graphics system
|
||||||
|
//IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||||
|
IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
|
||||||
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
|
|
||||||
|
// Create texture
|
||||||
|
SDL_GPUTextureCreateInfo texture_info = {};
|
||||||
|
texture_info.type = SDL_GPU_TEXTURETYPE_2D;
|
||||||
|
texture_info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
||||||
|
texture_info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER;
|
||||||
|
texture_info.width = tex->Width;
|
||||||
|
texture_info.height = tex->Height;
|
||||||
|
texture_info.layer_count_or_depth = 1;
|
||||||
|
texture_info.num_levels = 1;
|
||||||
|
texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
||||||
|
|
||||||
|
SDL_GPUTexture* raw_tex = SDL_CreateGPUTexture(v->Device, &texture_info);
|
||||||
|
IM_ASSERT(raw_tex != nullptr && "Failed to create texture, call SDL_GetError() for more info");
|
||||||
|
|
||||||
|
// Store identifiers
|
||||||
|
tex->SetTexID((ImTextureID)(intptr_t)raw_tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates)
|
||||||
|
{
|
||||||
|
SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID();
|
||||||
|
IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
|
||||||
|
|
||||||
|
// Update full texture or selected blocks. We only ever write to textures regions which have never been used before!
|
||||||
|
// This backend choose to use tex->UpdateRect but you can use tex->Updates[] to upload individual regions.
|
||||||
|
// We could use the smaller rect on _WantCreate but using the full rect allows us to clear the texture.
|
||||||
|
const int upload_x = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.x;
|
||||||
|
const int upload_y = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.y;
|
||||||
|
const int upload_w = (tex->Status == ImTextureStatus_WantCreate) ? tex->Width : tex->UpdateRect.w;
|
||||||
|
const int upload_h = (tex->Status == ImTextureStatus_WantCreate) ? tex->Height : tex->UpdateRect.h;
|
||||||
|
uint32_t upload_pitch = upload_w * tex->BytesPerPixel;
|
||||||
|
uint32_t upload_size = upload_w * upload_h * tex->BytesPerPixel;
|
||||||
|
|
||||||
|
// Create transfer buffer
|
||||||
|
if (bd->TexTransferBufferSize < upload_size)
|
||||||
|
{
|
||||||
|
SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer);
|
||||||
|
SDL_GPUTransferBufferCreateInfo transferbuffer_info = {};
|
||||||
|
transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
|
||||||
|
transferbuffer_info.size = upload_size + 1024;
|
||||||
|
bd->TexTransferBufferSize = upload_size + 1024;
|
||||||
|
bd->TexTransferBuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info);
|
||||||
|
IM_ASSERT(bd->TexTransferBuffer != nullptr && "Failed to create transfer buffer, call SDL_GetError() for more information");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy to transfer buffer
|
||||||
|
{
|
||||||
|
void* texture_ptr = SDL_MapGPUTransferBuffer(v->Device, bd->TexTransferBuffer, true);
|
||||||
|
for (int y = 0; y < upload_h; y++)
|
||||||
|
memcpy((void*)((uintptr_t)texture_ptr + y * upload_pitch), tex->GetPixelsAt(upload_x, upload_y + y), upload_pitch);
|
||||||
|
SDL_UnmapGPUTransferBuffer(v->Device, bd->TexTransferBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_GPUTextureTransferInfo transfer_info = {};
|
||||||
|
transfer_info.offset = 0;
|
||||||
|
transfer_info.transfer_buffer = bd->TexTransferBuffer;
|
||||||
|
|
||||||
|
SDL_GPUTextureRegion texture_region = {};
|
||||||
|
texture_region.texture = raw_tex;
|
||||||
|
texture_region.x = (Uint32)upload_x;
|
||||||
|
texture_region.y = (Uint32)upload_y;
|
||||||
|
texture_region.w = (Uint32)upload_w;
|
||||||
|
texture_region.h = (Uint32)upload_h;
|
||||||
|
texture_region.d = 1;
|
||||||
|
|
||||||
|
// Upload
|
||||||
|
{
|
||||||
|
SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(v->Device);
|
||||||
|
SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(cmd);
|
||||||
|
SDL_UploadToGPUTexture(copy_pass, &transfer_info, &texture_region, false);
|
||||||
|
SDL_EndGPUCopyPass(copy_pass);
|
||||||
|
SDL_SubmitGPUCommandBuffer(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->SetStatus(ImTextureStatus_OK);
|
||||||
|
}
|
||||||
|
if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
|
||||||
|
ImGui_ImplSDLGPU3_DestroyTexture(tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDLGPU3_CreateShaders()
|
||||||
|
{
|
||||||
|
// Create the shader modules
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
const char* driver = SDL_GetGPUDeviceDriver(v->Device);
|
||||||
|
|
||||||
|
SDL_GPUShaderCreateInfo vertex_shader_info = {};
|
||||||
|
vertex_shader_info.entrypoint = "main";
|
||||||
|
vertex_shader_info.stage = SDL_GPU_SHADERSTAGE_VERTEX;
|
||||||
|
vertex_shader_info.num_uniform_buffers = 1;
|
||||||
|
vertex_shader_info.num_storage_buffers = 0;
|
||||||
|
vertex_shader_info.num_storage_textures = 0;
|
||||||
|
vertex_shader_info.num_samplers = 0;
|
||||||
|
|
||||||
|
SDL_GPUShaderCreateInfo fragment_shader_info = {};
|
||||||
|
fragment_shader_info.entrypoint = "main";
|
||||||
|
fragment_shader_info.stage = SDL_GPU_SHADERSTAGE_FRAGMENT;
|
||||||
|
fragment_shader_info.num_samplers = 1;
|
||||||
|
fragment_shader_info.num_storage_buffers = 0;
|
||||||
|
fragment_shader_info.num_storage_textures = 0;
|
||||||
|
fragment_shader_info.num_uniform_buffers = 0;
|
||||||
|
|
||||||
|
if (strcmp(driver, "vulkan") == 0)
|
||||||
|
{
|
||||||
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV;
|
||||||
|
vertex_shader_info.code = spirv_vertex;
|
||||||
|
vertex_shader_info.code_size = sizeof(spirv_vertex);
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV;
|
||||||
|
fragment_shader_info.code = spirv_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(spirv_fragment);
|
||||||
|
}
|
||||||
|
else if (strcmp(driver, "direct3d12") == 0)
|
||||||
|
{
|
||||||
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC;
|
||||||
|
vertex_shader_info.code = dxbc_vertex;
|
||||||
|
vertex_shader_info.code_size = sizeof(dxbc_vertex);
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC;
|
||||||
|
fragment_shader_info.code = dxbc_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(dxbc_fragment);
|
||||||
|
}
|
||||||
|
#ifdef __APPLE__
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_GPUShaderFormat supported_formats = SDL_GetGPUShaderFormats(v->Device);
|
||||||
|
if (supported_formats & SDL_GPU_SHADERFORMAT_METALLIB)
|
||||||
|
{
|
||||||
|
// Using metallib blobs (macOS 14+, iOS)
|
||||||
|
vertex_shader_info.entrypoint = "main0";
|
||||||
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
||||||
|
vertex_shader_info.code = metallib_vertex;
|
||||||
|
vertex_shader_info.code_size = sizeof(metallib_vertex);
|
||||||
|
fragment_shader_info.entrypoint = "main0";
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
||||||
|
fragment_shader_info.code = metallib_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(metallib_fragment);
|
||||||
|
}
|
||||||
|
else if (supported_formats & SDL_GPU_SHADERFORMAT_MSL)
|
||||||
|
{
|
||||||
|
// macOS: using MSL source
|
||||||
|
vertex_shader_info.entrypoint = "main0";
|
||||||
|
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
|
||||||
|
vertex_shader_info.code = msl_vertex;
|
||||||
|
vertex_shader_info.code_size = sizeof(msl_vertex);
|
||||||
|
fragment_shader_info.entrypoint = "main0";
|
||||||
|
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
|
||||||
|
fragment_shader_info.code = msl_fragment;
|
||||||
|
fragment_shader_info.code_size = sizeof(msl_fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);
|
||||||
|
bd->FragmentShader = SDL_CreateGPUShader(v->Device, &fragment_shader_info);
|
||||||
|
IM_ASSERT(bd->VertexShader != nullptr && "Failed to create vertex shader, call SDL_GetError() for more information");
|
||||||
|
IM_ASSERT(bd->FragmentShader != nullptr && "Failed to create fragment shader, call SDL_GetError() for more information");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
ImGui_ImplSDLGPU3_CreateShaders();
|
||||||
|
|
||||||
|
SDL_GPUVertexBufferDescription vertex_buffer_desc[1];
|
||||||
|
vertex_buffer_desc[0].slot = 0;
|
||||||
|
vertex_buffer_desc[0].input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
|
||||||
|
vertex_buffer_desc[0].instance_step_rate = 0;
|
||||||
|
vertex_buffer_desc[0].pitch = sizeof(ImDrawVert);
|
||||||
|
|
||||||
|
SDL_GPUVertexAttribute vertex_attributes[3];
|
||||||
|
vertex_attributes[0].buffer_slot = 0;
|
||||||
|
vertex_attributes[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
|
||||||
|
vertex_attributes[0].location = 0;
|
||||||
|
vertex_attributes[0].offset = offsetof(ImDrawVert,pos);
|
||||||
|
|
||||||
|
vertex_attributes[1].buffer_slot = 0;
|
||||||
|
vertex_attributes[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
|
||||||
|
vertex_attributes[1].location = 1;
|
||||||
|
vertex_attributes[1].offset = offsetof(ImDrawVert, uv);
|
||||||
|
|
||||||
|
vertex_attributes[2].buffer_slot = 0;
|
||||||
|
vertex_attributes[2].format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM;
|
||||||
|
vertex_attributes[2].location = 2;
|
||||||
|
vertex_attributes[2].offset = offsetof(ImDrawVert, col);
|
||||||
|
|
||||||
|
SDL_GPUVertexInputState vertex_input_state = {};
|
||||||
|
vertex_input_state.num_vertex_attributes = 3;
|
||||||
|
vertex_input_state.vertex_attributes = vertex_attributes;
|
||||||
|
vertex_input_state.num_vertex_buffers = 1;
|
||||||
|
vertex_input_state.vertex_buffer_descriptions = vertex_buffer_desc;
|
||||||
|
|
||||||
|
SDL_GPURasterizerState rasterizer_state = {};
|
||||||
|
rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL;
|
||||||
|
rasterizer_state.cull_mode = SDL_GPU_CULLMODE_NONE;
|
||||||
|
rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
|
||||||
|
rasterizer_state.enable_depth_bias = false;
|
||||||
|
rasterizer_state.enable_depth_clip = false;
|
||||||
|
|
||||||
|
SDL_GPUMultisampleState multisample_state = {};
|
||||||
|
multisample_state.sample_count = v->MSAASamples;
|
||||||
|
multisample_state.enable_mask = false;
|
||||||
|
|
||||||
|
SDL_GPUDepthStencilState depth_stencil_state = {};
|
||||||
|
depth_stencil_state.enable_depth_test = false;
|
||||||
|
depth_stencil_state.enable_depth_write = false;
|
||||||
|
depth_stencil_state.enable_stencil_test = false;
|
||||||
|
|
||||||
|
SDL_GPUColorTargetBlendState blend_state = {};
|
||||||
|
blend_state.enable_blend = true;
|
||||||
|
blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA;
|
||||||
|
blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
|
||||||
|
blend_state.color_blend_op = SDL_GPU_BLENDOP_ADD;
|
||||||
|
blend_state.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE;
|
||||||
|
blend_state.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
|
||||||
|
blend_state.alpha_blend_op = SDL_GPU_BLENDOP_ADD;
|
||||||
|
blend_state.color_write_mask = SDL_GPU_COLORCOMPONENT_R | SDL_GPU_COLORCOMPONENT_G | SDL_GPU_COLORCOMPONENT_B | SDL_GPU_COLORCOMPONENT_A;
|
||||||
|
|
||||||
|
SDL_GPUColorTargetDescription color_target_desc[1];
|
||||||
|
color_target_desc[0].format = v->ColorTargetFormat;
|
||||||
|
color_target_desc[0].blend_state = blend_state;
|
||||||
|
|
||||||
|
SDL_GPUGraphicsPipelineTargetInfo target_info = {};
|
||||||
|
target_info.num_color_targets = 1;
|
||||||
|
target_info.color_target_descriptions = color_target_desc;
|
||||||
|
target_info.has_depth_stencil_target = false;
|
||||||
|
|
||||||
|
SDL_GPUGraphicsPipelineCreateInfo pipeline_info = {};
|
||||||
|
pipeline_info.vertex_shader = bd->VertexShader;
|
||||||
|
pipeline_info.fragment_shader = bd->FragmentShader;
|
||||||
|
pipeline_info.vertex_input_state = vertex_input_state;
|
||||||
|
pipeline_info.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
||||||
|
pipeline_info.rasterizer_state = rasterizer_state;
|
||||||
|
pipeline_info.multisample_state = multisample_state;
|
||||||
|
pipeline_info.depth_stencil_state = depth_stencil_state;
|
||||||
|
pipeline_info.target_info = target_info;
|
||||||
|
|
||||||
|
bd->Pipeline = SDL_CreateGPUGraphicsPipeline(v->Device, &pipeline_info);
|
||||||
|
IM_ASSERT(bd->Pipeline != nullptr && "Failed to create graphics pipeline, call SDL_GetError() for more information");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_CreateDeviceObjects()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
if (bd->TexSamplerLinear == nullptr)
|
||||||
|
{
|
||||||
|
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
|
||||||
|
SDL_GPUSamplerCreateInfo sampler_info = {};
|
||||||
|
sampler_info.min_filter = SDL_GPU_FILTER_LINEAR;
|
||||||
|
sampler_info.mag_filter = SDL_GPU_FILTER_LINEAR;
|
||||||
|
sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||||
|
sampler_info.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
||||||
|
sampler_info.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
||||||
|
sampler_info.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
||||||
|
sampler_info.mip_lod_bias = 0.0f;
|
||||||
|
sampler_info.min_lod = -1000.0f;
|
||||||
|
sampler_info.max_lod = 1000.0f;
|
||||||
|
sampler_info.enable_anisotropy = false;
|
||||||
|
sampler_info.max_anisotropy = 1.0f;
|
||||||
|
sampler_info.enable_compare = false;
|
||||||
|
bd->TexSamplerLinear = SDL_CreateGPUSampler(v->Device, &sampler_info);
|
||||||
|
IM_ASSERT(bd->TexSamplerLinear != nullptr && "Failed to create sampler, call SDL_GetError() for more information");
|
||||||
|
|
||||||
|
sampler_info.min_filter = SDL_GPU_FILTER_NEAREST;
|
||||||
|
sampler_info.mag_filter = SDL_GPU_FILTER_NEAREST;
|
||||||
|
sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
|
||||||
|
bd->TexSamplerNearest = SDL_CreateGPUSampler(v->Device, &sampler_info);
|
||||||
|
IM_ASSERT(bd->TexSamplerNearest != nullptr && "Failed to create sampler, call SDL_GetError() for more information");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_DestroyFrameData()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
|
||||||
|
SDL_ReleaseGPUBuffer(v->Device, fd->VertexBuffer);
|
||||||
|
SDL_ReleaseGPUBuffer(v->Device, fd->IndexBuffer);
|
||||||
|
SDL_ReleaseGPUTransferBuffer(v->Device, fd->VertexTransferBuffer);
|
||||||
|
SDL_ReleaseGPUTransferBuffer(v->Device, fd->IndexTransferBuffer);
|
||||||
|
fd->VertexBuffer = fd->IndexBuffer = nullptr;
|
||||||
|
fd->VertexTransferBuffer = fd->IndexTransferBuffer = nullptr;
|
||||||
|
fd->VertexBufferSize = fd->IndexBufferSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_DestroyDeviceObjects()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_DestroyFrameData();
|
||||||
|
|
||||||
|
// Destroy all textures
|
||||||
|
for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
|
||||||
|
if (tex->RefCount == 1)
|
||||||
|
ImGui_ImplSDLGPU3_DestroyTexture(tex);
|
||||||
|
if (bd->TexTransferBuffer) { SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer); bd->TexTransferBuffer = nullptr; }
|
||||||
|
if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; }
|
||||||
|
if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; }
|
||||||
|
if (bd->TexSamplerLinear) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerLinear); bd->TexSamplerLinear = nullptr; }
|
||||||
|
if (bd->TexSamplerNearest) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerNearest); bd->TexSamplerNearest = nullptr; }
|
||||||
|
if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; }
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
|
|
||||||
|
// Setup backend capabilities flags
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = IM_NEW(ImGui_ImplSDLGPU3_Data)();
|
||||||
|
io.BackendRendererUserData = (void*)bd;
|
||||||
|
io.BackendRendererName = "imgui_impl_sdlgpu3";
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.DrawCallback_ResetRenderState = ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState;
|
||||||
|
platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear;
|
||||||
|
platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest;
|
||||||
|
|
||||||
|
IM_ASSERT(info->Device != nullptr);
|
||||||
|
IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
|
||||||
|
|
||||||
|
bd->InitInfo = *info;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
io.BackendRendererName = nullptr;
|
||||||
|
io.BackendRendererUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures);
|
||||||
|
platform_io.ClearRendererHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDLGPU3_NewFrame()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDLGPU3_Init()?");
|
||||||
|
|
||||||
|
if (!bd->TexSamplerLinear)
|
||||||
|
ImGui_ImplSDLGPU3_CreateDeviceObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
62
src/imgui_impl_sdlgpu3.h
Normal file
62
src/imgui_impl_sdlgpu3.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// dear imgui: Renderer Backend for SDL_GPU
|
||||||
|
// This needs to be used along with the SDL3 Platform Backend
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'SDL_GPUTexture*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef! **IMPORTANT** Before 2025/08/08, ImTextureID was a reference to a SDL_GPUTextureSamplerBinding struct.
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
|
||||||
|
// The aim of imgui_impl_sdlgpu3.h/.cpp is to be usable in your engine without any modification.
|
||||||
|
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// Important note to the reader who wish to integrate imgui_impl_sdlgpu3.cpp/.h in their own engine/app.
|
||||||
|
// - Unlike other backends, the user must call the function ImGui_ImplSDLGPU_PrepareDrawData BEFORE issuing a SDL_GPURenderPass containing ImGui_ImplSDLGPU_RenderDrawData.
|
||||||
|
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include <SDL3/SDL_gpu.h>
|
||||||
|
|
||||||
|
// Initialization data, for ImGui_ImplSDLGPU_Init()
|
||||||
|
// - Remember to set ColorTargetFormat to the correct format. If you're rendering to the swapchain, call SDL_GetGPUSwapchainTextureFormat() to query the right value
|
||||||
|
struct ImGui_ImplSDLGPU3_InitInfo
|
||||||
|
{
|
||||||
|
SDL_GPUDevice* Device = nullptr;
|
||||||
|
SDL_GPUTextureFormat ColorTargetFormat = SDL_GPU_TEXTUREFORMAT_INVALID;
|
||||||
|
SDL_GPUSampleCount MSAASamples = SDL_GPU_SAMPLECOUNT_1;
|
||||||
|
SDL_GPUSwapchainComposition SwapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR; // Only used in multi-viewports mode.
|
||||||
|
SDL_GPUPresentMode PresentMode = SDL_GPU_PRESENTMODE_VSYNC; // Only used in multi-viewports mode.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_NewFrame();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline = nullptr);
|
||||||
|
|
||||||
|
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_CreateDeviceObjects();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplSDLGPU3_RenderDrawData() call.
|
||||||
|
// (Please open an issue if you feel you need access to more data)
|
||||||
|
struct ImGui_ImplSDLGPU3_RenderState
|
||||||
|
{
|
||||||
|
SDL_GPUDevice* Device;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
406
src/imgui_impl_sdlgpu3_shaders.h
Normal file
406
src/imgui_impl_sdlgpu3_shaders.h
Normal file
@ -0,0 +1,406 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Data exported using
|
||||||
|
// misc/fonts/binary_to_compressed_c.exe -u8 -nocompress filename symbolname >filename.h
|
||||||
|
// With some manual pasting.
|
||||||
|
|
||||||
|
// Check sdlgpu3/ folder for the shaders' source code and instruction on how to build them
|
||||||
|
const uint8_t spirv_vertex[1732] = {
|
||||||
|
3,2,35,7,0,0,1,0,11,0,13,0,55,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,10,0,0,0,0,0,4,0,0,0,109,
|
||||||
|
97,105,110,0,0,0,0,11,0,0,0,15,0,0,0,21,0,0,0,30,0,0,0,31,0,0,0,3,0,3,0,2,0,0,0,194,1,0,0,4,0,10,0,71,76,95,71,79,79,71,76,69,95,99,112,112,95,115,116,121,108,101,95,108,105,110,101,
|
||||||
|
95,100,105,114,101,99,116,105,118,101,0,0,4,0,8,0,71,76,95,71,79,79,71,76,69,95,105,110,99,108,117,100,101,95,100,105,114,101,99,116,105,118,101,0,5,0,4,0,4,0,0,0,109,97,105,110,0,
|
||||||
|
0,0,0,5,0,3,0,9,0,0,0,0,0,0,0,6,0,5,0,9,0,0,0,0,0,0,0,67,111,108,111,114,0,0,0,6,0,4,0,9,0,0,0,1,0,0,0,85,86,0,0,5,0,3,0,11,0,0,0,79,117,116,0,5,0,4,0,15,0,0,0,97,67,111,108,111,114,
|
||||||
|
0,0,5,0,3,0,21,0,0,0,97,85,86,0,5,0,6,0,28,0,0,0,103,108,95,80,101,114,86,101,114,116,101,120,0,0,0,0,6,0,6,0,28,0,0,0,0,0,0,0,103,108,95,80,111,115,105,116,105,111,110,0,6,0,7,0,28,
|
||||||
|
0,0,0,1,0,0,0,103,108,95,80,111,105,110,116,83,105,122,101,0,0,0,0,6,0,7,0,28,0,0,0,2,0,0,0,103,108,95,67,108,105,112,68,105,115,116,97,110,99,101,0,6,0,7,0,28,0,0,0,3,0,0,0,103,108,
|
||||||
|
95,67,117,108,108,68,105,115,116,97,110,99,101,0,5,0,3,0,30,0,0,0,0,0,0,0,5,0,4,0,31,0,0,0,97,80,111,115,0,0,0,0,5,0,6,0,33,0,0,0,117,80,117,115,104,67,111,110,115,116,97,110,116,0,
|
||||||
|
0,0,6,0,5,0,33,0,0,0,0,0,0,0,117,83,99,97,108,101,0,0,6,0,6,0,33,0,0,0,1,0,0,0,117,84,114,97,110,115,108,97,116,101,0,0,5,0,3,0,35,0,0,0,112,99,0,0,71,0,4,0,11,0,0,0,30,0,0,0,0,0,0,
|
||||||
|
0,71,0,4,0,15,0,0,0,30,0,0,0,2,0,0,0,71,0,4,0,21,0,0,0,30,0,0,0,1,0,0,0,71,0,3,0,28,0,0,0,2,0,0,0,72,0,5,0,28,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,72,0,5,0,28,0,0,0,1,0,0,0,11,0,0,0,1,0,
|
||||||
|
0,0,72,0,5,0,28,0,0,0,2,0,0,0,11,0,0,0,3,0,0,0,72,0,5,0,28,0,0,0,3,0,0,0,11,0,0,0,4,0,0,0,71,0,4,0,31,0,0,0,30,0,0,0,0,0,0,0,71,0,3,0,33,0,0,0,2,0,0,0,72,0,5,0,33,0,0,0,0,0,0,0,35,
|
||||||
|
0,0,0,0,0,0,0,72,0,5,0,33,0,0,0,1,0,0,0,35,0,0,0,8,0,0,0,71,0,4,0,35,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,35,0,0,0,34,0,0,0,1,0,0,0,19,0,2,0,2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,6,
|
||||||
|
0,0,0,32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,23,0,4,0,8,0,0,0,6,0,0,0,2,0,0,0,30,0,4,0,9,0,0,0,7,0,0,0,8,0,0,0,32,0,4,0,10,0,0,0,3,0,0,0,9,0,0,0,59,0,4,0,10,0,0,0,11,0,0,0,3,0,0,
|
||||||
|
0,21,0,4,0,12,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,12,0,0,0,13,0,0,0,0,0,0,0,32,0,4,0,14,0,0,0,1,0,0,0,7,0,0,0,59,0,4,0,14,0,0,0,15,0,0,0,1,0,0,0,32,0,4,0,17,0,0,0,3,0,0,0,7,0,0,0,43,0,
|
||||||
|
4,0,12,0,0,0,19,0,0,0,1,0,0,0,32,0,4,0,20,0,0,0,1,0,0,0,8,0,0,0,59,0,4,0,20,0,0,0,21,0,0,0,1,0,0,0,32,0,4,0,23,0,0,0,3,0,0,0,8,0,0,0,21,0,4,0,25,0,0,0,32,0,0,0,0,0,0,0,43,0,4,0,25,
|
||||||
|
0,0,0,26,0,0,0,1,0,0,0,28,0,4,0,27,0,0,0,6,0,0,0,26,0,0,0,30,0,6,0,28,0,0,0,7,0,0,0,6,0,0,0,27,0,0,0,27,0,0,0,32,0,4,0,29,0,0,0,3,0,0,0,28,0,0,0,59,0,4,0,29,0,0,0,30,0,0,0,3,0,0,0,
|
||||||
|
59,0,4,0,20,0,0,0,31,0,0,0,1,0,0,0,30,0,4,0,33,0,0,0,8,0,0,0,8,0,0,0,32,0,4,0,34,0,0,0,2,0,0,0,33,0,0,0,59,0,4,0,34,0,0,0,35,0,0,0,2,0,0,0,32,0,4,0,36,0,0,0,2,0,0,0,8,0,0,0,43,0,4,
|
||||||
|
0,6,0,0,0,43,0,0,0,0,0,0,0,43,0,4,0,6,0,0,0,44,0,0,0,0,0,128,63,43,0,4,0,6,0,0,0,49,0,0,0,0,0,128,191,32,0,4,0,50,0,0,0,3,0,0,0,6,0,0,0,54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,248,
|
||||||
|
0,2,0,5,0,0,0,61,0,4,0,7,0,0,0,16,0,0,0,15,0,0,0,65,0,5,0,17,0,0,0,18,0,0,0,11,0,0,0,13,0,0,0,62,0,3,0,18,0,0,0,16,0,0,0,61,0,4,0,8,0,0,0,22,0,0,0,21,0,0,0,65,0,5,0,23,0,0,0,24,0,0,
|
||||||
|
0,11,0,0,0,19,0,0,0,62,0,3,0,24,0,0,0,22,0,0,0,61,0,4,0,8,0,0,0,32,0,0,0,31,0,0,0,65,0,5,0,36,0,0,0,37,0,0,0,35,0,0,0,13,0,0,0,61,0,4,0,8,0,0,0,38,0,0,0,37,0,0,0,133,0,5,0,8,0,0,0,
|
||||||
|
39,0,0,0,32,0,0,0,38,0,0,0,65,0,5,0,36,0,0,0,40,0,0,0,35,0,0,0,19,0,0,0,61,0,4,0,8,0,0,0,41,0,0,0,40,0,0,0,129,0,5,0,8,0,0,0,42,0,0,0,39,0,0,0,41,0,0,0,81,0,5,0,6,0,0,0,45,0,0,0,42,
|
||||||
|
0,0,0,0,0,0,0,81,0,5,0,6,0,0,0,46,0,0,0,42,0,0,0,1,0,0,0,80,0,7,0,7,0,0,0,47,0,0,0,45,0,0,0,46,0,0,0,43,0,0,0,44,0,0,0,65,0,5,0,17,0,0,0,48,0,0,0,30,0,0,0,13,0,0,0,62,0,3,0,48,0,0,
|
||||||
|
0,47,0,0,0,65,0,6,0,50,0,0,0,51,0,0,0,30,0,0,0,13,0,0,0,26,0,0,0,61,0,4,0,6,0,0,0,52,0,0,0,51,0,0,0,133,0,5,0,6,0,0,0,53,0,0,0,52,0,0,0,49,0,0,0,65,0,6,0,50,0,0,0,54,0,0,0,30,0,0,0,
|
||||||
|
13,0,0,0,26,0,0,0,62,0,3,0,54,0,0,0,53,0,0,0,253,0,1,0,56,0,1,0,
|
||||||
|
};
|
||||||
|
const uint8_t spirv_fragment[844] = {
|
||||||
|
3,2,35,7,0,0,1,0,11,0,13,0,30,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,7,0,4,0,0,0,4,0,0,0,109,97,
|
||||||
|
105,110,0,0,0,0,9,0,0,0,13,0,0,0,16,0,3,0,4,0,0,0,7,0,0,0,3,0,3,0,2,0,0,0,194,1,0,0,4,0,10,0,71,76,95,71,79,79,71,76,69,95,99,112,112,95,115,116,121,108,101,95,108,105,110,101,95,100,
|
||||||
|
105,114,101,99,116,105,118,101,0,0,4,0,8,0,71,76,95,71,79,79,71,76,69,95,105,110,99,108,117,100,101,95,100,105,114,101,99,116,105,118,101,0,5,0,4,0,4,0,0,0,109,97,105,110,0,0,0,0,5,
|
||||||
|
0,4,0,9,0,0,0,102,67,111,108,111,114,0,0,5,0,3,0,11,0,0,0,0,0,0,0,6,0,5,0,11,0,0,0,0,0,0,0,67,111,108,111,114,0,0,0,6,0,4,0,11,0,0,0,1,0,0,0,85,86,0,0,5,0,3,0,13,0,0,0,73,110,0,0,5,
|
||||||
|
0,5,0,22,0,0,0,115,84,101,120,116,117,114,101,0,0,0,0,71,0,4,0,9,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,22,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,22,0,0,0,34,0,
|
||||||
|
0,0,2,0,0,0,19,0,2,0,2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,6,0,0,0,32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,32,0,4,0,8,0,0,0,3,0,0,0,7,0,0,0,59,0,4,0,8,0,0,0,9,0,0,0,3,0,0,0,23,
|
||||||
|
0,4,0,10,0,0,0,6,0,0,0,2,0,0,0,30,0,4,0,11,0,0,0,7,0,0,0,10,0,0,0,32,0,4,0,12,0,0,0,1,0,0,0,11,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,1,0,0,0,21,0,4,0,14,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,
|
||||||
|
14,0,0,0,15,0,0,0,0,0,0,0,32,0,4,0,16,0,0,0,1,0,0,0,7,0,0,0,25,0,9,0,19,0,0,0,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,27,0,3,0,20,0,0,0,19,0,0,0,32,0,4,0,21,0,0,0,0,
|
||||||
|
0,0,0,20,0,0,0,59,0,4,0,21,0,0,0,22,0,0,0,0,0,0,0,43,0,4,0,14,0,0,0,24,0,0,0,1,0,0,0,32,0,4,0,25,0,0,0,1,0,0,0,10,0,0,0,54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,248,0,2,0,5,0,0,0,65,
|
||||||
|
0,5,0,16,0,0,0,17,0,0,0,13,0,0,0,15,0,0,0,61,0,4,0,7,0,0,0,18,0,0,0,17,0,0,0,61,0,4,0,20,0,0,0,23,0,0,0,22,0,0,0,65,0,5,0,25,0,0,0,26,0,0,0,13,0,0,0,24,0,0,0,61,0,4,0,10,0,0,0,27,0,
|
||||||
|
0,0,26,0,0,0,87,0,5,0,7,0,0,0,28,0,0,0,23,0,0,0,27,0,0,0,133,0,5,0,7,0,0,0,29,0,0,0,18,0,0,0,28,0,0,0,62,0,3,0,9,0,0,0,29,0,0,0,253,0,1,0,56,0,1,0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t dxbc_vertex[1064] = {
|
||||||
|
68,88,66,67,32,50,127,204,241,196,165,104,216,114,216,116,220,164,29,45,1,0,0,0,40,4,0,0,5,0,0,0,52,0,0,0,136,1,0,0,236,1,0,0,92,2,0,0,140,3,0,0,82,68,69,70,76,1,0,0,1,0,0,0,116,0,
|
||||||
|
0,0,1,0,0,0,60,0,0,0,1,5,254,255,0,5,0,0,34,1,0,0,19,19,68,37,60,0,0,0,24,0,0,0,40,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
|
||||||
|
0,1,0,0,0,1,0,0,0,0,0,0,0,117,80,117,115,104,67,111,110,115,116,97,110,116,0,171,171,100,0,0,0,2,0,0,0,140,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,220,0,0,0,0,0,0,0,8,0,0,0,2,0,0,0,240,0,0,
|
||||||
|
0,0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0,20,1,0,0,8,0,0,0,8,0,0,0,2,0,0,0,240,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0,112,99,95,117,83,99,97,
|
||||||
|
108,101,0,102,108,111,97,116,50,0,171,171,171,1,0,3,0,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,230,0,0,0,112,99,95,117,84,114,97,110,115,108,97,116,101,0,77,105,99,114,
|
||||||
|
111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,49,48,46,49,0,171,171,73,83,71,78,92,0,0,0,3,0,0,0,8,0,0,0,80,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,3,0,0,0,0,0,0,0,3,3,0,0,80,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,3,3,0,0,80,0,0,0,2,0,0,0,0,0,0,0,3,0,0,0,2,0,0,0,15,15,0,0,84,69,88,67,79,79,82,68,0,171,171,171,79,83,
|
||||||
|
71,78,104,0,0,0,3,0,0,0,8,0,0,0,80,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,15,0,0,0,80,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,3,12,0,0,89,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,2,0,0,0,15,0,0,
|
||||||
|
0,84,69,88,67,79,79,82,68,0,83,86,95,80,111,115,105,116,105,111,110,0,171,171,171,83,72,69,88,40,1,0,0,81,0,1,0,74,0,0,0,106,8,0,1,89,0,0,7,70,142,48,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
|
||||||
|
0,0,1,0,0,0,95,0,0,3,50,16,16,0,0,0,0,0,95,0,0,3,50,16,16,0,1,0,0,0,95,0,0,3,242,16,16,0,2,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0,101,0,0,3,50,32,16,0,1,0,0,0,103,0,0,4,242,32,16,0,2,
|
||||||
|
0,0,0,1,0,0,0,104,0,0,2,1,0,0,0,50,0,0,13,50,0,16,0,0,0,0,0,70,16,16,0,0,0,0,0,70,128,48,0,0,0,0,0,0,0,0,0,0,0,0,0,230,138,48,0,0,0,0,0,0,0,0,0,0,0,0,0,54,0,0,6,34,32,16,0,2,0,0,0,
|
||||||
|
26,0,16,128,65,0,0,0,0,0,0,0,54,0,0,5,242,32,16,0,0,0,0,0,70,30,16,0,2,0,0,0,54,0,0,5,18,32,16,0,2,0,0,0,10,0,16,0,0,0,0,0,54,0,0,8,194,32,16,0,2,0,0,0,2,64,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,128,63,54,0,0,5,50,32,16,0,1,0,0,0,70,16,16,0,1,0,0,0,62,0,0,1,83,84,65,84,148,0,0,0,7,0,0,0,1,0,0,0,0,0,0,0,6,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
const uint8_t dxbc_fragment[744] = {
|
||||||
|
68,88,66,67,235,219,43,109,38,151,39,223,98,41,193,28,215,98,67,110,1,0,0,0,232,2,0,0,5,0,0,0,52,0,0,0,12,1,0,0,88,1,0,0,140,1,0,0,76,2,0,0,82,68,69,70,208,0,0,0,0,0,0,0,0,0,0,0,2,
|
||||||
|
0,0,0,60,0,0,0,1,5,255,255,0,5,0,0,167,0,0,0,19,19,68,37,60,0,0,0,24,0,0,0,40,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0,140,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
|
||||||
|
0,0,2,0,0,0,0,0,0,0,158,0,0,0,2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255,0,0,0,0,1,0,0,0,12,0,0,0,2,0,0,0,0,0,0,0,95,115,84,101,120,116,117,114,101,95,115,97,109,112,108,101,114,0,115,
|
||||||
|
84,101,120,116,117,114,101,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,49,48,46,49,0,171,73,83,71,78,
|
||||||
|
68,0,0,0,2,0,0,0,8,0,0,0,56,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,15,15,0,0,56,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,3,3,0,0,84,69,88,67,79,79,82,68,0,171,171,171,79,83,71,78,44,0,
|
||||||
|
0,0,1,0,0,0,8,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,15,0,0,0,83,86,95,84,97,114,103,101,116,0,171,171,83,72,69,88,184,0,0,0,81,0,0,0,46,0,0,0,106,8,0,1,90,0,0,6,70,110,48,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,88,24,0,7,70,126,48,0,0,0,0,0,0,0,0,0,0,0,0,0,85,85,0,0,2,0,0,0,98,16,0,3,242,16,16,0,0,0,0,0,98,16,0,3,50,16,16,0,1,0,0,0,101,0,0,3,242,32,16,0,0,
|
||||||
|
0,0,0,104,0,0,2,1,0,0,0,69,0,0,11,242,0,16,0,0,0,0,0,70,16,16,0,1,0,0,0,70,126,32,0,0,0,0,0,0,0,0,0,0,96,32,0,0,0,0,0,0,0,0,0,56,0,0,7,242,32,16,0,0,0,0,0,70,14,16,0,0,0,0,0,70,30,
|
||||||
|
16,0,0,0,0,0,62,0,0,1,83,84,65,84,148,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#if TARGET_OS_MAC
|
||||||
|
const uint8_t metallib_vertex[3892] = {
|
||||||
|
77,84,76,66,1,128,2,0,7,0,0,129,14,0,0,0,52,15,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,12,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,20,1,0,0,0,0,0,0,32,
|
||||||
|
14,0,0,0,0,0,0,1,0,0,0,123,0,0,0,78,65,77,69,6,0,109,97,105,110,48,0,84,89,80,69,1,0,0,72,65,83,72,32,0,62,81,190,157,8,240,236,158,164,213,65,62,170,226,96,136,231,243,238,160,100,
|
||||||
|
26,13,254,254,64,19,129,180,3,149,75,77,68,83,90,8,0,32,14,0,0,0,0,0,0,79,70,70,84,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,69,82,83,8,0,2,0,6,0,3,0,1,0,69,78,68,84,
|
||||||
|
69,78,68,84,45,0,0,0,86,65,84,84,24,0,3,0,97,80,111,115,0,0,128,97,85,86,0,1,128,97,67,111,108,111,114,0,2,128,86,65,84,89,5,0,3,0,4,4,6,69,78,68,84,4,0,0,0,69,78,68,84,222,192,23,
|
||||||
|
11,0,0,0,0,20,0,0,0,8,14,0,0,255,255,255,255,66,67,192,222,53,20,0,0,3,0,0,0,98,12,48,36,128,16,5,200,20,0,0,0,33,12,0,0,74,3,0,0,11,2,33,0,2,0,0,0,22,0,0,0,7,129,35,145,65,200,4,73,
|
||||||
|
6,16,50,57,146,1,132,12,37,5,8,25,30,4,139,98,128,16,69,2,66,146,11,66,132,16,50,20,56,8,24,75,10,50,66,136,72,112,196,33,35,68,18,135,140,16,65,146,2,100,200,8,177,20,32,67,70,136,
|
||||||
|
32,201,1,50,66,132,24,42,40,42,144,49,124,176,92,145,32,196,200,0,0,0,137,32,0,0,24,0,0,0,50,34,8,9,32,98,70,0,33,43,36,152,16,33,37,36,152,16,25,39,12,133,164,144,96,66,100,92,32,
|
||||||
|
36,100,130,224,153,1,24,70,32,128,97,4,1,184,67,72,32,37,77,17,37,76,62,149,82,210,193,57,141,52,1,205,148,4,145,65,4,66,48,197,136,68,145,13,4,204,17,128,129,10,228,28,1,40,12,34,
|
||||||
|
8,194,48,2,145,140,0,0,0,0,0,81,24,0,0,100,0,0,0,27,246,35,248,255,255,255,255,1,48,5,192,15,0,56,0,254,0,144,0,10,232,3,34,28,224,1,30,228,225,29,240,161,13,204,161,30,220,97,28,218,
|
||||||
|
192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,128,48,7,121,8,135,118,40,135,54,128,135,119,72,7,119,160,135,114,144,7,32,28,216,129,29,0,162,29,210,193,29,218,128,29,
|
||||||
|
202,225,28,194,129,29,218,192,30,202,97,28,232,225,29,228,161,13,238,33,29,200,129,30,208,1,136,3,57,192,3,96,112,135,119,104,3,113,168,135,116,96,7,122,72,7,119,152,7,128,112,135,
|
||||||
|
119,104,131,116,112,7,115,152,135,54,48,7,120,104,131,118,8,7,122,64,7,128,30,228,161,30,202,1,32,220,225,29,218,192,29,194,193,29,230,161,13,204,1,30,218,160,29,194,129,30,208,1,160,
|
||||||
|
7,121,168,135,114,0,8,119,120,135,54,152,135,116,56,7,119,40,7,114,104,3,125,40,7,121,120,135,121,104,3,115,128,135,54,104,135,112,160,7,116,0,232,65,30,234,161,28,0,194,29,222,161,
|
||||||
|
13,232,65,30,194,1,30,224,33,29,220,225,28,218,160,29,194,129,30,208,1,160,7,121,168,135,114,0,136,121,160,135,112,24,135,117,104,3,120,144,135,119,160,135,114,24,7,122,120,7,121,104,
|
||||||
|
3,113,168,7,115,48,135,114,144,135,54,152,135,116,208,135,114,0,240,0,32,234,193,29,230,33,28,204,161,28,218,192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,96,195,24,8,
|
||||||
|
4,176,0,164,0,84,65,128,4,105,0,13,225,144,14,242,208,6,226,80,15,230,96,14,229,32,15,109,224,14,239,208,6,225,192,14,233,16,14,243,0,0,0,73,24,0,0,1,0,0,0,19,132,64,0,19,176,112,72,
|
||||||
|
7,121,176,3,58,104,131,112,128,7,120,96,135,114,104,131,118,8,135,113,120,135,121,192,135,56,160,3,55,128,3,55,128,131,13,183,81,14,109,0,15,122,96,7,116,160,7,118,64,7,122,96,7,116,
|
||||||
|
208,6,233,16,7,122,128,7,122,128,7,109,144,14,120,160,7,120,160,7,120,208,6,233,16,7,118,160,7,113,96,7,122,16,7,118,208,6,233,48,7,114,160,7,115,32,7,122,48,7,114,208,6,233,96,7,116,
|
||||||
|
160,7,118,64,7,122,96,7,116,208,6,230,48,7,114,160,7,115,32,7,122,48,7,114,208,6,230,96,7,116,160,7,118,64,7,122,96,7,116,208,6,246,16,7,118,160,7,113,96,7,122,16,7,118,208,6,246,32,
|
||||||
|
7,116,160,7,115,32,7,122,48,7,114,208,6,246,48,7,114,160,7,115,32,7,122,48,7,114,208,6,246,64,7,120,160,7,118,64,7,122,96,7,116,208,6,246,96,7,116,160,7,118,64,7,122,96,7,116,208,6,
|
||||||
|
246,144,7,118,160,7,113,32,7,120,160,7,113,32,7,120,208,6,246,16,7,114,128,7,122,16,7,114,128,7,122,16,7,114,128,7,109,96,15,113,144,7,114,160,7,114,80,7,118,160,7,114,80,7,118,208,
|
||||||
|
6,246,32,7,117,96,7,122,32,7,117,96,7,122,32,7,117,96,7,109,96,15,117,16,7,114,160,7,117,16,7,114,160,7,117,16,7,114,208,6,246,16,7,112,32,7,116,160,7,113,0,7,114,64,7,122,16,7,112,
|
||||||
|
32,7,116,208,6,238,128,7,122,16,7,118,160,7,115,32,7,26,33,12,89,48,0,210,208,67,42,160,48,0,0,8,0,0,0,4,0,0,0,0,0,10,64,98,131,64,81,166,1,0,128,44,16,0,11,0,0,0,50,30,152,16,25,17,
|
||||||
|
76,144,140,9,38,71,198,4,67,202,34,40,129,66,40,135,242,41,64,129,130,40,144,98,24,1,40,3,218,17,0,210,177,132,39,0,0,0,177,24,0,0,165,0,0,0,51,8,128,28,196,225,28,102,20,1,61,136,
|
||||||
|
67,56,132,195,140,66,128,7,121,120,7,115,152,113,12,230,0,15,237,16,14,244,128,14,51,12,66,30,194,193,29,206,161,28,102,48,5,61,136,67,56,132,131,27,204,3,61,200,67,61,140,3,61,204,
|
||||||
|
120,140,116,112,7,123,8,7,121,72,135,112,112,7,122,112,3,118,120,135,112,32,135,25,204,17,14,236,144,14,225,48,15,110,48,15,227,240,14,240,80,14,51,16,196,29,222,33,28,216,33,29,194,
|
||||||
|
97,30,102,48,137,59,188,131,59,208,67,57,180,3,60,188,131,60,132,3,59,204,240,20,118,96,7,123,104,7,55,104,135,114,104,7,55,128,135,112,144,135,112,96,7,118,40,7,118,248,5,118,120,
|
||||||
|
135,119,128,135,95,8,135,113,24,135,114,152,135,121,152,129,44,238,240,14,238,224,14,245,192,14,236,48,3,98,200,161,28,228,161,28,204,161,28,228,161,28,220,97,28,202,33,28,196,129,
|
||||||
|
29,202,97,6,214,144,67,57,200,67,57,152,67,57,200,67,57,184,195,56,148,67,56,136,3,59,148,195,47,188,131,60,252,130,59,212,3,59,176,195,12,199,105,135,112,88,135,114,112,131,116,104,
|
||||||
|
7,120,96,135,116,24,135,116,160,135,25,206,83,15,238,0,15,242,80,14,228,144,14,227,64,15,225,32,14,236,80,14,51,32,40,29,220,193,30,194,65,30,210,33,28,220,129,30,220,224,28,228,225,
|
||||||
|
29,234,1,30,102,24,81,56,176,67,58,156,131,59,204,80,36,118,96,7,123,104,7,55,96,135,119,120,7,120,152,81,76,244,144,15,240,80,14,51,30,106,30,202,97,28,232,33,29,222,193,29,126,1,
|
||||||
|
30,228,161,28,204,33,29,240,97,6,84,133,131,56,204,195,59,176,67,61,208,67,57,252,194,60,228,67,59,136,195,59,176,195,140,197,10,135,121,152,135,119,24,135,116,8,7,122,40,7,114,152,
|
||||||
|
129,92,227,16,14,236,192,14,229,80,14,243,48,35,193,210,65,30,228,225,23,216,225,29,222,1,30,102,72,25,59,176,131,61,180,131,27,132,195,56,140,67,57,204,195,60,184,193,57,200,195,59,
|
||||||
|
212,3,60,204,72,180,113,8,7,118,96,7,113,8,135,113,88,135,25,219,198,14,236,96,15,237,224,6,240,32,15,229,48,15,229,32,15,246,80,14,110,16,14,227,48,14,229,48,15,243,224,6,233,224,
|
||||||
|
14,228,80,14,248,48,35,226,236,97,28,194,129,29,216,225,23,236,33,29,230,33,29,196,33,29,216,33,29,232,33,31,102,32,157,59,188,67,61,184,3,57,148,131,57,204,88,188,112,112,7,119,120,
|
||||||
|
7,122,8,7,122,72,135,119,112,135,25,206,135,14,229,16,14,240,16,14,236,192,14,239,48,14,243,144,14,244,80,14,51,40,48,8,135,116,144,7,55,48,135,122,112,135,113,160,135,116,120,7,119,
|
||||||
|
248,133,115,144,135,119,168,7,120,152,7,0,0,0,0,121,32,0,0,26,1,0,0,114,30,72,32,67,136,12,25,9,114,50,72,32,35,129,140,145,145,209,68,160,16,40,100,60,49,50,66,142,144,33,163,152,
|
||||||
|
6,100,208,82,0,0,0,139,210,88,216,6,109,80,28,20,27,71,6,209,18,25,76,178,24,6,179,64,18,49,24,202,131,68,148,161,68,87,35,0,0,0,0,83,68,75,32,86,101,114,115,105,111,110,119,99,104,
|
||||||
|
97,114,95,115,105,122,101,102,114,97,109,101,45,112,111,105,110,116,101,114,97,105,114,46,109,97,120,95,100,101,118,105,99,101,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,
|
||||||
|
95,99,111,110,115,116,97,110,116,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,104,114,101,97,100,103,114,111,117,112,95,98,117,102,102,101,114,115,97,105,114,46,109,
|
||||||
|
97,120,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,114,101,97,100,95,119,114,105,116,101,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,115,97,109,
|
||||||
|
112,108,101,114,115,65,112,112,108,101,32,109,101,116,97,108,32,118,101,114,115,105,111,110,32,51,50,48,50,51,46,51,54,56,32,40,109,101,116,97,108,102,101,45,51,50,48,50,51,46,51,54,
|
||||||
|
56,41,77,101,116,97,108,97,105,114,46,99,111,109,112,105,108,101,46,100,101,110,111,114,109,115,95,100,105,115,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,97,115,
|
||||||
|
116,95,109,97,116,104,95,101,110,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,114,97,109,101,98,117,102,102,101,114,95,102,101,116,99,104,95,101,110,97,98,108,101,
|
||||||
|
97,105,114,46,118,101,114,116,101,120,95,111,117,116,112,117,116,117,115,101,114,40,108,111,99,110,48,41,97,105,114,46,97,114,103,95,116,121,112,101,95,110,97,109,101,102,108,111,97,
|
||||||
|
116,52,97,105,114,46,97,114,103,95,110,97,109,101,79,117,116,95,67,111,108,111,114,117,115,101,114,40,108,111,99,110,49,41,102,108,111,97,116,50,79,117,116,95,85,86,97,105,114,46,112,
|
||||||
|
111,115,105,116,105,111,110,103,108,95,80,111,115,105,116,105,111,110,97,105,114,46,118,101,114,116,101,120,95,105,110,112,117,116,97,105,114,46,108,111,99,97,116,105,111,110,95,105,
|
||||||
|
110,100,101,120,97,80,111,115,97,85,86,97,67,111,108,111,114,97,105,114,46,98,117,102,102,101,114,97,105,114,46,98,117,102,102,101,114,95,115,105,122,101,97,105,114,46,114,101,97,100,
|
||||||
|
97,105,114,46,97,100,100,114,101,115,115,95,115,112,97,99,101,97,105,114,46,115,116,114,117,99,116,95,116,121,112,101,95,105,110,102,111,117,83,99,97,108,101,117,84,114,97,110,115,
|
||||||
|
108,97,116,101,97,105,114,46,97,114,103,95,116,121,112,101,95,115,105,122,101,97,105,114,46,97,114,103,95,116,121,112,101,95,97,108,105,103,110,95,115,105,122,101,117,80,117,115,104,
|
||||||
|
67,111,110,115,116,97,110,116,112,99,0,0,0,166,119,0,0,0,0,0,0,48,130,144,4,35,8,74,51,130,144,8,35,8,201,48,130,144,16,35,8,73,49,130,144,24,35,8,201,49,130,144,32,35,8,73,50,130,
|
||||||
|
144,40,35,8,201,50,130,112,0,51,12,106,16,172,193,12,3,27,8,109,48,195,224,6,131,26,204,48,184,1,241,6,51,12,110,80,188,193,12,131,27,24,111,48,195,224,6,7,28,204,48,184,1,18,7,51,
|
||||||
|
12,110,144,200,193,12,129,50,195,160,6,115,64,7,51,16,75,29,176,1,29,204,16,48,51,4,205,12,129,51,131,241,64,145,52,81,51,24,79,21,89,211,53,67,129,69,210,148,205,48,152,194,41,160,
|
||||||
|
194,12,9,29,104,27,29,176,65,100,77,220,12,9,27,104,27,27,176,65,100,77,221,12,137,26,104,155,26,176,65,36,77,222,12,10,29,196,1,29,88,100,16,7,113,64,7,86,25,204,64,213,193,7,6,114,
|
||||||
|
176,209,1,27,132,129,24,168,193,24,180,130,25,200,193,25,196,65,132,6,83,26,204,64,168,194,42,176,130,43,204,48,216,65,42,188,194,157,1,192,113,28,199,113,28,199,113,28,199,185,129,
|
||||||
|
27,184,129,27,184,129,27,184,129,27,184,129,69,7,122,96,89,22,29,208,129,27,208,1,46,224,2,46,240,3,122,128,130,140,4,38,40,35,54,54,187,54,151,182,55,178,58,182,50,23,51,182,176,179,
|
||||||
|
185,81,18,59,184,3,60,200,3,61,216,3,62,232,3,63,72,133,141,205,174,205,37,141,172,204,141,110,148,224,15,114,9,75,147,115,177,43,147,155,75,123,115,27,37,0,133,164,194,210,228,92,
|
||||||
|
216,194,220,206,234,194,206,202,190,236,202,228,230,210,222,220,70,9,66,33,167,176,52,57,151,177,183,54,184,52,182,178,175,55,56,186,180,55,183,185,81,6,81,24,5,82,72,37,44,77,206,
|
||||||
|
197,174,76,142,174,12,111,148,224,21,0,0,0,169,24,0,0,37,0,0,0,11,10,114,40,135,119,128,7,122,88,112,152,67,61,184,195,56,176,67,57,208,195,130,230,28,198,161,13,232,65,30,194,193,
|
||||||
|
29,230,33,29,232,33,29,222,193,29,22,52,227,96,14,231,80,15,225,32,15,228,64,15,225,32,15,231,80,14,244,176,128,129,7,121,40,135,112,96,7,118,120,135,113,8,7,122,40,7,114,88,112,156,
|
||||||
|
195,56,180,1,59,164,131,61,148,195,2,107,28,216,33,28,220,225,28,220,32,28,228,97,28,220,32,28,232,129,30,194,97,28,208,161,28,200,97,28,194,129,29,216,97,193,1,15,244,32,15,225,80,
|
||||||
|
15,244,128,14,0,0,0,0,209,16,0,0,6,0,0,0,7,204,60,164,131,59,156,3,59,148,3,61,160,131,60,148,67,56,144,195,1,0,0,0,97,32,0,0,68,0,0,0,19,4,65,44,16,0,0,0,11,0,0,0,148,51,0,180,37,
|
||||||
|
64,61,7,161,72,146,52,7,161,72,9,65,48,26,48,2,48,70,0,130,32,136,127,20,115,16,150,117,97,36,163,1,52,51,0,0,0,0,0,241,48,0,0,32,0,0,0,34,71,200,144,81,18,196,43,0,0,0,0,207,115,89,
|
||||||
|
0,111,109,110,105,112,111,116,101,110,116,32,99,104,97,114,83,105,109,112,108,101,32,67,43,43,32,84,66,65,65,97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,115,40,109,97,105,
|
||||||
|
110,48,41,97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,45,97,114,103,40,51,41,0,19,132,133,89,33,216,194,44,172,24,110,193,22,104,97,67,32,11,27,134,88,192,133,90,216,48,228,
|
||||||
|
66,46,212,194,134,224,22,0,0,157,134,5,146,40,16,130,1,36,254,157,6,103,234,40,16,130,67,0,254,131,12,1,226,12,50,4,138,51,134,48,68,22,128,255,28,195,16,76,179,13,204,5,204,54,4,89,
|
||||||
|
48,219,16,12,194,6,1,49,0,4,0,0,0,91,138,32,200,133,67,23,182,20,68,144,11,135,46,0,0,0,0,0,0,113,32,0,0,3,0,0,0,50,14,16,34,132,0,134,6,0,0,0,0,0,0,0,0,101,12,0,0,31,0,0,0,18,3,148,
|
||||||
|
240,0,0,0,0,3,0,0,0,5,0,0,0,9,0,0,0,76,0,0,0,1,0,0,0,88,0,0,0,0,0,0,0,88,0,0,0,1,0,0,0,112,0,0,0,0,0,0,0,14,0,0,0,24,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0,0,0,0,0,112,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
1,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,5,0,0,0,255,255,255,255,0,36,0,0,0,0,0,0,93,12,0,0,13,0,0,0,18,3,148,102,0,0,0,0,109,97,105,110,48,51,50,48,50,51,46,51,54,56,97,105,114,54,
|
||||||
|
52,45,97,112,112,108,101,45,109,97,99,111,115,120,49,52,46,48,46,48,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
const uint8_t metallib_fragment[3787] = {
|
||||||
|
77,84,76,66,1,128,2,0,7,0,0,129,14,0,0,0,203,14,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,227,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,235,0,0,0,0,0,0,0,
|
||||||
|
224,13,0,0,0,0,0,0,1,0,0,0,123,0,0,0,78,65,77,69,6,0,109,97,105,110,48,0,84,89,80,69,1,0,1,72,65,83,72,32,0,201,103,233,140,10,95,185,107,79,93,85,82,78,218,248,8,95,184,8,139,191,
|
||||||
|
155,174,56,51,95,203,135,255,117,44,62,77,68,83,90,8,0,224,13,0,0,0,0,0,0,79,70,70,84,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,69,82,83,8,0,2,0,6,0,3,0,1,0,69,78,68,
|
||||||
|
84,69,78,68,84,4,0,0,0,69,78,68,84,4,0,0,0,69,78,68,84,222,192,23,11,0,0,0,0,20,0,0,0,196,13,0,0,255,255,255,255,66,67,192,222,53,20,0,0,3,0,0,0,98,12,48,36,128,16,5,200,20,0,0,0,33,
|
||||||
|
12,0,0,44,3,0,0,11,2,33,0,2,0,0,0,22,0,0,0,7,129,35,145,65,200,4,73,6,16,50,57,146,1,132,12,37,5,8,25,30,4,139,98,128,20,69,2,66,146,11,66,164,16,50,20,56,8,24,75,10,50,82,136,72,112,
|
||||||
|
196,33,35,68,18,135,140,16,65,146,2,100,200,8,177,20,32,67,70,136,32,201,1,50,82,132,24,42,40,42,144,49,124,176,92,145,32,197,200,0,0,0,137,32,0,0,31,0,0,0,50,34,72,9,32,98,70,0,33,
|
||||||
|
43,36,152,20,33,37,36,152,20,25,39,12,133,164,144,96,82,100,92,32,36,101,130,128,154,1,24,70,32,128,27,132,97,4,1,64,74,154,34,74,152,252,127,34,174,137,138,136,223,30,254,105,140,
|
||||||
|
0,24,68,32,2,140,164,41,162,132,201,255,37,128,121,22,34,250,167,49,2,96,16,193,16,76,33,194,40,135,208,28,1,114,132,160,230,8,130,57,2,48,24,70,16,26,163,172,114,6,115,12,128,70,111,
|
||||||
|
32,64,5,218,8,0,0,81,24,0,0,105,0,0,0,27,246,35,248,255,255,255,255,1,104,3,96,13,0,83,0,252,0,144,128,10,232,3,34,28,224,1,30,228,225,29,240,161,13,204,161,30,220,97,28,218,192,28,
|
||||||
|
224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,128,48,7,121,8,135,118,40,135,54,128,135,119,72,7,119,160,135,114,144,7,32,28,216,129,29,0,162,29,210,193,29,218,128,29,202,225,
|
||||||
|
28,194,129,29,218,192,30,202,97,28,232,225,29,228,161,13,238,33,29,200,129,30,208,1,136,3,57,192,3,96,112,135,119,104,3,113,168,135,116,96,7,122,72,7,119,152,7,128,112,135,119,104,
|
||||||
|
131,116,112,7,115,152,135,54,48,7,120,104,131,118,8,7,122,64,7,128,30,228,161,30,202,1,32,220,225,29,218,192,29,194,193,29,230,161,13,204,1,30,218,160,29,194,129,30,208,1,160,7,121,
|
||||||
|
168,135,114,0,8,119,120,135,54,152,135,116,56,7,119,40,7,114,104,3,125,40,7,121,120,135,121,104,3,115,128,135,54,104,135,112,160,7,116,0,232,65,30,234,161,28,0,194,29,222,161,13,232,
|
||||||
|
65,30,194,1,30,224,33,29,220,225,28,218,160,29,194,129,30,208,1,160,7,121,168,135,114,0,136,121,160,135,112,24,135,117,104,3,120,144,135,119,160,135,114,24,7,122,120,7,121,104,3,113,
|
||||||
|
168,7,115,48,135,114,144,135,54,152,135,116,208,135,114,0,240,0,32,234,193,29,230,33,28,204,161,28,218,192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,96,131,33,12,192,
|
||||||
|
2,84,27,140,129,0,22,160,218,0,17,255,255,255,255,63,0,109,0,172,1,96,10,128,31,0,18,80,1,125,176,193,40,2,96,1,170,13,134,33,0,11,80,109,96,142,255,255,255,255,31,128,54,0,214,0,144,
|
||||||
|
128,10,232,3,0,73,24,0,0,4,0,0,0,19,134,64,24,38,12,68,97,76,24,142,194,0,0,0,0,19,176,112,72,7,121,176,3,58,104,131,112,128,7,120,96,135,114,104,131,118,8,135,113,120,135,121,192,
|
||||||
|
135,56,160,3,55,128,3,55,128,131,13,183,81,14,109,0,15,122,96,7,116,160,7,118,64,7,122,96,7,116,208,6,233,16,7,122,128,7,122,128,7,109,144,14,120,160,7,120,160,7,120,208,6,233,16,7,
|
||||||
|
118,160,7,113,96,7,122,16,7,118,208,6,233,48,7,114,160,7,115,32,7,122,48,7,114,208,6,233,96,7,116,160,7,118,64,7,122,96,7,116,208,6,230,48,7,114,160,7,115,32,7,122,48,7,114,208,6,230,
|
||||||
|
96,7,116,160,7,118,64,7,122,96,7,116,208,6,246,16,7,118,160,7,113,96,7,122,16,7,118,208,6,246,32,7,116,160,7,115,32,7,122,48,7,114,208,6,246,48,7,114,160,7,115,32,7,122,48,7,114,208,
|
||||||
|
6,246,64,7,120,160,7,118,64,7,122,96,7,116,208,6,246,96,7,116,160,7,118,64,7,122,96,7,116,208,6,246,144,7,118,160,7,113,32,7,120,160,7,113,32,7,120,208,6,246,16,7,114,128,7,122,16,
|
||||||
|
7,114,128,7,122,16,7,114,128,7,109,96,15,113,144,7,114,160,7,114,80,7,118,160,7,114,80,7,118,208,6,246,32,7,117,96,7,122,32,7,117,96,7,122,32,7,117,96,7,109,96,15,117,16,7,114,160,
|
||||||
|
7,117,16,7,114,160,7,117,16,7,114,208,6,246,16,7,112,32,7,116,160,7,113,0,7,114,64,7,122,16,7,112,32,7,116,208,6,238,128,7,122,16,7,118,160,7,115,32,7,26,33,12,89,48,0,210,208,67,42,
|
||||||
|
160,64,0,0,8,0,0,0,4,0,0,0,0,0,10,96,72,85,108,15,16,0,2,0,0,128,0,0,0,0,0,64,1,72,108,16,40,234,50,0,0,144,5,2,0,0,0,10,0,0,0,50,30,152,16,25,17,76,144,140,9,38,71,198,4,67,106,69,
|
||||||
|
80,2,133,80,14,229,83,128,2,5,81,32,197,48,2,80,6,36,199,18,158,0,0,177,24,0,0,165,0,0,0,51,8,128,28,196,225,28,102,20,1,61,136,67,56,132,195,140,66,128,7,121,120,7,115,152,113,12,
|
||||||
|
230,0,15,237,16,14,244,128,14,51,12,66,30,194,193,29,206,161,28,102,48,5,61,136,67,56,132,131,27,204,3,61,200,67,61,140,3,61,204,120,140,116,112,7,123,8,7,121,72,135,112,112,7,122,
|
||||||
|
112,3,118,120,135,112,32,135,25,204,17,14,236,144,14,225,48,15,110,48,15,227,240,14,240,80,14,51,16,196,29,222,33,28,216,33,29,194,97,30,102,48,137,59,188,131,59,208,67,57,180,3,60,
|
||||||
|
188,131,60,132,3,59,204,240,20,118,96,7,123,104,7,55,104,135,114,104,7,55,128,135,112,144,135,112,96,7,118,40,7,118,248,5,118,120,135,119,128,135,95,8,135,113,24,135,114,152,135,121,
|
||||||
|
152,129,44,238,240,14,238,224,14,245,192,14,236,48,3,98,200,161,28,228,161,28,204,161,28,228,161,28,220,97,28,202,33,28,196,129,29,202,97,6,214,144,67,57,200,67,57,152,67,57,200,67,
|
||||||
|
57,184,195,56,148,67,56,136,3,59,148,195,47,188,131,60,252,130,59,212,3,59,176,195,12,199,105,135,112,88,135,114,112,131,116,104,7,120,96,135,116,24,135,116,160,135,25,206,83,15,238,
|
||||||
|
0,15,242,80,14,228,144,14,227,64,15,225,32,14,236,80,14,51,32,40,29,220,193,30,194,65,30,210,33,28,220,129,30,220,224,28,228,225,29,234,1,30,102,24,81,56,176,67,58,156,131,59,204,80,
|
||||||
|
36,118,96,7,123,104,7,55,96,135,119,120,7,120,152,81,76,244,144,15,240,80,14,51,30,106,30,202,97,28,232,33,29,222,193,29,126,1,30,228,161,28,204,33,29,240,97,6,84,133,131,56,204,195,
|
||||||
|
59,176,67,61,208,67,57,252,194,60,228,67,59,136,195,59,176,195,140,197,10,135,121,152,135,119,24,135,116,8,7,122,40,7,114,152,129,92,227,16,14,236,192,14,229,80,14,243,48,35,193,210,
|
||||||
|
65,30,228,225,23,216,225,29,222,1,30,102,72,25,59,176,131,61,180,131,27,132,195,56,140,67,57,204,195,60,184,193,57,200,195,59,212,3,60,204,72,180,113,8,7,118,96,7,113,8,135,113,88,
|
||||||
|
135,25,219,198,14,236,96,15,237,224,6,240,32,15,229,48,15,229,32,15,246,80,14,110,16,14,227,48,14,229,48,15,243,224,6,233,224,14,228,80,14,248,48,35,226,236,97,28,194,129,29,216,225,
|
||||||
|
23,236,33,29,230,33,29,196,33,29,216,33,29,232,33,31,102,32,157,59,188,67,61,184,3,57,148,131,57,204,88,188,112,112,7,119,120,7,122,8,7,122,72,135,119,112,135,25,206,135,14,229,16,
|
||||||
|
14,240,16,14,236,192,14,239,48,14,243,144,14,244,80,14,51,40,48,8,135,116,144,7,55,48,135,122,112,135,113,160,135,116,120,7,119,248,133,115,144,135,119,168,7,120,152,7,0,0,0,0,121,
|
||||||
|
32,0,0,252,0,0,0,114,30,72,32,67,136,12,25,9,114,50,72,32,35,129,140,145,145,209,68,160,16,40,100,60,49,50,66,142,144,33,163,56,6,220,41,1,0,0,0,139,210,88,216,6,109,80,28,20,27,71,
|
||||||
|
6,81,100,48,134,180,40,15,178,24,197,34,41,24,178,28,13,83,68,75,32,86,101,114,115,105,111,110,119,99,104,97,114,95,115,105,122,101,102,114,97,109,101,45,112,111,105,110,116,101,114,
|
||||||
|
97,105,114,46,109,97,120,95,100,101,118,105,99,101,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,99,111,110,115,116,97,110,116,95,98,117,102,102,101,114,115,97,105,114,
|
||||||
|
46,109,97,120,95,116,104,114,101,97,100,103,114,111,117,112,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,114,
|
||||||
|
101,97,100,95,119,114,105,116,101,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,115,97,109,112,108,101,114,115,65,112,112,108,101,32,109,101,116,97,108,32,118,101,
|
||||||
|
114,115,105,111,110,32,51,50,48,50,51,46,51,54,56,32,40,109,101,116,97,108,102,101,45,51,50,48,50,51,46,51,54,56,41,77,101,116,97,108,97,105,114,46,99,111,109,112,105,108,101,46,100,
|
||||||
|
101,110,111,114,109,115,95,100,105,115,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,97,115,116,95,109,97,116,104,95,101,110,97,98,108,101,97,105,114,46,99,111,109,
|
||||||
|
112,105,108,101,46,102,114,97,109,101,98,117,102,102,101,114,95,102,101,116,99,104,95,101,110,97,98,108,101,97,105,114,46,114,101,110,100,101,114,95,116,97,114,103,101,116,97,105,114,
|
||||||
|
46,97,114,103,95,116,121,112,101,95,110,97,109,101,102,108,111,97,116,52,97,105,114,46,97,114,103,95,110,97,109,101,102,67,111,108,111,114,97,105,114,46,102,114,97,103,109,101,110,
|
||||||
|
116,95,105,110,112,117,116,117,115,101,114,40,108,111,99,110,48,41,97,105,114,46,99,101,110,116,101,114,97,105,114,46,112,101,114,115,112,101,99,116,105,118,101,73,110,95,67,111,108,
|
||||||
|
111,114,117,115,101,114,40,108,111,99,110,49,41,102,108,111,97,116,50,73,110,95,85,86,97,105,114,46,116,101,120,116,117,114,101,97,105,114,46,108,111,99,97,116,105,111,110,95,105,110,
|
||||||
|
100,101,120,97,105,114,46,115,97,109,112,108,101,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,44,32,115,97,109,112,108,101,62,115,84,101,120,116,117,114,101,97,105,114,
|
||||||
|
46,115,97,109,112,108,101,114,115,97,109,112,108,101,114,115,84,101,120,116,117,114,101,83,109,112,108,114,0,198,96,0,0,0,0,0,0,48,130,208,8,35,8,82,51,130,208,12,35,8,13,49,130,208,
|
||||||
|
20,35,8,141,49,130,208,28,35,8,13,50,130,208,36,35,8,141,50,130,208,44,35,8,13,51,130,144,0,51,12,100,16,148,193,12,131,25,8,103,48,195,128,6,3,25,204,48,160,1,145,6,51,12,104,80,164,
|
||||||
|
193,12,3,26,24,105,48,195,128,6,135,26,204,48,160,1,178,6,51,12,104,144,176,193,12,129,50,195,64,6,109,224,6,51,16,203,27,152,129,27,204,16,48,51,4,205,12,129,51,195,241,184,129,27,
|
||||||
|
64,145,52,205,16,128,194,12,137,27,80,149,117,65,145,132,205,144,152,1,149,89,23,164,73,219,12,10,25,112,157,27,152,129,7,125,18,24,204,144,188,65,24,116,110,96,6,144,24,72,99,48,3,
|
||||||
|
33,10,163,64,10,165,48,195,0,7,161,96,10,71,6,0,199,113,28,199,113,28,199,113,28,231,6,110,224,6,110,224,6,110,224,6,110,224,6,22,29,232,129,101,89,166,192,177,2,43,144,131,58,128,
|
||||||
|
130,140,4,38,40,35,54,54,187,54,151,182,55,178,58,182,50,23,51,182,176,179,185,81,18,56,136,3,57,152,3,58,168,3,59,184,3,60,72,133,141,205,174,205,37,141,172,204,141,110,148,32,15,
|
||||||
|
114,9,75,147,115,177,43,147,155,75,123,115,27,37,208,131,164,194,210,228,92,216,194,220,206,234,194,206,202,190,236,202,228,230,210,222,220,70,9,246,32,167,176,52,57,151,177,183,54,
|
||||||
|
184,52,182,178,175,55,56,186,180,55,183,185,81,6,62,232,3,63,72,38,44,77,206,197,76,46,236,172,173,204,141,110,148,192,20,0,0,0,0,169,24,0,0,37,0,0,0,11,10,114,40,135,119,128,7,122,
|
||||||
|
88,112,152,67,61,184,195,56,176,67,57,208,195,130,230,28,198,161,13,232,65,30,194,193,29,230,33,29,232,33,29,222,193,29,22,52,227,96,14,231,80,15,225,32,15,228,64,15,225,32,15,231,
|
||||||
|
80,14,244,176,128,129,7,121,40,135,112,96,7,118,120,135,113,8,7,122,40,7,114,88,112,156,195,56,180,1,59,164,131,61,148,195,2,107,28,216,33,28,220,225,28,220,32,28,228,97,28,220,32,
|
||||||
|
28,232,129,30,194,97,28,208,161,28,200,97,28,194,129,29,216,97,193,1,15,244,32,15,225,80,15,244,128,14,0,0,0,0,209,16,0,0,6,0,0,0,7,204,60,164,131,59,156,3,59,148,3,61,160,131,60,148,
|
||||||
|
67,56,144,195,1,0,0,0,97,32,0,0,49,0,0,0,19,4,65,44,16,0,0,0,4,0,0,0,196,106,96,4,128,220,8,0,129,17,0,18,51,0,0,0,241,48,0,0,28,0,0,0,34,71,200,144,81,14,196,42,0,0,0,0,23,134,1,0,
|
||||||
|
97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,115,40,109,97,105,110,48,41,97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,45,115,97,109,112,108,101,114,115,97,105,114,
|
||||||
|
45,97,108,105,97,115,45,115,99,111,112,101,45,116,101,120,116,117,114,101,115,0,43,132,85,64,133,21,3,43,172,66,42,172,24,90,97,21,84,97,131,208,10,172,0,0,35,6,205,16,130,96,240,88,
|
||||||
|
135,129,20,3,33,8,204,104,66,0,96,176,136,255,108,3,17,0,27,4,196,0,0,0,2,0,0,0,91,6,224,104,5,0,0,0,0,0,0,0,113,32,0,0,3,0,0,0,50,14,16,34,132,0,251,5,0,0,0,0,0,0,0,0,101,12,0,0,37,
|
||||||
|
0,0,0,18,3,148,40,1,0,0,0,3,0,0,0,32,0,0,0,9,0,0,0,76,0,0,0,1,0,0,0,88,0,0,0,0,0,0,0,88,0,0,0,2,0,0,0,136,0,0,0,0,0,0,0,41,0,0,0,24,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0,0,0,0,0,136,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,5,0,0,0,255,255,255,255,0,36,0,0,5,0,0,0,27,0,0,0,5,0,0,0,27,0,0,0,255,255,255,255,8,36,0,0,0,0,0,0,93,12,0,0,20,0,0,0,18,3,
|
||||||
|
148,161,0,0,0,0,109,97,105,110,48,97,105,114,46,115,97,109,112,108,101,95,116,101,120,116,117,114,101,95,50,100,46,118,52,102,51,50,51,50,48,50,51,46,51,54,56,97,105,114,54,52,45,97,
|
||||||
|
112,112,108,101,45,109,97,99,111,115,120,49,52,46,48,46,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
static uint8_t msl_vertex[800] =
|
||||||
|
{
|
||||||
|
35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,
|
||||||
|
105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,95,57,10,123,10,32,32,32,32,102,108,111,97,116,52,32,67,111,108,111,114,59,
|
||||||
|
10,32,32,32,32,102,108,111,97,116,50,32,85,86,59,10,125,59,10,10,115,116,114,117,99,116,32,85,66,79,10,123,10,32,32,32,32,102,108,111,97,116,50,32,117,83,99,97,108,101,59,10,32,32,
|
||||||
|
32,32,102,108,111,97,116,50,32,117,84,114,97,110,115,108,97,116,101,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,
|
||||||
|
97,116,52,32,79,117,116,95,67,111,108,111,114,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,32,32,32,32,102,108,111,97,116,50,32,79,117,116,95,85,86,32,91,91,117,115,
|
||||||
|
101,114,40,108,111,99,110,49,41,93,93,59,10,32,32,32,32,102,108,111,97,116,52,32,103,108,95,80,111,115,105,116,105,111,110,32,91,91,112,111,115,105,116,105,111,110,93,93,59,10,125,
|
||||||
|
59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,50,32,97,80,111,115,32,91,91,97,116,116,114,105,98,117,116,101,40,48,41,93,
|
||||||
|
93,59,10,32,32,32,32,102,108,111,97,116,50,32,97,85,86,32,91,91,97,116,116,114,105,98,117,116,101,40,49,41,93,93,59,10,32,32,32,32,102,108,111,97,116,52,32,97,67,111,108,111,114,32,
|
||||||
|
91,91,97,116,116,114,105,98,117,116,101,40,50,41,93,93,59,10,125,59,10,10,118,101,114,116,101,120,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,
|
||||||
|
110,32,105,110,32,91,91,115,116,97,103,101,95,105,110,93,93,44,32,99,111,110,115,116,97,110,116,32,85,66,79,38,32,117,98,111,32,91,91,98,117,102,102,101,114,40,48,41,93,93,41,10,123,
|
||||||
|
10,32,32,32,32,109,97,105,110,48,95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,95,57,32,79,117,116,32,61,32,123,125,59,10,32,32,32,32,79,117,116,46,67,111,108,111,
|
||||||
|
114,32,61,32,105,110,46,97,67,111,108,111,114,59,10,32,32,32,32,79,117,116,46,85,86,32,61,32,105,110,46,97,85,86,59,10,32,32,32,32,111,117,116,46,103,108,95,80,111,115,105,116,105,
|
||||||
|
111,110,32,61,32,102,108,111,97,116,52,40,40,105,110,46,97,80,111,115,32,42,32,117,98,111,46,117,83,99,97,108,101,41,32,43,32,117,98,111,46,117,84,114,97,110,115,108,97,116,101,44,
|
||||||
|
32,48,46,48,44,32,49,46,48,41,59,10,32,32,32,32,111,117,116,46,103,108,95,80,111,115,105,116,105,111,110,46,121,32,42,61,32,40,45,49,46,48,41,59,10,32,32,32,32,111,117,116,46,79,117,
|
||||||
|
116,95,67,111,108,111,114,32,61,32,79,117,116,46,67,111,108,111,114,59,10,32,32,32,32,111,117,116,46,79,117,116,95,85,86,32,61,32,79,117,116,46,85,86,59,10,32,32,32,32,114,101,116,
|
||||||
|
117,114,110,32,111,117,116,59,10,125,10,10,
|
||||||
|
};
|
||||||
|
static uint8_t msl_fragment[580] =
|
||||||
|
{
|
||||||
|
35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,
|
||||||
|
105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,95,49,49,10,123,10,32,32,32,32,102,108,111,97,116,52,32,67,111,108,111,114,
|
||||||
|
59,10,32,32,32,32,102,108,111,97,116,50,32,85,86,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,97,116,52,32,102,67,
|
||||||
|
111,108,111,114,32,91,91,99,111,108,111,114,40,48,41,93,93,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,52,32,
|
||||||
|
73,110,95,67,111,108,111,114,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,32,32,32,32,102,108,111,97,116,50,32,73,110,95,85,86,32,91,91,117,115,101,114,40,108,111,99,
|
||||||
|
110,49,41,93,93,59,10,125,59,10,10,102,114,97,103,109,101,110,116,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,110,32,105,110,32,91,91,115,116,
|
||||||
|
97,103,101,95,105,110,93,93,44,32,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,62,32,115,84,101,120,116,117,114,101,32,91,91,116,101,120,116,117,114,101,40,48,41,93,93,
|
||||||
|
44,32,115,97,109,112,108,101,114,32,115,84,101,120,116,117,114,101,83,109,112,108,114,32,91,91,115,97,109,112,108,101,114,40,48,41,93,93,41,10,123,10,32,32,32,32,109,97,105,110,48,
|
||||||
|
95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,95,49,49,32,73,110,32,61,32,123,125,59,10,32,32,32,32,73,110,46,67,111,108,111,114,32,61,32,105,110,46,73,110,95,67,
|
||||||
|
111,108,111,114,59,10,32,32,32,32,73,110,46,85,86,32,61,32,105,110,46,73,110,95,85,86,59,10,32,32,32,32,111,117,116,46,102,67,111,108,111,114,32,61,32,73,110,46,67,111,108,111,114,
|
||||||
|
32,42,32,115,84,101,120,116,117,114,101,46,115,97,109,112,108,101,40,115,84,101,120,116,117,114,101,83,109,112,108,114,44,32,73,110,46,85,86,41,59,10,32,32,32,32,114,101,116,117,114,
|
||||||
|
110,32,111,117,116,59,10,125,10,10,
|
||||||
|
};
|
||||||
|
#elif TARGET_OS_IPHONE
|
||||||
|
const uint8_t metallib_vertex[3876] = {
|
||||||
|
77,84,76,66,1,0,2,0,7,0,0,130,18,0,1,0,36,15,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,12,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,20,1,0,0,0,0,0,0,16,
|
||||||
|
14,0,0,0,0,0,0,1,0,0,0,123,0,0,0,78,65,77,69,6,0,109,97,105,110,48,0,84,89,80,69,1,0,0,72,65,83,72,32,0,240,54,230,217,232,66,102,78,35,5,77,235,101,252,229,192,148,96,126,162,111,
|
||||||
|
77,253,247,211,52,17,198,182,137,68,244,77,68,83,90,8,0,16,14,0,0,0,0,0,0,79,70,70,84,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,69,82,83,8,0,2,0,7,0,3,0,2,0,69,78,68,
|
||||||
|
84,69,78,68,84,45,0,0,0,86,65,84,84,24,0,3,0,97,80,111,115,0,0,128,97,85,86,0,1,128,97,67,111,108,111,114,0,2,128,86,65,84,89,5,0,3,0,4,4,6,69,78,68,84,4,0,0,0,69,78,68,84,222,192,
|
||||||
|
23,11,0,0,0,0,20,0,0,0,252,13,0,0,255,255,255,255,66,67,192,222,53,20,0,0,3,0,0,0,98,12,48,36,128,16,5,200,20,0,0,0,33,12,0,0,72,3,0,0,11,2,33,0,2,0,0,0,22,0,0,0,7,129,35,145,65,200,
|
||||||
|
4,73,6,16,50,57,146,1,132,12,37,5,8,25,30,4,139,98,128,16,69,2,66,146,11,66,132,16,50,20,56,8,24,75,10,50,66,136,72,112,196,33,35,68,18,135,140,16,65,146,2,100,200,8,177,20,32,67,70,
|
||||||
|
136,32,201,1,50,66,132,24,42,40,42,144,49,124,176,92,145,32,196,200,0,0,0,137,32,0,0,24,0,0,0,50,34,8,9,32,98,70,0,33,43,36,152,16,33,37,36,152,16,25,39,12,133,164,144,96,66,100,92,
|
||||||
|
32,36,100,130,224,153,1,24,70,32,128,97,4,1,184,67,72,32,37,77,17,37,76,62,149,82,210,193,57,141,52,1,205,148,4,145,65,4,66,48,197,136,68,145,13,4,204,17,128,129,10,228,28,1,40,12,
|
||||||
|
34,8,194,48,2,145,140,0,0,0,0,0,81,24,0,0,100,0,0,0,27,246,35,248,255,255,255,255,1,48,5,192,15,0,56,0,254,0,144,0,10,232,3,34,28,224,1,30,228,225,29,240,161,13,204,161,30,220,97,28,
|
||||||
|
218,192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,128,48,7,121,8,135,118,40,135,54,128,135,119,72,7,119,160,135,114,144,7,32,28,216,129,29,0,162,29,210,193,29,218,128,
|
||||||
|
29,202,225,28,194,129,29,218,192,30,202,97,28,232,225,29,228,161,13,238,33,29,200,129,30,208,1,136,3,57,192,3,96,112,135,119,104,3,113,168,135,116,96,7,122,72,7,119,152,7,128,112,135,
|
||||||
|
119,104,131,116,112,7,115,152,135,54,48,7,120,104,131,118,8,7,122,64,7,128,30,228,161,30,202,1,32,220,225,29,218,192,29,194,193,29,230,161,13,204,1,30,218,160,29,194,129,30,208,1,160,
|
||||||
|
7,121,168,135,114,0,8,119,120,135,54,152,135,116,56,7,119,40,7,114,104,3,125,40,7,121,120,135,121,104,3,115,128,135,54,104,135,112,160,7,116,0,232,65,30,234,161,28,0,194,29,222,161,
|
||||||
|
13,232,65,30,194,1,30,224,33,29,220,225,28,218,160,29,194,129,30,208,1,160,7,121,168,135,114,0,136,121,160,135,112,24,135,117,104,3,120,144,135,119,160,135,114,24,7,122,120,7,121,104,
|
||||||
|
3,113,168,7,115,48,135,114,144,135,54,152,135,116,208,135,114,0,240,0,32,234,193,29,230,33,28,204,161,28,218,192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,96,195,24,8,
|
||||||
|
4,176,0,164,0,84,65,128,4,105,0,13,225,144,14,242,208,6,226,80,15,230,96,14,229,32,15,109,224,14,239,208,6,225,192,14,233,16,14,243,0,0,0,73,24,0,0,1,0,0,0,19,132,64,0,19,170,112,72,
|
||||||
|
7,121,176,3,58,104,131,112,128,7,120,96,135,114,104,131,116,120,135,121,136,3,60,112,131,56,112,3,56,216,112,27,229,208,6,240,160,7,118,64,7,122,96,7,116,160,7,118,64,7,109,144,14,
|
||||||
|
113,160,7,120,160,7,120,208,6,233,128,7,122,128,7,122,128,7,109,144,14,113,96,7,122,16,7,118,160,7,113,96,7,109,144,14,115,32,7,122,48,7,114,160,7,115,32,7,109,144,14,118,64,7,122,
|
||||||
|
96,7,116,160,7,118,64,7,109,96,14,115,32,7,122,48,7,114,160,7,115,32,7,109,96,14,118,64,7,122,96,7,116,160,7,118,64,7,109,96,15,113,96,7,122,16,7,118,160,7,113,96,7,109,96,15,114,64,
|
||||||
|
7,122,48,7,114,160,7,115,32,7,109,96,15,115,32,7,122,48,7,114,160,7,115,32,7,109,96,15,116,128,7,122,96,7,116,160,7,118,64,7,109,96,15,118,64,7,122,96,7,116,160,7,118,64,7,109,96,15,
|
||||||
|
121,96,7,122,16,7,114,128,7,122,16,7,114,128,7,109,96,15,113,32,7,120,160,7,113,32,7,120,160,7,113,32,7,120,208,6,246,16,7,121,32,7,122,32,7,117,96,7,122,32,7,117,96,7,109,96,15,114,
|
||||||
|
80,7,118,160,7,114,80,7,118,160,7,114,80,7,118,208,6,246,80,7,113,32,7,122,80,7,113,32,7,122,80,7,113,32,7,109,96,15,113,0,7,114,64,7,122,16,7,112,32,7,116,160,7,113,0,7,114,64,7,109,
|
||||||
|
224,14,120,160,7,113,96,7,122,48,7,114,160,17,194,144,5,3,32,13,61,164,2,10,3,0,128,0,0,0,64,0,0,0,0,0,160,0,36,54,8,20,85,26,0,0,200,2,1,0,11,0,0,0,50,30,152,16,25,17,76,144,140,9,
|
||||||
|
38,71,198,4,67,202,34,40,129,66,40,135,242,41,64,129,130,40,144,17,128,50,160,29,1,32,29,75,144,2,0,0,0,0,177,24,0,0,165,0,0,0,51,8,128,28,196,225,28,102,20,1,61,136,67,56,132,195,
|
||||||
|
140,66,128,7,121,120,7,115,152,113,12,230,0,15,237,16,14,244,128,14,51,12,66,30,194,193,29,206,161,28,102,48,5,61,136,67,56,132,131,27,204,3,61,200,67,61,140,3,61,204,120,140,116,112,
|
||||||
|
7,123,8,7,121,72,135,112,112,7,122,112,3,118,120,135,112,32,135,25,204,17,14,236,144,14,225,48,15,110,48,15,227,240,14,240,80,14,51,16,196,29,222,33,28,216,33,29,194,97,30,102,48,137,
|
||||||
|
59,188,131,59,208,67,57,180,3,60,188,131,60,132,3,59,204,240,20,118,96,7,123,104,7,55,104,135,114,104,7,55,128,135,112,144,135,112,96,7,118,40,7,118,248,5,118,120,135,119,128,135,95,
|
||||||
|
8,135,113,24,135,114,152,135,121,152,129,44,238,240,14,238,224,14,245,192,14,236,48,3,98,200,161,28,228,161,28,204,161,28,228,161,28,220,97,28,202,33,28,196,129,29,202,97,6,214,144,
|
||||||
|
67,57,200,67,57,152,67,57,200,67,57,184,195,56,148,67,56,136,3,59,148,195,47,188,131,60,252,130,59,212,3,59,176,195,12,199,105,135,112,88,135,114,112,131,116,104,7,120,96,135,116,24,
|
||||||
|
135,116,160,135,25,206,83,15,238,0,15,242,80,14,228,144,14,227,64,15,225,32,14,236,80,14,51,32,40,29,220,193,30,194,65,30,210,33,28,220,129,30,220,224,28,228,225,29,234,1,30,102,24,
|
||||||
|
81,56,176,67,58,156,131,59,204,80,36,118,96,7,123,104,7,55,96,135,119,120,7,120,152,81,76,244,144,15,240,80,14,51,30,106,30,202,97,28,232,33,29,222,193,29,126,1,30,228,161,28,204,33,
|
||||||
|
29,240,97,6,84,133,131,56,204,195,59,176,67,61,208,67,57,252,194,60,228,67,59,136,195,59,176,195,140,197,10,135,121,152,135,119,24,135,116,8,7,122,40,7,114,152,129,92,227,16,14,236,
|
||||||
|
192,14,229,80,14,243,48,35,193,210,65,30,228,225,23,216,225,29,222,1,30,102,72,25,59,176,131,61,180,131,27,132,195,56,140,67,57,204,195,60,184,193,57,200,195,59,212,3,60,204,72,180,
|
||||||
|
113,8,7,118,96,7,113,8,135,113,88,135,25,219,198,14,236,96,15,237,224,6,240,32,15,229,48,15,229,32,15,246,80,14,110,16,14,227,48,14,229,48,15,243,224,6,233,224,14,228,80,14,248,48,
|
||||||
|
35,226,236,97,28,194,129,29,216,225,23,236,33,29,230,33,29,196,33,29,216,33,29,232,33,31,102,32,157,59,188,67,61,184,3,57,148,131,57,204,88,188,112,112,7,119,120,7,122,8,7,122,72,135,
|
||||||
|
119,112,135,25,206,135,14,229,16,14,240,16,14,236,192,14,239,48,14,243,144,14,244,80,14,51,40,48,8,135,116,144,7,55,48,135,122,112,135,113,160,135,116,120,7,119,248,133,115,144,135,
|
||||||
|
119,168,7,120,152,7,0,0,0,0,121,32,0,0,25,1,0,0,114,30,72,32,67,136,12,25,9,114,50,72,32,35,129,140,145,145,209,68,160,16,40,100,60,49,50,66,142,144,33,163,152,6,100,208,82,0,0,0,139,
|
||||||
|
210,88,216,6,109,80,28,20,27,71,6,209,18,25,76,178,24,6,179,64,18,49,24,202,131,68,148,161,68,87,35,0,0,0,0,83,68,75,32,86,101,114,115,105,111,110,119,99,104,97,114,95,115,105,122,
|
||||||
|
101,102,114,97,109,101,45,112,111,105,110,116,101,114,97,105,114,46,109,97,120,95,100,101,118,105,99,101,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,99,111,110,115,116,
|
||||||
|
97,110,116,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,104,114,101,97,100,103,114,111,117,112,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,101,120,
|
||||||
|
116,117,114,101,115,97,105,114,46,109,97,120,95,114,101,97,100,95,119,114,105,116,101,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,115,97,109,112,108,101,114,115,
|
||||||
|
65,112,112,108,101,32,109,101,116,97,108,32,118,101,114,115,105,111,110,32,51,50,48,50,51,46,51,54,56,32,40,109,101,116,97,108,102,101,45,51,50,48,50,51,46,51,54,56,41,77,101,116,97,
|
||||||
|
108,97,105,114,46,99,111,109,112,105,108,101,46,100,101,110,111,114,109,115,95,100,105,115,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,97,115,116,95,109,97,116,104,
|
||||||
|
95,101,110,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,114,97,109,101,98,117,102,102,101,114,95,102,101,116,99,104,95,101,110,97,98,108,101,97,105,114,46,118,101,
|
||||||
|
114,116,101,120,95,111,117,116,112,117,116,117,115,101,114,40,108,111,99,110,48,41,97,105,114,46,97,114,103,95,116,121,112,101,95,110,97,109,101,102,108,111,97,116,52,97,105,114,46,
|
||||||
|
97,114,103,95,110,97,109,101,79,117,116,95,67,111,108,111,114,117,115,101,114,40,108,111,99,110,49,41,102,108,111,97,116,50,79,117,116,95,85,86,97,105,114,46,112,111,115,105,116,105,
|
||||||
|
111,110,103,108,95,80,111,115,105,116,105,111,110,97,105,114,46,118,101,114,116,101,120,95,105,110,112,117,116,97,105,114,46,108,111,99,97,116,105,111,110,95,105,110,100,101,120,97,
|
||||||
|
80,111,115,97,85,86,97,67,111,108,111,114,97,105,114,46,98,117,102,102,101,114,97,105,114,46,98,117,102,102,101,114,95,115,105,122,101,97,105,114,46,114,101,97,100,97,105,114,46,97,
|
||||||
|
100,100,114,101,115,115,95,115,112,97,99,101,97,105,114,46,115,116,114,117,99,116,95,116,121,112,101,95,105,110,102,111,117,83,99,97,108,101,117,84,114,97,110,115,108,97,116,101,97,
|
||||||
|
105,114,46,97,114,103,95,116,121,112,101,95,115,105,122,101,97,105,114,46,97,114,103,95,116,121,112,101,95,97,108,105,103,110,95,115,105,122,101,117,80,117,115,104,67,111,110,115,116,
|
||||||
|
97,110,116,112,99,0,0,0,230,117,0,0,0,0,0,0,48,130,144,4,35,8,10,51,130,144,8,35,8,201,48,130,144,16,35,8,73,49,130,144,24,35,8,201,49,130,144,32,35,8,73,50,130,144,40,35,8,7,48,195,
|
||||||
|
160,6,193,26,204,48,176,129,208,6,51,12,110,48,168,193,12,131,27,16,111,48,195,224,6,197,27,204,48,184,129,241,6,51,12,110,112,192,193,12,131,27,32,113,48,195,224,6,137,28,204,16,40,
|
||||||
|
51,12,106,224,6,115,48,3,177,208,129,26,204,193,12,1,51,67,208,204,16,56,51,24,15,20,73,19,53,131,241,84,145,53,93,51,20,88,36,77,217,12,67,41,152,194,41,204,144,204,129,182,205,1,
|
||||||
|
27,68,214,196,205,144,176,129,182,177,1,27,68,214,212,205,144,168,129,182,169,1,27,68,210,228,205,160,204,65,28,204,129,69,6,113,16,7,115,96,149,193,12,20,29,124,96,32,7,219,28,176,
|
||||||
|
65,24,136,129,26,140,1,43,152,129,28,156,65,28,68,104,48,165,193,12,68,42,168,194,42,180,194,12,67,29,160,130,43,156,25,0,28,199,113,28,199,113,28,199,113,110,224,6,110,224,6,110,224,
|
||||||
|
6,110,224,6,110,96,209,129,30,88,150,69,7,116,224,6,116,128,11,184,128,11,252,128,30,160,32,35,129,9,202,136,141,205,174,205,165,237,141,172,142,173,204,197,140,45,236,108,110,148,
|
||||||
|
164,14,236,224,14,240,32,15,244,96,15,248,160,15,82,97,99,179,107,115,73,35,43,115,163,27,37,240,131,92,194,210,228,92,236,202,228,230,210,222,220,70,9,254,32,169,176,52,57,23,182,
|
||||||
|
48,183,179,186,176,179,178,47,187,50,185,185,180,55,183,81,2,80,200,41,44,77,206,101,236,173,13,46,141,173,236,235,13,142,46,237,205,109,110,148,33,20,68,97,20,82,9,75,147,115,177,
|
||||||
|
43,147,163,43,195,27,37,112,5,0,0,0,169,24,0,0,37,0,0,0,11,10,114,40,135,119,128,7,122,88,112,152,67,61,184,195,56,176,67,57,208,195,130,230,28,198,161,13,232,65,30,194,193,29,230,
|
||||||
|
33,29,232,33,29,222,193,29,22,52,227,96,14,231,80,15,225,32,15,228,64,15,225,32,15,231,80,14,244,176,128,129,7,121,40,135,112,96,7,118,120,135,113,8,7,122,40,7,114,88,112,156,195,56,
|
||||||
|
180,1,59,164,131,61,148,195,2,107,28,216,33,28,220,225,28,220,32,28,228,97,28,220,32,28,232,129,30,194,97,28,208,161,28,200,97,28,194,129,29,216,97,193,1,15,244,32,15,225,80,15,244,
|
||||||
|
128,14,0,0,0,0,209,16,0,0,6,0,0,0,7,204,60,164,131,59,156,3,59,148,3,61,160,131,60,148,67,56,144,195,1,0,0,0,97,32,0,0,68,0,0,0,19,4,65,44,16,0,0,0,11,0,0,0,148,51,0,197,64,91,2,212,
|
||||||
|
115,16,73,20,69,115,16,73,36,17,4,163,1,35,0,99,4,32,8,130,248,71,49,7,97,89,23,70,50,26,64,51,3,0,0,0,241,48,0,0,32,0,0,0,34,71,200,144,81,18,196,43,0,0,0,0,207,115,89,0,111,109,110,
|
||||||
|
105,112,111,116,101,110,116,32,99,104,97,114,83,105,109,112,108,101,32,67,43,43,32,84,66,65,65,97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,115,40,109,97,105,110,48,41,97,
|
||||||
|
105,114,45,97,108,105,97,115,45,115,99,111,112,101,45,97,114,103,40,51,41,0,19,132,101,89,33,212,130,44,172,24,108,161,22,102,97,67,16,11,27,6,88,184,5,90,216,48,224,2,46,208,194,134,
|
||||||
|
192,22,0,0,157,6,38,154,40,16,130,65,36,254,157,134,135,234,40,16,130,67,0,254,131,12,1,226,12,50,4,138,51,134,48,68,22,128,255,28,195,16,76,179,13,12,6,204,54,4,90,48,219,16,12,194,
|
||||||
|
6,1,49,0,4,0,0,0,91,138,32,192,133,35,23,182,20,68,128,11,71,46,0,0,0,0,0,0,113,32,0,0,3,0,0,0,50,14,16,34,132,0,132,6,0,0,0,0,0,0,0,0,101,12,0,0,31,0,0,0,18,3,148,240,0,0,0,0,3,0,
|
||||||
|
0,0,5,0,0,0,9,0,0,0,76,0,0,0,1,0,0,0,88,0,0,0,0,0,0,0,88,0,0,0,1,0,0,0,112,0,0,0,0,0,0,0,14,0,0,0,21,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0,0,0,0,0,112,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,5,0,0,0,0,0,0,0,5,0,0,0,255,255,255,255,0,36,0,0,0,0,0,0,93,12,0,0,12,0,0,0,18,3,148,99,0,0,0,0,109,97,105,110,48,51,50,48,50,51,46,51,54,56,97,105,114,54,52,45,97,112,112,
|
||||||
|
108,101,45,105,111,115,49,56,46,49,46,48,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
const uint8_t metallib_fragment[3771] = {
|
||||||
|
77,84,76,66,1,0,2,0,7,0,0,130,18,0,1,0,187,14,0,0,0,0,0,0,88,0,0,0,0,0,0,0,123,0,0,0,0,0,0,0,219,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,227,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,235,0,0,0,0,0,0,0,208,
|
||||||
|
13,0,0,0,0,0,0,1,0,0,0,123,0,0,0,78,65,77,69,6,0,109,97,105,110,48,0,84,89,80,69,1,0,1,72,65,83,72,32,0,167,26,51,31,140,153,203,226,66,149,243,47,185,58,96,202,28,176,71,121,86,159,
|
||||||
|
244,234,235,69,155,58,121,67,241,212,77,68,83,90,8,0,208,13,0,0,0,0,0,0,79,70,70,84,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,69,82,83,8,0,2,0,7,0,3,0,2,0,69,78,68,84,
|
||||||
|
69,78,68,84,4,0,0,0,69,78,68,84,4,0,0,0,69,78,68,84,222,192,23,11,0,0,0,0,20,0,0,0,180,13,0,0,255,255,255,255,66,67,192,222,53,20,0,0,3,0,0,0,98,12,48,36,128,16,5,200,20,0,0,0,33,12,
|
||||||
|
0,0,41,3,0,0,11,2,33,0,2,0,0,0,22,0,0,0,7,129,35,145,65,200,4,73,6,16,50,57,146,1,132,12,37,5,8,25,30,4,139,98,128,20,69,2,66,146,11,66,164,16,50,20,56,8,24,75,10,50,82,136,72,112,
|
||||||
|
196,33,35,68,18,135,140,16,65,146,2,100,200,8,177,20,32,67,70,136,32,201,1,50,82,132,24,42,40,42,144,49,124,176,92,145,32,197,200,0,0,0,137,32,0,0,31,0,0,0,50,34,72,9,32,98,70,0,33,
|
||||||
|
43,36,152,20,33,37,36,152,20,25,39,12,133,164,144,96,82,100,92,32,36,101,130,128,154,1,24,70,32,128,27,132,97,4,1,64,74,154,34,74,152,252,127,34,174,137,138,136,223,30,254,105,140,
|
||||||
|
0,24,68,32,2,140,164,41,162,132,201,255,37,128,121,22,34,250,167,49,2,96,16,193,16,76,33,194,40,135,208,28,1,114,132,160,230,8,130,57,2,48,24,70,16,26,163,172,114,6,115,12,128,70,111,
|
||||||
|
32,64,5,218,8,0,0,81,24,0,0,105,0,0,0,27,246,35,248,255,255,255,255,1,104,3,96,13,0,83,0,252,0,144,128,10,232,3,34,28,224,1,30,228,225,29,240,161,13,204,161,30,220,97,28,218,192,28,
|
||||||
|
224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,128,48,7,121,8,135,118,40,135,54,128,135,119,72,7,119,160,135,114,144,7,32,28,216,129,29,0,162,29,210,193,29,218,128,29,202,225,
|
||||||
|
28,194,129,29,218,192,30,202,97,28,232,225,29,228,161,13,238,33,29,200,129,30,208,1,136,3,57,192,3,96,112,135,119,104,3,113,168,135,116,96,7,122,72,7,119,152,7,128,112,135,119,104,
|
||||||
|
131,116,112,7,115,152,135,54,48,7,120,104,131,118,8,7,122,64,7,128,30,228,161,30,202,1,32,220,225,29,218,192,29,194,193,29,230,161,13,204,1,30,218,160,29,194,129,30,208,1,160,7,121,
|
||||||
|
168,135,114,0,8,119,120,135,54,152,135,116,56,7,119,40,7,114,104,3,125,40,7,121,120,135,121,104,3,115,128,135,54,104,135,112,160,7,116,0,232,65,30,234,161,28,0,194,29,222,161,13,232,
|
||||||
|
65,30,194,1,30,224,33,29,220,225,28,218,160,29,194,129,30,208,1,160,7,121,168,135,114,0,136,121,160,135,112,24,135,117,104,3,120,144,135,119,160,135,114,24,7,122,120,7,121,104,3,113,
|
||||||
|
168,7,115,48,135,114,144,135,54,152,135,116,208,135,114,0,240,0,32,234,193,29,230,33,28,204,161,28,218,192,28,224,161,13,218,33,28,232,1,29,0,122,144,135,122,40,7,96,131,33,12,192,
|
||||||
|
2,84,27,140,129,0,22,160,218,0,17,255,255,255,255,63,0,109,0,172,1,96,10,128,31,0,18,80,1,125,176,193,40,2,96,1,170,13,134,33,0,11,80,109,96,142,255,255,255,255,31,128,54,0,214,0,144,
|
||||||
|
128,10,232,3,0,73,24,0,0,4,0,0,0,19,134,64,24,38,12,68,97,76,24,142,194,0,0,0,0,19,170,112,72,7,121,176,3,58,104,131,112,128,7,120,96,135,114,104,131,116,120,135,121,136,3,60,112,131,
|
||||||
|
56,112,3,56,216,112,27,229,208,6,240,160,7,118,64,7,122,96,7,116,160,7,118,64,7,109,144,14,113,160,7,120,160,7,120,208,6,233,128,7,122,128,7,122,128,7,109,144,14,113,96,7,122,16,7,
|
||||||
|
118,160,7,113,96,7,109,144,14,115,32,7,122,48,7,114,160,7,115,32,7,109,144,14,118,64,7,122,96,7,116,160,7,118,64,7,109,96,14,115,32,7,122,48,7,114,160,7,115,32,7,109,96,14,118,64,7,
|
||||||
|
122,96,7,116,160,7,118,64,7,109,96,15,113,96,7,122,16,7,118,160,7,113,96,7,109,96,15,114,64,7,122,48,7,114,160,7,115,32,7,109,96,15,115,32,7,122,48,7,114,160,7,115,32,7,109,96,15,116,
|
||||||
|
128,7,122,96,7,116,160,7,118,64,7,109,96,15,118,64,7,122,96,7,116,160,7,118,64,7,109,96,15,121,96,7,122,16,7,114,128,7,122,16,7,114,128,7,109,96,15,113,32,7,120,160,7,113,32,7,120,
|
||||||
|
160,7,113,32,7,120,208,6,246,16,7,121,32,7,122,32,7,117,96,7,122,32,7,117,96,7,109,96,15,114,80,7,118,160,7,114,80,7,118,160,7,114,80,7,118,208,6,246,80,7,113,32,7,122,80,7,113,32,
|
||||||
|
7,122,80,7,113,32,7,109,96,15,113,0,7,114,64,7,122,16,7,112,32,7,116,160,7,113,0,7,114,64,7,109,224,14,120,160,7,113,96,7,122,48,7,114,160,17,194,144,5,3,32,13,61,164,2,10,4,0,128,
|
||||||
|
0,0,0,64,0,0,0,0,0,160,0,134,84,197,246,0,1,32,0,0,0,8,0,0,0,0,0,20,128,196,6,129,162,43,3,0,0,89,32,10,0,0,0,50,30,152,16,25,17,76,144,140,9,38,71,198,4,67,106,69,80,2,133,80,14,229,
|
||||||
|
83,128,2,5,81,32,35,0,101,64,114,44,65,10,0,0,0,177,24,0,0,165,0,0,0,51,8,128,28,196,225,28,102,20,1,61,136,67,56,132,195,140,66,128,7,121,120,7,115,152,113,12,230,0,15,237,16,14,244,
|
||||||
|
128,14,51,12,66,30,194,193,29,206,161,28,102,48,5,61,136,67,56,132,131,27,204,3,61,200,67,61,140,3,61,204,120,140,116,112,7,123,8,7,121,72,135,112,112,7,122,112,3,118,120,135,112,32,
|
||||||
|
135,25,204,17,14,236,144,14,225,48,15,110,48,15,227,240,14,240,80,14,51,16,196,29,222,33,28,216,33,29,194,97,30,102,48,137,59,188,131,59,208,67,57,180,3,60,188,131,60,132,3,59,204,
|
||||||
|
240,20,118,96,7,123,104,7,55,104,135,114,104,7,55,128,135,112,144,135,112,96,7,118,40,7,118,248,5,118,120,135,119,128,135,95,8,135,113,24,135,114,152,135,121,152,129,44,238,240,14,
|
||||||
|
238,224,14,245,192,14,236,48,3,98,200,161,28,228,161,28,204,161,28,228,161,28,220,97,28,202,33,28,196,129,29,202,97,6,214,144,67,57,200,67,57,152,67,57,200,67,57,184,195,56,148,67,
|
||||||
|
56,136,3,59,148,195,47,188,131,60,252,130,59,212,3,59,176,195,12,199,105,135,112,88,135,114,112,131,116,104,7,120,96,135,116,24,135,116,160,135,25,206,83,15,238,0,15,242,80,14,228,
|
||||||
|
144,14,227,64,15,225,32,14,236,80,14,51,32,40,29,220,193,30,194,65,30,210,33,28,220,129,30,220,224,28,228,225,29,234,1,30,102,24,81,56,176,67,58,156,131,59,204,80,36,118,96,7,123,104,
|
||||||
|
7,55,96,135,119,120,7,120,152,81,76,244,144,15,240,80,14,51,30,106,30,202,97,28,232,33,29,222,193,29,126,1,30,228,161,28,204,33,29,240,97,6,84,133,131,56,204,195,59,176,67,61,208,67,
|
||||||
|
57,252,194,60,228,67,59,136,195,59,176,195,140,197,10,135,121,152,135,119,24,135,116,8,7,122,40,7,114,152,129,92,227,16,14,236,192,14,229,80,14,243,48,35,193,210,65,30,228,225,23,216,
|
||||||
|
225,29,222,1,30,102,72,25,59,176,131,61,180,131,27,132,195,56,140,67,57,204,195,60,184,193,57,200,195,59,212,3,60,204,72,180,113,8,7,118,96,7,113,8,135,113,88,135,25,219,198,14,236,
|
||||||
|
96,15,237,224,6,240,32,15,229,48,15,229,32,15,246,80,14,110,16,14,227,48,14,229,48,15,243,224,6,233,224,14,228,80,14,248,48,35,226,236,97,28,194,129,29,216,225,23,236,33,29,230,33,
|
||||||
|
29,196,33,29,216,33,29,232,33,31,102,32,157,59,188,67,61,184,3,57,148,131,57,204,88,188,112,112,7,119,120,7,122,8,7,122,72,135,119,112,135,25,206,135,14,229,16,14,240,16,14,236,192,
|
||||||
|
14,239,48,14,243,144,14,244,80,14,51,40,48,8,135,116,144,7,55,48,135,122,112,135,113,160,135,116,120,7,119,248,133,115,144,135,119,168,7,120,152,7,0,0,0,0,121,32,0,0,251,0,0,0,114,
|
||||||
|
30,72,32,67,136,12,25,9,114,50,72,32,35,129,140,145,145,209,68,160,16,40,100,60,49,50,66,142,144,33,163,56,6,220,41,1,0,0,0,139,210,88,216,6,109,80,28,20,27,71,6,81,100,48,134,180,
|
||||||
|
40,15,178,24,197,34,41,24,178,28,13,83,68,75,32,86,101,114,115,105,111,110,119,99,104,97,114,95,115,105,122,101,102,114,97,109,101,45,112,111,105,110,116,101,114,97,105,114,46,109,
|
||||||
|
97,120,95,100,101,118,105,99,101,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,99,111,110,115,116,97,110,116,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,
|
||||||
|
104,114,101,97,100,103,114,111,117,112,95,98,117,102,102,101,114,115,97,105,114,46,109,97,120,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,114,101,97,100,95,119,114,
|
||||||
|
105,116,101,95,116,101,120,116,117,114,101,115,97,105,114,46,109,97,120,95,115,97,109,112,108,101,114,115,65,112,112,108,101,32,109,101,116,97,108,32,118,101,114,115,105,111,110,32,
|
||||||
|
51,50,48,50,51,46,51,54,56,32,40,109,101,116,97,108,102,101,45,51,50,48,50,51,46,51,54,56,41,77,101,116,97,108,97,105,114,46,99,111,109,112,105,108,101,46,100,101,110,111,114,109,115,
|
||||||
|
95,100,105,115,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,97,115,116,95,109,97,116,104,95,101,110,97,98,108,101,97,105,114,46,99,111,109,112,105,108,101,46,102,114,
|
||||||
|
97,109,101,98,117,102,102,101,114,95,102,101,116,99,104,95,101,110,97,98,108,101,97,105,114,46,114,101,110,100,101,114,95,116,97,114,103,101,116,97,105,114,46,97,114,103,95,116,121,
|
||||||
|
112,101,95,110,97,109,101,102,108,111,97,116,52,97,105,114,46,97,114,103,95,110,97,109,101,102,67,111,108,111,114,97,105,114,46,102,114,97,103,109,101,110,116,95,105,110,112,117,116,
|
||||||
|
117,115,101,114,40,108,111,99,110,48,41,97,105,114,46,99,101,110,116,101,114,97,105,114,46,112,101,114,115,112,101,99,116,105,118,101,73,110,95,67,111,108,111,114,117,115,101,114,40,
|
||||||
|
108,111,99,110,49,41,102,108,111,97,116,50,73,110,95,85,86,97,105,114,46,116,101,120,116,117,114,101,97,105,114,46,108,111,99,97,116,105,111,110,95,105,110,100,101,120,97,105,114,46,
|
||||||
|
115,97,109,112,108,101,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,44,32,115,97,109,112,108,101,62,115,84,101,120,116,117,114,101,97,105,114,46,115,97,109,112,108,101,
|
||||||
|
114,115,97,109,112,108,101,114,115,84,101,120,116,117,114,101,83,109,112,108,114,0,6,95,0,0,0,0,0,0,48,130,208,8,35,8,18,51,130,208,12,35,8,13,49,130,208,20,35,8,141,49,130,208,28,
|
||||||
|
35,8,13,50,130,208,36,35,8,141,50,130,208,44,35,8,9,48,195,64,6,65,25,204,48,152,129,112,6,51,12,104,48,144,193,12,3,26,16,105,48,195,128,6,69,26,204,48,160,129,145,6,51,12,104,112,
|
||||||
|
168,193,12,3,26,32,107,48,195,128,6,9,27,204,16,40,51,12,100,128,6,109,48,3,177,184,1,25,180,193,12,1,51,67,208,204,16,56,51,28,79,27,180,1,20,73,211,12,193,31,204,144,180,1,85,89,
|
||||||
|
23,20,73,216,12,137,25,80,153,117,65,154,180,205,160,144,1,215,181,129,25,120,208,39,129,193,12,137,27,132,65,215,6,102,0,137,129,52,6,51,16,161,32,10,163,64,10,51,12,111,0,10,165,
|
||||||
|
112,99,0,112,28,199,113,28,199,113,28,199,185,129,27,184,129,27,184,129,27,184,129,27,184,129,69,7,122,96,89,150,41,112,172,192,10,228,160,14,160,32,35,129,9,202,136,141,205,174,205,
|
||||||
|
165,237,141,172,142,173,204,197,140,45,236,108,110,148,228,13,224,32,14,228,96,14,232,160,14,236,224,14,82,97,99,179,107,115,73,35,43,115,163,27,37,192,131,92,194,210,228,92,236,202,
|
||||||
|
228,230,210,222,220,70,9,242,32,169,176,52,57,23,182,48,183,179,186,176,179,178,47,187,50,185,185,180,55,183,81,2,61,200,41,44,77,206,101,236,173,13,46,141,173,236,235,13,142,46,237,
|
||||||
|
205,109,110,148,97,15,248,160,15,146,9,75,147,115,49,147,11,59,107,43,115,163,27,37,40,5,0,0,0,0,169,24,0,0,37,0,0,0,11,10,114,40,135,119,128,7,122,88,112,152,67,61,184,195,56,176,
|
||||||
|
67,57,208,195,130,230,28,198,161,13,232,65,30,194,193,29,230,33,29,232,33,29,222,193,29,22,52,227,96,14,231,80,15,225,32,15,228,64,15,225,32,15,231,80,14,244,176,128,129,7,121,40,135,
|
||||||
|
112,96,7,118,120,135,113,8,7,122,40,7,114,88,112,156,195,56,180,1,59,164,131,61,148,195,2,107,28,216,33,28,220,225,28,220,32,28,228,97,28,220,32,28,232,129,30,194,97,28,208,161,28,
|
||||||
|
200,97,28,194,129,29,216,97,193,1,15,244,32,15,225,80,15,244,128,14,0,0,0,0,209,16,0,0,6,0,0,0,7,204,60,164,131,59,156,3,59,148,3,61,160,131,60,148,67,56,144,195,1,0,0,0,97,32,0,0,
|
||||||
|
49,0,0,0,19,4,65,44,16,0,0,0,4,0,0,0,196,106,96,4,128,220,8,0,129,17,0,18,51,0,0,0,241,48,0,0,28,0,0,0,34,71,200,144,81,14,196,42,0,0,0,0,23,134,1,0,97,105,114,45,97,108,105,97,115,
|
||||||
|
45,115,99,111,112,101,115,40,109,97,105,110,48,41,97,105,114,45,97,108,105,97,115,45,115,99,111,112,101,45,115,97,109,112,108,101,114,115,97,105,114,45,97,108,105,97,115,45,115,99,
|
||||||
|
111,112,101,45,116,101,120,116,117,114,101,115,0,43,4,85,56,133,21,195,42,168,2,42,172,24,88,65,21,82,97,131,192,10,171,0,0,35,6,205,16,130,96,240,84,135,129,20,3,33,8,204,104,66,0,
|
||||||
|
96,176,136,255,108,3,17,0,27,4,196,0,0,0,2,0,0,0,91,6,224,96,5,0,0,0,0,0,0,0,113,32,0,0,3,0,0,0,50,14,16,34,132,0,248,5,0,0,0,0,0,0,0,0,101,12,0,0,37,0,0,0,18,3,148,40,1,0,0,0,3,0,
|
||||||
|
0,0,32,0,0,0,9,0,0,0,76,0,0,0,1,0,0,0,88,0,0,0,0,0,0,0,88,0,0,0,2,0,0,0,136,0,0,0,0,0,0,0,41,0,0,0,21,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0,0,0,0,0,136,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,5,0,0,0,0,0,0,0,5,0,0,0,255,255,255,255,0,36,0,0,5,0,0,0,27,0,0,0,5,0,0,0,27,0,0,0,255,255,255,255,8,36,0,0,0,0,0,0,93,12,0,0,19,0,0,0,18,3,148,126,0,0,0,0,109,97,105,110,
|
||||||
|
48,97,105,114,46,115,97,109,112,108,101,95,116,101,120,116,117,114,101,95,50,100,46,118,52,102,51,50,51,50,48,50,51,46,51,54,56,97,105,114,54,52,45,97,112,112,108,101,45,105,111,115,
|
||||||
|
49,56,46,49,46,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
};
|
||||||
|
#elif TARGET_IPHONE_SIMULATOR
|
||||||
|
#error "SDL_GPU does not support the iphone simulator"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
53
src/imgui_impl_sdlrenderer3.h
Normal file
53
src/imgui_impl_sdlrenderer3.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// dear imgui: Renderer Backend for SDL_Renderer for SDL3
|
||||||
|
// (Requires: SDL 3.1.8+)
|
||||||
|
|
||||||
|
// Note that SDL_Renderer is an _optional_ component of SDL3, which IMHO is now largely obsolete.
|
||||||
|
// For a multi-platform app consider using other technologies:
|
||||||
|
// - SDL3+SDL_GPU: SDL_GPU is SDL3 new graphics abstraction API.
|
||||||
|
// - SDL3+DirectX, SDL3+OpenGL, SDL3+Vulkan: combine SDL with dedicated renderers.
|
||||||
|
// If your application wants to render any non trivial amount of graphics other than UI,
|
||||||
|
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user
|
||||||
|
// and it might be difficult to step out of those boundaries.
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
struct SDL_Renderer;
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer);
|
||||||
|
|
||||||
|
// Called by Init/NewFrame/Shutdown
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplSDLRenderer3_RenderDrawData() call.
|
||||||
|
// (Please open an issue if you feel you need access to more data)
|
||||||
|
struct ImGui_ImplSDLRenderer3_RenderState
|
||||||
|
{
|
||||||
|
SDL_Renderer* Renderer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
4021
src/imgui_internal.h
Normal file
4021
src/imgui_internal.h
Normal file
File diff suppressed because it is too large
Load Diff
4665
src/imgui_tables.cpp
Normal file
4665
src/imgui_tables.cpp
Normal file
File diff suppressed because it is too large
Load Diff
10953
src/imgui_widgets.cpp
Normal file
10953
src/imgui_widgets.cpp
Normal file
File diff suppressed because it is too large
Load Diff
627
src/imstb_rectpack.h
Normal file
627
src/imstb_rectpack.h
Normal file
@ -0,0 +1,627 @@
|
|||||||
|
// [DEAR IMGUI]
|
||||||
|
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||||
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
//
|
||||||
|
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||||
|
// Sean Barrett 2014
|
||||||
|
//
|
||||||
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
// Does not do rotation.
|
||||||
|
//
|
||||||
|
// Before #including,
|
||||||
|
//
|
||||||
|
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//
|
||||||
|
// in the file that you want to have the implementation.
|
||||||
|
//
|
||||||
|
// Not necessarily the awesomest packing method, but better than
|
||||||
|
// the totally naive one in stb_truetype (which is primarily what
|
||||||
|
// this is meant to replace).
|
||||||
|
//
|
||||||
|
// Has only had a few tests run, may have issues.
|
||||||
|
//
|
||||||
|
// More docs to come.
|
||||||
|
//
|
||||||
|
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||||
|
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||||
|
//
|
||||||
|
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||||
|
//
|
||||||
|
// Please note: better rectangle packers are welcome! Please
|
||||||
|
// implement them to the same API, but with a different init
|
||||||
|
// function.
|
||||||
|
//
|
||||||
|
// Credits
|
||||||
|
//
|
||||||
|
// Library
|
||||||
|
// Sean Barrett
|
||||||
|
// Minor features
|
||||||
|
// Martins Mozeiko
|
||||||
|
// github:IntellectualKitty
|
||||||
|
//
|
||||||
|
// Bugfixes / warning fixes
|
||||||
|
// Jeremy Jaussaud
|
||||||
|
// Fabian Giesen
|
||||||
|
//
|
||||||
|
// Version history:
|
||||||
|
//
|
||||||
|
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||||
|
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||||
|
// 0.99 (2019-02-07) warning fixes
|
||||||
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
|
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||||
|
// 0.09 (2016-08-27) fix compiler warnings
|
||||||
|
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||||
|
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||||
|
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||||
|
// 0.01: initial release
|
||||||
|
//
|
||||||
|
// LICENSE
|
||||||
|
//
|
||||||
|
// See end of file for license information.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// INCLUDE SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
|
||||||
|
#define STB_RECT_PACK_VERSION 1
|
||||||
|
|
||||||
|
#ifdef STBRP_STATIC
|
||||||
|
#define STBRP_DEF static
|
||||||
|
#else
|
||||||
|
#define STBRP_DEF extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct stbrp_context stbrp_context;
|
||||||
|
typedef struct stbrp_node stbrp_node;
|
||||||
|
typedef struct stbrp_rect stbrp_rect;
|
||||||
|
|
||||||
|
typedef int stbrp_coord;
|
||||||
|
|
||||||
|
#define STBRP__MAXVAL 0x7fffffff
|
||||||
|
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||||
|
// Assign packed locations to rectangles. The rectangles are of type
|
||||||
|
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||||
|
// are 'num_rects' many of them.
|
||||||
|
//
|
||||||
|
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||||
|
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||||
|
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||||
|
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||||
|
// have the 'was_packed' flag set to 0.
|
||||||
|
//
|
||||||
|
// You should not try to access the 'rects' array from another thread
|
||||||
|
// while this function is running, as the function temporarily reorders
|
||||||
|
// the array while it executes.
|
||||||
|
//
|
||||||
|
// To pack into another rectangle, you need to call stbrp_init_target
|
||||||
|
// again. To continue packing into the same rectangle, you can call
|
||||||
|
// this function again. Calling this multiple times with multiple rect
|
||||||
|
// arrays will probably produce worse packing results than calling it
|
||||||
|
// a single time with the full rectangle array, but the option is
|
||||||
|
// available.
|
||||||
|
//
|
||||||
|
// The function returns 1 if all of the rectangles were successfully
|
||||||
|
// packed and 0 otherwise.
|
||||||
|
|
||||||
|
struct stbrp_rect
|
||||||
|
{
|
||||||
|
// reserved for your use:
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// input:
|
||||||
|
stbrp_coord w, h;
|
||||||
|
|
||||||
|
// output:
|
||||||
|
stbrp_coord x, y;
|
||||||
|
int was_packed; // non-zero if valid packing
|
||||||
|
|
||||||
|
}; // 16 bytes, nominally
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||||
|
// Initialize a rectangle packer to:
|
||||||
|
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||||
|
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||||
|
//
|
||||||
|
// You must call this function every time you start packing into a new target.
|
||||||
|
//
|
||||||
|
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||||
|
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||||
|
// the call (or calls) finish.
|
||||||
|
//
|
||||||
|
// Note: to guarantee best results, either:
|
||||||
|
// 1. make sure 'num_nodes' >= 'width'
|
||||||
|
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||||
|
//
|
||||||
|
// If you don't do either of the above things, widths will be quantized to multiples
|
||||||
|
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||||
|
//
|
||||||
|
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||||
|
// may run out of temporary storage and be unable to pack some rectangles.
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||||
|
// Optionally call this function after init but before doing any packing to
|
||||||
|
// change the handling of the out-of-temp-memory scenario, described above.
|
||||||
|
// If you call init again, this will be reset to the default (false).
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||||
|
// Optionally select which packing heuristic the library should use. Different
|
||||||
|
// heuristics will produce better/worse results for different data sets.
|
||||||
|
// If you call init again, this will be reset to the default.
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP_HEURISTIC_Skyline_default=0,
|
||||||
|
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||||
|
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// the details of the following structures don't matter to you, but they must
|
||||||
|
// be visible so you can handle the memory allocations for them
|
||||||
|
|
||||||
|
struct stbrp_node
|
||||||
|
{
|
||||||
|
stbrp_coord x,y;
|
||||||
|
stbrp_node *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct stbrp_context
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int align;
|
||||||
|
int init_mode;
|
||||||
|
int heuristic;
|
||||||
|
int num_nodes;
|
||||||
|
stbrp_node *active_head;
|
||||||
|
stbrp_node *free_head;
|
||||||
|
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPLEMENTATION SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#ifndef STBRP_SORT
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define STBRP_SORT qsort
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBRP_ASSERT
|
||||||
|
#include <assert.h>
|
||||||
|
#define STBRP_ASSERT assert
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define STBRP__NOTUSED(v) (void)(v)
|
||||||
|
#define STBRP__CDECL __cdecl
|
||||||
|
#else
|
||||||
|
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||||
|
#define STBRP__CDECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP__INIT_skyline = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||||
|
{
|
||||||
|
switch (context->init_mode) {
|
||||||
|
case STBRP__INIT_skyline:
|
||||||
|
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||||
|
context->heuristic = heuristic;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
STBRP_ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||||
|
{
|
||||||
|
if (allow_out_of_mem)
|
||||||
|
// if it's ok to run out of memory, then don't bother aligning them;
|
||||||
|
// this gives better packing, but may fail due to OOM (even though
|
||||||
|
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||||
|
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||||
|
context->align = 1;
|
||||||
|
else {
|
||||||
|
// if it's not ok to run out of memory, then quantize the widths
|
||||||
|
// so that num_nodes is always enough nodes.
|
||||||
|
//
|
||||||
|
// I.e. num_nodes * align >= width
|
||||||
|
// align >= width / num_nodes
|
||||||
|
// align = ceil(width/num_nodes)
|
||||||
|
|
||||||
|
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i < num_nodes-1; ++i)
|
||||||
|
nodes[i].next = &nodes[i+1];
|
||||||
|
nodes[i].next = NULL;
|
||||||
|
context->init_mode = STBRP__INIT_skyline;
|
||||||
|
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||||
|
context->free_head = &nodes[0];
|
||||||
|
context->active_head = &context->extra[0];
|
||||||
|
context->width = width;
|
||||||
|
context->height = height;
|
||||||
|
context->num_nodes = num_nodes;
|
||||||
|
stbrp_setup_allow_out_of_mem(context, 0);
|
||||||
|
|
||||||
|
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||||
|
context->extra[0].x = 0;
|
||||||
|
context->extra[0].y = 0;
|
||||||
|
context->extra[0].next = &context->extra[1];
|
||||||
|
context->extra[1].x = (stbrp_coord) width;
|
||||||
|
context->extra[1].y = (1<<30);
|
||||||
|
context->extra[1].next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find minimum y position if it starts at x1
|
||||||
|
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||||
|
{
|
||||||
|
stbrp_node *node = first;
|
||||||
|
int x1 = x0 + width;
|
||||||
|
int min_y, visited_width, waste_area;
|
||||||
|
|
||||||
|
STBRP__NOTUSED(c);
|
||||||
|
|
||||||
|
STBRP_ASSERT(first->x <= x0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// skip in case we're past the node
|
||||||
|
while (node->next->x <= x0)
|
||||||
|
++node;
|
||||||
|
#else
|
||||||
|
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STBRP_ASSERT(node->x <= x0);
|
||||||
|
|
||||||
|
min_y = 0;
|
||||||
|
waste_area = 0;
|
||||||
|
visited_width = 0;
|
||||||
|
while (node->x < x1) {
|
||||||
|
if (node->y > min_y) {
|
||||||
|
// raise min_y higher.
|
||||||
|
// we've accounted for all waste up to min_y,
|
||||||
|
// but we'll now add more waste for everything we've visited
|
||||||
|
waste_area += visited_width * (node->y - min_y);
|
||||||
|
min_y = node->y;
|
||||||
|
// the first time through, visited_width might be reduced
|
||||||
|
if (node->x < x0)
|
||||||
|
visited_width += node->next->x - x0;
|
||||||
|
else
|
||||||
|
visited_width += node->next->x - node->x;
|
||||||
|
} else {
|
||||||
|
// add waste area
|
||||||
|
int under_width = node->next->x - node->x;
|
||||||
|
if (under_width + visited_width > width)
|
||||||
|
under_width = width - visited_width;
|
||||||
|
waste_area += under_width * (min_y - node->y);
|
||||||
|
visited_width += under_width;
|
||||||
|
}
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pwaste = waste_area;
|
||||||
|
return min_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
stbrp_node **prev_link;
|
||||||
|
} stbrp__findresult;
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||||
|
{
|
||||||
|
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||||
|
stbrp__findresult fr;
|
||||||
|
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||||
|
|
||||||
|
// align to multiple of c->align
|
||||||
|
width = (width + c->align - 1);
|
||||||
|
width -= width % c->align;
|
||||||
|
STBRP_ASSERT(width % c->align == 0);
|
||||||
|
|
||||||
|
// if it can't possibly fit, bail immediately
|
||||||
|
if (width > c->width || height > c->height) {
|
||||||
|
fr.prev_link = NULL;
|
||||||
|
fr.x = fr.y = 0;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
while (node->x + width <= c->width) {
|
||||||
|
int y,waste;
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||||
|
// bottom left
|
||||||
|
if (y < best_y) {
|
||||||
|
best_y = y;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// best-fit
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
// can only use it if it first vertically
|
||||||
|
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||||
|
|
||||||
|
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||||
|
//
|
||||||
|
// e.g, if fitting
|
||||||
|
//
|
||||||
|
// ____________________
|
||||||
|
// |____________________|
|
||||||
|
//
|
||||||
|
// into
|
||||||
|
//
|
||||||
|
// | |
|
||||||
|
// | ____________|
|
||||||
|
// |____________|
|
||||||
|
//
|
||||||
|
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||||
|
//
|
||||||
|
// This makes BF take about 2x the time
|
||||||
|
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||||
|
tail = c->active_head;
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
// find first node that's admissible
|
||||||
|
while (tail->x < width)
|
||||||
|
tail = tail->next;
|
||||||
|
while (tail) {
|
||||||
|
int xpos = tail->x - width;
|
||||||
|
int y,waste;
|
||||||
|
STBRP_ASSERT(xpos >= 0);
|
||||||
|
// find the left position that matches this
|
||||||
|
while (node->next->x <= xpos) {
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
if (y <= best_y) {
|
||||||
|
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||||
|
best_x = xpos;
|
||||||
|
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tail = tail->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fr.prev_link = best;
|
||||||
|
fr.x = best_x;
|
||||||
|
fr.y = best_y;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||||
|
{
|
||||||
|
// find best position according to heuristic
|
||||||
|
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||||
|
stbrp_node *node, *cur;
|
||||||
|
|
||||||
|
// bail if:
|
||||||
|
// 1. it failed
|
||||||
|
// 2. the best node doesn't fit (we don't always check this)
|
||||||
|
// 3. we're out of memory
|
||||||
|
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||||
|
res.prev_link = NULL;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on success, create new node
|
||||||
|
node = context->free_head;
|
||||||
|
node->x = (stbrp_coord) res.x;
|
||||||
|
node->y = (stbrp_coord) (res.y + height);
|
||||||
|
|
||||||
|
context->free_head = node->next;
|
||||||
|
|
||||||
|
// insert the new node into the right starting point, and
|
||||||
|
// let 'cur' point to the remaining nodes needing to be
|
||||||
|
// stitched back in
|
||||||
|
|
||||||
|
cur = *res.prev_link;
|
||||||
|
if (cur->x < res.x) {
|
||||||
|
// preserve the existing one, so start testing with the next one
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
cur->next = node;
|
||||||
|
cur = next;
|
||||||
|
} else {
|
||||||
|
*res.prev_link = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// from here, traverse cur and free the nodes, until we get to one
|
||||||
|
// that shouldn't be freed
|
||||||
|
while (cur->next && cur->next->x <= res.x + width) {
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
// move the current node to the free list
|
||||||
|
cur->next = context->free_head;
|
||||||
|
context->free_head = cur;
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stitch the list back in
|
||||||
|
node->next = cur;
|
||||||
|
|
||||||
|
if (cur->x < res.x + width)
|
||||||
|
cur->x = (stbrp_coord) (res.x + width);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur->x < context->width) {
|
||||||
|
STBRP_ASSERT(cur->x < cur->next->x);
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(cur->next == NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
int count=0;
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
cur = context->free_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(count == context->num_nodes+2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
if (p->h > q->h)
|
||||||
|
return -1;
|
||||||
|
if (p->h < q->h)
|
||||||
|
return 1;
|
||||||
|
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||||
|
{
|
||||||
|
int i, all_rects_packed = 1;
|
||||||
|
|
||||||
|
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort according to heuristic
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||||
|
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||||
|
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||||
|
} else {
|
||||||
|
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||||
|
if (fr.prev_link) {
|
||||||
|
rects[i].x = (stbrp_coord) fr.x;
|
||||||
|
rects[i].y = (stbrp_coord) fr.y;
|
||||||
|
} else {
|
||||||
|
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unsort
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||||
|
|
||||||
|
// set was_packed flags and all_rects_packed status
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||||
|
if (!rects[i].was_packed)
|
||||||
|
all_rects_packed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the all_rects_packed status
|
||||||
|
return all_rects_packed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
This software is available under 2 licenses -- choose whichever you prefer.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE A - MIT License
|
||||||
|
Copyright (c) 2017 Sean Barrett
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||||
|
software, either in source code form or as a compiled binary, for any purpose,
|
||||||
|
commercial or non-commercial, and by any means.
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||||
|
software dedicate any and all copyright interest in the software to the public
|
||||||
|
domain. We make this dedication for the benefit of the public at large and to
|
||||||
|
the detriment of our heirs and successors. We intend this dedication to be an
|
||||||
|
overt act of relinquishment in perpetuity of all present and future rights to
|
||||||
|
this software under copyright law.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
1527
src/imstb_textedit.h
Normal file
1527
src/imstb_textedit.h
Normal file
File diff suppressed because it is too large
Load Diff
5085
src/imstb_truetype.h
Normal file
5085
src/imstb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
64
src/main.cpp
64
src/main.cpp
@ -1,15 +1,46 @@
|
|||||||
|
#include "imgui.h"
|
||||||
|
#include <SDL3/SDL_events.h>
|
||||||
|
#include <SDL3/SDL_gamepad.h>
|
||||||
#include <SDL3/SDL_init.h>
|
#include <SDL3/SDL_init.h>
|
||||||
|
#include <SDL3/SDL_mouse.h>
|
||||||
#include <SDL3/SDL_scancode.h>
|
#include <SDL3/SDL_scancode.h>
|
||||||
#define SDL_MAIN_USE_CALLBACKS
|
#define SDL_MAIN_USE_CALLBACKS
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
|
||||||
static Camera camera;
|
static Camera camera;
|
||||||
static Renderer renderer;
|
static Renderer renderer;
|
||||||
|
|
||||||
|
static SDL_Gamepad* GetGamepad() {
|
||||||
|
int count = 0;
|
||||||
|
SDL_JoystickID* jids = SDL_GetGamepads(&count);
|
||||||
|
|
||||||
|
SDL_Gamepad* gamepad = nullptr;
|
||||||
|
for(int i = 0; i < count; i++) {
|
||||||
|
SDL_Gamepad* candidate_gamepad = SDL_OpenGamepad(jids[i]);
|
||||||
|
|
||||||
|
if(!gamepad) {
|
||||||
|
gamepad = candidate_gamepad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!gamepad) {
|
||||||
|
std::cerr << "No Gamepad :(" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Selected: " << SDL_GetGamepadName(gamepad) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_free(jids);
|
||||||
|
return gamepad;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) {
|
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) {
|
||||||
(void)appstate;
|
(void)appstate;
|
||||||
(void)argc;
|
(void)argc;
|
||||||
@ -17,20 +48,26 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) {
|
|||||||
SDL_Window* win = SDL_CreateWindow("Kale", 960, 540, SDL_WINDOW_RESIZABLE);
|
SDL_Window* win = SDL_CreateWindow("Kale", 960, 540, SDL_WINDOW_RESIZABLE);
|
||||||
SDL_SetWindowRelativeMouseMode(win, true);
|
SDL_SetWindowRelativeMouseMode(win, true);
|
||||||
|
|
||||||
|
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
||||||
|
|
||||||
|
SDL_SetGamepadEventsEnabled(true);
|
||||||
|
|
||||||
if (!renderer.init(win))
|
if (!renderer.init(win))
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
|
|
||||||
|
renderer.gamepad = GetGamepad();
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppIterate(void* appstate) {
|
SDL_AppResult SDL_AppIterate(void* appstate) {
|
||||||
(void)appstate;
|
(void)appstate;
|
||||||
|
camera.on_gamepad(renderer.gamepad);
|
||||||
camera.update();
|
camera.update();
|
||||||
|
|
||||||
uint32_t sw_w = renderer.render_w;
|
uint32_t sw_w = renderer.render_w;
|
||||||
uint32_t sw_h = renderer.render_h;
|
uint32_t sw_h = renderer.render_h;
|
||||||
CameraUBO ubo = camera.ubo((float)sw_w / (float)(sw_h ? sw_h : 1));
|
CameraUBO ubo = camera.ubo((float)sw_w / (float)(sw_h ? sw_h : 1));
|
||||||
|
|
||||||
renderer.draw(ubo);
|
renderer.draw(ubo);
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
@ -38,19 +75,34 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
|||||||
|
|
||||||
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
||||||
(void)appstate;
|
(void)appstate;
|
||||||
|
ImGui_ImplSDL3_ProcessEvent(event);
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
|
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
|
||||||
case SDL_EVENT_QUIT:
|
case SDL_EVENT_QUIT:
|
||||||
return SDL_APP_SUCCESS;
|
return SDL_APP_SUCCESS;
|
||||||
|
case SDL_EVENT_GAMEPAD_ADDED:
|
||||||
|
if(!renderer.gamepad)
|
||||||
|
renderer.gamepad = SDL_OpenGamepad(event->gdevice.which);
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||||
|
if (renderer.gamepad && SDL_GetGamepadID(renderer.gamepad) == event->gdevice.which) {
|
||||||
|
SDL_CloseGamepad(renderer.gamepad);
|
||||||
|
renderer.gamepad = nullptr;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SDL_EVENT_KEY_DOWN:
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
if(event->key.scancode == SDL_SCANCODE_ESCAPE) {
|
||||||
|
renderer.in_menu = !renderer.in_menu;
|
||||||
|
SDL_Window* win = SDL_GetWindowFromID(event->key.windowID);
|
||||||
|
SDL_SetWindowRelativeMouseMode(win, !renderer.in_menu);
|
||||||
|
}
|
||||||
case SDL_EVENT_KEY_UP:
|
case SDL_EVENT_KEY_UP:
|
||||||
if(event->key.scancode == SDL_SCANCODE_ESCAPE)
|
if(!renderer.in_menu)
|
||||||
return SDL_APP_SUCCESS;
|
camera.on_key(event->key.scancode, event->type == SDL_EVENT_KEY_DOWN);
|
||||||
camera.on_key(event->key.scancode, event->type == SDL_EVENT_KEY_DOWN);
|
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_MOUSE_MOTION:
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
camera.on_mouse_motion(event->motion.xrel, event->motion.yrel);
|
if(!renderer.in_menu)
|
||||||
|
camera.on_mouse_motion(event->motion.xrel, event->motion.yrel);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
void ScenePipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
void ScenePipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
||||||
vert = load_shader(dev, "shaders/scene.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 1);
|
vert = load_shader(dev, "shaders/scene.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 1);
|
||||||
frag = load_shader(dev, "shaders/scene.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 0, 0);
|
frag = load_shader(dev, "shaders/scene.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 0);
|
||||||
|
|
||||||
SDL_GPUVertexBufferDescription vert_buf {
|
SDL_GPUVertexBufferDescription vert_buf {
|
||||||
.slot = 0,
|
.slot = 0,
|
||||||
@ -16,8 +16,8 @@ void ScenePipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
|||||||
|
|
||||||
SDL_GPUVertexAttribute attrs[3] = {
|
SDL_GPUVertexAttribute attrs[3] = {
|
||||||
{ .location = 0, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = 0 },
|
{ .location = 0, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = 0 },
|
||||||
{ .location = 1, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4, .offset = (uint32_t)offsetof(Vertex, color) },
|
{ .location = 1, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2, .offset = (uint32_t)offsetof(Vertex, uv) },
|
||||||
{ .location = 2, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = (uint32_t)offsetof(Vertex, normal) },
|
{ .location = 2, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = (uint32_t)offsetof(Vertex, norm) },
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_GPUColorTargetDescription color_tgt {
|
SDL_GPUColorTargetDescription color_tgt {
|
||||||
@ -48,9 +48,16 @@ void ScenePipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
|||||||
.cull_mode = SDL_GPU_CULLMODE_NONE,
|
.cull_mode = SDL_GPU_CULLMODE_NONE,
|
||||||
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
|
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
|
||||||
},
|
},
|
||||||
|
.depth_stencil_state = {
|
||||||
|
.compare_op = SDL_GPU_COMPAREOP_LESS,
|
||||||
|
.enable_depth_test = true,
|
||||||
|
.enable_depth_write = true,
|
||||||
|
},
|
||||||
.target_info = {
|
.target_info = {
|
||||||
.color_target_descriptions = &color_tgt,
|
.color_target_descriptions = &color_tgt,
|
||||||
.num_color_targets = 1,
|
.num_color_targets = 1,
|
||||||
|
.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
|
||||||
|
.has_depth_stencil_target = true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,9 +72,9 @@ void ScenePipeline::destroy(SDL_GPUDevice* dev) {
|
|||||||
if (frag) SDL_ReleaseGPUShader(dev, frag);
|
if (frag) SDL_ReleaseGPUShader(dev, frag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlitPipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
void RayPipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
||||||
vert = load_shader(dev, "shaders/blit.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 0);
|
vert = load_shader(dev, "shaders/ray.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 0);
|
||||||
frag = load_shader(dev, "shaders/blit.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 1);
|
frag = load_shader(dev, "shaders/ray.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 2, 1);
|
||||||
|
|
||||||
SDL_GPUColorTargetDescription color_tgt {
|
SDL_GPUColorTargetDescription color_tgt {
|
||||||
.format = SDL_GetGPUSwapchainTextureFormat(dev, win),
|
.format = SDL_GetGPUSwapchainTextureFormat(dev, win),
|
||||||
@ -96,17 +103,17 @@ void BlitPipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
|||||||
|
|
||||||
pipeline = SDL_CreateGPUGraphicsPipeline(dev, &info);
|
pipeline = SDL_CreateGPUGraphicsPipeline(dev, &info);
|
||||||
if (!pipeline)
|
if (!pipeline)
|
||||||
std::cerr << "Blit pipeline failed: " << SDL_GetError() << std::endl;
|
std::cerr << "Ray pipeline failed: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlitPipeline::destroy(SDL_GPUDevice* dev) {
|
void RayPipeline::destroy(SDL_GPUDevice* dev) {
|
||||||
if (pipeline) SDL_ReleaseGPUGraphicsPipeline(dev, pipeline);
|
if (pipeline) SDL_ReleaseGPUGraphicsPipeline(dev, pipeline);
|
||||||
if (vert) SDL_ReleaseGPUShader(dev, vert);
|
if (vert) SDL_ReleaseGPUShader(dev, vert);
|
||||||
if (frag) SDL_ReleaseGPUShader(dev, frag);
|
if (frag) SDL_ReleaseGPUShader(dev, frag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostPipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
void PostPipeline::create(SDL_GPUDevice* dev, SDL_Window* win) {
|
||||||
vert = load_shader(dev, "shaders/blit.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 0);
|
vert = load_shader(dev, "shaders/ray.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX, 0, 0);
|
||||||
frag = load_shader(dev, "shaders/post.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 1);
|
frag = load_shader(dev, "shaders/post.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 1);
|
||||||
|
|
||||||
SDL_GPUColorTargetDescription color_tgt {
|
SDL_GPUColorTargetDescription color_tgt {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ struct ScenePipeline {
|
|||||||
void destroy(SDL_GPUDevice* dev);
|
void destroy(SDL_GPUDevice* dev);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BlitPipeline {
|
struct RayPipeline {
|
||||||
SDL_GPUGraphicsPipeline* pipeline = nullptr;
|
SDL_GPUGraphicsPipeline* pipeline = nullptr;
|
||||||
SDL_GPUShader* vert = nullptr;
|
SDL_GPUShader* vert = nullptr;
|
||||||
SDL_GPUShader* frag = nullptr;
|
SDL_GPUShader* frag = nullptr;
|
||||||
|
|||||||
268
src/renderer.cpp
268
src/renderer.cpp
@ -1,9 +1,24 @@
|
|||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "gpu.h"
|
#include "gpu.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <SDL3/SDL_gpu.h>
|
||||||
|
#include <SDL3/SDL_gamepad.h>
|
||||||
|
#include <SDL3/SDL_oldnames.h>
|
||||||
|
#include <SDL3/SDL_pixels.h>
|
||||||
|
#include <SDL3/SDL_timer.h>
|
||||||
|
#include <SDL3_image/SDL_image.h>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#define TINYOBJLOADER_IMPLEMENTATION
|
#include "bsp/BSP.h"
|
||||||
#include "tiny_obj_loader.h"
|
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
#include "imgui_impl_sdlgpu3.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern int post_mode;
|
||||||
|
extern vec2 atlas_adjust;
|
||||||
|
|
||||||
bool Renderer::init(SDL_Window* w) {
|
bool Renderer::init(SDL_Window* w) {
|
||||||
win = w;
|
win = w;
|
||||||
@ -12,81 +27,111 @@ bool Renderer::init(SDL_Window* w) {
|
|||||||
|
|
||||||
SDL_ClaimWindowForGPUDevice(dev, win);
|
SDL_ClaimWindowForGPUDevice(dev, win);
|
||||||
|
|
||||||
load_obj();
|
printf("LOAD BIN?\n");
|
||||||
|
load_bin();
|
||||||
|
printf("BIN LOADED\n");
|
||||||
|
|
||||||
render_sampler = create_linear_sampler(dev);
|
render_sampler = create_linear_sampler(dev);
|
||||||
|
SDL_GPUSamplerCreateInfo depth_sampler_info {
|
||||||
|
.min_filter = SDL_GPU_FILTER_NEAREST,
|
||||||
|
.mag_filter = SDL_GPU_FILTER_NEAREST,
|
||||||
|
.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST,
|
||||||
|
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT,
|
||||||
|
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT,
|
||||||
|
.compare_op = SDL_GPU_COMPAREOP_INVALID,
|
||||||
|
.enable_compare = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
depth_sampler = SDL_CreateGPUSampler(dev, &depth_sampler_info);
|
||||||
|
atlas_sampler = SDL_CreateGPUSampler(dev, &depth_sampler_info);
|
||||||
|
|
||||||
resize_render_texture(960, 540);
|
resize_render_texture(960, 540);
|
||||||
|
|
||||||
scene.create(dev, win);
|
setup_imgui();
|
||||||
blit.create(dev, win);
|
|
||||||
post.create(dev, win);
|
|
||||||
|
|
||||||
return scene.pipeline && blit.pipeline;
|
fprintf(stderr, "Pipeline creation....");
|
||||||
|
scene.create(dev, win);
|
||||||
|
ray.create(dev, win);
|
||||||
|
post.create(dev, win);
|
||||||
|
fprintf(stderr, "finished\n");
|
||||||
|
|
||||||
|
return scene.pipeline && ray.pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::destroy() {
|
void Renderer::destroy() {
|
||||||
if (render_tex) SDL_ReleaseGPUTexture(dev, render_tex);
|
if (render_tex) SDL_ReleaseGPUTexture(dev, render_tex);
|
||||||
if (post_tex) SDL_ReleaseGPUTexture(dev, post_tex);
|
if (post_tex) SDL_ReleaseGPUTexture(dev, post_tex);
|
||||||
if (render_sampler) SDL_ReleaseGPUSampler(dev, render_sampler);
|
if (render_sampler) SDL_ReleaseGPUSampler(dev, render_sampler);
|
||||||
if (vert_buff) SDL_ReleaseGPUBuffer(dev, vert_buff);
|
if (vert_buff) SDL_ReleaseGPUBuffer(dev, vert_buff);
|
||||||
|
if (depth_tex) SDL_ReleaseGPUTexture(dev, depth_tex);
|
||||||
|
if (gamepad) SDL_CloseGamepad(gamepad);
|
||||||
scene.destroy(dev);
|
scene.destroy(dev);
|
||||||
blit.destroy(dev);
|
ray.destroy(dev);
|
||||||
post.destroy(dev);
|
post.destroy(dev);
|
||||||
SDL_DestroyGPUDevice(dev);
|
SDL_DestroyGPUDevice(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::load_obj() {
|
bool Renderer::load_bin() {
|
||||||
const std::string& path = "assets/homer.obj";
|
const char* path = "assets/bin/hl1.bin";
|
||||||
tinyobj::attrib_t attrib;
|
const char* tex_path = "assets/bin/hl1.bin.png";
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
/*if(!std::filesystem::exists(path) || !std::filesystem::exists(tex_path)) {
|
||||||
std::vector<tinyobj::material_t> materials;
|
SDL_Log("Failed to find %s (or maybe %s)", path, tex_path);
|
||||||
std::string warn, err;
|
return false;
|
||||||
if(!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, path.c_str())) {
|
}*/
|
||||||
std::cerr << "OBJ fail: " << warn << err << std::endl;
|
|
||||||
|
size_t bin_size;
|
||||||
|
const uint8_t* bin_data = (uint8_t*)SDL_LoadFile(path, &bin_size);
|
||||||
|
if(!bin_data) {
|
||||||
|
SDL_Log("Failed to read %s %s", path, tex_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
vertices.resize(bin_size/sizeof(Vertex));
|
||||||
|
memcpy(vertices.data(), bin_data, bin_size);
|
||||||
|
SDL_Log("File size: %zu, %zu vertices", bin_size, bin_size/3);
|
||||||
|
|
||||||
vertices.clear();
|
|
||||||
for(const auto& shape : shapes) {
|
|
||||||
const auto& indices = shape.mesh.indices;
|
|
||||||
for(size_t i = 0; i < indices.size(); i += 3) {
|
|
||||||
// Use OBJ normals if present, otherwise compute face normal
|
|
||||||
vec3 pos[3];
|
|
||||||
vec3 nor[3];
|
|
||||||
bool has_normals = true;
|
|
||||||
|
|
||||||
for(int v = 0; v < 3; v++) {
|
SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(dev);
|
||||||
const auto& idx = indices[i + v];
|
SDL_GPUCopyPass *copy_pass = SDL_BeginGPUCopyPass(cmd);
|
||||||
pos[v] = vec3(
|
int w,h;
|
||||||
attrib.vertices[3 * idx.vertex_index + 0],
|
atlas_tex = IMG_LoadGPUTexture(dev, copy_pass, tex_path, &w, &h);
|
||||||
attrib.vertices[3 * idx.vertex_index + 1],
|
|
||||||
attrib.vertices[3 * idx.vertex_index + 2]
|
|
||||||
);
|
|
||||||
if(idx.normal_index >= 0) {
|
|
||||||
nor[v] = vec3(
|
|
||||||
attrib.normals[3 * idx.normal_index + 0],
|
|
||||||
attrib.normals[3 * idx.normal_index + 1],
|
|
||||||
attrib.normals[3 * idx.normal_index + 2]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
has_normals = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!has_normals) {
|
SDL_EndGPUCopyPass(copy_pass);
|
||||||
vec3 face_normal = glm::normalize(glm::cross(pos[1] - pos[0], pos[2] - pos[0]));
|
SDL_SubmitGPUCommandBuffer(cmd);
|
||||||
nor[0] = nor[1] = nor[2] = face_normal;
|
SDL_GPUBufferCreateInfo info {
|
||||||
}
|
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
|
||||||
|
.size = static_cast<uint32_t>(vertices.size() * sizeof(Vertex)),
|
||||||
|
};
|
||||||
|
vert_buff = SDL_CreateGPUBuffer(dev, &info);
|
||||||
|
upload_buffer(dev, vert_buff, vertices.data(), info.size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for(int v = 0; v < 3; v++) {
|
void Renderer::setup_imgui() {
|
||||||
vertices.push_back(Vertex {
|
IMGUI_CHECKVERSION();
|
||||||
.pos = pos[v],
|
ImGui::CreateContext();
|
||||||
.color = vec4(abs(sin(pos[v].x)), abs(cos(pos[v].y)), abs(sin(pos[v].z) * cos(pos[v].y)), 1.0f),
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
.normal = nor[v],
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
});
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||||
}
|
|
||||||
}
|
ImGui::StyleColorsDark();
|
||||||
}
|
|
||||||
|
ImGui_ImplSDL3_InitForSDLGPU(win);
|
||||||
|
ImGui_ImplSDLGPU3_InitInfo init_info = {
|
||||||
|
.Device = dev,
|
||||||
|
.ColorTargetFormat = SDL_GetGPUSwapchainTextureFormat(dev, win),
|
||||||
|
.MSAASamples = SDL_GPU_SAMPLECOUNT_1,
|
||||||
|
.SwapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR,
|
||||||
|
.PresentMode = SDL_GPU_PRESENTMODE_VSYNC,
|
||||||
|
};
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_Init(&init_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Renderer::load_bsp() {
|
||||||
|
const std::string& path = "assets/hl1.bsp";
|
||||||
|
HLBSP::BSP bsp(path);
|
||||||
|
bsp.load_vertices();
|
||||||
|
vertices = bsp.textured_vertices;
|
||||||
|
|
||||||
SDL_GPUBufferCreateInfo info {
|
SDL_GPUBufferCreateInfo info {
|
||||||
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
|
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
|
||||||
@ -101,6 +146,19 @@ void Renderer::resize_render_texture(uint32_t w, uint32_t h) {
|
|||||||
SDL_WaitForGPUIdle(dev);
|
SDL_WaitForGPUIdle(dev);
|
||||||
if (render_tex) SDL_ReleaseGPUTexture(dev, render_tex);
|
if (render_tex) SDL_ReleaseGPUTexture(dev, render_tex);
|
||||||
if (post_tex) SDL_ReleaseGPUTexture(dev, post_tex);
|
if (post_tex) SDL_ReleaseGPUTexture(dev, post_tex);
|
||||||
|
if (depth_tex) SDL_ReleaseGPUTexture(dev, depth_tex);
|
||||||
|
|
||||||
|
SDL_GPUTextureCreateInfo depth_info {
|
||||||
|
.type = SDL_GPU_TEXTURETYPE_2D,
|
||||||
|
.format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
|
||||||
|
.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER,
|
||||||
|
.width = w,
|
||||||
|
.height = h,
|
||||||
|
.layer_count_or_depth = 1,
|
||||||
|
.num_levels = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
depth_tex = SDL_CreateGPUTexture(dev, &depth_info);
|
||||||
render_tex = create_render_texture(dev, win, w, h);
|
render_tex = create_render_texture(dev, win, w, h);
|
||||||
post_tex = create_render_texture(dev, win, w, h);
|
post_tex = create_render_texture(dev, win, w, h);
|
||||||
render_w = w;
|
render_w = w;
|
||||||
@ -118,15 +176,29 @@ void Renderer::pass_scene(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo) {
|
|||||||
.store_op = SDL_GPU_STOREOP_STORE,
|
.store_op = SDL_GPU_STOREOP_STORE,
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &tgt, 1, NULL);
|
SDL_GPUDepthStencilTargetInfo depth_tgt {
|
||||||
|
.texture = depth_tex,
|
||||||
|
.clear_depth = 1.0f,
|
||||||
|
.load_op = SDL_GPU_LOADOP_CLEAR,
|
||||||
|
.store_op = SDL_GPU_STOREOP_STORE,
|
||||||
|
.stencil_load_op = SDL_GPU_LOADOP_DONT_CARE,
|
||||||
|
.stencil_store_op = SDL_GPU_STOREOP_STORE,
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &tgt, 1, &depth_tgt);
|
||||||
SDL_BindGPUGraphicsPipeline(pass, scene.pipeline);
|
SDL_BindGPUGraphicsPipeline(pass, scene.pipeline);
|
||||||
SDL_GPUBufferBinding binding { .buffer = vert_buff, .offset = 0 };
|
SDL_GPUBufferBinding binding { .buffer = vert_buff, .offset = 0 };
|
||||||
SDL_BindGPUVertexBuffers(pass, 0, &binding, 1);
|
SDL_BindGPUVertexBuffers(pass, 0, &binding, 1);
|
||||||
|
|
||||||
|
SDL_GPUTextureSamplerBinding tex[1] = {
|
||||||
|
{ .texture = atlas_tex, .sampler = atlas_sampler },
|
||||||
|
};
|
||||||
|
SDL_BindGPUFragmentSamplers(pass, 0, tex, 1);
|
||||||
SDL_DrawGPUPrimitives(pass, vertices.size(), 1, 0, 0);
|
SDL_DrawGPUPrimitives(pass, vertices.size(), 1, 0, 0);
|
||||||
SDL_EndGPURenderPass(pass);
|
SDL_EndGPURenderPass(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::pass_blit(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo) {
|
void Renderer::pass_ray(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo) {
|
||||||
SDL_PushGPUFragmentUniformData(cmd, 0, &ubo, sizeof(ubo));
|
SDL_PushGPUFragmentUniformData(cmd, 0, &ubo, sizeof(ubo));
|
||||||
|
|
||||||
SDL_GPUColorTargetInfo tgt {
|
SDL_GPUColorTargetInfo tgt {
|
||||||
@ -136,9 +208,12 @@ void Renderer::pass_blit(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &tgt, 1, NULL);
|
SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &tgt, 1, NULL);
|
||||||
SDL_BindGPUGraphicsPipeline(pass, blit.pipeline);
|
SDL_BindGPUGraphicsPipeline(pass, ray.pipeline);
|
||||||
SDL_GPUTextureSamplerBinding tex { .texture = render_tex, .sampler = render_sampler };
|
SDL_GPUTextureSamplerBinding texs[2] = {
|
||||||
SDL_BindGPUFragmentSamplers(pass, 0, &tex, 1);
|
{ .texture = render_tex, .sampler = render_sampler },
|
||||||
|
{ .texture = depth_tex, .sampler = depth_sampler },
|
||||||
|
};
|
||||||
|
SDL_BindGPUFragmentSamplers(pass, 0, texs, 2);
|
||||||
SDL_DrawGPUPrimitives(pass, 3, 1, 0, 0);
|
SDL_DrawGPUPrimitives(pass, 3, 1, 0, 0);
|
||||||
SDL_EndGPURenderPass(pass);
|
SDL_EndGPURenderPass(pass);
|
||||||
}
|
}
|
||||||
@ -160,7 +235,69 @@ void Renderer::pass_post(SDL_GPUCommandBuffer* cmd, SDL_GPUTexture* swapchain, c
|
|||||||
SDL_EndGPURenderPass(pass);
|
SDL_EndGPURenderPass(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::draw(const CameraUBO& ubo) {
|
void Renderer::draw_imgui(SDL_GPUCommandBuffer* cmd, SDL_GPUTexture* tex) {
|
||||||
|
ImGui_ImplSDLGPU3_NewFrame();
|
||||||
|
ImGui_ImplSDL3_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
ImGui::Begin("Kale Renderer");
|
||||||
|
ImGui::Text("Fps: %f", fps);
|
||||||
|
|
||||||
|
if(ImGui::RadioButton("Standard", (post_mode == 0)))
|
||||||
|
post_mode = 0;
|
||||||
|
if(ImGui::RadioButton("Black/White", (post_mode == 1)))
|
||||||
|
post_mode = 1;
|
||||||
|
if(ImGui::RadioButton("Dithered", (post_mode == 2)))
|
||||||
|
post_mode = 2;
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::SliderFloat("Atlas du", &atlas_adjust.x, 0.1f, 100.0f);
|
||||||
|
ImGui::SliderFloat("Atlas dv", &atlas_adjust.y, 0.1f, 100.0f);
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::Render();
|
||||||
|
ImDrawData* draw_data = ImGui::GetDrawData();
|
||||||
|
const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f);
|
||||||
|
|
||||||
|
if(tex && !is_minimized) {
|
||||||
|
ImGui_ImplSDLGPU3_PrepareDrawData(draw_data, cmd);
|
||||||
|
|
||||||
|
SDL_GPUColorTargetInfo tgt_info = {
|
||||||
|
.texture = tex,
|
||||||
|
.mip_level = 0,
|
||||||
|
.layer_or_depth_plane = 0,
|
||||||
|
.load_op = SDL_GPU_LOADOP_LOAD,
|
||||||
|
.store_op = SDL_GPU_STOREOP_STORE,
|
||||||
|
.cycle = false
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &tgt_info, 1, NULL);
|
||||||
|
|
||||||
|
ImGui_ImplSDLGPU3_RenderDrawData(draw_data, cmd, pass);
|
||||||
|
|
||||||
|
SDL_EndGPURenderPass(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::draw(CameraUBO& ubo) {
|
||||||
|
ubo.post_mode = post_mode;
|
||||||
|
ubo.atlas_adjust = atlas_adjust;
|
||||||
|
static std::array<float, 25> frame_times;
|
||||||
|
|
||||||
|
static float last_time = (float)SDL_GetPerformanceCounter()/(float)SDL_GetPerformanceFrequency();
|
||||||
|
|
||||||
|
float now = (float)SDL_GetPerformanceCounter()/(float)SDL_GetPerformanceFrequency();
|
||||||
|
frame_times[frame % 25] = 1.0f/(25.0f*(now-last_time));
|
||||||
|
last_time = now;
|
||||||
|
|
||||||
|
if(frame > 25) {
|
||||||
|
fps = 0.0f;
|
||||||
|
for(const auto& t : frame_times) {
|
||||||
|
fps += t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(dev);
|
SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(dev);
|
||||||
|
|
||||||
SDL_GPUTexture* swapchain;
|
SDL_GPUTexture* swapchain;
|
||||||
@ -176,8 +313,11 @@ void Renderer::draw(const CameraUBO& ubo) {
|
|||||||
resize_render_texture(sw_w, sw_h);
|
resize_render_texture(sw_w, sw_h);
|
||||||
|
|
||||||
pass_scene(cmd, ubo);
|
pass_scene(cmd, ubo);
|
||||||
pass_blit(cmd, ubo);
|
pass_ray(cmd, ubo);
|
||||||
pass_post(cmd, swapchain, ubo);
|
pass_post(cmd, swapchain, ubo);
|
||||||
|
draw_imgui(cmd, swapchain);
|
||||||
|
|
||||||
SDL_SubmitGPUCommandBuffer(cmd);
|
SDL_SubmitGPUCommandBuffer(cmd);
|
||||||
|
|
||||||
|
frame++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,32 +3,49 @@
|
|||||||
#include "pipelines.h"
|
#include "pipelines.h"
|
||||||
#include <SDL3/SDL_gpu.h>
|
#include <SDL3/SDL_gpu.h>
|
||||||
#include <SDL3/SDL_video.h>
|
#include <SDL3/SDL_video.h>
|
||||||
|
#include <SDL3/SDL_gamepad.h>
|
||||||
|
|
||||||
struct Renderer {
|
struct Renderer {
|
||||||
SDL_GPUDevice* dev = nullptr;
|
SDL_GPUDevice* dev = nullptr;
|
||||||
SDL_Window* win = nullptr;
|
SDL_Window* win = nullptr;
|
||||||
|
SDL_Gamepad* gamepad = nullptr;
|
||||||
|
|
||||||
ScenePipeline scene;
|
ScenePipeline scene;
|
||||||
BlitPipeline blit;
|
RayPipeline ray;
|
||||||
PostPipeline post;
|
PostPipeline post;
|
||||||
|
|
||||||
SDL_GPUBuffer* vert_buff = nullptr;
|
SDL_GPUBuffer* vert_buff = nullptr;
|
||||||
SDL_GPUTexture* render_tex = nullptr;
|
SDL_GPUTexture* render_tex = nullptr;
|
||||||
SDL_GPUTexture* post_tex = nullptr;
|
SDL_GPUTexture* post_tex = nullptr;
|
||||||
|
SDL_GPUTexture* depth_tex = nullptr;
|
||||||
|
SDL_GPUTexture* atlas_tex = nullptr;
|
||||||
SDL_GPUSampler* render_sampler = nullptr;
|
SDL_GPUSampler* render_sampler = nullptr;
|
||||||
|
SDL_GPUSampler* depth_sampler = nullptr;
|
||||||
|
SDL_GPUSampler* atlas_sampler = nullptr;
|
||||||
uint32_t render_w = 0, render_h = 0;
|
uint32_t render_w = 0, render_h = 0;
|
||||||
|
uint64_t frame = 0;
|
||||||
|
|
||||||
|
bool in_menu = 0;
|
||||||
|
float fps = 0.0;
|
||||||
|
/* imgui controlled */
|
||||||
|
int post_mode = 0;
|
||||||
|
vec2 atlas_adjust = vec2(0);
|
||||||
|
|
||||||
std::vector<Vertex> vertices;
|
std::vector<Vertex> vertices;
|
||||||
|
|
||||||
bool init(SDL_Window* win);
|
bool init(SDL_Window* win);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
void draw(const CameraUBO& ubo);
|
void draw(CameraUBO& ubo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool load_obj();
|
bool load_bin();
|
||||||
|
bool load_bsp();
|
||||||
|
void setup_imgui();
|
||||||
|
void draw_imgui(SDL_GPUCommandBuffer* cmd, SDL_GPUTexture* tex);
|
||||||
|
void add_gol_layer();
|
||||||
void resize_render_texture(uint32_t w, uint32_t h);
|
void resize_render_texture(uint32_t w, uint32_t h);
|
||||||
void pass_scene(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo);
|
void pass_scene(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo);
|
||||||
void pass_blit(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo);
|
void pass_ray(SDL_GPUCommandBuffer* cmd, const CameraUBO& ubo);
|
||||||
void pass_post(SDL_GPUCommandBuffer* cmd, SDL_GPUTexture* swapchain, const CameraUBO& ubo);
|
void pass_post(SDL_GPUCommandBuffer* cmd, SDL_GPUTexture* swapchain, const CameraUBO& ubo);
|
||||||
};
|
};
|
||||||
|
|||||||
499
src/sdf.cpp
Normal file
499
src/sdf.cpp
Normal file
@ -0,0 +1,499 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <memory>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
#include <variant>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
/* converted form of the rayquake sdf parsing code I wrote with Caz, which was in Zig */
|
||||||
|
|
||||||
|
struct Expr;
|
||||||
|
|
||||||
|
struct BinArgs { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct SqrtArg { std::unique_ptr<Expr> arg; };
|
||||||
|
struct Constant { float val; };
|
||||||
|
struct Input { unsigned idx; };
|
||||||
|
|
||||||
|
using ExprVariant = std::variant<
|
||||||
|
Constant, Input,
|
||||||
|
struct Add, struct Sub, struct Mul, struct Div,
|
||||||
|
struct Min, struct Max, struct Sqrt
|
||||||
|
>;
|
||||||
|
|
||||||
|
struct Add { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Sub { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Mul { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Div { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Min { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Max { std::unique_ptr<Expr> lhs, rhs; };
|
||||||
|
struct Sqrt { std::unique_ptr<Expr> arg; };
|
||||||
|
|
||||||
|
struct Expr {
|
||||||
|
std::variant<Constant, Input, Add, Sub, Mul, Div, Min, Max, Sqrt> v;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Expr(T &&t) : v(std::forward<T>(t)) {}
|
||||||
|
|
||||||
|
Expr(Expr &&) = default;
|
||||||
|
Expr &operator=(Expr &&) = default;
|
||||||
|
Expr(const Expr &) = delete;
|
||||||
|
Expr &operator=(const Expr &) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::unique_ptr<Expr> box(Expr e) {
|
||||||
|
return std::make_unique<Expr>(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr make_constant(float f) { return Expr{ Constant{ f } }; }
|
||||||
|
Expr make_input(unsigned i) { return Expr{ Input{ i } }; }
|
||||||
|
|
||||||
|
Expr expr_add(Expr l, Expr r) { return Expr{ Add{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_sub(Expr l, Expr r) { return Expr{ Sub{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_mul(Expr l, Expr r) { return Expr{ Mul{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_div(Expr l, Expr r) { return Expr{ Div{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_min(Expr l, Expr r) { return Expr{ Min{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_max(Expr l, Expr r) { return Expr{ Max{ box(std::move(l)), box(std::move(r)) } }; }
|
||||||
|
Expr expr_sqrt(Expr a) { return Expr{ Sqrt{ box(std::move(a)) } }; }
|
||||||
|
|
||||||
|
|
||||||
|
/* deep copy */
|
||||||
|
Expr clone(const Expr &e);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::unique_ptr<Expr> clone_box(const std::unique_ptr<T> &p) {
|
||||||
|
return box(clone(*p));
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr clone(const Expr &e) {
|
||||||
|
return std::visit([](const auto &node) -> Expr {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
/* filter 0-ary */
|
||||||
|
if constexpr (std::is_same_v<T, Constant> || std::is_same_v<T, Input>) {
|
||||||
|
return Expr{ node };
|
||||||
|
} else if constexpr (std::is_same_v<T, Sqrt>) {
|
||||||
|
/* only unary */
|
||||||
|
return expr_sqrt(clone(*node.arg));
|
||||||
|
} else {
|
||||||
|
/* all binary nodes have lhs and rhs */
|
||||||
|
using R = T;
|
||||||
|
return Expr{ R{ box(clone(*node.lhs)), box(clone(*node.rhs)) } };
|
||||||
|
}
|
||||||
|
}, e.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
float expr_eval(const Expr &e, const float *vals) {
|
||||||
|
return std::visit([&](const auto &node) -> float {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
if constexpr (std::is_same_v<T, Constant>) return node.val;
|
||||||
|
if constexpr (std::is_same_v<T, Input>) return vals[node.idx];
|
||||||
|
if constexpr (std::is_same_v<T, Add>) return expr_eval(*node.lhs, vals) + expr_eval(*node.rhs, vals);
|
||||||
|
if constexpr (std::is_same_v<T, Sub>) return expr_eval(*node.lhs, vals) - expr_eval(*node.rhs, vals);
|
||||||
|
if constexpr (std::is_same_v<T, Mul>) return expr_eval(*node.lhs, vals) * expr_eval(*node.rhs, vals);
|
||||||
|
if constexpr (std::is_same_v<T, Div>) return expr_eval(*node.lhs, vals) / expr_eval(*node.rhs, vals);
|
||||||
|
if constexpr (std::is_same_v<T, Min>) return std::min(expr_eval(*node.lhs, vals), expr_eval(*node.rhs, vals));
|
||||||
|
if constexpr (std::is_same_v<T, Max>) return std::max(expr_eval(*node.lhs, vals), expr_eval(*node.rhs, vals));
|
||||||
|
if constexpr (std::is_same_v<T, Sqrt>) return std::sqrt(expr_eval(*node.arg, vals));
|
||||||
|
return 0.f;
|
||||||
|
}, e.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class... Ts>
|
||||||
|
struct overloads : Ts... { using Ts::operator()...; };
|
||||||
|
|
||||||
|
// symbolic differentiation
|
||||||
|
Expr expr_diff(const Expr &e, unsigned i) {
|
||||||
|
return std::visit([&](const auto &node) -> Expr {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
|
||||||
|
/* Rules for diff:
|
||||||
|
* - Variable/Input: same? 1 : 0
|
||||||
|
* - Constant: 0
|
||||||
|
* - Addition/Subtraction: a' +/- b'
|
||||||
|
* - Mul: f'g + g'f
|
||||||
|
* - Div: (fg' - gf') / g^2
|
||||||
|
* - Sqrt: (1/2)f' / sqrt(f)
|
||||||
|
* - Min/Max: Identity
|
||||||
|
*/
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Input>)
|
||||||
|
return make_constant(node.idx == i ? 1.f : 0.f);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Constant>)
|
||||||
|
return make_constant(0.f);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Add>)
|
||||||
|
return expr_add(expr_diff(*node.lhs, i), expr_diff(*node.rhs, i));
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Sub>)
|
||||||
|
return expr_sub(expr_diff(*node.lhs, i), expr_diff(*node.rhs, i));
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Mul>)
|
||||||
|
return expr_add(
|
||||||
|
expr_mul(expr_diff(*node.lhs, i), clone(*node.rhs)),
|
||||||
|
expr_mul(expr_diff(*node.rhs, i), clone(*node.lhs))
|
||||||
|
);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Div>)
|
||||||
|
return expr_div(
|
||||||
|
expr_add(
|
||||||
|
expr_mul(clone(*node.lhs), expr_diff(*node.rhs, i)),
|
||||||
|
expr_mul(expr_mul(clone(*node.rhs), expr_diff(*node.lhs, i)),
|
||||||
|
make_constant(-1.f))
|
||||||
|
),
|
||||||
|
expr_mul(clone(*node.rhs), clone(*node.rhs))
|
||||||
|
);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Sqrt>)
|
||||||
|
return expr_mul(
|
||||||
|
expr_diff(*node.arg, i),
|
||||||
|
expr_mul(make_constant(0.5f),
|
||||||
|
expr_div(make_constant(1.f), expr_sqrt(clone(*node.arg))))
|
||||||
|
);
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Min> || std::is_same_v<T, Max>)
|
||||||
|
return clone(e);
|
||||||
|
|
||||||
|
return make_constant(0.f);
|
||||||
|
}, e.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Dual { float val, d; };
|
||||||
|
|
||||||
|
|
||||||
|
/* Autodiff */
|
||||||
|
|
||||||
|
Dual expr_auto_diff(const Expr &e, const Dual *pos) {
|
||||||
|
return std::visit([&](const auto &node) -> Dual {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Input>) return pos[node.idx];
|
||||||
|
if constexpr (std::is_same_v<T, Constant>) return { node.val, 0.f };
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Add>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return { l.val + r.val, l.d + r.d };
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Sub>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return { l.val - r.val, l.d - r.d };
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Mul>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return { l.val * r.val, l.val * r.d + l.d * r.val };
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Div>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return { l.val / r.val, (l.d * r.val - l.val * r.d) / (r.val * r.val) };
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Sqrt>) {
|
||||||
|
auto v = expr_auto_diff(*node.arg, pos);
|
||||||
|
float sv = std::sqrt(v.val);
|
||||||
|
return { sv, v.d / (2.f * sv) };
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Min>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return l.val < r.val ? l : r;
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<T, Max>) {
|
||||||
|
auto l = expr_auto_diff(*node.lhs, pos), r = expr_auto_diff(*node.rhs, pos);
|
||||||
|
return l.val > r.val ? l : r;
|
||||||
|
}
|
||||||
|
return { 0.f, 0.f };
|
||||||
|
}, e.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void expr_ndiff(const Expr &e, const float *vals, float eps, float out[3]) {
|
||||||
|
for (int k = 0; k < 3; k++) {
|
||||||
|
float vp[3] = { vals[0], vals[1], vals[2] };
|
||||||
|
float vm[3] = { vals[0], vals[1], vals[2] };
|
||||||
|
vp[k] += eps; vm[k] -= eps;
|
||||||
|
out[k] = (expr_eval(e, vp) - expr_eval(e, vm)) / (2.f * eps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expr_print(const Expr &e, std::ostream &os = std::cout) {
|
||||||
|
const auto visitor = overloads {
|
||||||
|
[&](const Input& node) { os << "x" << node.idx; },
|
||||||
|
[&](const Constant& node) { os << node.val; },
|
||||||
|
[&](const Sqrt& node) { os << "(sqrt "; expr_print(*node.arg, os); os << ")"; },
|
||||||
|
[&](const auto& node) {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
if constexpr (std::is_same_v<T, Input>) { os << "x" << node.idx; return; }
|
||||||
|
if constexpr (std::is_same_v<T, Constant>) { os << node.val; return; }
|
||||||
|
if constexpr (std::is_same_v<T, Sqrt>) {
|
||||||
|
os << "(sqrt "; expr_print(*node.arg, os); os << ")"; return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *op =
|
||||||
|
std::is_same_v<T, Add> ? "+" :
|
||||||
|
std::is_same_v<T, Sub> ? "-" :
|
||||||
|
std::is_same_v<T, Mul> ? "*" :
|
||||||
|
std::is_same_v<T, Div> ? "/" :
|
||||||
|
std::is_same_v<T, Min> ? "min" : "max";
|
||||||
|
|
||||||
|
os << "(" << op << " ";
|
||||||
|
expr_print(*node.lhs, os);
|
||||||
|
os << " ";
|
||||||
|
expr_print(*node.rhs, os);
|
||||||
|
os << ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::visit(visitor, e.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t gen_glsl_step(
|
||||||
|
const Expr &e,
|
||||||
|
std::unordered_map<const Expr *, size_t> &visited,
|
||||||
|
std::ostringstream &ss)
|
||||||
|
{
|
||||||
|
auto it = visited.find(&e);
|
||||||
|
if (it != visited.end()) return it->second;
|
||||||
|
|
||||||
|
size_t idx = visited.size();
|
||||||
|
visited[&e] = idx;
|
||||||
|
|
||||||
|
std::ostringstream tmp;
|
||||||
|
|
||||||
|
const auto visitor = overloads {
|
||||||
|
[&](const Constant& node) -> std::string {
|
||||||
|
tmp << "vec2(" << node.val << ", 0.0)";
|
||||||
|
return tmp.str();
|
||||||
|
},
|
||||||
|
[&](const Input& node)-> std::string {
|
||||||
|
switch (node.idx) {
|
||||||
|
case 0: return "vec2(v.x, vp.x)";
|
||||||
|
case 1: return "vec2(v.y, vp.y)";
|
||||||
|
case 2: return "vec2(v.z, vp.z)";
|
||||||
|
default: return "vec2(0.0, 0.0)";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[&](const Sqrt& node) -> std::string {
|
||||||
|
size_t a = gen_glsl_step(*node.arg, visited, ss);
|
||||||
|
tmp << "nsqrt(_" << a << ")";
|
||||||
|
return tmp.str();
|
||||||
|
},
|
||||||
|
[&](const auto& node) -> std::string {
|
||||||
|
/* binops */
|
||||||
|
size_t l = gen_glsl_step(*node.lhs, visited, ss);
|
||||||
|
size_t r = gen_glsl_step(*node.rhs, visited, ss);
|
||||||
|
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
|
||||||
|
const char *fn =
|
||||||
|
std::is_same_v<T, Add> ? nullptr :
|
||||||
|
std::is_same_v<T, Sub> ? nullptr :
|
||||||
|
std::is_same_v<T, Mul> ? "nmul" :
|
||||||
|
std::is_same_v<T, Div> ? "ndiv" :
|
||||||
|
std::is_same_v<T, Min> ? "nmin" : "nmax";
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<T, Add>)
|
||||||
|
tmp << "(_" << l << " + _" << r << ")";
|
||||||
|
else if constexpr (std::is_same_v<T, Sub>)
|
||||||
|
tmp << "(_" << l << " - _" << r << ")";
|
||||||
|
else
|
||||||
|
tmp << fn << "(_" << l << ", _" << r << ")";
|
||||||
|
|
||||||
|
return tmp.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string rhs = std::visit(visitor, e.v);
|
||||||
|
|
||||||
|
ss << "vec2 _" << idx << " = " << rhs << ";\n";
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gen_glsl(const Expr &e) {
|
||||||
|
std::unordered_map<const Expr *, size_t> visited;
|
||||||
|
std::ostringstream ss;
|
||||||
|
size_t last = gen_glsl_step(e, visited, ss);
|
||||||
|
ss << "return _" << last << ";";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void skip_ws(const std::string &s, size_t &i) {
|
||||||
|
while (i < s.size() && std::isspace((unsigned char)s[i])) i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_op_char(char c) {
|
||||||
|
return std::isalpha((unsigned char)c) || std::string("+-/*").find(c) != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string parse_op_str(const std::string &s, size_t &i) {
|
||||||
|
size_t start = i;
|
||||||
|
while (i < s.size() && is_op_char(s[i])) i++;
|
||||||
|
return s.substr(start, i - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Expr parse_arg(const std::string &s, size_t &i,
|
||||||
|
std::unordered_map<std::string, unsigned> &vm);
|
||||||
|
|
||||||
|
static Expr parse_iden(const std::string &s, size_t &i,
|
||||||
|
std::unordered_map<std::string, unsigned> &vm) {
|
||||||
|
size_t start = i;
|
||||||
|
while (i < s.size() && std::isalnum((unsigned char)s[i])) i++;
|
||||||
|
std::string name = s.substr(start, i - start);
|
||||||
|
auto [it, inserted] = vm.emplace(name, (unsigned)vm.size());
|
||||||
|
return make_input(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Expr parse_num(const std::string &s, size_t &i) {
|
||||||
|
bool neg = false;
|
||||||
|
if (i < s.size() && s[i] == '-') { neg = true; ++i; }
|
||||||
|
float num = 0.f;
|
||||||
|
int frac_digits = 0;
|
||||||
|
size_t start = i;
|
||||||
|
bool saw_digit = false;
|
||||||
|
|
||||||
|
|
||||||
|
while (i < s.size() && std::isdigit((unsigned char)s[i])) {
|
||||||
|
saw_digit = true;
|
||||||
|
num = num * 10.f + (s[i] - '0');
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < s.size() && s[i] == '.') {
|
||||||
|
++i;
|
||||||
|
while (i < s.size() && std::isdigit((unsigned char)s[i])) {
|
||||||
|
saw_digit = true;
|
||||||
|
num = num * 10.f + (s[i] - '0');
|
||||||
|
++i;
|
||||||
|
++frac_digits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!saw_digit) {
|
||||||
|
return make_constant(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frac_digits > 0) {
|
||||||
|
num /= std::pow(10.f, (float)frac_digits);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (neg) num = -num;
|
||||||
|
return make_constant(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static Expr parse_expr(const std::string &s, size_t &i,
|
||||||
|
std::unordered_map<std::string, unsigned> &vm) {
|
||||||
|
skip_ws(s, i);
|
||||||
|
assert(s[i] == '('); i++;
|
||||||
|
skip_ws(s, i);
|
||||||
|
|
||||||
|
std::string op = parse_op_str(s, i);
|
||||||
|
|
||||||
|
Expr e = [&]() -> Expr {
|
||||||
|
if (op == "sqrt") return expr_sqrt(parse_arg(s, i, vm));
|
||||||
|
Expr lhs = parse_arg(s, i, vm);
|
||||||
|
Expr rhs = parse_arg(s, i, vm);
|
||||||
|
if (op == "+") return expr_add(std::move(lhs), std::move(rhs));
|
||||||
|
if (op == "-") return expr_sub(std::move(lhs), std::move(rhs));
|
||||||
|
if (op == "*") return expr_mul(std::move(lhs), std::move(rhs));
|
||||||
|
if (op == "/") return expr_div(std::move(lhs), std::move(rhs));
|
||||||
|
if (op == "min") return expr_min(std::move(lhs), std::move(rhs));
|
||||||
|
if (op == "max") return expr_max(std::move(lhs), std::move(rhs));
|
||||||
|
std::cerr << "Unknown op: " << op << "\n"; std::exit(1);
|
||||||
|
}();
|
||||||
|
|
||||||
|
skip_ws(s, i);
|
||||||
|
assert(s[i] == ')'); i++;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Expr parse_arg(const std::string &s, size_t &i,
|
||||||
|
std::unordered_map<std::string, unsigned> &vm) {
|
||||||
|
skip_ws(s, i);
|
||||||
|
char c = s[i];
|
||||||
|
if (c == '(') return parse_expr(s, i, vm);
|
||||||
|
if (std::isalpha((unsigned char)c)) return parse_iden(s, i, vm);
|
||||||
|
if (std::isdigit((unsigned char)c) || c == '-' || c == '.')
|
||||||
|
return parse_num(s, i);
|
||||||
|
std::cerr << "Unexpected char '" << c << "'\n"; std::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr expr_parse(const std::string &src) {
|
||||||
|
std::unordered_map<std::string, unsigned> vm;
|
||||||
|
size_t i = 0;
|
||||||
|
skip_ws(src, i);
|
||||||
|
return parse_expr(src, i, vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr sdf_length(Expr pos[3]) {
|
||||||
|
return expr_sqrt(
|
||||||
|
expr_add(
|
||||||
|
expr_mul(clone(pos[0]), clone(pos[0])),
|
||||||
|
expr_add(
|
||||||
|
expr_mul(clone(pos[1]), clone(pos[1])),
|
||||||
|
expr_mul(clone(pos[2]), clone(pos[2]))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr sdf_sphere(Expr pos[3], float radius) {
|
||||||
|
return expr_sub(sdf_length(pos), make_constant(radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr sdf_box(Expr p[3], float b[3]) {
|
||||||
|
Expr q[3] = {
|
||||||
|
expr_sub(expr_sqrt(expr_mul(clone(p[0]), clone(p[0]))), make_constant(b[0])),
|
||||||
|
expr_sub(expr_sqrt(expr_mul(clone(p[1]), clone(p[1]))), make_constant(b[1])),
|
||||||
|
expr_sub(expr_sqrt(expr_mul(clone(p[2]), clone(p[2]))), make_constant(b[2])),
|
||||||
|
};
|
||||||
|
Expr inner[3] = {
|
||||||
|
expr_max(clone(q[0]), make_constant(0.f)),
|
||||||
|
expr_max(clone(q[1]), make_constant(0.f)),
|
||||||
|
expr_max(clone(q[2]), make_constant(0.f)),
|
||||||
|
};
|
||||||
|
return expr_add(
|
||||||
|
sdf_length(inner),
|
||||||
|
expr_min(
|
||||||
|
expr_max(clone(q[0]), expr_max(clone(q[1]), clone(q[2]))),
|
||||||
|
make_constant(0.f)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int main() {
|
||||||
|
Expr x = make_input(0), y = make_input(1), z = make_input(2);
|
||||||
|
Expr x2 = expr_mul(clone(x), clone(x));
|
||||||
|
Expr y2 = expr_mul(clone(y), clone(y));
|
||||||
|
Expr z2 = expr_mul(clone(z), clone(z));
|
||||||
|
Expr l = expr_sqrt(expr_add(expr_add(std::move(x2), std::move(y2)), std::move(z2)));
|
||||||
|
Expr dl = expr_diff(l, 0);
|
||||||
|
|
||||||
|
expr_print(l); std::cout << "\n";
|
||||||
|
expr_print(dl); std::cout << "\n";
|
||||||
|
|
||||||
|
float v[3] = { 0.5f, 0.3f, 0.2f };
|
||||||
|
std::cout << expr_eval(l, v) << "\n";
|
||||||
|
|
||||||
|
std::string src =
|
||||||
|
"(min"
|
||||||
|
" (- y 1)"
|
||||||
|
" (max"
|
||||||
|
" (max x (+ -9 (* -1 x)))"
|
||||||
|
" (* -1 (- (sqrt (+ (+ (* x x) (* y y)) (* z z))) 15))"
|
||||||
|
" ))";
|
||||||
|
|
||||||
|
Expr parsed = expr_parse(src);
|
||||||
|
expr_print(parsed);
|
||||||
|
std::cout << "\n";
|
||||||
|
|
||||||
|
std::cout << "\nGLSL:\n" << gen_glsl(l) << "\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
File diff suppressed because it is too large
Load Diff
15
src/types.h
15
src/types.h
@ -5,13 +5,18 @@ using namespace glm;
|
|||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
vec3 pos;
|
vec3 pos;
|
||||||
vec4 color;
|
vec2 uv;
|
||||||
vec3 normal;
|
vec3 norm;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CameraUBO {
|
struct CameraUBO {
|
||||||
mat4 model;
|
mat4 model;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
|
mat4 inv_view;
|
||||||
|
mat4 inv_proj;
|
||||||
|
vec4 cam_pos;
|
||||||
float time;
|
float time;
|
||||||
|
int post_mode;
|
||||||
|
vec2 atlas_adjust;
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user