qrhi.h 33.4 KB
Newer Older
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 42 43 44 45 46 47
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QRHI_H
#define QRHI_H

#include <QtRhi/qtrhiglobal.h>
#include <QVector4D>
#include <QVector2D>
#include <QSize>
#include <QMatrix4x4>
#include <QVector>
#include <QImage>
#include <QtShaderTools/QBakedShader>
48
#include <functional>
49 50 51 52

QT_BEGIN_NAMESPACE

class QWindow;
Laszlo Agocs's avatar
Laszlo Agocs committed
53 54 55 56 57
class QRhiImplementation;
class QRhiBuffer;
class QRhiRenderBuffer;
class QRhiTexture;
class QRhiSampler;
58 59
class QRhiCommandBuffer;
class QRhiResourceUpdateBatch;
Laszlo Agocs's avatar
Laszlo Agocs committed
60
class QRhiResourceUpdateBatchPrivate;
61
class QRhiProfiler;
62

Laszlo Agocs's avatar
Laszlo Agocs committed
63
class Q_RHI_EXPORT QRhiColorClearValue
64
{
Laszlo Agocs's avatar
Laszlo Agocs committed
65 66 67 68 69 70 71 72 73 74
public:
    QRhiColorClearValue() : m_rgba(0, 0, 0, 1) { }
    explicit QRhiColorClearValue(const QVector4D &c) : m_rgba(c) { }
    QRhiColorClearValue(float r, float g, float b, float a) : m_rgba(r, g, b, a) { }

    QVector4D rgba() const { return m_rgba; }
    void setRgba(const QVector4D &c) { m_rgba = c; }

private:
    QVector4D m_rgba;
75 76 77 78
};

Q_DECLARE_TYPEINFO(QRhiColorClearValue, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
79
class Q_RHI_EXPORT QRhiDepthStencilClearValue
80
{
Laszlo Agocs's avatar
Laszlo Agocs committed
81 82 83 84 85 86 87 88 89 90 91 92 93
public:
    QRhiDepthStencilClearValue() : m_d(1), m_s(0) { }
    QRhiDepthStencilClearValue(float d, quint32 s) : m_d(d), m_s(s) { }

    float depthClearValue() const { return m_d; }
    void setDepthClearValue(float d) { m_d = d; }

    quint32 stencilClearValue() const { return m_s; }
    void setStencilClearValue(quint32 s) { m_s = s; }

private:
    float m_d;
    quint32 m_s;
94 95 96 97
};

Q_DECLARE_TYPEINFO(QRhiDepthStencilClearValue, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
98
class Q_RHI_EXPORT QRhiViewport
99
{
Laszlo Agocs's avatar
Laszlo Agocs committed
100
public:
Laszlo Agocs's avatar
Laszlo Agocs committed
101
    QRhiViewport()
Laszlo Agocs's avatar
Laszlo Agocs committed
102
        : m_rect(0, 0, 1280, 720), m_minDepth(0), m_maxDepth(1)
Laszlo Agocs's avatar
Laszlo Agocs committed
103
    { }
Laszlo Agocs's avatar
Laszlo Agocs committed
104 105
    QRhiViewport(float x, float y, float w, float h, float minDepth = 0.0f, float maxDepth = 1.0f)
        : m_rect(x, y, w, h), m_minDepth(minDepth), m_maxDepth(maxDepth)
106
    { }
Laszlo Agocs's avatar
Laszlo Agocs committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120

    QVector4D viewport() const { return m_rect; }
    void setViewport(const QVector4D &v) { m_rect = v; }

    float minDepth() const { return m_minDepth; }
    void setMinDepth(float minDepth) { m_minDepth = minDepth; }

    float maxDepth() const { return m_maxDepth; }
    void setMaxDepth(float maxDepth) { m_maxDepth = maxDepth; }

private:
    QVector4D m_rect;
    float m_minDepth;
    float m_maxDepth;
121 122 123 124
};

Q_DECLARE_TYPEINFO(QRhiViewport, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
125
class Q_RHI_EXPORT QRhiScissor
126
{
Laszlo Agocs's avatar
Laszlo Agocs committed
127
public:
128 129
    QRhiScissor() { }
    QRhiScissor(int x, int y, int w, int h)
Laszlo Agocs's avatar
Laszlo Agocs committed
130
        : m_rect(x, y, w, h)
131
    { }
Laszlo Agocs's avatar
Laszlo Agocs committed
132 133 134 135 136 137

    QVector4D scissor() const { return m_rect; }
    void setScissor(const QVector4D &v) { m_rect = v; }

private:
    QVector4D m_rect;
138 139 140 141
};

Q_DECLARE_TYPEINFO(QRhiScissor, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
142
class Q_RHI_EXPORT QRhiVertexInputBinding
143
{
Laszlo Agocs's avatar
Laszlo Agocs committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
public:
    enum Classification {
        PerVertex,
        PerInstance
    };

    QRhiVertexInputBinding() { }
    QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, int stepRate = 1)
        : m_stride(stride), m_classification(cls), m_instanceStepRate(stepRate)
    { }

    quint32 stride() const { return m_stride; }
    void setStride(quint32 s) { m_stride = s; }

    Classification classification() const { return m_classification; }
    void setClassification(Classification c) { m_classification = c; }

    int instanceStepRate() const { return m_instanceStepRate; }
    void setInstanceStepRate(int rate) { m_instanceStepRate = rate; }

private:
    quint32 m_stride;
    Classification m_classification;
    int m_instanceStepRate;
};

Q_DECLARE_TYPEINFO(QRhiVertexInputBinding, Q_MOVABLE_TYPE);

class Q_RHI_EXPORT QRhiVertexInputAttribute
{
public:
    enum Format {
        Float4,
        Float3,
        Float2,
        Float,
        UNormByte4,
        UNormByte2,
        UNormByte
    };

    QRhiVertexInputAttribute() { }
    QRhiVertexInputAttribute(int binding, int location, Format format, quint32 offset)
        : m_binding(binding), m_location(location), m_format(format), m_offset(offset)
    { }

    int binding() const { return m_binding; }
    void setBinding(int b) { m_binding = b; }

    int location() const { return m_location; }
    void setLocation(int loc) { m_location = loc; }

    Format format() const { return m_format; }
    void setFormt(Format f) { m_format = f; }

    quint32 offset() const { return m_offset; }
    void setOffset(quint32 ofs) { m_offset = ofs; }

private:
    int m_binding;
    int m_location;
    Format m_format;
    quint32 m_offset;
};

Q_DECLARE_TYPEINFO(QRhiVertexInputAttribute, Q_MOVABLE_TYPE);

class Q_RHI_EXPORT QRhiVertexInputLayout
{
public:
    QVector<QRhiVertexInputBinding> bindings() const { return m_bindings; }
    void setBindings(const QVector<QRhiVertexInputBinding> &v) { m_bindings = v; }

    QVector<QRhiVertexInputAttribute> attributes() const { return m_attributes; }
    void setAttributes(const QVector<QRhiVertexInputAttribute> &v) { m_attributes = v; }

private:
    QVector<QRhiVertexInputBinding> m_bindings;
    QVector<QRhiVertexInputAttribute> m_attributes;
223 224 225 226
};

Q_DECLARE_TYPEINFO(QRhiVertexInputLayout, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
227
class Q_RHI_EXPORT QRhiGraphicsShaderStage
228
{
Laszlo Agocs's avatar
Laszlo Agocs committed
229
public:
230 231 232
    enum Type {
        Vertex,
        Fragment,
233 234
        TessellationControl,
        TessellationEvaluation
235 236 237
    };

    QRhiGraphicsShaderStage() { }
Laszlo Agocs's avatar
Laszlo Agocs committed
238 239
    QRhiGraphicsShaderStage(Type type, const QBakedShader &shader)
        : m_type(type), m_shader(shader)
240 241
    { }

Laszlo Agocs's avatar
Laszlo Agocs committed
242 243 244 245 246 247 248 249 250
    Type type() const { return m_type; }
    void setType(Type t) { m_type = t; }

    QBakedShader shader() const { return m_shader; }
    void setShader(const QBakedShader &s) { m_shader = s; }

private:
    Type m_type;
    QBakedShader m_shader;
251 252 253 254
};

Q_DECLARE_TYPEINFO(QRhiGraphicsShaderStage, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
255 256 257 258 259 260 261 262 263 264
struct Q_RHI_EXPORT QRhiShaderResourceBinding
{
    enum Type {
        UniformBuffer,
        SampledTexture
    };

    enum StageFlag {
        VertexStage = 1 << 0,
        FragmentStage = 1 << 1,
265 266
        TessellationControlStage = 1 << 2,
        TessellationEvaluationStage = 1 << 3
Laszlo Agocs's avatar
Laszlo Agocs committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    };
    Q_DECLARE_FLAGS(StageFlags, StageFlag)

    static QRhiShaderResourceBinding uniformBuffer(int binding_, StageFlags stage_, QRhiBuffer *buf_);
    static QRhiShaderResourceBinding uniformBuffer(int binding_, StageFlags stage_, QRhiBuffer *buf_, int offset_, int size_);
    static QRhiShaderResourceBinding sampledTexture(int binding_, StageFlags stage_, QRhiTexture *tex_, QRhiSampler *sampler_);

    int binding;
    StageFlags stage;
    Type type;
    struct UniformBufferData {
        QRhiBuffer *buf;
        int offset;
        int maybeSize;
    };
    struct SampledTextureData {
        QRhiTexture *tex;
        QRhiSampler *sampler;
    };
    union {
        UniformBufferData ubuf;
        SampledTextureData stex;
    };
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_MOVABLE_TYPE);

Laszlo Agocs's avatar
Laszlo Agocs committed
295
class Q_RHI_EXPORT QRhiColorAttachment
Laszlo Agocs's avatar
Laszlo Agocs committed
296
{
Laszlo Agocs's avatar
Laszlo Agocs committed
297 298 299 300
public:
    QRhiColorAttachment() { }
    QRhiColorAttachment(QRhiTexture *texture) : m_texture(texture) { }
    QRhiColorAttachment(QRhiRenderBuffer *renderBuffer) : m_renderBuffer(renderBuffer) { }
301

Laszlo Agocs's avatar
Laszlo Agocs committed
302 303
    QRhiTexture *texture() const { return m_texture; }
    void setTexture(QRhiTexture *tex) { m_texture = tex; }
304

Laszlo Agocs's avatar
Laszlo Agocs committed
305 306
    QRhiRenderBuffer *renderBuffer() const { return m_renderBuffer; }
    void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; }
307

Laszlo Agocs's avatar
Laszlo Agocs committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    int layer() const { return m_layer; }
    void setLayer(int layer) { m_layer = layer; }

    int level() const { return m_level; }
    void setLevel(int level) { m_level = level; }

    QRhiTexture *resolveTexture() const { return m_resolveTexture; }
    void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; }

    int resolveLayer() const { return m_resolveLayer; }
    void setResolveLayer(int layer) { m_resolveLayer = layer; }

    int resolveLevel() const { return m_resolveLevel; }
    void setResolveLevel(int level) { m_resolveLevel = level; }

private:
    QRhiTexture *m_texture = nullptr;
    QRhiRenderBuffer *m_renderBuffer = nullptr;

    int m_layer = 0;
    int m_level = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
329

Laszlo Agocs's avatar
Laszlo Agocs committed
330 331 332 333 334 335 336 337 338 339
    QRhiTexture *m_resolveTexture = nullptr;
    int m_resolveLayer = 0;
    int m_resolveLevel = 0;
};

Q_DECLARE_TYPEINFO(QRhiColorAttachment, Q_MOVABLE_TYPE);

class Q_RHI_EXPORT QRhiTextureRenderTargetDescription
{
public:
Laszlo Agocs's avatar
Laszlo Agocs committed
340 341
    QRhiTextureRenderTargetDescription()
    { }
Laszlo Agocs's avatar
Laszlo Agocs committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
    QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment)
    { m_colorAttachments.append(colorAttachment); }
    QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer)
        : m_depthStencilBuffer(depthStencilBuffer)
    { m_colorAttachments.append(colorAttachment); }
    QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture)
        : m_depthTexture(depthTexture)
    { m_colorAttachments.append(colorAttachment); }

    QVector<QRhiColorAttachment> colorAttachments() const { return m_colorAttachments; }
    void setColorAttachments(const QVector<QRhiColorAttachment> &att) { m_colorAttachments = att; }

    QRhiRenderBuffer *depthStencilBuffer() const { return m_depthStencilBuffer; }
    void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; }

    QRhiTexture *depthTexture() const { return m_depthTexture; }
    void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }

private:
    QVector<QRhiColorAttachment> m_colorAttachments;
    QRhiRenderBuffer *m_depthStencilBuffer = nullptr;
    QRhiTexture *m_depthTexture = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
364 365 366 367 368 369 370 371 372 373
};

Q_DECLARE_TYPEINFO(QRhiTextureRenderTargetDescription, Q_MOVABLE_TYPE);

struct Q_RHI_EXPORT QRhiTextureUploadDescription
{
    struct Q_RHI_EXPORT Layer {
        struct Q_RHI_EXPORT MipLevel {
            MipLevel() { }
            MipLevel(const QImage &image_) : image(image_) { }
374
            MipLevel(const QByteArray &compressedData_) : compressedData(compressedData_) { }
375

Laszlo Agocs's avatar
Laszlo Agocs committed
376
            QImage image;
377
            QByteArray compressedData;
378

379
            QPoint destinationTopLeft;
380 381
            QSize sourceSize;
            QPoint sourceTopLeft;
Laszlo Agocs's avatar
Laszlo Agocs committed
382
        };
383

Laszlo Agocs's avatar
Laszlo Agocs committed
384 385 386 387
        Layer() { }
        Layer(const QVector<MipLevel> &mipImages_) : mipImages(mipImages_) { }
        QVector<MipLevel> mipImages;
    };
388

Laszlo Agocs's avatar
Laszlo Agocs committed
389 390
    QRhiTextureUploadDescription() { }
    QRhiTextureUploadDescription(const QVector<Layer> &layers_) : layers(layers_) { }
391
    QVector<Layer> layers;
Laszlo Agocs's avatar
Laszlo Agocs committed
392 393 394 395 396 397
};

Q_DECLARE_TYPEINFO(QRhiTextureUploadDescription::Layer::MipLevel, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(QRhiTextureUploadDescription::Layer, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(QRhiTextureUploadDescription, Q_MOVABLE_TYPE);

398 399
struct Q_RHI_EXPORT QRhiTextureCopyDescription
{
400
    QSize pixelSize;
401 402 403

    int sourceLayer = 0;
    int sourceLevel = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
404
    QPoint sourceTopLeft;
405 406 407

    int destinationLayer = 0;
    int destinationLevel = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
408
    QPoint destinationTopLeft;
409 410 411 412
};

Q_DECLARE_TYPEINFO(QRhiTextureCopyDescription, Q_MOVABLE_TYPE);

413
struct Q_RHI_EXPORT QRhiReadbackDescription
Laszlo Agocs's avatar
Laszlo Agocs committed
414
{
415 416
    QRhiReadbackDescription() { }
    QRhiReadbackDescription(QRhiTexture *texture_) : texture(texture_) { }
417

418 419 420
    QRhiTexture *texture = nullptr;
    int layer = 0;
    int level = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
421 422
};

423 424
Q_DECLARE_TYPEINFO(QRhiReadbackDescription, Q_MOVABLE_TYPE);

425 426 427 428
struct Q_RHI_EXPORT QRhiNativeHandles
{
};

429 430 431 432
class Q_RHI_EXPORT QRhiResource
{
public:
    virtual ~QRhiResource();
433

434 435 436
    virtual void release() = 0;
    void releaseAndDestroy();

437 438 439
    QByteArray name() const;
    void setName(const QByteArray &name);

440 441 442
protected:
    QRhiResource(QRhiImplementation *rhi_);
    Q_DISABLE_COPY(QRhiResource)
443 444
    QRhiImplementation *rhi = nullptr;
    QByteArray objectName;
445 446 447 448 449 450
};

class Q_RHI_EXPORT QRhiBuffer : public QRhiResource
{
public:
    enum Type {
451 452 453
        Immutable,
        Static,
        Dynamic
454 455 456 457 458 459 460 461 462
    };

    enum UsageFlag {
        VertexBuffer = 1 << 0,
        IndexBuffer = 1 << 1,
        UniformBuffer = 1 << 2
    };
    Q_DECLARE_FLAGS(UsageFlags, UsageFlag)

Laszlo Agocs's avatar
Laszlo Agocs committed
463 464 465 466 467 468 469 470
    Type type() const { return m_type; }
    void setType(Type t) { m_type = t; }

    UsageFlags usage() const { return m_usage; }
    void setUsage(UsageFlags u) { m_usage = u; }

    int size() const { return m_size; }
    void setSize(int sz) { m_size = sz; }
471 472 473 474 475

    virtual bool build() = 0;

protected:
    QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_);
Laszlo Agocs's avatar
Laszlo Agocs committed
476 477
    Type m_type;
    UsageFlags m_usage;
478
    int m_size;
Laszlo Agocs's avatar
Laszlo Agocs committed
479
    void *m_reserved;
480 481 482 483 484 485 486 487 488
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)

class Q_RHI_EXPORT QRhiTexture : public QRhiResource
{
public:
    enum Flag {
        RenderTarget = 1 << 0,
489
        ChangesFrequently = 1 << 1,
490
        CubeMap = 1 << 2,
491
        MipMapped = 1 << 3,
492
        sRGB = 1 << 4,
493
        UsedAsTransferSource = 1 << 5,
494
        UsedWithGenerateMips = 1 << 6
495 496 497 498
    };
    Q_DECLARE_FLAGS(Flags, Flag)

    enum Format {
499 500
        UnknownFormat,

501 502 503 504 505 506
        RGBA8,
        BGRA8,
        R8,
        R16,

        D16,
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
        D32,

        BC1,
        BC2,
        BC3,
        BC4,
        BC5,
        BC6H,
        BC7,

        ETC2_RGB8,
        ETC2_RGB8A1,
        ETC2_RGBA8,

        ASTC_4x4,
        ASTC_5x4,
        ASTC_5x5,
        ASTC_6x5,
        ASTC_6x6,
        ASTC_8x5,
        ASTC_8x6,
        ASTC_8x8,
        ASTC_10x5,
        ASTC_10x6,
        ASTC_10x8,
        ASTC_10x10,
        ASTC_12x10,
        ASTC_12x12
535 536
    };

Laszlo Agocs's avatar
Laszlo Agocs committed
537 538 539 540 541 542 543 544
    Format format() const { return m_format; }
    void setFormat(Format fmt) { m_format = fmt; }

    QSize pixelSize() const { return m_pixelSize; }
    void setPixelSize(const QSize &sz) { m_pixelSize = sz; }

    Flags flags() const { return m_flags; }
    void setFlags(Flags f) { m_flags = f; }
545

Laszlo Agocs's avatar
Laszlo Agocs committed
546 547 548
    int sampleCount() const { return m_sampleCount; }
    void setSampleCount(int s) { m_sampleCount = s; }

549
    virtual bool build() = 0;
550 551
    virtual const QRhiNativeHandles *nativeHandles();
    virtual bool buildFrom(const QRhiNativeHandles *src);
552

553
protected:
Laszlo Agocs's avatar
Laszlo Agocs committed
554 555
    QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_,
                int sampleCount_, Flags flags_);
Laszlo Agocs's avatar
Laszlo Agocs committed
556 557
    Format m_format;
    QSize m_pixelSize;
Laszlo Agocs's avatar
Laszlo Agocs committed
558
    int m_sampleCount;
Laszlo Agocs's avatar
Laszlo Agocs committed
559
    Flags m_flags;
Laszlo Agocs's avatar
Laszlo Agocs committed
560
    void *m_reserved;
561 562 563 564 565 566 567 568
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)

class Q_RHI_EXPORT QRhiSampler : public QRhiResource
{
public:
    enum Filter {
569
        None,
570 571 572 573 574 575 576 577 578 579 580 581
        Nearest,
        Linear
    };

    enum AddressMode {
        Repeat,
        ClampToEdge,
        Border,
        Mirror,
        MirrorOnce
    };

Laszlo Agocs's avatar
Laszlo Agocs committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
    Filter magFilter() const { return m_magFilter; }
    void setMagFilter(Filter f) { m_magFilter = f; }

    Filter minFilter() const { return m_minFilter; }
    void setMinFilter(Filter f) { m_minFilter = f; }

    Filter mipmapMode() const { return m_mipmapMode; }
    void setMipmapMode(Filter f) { m_mipmapMode = f; }

    AddressMode addressU() const { return m_addressU; }
    void setAddressU(AddressMode mode) { m_addressU = mode; }

    AddressMode addressV() const { return m_addressV; }
    void setAddressV(AddressMode mode) { m_addressV = mode; }

    AddressMode addressW() const { return m_addressW; }
    void setAddressW(AddressMode mode) { m_addressW = mode; }
599 600 601 602 603 604 605

    virtual bool build() = 0;

protected:
    QRhiSampler(QRhiImplementation *rhi,
                Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
                AddressMode u_, AddressMode v_, AddressMode w_);
Laszlo Agocs's avatar
Laszlo Agocs committed
606 607 608 609 610 611 612
    Filter m_magFilter;
    Filter m_minFilter;
    Filter m_mipmapMode;
    AddressMode m_addressU;
    AddressMode m_addressV;
    AddressMode m_addressW;
    void *m_reserved;
613 614
};

Laszlo Agocs's avatar
Laszlo Agocs committed
615 616 617 618 619 620 621 622 623
class Q_RHI_EXPORT QRhiRenderBuffer : public QRhiResource
{
public:
    enum Type {
        DepthStencil,
        Color
    };

    enum Flag {
624
        UsedWithSwapChainOnly = 1 << 0
Laszlo Agocs's avatar
Laszlo Agocs committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
    };
    Q_DECLARE_FLAGS(Flags, Flag)

    Type type() const { return m_type; }
    void setType(Type t) { m_type = t; }

    QSize pixelSize() const { return m_pixelSize; }
    void setPixelSize(const QSize &sz) { m_pixelSize = sz; }

    int sampleCount() const { return m_sampleCount; }
    void setSampleCount(int s) { m_sampleCount = s; }

    Flags flags() const { return m_flags; }
    void setFlags(Flags h) { m_flags = h; }

    virtual bool build() = 0;

    virtual QRhiTexture::Format backingFormat() const = 0;

protected:
    QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_,
                     int sampleCount_, Flags flags_);
    Type m_type;
    QSize m_pixelSize;
    int m_sampleCount;
    Flags m_flags;
    void *m_reserved;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)

656
class Q_RHI_EXPORT QRhiRenderPassDescriptor : public QRhiResource
657 658
{
protected:
659
    QRhiRenderPassDescriptor(QRhiImplementation *rhi);
Laszlo Agocs's avatar
Laszlo Agocs committed
660
    void *m_reserved;
661 662 663 664 665 666 667 668 669 670 671 672
};

class Q_RHI_EXPORT QRhiRenderTarget : public QRhiResource
{
public:
    enum Type {
        RtRef,
        RtTexture
    };

    virtual Type type() const = 0;
    virtual QSize sizeInPixels() const = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
673
    virtual float devicePixelRatio() const = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
674

675 676
    QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
    void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
677 678 679

protected:
    QRhiRenderTarget(QRhiImplementation *rhi);
680
    QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
681
    void *m_reserved;
682 683 684 685 686 687
};

class Q_RHI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget
{
public:
    enum Flag {
688 689
        PreserveColorContents = 1 << 0,
        PreserveDepthStencilContents = 1 << 1
690 691 692
    };
    Q_DECLARE_FLAGS(Flags, Flag)

Laszlo Agocs's avatar
Laszlo Agocs committed
693 694
    QRhiTextureRenderTargetDescription description() const { return m_desc; }
    void setDescription(const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
695

Laszlo Agocs's avatar
Laszlo Agocs committed
696 697 698
    Flags flags() const { return m_flags; }
    void setFlags(Flags f) { m_flags = f; }

699
    virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
700

701 702 703 704
    virtual bool build() = 0;

protected:
    QRhiTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
Laszlo Agocs's avatar
Laszlo Agocs committed
705 706
    QRhiTextureRenderTargetDescription m_desc;
    Flags m_flags;
707 708 709 710 711 712 713
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)

class Q_RHI_EXPORT QRhiShaderResourceBindings : public QRhiResource
{
public:
Laszlo Agocs's avatar
Laszlo Agocs committed
714 715
    QVector<QRhiShaderResourceBinding> bindings() const { return m_bindings; }
    void setBindings(const QVector<QRhiShaderResourceBinding> &b) { m_bindings = b; }
716 717 718 719 720

    virtual bool build() = 0;

protected:
    QRhiShaderResourceBindings(QRhiImplementation *rhi);
Laszlo Agocs's avatar
Laszlo Agocs committed
721 722
    QVector<QRhiShaderResourceBinding> m_bindings;
    void *m_reserved;
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
};

class Q_RHI_EXPORT QRhiGraphicsPipeline : public QRhiResource
{
public:
    enum Flag {
        UsesBlendConstants = 1 << 0,
        UsesStencilRef = 1 << 1,
        UsesScissor = 1 << 2
    };
    Q_DECLARE_FLAGS(Flags, Flag)

    enum Topology {
        Triangles,
        TriangleStrip,
        Lines,
        LineStrip,
        Points
    };

743
    enum CullMode {
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
        None,
        Front,
        Back
    };

    enum FrontFace {
        CCW,
        CW
    };

    enum ColorMaskComponent {
        R = 1 << 0,
        G = 1 << 1,
        B = 1 << 2,
        A = 1 << 3
    };
    Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)

    enum BlendFactor {
        Zero,
        One,
        SrcColor,
        OneMinusSrcColor,
        DstColor,
        OneMinusDstColor,
        SrcAlpha,
        OneMinusSrcAlpha,
        DstAlpha,
        OneMinusDstAlpha,
        ConstantColor,
        OneMinusConstantColor,
        ConstantAlpha,
        OneMinusConstantAlpha,
        SrcAlphaSaturate,
        Src1Color,
        OneMinusSrc1Color,
        Src1Alpha,
        OneMinusSrc1Alpha
    };

    enum BlendOp {
        Add,
        Subtract,
        ReverseSubtract,
        Min,
        Max
    };

    struct TargetBlend {
        ColorMask colorWrite = ColorMask(0xF); // R | G | B | A
        bool enable = false;
        BlendFactor srcColor = One;
        BlendFactor dstColor = OneMinusSrcAlpha;
        BlendOp opColor = Add;
        BlendFactor srcAlpha = One;
        BlendFactor dstAlpha = OneMinusSrcAlpha;
        BlendOp opAlpha = Add;
    };

    enum CompareOp {
        Never,
        Less,
        Equal,
        LessOrEqual,
        Greater,
        NotEqual,
        GreaterOrEqual,
        Always
    };

    enum StencilOp {
        StencilZero,
        Keep,
        Replace,
        IncrementAndClamp,
        DecrementAndClamp,
        Invert,
        IncrementAndWrap,
        DecrementAndWrap
    };

    struct StencilOpState {
        StencilOp failOp = Keep;
        StencilOp depthFailOp = Keep;
        StencilOp passOp = Keep;
        CompareOp compareOp = Always;
    };

Laszlo Agocs's avatar
Laszlo Agocs committed
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
    Flags flags() const { return m_flags; }
    void setFlags(Flags f) { m_flags = f; }

    Topology topology() const { return m_topology; }
    void setTopology(Topology t) { m_topology = t; }

    CullMode cullMode() const { return m_cullMode; }
    void setCullMode(CullMode mode) { m_cullMode = mode; }

    FrontFace frontFace() const { return m_frontFace; }
    void setFrontFace(FrontFace f) { m_frontFace = f; }

    QVector<TargetBlend> targetBlends() const { return m_targetBlends; }
    void setTargetBlends(const QVector<TargetBlend> &blends) { m_targetBlends = blends; }

    bool hasDepthTest() const { return m_depthTest; }
    void setDepthTest(bool enable) { m_depthTest = enable; }

    bool hasDepthWrite() const { return m_depthWrite; }
    void setDepthWrite(bool enable) { m_depthWrite = enable; }

    CompareOp depthOp() const { return m_depthOp; }
    void setDepthOp(CompareOp op) { m_depthOp = op; }

    bool hasStencilTest() const { return m_stencilTest; }
    void setStencilTest(bool enable) { m_stencilTest = enable; }

    StencilOpState stencilFront() const { return m_stencilFront; }
    void setStencilFront(const StencilOpState &state) { m_stencilFront = state; }

    StencilOpState stencilBack() const { return m_stencilBack; }
    void setStencilBack(const StencilOpState &state) { m_stencilBack = state; }

    quint32 stencilReadMask() const { return m_stencilReadMask; }
    void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }

    quint32 stencilWriteMask() const { return m_stencilWriteMask; }
    void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }

    int sampleCount() const { return m_sampleCount; }
    void setSampleCount(int s) { m_sampleCount = s; }

    QVector<QRhiGraphicsShaderStage> shaderStages() const { return m_shaderStages; }
    void setShaderStages(const QVector<QRhiGraphicsShaderStage> &stages) { m_shaderStages = stages; }

    QRhiVertexInputLayout vertexInputLayout() const { return m_vertexInputLayout; }
    void setVertexInputLayout(const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }

    QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; }
    void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }

883 884
    QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
    void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
885 886 887 888 889

    virtual bool build() = 0;

protected:
    QRhiGraphicsPipeline(QRhiImplementation *rhi);
Laszlo Agocs's avatar
Laszlo Agocs committed
890 891 892 893
    Flags m_flags;
    Topology m_topology = Triangles;
    CullMode m_cullMode = None;
    FrontFace m_frontFace = CCW;
894
    QVector<TargetBlend> m_targetBlends;
Laszlo Agocs's avatar
Laszlo Agocs committed
895 896 897 898 899 900
    bool m_depthTest = false;
    bool m_depthWrite = false;
    CompareOp m_depthOp = Less;
    bool m_stencilTest = false;
    StencilOpState m_stencilFront;
    StencilOpState m_stencilBack;
901 902 903
    quint32 m_stencilReadMask = 0xFF;
    quint32 m_stencilWriteMask = 0xFF;
    int m_sampleCount = 1;
Laszlo Agocs's avatar
Laszlo Agocs committed
904 905
    QVector<QRhiGraphicsShaderStage> m_shaderStages;
    QRhiVertexInputLayout m_vertexInputLayout;
906
    QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr;
907
    QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
908
    void *m_reserved;
909 910 911 912 913 914 915 916 917
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_MOVABLE_TYPE);

class Q_RHI_EXPORT QRhiSwapChain : public QRhiResource
{
public:
918
    enum Flag {
919
        SurfaceHasPreMulAlpha = 1 << 0,
920
        SurfaceHasNonPreMulAlpha = 1 << 1,
921
        sRGB = 1 << 2,
922 923
        UsedAsTransferSource = 1 << 3,
        NoVSync = 1 << 4
924
    };
925
    Q_DECLARE_FLAGS(Flags, Flag)
926

Laszlo Agocs's avatar
Laszlo Agocs committed
927 928 929
    QWindow *window() const { return m_window; }
    void setWindow(QWindow *window) { m_window = window; }

930 931
    Flags flags() const { return m_flags; }
    void setFlags(Flags f) { m_flags = f; }
Laszlo Agocs's avatar
Laszlo Agocs committed
932 933 934 935 936 937 938

    QRhiRenderBuffer *depthStencil() const { return m_depthStencil; }
    void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }

    int sampleCount() const { return m_sampleCount; }
    void setSampleCount(int samples) { m_sampleCount = samples; }

939 940
    QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
    void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
Laszlo Agocs's avatar
Laszlo Agocs committed
941

Laszlo Agocs's avatar
Laszlo Agocs committed
942 943 944
    QObject *target() const { return m_target; }
    void setTarget(QObject *obj) { m_target = obj; }

945 946
    QSize currentPixelSize() const { return m_currentPixelSize; }

947 948
    virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
    virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
949
    virtual QSize surfacePixelSize() = 0;
950
    virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
951
    virtual bool buildOrResize() = 0;
952 953 954

protected:
    QRhiSwapChain(QRhiImplementation *rhi);
Laszlo Agocs's avatar
Laszlo Agocs committed
955
    QWindow *m_window = nullptr;
956
    Flags m_flags;
Laszlo Agocs's avatar
Laszlo Agocs committed
957 958
    QRhiRenderBuffer *m_depthStencil = nullptr;
    int m_sampleCount = 1;
959
    QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
960
    QObject *m_target = nullptr;
961
    QSize m_currentPixelSize;
Laszlo Agocs's avatar
Laszlo Agocs committed
962
    void *m_reserved;
963 964
};

965
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
966

967 968 969 970 971 972 973 974
class Q_RHI_EXPORT QRhiCommandBuffer : public QRhiResource
{
public:
    enum IndexFormat {
        IndexUInt16,
        IndexUInt32
    };

975 976
    void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);

977
    void beginPass(QRhiRenderTarget *rt,
978 979
                   const QRhiColorClearValue &colorClearValue,
                   const QRhiDepthStencilClearValue &depthStencilClearValue,
980
                   QRhiResourceUpdateBatch *resourceUpdates = nullptr);
981
    void endPass(QRhiResourceUpdateBatch *resourceUpdates = nullptr);
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006

    void setGraphicsPipeline(QRhiGraphicsPipeline *ps,
                             QRhiShaderResourceBindings *srb = nullptr);

    using VertexInput = QPair<QRhiBuffer *, quint32>; // buffer, offset
    void setVertexInput(int startBinding, const QVector<VertexInput> &bindings,
                        QRhiBuffer *indexBuf = nullptr, quint32 indexOffset = 0,
                        IndexFormat indexFormat = IndexUInt16);

    void setViewport(const QRhiViewport &viewport);
    void setScissor(const QRhiScissor &scissor);
    void setBlendConstants(const QVector4D &c);
    void setStencilRef(quint32 refValue);

    void draw(quint32 vertexCount,
              quint32 instanceCount = 1,
              quint32 firstVertex = 0,
              quint32 firstInstance = 0);

    void drawIndexed(quint32 indexCount,
                     quint32 instanceCount = 1,
                     quint32 firstIndex = 0,
                     qint32 vertexOffset = 0,
                     quint32 firstInstance = 0);

1007 1008 1009 1010
    void debugMarkBegin(const QByteArray &name);
    void debugMarkEnd();
    void debugMarkMsg(const QByteArray &msg);

1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
protected:
    QRhiCommandBuffer(QRhiImplementation *rhi);
    void *m_reserved;
};

struct Q_RHI_EXPORT QRhiReadbackResult
{
    std::function<void()> completed = nullptr;
    QRhiTexture::Format format;
    QSize pixelSize;
    QByteArray data;
}; // non-movable due to the std::function
1023

1024
class Q_RHI_EXPORT QRhiResourceUpdateBatch
1025 1026
{
public:
1027 1028 1029 1030 1031 1032
    enum TexturePrepareFlag {
        TextureRead = 1 << 0,
        TextureWrite = 1 << 1
    };
    Q_DECLARE_FLAGS(TexturePrepareFlags, TexturePrepareFlag)

1033
    ~QRhiResourceUpdateBatch();
1034

1035 1036
    void release();

1037 1038
    void merge(QRhiResourceUpdateBatch *other);

1039
    void updateDynamicBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
1040
    void uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
1041
    void uploadStaticBuffer(QRhiBuffer *buf, const void *data);
Laszlo Agocs's avatar
Laszlo Agocs committed
1042
    void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc);
1043
    void uploadTexture(QRhiTexture *tex, const QImage &image);
1044
    void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1045
    void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1046
    void generateMips(QRhiTexture *tex);
1047

1048 1049
    void prepareTextureForUse(QRhiTexture *tex, TexturePrepareFlags flags);

1050 1051 1052 1053
private:
    QRhiResourceUpdateBatch(QRhiImplementation *rhi);
    Q_DISABLE_COPY(QRhiResourceUpdateBatch)
    QRhiResourceUpdateBatchPrivate *d;
Laszlo Agocs's avatar
Laszlo Agocs committed
1054
    friend class QRhiResourceUpdateBatchPrivate;
1055 1056 1057
    friend class QRhi;
};

1058 1059
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiResourceUpdateBatch::TexturePrepareFlags)

1060 1061 1062 1063 1064 1065 1066 1067
struct Q_RHI_EXPORT QRhiInitParams
{
};

class Q_RHI_EXPORT QRhi
{
public:
    enum Implementation {
Laszlo Agocs's avatar
Laszlo Agocs committed
1068
        Null,
1069 1070 1071 1072 1073 1074
        Vulkan,
        OpenGLES2,
        D3D11,
        Metal
    };

1075
    enum Flag {
1076 1077
        EnableProfiling = 1 << 0,
        EnableDebugMarkers = 1 << 1
1078 1079 1080
    };
    Q_DECLARE_FLAGS(Flags, Flag)

1081 1082 1083 1084 1085 1086 1087
    enum FrameOpResult {
        FrameOpSuccess = 0,
        FrameOpError,
        FrameOpSwapChainOutOfDate,
        FrameOpDeviceLost
    };

1088 1089
    enum Feature {
        MultisampleTexture = 1,
1090
        MultisampleRenderBuffer,
1091
        DebugMarkers,
1092 1093
        Timestamps,
        Instancing,
1094 1095
        CustomInstanceStepRate,
        PrimitiveRestart
1096 1097
    };

1098 1099 1100 1101 1102
    enum ResourceSizeLimit {
        TextureSizeMin = 1,
        TextureSizeMax
    };

1103 1104
    ~QRhi();

1105
    static QRhi *create(Implementation impl, QRhiInitParams *params, Flags flags = Flags());
1106

1107 1108
    QRhiGraphicsPipeline *newGraphicsPipeline();
    QRhiShaderResourceBindings *newShaderResourceBindings();
1109

1110 1111 1112
    QRhiBuffer *newBuffer(QRhiBuffer::Type type,
                          QRhiBuffer::UsageFlags usage,
                          int size);
1113

1114 1115 1116
    QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
                                      const QSize &pixelSize,
                                      int sampleCount = 1,
Laszlo Agocs's avatar
Laszlo Agocs committed
1117
                                      QRhiRenderBuffer::Flags flags = QRhiRenderBuffer::Flags());
1118

1119 1120
    QRhiTexture *newTexture(QRhiTexture::Format format,
                            const QSize &pixelSize,
Laszlo Agocs's avatar
Laszlo Agocs committed
1121
                            int sampleCount = 1,
1122
                            QRhiTexture::Flags flags = QRhiTexture::Flags());
1123

1124 1125 1126
    QRhiSampler *newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
                            QRhiSampler::Filter mipmapMode,
                            QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w = QRhiSampler::ClampToEdge);
1127

1128 1129
    QRhiTextureRenderTarget *newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
                                                    QRhiTextureRenderTarget::Flags flags = QRhiTextureRenderTarget::Flags());
1130

1131
    QRhiSwapChain *newSwapChain();
1132 1133 1134
    FrameOpResult beginFrame(QRhiSwapChain *swapChain);
    FrameOpResult endFrame(QRhiSwapChain *swapChain);

1135
    FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb);
1136 1137 1138
    FrameOpResult endOffscreenFrame();

    QRhi::FrameOpResult finish();
1139

1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
    QRhiResourceUpdateBatch *nextResourceUpdateBatch();

    QVector<int> supportedSampleCounts() const;

    int ubufAlignment() const;
    int ubufAligned(int v) const;

    int mipLevelsForSize(const QSize &size) const;
    QSize sizeForMipLevel(int mipLevel, const QSize &baseLevelSize) const;

    bool isYUpInFramebuffer() const;

    QMatrix4x4 clipSpaceCorrMatrix() const;

1154
    bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = QRhiTexture::Flags()) const;
1155
    bool isFeatureSupported(QRhi::Feature feature) const;
1156
    int resourceSizeLimit(ResourceSizeLimit limit) const;
1157

1158 1159
    const QRhiNativeHandles *nativeHandles();

1160
    QRhiProfiler *profiler();
1161

1162 1163 1164 1165 1166 1167 1168 1169
protected:
    QRhi();

private:
    Q_DISABLE_COPY(QRhi)
    QRhiImplementation *d = nullptr;
};

1170 1171
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)

1172 1173 1174
QT_END_NAMESPACE

#endif