mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
make vao mode selectable at runtime (enabled by default, disabled by multiviewports)
This commit is contained in:
@@ -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
|
||||
|
||||
77
gl/vao.cpp
77
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<void*>(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<void*>(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<void*>(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<void*>(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()
|
||||
|
||||
10
gl/vao.h
10
gl/vao.h
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace gl
|
||||
{
|
||||
class vao : public bindable<vao>
|
||||
class vao : object, public bindable<vao>
|
||||
{
|
||||
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<attrib_params> 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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user