chore: decouple rendering & geometry generation logic

This commit is contained in:
Beriff
2026-03-14 01:50:44 +07:00
parent 5e883e2d27
commit e7dc799f54
3 changed files with 21 additions and 8 deletions

View File

@@ -61,8 +61,7 @@ static void appstate_on_color_change(VektorColorWheel* wheel,
gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryB), gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryB),
str_b); str_b);
/*gtk_gl_area_queue_render( vektor_canvas_geometry_changed(appstate->renderInfo);
GTK_GL_AREA(appstate->widgetState->workspaceCanvas));*/
} }
static void appstate_on_entry_update(GtkEntry* entry, gpointer user_data) { static void appstate_on_entry_update(GtkEntry* entry, gpointer user_data) {
@@ -96,7 +95,11 @@ static void canvas_onclick(GtkGestureClick* gesture, int n_press, double x,
vektor_appstate_canvas_click(state, normalized_coords.x, vektor_appstate_canvas_click(state, normalized_coords.x,
normalized_coords.y); normalized_coords.y);
// gtk_gl_area_queue_render(GTK_GL_AREA(widget)); // technically there are cases when a click would not result in change of the geometry
// but this is more concise then writing it inside that function
// a bunch of times and burder future click dispatches with
// handling this signal
vektor_canvas_geometry_changed(state->renderInfo);
} }
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) { void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) {
@@ -253,6 +256,7 @@ void vektor_appstate_canvas_drag_begin(GtkGestureDrag* gesture, gdouble x,
if(vektor_bbox_isinside(bbox, position)) { if(vektor_bbox_isinside(bbox, position)) {
// clicked inside handle // clicked inside handle
state->heldHandleIndex = i; state->heldHandleIndex = i;
vektor_canvas_geometry_changed(state->renderInfo);
break; break;
} }
} }
@@ -282,6 +286,7 @@ void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture, gdouble x,
if(state->selectedShape != NULL && state->heldHandleIndex != -1) { if(state->selectedShape != NULL && state->heldHandleIndex != -1) {
state->selectedShape->handles[state->heldHandleIndex] = position; state->selectedShape->handles[state->heldHandleIndex] = position;
vektor_shape_handles_updated(state->selectedShape, &state->heldHandleIndex); vektor_shape_handles_updated(state->selectedShape, &state->heldHandleIndex);
vektor_canvas_geometry_changed(state->renderInfo);
} }
} }
@@ -293,6 +298,7 @@ void vektor_appstate_canvas_drag_end(GtkGestureDrag* gesture, gdouble x,
// if we were dragging a handle // if we were dragging a handle
if(state->selectedShape != NULL && state->heldHandleIndex != -1) { if(state->selectedShape != NULL && state->heldHandleIndex != -1) {
state->heldHandleIndex = -1; // ...then remove handle drag flag state->heldHandleIndex = -1; // ...then remove handle drag flag
vektor_canvas_geometry_changed(state->renderInfo);
} }
} }

View File

@@ -45,6 +45,7 @@ static GLuint shader_selection_uMaxLoc;
static GLuint vao; static GLuint vao;
VertexBuffer vb; VertexBuffer vb;
static size_t shape_vertex_count = 0;
static GLuint compile_shader(GLenum type, const char* src) { static GLuint compile_shader(GLenum type, const char* src) {
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
@@ -135,13 +136,11 @@ static void init_geometry(void) {
glBindVertexArray(0); glBindVertexArray(0);
} }
static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
VektorCanvasRenderInfo* renderInfo) {
vb.count = 0;
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo) {
vb.count = 0;
vektor_rasterize(&vb, renderInfo->shapes, renderInfo->zoom); vektor_rasterize(&vb, renderInfo->shapes, renderInfo->zoom);
size_t shape_vertex_count = shape_vertex_count = vb.count;
vb.count; // remember how many vertices belong to shapes
if (renderInfo->selectedShape != NULL && if (renderInfo->selectedShape != NULL &&
*(renderInfo->selectedShape) != NULL) { *(renderInfo->selectedShape) != NULL) {
@@ -166,6 +165,13 @@ static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
vektor_vb_add_quad(&vb, bbox.min, bbox.max, vektor_vb_add_quad(&vb, bbox.min, bbox.max,
vektor_color_new(255, 255, 255, 255)); vektor_color_new(255, 255, 255, 255));
} }
}
static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
VektorCanvasRenderInfo* renderInfo) {
//vektor_canvas_geometry_changed(renderInfo);
glBufferData(GL_ARRAY_BUFFER, vb.count * sizeof(Vertex), vb.vertices, glBufferData(GL_ARRAY_BUFFER, vb.count * sizeof(Vertex), vb.vertices,
GL_STATIC_DRAW); GL_STATIC_DRAW);

View File

@@ -44,6 +44,7 @@ typedef struct VektorCanvasRenderInfo {
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut, void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
VektorCanvasRenderInfo* renderInfo); VektorCanvasRenderInfo* renderInfo);
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo);
// void vektor_canvas_update(VektorCanvas* canvas); // void vektor_canvas_update(VektorCanvas* canvas);
// void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color); // void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color);
// void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas); // void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas);