chore: decouple rendering & geometry generation logic
This commit is contained in:
@@ -61,8 +61,7 @@ static void appstate_on_color_change(VektorColorWheel* wheel,
|
||||
gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryB),
|
||||
str_b);
|
||||
|
||||
/*gtk_gl_area_queue_render(
|
||||
GTK_GL_AREA(appstate->widgetState->workspaceCanvas));*/
|
||||
vektor_canvas_geometry_changed(appstate->renderInfo);
|
||||
}
|
||||
|
||||
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,
|
||||
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) {
|
||||
@@ -253,6 +256,7 @@ void vektor_appstate_canvas_drag_begin(GtkGestureDrag* gesture, gdouble x,
|
||||
if(vektor_bbox_isinside(bbox, position)) {
|
||||
// clicked inside handle
|
||||
state->heldHandleIndex = i;
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -282,6 +286,7 @@ void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture, gdouble x,
|
||||
if(state->selectedShape != NULL && state->heldHandleIndex != -1) {
|
||||
state->selectedShape->handles[state->heldHandleIndex] = position;
|
||||
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(state->selectedShape != NULL && state->heldHandleIndex != -1) {
|
||||
state->heldHandleIndex = -1; // ...then remove handle drag flag
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ static GLuint shader_selection_uMaxLoc;
|
||||
|
||||
static GLuint vao;
|
||||
VertexBuffer vb;
|
||||
static size_t shape_vertex_count = 0;
|
||||
|
||||
static GLuint compile_shader(GLenum type, const char* src) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
@@ -135,13 +136,11 @@ static void init_geometry(void) {
|
||||
|
||||
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);
|
||||
size_t shape_vertex_count =
|
||||
vb.count; // remember how many vertices belong to shapes
|
||||
shape_vertex_count = vb.count;
|
||||
|
||||
if (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_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,
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef struct VektorCanvasRenderInfo {
|
||||
|
||||
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
|
||||
VektorCanvasRenderInfo* renderInfo);
|
||||
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo);
|
||||
// void vektor_canvas_update(VektorCanvas* canvas);
|
||||
// void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color);
|
||||
// void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas);
|
||||
|
||||
Reference in New Issue
Block a user