Problems reloading textures!

Blitz3D Forums/Blitz3D Programming/Problems reloading textures!

Serpent(Posted 2010) [#1]
In a program I'm writing, I need to reload the same bitmap file (which is a screenshot) over and over again as a texture - i.e. the bitmap is updated when a screenshot is taken and needs to be loaded as a new texture.

The problem occurs when the bitmap is reloaded. Even if the bitmap has changed, LoadTexture() returns the same handle as when it was first loaded.

I can get around this by using a different filename for each screenshot, but it's strange that this happens.


I don't think the problem has anything to do with my code. I wrote a simple test program:



All that this does:
- Loads "Test.bmp" as an image and a texture.
- Displays the 2D image in the top-left corner
- Displays a cube textured with the texture in the bottom-right corner
- Reloads the image and the texture whenever the spacebar is hit


To see the problem, just create two different bitmaps in paint (i.e. each a different coloured rectangle), name one "Test.bmp", run the program, rename them so that the other one is "Test.bmp", then press spacebar.

The 2D Image in the top-left changes to the new "Test.bmp"
The texture remains the same, as seen in the bottom-right.



I dont know what to make of this, but it's almost like Blitz3D remembers that the texture was already loaded and is in memory (again, despite the fact that the texture was already 'freed' from memory).

If anybody knows anything that could help or shed light on this that would be great.


_PJ_(Posted 2010) [#2]
It is weird, you're right.

I tried a few different things, i.e. using brushes instead of straight textures or full absolute pathnames to the bitmaps, but the only thing that seemed to work properly was introducing the ClearTextureFilters command.




puki(Posted 2010) [#3]
Freeing a texture means you will not be able to use it again; however, entities already textured with it will not lose the texture.



Serpent(Posted 2010) [#4]
It seems very strange that calling ClearTextureFilters before each time you reload the texture would fix this problem. Thanks for finding this Malice. But it seems only to work for one reload. When the program tries to reload again, the texture does not change.


Serpent(Posted 2010) [#5]
The only explanation that I have is that Blitz caches the file when first loaded as a texture to reduce load times later....


jfk EO-11110(Posted 2010) [#6]
This is DirectX's Memory usage and Loading optimation. It is thinking the texture is already in Memory and is using the already loaded version. Unfort. it doesn't know that you have altered it.

Quick work around: load them as an image and CopyRect it to a Texturebuffer made with CreateTexture. There might be a limitation: images may not be bigger than the desktop. But in your case it IS the desktop, so it should work.

(But you should use power-of-2 sizes for the texture only anyway, eg. 1024*1024, or 2048*1024, then copyrect the desktop to the center of it.)


Serpent(Posted 2010) [#7]
Thanks jfk. This is annoying, but at least its possible to work around.


_PJ_(Posted 2010) [#8]
[qouote]Freeing a texture means you will not be able to use it again; however, entities already textured with it will not lose the texture.[/quote]
Whilst this is true, retexturing with a different texture will upddate the existing. The problem in this case is that the path to the original texture seems to be retained in the mesh information itself, So Blitz (DrectX whatever....) doesn't 'realise' the file has changed. But anywho, welcome back Puki ;)

There's a few ways of working around, but it is a weird problem. As for the ClearTextureFilters, sorry I only tried changing it once, It was pure chance I tried it.


Serpent(Posted 2010) [#9]
I think I've figured out why using ClearTextureFilters works. As it removes default filters that are applied to the texture, the second time the texture is loaded it is loaded with different filters, forcing the texture to be reloaded.
Just as a test I applied random filters each time the texture was loaded (to see if it would be reloaded each time). Sure enough it seemed to work.