1 /****************************************************************************
2 **
3 ** Copyright (C) 2008-2012 NVIDIA Corporation.
4 ** Copyright (C) 2019 The Qt Company Ltd.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of Qt Quick 3D.
8 **
9 ** $QT_BEGIN_LICENSE:GPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 or (at your option) any later version
21 ** approved by the KDE Free Qt Foundation. The licenses are as published by
22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30 
31 #include <QtQuick3DRender/private/qssgrenderbasetypes_p.h>
32 #include <QtQuick3DRender/private/qssgrenderprogrampipeline_p.h>
33 #include <QtQuick3DRender/private/qssgrendershaderprogram_p.h>
34 
35 QT_BEGIN_NAMESPACE
36 
QSSGRenderProgramPipeline(const QSSGRef<QSSGRenderContext> & context)37 QSSGRenderProgramPipeline::QSSGRenderProgramPipeline(const QSSGRef<QSSGRenderContext> &context)
38     : m_context(context)
39     , m_backend(context->backend())
40     , m_program(nullptr)
41     , m_vertexProgram(nullptr)
42     , m_fragmentProgram(nullptr)
43     , m_tessControlProgram(nullptr)
44     , m_tessEvalProgram(nullptr)
45     , m_geometryProgram(nullptr)
46     , m_computProgram(nullptr)
47 {
48     m_handle = m_backend->createProgramPipeline();
49 }
50 
~QSSGRenderProgramPipeline()51 QSSGRenderProgramPipeline::~QSSGRenderProgramPipeline()
52 {
53     if (m_handle) {
54         m_backend->releaseProgramPipeline(m_handle);
55     }
56 
57     if (m_vertexProgram)
58         m_vertexProgram.clear();
59     if (m_fragmentProgram)
60         m_fragmentProgram.clear();
61     if (m_tessControlProgram)
62         m_tessControlProgram.clear();
63     if (m_tessEvalProgram)
64         m_tessEvalProgram.clear();
65     if (m_geometryProgram)
66         m_geometryProgram.clear();
67 }
68 
isValid()69 bool QSSGRenderProgramPipeline::isValid()
70 {
71     return (m_handle != nullptr);
72 }
73 
setProgramStages(const QSSGRef<QSSGRenderShaderProgram> & inProgram,QSSGRenderShaderTypeFlags flags)74 void QSSGRenderProgramPipeline::setProgramStages(const QSSGRef<QSSGRenderShaderProgram> &inProgram, QSSGRenderShaderTypeFlags flags)
75 {
76     bool bDirty = false;
77 
78     if (flags & QSSGRenderShaderTypeValue::Vertex && inProgram != m_vertexProgram) {
79         m_vertexProgram = inProgram;
80         bDirty = true;
81     }
82     if (flags & QSSGRenderShaderTypeValue::Fragment && inProgram != m_fragmentProgram) {
83         m_fragmentProgram = inProgram;
84         bDirty = true;
85     }
86     if (flags & QSSGRenderShaderTypeValue::TessControl && inProgram != m_tessControlProgram) {
87         m_tessControlProgram = inProgram;
88         bDirty = true;
89     }
90     if (flags & QSSGRenderShaderTypeValue::TessEvaluation && inProgram != m_tessEvalProgram) {
91         m_tessEvalProgram = inProgram;
92         bDirty = true;
93     }
94     if (flags & QSSGRenderShaderTypeValue::Geometry && inProgram != m_geometryProgram) {
95         m_geometryProgram = inProgram;
96         bDirty = true;
97     }
98 
99     if (bDirty) {
100         m_backend->setProgramStages(m_handle, flags, (inProgram) ? inProgram->handle() : nullptr);
101     }
102 }
103 
bind()104 void QSSGRenderProgramPipeline::bind()
105 {
106     m_backend->setActiveProgramPipeline(m_handle);
107 }
108 
vertexStage()109 QSSGRef<QSSGRenderShaderProgram> QSSGRenderProgramPipeline::vertexStage()
110 {
111     return m_vertexProgram;
112 }
113 
114 QT_END_NAMESPACE
115