mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-16 23:18:12 +08:00
Add "ensureInitialize" function and now we can make empty objects
This commit is contained in:
parent
38731299fd
commit
7ce0a4e27d
3
.gitignore
vendored
3
.gitignore
vendored
@ -360,4 +360,5 @@ MigrationBackup/
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
FodyWeavers.xsd
|
||||
/FinalProject/temp/shaders
|
||||
|
||||
@ -1,33 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "ebo.h"
|
||||
#include "logger.h"
|
||||
|
||||
ElementBufferObject::ElementBufferObject() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
ElementBufferObject::ElementBufferObject(const std::vector<unsigned int>& indices) :
|
||||
_indices(indices) {
|
||||
ElementBufferObject::ElementBufferObject(const std::vector<unsigned int>& indices) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
_indices.size() * sizeof(unsigned int),
|
||||
_indices.data(),
|
||||
indices.size() * sizeof(unsigned int),
|
||||
indices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
ElementBufferObject::ElementBufferObject(std::vector<unsigned int>&& indices) :
|
||||
_indices(std::move(indices)) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
void ElementBufferObject::setBuffer(const std::vector<unsigned int>& indices) {
|
||||
if (_id == 0) {
|
||||
Logger::error("Try to bind buffer to an uninitialized element buffer object");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
_indices.size() * sizeof(unsigned int),
|
||||
_indices.data(),
|
||||
indices.size() * sizeof(unsigned int),
|
||||
indices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
@ -6,21 +6,49 @@
|
||||
|
||||
class ElementBufferObject
|
||||
{
|
||||
public:
|
||||
static ElementBufferObject empty() {
|
||||
return ElementBufferObject();
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int _id = 0;
|
||||
std::vector<unsigned int> _indices;
|
||||
|
||||
private:
|
||||
ElementBufferObject();
|
||||
|
||||
public:
|
||||
ElementBufferObject();
|
||||
ElementBufferObject(const std::vector<unsigned int>& indices);
|
||||
ElementBufferObject(std::vector<unsigned int>&& indices);
|
||||
|
||||
inline unsigned int id() const { return _id; }
|
||||
inline std::vector<unsigned int> indices() const { return _indices; }
|
||||
|
||||
inline void dispose() const;
|
||||
inline void bind() const;
|
||||
inline void unbind() const;
|
||||
inline void dispose();
|
||||
inline void ensureInitialized();
|
||||
|
||||
void setBuffer(const std::vector<unsigned int>& indices);
|
||||
};
|
||||
|
||||
inline void ElementBufferObject::dispose() const {
|
||||
inline void ElementBufferObject::bind() const {
|
||||
if (_id == 0) {
|
||||
Logger::error("Binding an invalid ElementBufferObject");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
||||
}
|
||||
|
||||
inline void ElementBufferObject::unbind() const {
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
inline void ElementBufferObject::dispose() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glDeleteBuffers(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
inline void ElementBufferObject::ensureInitialized() {
|
||||
if (_id == 0) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "qdebug.h"
|
||||
#include <qdebug.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
|
||||
@ -30,8 +30,6 @@ SceneViewer::SceneViewer(QWidget* parent)
|
||||
// Copy the shaders to the folder
|
||||
QFile::copy(":/shaders/vertexshader.vs", "./temp/shaders/vertexshader.vs");
|
||||
QFile::copy(":/shaders/fragmentshader.fs", "./temp/shaders/fragmentshader.fs");
|
||||
|
||||
|
||||
}
|
||||
|
||||
SceneViewer::~SceneViewer() {
|
||||
@ -45,6 +43,17 @@ void SceneViewer::initializeGL() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Logger::info("Currently running on OpenGL version: " + std::string((const char*)glGetString(GL_VERSION)));
|
||||
|
||||
_vao.ensureInitialized();
|
||||
Logger::info("Vertex Array Object initialized");
|
||||
|
||||
_shaderProgram.ensureInitialized();
|
||||
Logger::info("Shader Program initialized");
|
||||
|
||||
VertexShader vertexShader("./temp/shaders/vertexshader.vs");
|
||||
FragmentShader fragmentShader("./temp/shaders/fragmentshader.fs");
|
||||
_shaderProgram.attachShader(vertexShader);
|
||||
|
||||
}
|
||||
|
||||
void SceneViewer::resizeGL(int w, int h) {
|
||||
@ -67,7 +76,7 @@ void SceneViewer::paintGL() {
|
||||
VertexShader vertexShader("./temp/shaders/vertexshader.vs");
|
||||
FragmentShader fragmentShader("./temp/shaders/fragmentshader.fs");
|
||||
ShaderProgram shaderProgram(vertexShader, fragmentShader);
|
||||
shaderProgram.setActive();
|
||||
shaderProgram.bind();
|
||||
vao.bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "shader.h"
|
||||
#include "renderable.h"
|
||||
#include "vao.h"
|
||||
#include "utils.h"
|
||||
@ -16,6 +17,8 @@ class SceneViewer : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
|
||||
private:
|
||||
std::vector<Renderable> _objects;
|
||||
ShaderProgram _shaderProgram = ShaderProgram::empty();
|
||||
VertexArrayObject _vao = VertexArrayObject::empty();
|
||||
|
||||
public:
|
||||
SceneViewer(QWidget* parent = 0);
|
||||
|
||||
@ -102,7 +102,7 @@ void GeometryShader::compile(const std::string& source) {
|
||||
}
|
||||
|
||||
ShaderProgram::ShaderProgram() {
|
||||
_programId = OPENGL_EXTRA_FUNCTIONS->glCreateProgram();
|
||||
_programId = 0;
|
||||
}
|
||||
|
||||
ShaderProgram::ShaderProgram(VertexShader vertexShader) {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
class Shader {
|
||||
protected:
|
||||
unsigned int _shaderId = -1;
|
||||
unsigned int _shaderId = 0;
|
||||
|
||||
public:
|
||||
Shader() {}
|
||||
@ -27,7 +27,6 @@ inline void Shader::dispose() {
|
||||
|
||||
class VertexShader : public Shader {
|
||||
public:
|
||||
VertexShader() {}
|
||||
VertexShader(const std::string& sourceFilePath);
|
||||
|
||||
protected:
|
||||
@ -36,7 +35,6 @@ protected:
|
||||
|
||||
class FragmentShader : public Shader {
|
||||
public:
|
||||
FragmentShader() {}
|
||||
FragmentShader(const std::string& sourceFilePath);
|
||||
|
||||
protected:
|
||||
@ -45,7 +43,6 @@ protected:
|
||||
|
||||
class GeometryShader : public Shader {
|
||||
public:
|
||||
GeometryShader() {}
|
||||
GeometryShader(const std::string& sourceFilePath);
|
||||
|
||||
protected:
|
||||
@ -53,11 +50,18 @@ protected:
|
||||
};
|
||||
|
||||
class ShaderProgram {
|
||||
public:
|
||||
static ShaderProgram empty() {
|
||||
return ShaderProgram();
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int _programId = 0;
|
||||
|
||||
public:
|
||||
private:
|
||||
ShaderProgram();
|
||||
|
||||
public:
|
||||
ShaderProgram(VertexShader vertexShader);
|
||||
ShaderProgram(FragmentShader fragmentShader);
|
||||
ShaderProgram(GeometryShader geometryShader);
|
||||
@ -67,19 +71,33 @@ public:
|
||||
ShaderProgram(VertexShader vertexShader, FragmentShader fragmentShader, GeometryShader geometryShader);
|
||||
|
||||
public:
|
||||
inline void setActive();
|
||||
inline void setInactive();
|
||||
|
||||
inline unsigned int programId() const { return _programId; }
|
||||
|
||||
inline void attachShader(const Shader& shader) const;
|
||||
|
||||
inline void bind() const;
|
||||
inline void unbind() const;
|
||||
inline void dispose();
|
||||
inline void ensureInitialized();
|
||||
};
|
||||
|
||||
inline void ShaderProgram::setActive() {
|
||||
inline void ShaderProgram::attachShader(const Shader& shader) const {
|
||||
if (_programId == 0) {
|
||||
Logger::error("Attaching a shader to an invalid ShaderProgram");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glAttachShader(_programId, shader.shaderId());
|
||||
}
|
||||
|
||||
inline void ShaderProgram::bind() const {
|
||||
if (_programId == 0) {
|
||||
Logger::error("Binding an invalid ShaderProgram");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glUseProgram(_programId);
|
||||
}
|
||||
|
||||
inline void ShaderProgram::setInactive() {
|
||||
inline void ShaderProgram::unbind() const {
|
||||
OPENGL_EXTRA_FUNCTIONS->glUseProgram(0);
|
||||
}
|
||||
|
||||
@ -87,3 +105,9 @@ inline void ShaderProgram::dispose() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glDeleteProgram(_programId);
|
||||
_programId = 0;
|
||||
}
|
||||
|
||||
inline void ShaderProgram::ensureInitialized() {
|
||||
if (_programId == 0) {
|
||||
_programId = OPENGL_EXTRA_FUNCTIONS->glCreateProgram();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,39 +3,20 @@
|
||||
#include "vao.h"
|
||||
|
||||
VertexArrayObject::VertexArrayObject() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo) :
|
||||
_vbo(vbo) {
|
||||
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
VertexArrayObject::VertexArrayObject(VertexBufferObject&& vbo) :
|
||||
_vbo(std::move(vbo)) {
|
||||
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo) :
|
||||
_vbo(vbo), _ebo(ebo) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
VertexArrayObject::VertexArrayObject(VertexBufferObject&& vbo, ElementBufferObject&& ebo) :
|
||||
_vbo(std::move(vbo)), _ebo(std::move(ebo)) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
@ -8,27 +8,30 @@
|
||||
#include "logger.h"
|
||||
|
||||
class VertexArrayObject {
|
||||
public:
|
||||
static VertexArrayObject empty() {
|
||||
return VertexArrayObject();
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int _id = 0;
|
||||
VertexBufferObject _vbo;
|
||||
ElementBufferObject _ebo;
|
||||
|
||||
private:
|
||||
VertexArrayObject();
|
||||
|
||||
public:
|
||||
VertexArrayObject();
|
||||
VertexArrayObject(const VertexBufferObject& vbo);
|
||||
VertexArrayObject(VertexBufferObject&& vbo);
|
||||
VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo);
|
||||
VertexArrayObject(VertexBufferObject&& vbo, ElementBufferObject&& ebo);
|
||||
|
||||
inline unsigned int id() const { return _id; }
|
||||
|
||||
|
||||
inline void bind() const;
|
||||
inline void unbind() const;
|
||||
inline void dispose();
|
||||
inline void ensureInitialized();
|
||||
|
||||
inline void bindVertexBufferObject(const VertexBufferObject& vbo);
|
||||
inline void bindVertexBufferObject(VertexBufferObject&& vbo);
|
||||
inline void bindElementBufferObject(const ElementBufferObject& ebo);
|
||||
inline void bindElementBufferObject(ElementBufferObject&& ebo);
|
||||
|
||||
inline void setVertexAttributePointer(unsigned int index, int size, unsigned int type, bool normalized, unsigned int stride, const void* pointer) const;
|
||||
inline void enableVertexAttribute(unsigned int index) const;
|
||||
@ -37,7 +40,7 @@ public:
|
||||
|
||||
inline void VertexArrayObject::bind() const {
|
||||
// Check is id is valid
|
||||
if (_id == -1) {
|
||||
if (_id == 0) {
|
||||
Logger::error("Binding an invalid VertexArrayObject");
|
||||
return;
|
||||
}
|
||||
@ -48,31 +51,26 @@ inline void VertexArrayObject::unbind() const {
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
inline void VertexArrayObject::bindVertexBufferObject(const VertexBufferObject& vbo) {
|
||||
_vbo = vbo;
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
inline void VertexArrayObject::dispose() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glDeleteVertexArrays(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
inline void VertexArrayObject::bindVertexBufferObject(VertexBufferObject&& vbo) {
|
||||
_vbo = std::move(vbo);
|
||||
inline void VertexArrayObject::ensureInitialized() {
|
||||
if (_id == 0) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||
}
|
||||
}
|
||||
|
||||
inline void VertexArrayObject::bindVertexBufferObject(const VertexBufferObject& vbo) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, vbo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
inline void VertexArrayObject::bindElementBufferObject(const ElementBufferObject& ebo) {
|
||||
_ebo = ebo;
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
inline void VertexArrayObject::bindElementBufferObject(ElementBufferObject&& ebo) {
|
||||
_ebo = std::move(ebo);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo.id());
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
||||
@ -1,33 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "vbo.h"
|
||||
#include "logger.h"
|
||||
|
||||
VertexBufferObject::VertexBufferObject() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
VertexBufferObject::VertexBufferObject(const std::vector<Vertex>& vertices) :
|
||||
_vertices(vertices) {
|
||||
VertexBufferObject::VertexBufferObject(const std::vector<Vertex>& vertices) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_vertices.size() * sizeof(Vertex),
|
||||
_vertices.data(),
|
||||
vertices.size() * sizeof(Vertex),
|
||||
vertices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
VertexBufferObject::VertexBufferObject(std::vector<Vertex>&& vertices) :
|
||||
_vertices(std::move(vertices)) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
void VertexBufferObject::setBuffer(const std::vector<Vertex>& vertices) {
|
||||
if (id == 0) {
|
||||
Logger::error("Try to bind buffer to an uninitialized vertex buffer object");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_vertices.size() * sizeof(Vertex),
|
||||
_vertices.data(),
|
||||
vertices.size() * sizeof(Vertex),
|
||||
vertices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
@ -6,21 +6,49 @@
|
||||
#include "utils.h"
|
||||
|
||||
class VertexBufferObject {
|
||||
public:
|
||||
static VertexBufferObject empty() {
|
||||
return VertexBufferObject();
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int _id = 0;
|
||||
std::vector<Vertex> _vertices;
|
||||
|
||||
public:
|
||||
private:
|
||||
VertexBufferObject();
|
||||
|
||||
public:
|
||||
VertexBufferObject(const std::vector<Vertex>& vertices);
|
||||
VertexBufferObject(std::vector<Vertex>&& vertices);
|
||||
|
||||
inline unsigned int id() const { return _id; }
|
||||
inline std::vector<Vertex> vertices() const { return _vertices; }
|
||||
|
||||
inline void dispose() const;
|
||||
inline void bind() const;
|
||||
inline void unbind() const;
|
||||
inline void dispose();
|
||||
inline void ensureInitialized();
|
||||
|
||||
void setBuffer(const std::vector<Vertex>& vertices);
|
||||
};
|
||||
|
||||
inline void VertexBufferObject::dispose() const {
|
||||
inline void VertexBufferObject::bind() const {
|
||||
if (_id == 0) {
|
||||
Logger::error("Binding an invalid VertexBufferObject");
|
||||
return;
|
||||
}
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
||||
}
|
||||
|
||||
inline void VertexBufferObject::unbind() const {
|
||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
inline void VertexBufferObject::dispose() {
|
||||
OPENGL_EXTRA_FUNCTIONS->glDeleteBuffers(1, &_id);
|
||||
_id = 0;
|
||||
}
|
||||
|
||||
inline void VertexBufferObject::ensureInitialized() {
|
||||
if (_id == 0) {
|
||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user