void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); gs_effect_t *effect = gs_get_effect(); struct gs_program *program; if (!can_render(device)) goto fail; if (effect) gs_effect_update_params(effect); program = get_shader_program(device); if (!program) goto fail; load_vb_buffers(program, device->cur_vertex_buffer); if (program != device->cur_program && device->cur_program) { glUseProgram(0); gl_success("glUseProgram (zero)"); } if (program != device->cur_program) { device->cur_program = program; glUseProgram(program->obj); if (!gl_success("glUseProgram")) goto fail; } update_viewproj_matrix(device); program_update_params(program); if (ib) { if (num_verts == 0) num_verts = (uint32_t)device->cur_index_buffer->num; glDrawElements(topology, num_verts, ib->gl_type, (const GLvoid*)(start_vert * ib->width)); if (!gl_success("glDrawElements")) goto fail; } else { if (num_verts == 0) num_verts = (uint32_t)device->cur_vertex_buffer->num; glDrawArrays(topology, start_vert, num_verts); if (!gl_success("glDrawArrays")) goto fail; } return; fail: blog(LOG_ERROR, "device_draw (GL) failed"); }
void device_draw(device_t device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); effect_t effect = gs_geteffect(); if (!can_render(device)) goto fail; if (effect) effect_updateparams(effect); shader_update_textures(device->cur_pixel_shader); update_viewproj_matrix(device); #ifdef _DEBUG if (!check_shader_pipeline_validity(device)) goto fail; #endif if (ib) { if (num_verts == 0) num_verts = (uint32_t)device->cur_index_buffer->num; glDrawElements(topology, num_verts, ib->gl_type, (const GLvoid*)(start_vert * ib->width)); if (!gl_success("glDrawElements")) goto fail; } else { if (num_verts == 0) num_verts = (uint32_t)device->cur_vertex_buffer->num; glDrawArrays(topology, start_vert, num_verts); if (!gl_success("glDrawArrays")) goto fail; } return; fail: blog(LOG_ERROR, "device_draw (GL) failed"); }