Wed, 25 May 2022 20:36:34 +0300
Fix pick() picking from weird places on the screen with high DPI scaling
glReadPixels reads data from the frame buffer, which contains data after
high DPI scaling, so any reads to that need to take this scaling into account
#include "polygoncache.h" #include "documentmanager.h" static void getObjectPolygons( Model* model, const int index, std::vector<gl::Polygon>& polygons_out, ldraw::GetPolygonsContext* context); /** * @brief Gets a list of GL polygons that are used to represent this model. * @details Will build polygons if polygons are outdated. * @param documents Documents to use to resolve subfile references * @return vector of GL polygons */ const std::vector<gl::Polygon> &getCachedPolygons( PolygonCache *cache, Model *model, DocumentManager *documents) { if (cache->needRecache) { cache->cachedPolygons.clear(); const std::optional<ModelId> modelId = documents->findIdForModel(model); if (modelId.has_value()) { ldraw::GetPolygonsContext context{modelId.value(), documents}; for (int i = 0; i < model->size(); i += 1) { getObjectPolygons(model, i, cache->cachedPolygons, &context); } } cache->needRecache = false; } return cache->cachedPolygons; } /** * @brief Gets the GL polygons of the object at the specified position in the model * @param index Index of object in the model * @param polygons_out Vector to add polygons into * @param context Context to use to resolve subfile references */ static void getObjectPolygons( Model* model, const int index, std::vector<gl::Polygon>& polygons_out, ldraw::GetPolygonsContext* context) { const ldraw::Object* object = (*model)[unsigned_cast(index)]; object->getPolygons(polygons_out, context); }