Skip to content

Commit

Permalink
- fixed bug in NO_OPENGL mode: uninitialized quad buffer
Browse files Browse the repository at this point in the history
- fixed bug in user callback drawing: always-increasing vertex buffer size
  • Loading branch information
jtsiomb committed Jun 15, 2018
1 parent 2fab860 commit 4d94692
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/drawgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ static int num_quads;
static dtx_user_draw_func user_draw_func;
static void *user_cls;

static int dtx_draw_init(void);
static void cleanup(void);

static void set_glyphmap_texture(struct dtx_glyphmap *gmap);
static const char *drawchar(const char *str, float *pos_x, float *pos_y, int *should_flush);
static void flush_user(void);
Expand Down Expand Up @@ -102,7 +105,7 @@ static PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;

void dtx_target_opengl(void)
{
dtx_gl_init();
dtx_draw_init();
dtx_drawchar = drawchar;
dtx_drawflush = flush;

Expand Down Expand Up @@ -145,12 +148,8 @@ int dtx_gl_getopt(enum dtx_option opt, int *res)
return 0;
}

static int dtx_gl_init(void)
static void dtx_gl_init(void)
{
if(qbuf) {
return 0; /* already initialized */
}

#ifndef GL_VERSION_1_5
glBindBuffer = (PFNGLBINDBUFFERPROC)load_glfunc("glBindBuffer");
#endif
Expand All @@ -159,19 +158,6 @@ static int dtx_gl_init(void)
glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)load_glfunc("glDisableVertexAttribArray");
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)load_glfunc("glVertexAttribPointer");
#endif

if(!(qbuf = malloc(QBUF_SZ * sizeof *qbuf))) {
return -1;
}
num_quads = 0;

atexit(cleanup);
return 0;
}

static void cleanup(void)
{
free(qbuf);
}


Expand Down Expand Up @@ -303,8 +289,35 @@ static void set_glyphmap_texture_gl(struct dtx_glyphmap *gmap) {}

#endif /* !def NO_OPENGL */

static int dtx_draw_init(void)
{
if(qbuf) {
return 0; /* already initialized */
}

#ifndef NO_OPENGL
dtx_gl_init();
#endif

if(!(qbuf = malloc(QBUF_SZ * sizeof *qbuf))) {
return -1;
}
num_quads = 0;

atexit(cleanup);
return 0;
}

static void cleanup(void)
{
free(qbuf);
}


void dtx_target_user(dtx_user_draw_func func, void *cls)
{
dtx_draw_init();

user_draw_func = func;
user_cls = cls;

Expand Down Expand Up @@ -402,4 +415,6 @@ static void flush_user(void)

user_draw_func((struct dtx_vertex*)qbuf, num_quads * 6, &pixmap, user_cls);
cur_gmap->udata = pixmap.udata;

num_quads = 0;
}

0 comments on commit 4d94692

Please sign in to comment.