[Suggestion] ITexture::lock() and data size

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.

[Suggestion] ITexture::lock() and data size

Postby Mloren » Tue Dec 07, 2010 8:26 am

When you call ITexture::lock() it returns a void* to the pixel data, but it doesn't give any indication of the size of that data. Now while you can probably use getColorFormat() and getSize() to work this out, it still feels a little unsafe to me.

If I use these functions to calculate data size, I feel like I'm making an assumption about the internal workings and a dangerous one.

I assume this is the correct approach but it would probably be better if lock() output a data size through an int* parameter or something so you could be sure of the size.
Mloren
 
Posts: 114
Joined: Mon Aug 07, 2006 2:30 am
Location: Australia

Postby hybrid » Tue Dec 07, 2010 9:44 am

Why would you know the size if an int* is returned? While the number of pixels is easily calculated, returning an int* would fail in many situations (e.g. 16bit textures).
A safer way would be to return an IImage*, which would require another lock inturn, though, which would return the void* again. But it would allow to pass more information along.
A much better way would be access via some SColor* type, which transparently handles the access. This is more or less already possible, via setPixel. But it's not really efficient. Moreover, all these changes would require heavy rework of the internals of images and textures, so it won't happen before Irrlicht 2.0 probably.
hybrid
Admin
 
Posts: 13980
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby slavik262 » Tue Dec 07, 2010 1:56 pm

I think he's asking if you could pass a parameter in which the function would set to the number of bytes, i.e.

Code: Select all
virtual void* lock (bool readOnly, u32 mipmapLevel, u32* numBytesOut)


However, Mloren: getPitch() * getSize().Height will get you the total number of bytes, and is perfectly safe. The pitch is the number of bytes per row, so multiplying it by the height of the texture will get the exact number of bytes in that texture.
User avatar
slavik262
 
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Postby hybrid » Tue Dec 07, 2010 3:24 pm

Oh yeah, sorry, I skipped over one of the 'size's in the last sentence.
hybrid
Admin
 
Posts: 13980
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby Mloren » Wed Dec 08, 2010 1:42 am

ok thanks
Mloren
 
Posts: 114
Joined: Mon Aug 07, 2006 2:30 am
Location: Australia


Return to Bug reports

Who is online

Users browsing this forum: No registered users and 0 guests