mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-18 16:08:11 +08:00
modify model to add LOADED status
This commit is contained in:
commit
59c4b24a98
3
.gitignore
vendored
3
.gitignore
vendored
@ -360,4 +360,5 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
/FinalProject/temp/shaders
|
||||||
|
|||||||
@ -157,10 +157,10 @@
|
|||||||
</QtMoc>
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="vertexshader.vs">
|
<None Include="fragmentshader.fs">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="fragmentshader.fs">
|
<None Include="vertexshader.vs">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -1,33 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ebo.h"
|
#include "ebo.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
ElementBufferObject::ElementBufferObject() {
|
ElementBufferObject::ElementBufferObject() {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementBufferObject::ElementBufferObject(const std::vector<unsigned int>& indices) :
|
ElementBufferObject::ElementBufferObject(const std::vector<unsigned int>& indices) {
|
||||||
_indices(indices) {
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||||
GL_ELEMENT_ARRAY_BUFFER,
|
GL_ELEMENT_ARRAY_BUFFER,
|
||||||
_indices.size() * sizeof(unsigned int),
|
indices.size() * sizeof(unsigned int),
|
||||||
_indices.data(),
|
indices.data(),
|
||||||
GL_STATIC_DRAW
|
GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementBufferObject::ElementBufferObject(std::vector<unsigned int>&& indices) :
|
void ElementBufferObject::setBuffer(const std::vector<unsigned int>& indices) {
|
||||||
_indices(std::move(indices)) {
|
if (_id == 0) {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
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->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||||
GL_ELEMENT_ARRAY_BUFFER,
|
GL_ELEMENT_ARRAY_BUFFER,
|
||||||
_indices.size() * sizeof(unsigned int),
|
indices.size() * sizeof(unsigned int),
|
||||||
_indices.data(),
|
indices.data(),
|
||||||
GL_STATIC_DRAW
|
GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
@ -6,21 +6,49 @@
|
|||||||
|
|
||||||
class ElementBufferObject
|
class ElementBufferObject
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
static ElementBufferObject empty() {
|
||||||
|
return ElementBufferObject();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _id = 0;
|
unsigned int _id = 0;
|
||||||
std::vector<unsigned int> _indices;
|
|
||||||
|
private:
|
||||||
|
ElementBufferObject();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementBufferObject();
|
|
||||||
ElementBufferObject(const std::vector<unsigned int>& indices);
|
ElementBufferObject(const std::vector<unsigned int>& indices);
|
||||||
ElementBufferObject(std::vector<unsigned int>&& indices);
|
|
||||||
|
|
||||||
inline unsigned int id() const { return _id; }
|
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);
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "qdebug.h"
|
#include <qdebug.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="MainWindow">
|
<qresource prefix="/shaders">
|
||||||
|
<file>fragmentshader.fs</file>
|
||||||
|
<file>vertexshader.vs</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <qresource.h>
|
||||||
|
#include <qurl.h>
|
||||||
|
#include <qdir.h>
|
||||||
|
|
||||||
#include "vbo.h"
|
#include "vbo.h"
|
||||||
#include "vao.h"
|
#include "vao.h"
|
||||||
@ -18,6 +21,16 @@ SceneViewer::SceneViewer(QWidget* parent)
|
|||||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||||
format.setVersion(4, 3);
|
format.setVersion(4, 3);
|
||||||
setFormat(format);
|
setFormat(format);
|
||||||
|
|
||||||
|
// Create a folder
|
||||||
|
QDir dir("./temp/shaders");
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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() {
|
SceneViewer::~SceneViewer() {
|
||||||
@ -31,6 +44,17 @@ void SceneViewer::initializeGL() {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
Logger::info("Currently running on OpenGL version: " + std::string((const char*)glGetString(GL_VERSION)));
|
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) {
|
void SceneViewer::resizeGL(int w, int h) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "shader.h"
|
||||||
#include "renderable.h"
|
#include "renderable.h"
|
||||||
#include "vao.h"
|
#include "vao.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -16,6 +17,8 @@ class SceneViewer : public QOpenGLWidget, protected QOpenGLFunctions
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Renderable> _objects;
|
std::vector<Renderable> _objects;
|
||||||
|
ShaderProgram _shaderProgram = ShaderProgram::empty();
|
||||||
|
VertexArrayObject _vao = VertexArrayObject::empty();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SceneViewer(QWidget* parent = 0);
|
SceneViewer(QWidget* parent = 0);
|
||||||
|
|||||||
@ -102,7 +102,7 @@ void GeometryShader::compile(const std::string& source) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderProgram::ShaderProgram() {
|
ShaderProgram::ShaderProgram() {
|
||||||
_programId = OPENGL_EXTRA_FUNCTIONS->glCreateProgram();
|
_programId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderProgram::ShaderProgram(VertexShader vertexShader) {
|
ShaderProgram::ShaderProgram(VertexShader vertexShader) {
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
protected:
|
protected:
|
||||||
unsigned int _shaderId = -1;
|
unsigned int _shaderId = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Shader() {}
|
Shader() {}
|
||||||
@ -27,7 +27,6 @@ inline void Shader::dispose() {
|
|||||||
|
|
||||||
class VertexShader : public Shader {
|
class VertexShader : public Shader {
|
||||||
public:
|
public:
|
||||||
VertexShader() {}
|
|
||||||
VertexShader(const std::string& sourceFilePath);
|
VertexShader(const std::string& sourceFilePath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -36,7 +35,6 @@ protected:
|
|||||||
|
|
||||||
class FragmentShader : public Shader {
|
class FragmentShader : public Shader {
|
||||||
public:
|
public:
|
||||||
FragmentShader() {}
|
|
||||||
FragmentShader(const std::string& sourceFilePath);
|
FragmentShader(const std::string& sourceFilePath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -45,7 +43,6 @@ protected:
|
|||||||
|
|
||||||
class GeometryShader : public Shader {
|
class GeometryShader : public Shader {
|
||||||
public:
|
public:
|
||||||
GeometryShader() {}
|
|
||||||
GeometryShader(const std::string& sourceFilePath);
|
GeometryShader(const std::string& sourceFilePath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -53,11 +50,18 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class ShaderProgram {
|
class ShaderProgram {
|
||||||
|
public:
|
||||||
|
static ShaderProgram empty() {
|
||||||
|
return ShaderProgram();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _programId = 0;
|
unsigned int _programId = 0;
|
||||||
|
|
||||||
public:
|
private:
|
||||||
ShaderProgram();
|
ShaderProgram();
|
||||||
|
|
||||||
|
public:
|
||||||
ShaderProgram(VertexShader vertexShader);
|
ShaderProgram(VertexShader vertexShader);
|
||||||
ShaderProgram(FragmentShader fragmentShader);
|
ShaderProgram(FragmentShader fragmentShader);
|
||||||
ShaderProgram(GeometryShader geometryShader);
|
ShaderProgram(GeometryShader geometryShader);
|
||||||
@ -67,19 +71,33 @@ public:
|
|||||||
ShaderProgram(VertexShader vertexShader, FragmentShader fragmentShader, GeometryShader geometryShader);
|
ShaderProgram(VertexShader vertexShader, FragmentShader fragmentShader, GeometryShader geometryShader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void setActive();
|
|
||||||
inline void setInactive();
|
|
||||||
|
|
||||||
inline unsigned int programId() const { return _programId; }
|
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 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);
|
OPENGL_EXTRA_FUNCTIONS->glUseProgram(_programId);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ShaderProgram::setInactive() {
|
inline void ShaderProgram::unbind() const {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glUseProgram(0);
|
OPENGL_EXTRA_FUNCTIONS->glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,3 +105,9 @@ inline void ShaderProgram::dispose() {
|
|||||||
OPENGL_EXTRA_FUNCTIONS->glDeleteProgram(_programId);
|
OPENGL_EXTRA_FUNCTIONS->glDeleteProgram(_programId);
|
||||||
_programId = 0;
|
_programId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void ShaderProgram::ensureInitialized() {
|
||||||
|
if (_programId == 0) {
|
||||||
|
_programId = OPENGL_EXTRA_FUNCTIONS->glCreateProgram();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -3,39 +3,20 @@
|
|||||||
#include "vao.h"
|
#include "vao.h"
|
||||||
|
|
||||||
VertexArrayObject::VertexArrayObject() {
|
VertexArrayObject::VertexArrayObject() {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo) :
|
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo) {
|
||||||
_vbo(vbo) {
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_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);
|
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexArrayObject::VertexArrayObject(VertexBufferObject&& vbo) :
|
VertexArrayObject::VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo) {
|
||||||
_vbo(std::move(vbo)) {
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_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);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo.id());
|
||||||
}
|
|
||||||
|
|
||||||
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->glBindVertexArray(0);
|
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
@ -8,27 +8,30 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
class VertexArrayObject {
|
class VertexArrayObject {
|
||||||
|
public:
|
||||||
|
static VertexArrayObject empty() {
|
||||||
|
return VertexArrayObject();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _id = 0;
|
unsigned int _id = 0;
|
||||||
VertexBufferObject _vbo;
|
|
||||||
ElementBufferObject _ebo;
|
private:
|
||||||
|
VertexArrayObject();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VertexArrayObject();
|
|
||||||
VertexArrayObject(const VertexBufferObject& vbo);
|
VertexArrayObject(const VertexBufferObject& vbo);
|
||||||
VertexArrayObject(VertexBufferObject&& vbo);
|
|
||||||
VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo);
|
VertexArrayObject(const VertexBufferObject& vbo, const ElementBufferObject& ebo);
|
||||||
VertexArrayObject(VertexBufferObject&& vbo, ElementBufferObject&& ebo);
|
|
||||||
|
|
||||||
inline unsigned int id() const { return _id; }
|
inline unsigned int id() const { return _id; }
|
||||||
|
|
||||||
inline void bind() const;
|
inline void bind() const;
|
||||||
inline void unbind() const;
|
inline void unbind() const;
|
||||||
|
inline void dispose();
|
||||||
|
inline void ensureInitialized();
|
||||||
|
|
||||||
inline void bindVertexBufferObject(const VertexBufferObject& vbo);
|
inline void bindVertexBufferObject(const VertexBufferObject& vbo);
|
||||||
inline void bindVertexBufferObject(VertexBufferObject&& vbo);
|
|
||||||
inline void bindElementBufferObject(const ElementBufferObject& ebo);
|
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 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;
|
inline void enableVertexAttribute(unsigned int index) const;
|
||||||
@ -37,7 +40,7 @@ public:
|
|||||||
|
|
||||||
inline void VertexArrayObject::bind() const {
|
inline void VertexArrayObject::bind() const {
|
||||||
// Check is id is valid
|
// Check is id is valid
|
||||||
if (_id == -1) {
|
if (_id == 0) {
|
||||||
Logger::error("Binding an invalid VertexArrayObject");
|
Logger::error("Binding an invalid VertexArrayObject");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -48,31 +51,26 @@ inline void VertexArrayObject::unbind() const {
|
|||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void VertexArrayObject::bindVertexBufferObject(const VertexBufferObject& vbo) {
|
inline void VertexArrayObject::dispose() {
|
||||||
_vbo = vbo;
|
OPENGL_EXTRA_FUNCTIONS->glDeleteVertexArrays(1, &_id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
_id = 0;
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _vbo.id());
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void VertexArrayObject::bindVertexBufferObject(VertexBufferObject&& vbo) {
|
inline void VertexArrayObject::ensureInitialized() {
|
||||||
_vbo = std::move(vbo);
|
if (_id == 0) {
|
||||||
|
OPENGL_EXTRA_FUNCTIONS->glGenVertexArrays(1, &_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VertexArrayObject::bindVertexBufferObject(const VertexBufferObject& vbo) {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_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);
|
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void VertexArrayObject::bindElementBufferObject(const ElementBufferObject& ebo) {
|
inline void VertexArrayObject::bindElementBufferObject(const ElementBufferObject& ebo) {
|
||||||
_ebo = ebo;
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(_id);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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->glBindVertexArray(0);
|
OPENGL_EXTRA_FUNCTIONS->glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,33 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "vbo.h"
|
#include "vbo.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
VertexBufferObject::VertexBufferObject() {
|
VertexBufferObject::VertexBufferObject() {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBufferObject::VertexBufferObject(const std::vector<Vertex>& vertices) :
|
VertexBufferObject::VertexBufferObject(const std::vector<Vertex>& vertices) {
|
||||||
_vertices(vertices) {
|
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
_vertices.size() * sizeof(Vertex),
|
vertices.size() * sizeof(Vertex),
|
||||||
_vertices.data(),
|
vertices.data(),
|
||||||
GL_STATIC_DRAW
|
GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBufferObject::VertexBufferObject(std::vector<Vertex>&& vertices) :
|
void VertexBufferObject::setBuffer(const std::vector<Vertex>& vertices) {
|
||||||
_vertices(std::move(vertices)) {
|
if (id == 0) {
|
||||||
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
Logger::error("Try to bind buffer to an uninitialized vertex buffer object");
|
||||||
|
return;
|
||||||
|
}
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, _id);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
OPENGL_EXTRA_FUNCTIONS->glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
_vertices.size() * sizeof(Vertex),
|
vertices.size() * sizeof(Vertex),
|
||||||
_vertices.data(),
|
vertices.data(),
|
||||||
GL_STATIC_DRAW
|
GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
OPENGL_EXTRA_FUNCTIONS->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
@ -6,21 +6,49 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
class VertexBufferObject {
|
class VertexBufferObject {
|
||||||
|
public:
|
||||||
|
static VertexBufferObject empty() {
|
||||||
|
return VertexBufferObject();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _id = 0;
|
unsigned int _id = 0;
|
||||||
std::vector<Vertex> _vertices;
|
|
||||||
|
|
||||||
public:
|
private:
|
||||||
VertexBufferObject();
|
VertexBufferObject();
|
||||||
|
|
||||||
|
public:
|
||||||
VertexBufferObject(const std::vector<Vertex>& vertices);
|
VertexBufferObject(const std::vector<Vertex>& vertices);
|
||||||
VertexBufferObject(std::vector<Vertex>&& vertices);
|
|
||||||
|
|
||||||
inline unsigned int id() const { return _id; }
|
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);
|
OPENGL_EXTRA_FUNCTIONS->glDeleteBuffers(1, &_id);
|
||||||
|
_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VertexBufferObject::ensureInitialized() {
|
||||||
|
if (_id == 0) {
|
||||||
|
OPENGL_EXTRA_FUNCTIONS->glGenBuffers(1, &_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BIN
Models/backpack/ao.jpg
Normal file
BIN
Models/backpack/ao.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
16
Models/backpack/backpack.mtl
Normal file
16
Models/backpack/backpack.mtl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Scene_-_Root
|
||||||
|
Ns 225.000000
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.800000 0.800000 0.800000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.0 0.0 0.0
|
||||||
|
Ni 1.450000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd diffuse.jpg
|
||||||
|
map_Bump normal.png
|
||||||
|
map_Ks specular.jpg
|
||||||
|
|
||||||
BIN
Models/backpack/diffuse.jpg
Normal file
BIN
Models/backpack/diffuse.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.8 MiB |
BIN
Models/backpack/normal.png
Normal file
BIN
Models/backpack/normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 MiB |
BIN
Models/backpack/roughness.jpg
Normal file
BIN
Models/backpack/roughness.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 MiB |
3
Models/backpack/source_attribution.txt
Normal file
3
Models/backpack/source_attribution.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Model by Berk Gedik, from: https://sketchfab.com/3d-models/survival-guitar-backpack-low-poly-799f8c4511f84fab8c3f12887f7e6b36
|
||||||
|
|
||||||
|
Modified material assignment (Joey de Vries) for easier load in OpenGL model loading chapter, and renamed albedo to diffuse and metallic to specular to match non-PBR lighting setup.
|
||||||
BIN
Models/backpack/specular.jpg
Normal file
BIN
Models/backpack/specular.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 MiB |
Loading…
x
Reference in New Issue
Block a user