canvas: allow flushing externally built commands with mg_flush_commands()
This commit is contained in:
parent
2419ab7889
commit
38c27f21d6
|
@ -2799,7 +2799,7 @@ void mg_flush_batch(mg_canvas_data* canvas)
|
||||||
canvas->indexCount = 0;
|
canvas->indexCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_flush()
|
void mg_flush_commands(int primitiveCount, mg_primitive* primitives, mg_path_elt* pathElements)
|
||||||
{
|
{
|
||||||
mg_canvas_data* canvas = __mgCurrentCanvas;
|
mg_canvas_data* canvas = __mgCurrentCanvas;
|
||||||
if(!canvas)
|
if(!canvas)
|
||||||
|
@ -2809,8 +2809,6 @@ void mg_flush()
|
||||||
|
|
||||||
mg_color clearColor = {0, 0, 0, 1};
|
mg_color clearColor = {0, 0, 0, 1};
|
||||||
|
|
||||||
u32 count = canvas->primitiveCount;
|
|
||||||
|
|
||||||
u32 nextIndex = 0;
|
u32 nextIndex = 0;
|
||||||
|
|
||||||
mg_reset_z_index(canvas);
|
mg_reset_z_index(canvas);
|
||||||
|
@ -2822,14 +2820,14 @@ void mg_flush()
|
||||||
|
|
||||||
canvas->backend->begin(canvas->backend);
|
canvas->backend->begin(canvas->backend);
|
||||||
|
|
||||||
for(int i=0; i<count; i++)
|
for(int i=0; i<primitiveCount; i++)
|
||||||
{
|
{
|
||||||
if(nextIndex >= count)
|
if(nextIndex >= primitiveCount)
|
||||||
{
|
{
|
||||||
LOG_ERROR("invalid location '%i' in graphics command buffer would cause an overrun\n", nextIndex);
|
LOG_ERROR("invalid location '%i' in graphics command buffer would cause an overrun\n", nextIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mg_primitive* primitive = &(canvas->primitives[nextIndex]);
|
mg_primitive* primitive = &(primitives[nextIndex]);
|
||||||
nextIndex++;
|
nextIndex++;
|
||||||
|
|
||||||
if(i && primitive->attributes.image.h != currentImage.h)
|
if(i && primitive->attributes.image.h != currentImage.h)
|
||||||
|
@ -2853,7 +2851,7 @@ void mg_flush()
|
||||||
{
|
{
|
||||||
u32 zIndex = mg_next_shape(canvas, primitive->attributes.color);
|
u32 zIndex = mg_next_shape(canvas, primitive->attributes.color);
|
||||||
mg_render_fill(canvas,
|
mg_render_fill(canvas,
|
||||||
canvas->pathElements + primitive->path.startIndex,
|
pathElements + primitive->path.startIndex,
|
||||||
&primitive->path,
|
&primitive->path,
|
||||||
zIndex,
|
zIndex,
|
||||||
primitive->attributes.color);
|
primitive->attributes.color);
|
||||||
|
@ -2862,7 +2860,7 @@ void mg_flush()
|
||||||
case MG_CMD_STROKE:
|
case MG_CMD_STROKE:
|
||||||
{
|
{
|
||||||
mg_render_stroke(canvas,
|
mg_render_stroke(canvas,
|
||||||
canvas->pathElements + primitive->path.startIndex,
|
pathElements + primitive->path.startIndex,
|
||||||
&primitive->path,
|
&primitive->path,
|
||||||
&primitive->attributes);
|
&primitive->attributes);
|
||||||
} break;
|
} break;
|
||||||
|
@ -2899,7 +2897,7 @@ void mg_flush()
|
||||||
//NOTE(martin): normal end of stream marker
|
//NOTE(martin): normal end of stream marker
|
||||||
goto exit_command_loop;
|
goto exit_command_loop;
|
||||||
}
|
}
|
||||||
else if(primitive->jump >= count)
|
else if(primitive->jump >= primitiveCount)
|
||||||
{
|
{
|
||||||
LOG_ERROR("invalid jump location '%i' in graphics command buffer\n", primitive->jump);
|
LOG_ERROR("invalid jump location '%i' in graphics command buffer\n", primitive->jump);
|
||||||
goto exit_command_loop;
|
goto exit_command_loop;
|
||||||
|
@ -2952,16 +2950,26 @@ void mg_flush()
|
||||||
canvas->backend->end(canvas->backend);
|
canvas->backend->end(canvas->backend);
|
||||||
|
|
||||||
//NOTE(martin): clear buffers
|
//NOTE(martin): clear buffers
|
||||||
canvas->primitiveCount = 0;
|
|
||||||
canvas->vertexCount = 0;
|
canvas->vertexCount = 0;
|
||||||
canvas->indexCount = 0;
|
canvas->indexCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mg_flush()
|
||||||
|
{
|
||||||
|
mg_canvas_data* canvas = __mgCurrentCanvas;
|
||||||
|
if(!canvas)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_flush_commands(canvas->primitiveCount, canvas->primitives, canvas->pathElements);
|
||||||
|
|
||||||
|
canvas->primitiveCount = 0;
|
||||||
canvas->path.startIndex = 0;
|
canvas->path.startIndex = 0;
|
||||||
canvas->path.count = 0;
|
canvas->path.count = 0;
|
||||||
|
|
||||||
canvas->frameCounter++;
|
canvas->frameCounter++;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
//NOTE(martin): transform, viewport and clipping
|
//NOTE(martin): transform, viewport and clipping
|
||||||
|
|
7
todo.txt
7
todo.txt
|
@ -15,7 +15,14 @@ Canvas renderer perf
|
||||||
[ ] Add surface scaling for high dpi surfaces
|
[ ] Add surface scaling for high dpi surfaces
|
||||||
[ ] Allow setting swap interval
|
[ ] Allow setting swap interval
|
||||||
|
|
||||||
|
[ ] Fix resource loading path in examples (to load font relative to executable)
|
||||||
|
|
||||||
|
[ ] GL loader: allow using different GL versions (eg using a desktop GL surface and a GLES surface in the same app).
|
||||||
|
[ ] Clean up surface backend and canvas backend compile-time and run-time selections
|
||||||
|
|
||||||
|
[/] backport to GLES?
|
||||||
|
|
||||||
|
[ ] Ghostscript tiger stress test? -> need an svg loader, and a way to flush external command list
|
||||||
|
|
||||||
-----------
|
-----------
|
||||||
[.] Check changes in macos version
|
[.] Check changes in macos version
|
||||||
|
|
Loading…
Reference in New Issue