2016-12-09 14:56:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include <QOpenGLWidget>
|
|
|
|
#include <QOpenGLFunctions>
|
2016-12-10 13:42:00 +00:00
|
|
|
#include <QOpenGLBuffer>
|
|
|
|
#include <QOPenGLVertexArrayObject>
|
|
|
|
#include <QOpenGlShaderProgram>
|
2016-12-14 16:20:20 +00:00
|
|
|
#include "..\Header\Texture.h"
|
2016-12-12 15:47:38 +00:00
|
|
|
#include "..\Header\FileInterface.h"
|
2016-12-11 16:46:22 +00:00
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
GLfloat position[3];
|
|
|
|
GLfloat uv[2];
|
|
|
|
};
|
|
|
|
|
2016-12-14 16:20:20 +00:00
|
|
|
struct TextureData {
|
|
|
|
bool alpha;
|
|
|
|
std::uint32_t width;
|
|
|
|
std::uint32_t height;
|
|
|
|
std::vector<std::uint8_t>* data;
|
|
|
|
};
|
|
|
|
|
2016-12-09 14:56:45 +00:00
|
|
|
class OpenGlViewer : public QOpenGLWidget, protected QOpenGLFunctions
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenGlViewer(QWidget *parent);
|
|
|
|
~OpenGlViewer();
|
|
|
|
|
2016-12-10 13:42:00 +00:00
|
|
|
private:
|
2016-12-11 16:46:22 +00:00
|
|
|
// OpenGL ======================================
|
2016-12-12 11:38:13 +00:00
|
|
|
int m_uniformMVP;
|
2016-12-14 16:20:20 +00:00
|
|
|
GLuint m_oglTexture;
|
|
|
|
GLuint m_vertexBuffer;
|
2016-12-11 16:46:22 +00:00
|
|
|
QOpenGLVertexArrayObject m_vertexArray;
|
|
|
|
QOpenGLShaderProgram* m_program = nullptr;
|
2016-12-10 13:42:00 +00:00
|
|
|
|
2016-12-11 16:46:22 +00:00
|
|
|
// Data ========================================
|
2016-12-12 15:47:38 +00:00
|
|
|
std::vector<Model*>* m_vModels = nullptr;
|
2016-12-14 16:20:20 +00:00
|
|
|
std::vector<TextureData*>* m_vTextures = nullptr;
|
2016-12-11 16:46:22 +00:00
|
|
|
BoundingBox m_sceneBoundings;
|
|
|
|
|
|
|
|
// Transformation ==============================
|
|
|
|
float m_fRotX = 0;
|
|
|
|
float m_fRotY = 0;
|
|
|
|
float m_fRotZ = 0;
|
|
|
|
float m_fTranX = 0;
|
|
|
|
float m_fTranY = 0;
|
|
|
|
float m_fTranZ = 0;
|
|
|
|
|
|
|
|
// Camera ======================================
|
|
|
|
float m_fFOV = 45.0f;
|
|
|
|
float m_fMinView = 0.1f;
|
|
|
|
float m_fMaxView = 100.0f;
|
2016-12-10 13:42:00 +00:00
|
|
|
|
2016-12-11 16:46:22 +00:00
|
|
|
private:
|
2016-12-09 14:56:45 +00:00
|
|
|
virtual void initializeGL() override final;
|
|
|
|
virtual void paintGL() override final;
|
2016-12-10 13:42:00 +00:00
|
|
|
|
2016-12-11 16:46:22 +00:00
|
|
|
void printContextInformation();
|
2016-12-12 15:47:38 +00:00
|
|
|
QMatrix4x4 getModelMatrix(unsigned int index) const;
|
2016-12-12 11:38:13 +00:00
|
|
|
QMatrix4x4 getMVPMatrix(unsigned int index) const;
|
2016-12-11 16:46:22 +00:00
|
|
|
void deleteData();
|
|
|
|
|
2016-12-10 13:42:00 +00:00
|
|
|
public:
|
2016-12-14 16:20:20 +00:00
|
|
|
void setData(std::vector<Model*>* models, std::vector<TextureData*>* textures, BoundingBox bbox);
|
2016-12-09 14:56:45 +00:00
|
|
|
};
|