Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Add geometry memory usage in gltfEditor
Browse files Browse the repository at this point in the history
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
Juan Jose Casafranca authored and lemirep committed Dec 4, 2019
1 parent 065f00a commit dd1064e
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tools/gltfEditor/gltfEditor.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ SOURCES += \
texturepreviewmaterial.cpp \
settingsdialog.cpp \
orbitcameracontroller.cpp \
exportdialog.cpp
exportdialog.cpp \
memoryusagewidget.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -78,7 +79,8 @@ HEADERS += \
texturepreviewmaterial.h \
settingsdialog.h \
orbitcameracontroller.h \
exportdialog.h
exportdialog.h \
memoryusagewidget.h

FORMS += \
animationwidget.ui \
Expand All @@ -90,7 +92,8 @@ FORMS += \
meshwidget.ui \
texturewidget.ui \
settingsdialog.ui \
exportdialog.ui
exportdialog.ui \
memoryusagewidget.ui

RESOURCES += \
qml.qrc \
Expand Down
8 changes: 8 additions & 0 deletions tools/gltfEditor/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "meshinspector.h"
#include "animationwidget.h"
#include "camerawidget.h"
#include "memoryusagewidget.h"
#include "orbitcameracontroller.h"
#include "exportdialog.h"

Expand Down Expand Up @@ -152,6 +153,10 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->cameraDockWidget->setWidget(m_cameraWidget);
m_ui->cameraDockWidget->setVisible(false);

m_memoryUsageWidget = new MemoryUsageWidget;
m_ui->memoryUsageWidget->setWidget(m_memoryUsageWidget);
m_ui->memoryUsageWidget->setVisible(false);

qmlRegisterType<TexturePreviewMaterial>("GltfEditor", 1, 0, "TexturePreviewMaterial");
qmlRegisterType<OrbitCameraController>("GltfEditor", 1, 0, "OrbitCameraController");

Expand All @@ -174,6 +179,7 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->menuView->addAction(m_ui->assetInspectorDockWidget->toggleViewAction());
m_ui->menuView->addAction(m_ui->animationDockWidget->toggleViewAction());
m_ui->menuView->addAction(m_ui->cameraDockWidget->toggleViewAction());
m_ui->menuView->addAction(m_ui->memoryUsageWidget->toggleViewAction());

m_ui->collectionBrowser->setModel(new CollectionModel(this));

Expand Down Expand Up @@ -262,6 +268,8 @@ void MainWindow::updateScene(Kuesa::SceneEntity *entity)
m_sceneSelector->setEnabled(m_sceneSelector->count() > 1);
m_sceneSelector->setCurrentIndex(selectorIndex);
m_sceneSelector->blockSignals(false);

m_memoryUsageWidget->setSceneEntity(entity);
}

void MainWindow::assetSelected(const QString &assetName, Kuesa::AbstractAssetCollection *collection)
Expand Down
2 changes: 2 additions & 0 deletions tools/gltfEditor/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AnimationWidget;
class AssetInspectorWidget;
class AssetInspector;
class CameraWidget;
class MemoryUsageWidget;

namespace Ui {
class MainWindow;
Expand Down Expand Up @@ -133,6 +134,7 @@ private slots:
QString m_selectedAssetName;
QColor m_clearColor;
CameraWidget *m_cameraWidget;
MemoryUsageWidget *m_memoryUsageWidget;
QSize m_renderAreaSize;
bool m_generateTangents;
bool m_generateNormals;
Expand Down
11 changes: 10 additions & 1 deletion tools/gltfEditor/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<x>0</x>
<y>0</y>
<width>1400</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -151,6 +151,15 @@
</attribute>
<widget class="QWidget" name="dockWidgetContents_4"/>
</widget>
<widget class="QDockWidget" name="memoryUsageWidget">
<property name="windowTitle">
<string>GPU memory usage</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_6"/>
</widget>
<action name="actionOpen">
<property name="text">
<string>&amp;Open...</string>
Expand Down
99 changes: 99 additions & 0 deletions tools/gltfEditor/memoryusagewidget.cpp
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));
}
62 changes: 62 additions & 0 deletions tools/gltfEditor/memoryusagewidget.h
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
86 changes: 86 additions & 0 deletions tools/gltfEditor/memoryusagewidget.ui
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>

0 comments on commit dd1064e

Please sign in to comment.