From 613bdb91d98ff5b7b17c25a006d1788a6808f334 Mon Sep 17 00:00:00 2001 From: milek7 Date: Thu, 8 Aug 2019 15:48:55 +0200 Subject: [PATCH] make vao mode selectable at runtime (enabled by default, disabled by multiviewports) --- Globals.cpp | 5 ++++ gl/vao.cpp | 77 ++++++++++++++++++++++++++++------------------------ gl/vao.h | 10 +++---- renderer.cpp | 1 + 4 files changed, 52 insertions(+), 41 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index ec447eff..d9f6c225 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/. #include "Console.h" #include "PyInt.h" #include "Timer.h" +#include "vao.h" global_settings Global; @@ -855,6 +856,10 @@ global_settings::ConfigParse(cParser &Parser) { Parser >> conf.transform[i / 4][i % 4]; extra_viewports.push_back(conf); + if (gl::vao::use_vao) { + gl::vao::use_vao = false; + WriteLog("using multiple viewports, disabling vao!"); + } } } while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile) // na koniec trochę zależności diff --git a/gl/vao.cpp b/gl/vao.cpp index 88a2149c..df28392b 100644 --- a/gl/vao.cpp +++ b/gl/vao.cpp @@ -1,48 +1,48 @@ #include "stdafx.h" #include "vao.h" -/* +bool gl::vao::use_vao = true; + gl::vao::vao() { + if (!use_vao) + return; + glGenVertexArrays(1, *this); } gl::vao::~vao() { + if (!use_vao) + return; + glDeleteVertexArrays(1, *this); } void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, int stride, int offset) { - bind(); - buffer.bind(gl::buffer::ARRAY_BUFFER); - glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast(offset)); - glEnableVertexAttribArray(attrib); - -} - -void gl::vao::setup_ebo(buffer &ebo) -{ - bind(); - ebo.bind(gl::buffer::ELEMENT_ARRAY_BUFFER); -} - -void gl::vao::bind(GLuint i) -{ - glBindVertexArray(i); -} -*/ - -void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, int stride, int offset) -{ - params.push_back({buffer, attrib, size, type, stride, offset}); - active = nullptr; + if (use_vao) { + bind(); + buffer.bind(buffer::ARRAY_BUFFER); + glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast(offset)); + glEnableVertexAttribArray(attrib); + } + else { + params.push_back({buffer, attrib, size, type, stride, offset}); + active = nullptr; + } } void gl::vao::setup_ebo(buffer &e) { - ebo = &e; - active = nullptr; + if (use_vao) { + bind(); + e.bind(buffer::ELEMENT_ARRAY_BUFFER); + } + else { + ebo = &e; + active = nullptr; + } } void gl::vao::bind() @@ -51,19 +51,24 @@ void gl::vao::bind() return; active = this; - for (attrib_params ¶m : params) { - param.buffer.bind(gl::buffer::ARRAY_BUFFER); - glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast(param.offset)); - glEnableVertexAttribArray(param.attrib); + if (use_vao) { + glBindVertexArray(*this); } + else { + for (attrib_params ¶m : params) { + param.buffer.bind(gl::buffer::ARRAY_BUFFER); + glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast(param.offset)); + glEnableVertexAttribArray(param.attrib); + } - for (size_t i = params.size(); i < 4; i++) - glDisableVertexAttribArray(i); + for (size_t i = params.size(); i < 4; i++) + glDisableVertexAttribArray(i); - if (ebo) - ebo->bind(gl::buffer::ELEMENT_ARRAY_BUFFER); - else - gl::buffer::unbind(gl::buffer::ELEMENT_ARRAY_BUFFER); + if (ebo) + ebo->bind(gl::buffer::ELEMENT_ARRAY_BUFFER); + else + gl::buffer::unbind(gl::buffer::ELEMENT_ARRAY_BUFFER); + } } void gl::vao::unbind() diff --git a/gl/vao.h b/gl/vao.h index 16ea06a8..a4415d03 100644 --- a/gl/vao.h +++ b/gl/vao.h @@ -6,7 +6,7 @@ namespace gl { - class vao : public bindable + class vao : object, public bindable { struct attrib_params { // TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist) @@ -23,15 +23,15 @@ namespace gl std::vector params; public: - //vao(); - //~vao(); + vao(); + ~vao(); void setup_attrib(buffer &buffer, int attrib, int size, int type, int stride, int offset); void setup_ebo(buffer &ebo); - //using bindable::bind; void bind(); static void unbind(); - //static void bind(GLuint i); + + static bool use_vao; }; } diff --git a/renderer.cpp b/renderer.cpp index 75db899f..ee10ece0 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -450,6 +450,7 @@ bool opengl_renderer::init_viewport(viewport_config &vp) if (!Global.gfx_usegles) glEnable(GL_PROGRAM_POINT_SIZE); + if (!gl::vao::use_vao) { GLuint v; glGenVertexArrays(1, &v);