v4k-git-backup/demos/99-compute.c

37 lines
908 B
C
Raw Normal View History

2023-09-08 06:16:32 +00:00
#include "v4k.h"
int main() {
// 75% sized, MSAAx2
window_create(50, WINDOW_SQUARE);
window_title(__FILE__);
2023-09-08 08:00:26 +00:00
unsigned TEX_WIDTH = 1000;
2023-09-08 06:16:32 +00:00
unsigned comp = compute(vfs_read("shaders/compute-test.glsl"));
2023-09-08 08:00:26 +00:00
texture_t tex = texture_create(TEX_WIDTH, TEX_WIDTH, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT);
shader_bind(comp);
2023-09-10 16:16:25 +00:00
shader_image(tex, 0, 0, 0, BUFFER_READ);
2023-09-08 08:00:26 +00:00
struct {
float f;
} data;
unsigned buf = ssbo_create(&data, sizeof(data), STREAM_DRAW);
2023-09-08 06:16:32 +00:00
while ( window_swap() && !input_down(KEY_ESC) ){
2023-09-08 06:31:58 +00:00
if (input(KEY_F5)) window_reload();
2023-09-08 08:00:26 +00:00
2023-09-08 06:16:32 +00:00
shader_bind(comp);
2023-09-08 08:00:26 +00:00
data.f = (float)window_time();
ssbo_bind(buf, 1);
ssbo_update(0, sizeof(data), &data);
2023-09-08 20:14:11 +00:00
compute_dispatch(TEX_WIDTH/10, TEX_WIDTH/10, 1);
2023-09-08 06:31:58 +00:00
image_write_barrier();
2023-09-08 08:00:26 +00:00
2023-09-08 06:16:32 +00:00
fullscreen_quad_rgb(tex, 2.2);
}
2023-09-08 06:31:58 +00:00
return 0;
2023-09-08 06:16:32 +00:00
}