私は OpenGL を使用してレンダラーに取り組んでいます。
私は最初のクラス、ジオメトリを持っています:
class Geometry
{
public:
void setIndices( const unsigned int* indices, int indicesCount );
private:
std::vector<unsigned char> colors;
std::vector<float> positions;
std::vector<unsigned int> indices;
};
時々、私のジオメトリは、異なるタイプの彼のインデックスをストックする必要があります。データは次のようになります:
1. std::vector<unsigned char>
2. std::vector<short>
3. std::vector<int>
// I've already think about std::vector<void>, but it sound dirty :/.
現在、どこでもunsigned intを使用しており、ジオメトリに設定したいときにデータをキャストしています。
const char* indices = { 0, 1, 2, 3 };
geometry.setIndices( (const unsigned int*) indices, 4 );
後で、実行時にこの配列を更新または読み取りたい (配列には 60000 を超えるインデックスを格納できる場合がある) ため、次のようにします。
std::vector<unsigned int>* indices = geometry.getIndices();
indices->resize(newIndicesCount);
std::vector<unsigned int>::iterator it = indices->begin();
問題は、イテレータがunsigned int配列でループするため、イテレータが 4 バイトから 4 バイトに移動し、初期データが char (1 バイトから 1 バイト) になる可能性があることです。初期データを読み取ったり、新しいデータで更新したりすることはできません。
ベクトルを更新したい場合、唯一の解決策は、新しい配列を作成し、データを入力してから、符号なし int 配列にキャストすることです。インデックス ポインターを反復処理したいと思います。
- どうすれば一般的なことを行うことができますか (unsigned int、char、および short を操作する)?
- コピーせずに配列を反復処理するにはどうすればよいですか?
御時間ありがとうございます!