This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add geometry memory usage in gltfEditor
Change-Id: I1ea1244f4af57b61cd2c8b632545ec08b79d0737 Reviewed-on: https://kuesa-codereview.kdab.com/c/kuesa/kuesa/+/336 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
- Loading branch information
Showing
7 changed files
with
273 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
memoryusage.cpp | ||
This file is part of Kuesa. | ||
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com | ||
Author: Juan Casafranca <juan.casafranca@kdab.com.com> | ||
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in | ||
accordance with the Kuesa Enterprise License Agreement provided with the Software in the | ||
LICENSE.KUESA.ENTERPRISE file. | ||
Contact info@kdab.com if any conditions of this licensing are not clear to you. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "memoryusagewidget.h" | ||
#include "ui_memoryusagewidget.h" | ||
|
||
#include <QFileDialog> | ||
#include <QFileInfo> | ||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QSettings> | ||
#include <QString> | ||
|
||
#include <Kuesa/SceneEntity> | ||
|
||
#include <Qt3DRender/QBuffer> | ||
#include <Qt3DRender/QAttribute> | ||
#include <Qt3DRender/QGeometryRenderer> | ||
#include <Qt3DRender/QGeometry> | ||
|
||
namespace { | ||
const QLatin1String LASTPATHSETTING("mainwindow/lastPath"); | ||
|
||
QString totalSizeString(int sizeInBytes) | ||
{ | ||
auto size = sizeInBytes / 1024.0; | ||
QString suffix(QStringLiteral(" KB")); | ||
if (size > 1024.) { | ||
size = size / 1024.; | ||
suffix = QStringLiteral(" MB"); | ||
} | ||
return QString::number(size, 'f', 2) + suffix; | ||
} | ||
} | ||
|
||
MemoryUsageWidget::MemoryUsageWidget(QWidget *parent) | ||
: QWidget(parent) | ||
, m_ui(new Ui::MemoryUsageWidget) | ||
, m_sceneEntity(nullptr) | ||
{ | ||
m_ui->setupUi(this); | ||
} | ||
|
||
MemoryUsageWidget::~MemoryUsageWidget() | ||
{ | ||
} | ||
|
||
void MemoryUsageWidget::setSceneEntity(Kuesa::SceneEntity *sceneEntity) | ||
{ | ||
m_sceneEntity = sceneEntity; | ||
updateWidgetValues(); | ||
} | ||
|
||
void MemoryUsageWidget::updateWidgetValues() | ||
{ | ||
Kuesa::MeshCollection *meshesCollection = m_sceneEntity->meshes(); | ||
const auto &names = meshesCollection->names(); | ||
|
||
int geometrySize = 0; | ||
QVector<Qt3DRender::QBuffer *> visitedBuffer; | ||
for (const auto &name: names) { | ||
Qt3DRender::QGeometryRenderer *mesh = meshesCollection->find(name); | ||
|
||
const auto &attributes = mesh->geometry()->attributes(); | ||
for (Qt3DRender::QAttribute *attribute : attributes) { | ||
if (!visitedBuffer.contains(attribute->buffer())) { | ||
geometrySize += attribute->buffer()->data().size(); | ||
visitedBuffer.push_back(attribute->buffer()); | ||
} | ||
} | ||
} | ||
|
||
m_ui->geometryUsage->setText(totalSizeString(geometrySize)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
MemoryUsageWidget.h | ||
This file is part of Kuesa. | ||
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com | ||
Author: Juan Casafranca <juan.casafranca@kdab.com> | ||
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in | ||
accordance with the Kuesa Enterprise License Agreement provided with the Software in the | ||
LICENSE.KUESA.ENTERPRISE file. | ||
Contact info@kdab.com if any conditions of this licensing are not clear to you. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MEMORYUSAGEWIDGET_H | ||
#define MEMORYUSAGEWIDGET_H | ||
|
||
#include <QWidget> | ||
#include <Qt3DRender/QCamera> | ||
#include <QScopedPointer> | ||
|
||
namespace Ui { | ||
class MemoryUsageWidget; | ||
} // namespace Ui | ||
|
||
namespace Kuesa | ||
{ | ||
class SceneEntity; | ||
} | ||
|
||
class MemoryUsageWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
MemoryUsageWidget(QWidget *parent = nullptr); | ||
virtual ~MemoryUsageWidget(); | ||
|
||
void setSceneEntity(Kuesa::SceneEntity *sceneEntity); | ||
|
||
private: | ||
void updateWidgetValues(); | ||
|
||
QScopedPointer<Ui::MemoryUsageWidget> m_ui; | ||
Kuesa::SceneEntity *m_sceneEntity; | ||
}; | ||
|
||
#endif // MEMORYUSAGEWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MemoryUsageWidget</class> | ||
<widget class="QWidget" name="MemoryUsageWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>571</width> | ||
<height>147</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label_7"> | ||
<property name="text"> | ||
<string>Geometry:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="label_8"> | ||
<property name="text"> | ||
<string>Texture:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QLabel" name="geometryUsage"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QLabel" name="textureUsage"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<spacer name="horizontalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeType"> | ||
<enum>QSizePolicy::Expanding</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>0</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |