2

I'm creating an app using VBO to render some objects with difficult color structure. I noticed, that VBO defines the color of the element equal to last vertex index in the element buffer. For example, when I use point array like this

    double pointBuf[]={    -0.1d,  0.1d, 0,
                            0.1d,  0.1d, 0,
                            0.1d, -0.1d, 0};

color array:

    double colorBuf[] = {   0d, 1d, 0d,
                            0d, 1d, 0d, 
                            1d, 0d, 0d};

and element array:

   int elementBuf[] = {0, 1, 2}; 

to draw a triangle, it will be red (as the last element in elementBuf is 2, in colorBuf it matches red).

In fact it can lead to additional memory usage to paint everything correctly.

Is there any other possible way to link colors with elements?

4

2 に答える 2

2

理解しておく必要があることの 1 つは、頂点はその位置だけではないということです。頂点 (OpenGL 用語で) は、属性のベクトル全体です。

/ pos_x        \
| pos_y        |
| pos_y        |
| normal_x     |
| normal_y     |
| normal_z     |
| color_r      |
| color_g      |
| color_b      |
| color_a      |
| texcoord0_s  |
| texcoord0_t  |
| texcoord0_r  |
| texcoord0_q  |
| texcoord1_s  |
| texcoord1_t  |
| texcoord1_r  |
| texcoord1_q  |
| …            |
| texcoordN_s  |
| texcoordN_t  |
| texcoordN_r  |
| texcoordN_q  |
| …            |
| attrib0      |
| …            |
\ attribM      /

これらのいずれかを変更すると、完全に異なる頂点になります。OpenGL のデータ モデルは、各属性を独自の配列に配置してインデックス ベクトルでアドレス指定できるように設計されていません。また、この種のデータ モデルでは、効率的なキャッシュの実装が非常に困難になるため、パフォーマンスが大幅に低下します。

また、メモリが不足していることもわかります。最新のシステムのほとんどは、数ギガバイトのグラフィック クライアント (つまり、CPU) メモリと、少なくとも数百メガバイトのグラフィック サーバー (つまり、GPU) メモリを提供します。GPU メモリに格納できるジオメトリ データ (つまり頂点) の量は、GPU のリアルタイム処理能力を超えています。また、画面で使用できるピクセルよりもはるかに多くの頂点になります。したがって、メモリの問題が発生する可能性は低いと確信しています。ボトルネックは別のものになります。

于 2011-08-19T09:28:02.637 に答える