このページでは

QOpenGLShader Class

QOpenGLShader クラスを使用すると、OpenGL シェーダーをコンパイルすることができます。詳細...

ヘッダー: #include <QOpenGLShader>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl
継承元: QObject

パブリック型

flags ShaderType
enum ShaderTypeBit { Vertex, Fragment, Geometry, TessellationControl, TessellationEvaluation, Compute }

パブリック関数

QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = nullptr)
virtual ~QOpenGLShader()
bool compileSourceCode(const char *source)
bool compileSourceCode(const QByteArray &source)
bool compileSourceCode(const QString &source)
bool compileSourceFile(const QString &fileName)
bool isCompiled() const
QString log() const
GLuint shaderId() const
QOpenGLShader::ShaderType shaderType() const
QByteArray sourceCode() const

静的パブリックメンバー

bool hasOpenGLShaders(QOpenGLShader::ShaderType type, QOpenGLContext *context = nullptr)

詳細な説明

このクラスは、OpenGL シェーディング言語 (GLSL) および OpenGL/ES シェーディング言語 (GLSL/ES) で記述されたシェーダーをサポートしています。

QOpenGLShader およびQOpenGLShaderProgram を使用することで、プログラマは頂点シェーダやフラグメントシェーダのコンパイルやリンクの詳細を気にする必要がなくなります。

Qt OpenGL が使用するすべてのデータは、信頼できるコンテンツであることが期待されます。シェーダーのソースコードは、場合によっては最小限の修正を加えた後、基盤となる OpenGL 実装のコンパイラに渡されますが、Qt の観点からは、このコンパイラはブラックボックスとなります。

警告: アプリケーション開発者は 、compileSourceFile() などの関数にユーザーが提供したコンテンツを渡す前に、その潜在的な影響を慎重に検討することをお勧めします。

QOpenGLShaderProgramも参照してください 。

メンバ型のドキュメント

enum QOpenGLShader::ShaderTypeBit
flags QOpenGLShader::ShaderType

この列挙型は、作成されるQOpenGLShader の型を指定します。

定数定数値説明
QOpenGLShader::Vertex0x0001OpenGL シェーディング言語 (GLSL) で記述された頂点シェーダー。
QOpenGLShader::Fragment0x0002OpenGL シェーディング言語 (GLSL) で記述されたフラグメントシェーダー。
QOpenGLShader::Geometry0x0004OpenGL シェーディング言語 (GLSL) で記述されたジオメトリシェーダー (OpenGL 3.2 以上、または OpenGL ES 3.2 以上が必要です)。
QOpenGLShader::TessellationControl0x0008OpenGL シェーディング言語 (GLSL) で記述されたテッセレーション制御シェーダー(OpenGL 4.0 以上、または OpenGL ES 3.2 以上が必要です)。
QOpenGLShader::TessellationEvaluation0x0010OpenGL シェーディング言語 (GLSL) で記述されたテッセレーション評価シェーダー(OpenGL 4.0 以上、または OpenGL ES 3.2 以上が必要です)。
QOpenGLShader::Compute0x0020OpenGL シェーディング言語 (GLSL) で記述されたコンピュートシェーダー(OpenGL 4.3 以上、または OpenGL ES 3.1 以上が必要です)。

ShaderType 型は、QFlags<ShaderTypeBit> の typedef です。これは、ShaderTypeBit 値の OR 組み合わせを格納します。

メンバ関数のドキュメント

[explicit] QOpenGLShader::QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = nullptr)

指定されたtype の新しいQOpenGLShaderオブジェクトを生成し、それをparent にアタッチします。シェーダープログラムがサポートされていない場合、QOpenGLShaderProgram::hasOpenGLShaderPrograms()はfalseを返します。

通常、このコンストラクタの呼び出し後には、compileSourceCode() またはcompileSourceFile() が呼び出されます。

シェーダーは、現在のQOpenGLContext に関連付けられます。

compileSourceCode() およびcompileSourceFile()も参照してください 。

[virtual noexcept] QOpenGLShader::~QOpenGLShader()

このシェーダーを削除します。シェーダーがQOpenGLShaderProgram オブジェクトにアタッチされている場合、QOpenGLShaderProgram が破棄されるまで、実際のシェーダーは残ります。

bool QOpenGLShader::compileSourceCode(const char *source)

このシェーダーのsource コードを設定し、コンパイルを行います。ソースのコンパイルが成功した場合はtrue を返し、失敗した場合はfalseを返します。

compileSourceFile()も参照してください 。

bool QOpenGLShader::compileSourceCode(const QByteArray &source)

このシェーダーのsource コードを設定し、コンパイルを行います。ソースのコンパイルに成功した場合はtrue を返し、そうでない場合はfalseを返します。

これはオーバーロードされた関数です。

compileSourceFile()も参照してください 。

bool QOpenGLShader::compileSourceCode(const QString &source)

このシェーダーのsource コードを設定し、コンパイルを行います。ソースのコンパイルに成功した場合はtrue を返し、失敗した場合はfalseを返します。

これはオーバーロードされた関数です。

compileSourceFile()も参照してください 。

bool QOpenGLShader::compileSourceFile(const QString &fileName)

このシェーダーのソースコードをfileName の内容に設定し、コンパイルを行います。ファイルを開いてソースをコンパイルできた場合はtrue を返し、そうでない場合はfalseを返します。

compileSourceCode()も参照してください 。

[static] bool QOpenGLShader::hasOpenGLShaders(QOpenGLShader::ShaderType type, QOpenGLContext *context = nullptr)

このシステムでtype 型のシェーダープログラムがサポートされている場合はtrue を返し、そうでない場合はfalseを返します。

context は、GLSL 拡張機能の解決に使用されます。context がnullptr の場合、QOpenGLContext::currentContext() が使用されます。

bool QOpenGLShader::isCompiled() const

このシェーダーがコンパイルされている場合は `true ` を返し、そうでない場合は `false` を返します。

compileSourceCode() およびcompileSourceFile()も参照してください 。

QString QOpenGLShader::log() const

前回のコンパイル中に発生したエラーと警告を返します。

compileSourceCode() およびcompileSourceFile()も参照してください 。

GLuint QOpenGLShader::shaderId() const

このシェーダーに関連付けられた OpenGL 識別子を返します。

QOpenGLShaderProgram::programId()も参照してください 。

QOpenGLShader::ShaderType QOpenGLShader::shaderType() const

このシェーダーの型を返します。

QByteArray QOpenGLShader::sourceCode() const

このシェーダーのソースコードを返します。

compileSourceCode()も参照してください 。

© 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.