-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
41 lines (32 loc) · 1.22 KB
/
MainWindow.cpp
File metadata and controls
41 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <print>
#include <rhi/qrhi.h>
#include "MainWindow.h"
MainWindow::MainWindow()
{
QObject::connect(this, &QQuickWindow::afterRendering, this, [this] { onAfterRendering_(); }, Qt::DirectConnection);
}
void MainWindow::onAfterRendering_()
{
const unsigned int texel = 0xc0540814;
QRhiCommandBuffer* cb = swapChain()->currentFrameCommandBuffer();
QRhiResourceUpdateBatch* rub = rhi()->nextResourceUpdateBatch();
if (!tex_) {
std::println("Qt version: {}", qVersion());
std::println("RHI backend: {}\n", rhi()->backendName());
tex_ = rhi()->newTexture(QRhiTexture::RGBA8, { 1, 1 }, 1, QRhiTexture::UsedAsTransferSource);
tex_->create();
rub->uploadTexture(tex_, { {0, 0, {&texel, 4}} });
rhi()->addCleanupCallback([this](QRhi*) { delete tex_; });
}
const int i = readBackIndex_++;
QRhiReadbackResult* rr = new QRhiReadbackResult;
rr->completed = [i, rr, texel] {
std::println("Readback {} complete", i);
assert(*reinterpret_cast<const unsigned int*>(rr->data.data()) == texel);
delete rr;
};
rub->readBackTexture(tex_, rr);
cb->resourceUpdate(rub);
std::println("Readback {} started", i);
update();
}