src/gl/compiler.h

changeset 80
764381756899
parent 78
97c3ce5aa498
child 150
b6cbba6e29a1
equal deleted inserted replaced
79:5fe2dd4e161a 80:764381756899
32 class DocumentManager; 32 class DocumentManager;
33 33
34 namespace gl 34 namespace gl
35 { 35 {
36 class Compiler; 36 class Compiler;
37
38 struct Vertex
39 {
40 glm::vec3 position;
41 glm::vec4 color;
42 glm::vec3 normal;
43 glm::int32 id;
44 glm::int32 selected = 0;
45 };
46 } 37 }
47 38
48 class gl::Compiler : public QObject, protected QOpenGLExtraFunctions 39 class gl::Compiler : public QObject, protected QOpenGLExtraFunctions
49 { 40 {
50 Q_OBJECT 41 Q_OBJECT
51 public: 42 public:
52 Compiler(const ldraw::ColorTable& colorTable, QObject* parent); 43 Compiler(const ldraw::ColorTable& colorTable, QObject* parent);
53 ~Compiler(); 44 ~Compiler();
54 void build(Model* model, DocumentManager* context, const RenderPreferences& preferences); 45 void build(Model* model, DocumentManager* context, const RenderPreferences& preferences);
55 void buildPolygon(Polygon polygon, std::vector<Vertex>* vboData, const gl::RenderPreferences& preferences);
56 std::size_t vertexCount(gl::ArrayClass arrayClass) const; 46 std::size_t vertexCount(gl::ArrayClass arrayClass) const;
57 QColor getColorForPolygon(const gl::Polygon& polygon, const RenderPreferences& preferences); 47 QColor getColorForPolygon(const gl::Polygon& polygon, const RenderPreferences& preferences);
58 glm::vec3 modelCenter() const; 48 glm::vec3 modelCenter() const;
59 double modelDistance() const; 49 double modelDistance() const;
60 void initialize(); 50 void initialize();
84 { 74 {
85 const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value)); 75 const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value));
86 this->setUniform(uniformName, *array); 76 this->setUniform(uniformName, *array);
87 } 77 }
88 private: 78 private:
89 std::size_t storedVertexCounts[gl::NUM_ARRAY_CLASSES] = {0_z}; 79 struct Vertex
80 {
81 glm::vec3 position;
82 glm::vec4 color;
83 glm::vec3 normal;
84 glm::int32 id;
85 glm::int32 selected = 0;
86 };
87 void buildPolygon(Polygon polygon, std::vector<Vertex>* vboData, const gl::RenderPreferences& preferences);
88 std::size_t storedVertexCounts[gl::NUM_POLYGON_TYPES] = {0};
90 bool initialized = false; 89 bool initialized = false;
91 BoundingBox boundingBox; 90 BoundingBox boundingBox;
92 const ldraw::ColorTable& colorTable; 91 const ldraw::ColorTable& colorTable;
93 ldraw::id_t hovered = ldraw::NULL_ID; 92 ldraw::id_t hovered = ldraw::NULL_ID;
94 struct 93 struct
95 { 94 {
96 QOpenGLShaderProgram* program = nullptr; 95 QOpenGLShaderProgram* program = nullptr;
97 QOpenGLShaderProgram* pickSceneProgram = nullptr; 96 QOpenGLShaderProgram* pickSceneProgram = nullptr;
98 QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer}; 97 QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer};
99 QOpenGLVertexArrayObject vertexArray; 98 QOpenGLVertexArrayObject vertexArray;
100 std::vector<gl::Vertex> cachedData; 99 std::vector<Vertex> cachedData;
101 } glObjects[gl::NUM_ARRAY_CLASSES]; 100 } glObjects[gl::NUM_POLYGON_TYPES];
102 }; 101 };
103 102
104 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); } 103 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }
105 void checkGLError (QString file, int line); 104 void checkGLError (QString file, int line);

mercurial