aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-11-14 15:07:45 +0100
committerAndre Weissflog <floooh@gmail.com>2022-11-14 15:07:45 +0100
commit2884a73cb6821cb70576b53d82187e9a55650683 (patch)
treea49648d407e2c0eee4f33b7ec9c0b82b51c413c6 /tests
parent7e7a691938a3e5c9f2b15f80ba8169c414929c8a (diff)
fix sokol_gl_test.c and sokol_debugtext_test.c
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/sokol_debugtext_test.c109
-rw-r--r--tests/functional/sokol_gl_test.c32
2 files changed, 108 insertions, 33 deletions
diff --git a/tests/functional/sokol_debugtext_test.c b/tests/functional/sokol_debugtext_test.c
index ce1bb5e0..d2523502 100644
--- a/tests/functional/sokol_debugtext_test.c
+++ b/tests/functional/sokol_debugtext_test.c
@@ -57,11 +57,12 @@ UTEST(sokol_debugtext, default_init_shutdown) {
T(_sdtx.cur_ctx->desc.color_format == 0);
T(_sdtx.cur_ctx->desc.depth_format == 0);
T(_sdtx.cur_ctx->desc.sample_count == 0);
- T(_sdtx.cur_ctx->cur_vertex_ptr);
- T(_sdtx.cur_ctx->max_vertex_ptr);
- T(_sdtx.cur_ctx->vertices);
- T(_sdtx.cur_ctx->vertices == _sdtx.cur_ctx->cur_vertex_ptr);
- T(_sdtx.cur_ctx->max_vertex_ptr == (_sdtx.cur_ctx->vertices + _SDTX_DEFAULT_CHAR_BUF_SIZE * 6));
+ T(_sdtx.cur_ctx->vertices.cap == _SDTX_DEFAULT_CHAR_BUF_SIZE * 6);
+ T(_sdtx.cur_ctx->vertices.next == 0);
+ T(_sdtx.cur_ctx->vertices.ptr);
+ T(_sdtx.cur_ctx->commands.cap == _SDTX_DEFAULT_MAX_COMMANDS);
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr);
T(_sdtx.cur_ctx->vbuf.id != 0);
T(_sdtx.cur_ctx->pip.id != 0);
TFLT(_sdtx.cur_ctx->canvas_size.x, 640.0f);
@@ -112,7 +113,7 @@ UTEST(sokol_debugtext, init_with_params) {
T(_sdtx.cur_ctx->desc.color_format == SG_PIXELFORMAT_RGBA8);
T(_sdtx.cur_ctx->desc.depth_format == SG_PIXELFORMAT_DEPTH_STENCIL);
T(_sdtx.cur_ctx->desc.sample_count == 4);
- T(_sdtx.cur_ctx->max_vertex_ptr == (_sdtx.cur_ctx->vertices + 256 * 6));
+ T(_sdtx.cur_ctx->vertices.cap == (256 * 6));
TFLT(_sdtx.cur_ctx->canvas_size.x, 320.0f);
TFLT(_sdtx.cur_ctx->canvas_size.y, 200.0f);
TFLT(_sdtx.cur_ctx->glyph_size.x, 8.0f / 320.0f);
@@ -144,9 +145,9 @@ UTEST(sokol_debugtext, make_destroy_context) {
T(ctx->desc.color_format == SG_PIXELFORMAT_RGBA32F);
T(ctx->desc.depth_format == 0);
T(ctx->desc.sample_count == 2);
- T(ctx->vertices);
- T(ctx->cur_vertex_ptr == ctx->vertices);
- T(ctx->max_vertex_ptr == ctx->vertices + 64 * 6);
+ T(ctx->vertices.ptr);
+ T(ctx->vertices.next == 0);
+ T(ctx->vertices.cap == (64 * 6));
TFLT(ctx->canvas_size.x, 1024.0f);
TFLT(ctx->canvas_size.y, 768.0f);
TFLT(ctx->glyph_size.x, 8.0f / 1024.0f);
@@ -155,7 +156,7 @@ UTEST(sokol_debugtext, make_destroy_context) {
sdtx_destroy_context(ctx_id);
T(0 == _sdtx_lookup_context(ctx_id.id));
T(ctx->desc.char_buf_size == 0);
- T(ctx->vertices == 0);
+ T(ctx->vertices.ptr == 0);
shutdown();
}
@@ -336,7 +337,7 @@ UTEST(sokol_debugtext, vertex_overflow) {
sdtx_puts("1234567890");
sdtx_putr("1234567890", 5);
sdtx_printf("Hello World %d!\n", 12);
- T(_sdtx.cur_ctx->cur_vertex_ptr == _sdtx.cur_ctx->max_vertex_ptr);
+ T(_sdtx.cur_ctx->vertices.next == _sdtx.cur_ctx->vertices.cap);
shutdown();
}
@@ -399,7 +400,7 @@ UTEST(sokol_debugtext, rewind_after_draw) {
sdtx_font(3);
T(_sdtx.cur_ctx->cur_font == 3);
sdtx_printf("Hello World!\n");
- T(_sdtx.cur_ctx->cur_vertex_ptr != _sdtx.cur_ctx->vertices);
+ T(_sdtx.cur_ctx->vertices.next != 0);
sg_begin_default_pass(&(sg_pass_action){ 0 }, 256, 256);
sdtx_draw();
sg_end_pass();
@@ -411,21 +412,21 @@ UTEST(sokol_debugtext, rewind_after_draw) {
TFLT(_sdtx.cur_ctx->pos.x, 0);
TFLT(_sdtx.cur_ctx->pos.x, 0);
T(_sdtx.cur_ctx->cur_font == 0);
- T(_sdtx.cur_ctx->cur_vertex_ptr == _sdtx.cur_ctx->vertices);
+ T(_sdtx.cur_ctx->vertices.next == 0);
shutdown();
}
UTEST(sokol_debugtext, putr) {
// test if sdtx_putr() draws the right amount of characters
init();
- _sdtx_vertex_t* start_ptr = _sdtx.cur_ctx->cur_vertex_ptr;
+ int start_index = _sdtx.cur_ctx->vertices.next;
sdtx_putr("Hello World!", 5);
- T((5 * 6) == (_sdtx.cur_ctx->cur_vertex_ptr - start_ptr));
+ T((5 * 6) == (_sdtx.cur_ctx->vertices.next - start_index));
- start_ptr = _sdtx.cur_ctx->cur_vertex_ptr;
+ start_index = _sdtx.cur_ctx->vertices.next;
sdtx_putr("Hello!\n\n\n\n\n\n\n\n\n\n\n", 10);
// NOTE: the \n's don't result in rendered vertices
- T((6 * 6) == (_sdtx.cur_ctx->cur_vertex_ptr - start_ptr));
+ T((6 * 6) == (_sdtx.cur_ctx->vertices.next - start_index));
shutdown();
}
@@ -434,3 +435,77 @@ UTEST(sokol_debugtext, default_context) {
T(sdtx_default_context().id == SDTX_DEFAULT_CONTEXT.id);
shutdown();
}
+
+// switching layers without any text inbetween should not advance the current draw command
+UTEST(sokol_debug_text, empty_layers) {
+ init();
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 0);
+ sdtx_layer(1);
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 1);
+ sdtx_layer(2);
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 2);
+ sdtx_layer(0);
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 0);
+ shutdown();
+}
+
+// switching layers with text inbetween should advance the current draw command
+UTEST(sokol_debug_text, non_empty_layers) {
+ init();
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 0);
+ T(_sdtx.cur_ctx->commands.ptr[0].first_vertex == 0);
+ T(_sdtx.cur_ctx->commands.ptr[0].num_vertices == 0);
+ sdtx_puts("123");
+ T(_sdtx.cur_ctx->commands.next == 1);
+ T(_sdtx.cur_ctx->commands.ptr[0].layer_id == 0);
+ T(_sdtx.cur_ctx->commands.ptr[0].first_vertex == 0);
+ T(_sdtx.cur_ctx->commands.ptr[0].num_vertices == (3 * 6));
+ sdtx_layer(1);
+ sdtx_puts("1234");
+ T(_sdtx.cur_ctx->commands.next == 2);
+ T(_sdtx.cur_ctx->commands.ptr[1].layer_id == 1);
+ T(_sdtx.cur_ctx->commands.ptr[1].first_vertex == (3 * 6));
+ T(_sdtx.cur_ctx->commands.ptr[1].num_vertices == (4 * 6));
+ // switching to same layer should not start a new draw commands
+ sdtx_layer(1);
+ sdtx_puts("12345");
+ T(_sdtx.cur_ctx->commands.next == 2);
+ T(_sdtx.cur_ctx->commands.ptr[1].layer_id == 1);
+ T(_sdtx.cur_ctx->commands.ptr[1].first_vertex == (3 * 6));
+ T(_sdtx.cur_ctx->commands.ptr[1].num_vertices == (9 * 6));
+ sdtx_layer(0);
+ sdtx_puts("123456");
+ T(_sdtx.cur_ctx->commands.next == 3);
+ T(_sdtx.cur_ctx->commands.ptr[2].layer_id == 0);
+ T(_sdtx.cur_ctx->commands.ptr[2].first_vertex == (12 * 6));
+ T(_sdtx.cur_ctx->commands.ptr[2].num_vertices == (6 * 6));
+ shutdown();
+}
+
+UTEST(sokol_debug_text, command_buffer_overflow) {
+ init_with(&(sdtx_desc_t){
+ .context = {
+ .max_commands = 4
+ }
+ });
+ sdtx_puts("0");
+ T(_sdtx.cur_ctx->commands.next == 1);
+ sdtx_layer(1);
+ sdtx_puts("1");
+ T(_sdtx.cur_ctx->commands.next == 2);
+ sdtx_layer(2);
+ sdtx_puts("2");
+ T(_sdtx.cur_ctx->commands.next == 3);
+ sdtx_layer(3);
+ sdtx_puts("3");
+ T(_sdtx.cur_ctx->commands.next == 4);
+ // from here on should fail
+ sdtx_layer(4);
+ sdtx_puts("4");
+ T(_sdtx.cur_ctx->commands.next == 4);
+} \ No newline at end of file
diff --git a/tests/functional/sokol_gl_test.c b/tests/functional/sokol_gl_test.c
index 6d3e92a3..1310e440 100644
--- a/tests/functional/sokol_gl_test.c
+++ b/tests/functional/sokol_gl_test.c
@@ -26,12 +26,12 @@ UTEST(sokol_gl, default_init_shutdown) {
T(_sgl.def_ctx_id.id == SGL_DEFAULT_CONTEXT.id);
T(_sgl.cur_ctx_id.id == _sgl.def_ctx_id.id);
T(_sgl.cur_ctx);
- T(_sgl.cur_ctx->vertices.num == 65536);
- T(_sgl.cur_ctx->commands.num == 16384);
- T(_sgl.cur_ctx->uniforms.num == 16384);
- T(_sgl.cur_ctx->vertices.cur == 0);
- T(_sgl.cur_ctx->commands.cur == 0);
- T(_sgl.cur_ctx->uniforms.cur == 0);
+ T(_sgl.cur_ctx->vertices.cap == 65536);
+ T(_sgl.cur_ctx->commands.cap == 16384);
+ T(_sgl.cur_ctx->uniforms.cap == 16384);
+ T(_sgl.cur_ctx->vertices.next == 0);
+ T(_sgl.cur_ctx->commands.next == 0);
+ T(_sgl.cur_ctx->uniforms.next == 0);
T(_sgl.cur_ctx->vertices.ptr != 0);
T(_sgl.cur_ctx->uniforms.ptr != 0);
T(_sgl.cur_ctx->commands.ptr != 0);
@@ -49,7 +49,7 @@ UTEST(sokol_gl, default_init_shutdown) {
UTEST(sokol_gl, viewport) {
init();
sgl_viewport(1, 2, 3, 4, true);
- T(_sgl.cur_ctx->commands.cur == 1);
+ T(_sgl.cur_ctx->commands.next == 1);
T(_sgl.cur_ctx->commands.ptr[0].cmd == SGL_COMMAND_VIEWPORT);
T(_sgl.cur_ctx->commands.ptr[0].args.viewport.x == 1);
T(_sgl.cur_ctx->commands.ptr[0].args.viewport.y == 2);
@@ -57,7 +57,7 @@ UTEST(sokol_gl, viewport) {
T(_sgl.cur_ctx->commands.ptr[0].args.viewport.h == 4);
T(_sgl.cur_ctx->commands.ptr[0].args.viewport.origin_top_left);
sgl_viewport(5, 6, 7, 8, false);
- T(_sgl.cur_ctx->commands.cur == 2);
+ T(_sgl.cur_ctx->commands.next == 2);
T(_sgl.cur_ctx->commands.ptr[1].cmd == SGL_COMMAND_VIEWPORT);
T(_sgl.cur_ctx->commands.ptr[1].args.viewport.x == 5);
T(_sgl.cur_ctx->commands.ptr[1].args.viewport.y == 6);
@@ -70,7 +70,7 @@ UTEST(sokol_gl, viewport) {
UTEST(sokol_gl, scissor_rect) {
init();
sgl_scissor_rect(10, 20, 30, 40, true);
- T(_sgl.cur_ctx->commands.cur == 1);
+ T(_sgl.cur_ctx->commands.next == 1);
T(_sgl.cur_ctx->commands.ptr[0].cmd == SGL_COMMAND_SCISSOR_RECT);
T(_sgl.cur_ctx->commands.ptr[0].args.scissor_rect.x == 10);
T(_sgl.cur_ctx->commands.ptr[0].args.scissor_rect.y == 20);
@@ -78,7 +78,7 @@ UTEST(sokol_gl, scissor_rect) {
T(_sgl.cur_ctx->commands.ptr[0].args.scissor_rect.h == 40);
T(_sgl.cur_ctx->commands.ptr[0].args.scissor_rect.origin_top_left);
sgl_scissor_rect(50, 60, 70, 80, false);
- T(_sgl.cur_ctx->commands.cur == 2);
+ T(_sgl.cur_ctx->commands.next == 2);
T(_sgl.cur_ctx->commands.ptr[1].cmd == SGL_COMMAND_SCISSOR_RECT);
T(_sgl.cur_ctx->commands.ptr[1].args.scissor_rect.x == 50);
T(_sgl.cur_ctx->commands.ptr[1].args.scissor_rect.y == 60);
@@ -111,9 +111,9 @@ UTEST(sokol_gl, begin_end) {
sgl_v3f(7.0f, 8.0f, 9.0f);
sgl_end();
T(_sgl.cur_ctx->base_vertex == 0);
- T(_sgl.cur_ctx->vertices.cur == 3);
- T(_sgl.cur_ctx->commands.cur == 1);
- T(_sgl.cur_ctx->uniforms.cur == 1);
+ T(_sgl.cur_ctx->vertices.next == 3);
+ T(_sgl.cur_ctx->commands.next == 1);
+ T(_sgl.cur_ctx->uniforms.next == 1);
T(_sgl.cur_ctx->commands.ptr[0].cmd == SGL_COMMAND_DRAW);
T(_sgl.cur_ctx->commands.ptr[0].args.draw.pip.id == _sgl_pipeline_at(_sgl.cur_ctx->def_pip.id)->pip[SGL_PRIMITIVETYPE_TRIANGLES].id);
T(_sgl.cur_ctx->commands.ptr[0].args.draw.base_vertex == 0);
@@ -223,9 +223,9 @@ UTEST(sokol_gl, make_destroy_contexts) {
// creating a context should not change the current context
T(ctx.id != _sgl.cur_ctx_id.id);
sgl_set_context(ctx);
- T(_sgl.cur_ctx->vertices.num == 1024);
- T(_sgl.cur_ctx->commands.num == 256);
- T(_sgl.cur_ctx->uniforms.num == 256);
+ T(_sgl.cur_ctx->vertices.cap == 1024);
+ T(_sgl.cur_ctx->commands.cap == 256);
+ T(_sgl.cur_ctx->uniforms.cap == 256);
T(ctx.id == _sgl.cur_ctx_id.id);
T(sgl_get_context().id == ctx.id);
sgl_set_context(SGL_DEFAULT_CONTEXT);