andrew
andrew

Reputation: 797

Texture Array, creating the texture

I'm working on a section of someone else's code and hence have been limited to the amount of modification I can do. Anyway, I'm currently trying to create a texture array and have become stuck with a problem: What I need to support is n textures being individually loaded and stored as GLubytes in a vector. I then need to take all of the data stored in that vector and store it in a single GLubyte object. Currently my code looks something like this:

vector<GLubyte*> vecPixelData;
GLubyte*         puData;

for(int i = 0; i < NumberOfTextures; i++)
{
    GLubyte* pixData;
    LoadTexture(&pixData);
    vecPixelData.push_back(pixData);
}

int puDataSize = nWidth * nHeight * 4 * NumberOfTextures;
puData = new GLubyte[puDataSize];

for(int i = 0; i < NumberOfTextures; i++)
    *puData += *vecPixelData[i];

Now I'm sure I'm missing some fundamental points on how to copy memory from vecPixelData to puData, and if not, can anyone give me a 'pointer' as to somewhere to begin on how to check if puData is actually storing the data required. (I've tried using the memory window but the data in puData doesn't seem to get altered.)

EDIT: The Solution in the end was:

int puDataSize = nWidth * nHeight * 4; 
    puData = new GLubyte[puDataSize * NumberOfTextures]; 

for(int i = 0; i < NumberOfTextures.size(); i++)
    memcpy(puData + (puDataSize * i), vecPixelData[i], puDataSize);

Upvotes: 2

Views: 559

Answers (1)

Fabio Fracassi
Fabio Fracassi

Reputation: 3890

If I understand your problem correctly you need to use std::copy. Something along the lines of std::copy(*vecPixelData[i], *vecPixelData[i] + imageSize, puData + offstet) (leaving the calculations of imageSize and offset to you) inside your last for loop.

Upvotes: 1

Related Questions