QSGGeometry Class
QSGGeometry クラスは、Qt Quick のシーングラフにおいて、グラフィックプリミティブを格納するための低レベルな機能を提供します。詳細...
| ヘッダー: | #include <QSGGeometry> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Quick) target_link_libraries(mytarget PRIVATE Qt6::Quick) |
| qmake: | QT += quick |
パブリック型
| struct | Attribute |
| struct | AttributeSet |
| struct | ColoredPoint2D |
| struct | Point2D |
| struct | TexturedPoint2D |
| enum | AttributeType { UnknownAttribute, PositionAttribute, ColorAttribute, TexCoordAttribute, TexCoord1Attribute, TexCoord2Attribute } |
| enum | DataPattern { AlwaysUploadPattern, DynamicPattern, StaticPattern, StreamPattern } |
| enum | DrawingMode { DrawPoints, DrawLines, DrawLineStrip, DrawTriangles, DrawTriangleStrip } |
| enum | Type { ByteType, UnsignedByteType, ShortType, UnsignedShortType, IntType, …, DoubleType } |
パブリック関数
| QSGGeometry(const QSGGeometry::AttributeSet &attributes, int vertexCount, int indexCount = 0, int indexType = UnsignedShortType) | |
| virtual | ~QSGGeometry() |
| void | allocate(int vertexCount, int indexCount = 0) |
| int | attributeCount() const |
| const QSGGeometry::Attribute * | attributes() const |
| unsigned int | drawingMode() const |
| int | indexCount() const |
| void * | indexData() |
| const void * | indexData() const |
| uint * | indexDataAsUInt() |
| const uint * | indexDataAsUInt() const |
| quint16 * | indexDataAsUShort() |
| const quint16 * | indexDataAsUShort() const |
| QSGGeometry::DataPattern | indexDataPattern() const |
| int | indexType() const |
| float | lineWidth() const |
| void | markIndexDataDirty() |
| void | markVertexDataDirty() |
| void | setDrawingMode(unsigned int mode) |
(since 6.10) void | setIndexCount(int count) |
| void | setIndexDataPattern(QSGGeometry::DataPattern p) |
| void | setLineWidth(float width) |
(since 6.10) void | setVertexCount(int count) |
| void | setVertexDataPattern(QSGGeometry::DataPattern p) |
| int | sizeOfIndex() const |
| int | sizeOfVertex() const |
| int | vertexCount() const |
| void * | vertexData() |
| const void * | vertexData() const |
| QSGGeometry::ColoredPoint2D * | vertexDataAsColoredPoint2D() |
| const QSGGeometry::ColoredPoint2D * | vertexDataAsColoredPoint2D() const |
| QSGGeometry::Point2D * | vertexDataAsPoint2D() |
| const QSGGeometry::Point2D * | vertexDataAsPoint2D() const |
| QSGGeometry::TexturedPoint2D * | vertexDataAsTexturedPoint2D() |
| const QSGGeometry::TexturedPoint2D * | vertexDataAsTexturedPoint2D() const |
| QSGGeometry::DataPattern | vertexDataPattern() const |
静的パブリックメンバー
| const QSGGeometry::AttributeSet & | defaultAttributes_ColoredPoint2D() |
| const QSGGeometry::AttributeSet & | defaultAttributes_Point2D() |
| const QSGGeometry::AttributeSet & | defaultAttributes_TexturedPoint2D() |
| void | updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect) |
| void | updateRectGeometry(QSGGeometry *g, const QRectF &rect) |
| void | updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect) |
詳細な説明
QSGGeometry クラスは、シーングラフでレンダリングされるプリミティブのジオメトリを格納します。このクラスには、頂点データと、オプションでインデックスデータが含まれます。ジオメトリの描画に使用されるモード(プリミティブのトポロジーとも呼ばれる)は、setDrawingMode() で指定されます。
頂点は、x および y 値で定義される単純な点である場合もあれば、各頂点が法線、テクスチャ座標、および 3D 位置を含むような、より複雑なものでもある場合があります。QSGGeometry::AttributeSet は、頂点データがどのように構成されるかを記述するために使用されます。 属性セットは、構築時にのみ指定可能です。QSGGeometryクラスは、デフォルトでいくつかの便利な属性および属性セットを提供しています。defaultAttributes_Point2D()関数は、単色の矩形に使用される属性セットを返し、defaultAttributes_TexturedPoint2D 関数は、テクスチャが適用された2Dジオメトリに使用される属性を返します。 頂点データは内部的にvoid * として格納され、vertexData()関数を使用してアクセスできます。一般的な属性セット用の便利なアクセサとして、vertexDataAsPoint2D()およびvertexDataAsTexturedPoint2D()が利用可能です。頂点データの割り当ては、コンストラクタに頂点数を渡すか、後でallocate()を呼び出すことによって行われます。
allocate() メソッドを使用してデータバッファのサイズを変更することで、構築後に頂点数やインデックス数を変更できます。ただし、allocate() を使用する場合は、呼び出すたびにすべての頂点データとインデックスデータを更新する必要があります。 Qt 6.10以降では、setVertexCount() およびsetIndexCount() を使用することで、データバッファを再割り当てすることなく頂点数やインデックス数を調整でき、新しい頂点やインデックスのみを更新すれば済みます。いずれの場合も、レンダラーが内部バッファを更新できるよう、呼び出し側はnode->markDirty(QSGNode::DirtyGeometry) を呼び出してジオメトリノードを「ダーティ」状態にマークする必要があります。
QSGGeometry は、オプションで、符号なし 32 ビット、符号なし 16 ビット、または符号なし 8 ビットの整数型のインデックスを含むことができます。インデックスの型は構築時に指定する必要があり、変更することはできません。
以下は、位置と色の頂点で構成されるジオメトリを構築する方法を示すスニペットです。
struct MyPoint2D {
float x;
float y;
float r;
float g;
float b;
float a;
void set(float x_, float y_, float r_, float g_, float b_, float a_) {
x = x_;
y = y_;
r = r_;
g = g_;
b = b_;
a = a_;
}
};
QSGGeometry::Attribute MyPoint2D_Attributes[] = {
QSGGeometry::Attribute::create(0, 2, FloatType, true),
QSGGeometry::Attribute::create(1, 4, FloatType, false)
};
QSGGeometry::AttributeSet MyPoint2D_AttributeSet = {
2,
sizeof(MyPoint2D),
MyPoint2D_Attributes
};
...
geometry = new QSGGeometry(MyPoint2D_AttributeSet, 2);
geometry->setDrawingMode(DrawLines);
MyPoint2D *vertices = static_cast<MyPoint2D *>(geometry->vertexData());
vertices[0].set(0, 0, 1, 0, 0, 1);
vertices[1].set(width(), height(), 0, 0, 1, 1);QSGGeometryはソフトウェアバッファであり、アクセラレーションレンダリングの観点からはクライアントサイドに位置します。これは、2Dグラフィックスで使用されるバッファは通常、フレームごとに変化する多数の小さなバッファで構成されており、グラフィックスメモリにアップロードしてもメリットがないためです。 ただし、QSGGeometryは、setVertexDataPattern()およびsetIndexDataPattern()関数を使用して、バッファをアップロードすべきであることをレンダラーに示唆する機能をサポートしています。この示唆が反映されるかどうかは、実装に依存します。
注: QSGという接頭辞を持つすべてのクラスは 、シーングラフのレンダリングスレッドでのみ使用する必要があります。詳細については、「シーングラフとレンダリング」を参照してください。
「 QSGGeometryNode 」 および「シーングラフ - カスタムジオメトリ」も参照してください 。
メンバ型のドキュメント
enum QSGGeometry::AttributeType
この列挙型は、いくつかの属性タイプを定義しています。
| 定数 | 値 | 説明 |
|---|---|---|
QSGGeometry::UnknownAttribute | 0 | 不特定 |
QSGGeometry::PositionAttribute | 1 | 不特定 |
QSGGeometry::ColorAttribute | 2 | 色 |
QSGGeometry::TexCoordAttribute | 3 | テクスチャ座標 |
QSGGeometry::TexCoord1Attribute | 4 | テクスチャ座標 1 |
QSGGeometry::TexCoord2Attribute | 5 | テクスチャ座標 2 |
enum QSGGeometry::DataPattern
DataPattern 列挙型は、ジオメトリオブジェクト内の頂点データおよびインデックスデータの使用パターンを指定するために使用されます。
| 定数 | 値 | 説明 |
|---|---|---|
QSGGeometry::AlwaysUploadPattern | 0 | データは常にアップロードされます。つまり、ユーザーはインデックスおよび頂点データを変更した後、明示的に「変更済み」としてマークする必要はありません。これがデフォルトの設定です。 |
QSGGeometry::DynamicPattern | 2 | データは繰り返し変更され、何度も描画されます。これは、パフォーマンスを向上させる可能性のあるヒントです。この設定の場合、ユーザーはデータを変更した後、必ずデータを「変更済み」としてマークする必要があります。 |
QSGGeometry::StaticPattern | 3 | データは一度変更され、何度も描画されます。これは、パフォーマンスの向上につながる可能性があるヒントです。この設定にした場合、ユーザーはデータを変更した後、必ずデータを「変更済み」としてマークする必要があります。 |
QSGGeometry::StreamPattern | 1 | データは描画されるほぼ毎回変更されます。これは、パフォーマンスの向上につながる可能性があるヒントです。この設定を有効にした場合、ユーザーはデータを変更した後、必ずデータを「変更済み」としてマークする必要があります。 |
enum QSGGeometry::DrawingMode
描画モード(プリミティブトポロジーとも呼ばれる)を指定します。
注: Qt6以降、 シーングラフでは、サポートされているすべての3DグラフィックスAPIで共通してサポートされているトポロジのみが公開されます。その結果、列挙型の値自体は依然として存在しますが、DrawLineLoop およびDrawTriangleFan の値は、Qt 6の実行時においてサポートされなくなりました。
| 定数 | 値 |
|---|---|
QSGGeometry::DrawPoints | 0x0000 |
QSGGeometry::DrawLines | 0x0001 |
QSGGeometry::DrawLineStrip | 0x0003 |
QSGGeometry::DrawTriangles | 0x0004 |
QSGGeometry::DrawTriangleStrip | 0x0005 |
enum QSGGeometry::Type
頂点データ内のコンポーネントのタイプを指定します。
| 定数 | 値 | 説明 |
|---|---|---|
QSGGeometry::ByteType | 0x1400 | |
QSGGeometry::UnsignedByteType | 0x1401 | |
QSGGeometry::ShortType | 0x1402 | |
QSGGeometry::UnsignedShortType | 0x1403 | |
QSGGeometry::IntType | 0x1404 | |
QSGGeometry::UnsignedIntType | 0x1405 | |
QSGGeometry::FloatType | 0x1406 | |
QSGGeometry::Bytes2Type | 0x1407 | Qt 5.14で追加されました。 |
QSGGeometry::Bytes3Type | 0x1408 | Qt 5.14 で追加されました。 |
QSGGeometry::Bytes4Type | 0x1409 | Qt 5.14 で追加されました。 |
QSGGeometry::DoubleType | 0x140A | Qt 5.14 で追加されました。 |
メンバ関数のドキュメント
QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes, int vertexCount, int indexCount = 0, int indexType = UnsignedShortType)
attributes に基づいてジオメトリオブジェクトを構築します。
このオブジェクトは、attributes に蓄積されたサイズに基づいてvertexCount の頂点用の領域を割り当て、indexCount 用の領域も割り当てます。
indexType は、UnsignedShortType またはUnsignedIntType のいずれかになります。後者のサポートは、実行時に使用されるグラフィックスAPIの実装に依存するため、常に利用可能とは限りません。
Geometry オブジェクトは、デフォルトでDrawTriangleStrip を描画モードとして構築されます。
注: attributes およびそれが参照するAttribute オブジェクトは、QSGGeometry の存続期間全体を通じて有効な状態を維持する必要があります。QSGGeometry はattributes への参照を保持し、Attribute オブジェクトを削除することはありません。
[virtual noexcept] QSGGeometry::~QSGGeometry()
ジオメトリオブジェクトと、それが割り当てた頂点データおよびインデックスデータを破棄します。
void QSGGeometry::allocate(int vertexCount, int indexCount = 0)
このジオメトリオブジェクトの頂点データとインデックスデータを、vertexCount 個の頂点およびindexCount 個のインデックスに収まるようにサイズ変更し、それに応じて頂点数とインデックス数を設定します。
setVertexCount() またはsetIndexCount() を使用すると、allocate() を再度呼び出すことなく、頂点数やインデックス数を変更できます。
この呼び出しの後、頂点およびインデックスデータは無効化されるため、呼び出し元はnode->markDirty(QSGNode::DirtyGeometry) を呼び出して関連するジオメトリノードを「ダーティ」としてマークし、レンダラーが内部バッファを更新できるようにする必要があります。
setVertexCount() およびsetIndexCount()も参照してください 。
int QSGGeometry::attributeCount() const
このジオメトリで使用されている属性セットに含まれる属性の数を返します。
const QSGGeometry::Attribute *QSGGeometry::attributes() const
このジオメトリの属性を格納した配列を返します。配列のサイズは、attributeCount() で指定されます。
[static] const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
頂点ごとの色付けを行う2D描画に使用する属性を返す便利な関数です。
[static] const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
2Dの単色描画に使用する属性を返す便利関数。
[static] const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
テクスチャ付き2D描画に使用する属性を返す便利な関数です。
unsigned int QSGGeometry::drawingMode() const
このジオメトリの描画モードを返します。
デフォルト値は `DrawTriangleStrip` です。
setDrawingMode()も参照してください 。
int QSGGeometry::indexCount() const
ジオメトリオブジェクトのレンダリング時に処理されるインデックスの数を返します。
setIndexCount()も参照してください 。
void *QSGGeometry::indexData()
このジオメトリオブジェクトの生のインデックスデータへのポインタを返します。
indexDataAsUShort() およびindexDataAsUInt()も参照してください 。
const void *QSGGeometry::indexData() const
このジオメトリオブジェクトの生のインデックスデータへのポインタを返します。
indexDataAsUShort() およびindexDataAsUInt()も参照してください 。
uint *QSGGeometry::indexDataAsUInt()
インデックスデータに、32ビットの符号なし整数の可変配列としてアクセスするための便利な関数です。
const uint *QSGGeometry::indexDataAsUInt() const
インデックスデータを、32ビットの符号なし整数の不変配列として取得するための便利な関数です。
quint16 *QSGGeometry::indexDataAsUShort()
インデックスデータを、16ビットの符号なし整数の可変配列としてアクセスするための便利な関数です。
const quint16 *QSGGeometry::indexDataAsUShort() const
インデックスデータを、16ビットの符号なし整数の不変配列として取得するための便利な関数です。
QSGGeometry::DataPattern QSGGeometry::indexDataPattern() const
このジオメトリにおけるインデックスの使用パターンを返します。デフォルトのパターンは `AlwaysUploadPattern` です。
setIndexDataPattern()も参照してください 。
int QSGGeometry::indexType() const
このジオメトリ・オブジェクトのインデックスに使用されるプリミティブ型を返します。
float QSGGeometry::lineWidth() const
このジオメトリに使用される現在の線の幅または点の幅を取得します。このプロパティは、drawingMode がDrawLines またはDrawLineStrip に設定されている場合にのみ、線の幅に適用されます。サポートされている場合、drawingMode がDrawPoints に設定されているときは、点のサイズにも適用されます。
デフォルト値は1.0
注: ポイントおよびライン描画のサポートは 、プラットフォームやグラフィックス API によって、実行時に制限される場合があります。たとえば、一部の API ではポイントスプライトがサポートされていないため、1 以外のサイズを設定することはできません。
注: 1.0 の幅は 常にサポートされています。
setLineWidth() およびdrawingMode()も参照してください 。
void QSGGeometry::markIndexDataDirty()
このジオメトリの頂点が変更されたため、再度アップロードする必要があることに注意してください。
この関数は、頂点の使用パターンが「StaticData」であり、このジオメトリをレンダリングするレンダラーがジオメトリを頂点バッファオブジェクト(VBO)にアップロードする場合にのみ効果を発揮します。
void QSGGeometry::markVertexDataDirty()
このジオメトリの頂点が変更されたため、再度アップロードする必要があることに注意してください。
この関数は、頂点の使用パターンが「StaticData」であり、かつこのジオメトリをレンダリングするレンダラーがジオメトリを頂点バッファオブジェクト(VBO)にアップロードする場合にのみ効果を発揮します。
void QSGGeometry::setDrawingMode(unsigned int mode)
このジオメトリの描画に使用するmode を設定します。
デフォルト値は `QSGGeometry::DrawTriangleStrip` です。
drawingMode() およびDrawingModeも参照してください 。
[since 6.10] void QSGGeometry::setIndexCount(int count)
ジオメトリオブジェクトがレンダリングされるたびに処理されるインデックスの数を設定します。
count は検証されず、0 から割り当てられたインデックス数までの範囲の値のみが指定されるよう確保するのは、ユーザーの責任です。
この呼び出しの後、頂点およびインデックスデータは無効化されませんが、レンダラーが内部バッファを更新できるよう、呼び出し元はnode->markDirty(QSGNode::DirtyGeometry) を呼び出してジオメトリノードを「ダーティ」としてマークする必要があります。
この関数は Qt 6.10 で導入されました。
indexCount()も参照してください 。
void QSGGeometry::setIndexDataPattern(QSGGeometry::DataPattern p)
インデックスの使用パターンを `p` に設定します。
デフォルトは `AlwaysUploadPattern` です。デフォルト以外の値に設定した場合、ユーザーは `QSGNode::DirtyGeometry` を引数に `QSGNode::markDirty()` を呼び出すことに加え、インデックスデータを変更した後に `markIndexDataDirty()` を呼び出す必要があります。
indexDataPattern()も参照してください 。
void QSGGeometry::setLineWidth(float width)
このジオメトリに使用される線幅または点幅をwidth に設定します。このプロパティは、drawingMode がDrawLines またはDrawLineStrip の場合にのみ、線幅に適用されます。サポートされている場合、drawingMode がDrawPoints であるときは、点サイズにも適用されます。
注: ポイントおよび線の描画のサポートは 、プラットフォームやグラフィックスAPIによって、実行時に制限される場合があります。たとえば、一部のAPIではポイントスプライトがサポートされていないため、1以外のサイズを設定することはできません。
注: 1.0 の幅は 常にサポートされています。
lineWidth() およびdrawingMode()も参照してください 。
[since 6.10] void QSGGeometry::setVertexCount(int count)
レンダリングする頂点数を設定します。
count は検証されません。0から割り当てられた頂点数までの範囲の値のみが指定されるようにすることは、ユーザーの責任です。
この呼び出しの後、頂点データは無効化されませんが、レンダラーが内部バッファを更新できるようにするため、呼び出し元は `node->markDirty(QSGNode::DirtyGeometry)` を呼び出してジオメトリノードを「ダーティ」としてマークする必要があります。
この関数は Qt 6.10 で導入されました。
vertexCount()も参照してください 。
void QSGGeometry::setVertexDataPattern(QSGGeometry::DataPattern p)
頂点の使用パターンを「p 」に設定します。
デフォルトは `AlwaysUploadPattern` です。デフォルト以外の値に設定した場合、ユーザーは `QSGNode::DirtyGeometry` を引き数として `QSGNode::markDirty()` を呼び出すことに加え、頂点データを変更した後に `markVertexDataDirty()` を呼び出す必要があります。
vertexDataPattern()も参照してください 。
int QSGGeometry::sizeOfIndex() const
インデックス型のバイトサイズを返します。
この値は、インデックス型が `UnsignedShortType` の場合は `2 `、インデックス型が `UnsignedIntType` の場合は `4 ` となります。
int QSGGeometry::sizeOfVertex() const
1つの頂点のサイズをバイト単位で返します。
この値は属性から取得されます。
[static] void QSGGeometry::updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect)
ジオメトリ `g ` を、`rect` 内の座標で更新します。
この関数は、ジオメトリオブジェクトがQSGGeometry::ColoredPoint2D の頂点からなる単一のトライアングルストリップを含んでいることを前提としています。
[static] void QSGGeometry::updateRectGeometry(QSGGeometry *g, const QRectF &rect)
ジオメトリ `g ` を、`rect` 内の座標で更新します。
この関数は、ジオメトリオブジェクトが、QSGGeometry::Point2D の頂点からなる単一のトライアングルストリップを含んでいることを前提としています。
[static] void QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect)
g のジオメトリを、rect の座標およびtextureRect のテクスチャ座標を用いて更新します。
textureRect 座標は正規化された座標である必要があります。
g QSGGeometry::TexturedPoint2D 型の4つの頂点からなるトライアングル・ストリップであると仮定します。
int QSGGeometry::vertexCount() const
レンダリング可能な頂点数を返します。また、インデックスが使用されている場合は、インデックスを通じてアクセス可能な頂点数を返します。
setVertexCount()も参照してください 。
void *QSGGeometry::vertexData()
このジオメトリオブジェクトの生の頂点データへのポインタを返します。
vertexDataAsPoint2D() およびvertexDataAsTexturedPoint2D()も参照してください 。
const void *QSGGeometry::vertexData() const
このジオメトリオブジェクトの生の頂点データへのポインタを返します。
vertexDataAsPoint2D() およびvertexDataAsTexturedPoint2D()も参照してください 。
QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D()
頂点データをQSGGeometry::ColoredPoint2D 型の可変配列としてアクセスするための便利な関数です。
const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() const
頂点データをQSGGeometry::ColoredPoint2D の不変配列として取得するための便利な関数です。
QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D()
頂点データをQSGGeometry::Point2D 型の可変配列として取得するための便利な関数です。
const QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() const
頂点データをQSGGeometry::Point2D の不変配列として取得するための便利な関数です。
QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D()
頂点データをQSGGeometry::TexturedPoint2D 型の可変配列として取得するための便利な関数です。
const QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() const
頂点データをQSGGeometry::TexturedPoint2D の不変配列として取得するための便利な関数です。
QSGGeometry::DataPattern QSGGeometry::vertexDataPattern() const
このジオメトリ内の頂点の使用パターンを返します。デフォルトのパターンは `AlwaysUploadPattern` です。
setVertexDataPattern()も参照してください 。
© 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.