summaryrefslogtreecommitdiffstats
path: root/tests/manual/deferred-renderer-cpp/gbuffer.cpp
blob: 489b785cd096dd1ef5167f39cf6d0a09bb4d6fde (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "gbuffer.h"

GBuffer::GBuffer(Qt3DCore::QNode *parent)
    : Qt3DRender::QRenderTarget(parent)
{
    const Qt3DRender::QAbstractTexture::TextureFormat formats[AttachmentsCount] = {
        Qt3DRender::QAbstractTexture::RGBA32F,
        // We use RGBA32F for the following two instead of a more fitting format because
        // OpenGL vendors might not support other formats
        Qt3DRender::QAbstractTexture::RGBA32F,
        Qt3DRender::QAbstractTexture::RGBA32F,
        Qt3DRender::QAbstractTexture::D32F
    };

    const Qt3DRender::QRenderTargetOutput::AttachmentPoint attachmentPoints[AttachmentsCount] = {
        Qt3DRender::QRenderTargetOutput::Color0,
        Qt3DRender::QRenderTargetOutput::Color1,
        Qt3DRender::QRenderTargetOutput::Color2,
        Qt3DRender::QRenderTargetOutput::Depth
    };

    for (int i = 0; i < AttachmentsCount; i++) {
        Qt3DRender::QRenderTargetOutput *output = new Qt3DRender::QRenderTargetOutput(this);

        m_textures[i] = new Qt3DRender::QTexture2D();
        m_textures[i]->setFormat(formats[i]);
        m_textures[i]->setWidth(1024);
        m_textures[i]->setHeight(1024);
        m_textures[i]->setGenerateMipMaps(false);
        m_textures[i]->setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToEdge));
        m_textures[i]->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear);
        m_textures[i]->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear);

        output->setTexture(m_textures[i]);
        output->setAttachmentPoint(attachmentPoints[i]);
        addOutput(output);
    }
}

Qt3DRender::QAbstractTexture *GBuffer::colorTexture() const
{
    return m_textures[Color];
}

Qt3DRender::QAbstractTexture *GBuffer::positionTexture() const
{
    return m_textures[Position];
}

Qt3DRender::QAbstractTexture *GBuffer::normalTexture() const
{
    return m_textures[Normal];
}

Qt3DRender::QAbstractTexture *GBuffer::depthTexture() const
{
    return m_textures[Depth];
}