mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
multi viewports (temporaily disable VAO)
This commit is contained in:
@@ -6,7 +6,7 @@ namespace gl
|
||||
class bindable
|
||||
{
|
||||
protected:
|
||||
static bindable<T>* active;
|
||||
thread_local static bindable<T>* active;
|
||||
|
||||
public:
|
||||
void bind()
|
||||
@@ -23,5 +23,5 @@ namespace gl
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> bindable<T>* bindable<T>::active;
|
||||
template <typename T> thread_local bindable<T>* bindable<T>::active;
|
||||
}
|
||||
|
||||
@@ -79,4 +79,4 @@ void gl::buffer::download(targets target, void *data, int offset, int size)
|
||||
}
|
||||
}
|
||||
|
||||
GLuint gl::buffer::binding_points[13];
|
||||
thread_local GLuint gl::buffer::binding_points[13];
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace gl
|
||||
{
|
||||
class buffer : public object
|
||||
{
|
||||
static GLuint binding_points[13];
|
||||
thread_local static GLuint binding_points[13];
|
||||
|
||||
public:
|
||||
enum targets
|
||||
|
||||
62
gl/vao.cpp
62
gl/vao.cpp
@@ -1,24 +1,72 @@
|
||||
#include "stdafx.h"
|
||||
#include "vao.h"
|
||||
|
||||
/*
|
||||
gl::vao::vao()
|
||||
{
|
||||
glGenVertexArrays(1, *this);
|
||||
glGenVertexArrays(1, *this);
|
||||
}
|
||||
|
||||
gl::vao::~vao()
|
||||
{
|
||||
glDeleteVertexArrays(1, *this);
|
||||
glDeleteVertexArrays(1, *this);
|
||||
}
|
||||
|
||||
void gl::vao::setup_attrib(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();
|
||||
glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast<void*>(offset));
|
||||
glEnableVertexAttribArray(attrib);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
ebo = &e;
|
||||
active = nullptr;
|
||||
}
|
||||
|
||||
void gl::vao::bind()
|
||||
{
|
||||
if (active == this)
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void gl::vao::unbind()
|
||||
{
|
||||
active = nullptr;
|
||||
}
|
||||
|
||||
30
gl/vao.h
30
gl/vao.h
@@ -2,18 +2,36 @@
|
||||
|
||||
#include "object.h"
|
||||
#include "bindable.h"
|
||||
#include "buffer.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
class vao : public object, public bindable<vao>
|
||||
class vao : public bindable<vao>
|
||||
{
|
||||
struct attrib_params {
|
||||
// TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist)
|
||||
gl::buffer &buffer;
|
||||
|
||||
int attrib;
|
||||
int size;
|
||||
int type;
|
||||
int stride;
|
||||
int offset;
|
||||
};
|
||||
buffer *ebo = nullptr;
|
||||
|
||||
std::vector<attrib_params> params;
|
||||
|
||||
public:
|
||||
vao();
|
||||
~vao();
|
||||
//vao();
|
||||
//~vao();
|
||||
|
||||
void setup_attrib(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);
|
||||
|
||||
using bindable::bind;
|
||||
static void bind(GLuint i);
|
||||
//using bindable::bind;
|
||||
void bind();
|
||||
static void unbind();
|
||||
//static void bind(GLuint i);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user