diff --git a/examples/atlas/main.c b/examples/atlas/main.c index 5038276..e1e0925 100644 --- a/examples/atlas/main.c +++ b/examples/atlas/main.c @@ -15,12 +15,8 @@ #include"milepost.h" -#define LOG_SUBSYSTEM "Main" - int main() { - LogLevel(LOG_LEVEL_WARNING); - mp_init(); mp_clock_init(); //TODO put that in mp_init()? @@ -30,14 +26,19 @@ int main() mp_rect contentRect = mp_window_get_content_rect(window); //NOTE: create surface - mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_DEFAULT); + mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); + if(mg_surface_is_nil(surface)) + { + log_error("couldn't create surface\n"); + return(-1); + } mg_surface_swap_interval(surface, 0); //NOTE: create canvas - mg_canvas canvas = mg_canvas_create(surface); + mg_canvas canvas = mg_canvas_create(); if(mg_canvas_is_nil(canvas)) { - printf("Error: couldn't create canvas\n"); + log_error("Error: couldn't create canvas\n"); return(-1); } @@ -46,7 +47,7 @@ int main() mem_arena_init(&permanentArena); mg_rect_atlas* atlas = mg_rect_atlas_create(&permanentArena, 16000, 16000); - mg_image atlasImage = mg_image_create(16000, 16000); + mg_image atlasImage = mg_image_create(surface, 16000, 16000); str8 path1 = path_executable_relative(mem_scratch(), STR8("../resources/triceratops.png")); str8 path2 = path_executable_relative(mem_scratch(), STR8("../resources/Top512.png")); @@ -61,10 +62,10 @@ int main() while(!mp_should_quit()) { mp_pump_events(0); - mp_event event = {0}; - while(mp_next_event(&event)) + mp_event* event = 0; + while((event = mp_next_event(mem_scratch())) != 0) { - switch(event.type) + switch(event->type) { case MP_EVENT_WINDOW_CLOSE: { @@ -86,7 +87,7 @@ int main() mg_image_draw_region(image1.image, image1.rect, (mp_rect){100, 100, 300, 300}); mg_image_draw_region(image2.image, image2.rect, (mp_rect){300, 200, 300, 300}); - mg_flush(); + mg_render(surface, canvas); mg_surface_present(surface); mem_arena_clear(mem_scratch()); diff --git a/examples/image/main.c b/examples/image/main.c index 6452a92..59d6546 100644 --- a/examples/image/main.c +++ b/examples/image/main.c @@ -81,7 +81,7 @@ int main() mg_set_color_rgba(1, 1, 1, 1); - +/* mg_matrix_push((mg_mat2x3){0.707, -0.707, 200, 0.707, 0.707, 100}); mg_set_image(image); @@ -99,6 +99,9 @@ int main() mg_matrix_pop(); mg_image_draw(image2, (mp_rect){300, 200, 300, 300}); +*/ + mg_image_draw(image, (mp_rect){100, 100, 300, 300}); + mg_image_draw(image2, (mp_rect){300, 200, 300, 300}); mg_render(surface, canvas); mg_surface_present(surface); diff --git a/src/gl_canvas.c b/src/gl_canvas.c index a23c327..7b0343e 100644 --- a/src/gl_canvas.c +++ b/src/gl_canvas.c @@ -981,6 +981,16 @@ void mg_gl_render_batch(mg_gl_canvas_backend* backend, glUniform1f(1, scale); glUniform1i(2, pathCount); + // if there's an image, don't cull solid tiles + if(image) + { + glUniform1i(3, 0); + } + else + { + glUniform1i(3, 1); + } + glDispatchCompute(nTilesX, nTilesY, 1); glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); @@ -1238,7 +1248,7 @@ mg_image_data* mg_gl_canvas_image_create(mg_canvas_backend* interface, vec2 size { glGenTextures(1, &image->texture); glBindTexture(GL_TEXTURE_2D, image->texture); -// glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, size.x, size.y); + glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, size.x, size.y); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -1263,7 +1273,7 @@ void mg_gl_canvas_image_upload_region(mg_canvas_backend* interface, //TODO: check that this image belongs to this context mg_gl_image* image = (mg_gl_image*)imageInterface; glBindTexture(GL_TEXTURE_2D, image->texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, region.w, region.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexSubImage2D(GL_TEXTURE_2D, 0, region.x, region.y, region.w, region.h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } //-------------------------------------------------------------------- diff --git a/src/glsl_shaders/merge.glsl b/src/glsl_shaders/merge.glsl index ea1fdda..ca0b2e1 100644 --- a/src/glsl_shaders/merge.glsl +++ b/src/glsl_shaders/merge.glsl @@ -37,6 +37,7 @@ layout(binding = 5) restrict writeonly buffer screenTilesBufferSSBO layout(location = 0) uniform int tileSize; layout(location = 1) uniform float scale; layout(location = 2) uniform int pathCount; +layout(location = 3) uniform int cullSolidTiles; void main() { @@ -89,6 +90,7 @@ void main() if( lastOpIndex < 0 ||(pathBuffer.elements[pathIndex].color.a == 1 + && cullSolidTiles != 0 && tileBox.x >= clip.x && tileBox.z < clip.z && tileBox.y >= clip.y diff --git a/src/graphics.h b/src/graphics.h index fd9f0b2..2eac71a 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -237,9 +237,9 @@ MP_API vec2 mg_image_size(mg_image image); //NOTE: rectangle allocator typedef struct mg_rect_atlas mg_rect_atlas; -mg_rect_atlas* mg_rect_atlas_create(mem_arena* arena, i32 width, i32 height); -mp_rect mg_rect_atlas_alloc(mg_rect_atlas* atlas, i32 width, i32 height); -void mg_rect_atlas_recycle(mg_rect_atlas* atlas, mp_rect rect); +MP_API mg_rect_atlas* mg_rect_atlas_create(mem_arena* arena, i32 width, i32 height); +MP_API mp_rect mg_rect_atlas_alloc(mg_rect_atlas* atlas, i32 width, i32 height); +MP_API void mg_rect_atlas_recycle(mg_rect_atlas* atlas, mp_rect rect); //NOTE: image atlas helpers typedef struct mg_image_region @@ -248,10 +248,10 @@ typedef struct mg_image_region mp_rect rect; } mg_image_region; -mg_image_region mg_image_atlas_alloc_from_rgba8(mg_rect_atlas* atlas, mg_image backingImage, u32 width, u32 height, u8* pixels); -mg_image_region mg_image_atlas_alloc_from_data(mg_rect_atlas* atlas, mg_image backingImage, str8 data, bool flip); -mg_image_region mg_image_atlas_alloc_from_file(mg_rect_atlas* atlas, mg_image backingImage, str8 path, bool flip); -void mg_image_atlas_recycle(mg_rect_atlas* atlas, mg_image_region imageRgn); +MP_API mg_image_region mg_image_atlas_alloc_from_rgba8(mg_rect_atlas* atlas, mg_image backingImage, u32 width, u32 height, u8* pixels); +MP_API mg_image_region mg_image_atlas_alloc_from_data(mg_rect_atlas* atlas, mg_image backingImage, str8 data, bool flip); +MP_API mg_image_region mg_image_atlas_alloc_from_file(mg_rect_atlas* atlas, mg_image backingImage, str8 path, bool flip); +MP_API void mg_image_atlas_recycle(mg_rect_atlas* atlas, mg_image_region imageRgn); //------------------------------------------------------------------------------------------ //NOTE(martin): transform, viewport and clipping