add line drawing
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_camera_c.h"
|
||||
#include "twn_types.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_vec.h"
|
||||
#include "twn_deferred_commands.h"
|
||||
|
||||
@ -284,6 +285,20 @@ static void render_2d(void) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: batching */
|
||||
case PRIMITIVE_2D_LINE: {
|
||||
struct Render2DInvocation const invocation = {
|
||||
.primitive = current,
|
||||
.layer = layer,
|
||||
};
|
||||
|
||||
if (current->line.color.a != 255)
|
||||
arrput(ghostly_invocations, invocation);
|
||||
else
|
||||
arrput(opaque_invocations, invocation);
|
||||
break;
|
||||
}
|
||||
|
||||
case PRIMITIVE_2D_TEXT: {
|
||||
struct Render2DInvocation const invocation = {
|
||||
.primitive = current,
|
||||
@ -320,6 +335,9 @@ static void render_2d(void) {
|
||||
case PRIMITIVE_2D_CIRCLE:
|
||||
render_circle(&invocation.primitive->circle);
|
||||
break;
|
||||
case PRIMITIVE_2D_LINE:
|
||||
render_line(&invocation.primitive->line);
|
||||
break;
|
||||
case PRIMITIVE_2D_TEXT:
|
||||
default:
|
||||
SDL_assert(false);
|
||||
@ -349,6 +367,9 @@ static void render_2d(void) {
|
||||
case PRIMITIVE_2D_TEXT:
|
||||
render_text(&invocation.primitive->text);
|
||||
break;
|
||||
case PRIMITIVE_2D_LINE:
|
||||
render_line(&invocation.primitive->line);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(false);
|
||||
}
|
||||
@ -480,3 +501,28 @@ void issue_deferred_draw_commands(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Support thickness */
|
||||
void draw_line(Vec2 start,
|
||||
Vec2 finish,
|
||||
float thickness,
|
||||
Color color)
|
||||
{
|
||||
if (fabsf(1.0f - thickness) >= 0.00001f)
|
||||
log_warn("Thickness isn't yet implemented for line drawing (got %f)", (double)thickness);
|
||||
|
||||
LinePrimitive line = {
|
||||
.start = start,
|
||||
.finish = finish,
|
||||
.thickness = thickness,
|
||||
.color = color,
|
||||
};
|
||||
|
||||
Primitive2D primitive = {
|
||||
.type = PRIMITIVE_2D_LINE,
|
||||
.line = line,
|
||||
};
|
||||
|
||||
arrput(ctx.render_queue_2d, primitive);
|
||||
}
|
||||
|
Reference in New Issue
Block a user