mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 00:35:27 +08:00
qt 6.5.1 original
This commit is contained in:
BIN
tests/manual/rhi/shared/OpenfootageNET_fieldairport-512.hdr
Normal file
BIN
tests/manual/rhi/shared/OpenfootageNET_fieldairport-512.hdr
Normal file
Binary file not shown.
7
tests/manual/rhi/shared/buildshaders.bat
Normal file
7
tests/manual/rhi/shared/buildshaders.bat
Normal file
@ -0,0 +1,7 @@
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c color.vert -o color.vert.qsb
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c color.frag -o color.frag.qsb
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture.vert -o texture.vert.qsb
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture.frag -o texture.frag.qsb
|
||||
qsb --glsl "310 es,150" --hlsl 50 --msl 12 -c texture_ms4.frag -o texture_ms4.frag.qsb
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture_arr.vert -o texture_arr.vert.qsb
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture_arr.frag -o texture_arr.frag.qsb
|
BIN
tests/manual/rhi/shared/bwqt224_64.png
Normal file
BIN
tests/manual/rhi/shared/bwqt224_64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
BIN
tests/manual/rhi/shared/bwqt224_64_nomips.dds
Normal file
BIN
tests/manual/rhi/shared/bwqt224_64_nomips.dds
Normal file
Binary file not shown.
15
tests/manual/rhi/shared/color.frag
Normal file
15
tests/manual/rhi/shared/color.frag
Normal file
@ -0,0 +1,15 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec3 v_color;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
float opacity;
|
||||
} ubuf;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = vec4(v_color * ubuf.opacity, ubuf.opacity);
|
||||
}
|
BIN
tests/manual/rhi/shared/color.frag.qsb
Normal file
BIN
tests/manual/rhi/shared/color.frag.qsb
Normal file
Binary file not shown.
19
tests/manual/rhi/shared/color.vert
Normal file
19
tests/manual/rhi/shared/color.vert
Normal file
@ -0,0 +1,19 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec4 position;
|
||||
layout(location = 1) in vec3 color;
|
||||
|
||||
layout(location = 0) out vec3 v_color;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
float opacity;
|
||||
} ubuf;
|
||||
|
||||
out gl_PerVertex { vec4 gl_Position; };
|
||||
|
||||
void main()
|
||||
{
|
||||
v_color = color;
|
||||
gl_Position = ubuf.mvp * position;
|
||||
}
|
BIN
tests/manual/rhi/shared/color.vert.qsb
Normal file
BIN
tests/manual/rhi/shared/color.vert.qsb
Normal file
Binary file not shown.
119
tests/manual/rhi/shared/cube.h
Normal file
119
tests/manual/rhi/shared/cube.h
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 The Khronos Group Inc.
|
||||
* Copyright (c) 2015-2016 Valve Corporation
|
||||
* Copyright (c) 2015-2016 LunarG, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Author: Chia-I Wu <olv@lunarg.com>
|
||||
* Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
|
||||
* Author: Ian Elliott <ian@LunarG.com>
|
||||
* Author: Ian Elliott <ianelliott@google.com>
|
||||
* Author: Jon Ashburn <jon@lunarg.com>
|
||||
* Author: Gwan-gyeong Mun <elongbug@gmail.com>
|
||||
* Author: Tony Barbour <tony@LunarG.com>
|
||||
* Author: Bill Hollings <bill.hollings@brenwill.com>
|
||||
*/
|
||||
|
||||
#ifndef CUBE_H
|
||||
#define CUBE_H
|
||||
|
||||
// clang-format off
|
||||
static const float cube[] = {
|
||||
-1.0f,-1.0f,-1.0f, // -X side
|
||||
-1.0f,-1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f,-1.0f,
|
||||
-1.0f,-1.0f,-1.0f,
|
||||
|
||||
-1.0f,-1.0f,-1.0f, // -Z side
|
||||
1.0f, 1.0f,-1.0f,
|
||||
1.0f,-1.0f,-1.0f,
|
||||
-1.0f,-1.0f,-1.0f,
|
||||
-1.0f, 1.0f,-1.0f,
|
||||
1.0f, 1.0f,-1.0f,
|
||||
|
||||
-1.0f,-1.0f,-1.0f, // -Y side
|
||||
1.0f,-1.0f,-1.0f,
|
||||
1.0f,-1.0f, 1.0f,
|
||||
-1.0f,-1.0f,-1.0f,
|
||||
1.0f,-1.0f, 1.0f,
|
||||
-1.0f,-1.0f, 1.0f,
|
||||
|
||||
-1.0f, 1.0f,-1.0f, // +Y side
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f,-1.0f,
|
||||
1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f,-1.0f,
|
||||
|
||||
1.0f, 1.0f,-1.0f, // +X side
|
||||
1.0f, 1.0f, 1.0f,
|
||||
1.0f,-1.0f, 1.0f,
|
||||
1.0f,-1.0f, 1.0f,
|
||||
1.0f,-1.0f,-1.0f,
|
||||
1.0f, 1.0f,-1.0f,
|
||||
|
||||
-1.0f, 1.0f, 1.0f, // +Z side
|
||||
-1.0f,-1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f,
|
||||
-1.0f,-1.0f, 1.0f,
|
||||
1.0f,-1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f,
|
||||
|
||||
0.0f, 1.0f, // -X side
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
|
||||
1.0f, 1.0f, // -Z side
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
|
||||
1.0f, 0.0f, // -Y side
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
|
||||
1.0f, 0.0f, // +Y side
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
|
||||
1.0f, 0.0f, // +X side
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
|
||||
0.0f, 0.0f, // +Z side
|
||||
0.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
#endif
|
90
tests/manual/rhi/shared/dds_bc1.h
Normal file
90
tests/manual/rhi/shared/dds_bc1.h
Normal file
@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2018 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
static const quint32 DDS_MAGIC = 0x20534444; // 'DDS '
|
||||
static const quint32 DDS_FOURCC = 4;
|
||||
|
||||
#define FOURCC(c0, c1, c2, c3) ((c0) | ((c1) << 8) | ((c2) << 16) | ((c3 << 24)))
|
||||
|
||||
struct DDS_PIXELFORMAT {
|
||||
quint32 size;
|
||||
quint32 flags;
|
||||
quint32 fourCC;
|
||||
quint32 rgbBitCount;
|
||||
quint32 rBitMask;
|
||||
quint32 gBitMask;
|
||||
quint32 bBitMask;
|
||||
quint32 aBitMask;
|
||||
};
|
||||
|
||||
struct DDS_HEADER {
|
||||
quint32 size;
|
||||
quint32 flags;
|
||||
quint32 height;
|
||||
quint32 width;
|
||||
quint32 pitch;
|
||||
quint32 depth;
|
||||
quint32 mipMapCount;
|
||||
quint32 reserved1[11];
|
||||
DDS_PIXELFORMAT pixelFormat;
|
||||
quint32 caps;
|
||||
quint32 caps2;
|
||||
quint32 caps3;
|
||||
quint32 caps4;
|
||||
quint32 reserved2;
|
||||
};
|
||||
|
||||
static quint32 bc1size(const QSize &size)
|
||||
{
|
||||
static const quint32 blockSize = 8; // 8 bytes for BC1
|
||||
const quint32 bytesPerLine = qMax<quint32>(1, (size.width() + 3) / 4) * blockSize;
|
||||
const quint32 ySize = qMax<quint32>(1, (size.height() + 3) / 4);
|
||||
return bytesPerLine * ySize;
|
||||
}
|
||||
|
||||
static QByteArrayList loadBC1(const QString &filename, QSize *size)
|
||||
{
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
qWarning("Failed to open %s", qPrintable(filename));
|
||||
return QByteArrayList();
|
||||
}
|
||||
|
||||
quint32 magic = 0;
|
||||
f.read(reinterpret_cast<char *>(&magic), sizeof(magic));
|
||||
if (magic != DDS_MAGIC) {
|
||||
qWarning("%s is not a DDS file", qPrintable(filename));
|
||||
return QByteArrayList();
|
||||
}
|
||||
DDS_HEADER header;
|
||||
f.read(reinterpret_cast<char *>(&header), sizeof(header));
|
||||
if (header.size != sizeof(DDS_HEADER)) {
|
||||
qWarning("Invalid DDS header size");
|
||||
return QByteArrayList();
|
||||
}
|
||||
if (header.pixelFormat.size != sizeof(DDS_PIXELFORMAT)) {
|
||||
qWarning("Invalid DDS pixel format size");
|
||||
return QByteArrayList();
|
||||
}
|
||||
if (!(header.pixelFormat.flags & DDS_FOURCC)) {
|
||||
qWarning("Invalid DDS pixel format");
|
||||
return QByteArrayList();
|
||||
}
|
||||
if (header.pixelFormat.fourCC != FOURCC('D', 'X', 'T', '1')) {
|
||||
qWarning("Only DXT1 (BC1) is supported");
|
||||
return QByteArrayList();
|
||||
}
|
||||
|
||||
QByteArrayList data;
|
||||
QSize sz(header.width, header.height);
|
||||
for (quint32 level = 0; level < header.mipMapCount; ++level) {
|
||||
data.append(f.read(bc1size(sz)));
|
||||
sz.setWidth(qMax(1, sz.width() / 2));
|
||||
sz.setHeight(qMax(1, sz.height() / 2));
|
||||
}
|
||||
|
||||
if (size)
|
||||
*size = QSize(header.width, header.height);
|
||||
|
||||
return data;
|
||||
}
|
518
tests/manual/rhi/shared/examplefw.h
Normal file
518
tests/manual/rhi/shared/examplefw.h
Normal file
@ -0,0 +1,518 @@
|
||||
// Copyright (C) 2018 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
// Adapted from hellominimalcrossgfxtriangle with the frame rendering stripped out.
|
||||
// Include this file and implement Window::customInit, release and render.
|
||||
// Debug/validation layer is enabled for D3D and Vulkan.
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QWindow>
|
||||
#include <QPlatformSurfaceEvent>
|
||||
#include <QElapsedTimer>
|
||||
#include <QTimer>
|
||||
#include <QLoggingCategory>
|
||||
#include <QColorSpace>
|
||||
|
||||
#include <QtGui/private/qshader_p.h>
|
||||
#include <QFile>
|
||||
#include <QtGui/private/qrhinull_p.h>
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
#include <QtGui/private/qrhigles2_p.h>
|
||||
#include <QOffscreenSurface>
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(vulkan)
|
||||
#include <QtGui/private/qrhivulkan_p.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QtGui/private/qrhid3d11_p.h>
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
|
||||
#include <QtGui/private/qrhimetal_p.h>
|
||||
#endif
|
||||
|
||||
QShader getShader(const QString &name)
|
||||
{
|
||||
QFile f(name);
|
||||
if (f.open(QIODevice::ReadOnly))
|
||||
return QShader::fromSerialized(f.readAll());
|
||||
|
||||
return QShader();
|
||||
}
|
||||
|
||||
enum GraphicsApi
|
||||
{
|
||||
Null,
|
||||
OpenGL,
|
||||
Vulkan,
|
||||
D3D11,
|
||||
Metal
|
||||
};
|
||||
|
||||
GraphicsApi graphicsApi;
|
||||
|
||||
QString graphicsApiName()
|
||||
{
|
||||
switch (graphicsApi) {
|
||||
case Null:
|
||||
return QLatin1String("Null (no output)");
|
||||
case OpenGL:
|
||||
return QLatin1String("OpenGL");
|
||||
case Vulkan:
|
||||
return QLatin1String("Vulkan");
|
||||
case D3D11:
|
||||
return QLatin1String("Direct3D 11");
|
||||
case Metal:
|
||||
return QLatin1String("Metal");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers;
|
||||
int sampleCount = 1;
|
||||
QRhiSwapChain::Flags scFlags;
|
||||
QRhi::BeginFrameFlags beginFrameFlags;
|
||||
QRhi::EndFrameFlags endFrameFlags;
|
||||
int framesUntilTdr = -1;
|
||||
bool transparentBackground = false;
|
||||
bool debugLayer = true;
|
||||
|
||||
class Window : public QWindow
|
||||
{
|
||||
public:
|
||||
Window();
|
||||
~Window();
|
||||
|
||||
protected:
|
||||
void init();
|
||||
void releaseResources();
|
||||
void resizeSwapChain();
|
||||
void releaseSwapChain();
|
||||
void render();
|
||||
|
||||
void customInit();
|
||||
void customRelease();
|
||||
void customRender();
|
||||
|
||||
void exposeEvent(QExposeEvent *) override;
|
||||
bool event(QEvent *) override;
|
||||
#ifdef EXAMPLEFW_KEYPRESS_EVENTS
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
#endif
|
||||
|
||||
bool m_running = false;
|
||||
bool m_notExposed = false;
|
||||
bool m_newlyExposed = false;
|
||||
|
||||
QRhi *m_r = nullptr;
|
||||
bool m_hasSwapChain = false;
|
||||
QRhiSwapChain *m_sc = nullptr;
|
||||
QRhiRenderBuffer *m_ds = nullptr;
|
||||
QRhiRenderPassDescriptor *m_rp = nullptr;
|
||||
|
||||
QMatrix4x4 m_proj;
|
||||
|
||||
QElapsedTimer m_timer;
|
||||
int m_frameCount;
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
QOffscreenSurface *m_fallbackSurface = nullptr;
|
||||
#endif
|
||||
|
||||
QColor m_clearColor;
|
||||
|
||||
friend int main(int, char**);
|
||||
};
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
// Tell the platform plugin what we want.
|
||||
switch (graphicsApi) {
|
||||
case OpenGL:
|
||||
setSurfaceType(OpenGLSurface);
|
||||
break;
|
||||
case Vulkan:
|
||||
setSurfaceType(VulkanSurface);
|
||||
break;
|
||||
case D3D11:
|
||||
setSurfaceType(Direct3DSurface);
|
||||
break;
|
||||
case Metal:
|
||||
setSurfaceType(MetalSurface);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_clearColor = transparentBackground ? Qt::transparent : QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
releaseResources();
|
||||
}
|
||||
|
||||
void Window::exposeEvent(QExposeEvent *)
|
||||
{
|
||||
// initialize and start rendering when the window becomes usable for graphics purposes
|
||||
if (isExposed() && !m_running) {
|
||||
m_running = true;
|
||||
init();
|
||||
resizeSwapChain();
|
||||
}
|
||||
|
||||
const QSize surfaceSize = m_hasSwapChain ? m_sc->surfacePixelSize() : QSize();
|
||||
|
||||
// stop pushing frames when not exposed (or size is 0)
|
||||
if ((!isExposed() || (m_hasSwapChain && surfaceSize.isEmpty())) && m_running)
|
||||
m_notExposed = true;
|
||||
|
||||
// continue when exposed again and the surface has a valid size.
|
||||
// note that the surface size can be (0, 0) even though size() reports a valid one...
|
||||
if (isExposed() && m_running && m_notExposed && !surfaceSize.isEmpty()) {
|
||||
m_notExposed = false;
|
||||
m_newlyExposed = true;
|
||||
}
|
||||
|
||||
// always render a frame on exposeEvent() (when exposed) in order to update
|
||||
// immediately on window resize.
|
||||
if (isExposed() && !surfaceSize.isEmpty())
|
||||
render();
|
||||
}
|
||||
|
||||
bool Window::event(QEvent *e)
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::UpdateRequest:
|
||||
render();
|
||||
break;
|
||||
|
||||
case QEvent::PlatformSurface:
|
||||
// this is the proper time to tear down the swapchain (while the native window and surface are still around)
|
||||
if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
|
||||
releaseSwapChain();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QWindow::event(e);
|
||||
}
|
||||
|
||||
void Window::init()
|
||||
{
|
||||
if (graphicsApi == Null) {
|
||||
QRhiNullInitParams params;
|
||||
m_r = QRhi::create(QRhi::Null, ¶ms, rhiFlags);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
if (graphicsApi == OpenGL) {
|
||||
m_fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
|
||||
QRhiGles2InitParams params;
|
||||
params.fallbackSurface = m_fallbackSurface;
|
||||
params.window = this;
|
||||
m_r = QRhi::create(QRhi::OpenGLES2, ¶ms, rhiFlags);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(vulkan)
|
||||
if (graphicsApi == Vulkan) {
|
||||
QRhiVulkanInitParams params;
|
||||
params.inst = vulkanInstance();
|
||||
params.window = this;
|
||||
m_r = QRhi::create(QRhi::Vulkan, ¶ms, rhiFlags);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (graphicsApi == D3D11) {
|
||||
QRhiD3D11InitParams params;
|
||||
if (debugLayer)
|
||||
qDebug("Enabling D3D11 debug layer");
|
||||
params.enableDebugLayer = debugLayer;
|
||||
if (framesUntilTdr > 0) {
|
||||
params.framesUntilKillingDeviceViaTdr = framesUntilTdr;
|
||||
params.repeatDeviceKill = true;
|
||||
}
|
||||
m_r = QRhi::create(QRhi::D3D11, ¶ms, rhiFlags);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
|
||||
if (graphicsApi == Metal) {
|
||||
QRhiMetalInitParams params;
|
||||
m_r = QRhi::create(QRhi::Metal, ¶ms, rhiFlags);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_r)
|
||||
qFatal("Failed to create RHI backend");
|
||||
|
||||
// now onto the backend-independent init
|
||||
|
||||
m_sc = m_r->newSwapChain();
|
||||
m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
|
||||
QSize(), // no need to set the size here, due to UsedWithSwapChainOnly
|
||||
sampleCount,
|
||||
QRhiRenderBuffer::UsedWithSwapChainOnly);
|
||||
m_sc->setWindow(this);
|
||||
m_sc->setDepthStencil(m_ds);
|
||||
m_sc->setSampleCount(sampleCount);
|
||||
m_sc->setFlags(scFlags);
|
||||
m_rp = m_sc->newCompatibleRenderPassDescriptor();
|
||||
m_sc->setRenderPassDescriptor(m_rp);
|
||||
|
||||
customInit();
|
||||
}
|
||||
|
||||
void Window::releaseResources()
|
||||
{
|
||||
customRelease();
|
||||
|
||||
delete m_rp;
|
||||
m_rp = nullptr;
|
||||
|
||||
delete m_ds;
|
||||
m_ds = nullptr;
|
||||
|
||||
delete m_sc;
|
||||
m_sc = nullptr;
|
||||
|
||||
delete m_r;
|
||||
m_r = nullptr;
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
delete m_fallbackSurface;
|
||||
m_fallbackSurface = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Window::resizeSwapChain()
|
||||
{
|
||||
m_hasSwapChain = m_sc->createOrResize(); // also handles m_ds
|
||||
|
||||
m_frameCount = 0;
|
||||
m_timer.restart();
|
||||
|
||||
const QSize outputSize = m_sc->currentPixelSize();
|
||||
m_proj = m_r->clipSpaceCorrMatrix();
|
||||
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
|
||||
m_proj.translate(0, 0, -4);
|
||||
}
|
||||
|
||||
void Window::releaseSwapChain()
|
||||
{
|
||||
if (m_hasSwapChain) {
|
||||
m_hasSwapChain = false;
|
||||
m_sc->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::render()
|
||||
{
|
||||
if (!m_hasSwapChain || m_notExposed)
|
||||
return;
|
||||
|
||||
// If the window got resized or got newly exposed, resize the swapchain.
|
||||
// (the newly-exposed case is not actually required by some
|
||||
// platforms/backends, but f.ex. Vulkan on Windows seems to need it)
|
||||
if (m_sc->currentPixelSize() != m_sc->surfacePixelSize() || m_newlyExposed) {
|
||||
resizeSwapChain();
|
||||
if (!m_hasSwapChain)
|
||||
return;
|
||||
m_newlyExposed = false;
|
||||
}
|
||||
|
||||
// Start a new frame. This is where we block when too far ahead of
|
||||
// GPU/present, and that's what throttles the thread to the refresh rate.
|
||||
// (except for OpenGL where it happens either in endFrame or somewhere else
|
||||
// depending on the GL implementation)
|
||||
QRhi::FrameOpResult r = m_r->beginFrame(m_sc, beginFrameFlags);
|
||||
if (r == QRhi::FrameOpSwapChainOutOfDate) {
|
||||
resizeSwapChain();
|
||||
if (!m_hasSwapChain)
|
||||
return;
|
||||
r = m_r->beginFrame(m_sc);
|
||||
}
|
||||
if (r != QRhi::FrameOpSuccess) {
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
m_frameCount += 1;
|
||||
if (m_timer.elapsed() > 1000) {
|
||||
qDebug("ca. %d fps", m_frameCount);
|
||||
m_timer.restart();
|
||||
m_frameCount = 0;
|
||||
}
|
||||
|
||||
customRender();
|
||||
|
||||
m_r->endFrame(m_sc, endFrameFlags);
|
||||
|
||||
if (!scFlags.testFlag(QRhiSwapChain::NoVSync))
|
||||
requestUpdate();
|
||||
else // try prevent all delays when NoVSync
|
||||
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QLoggingCategory::setFilterRules(QLatin1String("qt.rhi.*=true"));
|
||||
|
||||
// Defaults.
|
||||
#if defined(Q_OS_WIN)
|
||||
graphicsApi = D3D11;
|
||||
#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
|
||||
graphicsApi = Metal;
|
||||
#elif QT_CONFIG(vulkan)
|
||||
graphicsApi = Vulkan;
|
||||
#else
|
||||
graphicsApi = OpenGL;
|
||||
#endif
|
||||
|
||||
// Allow overriding via the command line.
|
||||
QCommandLineParser cmdLineParser;
|
||||
cmdLineParser.addHelpOption();
|
||||
QCommandLineOption nullOption({ "n", "null" }, QLatin1String("Null"));
|
||||
cmdLineParser.addOption(nullOption);
|
||||
QCommandLineOption glOption({ "g", "opengl" }, QLatin1String("OpenGL"));
|
||||
cmdLineParser.addOption(glOption);
|
||||
QCommandLineOption vkOption({ "v", "vulkan" }, QLatin1String("Vulkan"));
|
||||
cmdLineParser.addOption(vkOption);
|
||||
QCommandLineOption d3dOption({ "d", "d3d11" }, QLatin1String("Direct3D 11"));
|
||||
cmdLineParser.addOption(d3dOption);
|
||||
QCommandLineOption mtlOption({ "m", "metal" }, QLatin1String("Metal"));
|
||||
cmdLineParser.addOption(mtlOption);
|
||||
// Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and
|
||||
// QCoreApplication::quit() (e.g. what a menu widget would do) is important.
|
||||
// Use this parameter for the latter.
|
||||
QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds."));
|
||||
cmdLineParser.addOption(sdOption);
|
||||
QCommandLineOption coreProfOption({ "c", "core" }, QLatin1String("Request a core profile context for OpenGL"));
|
||||
cmdLineParser.addOption(coreProfOption);
|
||||
// Attempt testing device lost situations on D3D at least.
|
||||
QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. "
|
||||
"(generate a device reset every <count> frames when on D3D11)"),
|
||||
QLatin1String("count"));
|
||||
cmdLineParser.addOption(tdrOption);
|
||||
// Allow testing preferring the software adapter (D3D).
|
||||
QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
|
||||
"Only applicable with some APIs and platforms."));
|
||||
cmdLineParser.addOption(swOption);
|
||||
// Allow testing having a semi-transparent window.
|
||||
QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent"));
|
||||
cmdLineParser.addOption(transparentOption);
|
||||
|
||||
cmdLineParser.process(app);
|
||||
if (cmdLineParser.isSet(nullOption))
|
||||
graphicsApi = Null;
|
||||
if (cmdLineParser.isSet(glOption))
|
||||
graphicsApi = OpenGL;
|
||||
if (cmdLineParser.isSet(vkOption))
|
||||
graphicsApi = Vulkan;
|
||||
if (cmdLineParser.isSet(d3dOption))
|
||||
graphicsApi = D3D11;
|
||||
if (cmdLineParser.isSet(mtlOption))
|
||||
graphicsApi = Metal;
|
||||
|
||||
qDebug("Selected graphics API is %s", qPrintable(graphicsApiName()));
|
||||
qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText()));
|
||||
|
||||
if (cmdLineParser.isSet(transparentOption)) {
|
||||
transparentBackground = true;
|
||||
scFlags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
|
||||
}
|
||||
|
||||
#ifdef EXAMPLEFW_PREINIT
|
||||
void preInit();
|
||||
preInit();
|
||||
#endif
|
||||
|
||||
// OpenGL specifics.
|
||||
QSurfaceFormat fmt;
|
||||
fmt.setDepthBufferSize(24);
|
||||
fmt.setStencilBufferSize(8);
|
||||
if (cmdLineParser.isSet(coreProfOption)) {
|
||||
#ifdef Q_OS_DARWIN
|
||||
fmt.setVersion(4, 1);
|
||||
#else
|
||||
fmt.setVersion(4, 3);
|
||||
#endif
|
||||
fmt.setProfile(QSurfaceFormat::CoreProfile);
|
||||
}
|
||||
if (sampleCount > 1)
|
||||
fmt.setSamples(sampleCount);
|
||||
if (scFlags.testFlag(QRhiSwapChain::NoVSync))
|
||||
fmt.setSwapInterval(0);
|
||||
if (scFlags.testFlag(QRhiSwapChain::sRGB))
|
||||
fmt.setColorSpace(QColorSpace::SRgb);
|
||||
// Exception: The alpha size is not necessarily OpenGL specific.
|
||||
if (transparentBackground)
|
||||
fmt.setAlphaBufferSize(8);
|
||||
QSurfaceFormat::setDefaultFormat(fmt);
|
||||
|
||||
// Vulkan setup.
|
||||
#if QT_CONFIG(vulkan)
|
||||
QVulkanInstance inst;
|
||||
if (graphicsApi == Vulkan) {
|
||||
if (debugLayer) {
|
||||
qDebug("Enabling Vulkan validation layer (if available)");
|
||||
inst.setLayers({ "VK_LAYER_KHRONOS_validation" });
|
||||
}
|
||||
const QVersionNumber supportedVersion = inst.supportedApiVersion();
|
||||
qDebug() << "Supported Vulkan API version:" << supportedVersion;
|
||||
if (supportedVersion >= QVersionNumber(1, 1)) {
|
||||
qDebug("Requesting Vulkan API 1.1 on the VkInstance");
|
||||
inst.setApiVersion(QVersionNumber(1, 1));
|
||||
}
|
||||
inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
|
||||
if (!inst.create()) {
|
||||
qWarning("Failed to create Vulkan instance, switching to OpenGL");
|
||||
graphicsApi = OpenGL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cmdLineParser.isSet(tdrOption))
|
||||
framesUntilTdr = cmdLineParser.value(tdrOption).toInt();
|
||||
|
||||
if (cmdLineParser.isSet(swOption))
|
||||
rhiFlags |= QRhi::PreferSoftwareRenderer;
|
||||
|
||||
// Create and show the window.
|
||||
Window w;
|
||||
#if QT_CONFIG(vulkan)
|
||||
if (graphicsApi == Vulkan)
|
||||
w.setVulkanInstance(&inst);
|
||||
#endif
|
||||
w.resize(1280, 720);
|
||||
w.setTitle(QCoreApplication::applicationName() + QLatin1String(" - ") + graphicsApiName());
|
||||
w.show();
|
||||
|
||||
if (cmdLineParser.isSet(sdOption))
|
||||
QTimer::singleShot(5000, qGuiApp, SLOT(quit()));
|
||||
|
||||
int ret = app.exec();
|
||||
|
||||
// Window::event() will not get invoked when the
|
||||
// PlatformSurfaceAboutToBeDestroyed event is sent during the QWindow
|
||||
// destruction. That happens only when exiting via app::quit() instead of
|
||||
// the more common QWindow::close(). Take care of it: if the
|
||||
// QPlatformWindow is still around (there was no close() yet), get rid of
|
||||
// the swapchain while it's not too late.
|
||||
if (w.handle())
|
||||
w.releaseSwapChain();
|
||||
|
||||
return ret;
|
||||
}
|
BIN
tests/manual/rhi/shared/qt256.png
Normal file
BIN
tests/manual/rhi/shared/qt256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
BIN
tests/manual/rhi/shared/qt256_bc1_9mips.dds
Normal file
BIN
tests/manual/rhi/shared/qt256_bc1_9mips.dds
Normal file
Binary file not shown.
18
tests/manual/rhi/shared/texture.frag
Normal file
18
tests/manual/rhi/shared/texture.frag
Normal file
@ -0,0 +1,18 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec2 v_texcoord;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
int flip;
|
||||
} ubuf;
|
||||
|
||||
layout(binding = 1) uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(tex, v_texcoord);
|
||||
fragColor = vec4(c.rgb * c.a, c.a);
|
||||
}
|
BIN
tests/manual/rhi/shared/texture.frag.qsb
Normal file
BIN
tests/manual/rhi/shared/texture.frag.qsb
Normal file
Binary file not shown.
21
tests/manual/rhi/shared/texture.vert
Normal file
21
tests/manual/rhi/shared/texture.vert
Normal file
@ -0,0 +1,21 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec4 position;
|
||||
layout(location = 1) in vec2 texcoord;
|
||||
|
||||
layout(location = 0) out vec2 v_texcoord;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
int flip;
|
||||
} ubuf;
|
||||
|
||||
out gl_PerVertex { vec4 gl_Position; };
|
||||
|
||||
void main()
|
||||
{
|
||||
v_texcoord = vec2(texcoord.x, texcoord.y);
|
||||
if (ubuf.flip != 0)
|
||||
v_texcoord.y = 1.0 - v_texcoord.y;
|
||||
gl_Position = ubuf.mvp * position;
|
||||
}
|
BIN
tests/manual/rhi/shared/texture.vert.qsb
Normal file
BIN
tests/manual/rhi/shared/texture.vert.qsb
Normal file
Binary file not shown.
19
tests/manual/rhi/shared/texture_arr.frag
Normal file
19
tests/manual/rhi/shared/texture_arr.frag
Normal file
@ -0,0 +1,19 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec2 v_texcoord;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
int flip;
|
||||
int array_index;
|
||||
};
|
||||
|
||||
layout(binding = 1) uniform sampler2DArray texArr;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(texArr, vec3(v_texcoord, float(array_index)));
|
||||
fragColor = vec4(c.rgb * c.a, c.a);
|
||||
}
|
BIN
tests/manual/rhi/shared/texture_arr.frag.qsb
Normal file
BIN
tests/manual/rhi/shared/texture_arr.frag.qsb
Normal file
Binary file not shown.
20
tests/manual/rhi/shared/texture_arr.vert
Normal file
20
tests/manual/rhi/shared/texture_arr.vert
Normal file
@ -0,0 +1,20 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec4 position;
|
||||
layout(location = 1) in vec2 texcoord;
|
||||
|
||||
layout(location = 0) out vec2 v_texcoord;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
int flip;
|
||||
int array_index;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
v_texcoord = vec2(texcoord.x, texcoord.y);
|
||||
if (flip != 0)
|
||||
v_texcoord.y = 1.0 - v_texcoord.y;
|
||||
gl_Position = mvp * position;
|
||||
}
|
BIN
tests/manual/rhi/shared/texture_arr.vert.qsb
Normal file
BIN
tests/manual/rhi/shared/texture_arr.vert.qsb
Normal file
Binary file not shown.
20
tests/manual/rhi/shared/texture_ms4.frag
Normal file
20
tests/manual/rhi/shared/texture_ms4.frag
Normal file
@ -0,0 +1,20 @@
|
||||
#version 440
|
||||
|
||||
layout(location = 0) in vec2 v_texcoord;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 mvp;
|
||||
int flip;
|
||||
} ubuf;
|
||||
|
||||
layout(binding = 1) uniform sampler2DMS tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * v_texcoord));
|
||||
vec4 c = texelFetch(tex, tc, 0) + texelFetch(tex, tc, 1) + texelFetch(tex, tc, 2) + texelFetch(tex, tc, 3);
|
||||
c /= 4.0;
|
||||
fragColor = vec4(c.rgb * c.a, c.a);
|
||||
}
|
BIN
tests/manual/rhi/shared/texture_ms4.frag.qsb
Normal file
BIN
tests/manual/rhi/shared/texture_ms4.frag.qsb
Normal file
Binary file not shown.
Reference in New Issue
Block a user