idk
This commit is contained in:
parent
b8aa496964
commit
20ae97dbfd
2 changed files with 66 additions and 17 deletions
1
include/slibs
Submodule
1
include/slibs
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 112d98edcdd9780dbe101674568b9e6450e01d1a
|
82
src/main.c
82
src/main.c
|
@ -5,10 +5,11 @@
|
|||
#include <math.h>
|
||||
|
||||
#include <shaders/shader.glsl.h>
|
||||
#include <slibs/slibs.h>
|
||||
|
||||
static struct {
|
||||
sg_pipeline pip;
|
||||
sg_bindings bind;
|
||||
sl_vec(sg_bindings*) bindings;
|
||||
sg_pass_action pass_action;
|
||||
} state;
|
||||
|
||||
|
@ -23,6 +24,51 @@ static void init(void) {
|
|||
.logger.func = slog_func,
|
||||
});
|
||||
|
||||
{
|
||||
vertex_t vertices[] = {
|
||||
{ 1.0f, 1.0f, 0.0f, 1.0f * 32767, 1.0f * 32767 }, // top right
|
||||
{ 1.0f, -1.0f, 0.0f, 1.0f * 32767, 0.0f * 32767 }, // bottom right
|
||||
{ -1.0f, -1.0f, 0.0f, 0.0f * 32767, 0.0f * 32767 }, // bottom left
|
||||
{ -1.0f, 1.0f, 0.0f, 0.0f * 32767, 1.0f * 32767 } // top left
|
||||
};
|
||||
|
||||
unsigned int indices[] = { // note that we start from 0!
|
||||
0, 1, 3, // first triangle
|
||||
1, 2, 3 // second triangle
|
||||
};
|
||||
|
||||
sg_bindings* bind = calloc(1, sizeof(sg_bindings));
|
||||
sl_vec_push(state.bindings, bind);
|
||||
bind->vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data = SG_RANGE(vertices),
|
||||
.label = "triangle-vertices"
|
||||
});
|
||||
|
||||
bind->index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.type = SG_BUFFERTYPE_INDEXBUFFER,
|
||||
.data = SG_RANGE(indices),
|
||||
.label = "triangle-indices"
|
||||
});
|
||||
|
||||
uint32_t pixels[2*2] = {
|
||||
0xFF595959, 0xFF242424,
|
||||
0xFF242424, 0xFF595959
|
||||
};
|
||||
|
||||
bind->fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){
|
||||
.width = 2,
|
||||
.height = 2,
|
||||
.data.subimage[0][0] = SG_RANGE(pixels),
|
||||
.label = "triangle-texture",
|
||||
.pixel_format = SG_PIXELFORMAT_BGRA8,
|
||||
});
|
||||
|
||||
bind->fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){
|
||||
.label = "triangle-sampler"
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
vertex_t vertices[] = {
|
||||
{ 0.5f, 0.5f, 0.0f, 1.0f * 32767, 1.0f * 32767 }, // top right
|
||||
{ 0.5f, -0.5f, 0.0f, 1.0f * 32767, 0.0f * 32767 }, // bottom right
|
||||
|
@ -35,35 +81,36 @@ static void init(void) {
|
|||
1, 2, 3 // second triangle
|
||||
};
|
||||
|
||||
state.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
sg_bindings* bind = calloc(1, sizeof(sg_bindings));
|
||||
sl_vec_push(state.bindings, bind);
|
||||
bind->vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data = SG_RANGE(vertices),
|
||||
.label = "triangle-vertices"
|
||||
});
|
||||
|
||||
state.bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
bind->index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.type = SG_BUFFERTYPE_INDEXBUFFER,
|
||||
.data = SG_RANGE(indices),
|
||||
.label = "triangle-indices"
|
||||
});
|
||||
|
||||
uint32_t pixels[4*4] = {
|
||||
0xFF000000, 0xFFFF00FF, 0xFF000000, 0xFFFF00FF,
|
||||
0xFFFF00FF, 0xFF000000, 0xFFFF00FF, 0xFF000000,
|
||||
0xFF000000, 0xFFFF00FF, 0xFF000000, 0xFFFF00FF,
|
||||
0xFFFF00FF, 0xFF000000, 0xFFFF00FF, 0xFF000000,
|
||||
uint32_t pixels[2 * 2] = {
|
||||
0xFF242424, 0xFF595959,
|
||||
0xFF595959, 0xFF242424,
|
||||
};
|
||||
|
||||
state.bind.fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){
|
||||
.width = 4,
|
||||
.height = 4,
|
||||
bind->fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){
|
||||
.width = 2,
|
||||
.height = 2,
|
||||
.data.subimage[0][0] = SG_RANGE(pixels),
|
||||
.label = "triangle-texture",
|
||||
.pixel_format = SG_PIXELFORMAT_RGBA8,
|
||||
.pixel_format = SG_PIXELFORMAT_BGRA8,
|
||||
});
|
||||
|
||||
state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){
|
||||
bind->fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){
|
||||
.label = "triangle-sampler"
|
||||
});
|
||||
}
|
||||
|
||||
sg_shader shd = sg_make_shader(triangle_shader_desc(sg_query_backend()));
|
||||
|
||||
|
@ -89,8 +136,10 @@ static void init(void) {
|
|||
void frame(void) {
|
||||
sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
|
||||
sg_apply_pipeline(state.pip);
|
||||
sg_apply_bindings(&state.bind);
|
||||
sg_draw(0, 6, 1);
|
||||
for(sl_vec_it(bind, state.bindings)) {
|
||||
sg_apply_bindings(*bind);
|
||||
sg_draw(0, 6, 1);
|
||||
}
|
||||
sg_end_pass();
|
||||
sg_commit();
|
||||
}
|
||||
|
@ -111,5 +160,4 @@ sapp_desc sokol_main(int argc, char* argv[]) {
|
|||
.icon.sokol_default = true,
|
||||
.logger.func = slog_func,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue