mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 08:15:30 +08:00
qt 6.5.1 original
This commit is contained in:
59
examples/vulkan/hellovulkanwidget/CMakeLists.txt
Normal file
59
examples/vulkan/hellovulkanwidget/CMakeLists.txt
Normal file
@ -0,0 +1,59 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(hellovulkanwidget LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vulkan/hellovulkanwidget")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(hellovulkanwidget
|
||||
../shared/trianglerenderer.cpp ../shared/trianglerenderer.h
|
||||
hellovulkanwidget.cpp hellovulkanwidget.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(hellovulkanwidget PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(hellovulkanwidget PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set_source_files_properties("../shared/color_frag.spv"
|
||||
PROPERTIES QT_RESOURCE_ALIAS "color_frag.spv"
|
||||
)
|
||||
|
||||
set_source_files_properties("../shared/color_vert.spv"
|
||||
PROPERTIES QT_RESOURCE_ALIAS "color_vert.spv"
|
||||
)
|
||||
|
||||
set(hellovulkanwidget_resource_files
|
||||
"../shared/color_frag.spv"
|
||||
"../shared/color_vert.spv"
|
||||
)
|
||||
|
||||
qt_add_resources(hellovulkanwidget "hellovulkanwidget"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${hellovulkanwidget_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS hellovulkanwidget
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
138
examples/vulkan/hellovulkanwidget/hellovulkanwidget.cpp
Normal file
138
examples/vulkan/hellovulkanwidget/hellovulkanwidget.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "hellovulkanwidget.h"
|
||||
#include <QVulkanFunctions>
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QLCDNumber>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTabWidget>
|
||||
|
||||
MainWindow::MainWindow(VulkanWindow *w, QPlainTextEdit *logWidget)
|
||||
: m_window(w)
|
||||
{
|
||||
QWidget *wrapper = QWidget::createWindowContainer(w);
|
||||
|
||||
m_info = new QPlainTextEdit;
|
||||
m_info->setReadOnly(true);
|
||||
|
||||
m_number = new QLCDNumber(3);
|
||||
m_number->setSegmentStyle(QLCDNumber::Filled);
|
||||
|
||||
QPushButton *grabButton = new QPushButton(tr("&Grab"));
|
||||
grabButton->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
connect(grabButton, &QPushButton::clicked, this, &MainWindow::onGrabRequested);
|
||||
|
||||
QPushButton *quitButton = new QPushButton(tr("&Quit"));
|
||||
quitButton->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
connect(quitButton, &QPushButton::clicked, qApp, &QCoreApplication::quit);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
m_infoTab = new QTabWidget(this);
|
||||
m_infoTab->addTab(m_info, tr("Vulkan Info"));
|
||||
m_infoTab->addTab(logWidget, tr("Debug Log"));
|
||||
layout->addWidget(m_infoTab, 2);
|
||||
layout->addWidget(m_number, 1);
|
||||
layout->addWidget(wrapper, 5);
|
||||
layout->addWidget(grabButton, 1);
|
||||
layout->addWidget(quitButton, 1);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void MainWindow::onVulkanInfoReceived(const QString &text)
|
||||
{
|
||||
m_info->setPlainText(text);
|
||||
}
|
||||
|
||||
void MainWindow::onFrameQueued(int colorValue)
|
||||
{
|
||||
m_number->display(colorValue);
|
||||
}
|
||||
|
||||
void MainWindow::onGrabRequested()
|
||||
{
|
||||
if (!m_window->supportsGrab()) {
|
||||
QMessageBox::warning(this, tr("Cannot grab"), tr("This swapchain does not support readbacks."));
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img = m_window->grab();
|
||||
|
||||
// Our startNextFrame() implementation is synchronous so img is ready to be
|
||||
// used right here.
|
||||
|
||||
QFileDialog fd(this);
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd.setDefaultSuffix("png");
|
||||
fd.selectFile("test.png");
|
||||
if (fd.exec() == QDialog::Accepted)
|
||||
img.save(fd.selectedFiles().first());
|
||||
}
|
||||
|
||||
QVulkanWindowRenderer *VulkanWindow::createRenderer()
|
||||
{
|
||||
return new VulkanRenderer(this);
|
||||
}
|
||||
|
||||
VulkanRenderer::VulkanRenderer(VulkanWindow *w)
|
||||
: TriangleRenderer(w)
|
||||
{
|
||||
}
|
||||
|
||||
void VulkanRenderer::initResources()
|
||||
{
|
||||
TriangleRenderer::initResources();
|
||||
|
||||
QVulkanInstance *inst = m_window->vulkanInstance();
|
||||
m_devFuncs = inst->deviceFunctions(m_window->device());
|
||||
|
||||
QString info;
|
||||
info += QString::asprintf("Number of physical devices: %d\n", int(m_window->availablePhysicalDevices().count()));
|
||||
|
||||
QVulkanFunctions *f = inst->functions();
|
||||
VkPhysicalDeviceProperties props;
|
||||
f->vkGetPhysicalDeviceProperties(m_window->physicalDevice(), &props);
|
||||
info += QString::asprintf("Active physical device name: '%s' version %d.%d.%d\nAPI version %d.%d.%d\n",
|
||||
props.deviceName,
|
||||
VK_VERSION_MAJOR(props.driverVersion), VK_VERSION_MINOR(props.driverVersion),
|
||||
VK_VERSION_PATCH(props.driverVersion),
|
||||
VK_VERSION_MAJOR(props.apiVersion), VK_VERSION_MINOR(props.apiVersion),
|
||||
VK_VERSION_PATCH(props.apiVersion));
|
||||
|
||||
info += QStringLiteral("Supported instance layers:\n");
|
||||
for (const QVulkanLayer &layer : inst->supportedLayers())
|
||||
info += QString::asprintf(" %s v%u\n", layer.name.constData(), layer.version);
|
||||
info += QStringLiteral("Enabled instance layers:\n");
|
||||
for (const QByteArray &layer : inst->layers())
|
||||
info += QString::asprintf(" %s\n", layer.constData());
|
||||
|
||||
info += QStringLiteral("Supported instance extensions:\n");
|
||||
for (const QVulkanExtension &ext : inst->supportedExtensions())
|
||||
info += QString::asprintf(" %s v%u\n", ext.name.constData(), ext.version);
|
||||
info += QStringLiteral("Enabled instance extensions:\n");
|
||||
for (const QByteArray &ext : inst->extensions())
|
||||
info += QString::asprintf(" %s\n", ext.constData());
|
||||
|
||||
info += QString::asprintf("Color format: %u\nDepth-stencil format: %u\n",
|
||||
m_window->colorFormat(), m_window->depthStencilFormat());
|
||||
|
||||
info += QStringLiteral("Supported sample counts:");
|
||||
const QList<int> sampleCounts = m_window->supportedSampleCounts();
|
||||
for (int count : sampleCounts)
|
||||
info += QLatin1Char(' ') + QString::number(count);
|
||||
info += QLatin1Char('\n');
|
||||
|
||||
emit static_cast<VulkanWindow *>(m_window)->vulkanInfoReceived(info);
|
||||
}
|
||||
|
||||
void VulkanRenderer::startNextFrame()
|
||||
{
|
||||
TriangleRenderer::startNextFrame();
|
||||
emit static_cast<VulkanWindow *>(m_window)->frameQueued(int(m_rotation) % 360);
|
||||
}
|
58
examples/vulkan/hellovulkanwidget/hellovulkanwidget.h
Normal file
58
examples/vulkan/hellovulkanwidget/hellovulkanwidget.h
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef HELLOVULKANWIDGET_H
|
||||
#define HELLOVULKANWIDGET_H
|
||||
|
||||
#include "../shared/trianglerenderer.h"
|
||||
#include <QWidget>
|
||||
|
||||
class VulkanWindow;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTabWidget;
|
||||
class QPlainTextEdit;
|
||||
class QLCDNumber;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(VulkanWindow *w, QPlainTextEdit *logWidget);
|
||||
|
||||
public slots:
|
||||
void onVulkanInfoReceived(const QString &text);
|
||||
void onFrameQueued(int colorValue);
|
||||
void onGrabRequested();
|
||||
|
||||
private:
|
||||
VulkanWindow *m_window;
|
||||
QTabWidget *m_infoTab;
|
||||
QPlainTextEdit *m_info;
|
||||
QLCDNumber *m_number;
|
||||
};
|
||||
|
||||
class VulkanRenderer : public TriangleRenderer
|
||||
{
|
||||
public:
|
||||
VulkanRenderer(VulkanWindow *w);
|
||||
|
||||
void initResources() override;
|
||||
void startNextFrame() override;
|
||||
};
|
||||
|
||||
class VulkanWindow : public QVulkanWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QVulkanWindowRenderer *createRenderer() override;
|
||||
|
||||
signals:
|
||||
void vulkanInfoReceived(const QString &text);
|
||||
void frameQueued(int colorValue);
|
||||
};
|
||||
|
||||
#endif // HELLOVULKANWIDGET_H
|
16
examples/vulkan/hellovulkanwidget/hellovulkanwidget.pro
Normal file
16
examples/vulkan/hellovulkanwidget/hellovulkanwidget.pro
Normal file
@ -0,0 +1,16 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS += \
|
||||
hellovulkanwidget.h \
|
||||
../shared/trianglerenderer.h
|
||||
|
||||
SOURCES += \
|
||||
hellovulkanwidget.cpp \
|
||||
main.cpp \
|
||||
../shared/trianglerenderer.cpp
|
||||
|
||||
RESOURCES += hellovulkanwidget.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/vulkan/hellovulkanwidget
|
||||
INSTALLS += target
|
6
examples/vulkan/hellovulkanwidget/hellovulkanwidget.qrc
Normal file
6
examples/vulkan/hellovulkanwidget/hellovulkanwidget.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file alias="color_vert.spv">../shared/color_vert.spv</file>
|
||||
<file alias="color_frag.spv">../shared/color_frag.spv</file>
|
||||
</qresource>
|
||||
</RCC>
|
53
examples/vulkan/hellovulkanwidget/main.cpp
Normal file
53
examples/vulkan/hellovulkanwidget/main.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVulkanInstance>
|
||||
#include <QLibraryInfo>
|
||||
#include <QLoggingCategory>
|
||||
#include <QPointer>
|
||||
#include "hellovulkanwidget.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(lcVk, "qt.vulkan")
|
||||
|
||||
static QPointer<QPlainTextEdit> messageLogWidget;
|
||||
static QtMessageHandler oldMessageHandler = nullptr;
|
||||
|
||||
static void messageHandler(QtMsgType msgType, const QMessageLogContext &logContext, const QString &text)
|
||||
{
|
||||
if (!messageLogWidget.isNull())
|
||||
messageLogWidget->appendPlainText(text);
|
||||
if (oldMessageHandler)
|
||||
oldMessageHandler(msgType, logContext, text);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
messageLogWidget = new QPlainTextEdit(QLatin1String(QLibraryInfo::build()) + QLatin1Char('\n'));
|
||||
messageLogWidget->setReadOnly(true);
|
||||
|
||||
oldMessageHandler = qInstallMessageHandler(messageHandler);
|
||||
|
||||
QLoggingCategory::setFilterRules(QStringLiteral("qt.vulkan=true"));
|
||||
|
||||
QVulkanInstance inst;
|
||||
inst.setLayers({ "VK_LAYER_KHRONOS_validation" });
|
||||
|
||||
if (!inst.create())
|
||||
qFatal("Failed to create Vulkan instance: %d", inst.errorCode());
|
||||
|
||||
VulkanWindow *vulkanWindow = new VulkanWindow;
|
||||
vulkanWindow->setVulkanInstance(&inst);
|
||||
|
||||
MainWindow mainWindow(vulkanWindow, messageLogWidget.data());
|
||||
QObject::connect(vulkanWindow, &VulkanWindow::vulkanInfoReceived, &mainWindow, &MainWindow::onVulkanInfoReceived);
|
||||
QObject::connect(vulkanWindow, &VulkanWindow::frameQueued, &mainWindow, &MainWindow::onFrameQueued);
|
||||
|
||||
mainWindow.resize(1024, 768);
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
Reference in New Issue
Block a user