diff --git a/include/cx.h b/include/cx.h index c329911..a39f90e 100644 --- a/include/cx.h +++ b/include/cx.h @@ -33,6 +33,7 @@ typedef struct _cx_gl_ctx { ModelRegistry *mr; GLuint *VertexArrayIDs; void (*free)(void *self); + uint8_t master_lock; size_t VertexArray_count; size_t VertexArray_size; GLuint *programIDs; @@ -45,6 +46,7 @@ typedef struct _cx_nn_ctx { float *input_buffer; float *output_buffer; void (*free)(void *self); + uint8_t master_lock; } CX_NN_CTX; typedef struct _cx_ctx { diff --git a/src/cx.c b/src/cx.c index 20a42e8..bd452ab 100644 --- a/src/cx.c +++ b/src/cx.c @@ -230,7 +230,10 @@ cx_glrun(CX_GL_CTX *ctx) { glfwGetCursorPos(ctx->window, &xpos, &ypos); do { - cx_glrender(ctx->window, ctx->programIDs[0], ctx->mr); + // Skip render step if context is locked. + if (!ctx->master_lock) { + cx_glrender(ctx->window, ctx->programIDs[0], ctx->mr); + } usleep(1000000/60); // Check if the ESC key was pressed or the window was closed } while(glfwGetKey(ctx->window, GLFW_KEY_ESCAPE) != GLFW_PRESS @@ -287,14 +290,18 @@ cx_run(CX_Context *ctx) { // Establish a model registry ctx->gl_ctx->mr = modelRegistry_new(); + ctx->gl_ctx->master_lock = 1; + + tg[0] = cx_threadGroup_new(&cx_glthread, ctx->gl_ctx); tg[1] = cx_threadGroup_new(&cx_nnthread, ctx->nn_ctx); pthread_join(tg[1]->group_manager->thread, NULL); + ctx->gl_ctx->master_lock = 0; + neural_getMesh(ctx->nn_ctx->nn, ctx->gl_ctx->mr); - tg[0] = cx_threadGroup_new(&cx_glthread, ctx->gl_ctx); pthread_join(tg[0]->group_manager->thread, NULL);