fixed anti-aliased vertex output

This commit is contained in:
vurtun 2015-10-13 14:21:48 +02:00
parent bf426606f3
commit bd9eb035fd
3 changed files with 15 additions and 20 deletions

View File

@ -277,7 +277,8 @@ static zr_float fsin(zr_float f) {return (zr_float)sin(f);}
static zr_float fcos(zr_float f) {return (zr_float)cos(f);}
static void
device_draw(struct device *dev, struct zr_command_queue *queue, int width, int height)
device_draw(struct device *dev, struct zr_command_queue *queue, int width, int height,
enum zr_anti_aliasing AA)
{
GLint last_prog, last_tex;
GLint last_ebo, last_vbo, last_vao;
@ -333,16 +334,16 @@ device_draw(struct device *dev, struct zr_command_queue *queue, int width, int h
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{
struct zr_buffer vbuf, ebuf;
zr_buffer_init_fixed(&vbuf, vertexes, (zr_size)MAX_VERTEX_MEMORY);
zr_buffer_init_fixed(&ebuf, elements, (zr_size)MAX_ELEMENT_MEMORY);
zr_buffer_init_fixed(&vbuf, vertexes, MAX_VERTEX_MEMORY);
zr_buffer_init_fixed(&ebuf, elements, MAX_ELEMENT_MEMORY);
zr_draw_list_init(&draw_list, &dev->cmds, &vbuf, &ebuf,
fsin, fcos, dev->null, ZR_ANTI_ALIASING_ON);
fsin, fcos, dev->null, AA);
zr_draw_list_load(&draw_list, queue, 1.0f, 22);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
/* iterate and execute each draw command */
/* iterate over and execute each draw command */
zr_foreach_draw_command(cmd, &draw_list) {
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
glScissor((GLint)cmd->clip_rect.x,
@ -510,7 +511,7 @@ main(int argc, char *argv[])
/* Draw */
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
device_draw(&device, &gui.queue, width, height);
device_draw(&device, &gui.queue, width, height, ZR_ANTI_ALIASING_ON);
SDL_GL_SwapWindow(win);
}

View File

@ -1716,7 +1716,6 @@ zr_command_queue_next(struct zr_command_queue *queue, const struct zr_command *c
next = zr_ptr_add_const(struct zr_command, buffer, cmd->next);
return next;
}
/* ==============================================================
*
* Draw List
@ -2266,8 +2265,8 @@ zr_draw_list_add_poly_convex(struct zr_draw_list *list, struct zr_vec2 *points,
zr_uint vtx_inner_idx = (zr_uint)(index + 0);
zr_uint vtx_outer_idx = (zr_uint)(index + 1);
struct zr_vec2 *normals;
zr_size size;
struct zr_vec2 *normals = 0;
zr_size size = 0;
if (!vtx || !ids) return;
/* temporary allocate normals */
@ -2290,10 +2289,9 @@ zr_draw_list_add_poly_convex(struct zr_draw_list *list, struct zr_vec2 *points,
struct zr_vec2 p0 = points[i0];
struct zr_vec2 p1 = points[i1];
struct zr_vec2 diff = zr_vec2_sub(p1, p0);
zr_float len;
/* vec2 inverted lenth */
len = zr_vec2_len_sqr(diff);
zr_float len = zr_vec2_len_sqr(diff);
if (len != 0.0f)
len = zr_inv_sqrt(len);
else len = 1.0f;
@ -2318,13 +2316,10 @@ zr_draw_list_add_poly_convex(struct zr_draw_list *list, struct zr_vec2 *points,
}
dm = zr_vec2_muls(dm, AA_SIZE * 0.5f);
{
/* add vertexes */
struct zr_vec2 v = zr_vec2_sub(points[i1], dm);
vtx[0] = zr_draw_vertex(v, uv, col);
vtx[1] = zr_draw_vertex(v, uv, col_trans);
vtx += 2;
}
/* add vertexes */
vtx[0] = zr_draw_vertex(zr_vec2_sub(points[i1], dm), uv, col);
vtx[1] = zr_draw_vertex(zr_vec2_add(points[i1], dm), uv, col_trans);
vtx += 2;
/* add indexes */
ids[0] = (zr_draw_index)(vtx_inner_idx+(i1<<1));
@ -2338,7 +2333,7 @@ zr_draw_list_add_poly_convex(struct zr_draw_list *list, struct zr_vec2 *points,
/* free temporary normals + points */
zr_buffer_reset(list->vertexes, ZR_BUFFER_FRONT);
} else {
zr_size i;
zr_size i = 0;
zr_size index = list->vertex_count;
const zr_size idx_count = (points_count-2)*3;
const zr_size vtx_count = points_count;

View File

@ -1483,7 +1483,6 @@ const zr_long *zr_font_default_glyph_ranges(void);
const zr_long *zr_font_chinese_glyph_ranges(void);
const zr_long *zr_font_cyrillic_glyph_ranges(void);
const zr_long *zr_font_korean_glyph_ranges(void);
/* ---------------------------------------------------------------
* Baking
* ---------------------------------------------------------------*/