src/gl/compiler.cpp

changeset 39
caac957e9834
parent 37
90443fb328ea
child 43
08dc62e03a6d
equal deleted inserted replaced
38:bb60dda3093f 39:caac957e9834
141 } 141 }
142 this->initialized = true; 142 this->initialized = true;
143 } 143 }
144 } 144 }
145 145
146 void gl::Compiler::build(Model* model, DocumentManager* context) 146 void gl::Compiler::build(Model* model, DocumentManager* context, const gl::RenderPreferences& preferences)
147 { 147 {
148 this->boundingBox = {}; 148 this->boundingBox = {};
149 std::vector<gl::Vertex> vboData[gl::NUM_ARRAY_CLASSES]; 149 std::vector<gl::Vertex> vboData[gl::NUM_ARRAY_CLASSES];
150 const std::vector<gl::Polygon> polygons = model->getPolygons(context); 150 const std::vector<gl::Polygon> polygons = model->getPolygons(context);
151 for (const gl::Polygon& polygon : polygons) 151 for (const gl::Polygon& polygon : polygons)
152 { 152 {
153 this->buildPolygon(polygon, vboData); 153 this->buildPolygon(polygon, vboData, preferences);
154 } 154 }
155 for (int arrayId = 0; arrayId < gl::NUM_ARRAY_CLASSES; arrayId += 1) 155 for (int arrayId = 0; arrayId < gl::NUM_ARRAY_CLASSES; arrayId += 1)
156 { 156 {
157 auto& buffer = this->glObjects[arrayId].buffer; 157 auto& buffer = this->glObjects[arrayId].buffer;
158 auto& vector = vboData[arrayId]; 158 auto& vector = vboData[arrayId];
188 const int g = (id.value / 0x100) % 0x100; 188 const int g = (id.value / 0x100) % 0x100;
189 const int b = id.value % 0x100; 189 const int b = id.value % 0x100;
190 return {r, g, b}; 190 return {r, g, b};
191 } 191 }
192 192
193 void gl::Compiler::buildPolygon(gl::Polygon polygon, std::vector<gl::Vertex>* vboData) 193 void gl::Compiler::buildPolygon(
194 gl::Polygon polygon,
195 std::vector<gl::Vertex>* vboData,
196 const gl::RenderPreferences& preferences)
194 { 197 {
195 const gl::ArrayClass vboClass = classifyPolygon(polygon); 198 const gl::ArrayClass vboClass = classifyPolygon(polygon);
196 std::vector<gl::Vertex>& vertexBuffer = vboData[static_cast<int>(vboClass)]; 199 std::vector<gl::Vertex>& vertexBuffer = vboData[static_cast<int>(vboClass)];
197 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); 200 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices());
198 reserveMore(vertexBuffer, polygon.numPolygonVertices()); 201 reserveMore(vertexBuffer, polygon.numPolygonVertices());
199 const QColor color = this->getColorForPolygon(polygon); 202 const QColor color = this->getColorForPolygon(polygon, preferences);
200 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) 203 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
201 { 204 {
202 const glm::vec3& v1 = vertexRing[i - 1]; 205 const glm::vec3& v1 = vertexRing[i - 1];
203 const glm::vec3& v2 = vertexRing[i]; 206 const glm::vec3& v2 = vertexRing[i];
204 const glm::vec3& v3 = vertexRing[i + 1]; 207 const glm::vec3& v3 = vertexRing[i + 1];
208 vertex.normal = glm::normalize(glm::cross(v1 - v2, v3 - v2)); 211 vertex.normal = glm::normalize(glm::cross(v1 - v2, v3 - v2));
209 vertex.color = glm::vec4{color.redF(), color.greenF(), color.blueF(), color.alphaF()}; 212 vertex.color = glm::vec4{color.redF(), color.greenF(), color.blueF(), color.alphaF()};
210 } 213 }
211 } 214 }
212 215
213 QColor gl::Compiler::getColorForPolygon(const gl::Polygon& polygon) 216 QColor gl::Compiler::getColorForPolygon(const gl::Polygon& polygon, const gl::RenderPreferences& preferences)
214 { 217 {
215 QColor color; 218 QColor color;
216 // For normal colors, use the polygon's color. 219 // For normal colors, use the polygon's color.
217 if (polygon.color == ldraw::mainColor) 220 if (polygon.color == ldraw::mainColor)
218 { 221 {
219 color = {255, 255, 64}; // mainColorRepresentation(); 222 color = preferences.mainColor;
220 } 223 }
221 else if (polygon.color == ldraw::edgeColor) 224 else if (polygon.color == ldraw::edgeColor)
222 { 225 {
223 // Edge color is black, unless we have a dark background, in which case lines need to be bright. 226 // Edge color is black, unless we have a dark background, in which case lines need to be bright.
224 color = Qt::black; //luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white; 227 color = Qt::black; //luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white;

mercurial