qtk/src/object.h

144 lines
4.7 KiB
C
Raw Normal View History

2021-09-03 16:56:57 +00:00
/*##############################################################################
## Author: Shaun Reed ##
2022-03-06 16:54:05 +00:00
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
2021-09-03 16:56:57 +00:00
## About: Object class for storing object data ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#ifndef QTK_OBJECT_H
#define QTK_OBJECT_H
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <mesh.h>
#include <qtkapi.h>
2022-11-24 22:26:53 +00:00
#include <texture.h>
namespace Qtk {
2022-11-25 19:36:12 +00:00
/**
* Object base class for objects that can exist within a scene.
* An object could be a Cube, Skybox, 3D Model, or other standalone entities.
*/
class QTKAPI Object : public QObject {
2022-11-24 22:26:53 +00:00
Q_OBJECT
public:
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Typedefs
************************************************************************/
2022-11-24 22:26:53 +00:00
friend MeshRenderer;
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Constructors / Destructors
************************************************************************/
2022-11-24 22:26:53 +00:00
// Initialize an object with no shape data assigned
explicit Object(const char * name) :
mName(name), mVBO(QOpenGLBuffer::VertexBuffer), mBound(false) {}
// Initialize an object with shape data assigned
Object(const char * name, const ShapeBase & shape) :
mName(name), mVBO(QOpenGLBuffer::VertexBuffer), mShape(shape),
mBound(false) {}
~Object() override = default;
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Accessors
************************************************************************/
2022-11-24 22:26:53 +00:00
inline const Colors & getColors() { return mShape.mColors; }
inline const Indices & getIndexData() { return mShape.mIndices; }
inline const Normals & getNormals() { return mShape.mNormals; }
[[nodiscard]] inline const Shape & getShape() const { return mShape; }
inline const TexCoords & getTexCoords() { return mShape.mTexCoords; }
inline Texture & getTexture() { return mTexture; }
inline const Vertices & getVertices() { return mShape.mVertices; }
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Setters
************************************************************************/
2022-11-24 22:26:53 +00:00
virtual inline void setColors(const Colors & value) {
mShape.mColors = value;
}
virtual inline void setIndices(const Indices & value) {
mShape.mIndices = value;
}
virtual inline void setNormals(const Normals & value) {
mShape.mNormals = value;
}
virtual inline void setShape(const Shape & value) { mShape = value; }
virtual inline void setTexCoords(const TexCoords & value) {
mShape.mTexCoords = value;
}
virtual inline void setTexture(
const char * path, bool flipX = false, bool flipY = false) {
mTexture.setTexture(path, flipX, flipY);
}
virtual inline void setCubeMap(const char * path) {
mTexture.setCubeMap(path);
}
virtual inline void setTexture(const Texture & t) {
mTexture.setTexture(t.getPath());
}
virtual inline void setVertices(const Vertices & value) {
mShape.mVertices = value;
}
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Public Methods
************************************************************************/
2022-11-24 22:26:53 +00:00
virtual inline void bindShaders() {
mBound = true;
mProgram.bind();
}
virtual inline void releaseShaders() {
mBound = false;
mProgram.release();
}
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Public Members
************************************************************************/
2022-11-24 22:26:53 +00:00
QOpenGLBuffer mVBO, mNBO;
QOpenGLVertexArrayObject mVAO;
Transform3D mTransform;
Shape mShape;
Texture mTexture;
const char * mName;
bool mBound;
private:
2022-11-25 19:36:12 +00:00
/*************************************************************************
* Private Members
************************************************************************/
2022-11-24 22:26:53 +00:00
QOpenGLShaderProgram mProgram;
};
2022-11-24 22:26:53 +00:00
} // namespace Qtk
2021-09-03 16:56:57 +00:00
2022-11-24 22:26:53 +00:00
#endif // QTK_OBJECT_H