From b8e5cf3a95827af342ccb04b52974faa026322c4 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Mon, 24 Jun 2019 23:13:04 -0500 Subject: [PATCH] libobs-opengl: Empty VAO Use an empty VAO for shaders that generate their own vertices. --- libobs-opengl/gl-helpers.h | 7 +++++-- libobs-opengl/gl-subsystem.c | 9 ++++++++- libobs-opengl/gl-subsystem.h | 2 ++ libobs-opengl/gl-vertexbuffer.c | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libobs-opengl/gl-helpers.h b/libobs-opengl/gl-helpers.h index 939a1fc19..779d070d5 100644 --- a/libobs-opengl/gl-helpers.h +++ b/libobs-opengl/gl-helpers.h @@ -27,8 +27,11 @@ static inline bool gl_success(const char *funcname) { GLenum errorcode = glGetError(); if (errorcode != GL_NO_ERROR) { - blog(LOG_ERROR, "%s failed, glGetError returned 0x%X", funcname, - errorcode); + do { + blog(LOG_ERROR, "%s failed, glGetError returned 0x%X", + funcname, errorcode); + errorcode = glGetError(); + } while (errorcode != GL_NO_ERROR); return false; } diff --git a/libobs-opengl/gl-subsystem.c b/libobs-opengl/gl-subsystem.c index aab06994e..c68b40f95 100644 --- a/libobs-opengl/gl-subsystem.c +++ b/libobs-opengl/gl-subsystem.c @@ -248,6 +248,7 @@ int device_create(gs_device_t **p_device, uint32_t adapter) glVersion, glShadingLanguage); gl_enable(GL_CULL_FACE); + gl_gen_vertex_arrays(1, &device->empty_vao); device_leave_context(device); device->cur_swap = NULL; @@ -277,6 +278,8 @@ void device_destroy(gs_device_t *device) while (device->first_program) gs_program_destroy(device->first_program); + gl_delete_vertex_arrays(1, &device->empty_vao); + da_free(device->proj_stack); gl_platform_destroy(device->plat); bfree(device); @@ -987,6 +990,7 @@ static inline struct gs_program *get_shader_program(struct gs_device *device) void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { + struct gs_vertex_buffer *vb = device->cur_vertex_buffer; struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); gs_effect_t *effect = gs_get_effect(); @@ -1002,7 +1006,10 @@ void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode, if (!program) goto fail; - load_vb_buffers(program, device->cur_vertex_buffer, ib); + if (vb) + load_vb_buffers(program, vb, ib); + else + gl_bind_vertex_array(device->empty_vao); if (program != device->cur_program && device->cur_program) { glUseProgram(0); diff --git a/libobs-opengl/gl-subsystem.h b/libobs-opengl/gl-subsystem.h index ffdaa64de..027d31e52 100644 --- a/libobs-opengl/gl-subsystem.h +++ b/libobs-opengl/gl-subsystem.h @@ -581,6 +581,8 @@ struct gs_device { struct gl_platform *plat; enum copy_type copy_type; + GLuint empty_vao; + gs_texture_t *cur_render_target; gs_zstencil_t *cur_zstencil_buffer; int cur_render_side; diff --git a/libobs-opengl/gl-vertexbuffer.c b/libobs-opengl/gl-vertexbuffer.c index 3a2370a8c..2d212ced0 100644 --- a/libobs-opengl/gl-vertexbuffer.c +++ b/libobs-opengl/gl-vertexbuffer.c @@ -256,7 +256,7 @@ bool load_vb_buffers(struct gs_program *program, struct gs_vertex_buffer *vb, struct gs_shader *shader = program->vertex_shader; size_t i; - if (vb && !gl_bind_vertex_array(vb->vao)) + if (!gl_bind_vertex_array(vb->vao)) return false; for (i = 0; i < shader->attribs.num; i++) {