Sat, 01 Feb 2020 15:33:57 +0200
wired renderstyle up
19  1  /* 
2  * LDForge: LDraw parts authoring CAD  
3  * Copyright (C) 2013  2018 Teemu Piippo  
4  *  
5  * This program is free software: you can redistribute it and/or modify  
6  * it under the terms of the GNU General Public License as published by  
7  * the Free Software Foundation, either version 3 of the License, or  
8  * (at your option) any later version.  
9  *  
10  * This program is distributed in the hope that it will be useful,  
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13  * GNU General Public License for more details.  
14  *  
15  * You should have received a copy of the GNU General Public License  
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.  
17  */  
18  
19  #pragma once  
20  #include <QColor>  
21  #include <QOpenGLFunctions>  
22  #include <QGenericMatrix>  
23  #include "basics.h"  
24  #include "colors.h"  
25  
26  namespace gl  
27  {  
28  // Transformation matrices for projection cameras.  
29  static const QMatrix4x4 topCameraMatrix = {};  
30  static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1};  
31  static const QMatrix4x4 leftCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1};  
32  static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};  
33  static const QMatrix4x4 backCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1};  
34  static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1};  
35  static constexpr QRgb BlackRgb = 0xff000000;  
36  struct Polygon;  
37  }  
38  
39  struct gl::Polygon  
40  {  
41  enum Type : qint8  
42  {  
43  EdgeLine,  
44  Triangle,  
45  Quadrilateral,  
46  ConditionalEdge  
47  };  
48  Type type;  
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

49  glm::vec3 vertices[4]; 
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

50  ldraw::Color color; 
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

51  ldraw::Id id; 
19  52  
53  /**  
54  * @return amount of vertices used for geometry  
55  */  
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset

56  inline unsigned int numPolygonVertices() const 
19  57  { 
58  if (type == Type::ConditionalEdge)  
59  return 2;  
60  else  
61  return numVertices();  
62  }  
63  
64  /**  
65  * @return amount of vertices  
66  */  
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset

67  inline unsigned int numVertices() const 
19  68  { 
69  switch (type)  
70  {  
71  case Type::EdgeLine:  
72  return 2;  
73  case Type::Triangle:  
74  return 3;  
75  case Type::ConditionalEdge:  
76  case Type::Quadrilateral:  
77  return 4;  
78  }  
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset

79  return 0; 
19  80  } 
81  };  
82  
83  Q_DECLARE_METATYPE(gl::Polygon)  
84  
85  namespace gl  
86  {  
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

87  inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, ldraw::Color color, ldraw::Id id) 
19  88  { 
21  89  return {Polygon::EdgeLine, {v_1, v_2}, color, id}; 
19  90  } 
91  
21  92  inline Polygon triangle( 
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

93  const glm::vec3& v_1, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

94  const glm::vec3& v_2, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

95  const glm::vec3& v_3, 
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

96  ldraw::Color color, 
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

97  ldraw::Id id) 
19  98  { 
21  99  return {Polygon::Triangle, {v_1, v_2, v_3}, color, id}; 
19  100  } 
101  
102  inline Polygon quadrilateral(  
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

103  const glm::vec3& v_1, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

104  const glm::vec3& v_2, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

105  const glm::vec3& v_3, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

106  const glm::vec3& v_4, 
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

107  ldraw::Color color, 
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

108  ldraw::Id id) 
19  109  { 
21  110  return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id}; 
19  111  } 
112  
113  inline Polygon conditionalEdge(  
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

114  const glm::vec3& v_1, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

115  const glm::vec3& v_2, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

116  const glm::vec3& control_1, 
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset

117  const glm::vec3& control_2, 
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

118  ldraw::Color color, 
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

119  ldraw::Id id) 
19  120  { 
21  121  return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id}; 
19  122  } 
123  
124  // Vbo names  
26  125  enum class ArrayClass : std::uint8_t 
19  126  { 
127  Lines,  
128  Triangles,  
129  Quads,  
130  ConditionalLines  
131  };  
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset

132  
26  133  constexpr ArrayClass ARRAY_CLASSES[] = {ArrayClass::Lines, ArrayClass::Triangles, ArrayClass::Quads, ArrayClass::ConditionalLines}; 
134  constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES);  
135  constexpr int FLOATS_PER_VERTEX = 7;  
19  136  
137  enum class RenderStyle  
138  {  
139  Normal,  
140  Wireframe,  
141  BfcRedGreen,  
142  RandomColors  
143  };  
37  144  
145  // These are also defined in shaders  
146  enum class FragmentStyle  
147  {  
148  Normal = 0,  
149  BfcGreen = 1,  
150  BfcRed = 2,  
151  RandomColors = 3,  
152  };  
19  153  } 