diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index cd00c7ff..2e195d32 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -387,14 +387,34 @@ void lcPartSelectionListModel::PartLoaded(PieceInfo* Info) void lcPartSelectionListModel::DrawPreview(int InfoIndex) { + const int Width = mIconSize * 2; + const int Height = mIconSize * 2; + +#ifdef LC_USE_QOPENGLWIDGET + if (mView && (mView->GetWidth() != Width || mView->GetHeight() != Height)) + mView.reset(); + + if (!mView) + { + mView = std::unique_ptr(new lcView(lcViewType::PartsList, nullptr)); + + if (!mView->BeginRenderToImage(Width, Height)) + { + mView.reset(); + return; + } + } + + mView->MakeCurrent(); + + lcContext* Context = mView->mContext; +#else lcView* ActiveView = gMainWindow->GetActiveView(); if (!ActiveView) return; ActiveView->MakeCurrent(); lcContext* Context = ActiveView->mContext; - int Width = mIconSize * 2; - int Height = mIconSize * 2; if (mRenderFramebuffer.first.mWidth != Width || mRenderFramebuffer.first.mHeight != Height) { @@ -405,11 +425,13 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex) if (!mRenderFramebuffer.first.IsValid()) return; - float Aspect = (float)Width / (float)Height; + Context->BindFramebuffer(mRenderFramebuffer.first); +#endif + + const float Aspect = (float)Width / (float)Height; Context->SetViewport(0, 0, Width, Height); Context->SetDefaultState(); - Context->BindFramebuffer(mRenderFramebuffer.first); lcPiecesLibrary* Library = lcGetPiecesLibrary(); PieceInfo* Info = mParts[InfoIndex].first; @@ -434,11 +456,17 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex) Scene.Draw(Context); - mParts[InfoIndex].second = QPixmap::fromImage(Context->GetRenderFramebufferImage(mRenderFramebuffer)).scaled(mIconSize, mIconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +#ifdef LC_USE_QOPENGLWIDGET + QImage Image = mView->GetRenderFramebufferImage().convertToFormat(QImage::Format_ARGB32); +#else + QImage Image = Context->GetRenderFramebufferImage(mRenderFramebuffer); + Context->ClearFramebuffer(); +#endif + + mParts[InfoIndex].second = QPixmap::fromImage(Image).scaled(mIconSize, mIconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); Library->ReleasePieceInfo(Info); - Context->ClearFramebuffer(); Context->ClearResources(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index b0881818..e55806f9 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -136,7 +136,11 @@ protected: bool mShowDecoratedParts; bool mShowPartAliases; QByteArray mFilter; +#ifdef LC_USE_QOPENGLWIDGET + std::unique_ptr mView; +#else std::pair mRenderFramebuffer; +#endif }; class lcPartSelectionListView : public QListView diff --git a/common/lc_view.cpp b/common/lc_view.cpp index b5447bb2..97ee18e5 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -1093,6 +1093,7 @@ void lcView::DrawAxes() const break; case lcViewType::Minifig: + case lcViewType::PartsList: case lcViewType::Count: return; } diff --git a/common/lc_view.h b/common/lc_view.h index cbf6ce3d..95f52cbf 100644 --- a/common/lc_view.h +++ b/common/lc_view.h @@ -86,6 +86,7 @@ enum class lcViewType View, Preview, Minifig, + PartsList, Count }; diff --git a/common/lc_viewsphere.cpp b/common/lc_viewsphere.cpp index 006ed49e..495d7e0e 100644 --- a/common/lc_viewsphere.cpp +++ b/common/lc_viewsphere.cpp @@ -40,6 +40,7 @@ void lcViewSphere::UpdateSettings() break; case lcViewType::Minifig: + case lcViewType::PartsList: case lcViewType::Count: break; }