Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: [D3D] Converting TBitmap to Direct3dTexture8

  1. #11

    [D3D] Converting TBitmap to Direct3dTexture8

    Just wanted to add: in whole your discussion you are treating video memory as "infinite". But what will happen when you try to create too many textures in POOL_DEFAULT? Hint: it will fail, but MANAGED textures will be created and D3D runtime will guarantire what managed textures will always be usable by applicaiton and in any time.

    I mean if you want to manage textures by yourself - it's fine. But you should be aware about much more stuff in exhange of smallter application memory footprint. But if you limited by system memory - most probably all your system copies of manages textures will be flushed to swap file after some time - so they will not reduce perfromance in any way.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  2. #12

    re

    Ok, what i am going to say is just a technique that some people could found useful, it is not a "the best and only way" to works with texture data; and even it is not needed if your app/game dosent use big amount textures memory.


    You are right, in games once the texture is loaded is not needed to read the pixels back to memory, Ok then, but i still have the problem how to put in dx the textures when they are not stored in individual files, you see, for my game i have about 15 levels/stages, for stage 1 i have about 30 512x512 textures pages for my world geometry, I am using lightmaps so i have anothers 25 512x512 textures pages for lightmaps, i am also using bump maps in some textures so i also have 20 more 512x512 textures pages with dot3 pixels data for doing bumpmap effect, this es just for the world geomwtry, but I also have about 30 textures pages for Models (characters, baddies, weapons, pickables etc), I also have about 15 textures pages for things likes skybox, particles (fire, spark, snow, rain) animated textures etc, an finally i have about 10 more textures pages for 2d stufs like fonts, message boxes, icons, etc;...and there is another set textures package like that for next level/stage in the game, so do you think is a good idea to have every 512x512 texture page i need in a individual file disk?, i would preffer to put all this well ordered by stage in one texture resource file.

    It is not the same to destroy and then read 130 or more textures files one by one from disk than instead keeping opened one texture resource file and read in memory in one operation one chunk of 130*256*256*pixelsize bytes; and then update the 130 dx textures from that block memory. If you need to load several textures every time the user uses ALT+TAB from switch from application (so the device was lost) or you character go forward/backward between stages so you need to load another set of textures then destroying and loading one by one from disk is very noticiable.

    And, TBitmap could be inherited to create any customized formats... unfortunately the ScanLine[] property of TBitmap isn't implemented in TGraphic, making it harder to read JPG, PNG, and other thrid party graphic format classes out there. But that doesn't stop anyone from working with other formats with TBitmap.
    I am using a free units called graphicsEX, when included in your Units clause then the Timage class is expanded for open much more file formats, like tga,png,jpg,pcx,psp, etc, then i can use:

    var
    I:timage;
    a:bitmap;
    .
    .

    i:=timage.create(sender);
    i.loadfromfile('mytexture.psp');
    a.bitmap:=tbitmap.create;
    a.PixelFormat:=pf24bit;
    a.bitmap.width:=I.Picture.Graphic.Width;
    a.bitmap.Height:=I.Picture.Graphic.Height;
    a.Canvas.Draw(0,0,I.Picture.Graphic);
    i.free;

    That way wahtever file format in whatever color depth was opened is converted into a tbitmap in 24 bits color format.

    of course this is only for my tools, so the user can create content using what ever picture file format they want, but when i compile the content in the playable game data I always save it for my required game engine texture, which is raw rgba headerless data, most the time in 16 bits color coze i dont have lastest top noch ATI videocard that run faster with 32 bits dept color data.


    I made an algorithm to create those box elements using only 12 parameters to define the shape of the box. The idea is to create those boxes from code too.
    hey, somthing like that i am doing too, drawing the world using some kind parameterized boxes, the geometry will looks kind "cubic" but it will help me a lot to do faster and acurate collision, coz for at every position my characters is located I can easily know in what Box with what parameter it is collisionating; :-) i am not ready yet to use those phisics engine from today for checking colision against a soup of triangles.

    It is your editor for a 3d engine?, what kind of world partioned technque are you using?, BSP, Portals, octrees etc?, do you have a bigger picture of your editor? :-), it looks very very very nice.



    [quote]
    But what will happen when you try to create too many textures in POOL_DEFAULT?
    [\quote]

    Hey Clotie, i was thinking POOL_Default mean "keep just one copy in whatever place is currently best, in videomemory if there is available or in system memory if not videomemory available"; i did not know that the resource creation can fail if there is not video memory available when POOL_Default was used.

  3. #13

    [D3D] Converting TBitmap to Direct3dTexture8

    But what will happen when you try to create too many textures in POOL_DEFAULT?
    Hey Clotie, i was thinking POOL_Default mean "keep just one copy in whatever place is currently best, in videomemory if there is available or in system memory if not videomemory available"; i did not know that the resource creation can fail if there is not video memory available when POOL_Default was used.
    I thought the same. But I think Clootie is right, DX help says: "Resources are placed in the memory pool most appropriate for the set of usages requested for the given resource. This is usually video memory, including both local video memory and AGP memory. The D3DPOOL_DEFAULT pool is separate from D3DPOOL_MANAGED and D3DPOOL_SYTEMMEM, and it specifies that the resource is placed in the preferred memory for device access. Note that D3DPOOL_DEFAULT never indicates that either D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM should be chosen as the memory pool type for this resource."

    By the way, D3DXCreateTextureFromFileInMemoryEx also has a lot of interesting parameters that could be very helpful:

    HRESULT D3DXCreateTextureFromFileInMemoryEx(
    LPDIRECT3DDEVICE9 pDevice,
    LPCVOID pSrcData,
    UINT SrcDataSize,
    UINT Width,
    UINT Height,
    UINT MipLevels,
    DWORD Usage,
    D3DFORMAT Format,
    D3DPOOL Pool,
    DWORD Filter,
    DWORD MipFilter,
    D3DCOLOR ColorKey,
    D3DXIMAGE_INFO * pSrcInfo,
    PALETTEENTRY * pPalette,
    LPDIRECT3DTEXTURE9 * ppTexture
    );
    For example, Width and Height allows you to define the final size of the texture. This is helpful to optimize texture depending on the capacity of the graphic device.

    It is your editor for a 3d engine?, what kind of world partioned technque are you using?, BSP, Portals, octrees etc?, do you have a bigger picture of your editor? Smile, it looks very very very nice.
    I'm making a 3D/2D engine, and I'm using it to make this editor. But the editor is part of another project, that is an RPG maker. The camera view is the usual top-down view of RPGs, so the partition might be by map sections. First I have to make a new version to integrate months of additions to the engine, i.e. I'm not using Delphi's VCL anymore, instead I made a GUI system that can be customized. I will take some larger screenshots when I have the new version, which I think will be much better in many ways.

    Thanks for the information about GraphicEx. I'll check it out.

  4. #14

    [D3D] Converting TBitmap to Direct3dTexture8

    Good article about resource creation flags: Resource Management Best Practices @ MSDN

    There is another interesting flag for D3DXCreatetexture: D3DX_SKIP_DDS_MIP_LEVELS. It can be used to skip mip levels when loading a DDS file: D3DX_SKIP_DDS_MIP_LEVELS(levels, filter: DWORD). So on cards with low amount of video memory you can just pass something like D3DX_SKIP_DDS_MIP_LEVELS(2, D3DX_FILTER_BOX) to load mipmap levels (or automatically generate them if not available) only from 3-rd one and up.
    There are only 10 types of people in this world; those who understand binary and those who don't.

Page 2 of 2 FirstFirst 12

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
  •