Why must a function such as ResizeToTextureSize be time consuming when loading irregular image textures Is there a way to keep shape images from being automatically resized

procedure CalculateImageRightSize(
const Image: TCastleImage; const GUITexture: boolean;
out ImageRightSize: TCastleImage; out ImageRightSizeFree: boolean);
var
Sizing: TTextureSizing;
begin
if GUITexture then
Sizing := tsAny else
Sizing := tsScalablePowerOf2;
if IsTextureSized(Image, Sizing) then
begin
ImageRightSize := Image;
ImageRightSizeFree := false;
end else
begin
ImageRightSize := ResizeToTextureSize(Image, Sizing);
ImageRightSizeFree := true;
end;
end;

Because when textures do not have “power of 2”, we cannot use mipmaps, which makes them look unacceptably bad in some cases (when the texture may be arbitrarily small on the screen; this commonly happens in 3D, but also in some 2D uses).

Other game engines also either resize, or they don’t create mipmaps – in either case, some use-case is hurt.

You can always disable this feature:

  • If you use TCastleImageTransform, set Mipmaps property to false.

  • If you have access to X3D nodes like TImageTextureNode, you can set TextureProperties.guiTexture to true, like this:

var
  MyImageTexture: TImageTextureNode;
  MyTextureProperties: TTexturePropertiesNode;
begin
  ... // initialize MyImageTexture
  MyTextureProperties := TTexturePropertiesNode.Create;
  MyTextureProperties.GuiTexture := true;
  MyImageTexture.TextureProperties := MyTextureProperties;
end;
  • Note that in some cases, we disable this by default. E.g. when using TCastleImageControl, or when loading image or sprite sheet to TCastleScene.

Please put more context in your questions, so that we can help better :slight_smile: Terse question like this makes it harder for me to advise the solution, as I have to guess in what context did you encounter this problem.

If you want specific advise how to deactivate it in your case, please describe / show code how you are using the texture.