cdderivedmesh fix stippled faces not getting drawn at all

Also rearranged code here to not issue a draw call (explicit flush) per
face and not set shader per face either when stippled drawing is mixed
with regular drawing. Not good at all for performance.
This commit is contained in:
Antony Riakiotakis 2015-12-28 17:54:45 +01:00
parent 1dcae9e309
commit d346ed3b10

@ -748,6 +748,8 @@ static void cdDM_drawMappedFaces(
draw_option = setMaterial(bufmat->mat_nr + 1, NULL);
if (draw_option != DM_DRAW_OPTION_SKIP) {
DMDrawOption last_draw_option = DM_DRAW_OPTION_NORMAL;
for (i = 0; i < totpoly; i++) {
int actualFace = next_actualFace;
int flush = 0;
@ -766,17 +768,12 @@ static void cdDM_drawMappedFaces(
}
}
if (draw_option == DM_DRAW_OPTION_STIPPLE) {
GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
}
/* Goal is to draw as long of a contiguous triangle
* array as possible, so draw when we hit either an
* invisible triangle or at the end of the array */
/* flush buffer if current triangle isn't drawable or it's last triangle... */
flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == totpoly - 1);
flush = (draw_option != last_draw_option) || (i == totpoly - 1);
if (!flush && compareDrawOptions) {
flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
@ -786,18 +783,27 @@ static void cdDM_drawMappedFaces(
tot_element += tot_tri_verts;
if (flush) {
if (!ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE))
if (draw_option != DM_DRAW_OPTION_SKIP) {
tot_drawn += tot_tri_verts;
if (last_draw_option != draw_option) {
if (draw_option == DM_DRAW_OPTION_STIPPLE) {
GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
}
else {
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
}
}
}
if (tot_drawn) {
GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
tot_drawn = 0;
}
last_draw_option = draw_option;
start_element = tot_element;
if (draw_option == DM_DRAW_OPTION_STIPPLE)
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
}
else {
tot_drawn += tot_tri_verts;
@ -807,6 +813,7 @@ static void cdDM_drawMappedFaces(
}
}
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
glShadeModel(GL_FLAT);
GPU_buffers_unbind();