Sign in to follow this  

Should i be using LockRect?

This topic is 3840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heres the situation... Im reading a texture format, the format gives the height, width, num mips maps and all that kind of info and then it gives the raw image data. This data is dxt1 or dxt3. So up until now I have been creating a texture with the supplied info and then locking the rect reading the raw data into it and unlocking. Is this the best way or should I be doing it another? Thanks for any help, -Dave Heres the source if anyone needs a clearer idea of what im doing...
// create the texture
D3DXCreateTexture(*pDevice, textures[texturePos].width, textures[texturePos].height, textures[texturePos].mipmapCount, D3DUSAGE_DYNAMIC, format, D3DPOOL_DEFAULT, &textures[texturePos].texture);

for(mipmapPos = 0; mipmapPos < textures[texturePos].mipmapCount; mipmapPos++){
    readBinary(is, dataSize);

    imageData = new char[dataSize];
    is.read(imageData, dataSize);

    textures[texturePos].texture->LockRect(mipmapPos, &rect, NULL, D3DLOCK_DISCARD);
    memcpy(rect.pBits, imageData, dataSize);
    textures[texturePos].texture->UnlockRect(mipmapPos);

    delete [] imageData;
}

Share this post


Link to post
Share on other sites
The pitch may not always be the same as width * bytesPerPixel and therefore you should loop through the height and make sure you fill each row or pixel instead. If it's possible to just copy any arbitrary format like that into the texture memory i'm not sure but at least it's possible to clear all the pixels to an arbitrary color.


for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
void* curPixel = rect.pBits + y * rect.Pitch + x * bytesPerPixel;
*curPixel = MYCOLOR;
}
}

Share this post


Link to post
Share on other sites

This topic is 3840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this