Change texture size at runtime

Is there a way to change to the size of a texture a runtime? By this I don’t mean scale it with respect to the model (setTexScale), but change the size of the image that was loaded into panda.

I know that panda supports this to some extent because of the configuration option ‘textures-power-2’, but I can’t figure out to scale all the textures of a model after it has been loaded (for example from 1024x1024 to 512x512).

Any help would be appreciated.
Thanks.

You could do something like this:

# Iterate through all of the textures in the model.
textures = model.findAllTextures('*')
for i in range(textures.getNumTextures()):
    tex = textures.getTexture(i)

    # Extract the texture image.
    image = PNMImage()
    tex.store(image)

    # Scale the texture image to 512x512.
    scaled = PNMImage(512, 512)
    scaled.quickFilterFrom(image)

    # Store the image back in the texture.
    tex.clear()
    tex.load(scaled)

Note that if you have already rendered the model onscreen, some of the textures may have been moved to graphics memory, so that they would no longer have a presence in system RAM (and therefore breaking this code). To avoid this, you can put:


keep-texture-ram 1

in your Config.prc file.

David

Works like a charm, much appreciated.