make vao mode selectable at runtime (enabled by default, disabled by multiviewports)

This commit is contained in:
milek7
2019-08-08 15:48:55 +02:00
parent 37fea6db7a
commit 613bdb91d9
4 changed files with 52 additions and 41 deletions

View File

@@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/.
#include "Console.h" #include "Console.h"
#include "PyInt.h" #include "PyInt.h"
#include "Timer.h" #include "Timer.h"
#include "vao.h"
global_settings Global; global_settings Global;
@@ -855,6 +856,10 @@ global_settings::ConfigParse(cParser &Parser) {
Parser >> conf.transform[i / 4][i % 4]; Parser >> conf.transform[i / 4][i % 4];
extra_viewports.push_back(conf); 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) } while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile)
// na koniec trochę zależności // na koniec trochę zależności

View File

@@ -1,48 +1,48 @@
#include "stdafx.h" #include "stdafx.h"
#include "vao.h" #include "vao.h"
/* bool gl::vao::use_vao = true;
gl::vao::vao() gl::vao::vao()
{ {
if (!use_vao)
return;
glGenVertexArrays(1, *this); glGenVertexArrays(1, *this);
} }
gl::vao::~vao() gl::vao::~vao()
{ {
if (!use_vao)
return;
glDeleteVertexArrays(1, *this); glDeleteVertexArrays(1, *this);
} }
void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, int stride, int offset) void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, int stride, int offset)
{ {
bind(); if (use_vao) {
buffer.bind(gl::buffer::ARRAY_BUFFER); bind();
glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast<void*>(offset)); buffer.bind(buffer::ARRAY_BUFFER);
glEnableVertexAttribArray(attrib); glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast<void*>(offset));
glEnableVertexAttribArray(attrib);
} }
else {
void gl::vao::setup_ebo(buffer &ebo) params.push_back({buffer, attrib, size, type, stride, offset});
{ active = nullptr;
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;
} }
void gl::vao::setup_ebo(buffer &e) void gl::vao::setup_ebo(buffer &e)
{ {
ebo = &e; if (use_vao) {
active = nullptr; bind();
e.bind(buffer::ELEMENT_ARRAY_BUFFER);
}
else {
ebo = &e;
active = nullptr;
}
} }
void gl::vao::bind() void gl::vao::bind()
@@ -51,19 +51,24 @@ void gl::vao::bind()
return; return;
active = this; active = this;
for (attrib_params &param : params) { if (use_vao) {
param.buffer.bind(gl::buffer::ARRAY_BUFFER); glBindVertexArray(*this);
glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast<void*>(param.offset));
glEnableVertexAttribArray(param.attrib);
} }
else {
for (attrib_params &param : params) {
param.buffer.bind(gl::buffer::ARRAY_BUFFER);
glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast<void*>(param.offset));
glEnableVertexAttribArray(param.attrib);
}
for (size_t i = params.size(); i < 4; i++) for (size_t i = params.size(); i < 4; i++)
glDisableVertexAttribArray(i); glDisableVertexAttribArray(i);
if (ebo) if (ebo)
ebo->bind(gl::buffer::ELEMENT_ARRAY_BUFFER); ebo->bind(gl::buffer::ELEMENT_ARRAY_BUFFER);
else else
gl::buffer::unbind(gl::buffer::ELEMENT_ARRAY_BUFFER); gl::buffer::unbind(gl::buffer::ELEMENT_ARRAY_BUFFER);
}
} }
void gl::vao::unbind() void gl::vao::unbind()

View File

@@ -6,7 +6,7 @@
namespace gl namespace gl
{ {
class vao : public bindable<vao> class vao : object, public bindable<vao>
{ {
struct attrib_params { struct attrib_params {
// TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist) // TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist)
@@ -23,15 +23,15 @@ namespace gl
std::vector<attrib_params> params; std::vector<attrib_params> params;
public: public:
//vao(); vao();
//~vao(); ~vao();
void setup_attrib(buffer &buffer, int attrib, int size, int type, int stride, int offset); void setup_attrib(buffer &buffer, int attrib, int size, int type, int stride, int offset);
void setup_ebo(buffer &ebo); void setup_ebo(buffer &ebo);
//using bindable::bind;
void bind(); void bind();
static void unbind(); static void unbind();
//static void bind(GLuint i);
static bool use_vao;
}; };
} }

View File

@@ -450,6 +450,7 @@ bool opengl_renderer::init_viewport(viewport_config &vp)
if (!Global.gfx_usegles) if (!Global.gfx_usegles)
glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_PROGRAM_POINT_SIZE);
if (!gl::vao::use_vao)
{ {
GLuint v; GLuint v;
glGenVertexArrays(1, &v); glGenVertexArrays(1, &v);