Qt3DRender::QShaderProgram Class
class Qt3DRender::QShaderProgramRacchiude un programma shader. Maggiori informazioni...
| Intestazione: | #include <qshaderprogram.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS 3drender) target_link_libraries(mytarget PRIVATE Qt6::3drender) |
| qmake: | QT += 3drender |
| In QML: | ShaderProgram |
| Eredita da: | Qt3DCore::QNode |
| Stato: | Obsoleto |
Questa classe è deprecata. Si sconsiglia vivamente di utilizzarla nel nuovo codice.
Tipi pubblici
| enum | Format { GLSL, SPIRV } |
| enum | ShaderType { Vertex, Fragment, TessellationControl, TessellationEvaluation, Geometry, Compute } |
| enum | Status { NotReady, Ready, Error } |
Proprietà
|
|
Funzioni pubbliche
| QByteArray | computeShaderCode() const |
| Qt3DRender::QShaderProgram::Format | format() const |
| QByteArray | fragmentShaderCode() const |
| QByteArray | geometryShaderCode() const |
| QString | log() const |
| void | setFormat(Qt3DRender::QShaderProgram::Format format) |
| void | setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode) |
| QByteArray | shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const |
| Qt3DRender::QShaderProgram::Status | status() const |
| QByteArray | tessellationControlShaderCode() const |
| QByteArray | tessellationEvaluationShaderCode() const |
| QByteArray | vertexShaderCode() const |
Slot pubblici
| void | setComputeShaderCode(const QByteArray &computeShaderCode) |
| void | setFragmentShaderCode(const QByteArray &fragmentShaderCode) |
| void | setGeometryShaderCode(const QByteArray &geometryShaderCode) |
| void | setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) |
| void | setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) |
| void | setVertexShaderCode(const QByteArray &vertexShaderCode) |
Segnali
| void | computeShaderCodeChanged(const QByteArray &computeShaderCode) |
| void | formatChanged(Qt3DRender::QShaderProgram::Format format) |
| void | fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode) |
| void | geometryShaderCodeChanged(const QByteArray &geometryShaderCode) |
| void | logChanged(const QString &log) |
| void | statusChanged(Qt3DRender::QShaderProgram::Status status) |
| void | tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode) |
| void | tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode) |
| void | vertexShaderCodeChanged(const QByteArray &vertexShaderCode) |
Membri statici pubblici
| QByteArray | loadSource(const QUrl &sourceUrl) |
Descrizione dettagliata
Un programma shader è costituito da diversi shader, quali gli shader dei vertici e dei frammenti.
Qt3D popolerà automaticamente un insieme di uniform predefiniti se questi vengono rilevati durante la fase di ispezione dello shader.
| Uniform predefinito | Nome del parametro Qt3D associato | Dichiarazione GLSL |
|---|---|---|
| ModelMatrix | modelMatrix | uniform mat4 modelMatrix; |
| ViewMatrix | viewMatrix | uniform mat4 viewMatrix; |
| Matrice di proiezione | matrice di proiezione | uniform mat4 matriceProiezione; |
| MatriceModello-Vista | modelView | uniform mat4 modelView; |
| matrice di proiezione della vista | matrice di proiezione della vista | uniform mat4 viewProjectionMatrix; |
| ModelViewProjectionMatrix | modelViewProjection mvp | uniform mat4 modelViewProjection; uniform mat4 mvp; |
| MatriceInversaDelModello | matriceInversaDelModello | uniform mat4 inverseModelMatrix; |
| Matrice di vista inversa | matrice di vista inversa | uniform mat4 matriceInversaDellaVista; |
| Matrice di proiezione inversa | matrice di proiezione inversa | uniform mat4 matriceProiezioneInversa; |
| Matrice inversa modello-vista | inverseModelView | uniform mat4 inverseModelView; |
| Matrice di proiezione inversa della vista | matrice di proiezione inversa della vista | uniform mat4 matrice di proiezione inversa della vista; |
| Matrice di proiezione inversa ModelView | matrice inversa di proiezione modello-vista | uniform mat4 inversaMatriceProiezioneModelloVista; |
| MatriceNormaleModello | matrice delle normali del modello | uniform mat3 matriceNormaleModello; |
| MatriceNormaleModelloVista | modelViewNormal | uniform mat3 modelViewNormal; |
| ViewportMatrix | matrice del viewport | uniform mat4 viewportMatrix; |
| Matrice inversa del viewport | matrice inversa del viewport | uniform mat4 inverseViewportMatrix; |
| AspectRatio (larghezza della superficie / altezza della superficie) | aspectRatio | uniform float aspectRatio; |
| Esposizione | esposizione | uniform float esposizione; |
| Gamma | gamma | gamma uniforme in virgola mobile; |
e temporale (in nanosecondi) | tempo | uniform float time; |
| Posizione dell'occhio | posizione dell'occhio | uniform vec3 eyePosition; |
| SkinningPalette | skinningPalette[0] | const int maxJoints = 100; uniform mat4 skinningPalette[maxJoints]; |
Supporto RHI
Quando si scrive codice shader GLSL 450 da utilizzare con il backend RHI di Qt 3D, le uniform predefinite saranno fornite come 2 oggetti buffer uniform.
Le posizioni di binding per questi sono impostate su 0 per le uniform di RenderView e su 1 per quelle di Command.
#version 450 core
layout(location = 0) in vec3 vertexPosition;
layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 uncorrectedProjectionMatrix;
mat4 clipCorrectionMatrix;
mat4 viewProjectionMatrix;
mat4 inverseViewMatrix;
mat4 inverseProjectionMatrix;
mat4 inverseViewProjectionMatrix;
mat4 viewportMatrix;
mat4 inverseViewportMatrix;
vec4 textureTransformMatrix;
vec3 eyePosition;
float aspectRatio;
float gamma;
float exposure;
float time;
float yUpInNDC;
float yUpInFBO;
};
layout(std140, binding = 1) uniform qt3d_command_uniforms {
mat4 modelMatrix;
mat4 inverseModelMatrix;
mat4 modelViewMatrix;
mat3 modelNormalMatrix;
mat4 inverseModelViewMatrix;
mat4 modelViewProjection;
mat4 inverseModelViewProjectionMatrix;
};
void main()
{
gl_Position = (projectionMatrix * viewMatrix * modelMatrix * vertexPosition);
}Per gli oggetti buffer uniform definiti dall’utente, utilizzare un binding a partire da 2 oppure impostare “auto” per consentire a Qt 3D di gestire automaticamente il binding. Assicurarsi di mantenere la coerenza tra le diverse fasi dello shader.
#version 450 core
layout(std140, binding = auto) uniform my_uniforms {
vec4 myColor;
};
layout(location=0) out vec4 fragColor;
void main()
{
fragColor = myColor;
}Non vi è alcuna modifica per quanto riguarda l’assegnazione dei valori alle uniform.
Per l’esempio sopra riportato, l’impostazione di myColor potrebbe essere effettuata con:
QParameter *parameter = new QParameter();
parameter->setName("myColor");
parameter->setValue(QVariant::fromValue(QColor(Qt::blue)));Le texture devono comunque essere definite come uniformi autonome.
#version 450 core
layout(binding=0) uniform sampler2D source;
layout(location=0) out vec4 fragColor;
void main()
{
fragColor = texture(source, vec2(0.5, 0.5));
}Documentazione sui tipi di membro
enum QShaderProgram::Format
Questa enumerazione identifica il formato del codice shader utilizzato.
| Costante | Valore | Descrizione |
|---|---|---|
Qt3DRender::QShaderProgram::GLSL | 0 | OpenGL |
Qt3DRender::QShaderProgram::SPIRV | 1 | Vulkan, OpenGL 5 |
enum QShaderProgram::ShaderType
Questa enumerazione identifica il tipo di shader utilizzato.
| Costante | Valore | Descrizione |
|---|---|---|
Qt3DRender::QShaderProgram::Vertex | 0 | Shader dei vertici |
Qt3DRender::QShaderProgram::Fragment | 1 | Shader di frammento |
Qt3DRender::QShaderProgram::TessellationControl | 2 | Shader di controllo della tassellatura |
Qt3DRender::QShaderProgram::TessellationEvaluation | 3 | Shader di valutazione della tassellatura |
Qt3DRender::QShaderProgram::Geometry | 4 | Shader di geometria |
Qt3DRender::QShaderProgram::Compute | 5 | Shader di calcolo |
enum QShaderProgram::Status
Questa enumerazione identifica lo stato dello shader utilizzato.
| Costante | Valore | Descrizione |
|---|---|---|
Qt3DRender::QShaderProgram::NotReady | 0 | Lo shader non è stato ancora compilato e collegato |
Qt3DRender::QShaderProgram::Ready | 1 | Lo shader è stato compilato con successo |
Qt3DRender::QShaderProgram::Error | 2 | Si è verificato un errore durante la compilazione dello shader |
Documentazione delle proprietà
computeShaderCode : QByteArray
Contiene il codice dello shader di calcolo utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | computeShaderCode() const |
| void | setComputeShaderCode(const QByteArray &computeShaderCode) |
Segnale di notifica:
| void | computeShaderCodeChanged(const QByteArray &computeShaderCode) |
format : Format
Contiene il formato del codice specificato in ShaderProgram. Il valore predefinito è ShaderProgram.GLSL
Funzioni di accesso:
| Qt3DRender::QShaderProgram::Format | format() const |
| void | setFormat(Qt3DRender::QShaderProgram::Format format) |
Segnale di notifica:
| void | formatChanged(Qt3DRender::QShaderProgram::Format format) |
fragmentShaderCode : QByteArray
Contiene il codice dello shader di frammento utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | fragmentShaderCode() const |
| void | setFragmentShaderCode(const QByteArray &fragmentShaderCode) |
Segnale di notifica:
| void | fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode) |
geometryShaderCode : QByteArray
Contiene il codice dello shader geometrico utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | geometryShaderCode() const |
| void | setGeometryShaderCode(const QByteArray &geometryShaderCode) |
Segnale di notifica:
| void | geometryShaderCodeChanged(const QByteArray &geometryShaderCode) |
[read-only] log : QString
Contiene il log del programma shader corrente. È utile per diagnosticare un errore di compilazione del programma shader.
Funzioni di accesso:
| QString | log() const |
Segnale di notifica:
| void | logChanged(const QString &log) |
[read-only] status : Status
Contiene lo stato del programma shader corrente.
Funzioni di accesso:
| Qt3DRender::QShaderProgram::Status | status() const |
Segnale di notifica:
| void | statusChanged(Qt3DRender::QShaderProgram::Status status) |
tessellationControlShaderCode : QByteArray
Contiene il codice dello shader di controllo della tassellatura utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | tessellationControlShaderCode() const |
| void | setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) |
Segnale di notifica:
| void | tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode) |
tessellationEvaluationShaderCode : QByteArray
Contiene il codice dello shader di valutazione della tassellatura utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | tessellationEvaluationShaderCode() const |
| void | setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) |
Segnale di notifica:
| void | tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode) |
vertexShaderCode : QByteArray
Contiene il codice del vertex shader utilizzato da questo programma shader.
Funzioni di accesso:
| QByteArray | vertexShaderCode() const |
| void | setVertexShaderCode(const QByteArray &vertexShaderCode) |
Segnale di notifica:
| void | vertexShaderCodeChanged(const QByteArray &vertexShaderCode) |
Documentazione delle funzioni membro
[static invokable] QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl)
Restituisce il codice dello shader caricato da sourceUrl.
Nota: questa funzione può essere richiamata tramite il sistema dei meta-oggetti e da QML. Vedi Q_INVOKABLE.
void QShaderProgram::setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode)
Imposta il codice dello shader per l'type e dello shader su shaderCode.
Vedi anche shaderCode().
QByteArray QShaderProgram::shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const
Restituisce il codice dello shader per type.
Vedi anche setShaderCode().
Qt3DRender::QShaderProgram::Status QShaderProgram::status() const
Restituisce lo stato del programma shader corrente.
Nota: funzionegetter per la proprietà status.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.