KlassischeKeplerKriege/game/renderer_polygon_3d/polygon_model.hpp

69 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
#include <string>
2016-09-29 10:00:08 +00:00
#include <vector>
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
#include <epoxy/gl.h>
#include <epoxy/glx.h>
2016-09-29 09:38:26 +00:00
#include "glclasses.hpp"
// TODO: hide assimp inside
// and enable/disable
// to use own binary format without assimp for speed/compatibiblity
// TODO: add lod-options
// TODO: add generate from openscad options if models missing
namespace endofthejedi {
class PolygonModel {
public:
2016-09-29 09:38:26 +00:00
PolygonModel(const std::string &filename);
2016-09-29 06:28:56 +00:00
2016-09-29 11:11:01 +00:00
// (re) load data from file
2016-09-29 09:38:26 +00:00
bool import();
2016-09-29 06:28:56 +00:00
2016-09-29 11:11:01 +00:00
// connect stuff with the shader for rendering
// supply the current shader that should be used for this model.
// when it recompiles, call setup() again.
void setup(Shader *shader);
// upload model data to GPU
2016-09-29 09:38:26 +00:00
bool uploadToOpenGl();
2016-09-29 11:11:01 +00:00
// call bind before rendering
bool bind();
// call to render
bool render();
// clear everything and delete data
void clear();
private:
2016-09-29 09:38:26 +00:00
bool copyVertices(const aiScene *scene);
const std::string &filename() const { return m_filename; }
private:
std::string m_filename;
bool m_loaded_from_file;
bool m_loaded_to_opengl;
bool m_binding_active;
// both will hold 3 * numVertices floats
std::vector<float> m_data_position;
std::vector<float> m_data_normal;
size_t m_numVertices;
2016-09-29 11:11:01 +00:00
// TODO: watch for shader recompile
GLint m_attr_locations[2];
GLuint m_vbo_id[2];
Shader *m_shader;
};
}