mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 10:59:20 +02:00
Every module unit now includes the standard headers it uses. Declarations reaching a unit only through an imported module's global module fragment are reachable but not visible, so ADL misses the free operators older libstdc++ declares beside a type - reproduced on ubuntu 24.04 (libstdc++ 13), where gl/vao.cpp could not compare vector iterators. Also drops a stale editor/editorSettings.hpp from the MSVC source list, which broke the Windows configure step, silences the deliberate include-in-purview warning in the glm wrapper, and removes GCC support: clang or MSVC only.
94 lines
1.8 KiB
C++
94 lines
1.8 KiB
C++
module;
|
|
#include <vector>
|
|
#include "glad/glad.h"
|
|
#include <cstddef>
|
|
|
|
module eu07.gl.vao;
|
|
|
|
bool gl::vao::use_vao = true;
|
|
|
|
gl::vao::vao()
|
|
{
|
|
if (!use_vao)
|
|
return;
|
|
|
|
glGenVertexArrays(1, *this);
|
|
}
|
|
|
|
gl::vao::~vao()
|
|
{
|
|
if (!use_vao)
|
|
return;
|
|
|
|
unbind();
|
|
glDeleteVertexArrays(1, *this);
|
|
}
|
|
|
|
void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, int stride, int offset)
|
|
{
|
|
if (use_vao) {
|
|
bind();
|
|
buffer.bind(buffer::ARRAY_BUFFER);
|
|
glVertexAttribPointer(attrib, size, type, GL_FALSE, stride, reinterpret_cast<void*>(offset));
|
|
glEnableVertexAttribArray(attrib);
|
|
}
|
|
else {
|
|
if (attrib == 0)
|
|
params.clear();
|
|
params.push_back({buffer, attrib, size, type, stride, offset});
|
|
active = nullptr;
|
|
}
|
|
}
|
|
|
|
void gl::vao::setup_ebo(buffer &e)
|
|
{
|
|
if (use_vao) {
|
|
bind();
|
|
// ELEMENT_ARRAY_BUFFER is part of VAO and therefore shouldn't be managed by gl::buffer global tracker!
|
|
// but it is needed by it for buffer data management, so eh
|
|
e.bind(buffer::ELEMENT_ARRAY_BUFFER);
|
|
}
|
|
else {
|
|
ebo = &e;
|
|
active = nullptr;
|
|
}
|
|
}
|
|
|
|
void gl::vao::bind()
|
|
{
|
|
if (active == this)
|
|
return;
|
|
active = this;
|
|
|
|
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 < 5; 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;
|
|
if (use_vao) {
|
|
glBindVertexArray(0);
|
|
}
|
|
else {
|
|
for (size_t i = 0; i < 4; i++)
|
|
glDisableVertexAttribArray(i);
|
|
}
|
|
}
|