• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Custom main mipmap level (OpenGL)

Started by Luuk van Venrooij, 23 October 2007, 20:25:15

Previous topic - Next topic

Luuk van Venrooij

Currently I`m using your imagelib for loading my textures in the Genesis
Device engine. Works great and loads my textures very fast. Currently I`m
implementing detail settings for the engine. Because my terrain can use
mosaik textures it can eat up a lot of video memory and a texture
detailsettings is needed. My testmap for example uses 64 textures of 1k x
1k:). I created a version of your LoadGLTextureFromFile that can load the
texture with smaller dimensions to save memory.

function LoadTextureFromFile( aFileName: string; aDetail :
TGDTextureDetail ): GLuint;
var
 iImagesArray   : TDynImageDataArray;
 iWidth, iHeight : Integer;
begin
 if LoadMultiImageFromFile(aFileName, iImagesArray) and
(Length(iImagesArray) > 0) then
 begin
   case aDetail of
     TD_LOW     : begin
                    iWidth  := Round( iImagesArray[0].Width  * 0.50 );
                    iHeight := Round( iImagesArray[0].Height * 0.50 );
                  end;
     TD_MEDIUM  : begin
                    iWidth  := Round( iImagesArray[0].Width  * 0.75 );
                    iHeight := Round( iImagesArray[0].Height * 0.75 );
                  end;
     TD_HIGH    : begin
                    iWidth  := iImagesArray[0].Width;
                    iHeight := iImagesArray[0].Height;
                  end;
   end;
   Result := CreateGLTextureFromMultiImage(iImagesArray, iWidth, iHeight,
True, ifUnknown);
 end
 else
   Result := 0;

 FreeImagesInArray(iImagesArray);
end;

It works ok but it`s very slow for Low an medium. This because textures
are rescaled, mipmaps are regenerated enz. Since I`m already using dds
textures with mipmaps and compression I was wondering if you could expand
the ImagingOpenGL.pas with some settings which lets you choose from which
mipmap level you want to start loading. Something like this:

case aDetail of
 TD_LOW     : Start loading to GFX card at iImagesArray[2];
 TD_MEDIUM  : Start loading to GFX card at iImagesArray[1];
 TD_HIGH    : Start loading to GFX card at iImagesArray[0];
end;

This would lead of course to smaller textureload with much faster loading:).

I played a bit arround with the CreateGLTextureFromMultiImage to do just
that but without any results.

Thanks in advance.

Galfar

I added new parameter to CreateGLTextureFromMultiImage function which specifies
index of image in array which should be used as main mipmap level. New ImagingOpenGL.pas
is in SVN repository.

You can use it like this:

case aDetail of
  TD_LOW: MainLevelIndex := 2;
  TD_MEDIUM: MainLevelIndex := 1;
  TD_HIGH: MainLevelIndex := 0;
end;
GLTextureID := CreateGLTextureFromMultiImage(ImagesArray, 0, 0, True, MainLevelIndex);

Note that those two zeroes for Width and Height are important.
Let me know if it works ok for you.

Game with MainLevelIndex := 5 in action:

Luuk

Just added the new version and code and it works perfecty, thanks for this! :)

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk