diff -r 0133e565e072 -r 6da867fa5429 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Wed Jan 01 17:45:56 2020 +0200 +++ b/src/gl/compiler.cpp Sun Jan 19 02:54:48 2020 +0200 @@ -40,6 +40,7 @@ { this->initializeVbo(); } + this->boundingBox = {}; std::vector vboData[gl::numVbos]; const std::vector polygons = model->getPolygons(context); for (const gl::Polygon& polygon : polygons) @@ -80,9 +81,9 @@ void writeVertex(std::vector& data, const Point3D& point) { - data.push_back(point.x); - data.push_back(point.y); - data.push_back(point.z); + data.push_back(static_cast(point.x)); + data.push_back(static_cast(point.y)); + data.push_back(static_cast(point.z)); } void gl::Compiler::buildPolygon(gl::Polygon polygon, std::vector* vboData) @@ -93,7 +94,7 @@ return vboData[gl::vboIndex({vboClass, subclass})]; }; auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); - for (int i = 0; i < polygon.numPolygonVertices(); i += 1) + for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) { const Point3D& v1 = vertexRing[i - 1]; const Point3D& v2 = vertexRing[i]; @@ -105,18 +106,11 @@ } vboBuffer(VboSubclass::Surfaces).reserve(vboBuffer(VboSubclass::Surfaces).size() + polygon.numPolygonVertices()); // Transform vertices so that they're suitable for GL rendering - for (int i = 0; i < polygon.numPolygonVertices(); i += 1) + for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) { polygon.vertices[i].y = -polygon.vertices[i].y; polygon.vertices[i].z = -polygon.vertices[i].z; -#if 0 - // Add these vertices to the bounding box (unless we're going to do it over - // from scratch afterwards anyway) - if (not this->needBoundingBoxRebuild) - { - this->boundingBox.consider(poly.vertices[i]); - } -#endif + this->boundingBox.consider(polygon.vertices[i]); writeVertex(vboBuffer(VboSubclass::Surfaces), polygon.vertices[i]); } this->writeColor(vboData, polygon, VboSubclass::RegularColors); @@ -199,15 +193,25 @@ std::vector& buffer = data[gl::vboIndex({classifyPolygon(polygon), subclass})]; const QColor color = this->getColorForPolygon(polygon, subclass); buffer.reserve(data->size() + 4 * polygon.numPolygonVertices()); - for (int i = 0; i < polygon.numPolygonVertices(); i += 1) + for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) { - buffer.push_back(color.redF() / 255.0f); - buffer.push_back(color.greenF() / 255.0f); - buffer.push_back(color.blueF() / 255.0f); - buffer.push_back(color.alphaF() / 255.0f); + buffer.push_back(static_cast(color.redF())); + buffer.push_back(static_cast(color.greenF())); + buffer.push_back(static_cast(color.blueF())); + buffer.push_back(static_cast(color.alphaF())); } } +Point3D gl::Compiler::modelCenter() const +{ + return boxCenter(this->boundingBox); +} + +double gl::Compiler::modelDistance() const +{ + return longestMeasure(this->boundingBox); +} + void gl::Compiler::initializeVbo() { this->initializeOpenGLFunctions(); @@ -223,7 +227,7 @@ void gl::Compiler::upload(const int vboIndex, const std::vector& data) { glBindBuffer(GL_ARRAY_BUFFER, this->storedVbo[vboIndex]); - glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof data[0], data.data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, static_cast(data.size() * sizeof data[0]), data.data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); this->storedVboSizes[vboIndex] = data.size(); } @@ -233,7 +237,7 @@ return this->storedVbo[gl::vboIndex(vboAddress)]; } -int gl::Compiler::vboSize(const VboAddress vboAddress) const +std::size_t gl::Compiler::vboSize(const VboAddress vboAddress) const { return this->storedVboSizes[gl::vboIndex(vboAddress)]; }