Qt3DRender::QShaderProgram Class
class Qt3DRender::QShaderProgramEncapsula un programa de sombreado. Más...
| Encabezado: | #include <qshaderprogram.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS 3drender) target_link_libraries(mytarget PRIVATE Qt6::3drender) |
| qmake: | QT += 3drender |
| En QML: | ShaderProgram |
| Heredado de: | Qt3DCore::QNode |
| Estado: | Obsoleto |
Esta clase está obsoleta. Se desaconseja encarecidamente su uso en código nuevo.
Tipos públicos
| enum | Format { GLSL, SPIRV } |
| enum | ShaderType { Vertex, Fragment, TessellationControl, TessellationEvaluation, Geometry, Compute } |
| enum | Status { NotReady, Ready, Error } |
Propiedades
|
|
Funciones públicas
| 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 |
Ranuras públicas
| 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) |
Señales
| 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) |
Miembros públicos estáticos
| QByteArray | loadSource(const QUrl &sourceUrl) |
Descripción detallada
Un programa de sombreadores consta de varios sombreadores diferentes, como los sombreadores de vértices y de fragmentos.
Qt3D rellenará automáticamente un conjunto de uniformes predeterminados si los encuentra durante la fase de introspección del sombreador.
| Uniforme predeterminado | Nombre del parámetro Qt3D asociado | Declaración GLSL |
|---|---|---|
| ModelMatrix | modelMatrix | uniform mat4 modelMatrix; |
| ViewMatrix | viewMatrix | uniform mat4 viewMatrix; |
| Matriz de proyección | matriz de proyección | uniform mat4 matrizDeProyección; |
| Matriz de vista del modelo | modelView | uniform mat4 modelView; |
| Matriz de proyección de vista | matriz de proyección de la vista | uniform mat4 matrizDeProyecciónDeVista; |
| Matriz de modelo-vista-proyección | modelViewProjection mvp | uniform mat4 modelViewProjection; uniform mat4 mvp; |
| Matriz inversa del modelo | inverseModelMatrix | uniform mat4 inverseModelMatrix; |
| Matriz de vista inversa | matriz de vista inversa | uniform mat4 matrizInversaDeVista; |
| Matriz de proyección inversa | matriz de proyección inversa | uniform mat4 matriz de proyección inversa; |
| Matriz de vista del modelo inversa | inverseModelView | uniform mat4 inverseModelView; |
| Matriz de proyección inversa de la vista | matriz de proyección inversa de la vista | uniform mat4 matriz de proyección inversa de la vista; |
| Matriz de proyección inversa de ModelView | matriz inversa de la proyección del modelo y la vista | uniform mat4 inversa de la matriz de proyección del modelo-vista; |
| MatrizNormalDelModelo | matrizNormalDelModelo | uniform mat3 matrizNormalDelModelo; |
| MatrizNormalVistaModelo | modelViewNormal | uniform mat3 modelViewNormal; |
| Matriz de ventana gráfica | matriz de ventana gráfica | uniform mat4 viewportMatrix; |
| Matriz inversa de la ventana gráfica | inverseViewportMatrix | uniform mat4 inverseViewportMatrix; |
| AspectRatio (anchura de la superficie / altura de la superficie) | aspectRatio | uniform float aspectRatio; |
| Exposición | exposición | uniform float exposición; |
| Gamma | gamma | gamma uniforme en coma flotante; |
| Tiempo (en nanosegundos) | tiempo | tiempo uniforme de tipo float; |
| EyePosition | eyePosition | uniform vec3 posiciónDelOjo; |
| Paleta de texturizado | skinningPalette[0] | const int maxJoints = 100; uniform mat4 skinningPalette[maxJoints]; |
Compatibilidad con RHI
Al escribir código de shader GLSL 450 para utilizarlo con el backend RHI de Qt 3D, las uniformes predeterminadas se proporcionarán como 2 objetos de búfer uniforme.
Las ubicaciones de enlace para estos se establecen en el enlace 0 para los uniformes de RenderView y en el 1 para los uniformes de 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);
}Para los objetos de búfer uniformes definidos por el usuario, utiliza una ubicación de enlace a partir del 2 o «auto» para que Qt 3D determine el enlace automáticamente. Asegúrate de mantener la coherencia entre las diferentes etapas del shader.
#version 450 core
layout(std140, binding = auto) uniform my_uniforms {
vec4 myColor;
};
layout(location=0) out vec4 fragColor;
void main()
{
fragColor = myColor;
}No hay ningún cambio en lo que respecta a la asignación de valores a los uniformes.
Para el ejemplo anterior, la configuración de «myColor» podría realizarse de la siguiente manera:
QParameter *parameter = new QParameter();
parameter->setName("myColor");
parameter->setValue(QVariant::fromValue(QColor(Qt::blue)));Las texturas siguen teniendo que definirse como uniformes independientes.
#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));
}Documentación sobre los tipos de miembros
enum QShaderProgram::Format
Esta enumeración identifica el formato del código del shader utilizado.
| Constante | Valor | Descripción |
|---|---|---|
Qt3DRender::QShaderProgram::GLSL | 0 | OpenGL |
Qt3DRender::QShaderProgram::SPIRV | 1 | Vulkan, OpenGL 5 |
enum QShaderProgram::ShaderType
Esta enumeración identifica el tipo de shader utilizado.
| Constante | Valor | Descripción |
|---|---|---|
Qt3DRender::QShaderProgram::Vertex | 0 | Sombreador de vértices |
Qt3DRender::QShaderProgram::Fragment | 1 | Sombreador de fragmentos |
Qt3DRender::QShaderProgram::TessellationControl | 2 | Sombreador de control de teselación |
Qt3DRender::QShaderProgram::TessellationEvaluation | 3 | Sombreador de evaluación de teselación |
Qt3DRender::QShaderProgram::Geometry | 4 | Sombreador de geometría |
Qt3DRender::QShaderProgram::Compute | 5 | Sombreador de cálculo |
enum QShaderProgram::Status
Esta enumeración identifica el estado del shader utilizado.
| Constante | Valor | Descripción |
|---|---|---|
Qt3DRender::QShaderProgram::NotReady | 0 | El sombreador aún no se ha compilado ni enlazado |
Qt3DRender::QShaderProgram::Ready | 1 | El sombreador se ha compilado correctamente |
Qt3DRender::QShaderProgram::Error | 2 | Se ha producido un error al compilar el sombreador |
Documentación de la propiedad
computeShaderCode : QByteArray
Contiene el código del shader de cálculo utilizado por este programa de shader.
Funciones de acceso:
| QByteArray | computeShaderCode() const |
| void | setComputeShaderCode(const QByteArray &computeShaderCode) |
Señal de notificación:
| void | computeShaderCodeChanged(const QByteArray &computeShaderCode) |
format : Format
Contiene el formato del código proporcionado en ShaderProgram. El valor por defecto es ShaderProgram.GLSL
Funciones de acceso:
| Qt3DRender::QShaderProgram::Format | format() const |
| void | setFormat(Qt3DRender::QShaderProgram::Format format) |
Señal de notificador:
| void | formatChanged(Qt3DRender::QShaderProgram::Format format) |
fragmentShaderCode : QByteArray
Contiene el código del shader de fragmentos utilizado por este programa de shader.
Funciones de acceso:
| QByteArray | fragmentShaderCode() const |
| void | setFragmentShaderCode(const QByteArray &fragmentShaderCode) |
Señal de notificador:
| void | fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode) |
geometryShaderCode : QByteArray
Contiene el código del sombreador geométrico utilizado por este programa de sombreado.
Funciones de acceso:
| QByteArray | geometryShaderCode() const |
| void | setGeometryShaderCode(const QByteArray &geometryShaderCode) |
Señal de notificación:
| void | geometryShaderCodeChanged(const QByteArray &geometryShaderCode) |
[read-only] log : QString
Contiene el registro del programa de sombreado actual. Esto resulta útil para diagnosticar un error de compilación del programa de sombreado.
Funciones de acceso:
| QString | log() const |
Señal de notificación:
| void | logChanged(const QString &log) |
[read-only] status : Status
Contiene el estado del programa de sombreado actual.
Funciones de acceso:
| Qt3DRender::QShaderProgram::Status | status() const |
Señal de notificación:
| void | statusChanged(Qt3DRender::QShaderProgram::Status status) |
tessellationControlShaderCode : QByteArray
Contiene el código del shader de control de teselación que utiliza este programa de shader.
Funciones de acceso:
| QByteArray | tessellationControlShaderCode() const |
| void | setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) |
Señal de notificación:
| void | tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode) |
tessellationEvaluationShaderCode : QByteArray
Contiene el código del shader de evaluación de teselación utilizado por este programa de shader.
Funciones de acceso:
| QByteArray | tessellationEvaluationShaderCode() const |
| void | setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) |
Señal de notificación:
| void | tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode) |
vertexShaderCode : QByteArray
Contiene el código del sombreador de vértices utilizado por este programa de sombreado.
Funciones de acceso:
| QByteArray | vertexShaderCode() const |
| void | setVertexShaderCode(const QByteArray &vertexShaderCode) |
Señal de notificación:
| void | vertexShaderCodeChanged(const QByteArray &vertexShaderCode) |
Documentación de las funciones miembro
[static invokable] QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl)
Devuelve el código del shader cargado desde sourceUrl.
Nota: Esta función se puede invocar a través del sistema de metaobjetos y desde QML. Véase Q_INVOKABLE.
void QShaderProgram::setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode)
Establece el código del shader para « type » del shader en « shaderCode ».
Véase también shaderCode().
QByteArray QShaderProgram::shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const
Devuelve el código del shader para « type ».
Véase también setShaderCode().
Qt3DRender::QShaderProgram::Status QShaderProgram::status() const
Devuelve el estado del programa de sombreado actual.
Nota: Funcióngetter para la propiedad 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.