Page 3 of 7 FirstFirst 12345 ... LastLast
Results 21 to 30 of 63

Thread: Loading DX Textures in an imagelist - which is the fastest?

  1. #21

    Loading DX Textures in an imagelist - which is the fastest?

    Try this replacement OmegaImageList.pas
    OmegaImageList.zip

    It behaves exactly the same as the standard OmegaImageList, except it has some additional functionality.

    OmegaImageList.ImageList.LoadFromFileData(Filename : String);
    OmegaImageList.ImageList.LoadFromStreamData(Stream : TStream);
    OmegaImageList.ImageList.SaveToFileData(Filename: String);
    OmegaImageList.ImageList.SaveToStreamData(Stream: TStream);

    To test it out, load your imagelist as normal, then after the call to OmegaImageList.Init, call OmegaImageList.ImageList.SaveToFileData() with a different filename. Run your application and it should write out a file.

    Comment out the calls to LoadFromFile, Init and SaveToFileData. Add in their place a call to OmegaImageList.ImageList.LoadFromFileData(). No call to Init() is required! Run the game and see if there is any speed difference.

    Here is my test code.
    Code:
    {.$DEFINE CREATEFILE}
    {$DEFINE LOADFILE}
    
    procedure TForm3.FormCreate(Sender: TObject);
    {$IFDEF CREATEFILE}
    var
      Item: TImageListItem;
      Index: Integer;
    {$ENDIF CREATEFILE}
    begin
      OmegaScreen1.Init;
    
    {$IFDEF CREATEFILE}
      for Index := 1 to 7 do
      begin
        Item := OmegaImageList1.ImageList.Add;
        Item.Filepath := 'D:\Files\Bitmaps\Tatiana\Tatiana' + IntToStr(Index) + '.jpg';
        Item.TileWidth := -1;
        Item.TileHeight := -1;
      end;
      OmegaImageList1.Init;
    
      OmegaImageList1.ImageList.SaveToFileData('D:\Temp\tatiana.oil');
    {$ENDIF CREATEFILE}
    
    {$IFDEF LOADFILE}
      OmegaImageList1.ImageList.LoadFromFileData('D:\Temp\tatiana.oil');
    {$ENDIF LOADFILE}
    end;
    
    procedure TForm3.FormPaint(Sender: TObject);
    var
      Index: Integer;
    begin
      OmegaScreen1.BeginRender;
      OmegaScreen1.ClearScreen(0, 0, 0);
      for Index := 0 to OmegaImageList1.ImageList.Count - 1 do
        OmegaImageList1.ImageList.Items[Index].Draw(Index * 32, Index * 32, Index);
      OmegaScreen1.EndRender;
    end;
    The file is essentially a binary dump of the required properties of each image item, plus a PNG file written out by D3DXSaveTextureToFileInMemory(), all packed into one file. The file is loaded one image at a time, so memory usage has been cut dramatically.

    Hope that helps. I scared myself because that code worked first time. Let me know how it goes.

    It's time for me to go to bed seeing as it is now 1:50am and I have to get up at 7am.

    Edit: I also added "uses Jpeg;" so that it could load JPGs.

  2. #22

    Loading DX Textures in an imagelist - which is the fastest?

    Hallo Sly,

    thanks a lot! I have downloaded it and I will test it when I am home again (currently at work).

    Firle

  3. #23

    Loading DX Textures in an imagelist - which is the fastest?

    Hello Sly and everybody interested,

    the Omega forum is back again.
    I made a post to let them know you are working on our Imegalistproblem (thanks again):

    http://www.delphisanctuary.com/forum...920d3e29dcb1#9

    Firle

  4. #24

    Loading DX Textures in an imagelist - which is the fastest?

    Firlefanz, to answer your question in your forum about how to process all your 600 files with pngout, open a command prompt, cd to the directory containing your PNGs, and type this command

    for %I in (*.png) do pngout.exe %I

    Either have pngout.exe in your PATH, in the same directory as the PNGs, or specify the full path to it, such as

    for %I in (*.png) do c:\utils\pngout.exe %I

  5. #25

    Loading DX Textures in an imagelist - which is the fastest?

    This is again a good hint, thanks. But the problem is I have them in imagelists.

    Perhaps I could alter the Imagelsiteditor with a new method:

    1) Export all images with a process number at the beginning of the filename to a temp dir
    2) for %I in (*.png) do imagelisteditorpath\pngout.exe %I progress each single image
    3) Clear the imagelist, reload each single image by beginning number and remove that number.

    Do you know if they only get smaller on harddisk (filesize) or also in memory? Than this would be worth the effort...

    Firle

  6. #26

    Loading DX Textures in an imagelist - which is the fastest?

    Hi Sly,

    I did like you said. I produced some 'sly' files which are a bit smaller (some k) than my oil files.

    But when loading them, and then drawing them to, screen, I get an error.

    In OmegaScreen.setblendmode called from Draw4Col, I am examinig further, maybe I fogot something....

    Firle

  7. #27

    Loading DX Textures in an imagelist - which is the fastest?

    In Draw4Col, it seems

    FRenderer.OmegaScreen.SetBlendMode(BlendMode);

    than FRenderer.OmegaScreen the OmegaScreen is nil.

    I did it like this:

    Imagelistloading:=TOmegaImageList.Create(Commandof orm);
    Imagelistloading.SetOmegaScreen(xenscreen);
    //ImageListloading.ImageList.DecodeFunction := MyDecrypt;
    //imagelistloading.ImageList.LoadFromFile('grafix\im agelistloading.oil');
    //Imagelistloading.init;
    //imagelistloading.ImageList.SaveToFileData('grafix\ imagelistloading.sly');
    imagelistloading.ImageList.loadfromFileData('grafi x\imagelistloading.sly');

    I also tried another Imagelistloading.SetOmegaScreen(xenscreen);
    after that, but when drawing an item the first time I get that error.

    Firle

  8. #28

    Loading DX Textures in an imagelist - which is the fastest?

    Hi Sly,

    I also added a new test button to my imagelisteditor (if you don't have it I can send you the code) and tried to read your new imagelistfile there with loadfromfiledata. It adds the image to my list, but cannot open the picture.

    Did I forget something?

    Firle

  9. #29

    Loading DX Textures in an imagelist - which is the fastest?

    The ImageListEditor won't be able to open the picture because the Picture property is empty. There is no point having the image in Picture as well as a texture. That is a waste of memory. Is there a way around it in the ImageListEditor? Can you draw the texture instead of using the Picture property?

    To fix the crash, try adding these lines at the top of TImageListCollection.LoadFromStreamData.
    Code:
      TOmegaImageList(Owner).FRenderer.OmegaScreen := TOmegaImageList(Owner).OmegaScreen;
      TOmegaImageList(Owner).FRenderer.Init;
    That is something that TOmegaImageList.Init did but I forgot to do. I didn't notice it because I was using TImageListItem.Draw, not Draw4Col.

    Note: The size of the file is dependant on the file type that is specified in the call to D3DXSaveTextureToFileInMemory. I first tried DDS format, but its file sizes were huge. I'm currently using PNG, but you could experiment with different file types.

    I don't know what effect pngout.exe has on the sizes of PNGs in memory.

  10. #30

    Loading DX Textures in an imagelist - which is the fastest?

    Hello Sly and thanks a lot for the fix, I'll try that tomorrow.
    And also thanks for the info. I'll let you know how I proceed, thanks

    I don't need that stuff in the Imagelisteditor, it was just a test.

    Firle

Page 3 of 7 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •