Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: D3DXFill2D for Filling a cubemap ?

  1. #1

    D3DXFill2D for Filling a cubemap ?

    Hi all !

    I've been recently working on Per Pixel Lighting, and I've got a little problem with D3DXFill2D and D3DXFillCubeMap.

    The function D3DXFillCubeMap seems to require a TD3DXFill2D. That type is a procedure/function pointer.

    So, I define my own procedure to fill in the Cubemap, and then I have the D3DXFill2D points towards the procedure.

    The problem is the error during the compilation

    "Incompatible types "normal procedure and method pointer"" (this might be a bad translation from the French But I hope you see what I mean).

    My procedure is defined with the same parameters(same name, same type) and is called FillCubeMap

    After that, I just call the function D3DXFillCubeMap . this way :

    D3DXFillCubeMap(CubeMap, FillCubeMap, nil);

    And I get my error ... Any ideas ? (CubeMap is my output texture)

    Thanks in advance

    Bye
    Avatar

  2. #2

    D3DXFill2D for Filling a cubemap ?

    It sounds like you are trying to pass a method (of a class) and not a procedure. Even though the parameters as you see them are the same, methods have an additional hidden parameter which is the pointer to the instance of the class (Self).

    The solution is to declare "FillCubeMap" as a normal procedure outside the class, and then pass the pointer to the class instance in as the third parameter to the function ("pData"). In the body of your "FillCubeMap" procedure you can then cast the "pData" parameter to your class in order to access members of the class.

    Also note that the FillCubeMap procedure should have been declared exactly as the prototype:
    [pascal]TD3DXFill2D = procedure (out pOut: TD3DXVector4; const pTexCoord, pTexelSize: TD3DXVector2; var pData); cdecl;[/pascal]

    For example:
    [pascal]
    TYourClass = class
    public
    blah: Integer;
    end;

    ...

    implementation

    procedure (out pOut: TD3DXVector4; const pTexCoord, pTexelSize: TD3DXVector2; var pData); cdecl;
    var
    Self: TYourClass;
    begin
    Self := TYourClass(@pData);

    ...
    Self.blah := 31337;
    ...
    end;

    ...
    var
    YourClass: TYourClass;
    ...
    D3DXFillCubeMap(CubeMap, FillCubeMap, YourClass^);
    ...[/pascal]

    Try that; though you will probably find I have got something wrong somewhere, especially with the @s and ^s.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  3. #3

    D3DXFill2D for Filling a cubemap ?

    Welle since I just build a normalizing cubemap, I don't need pData

    But thanks.

    I have only 2 stupid questions after your post

    1-

    In the implementation ... The procedure needs a name doesn't it ? You just forgot it ? Or did I missed something ?

    2-

    What is cdecl ?

    I'll look in delphi's help, but I never seen that before

    anyway ! Thanks a lot for the answer ^^

    Bye
    Avatar

  4. #4

    D3DXFill2D for Filling a cubemap ?

    Okay ! I found my problem As you said my FillCubeMap function was a method of my Form's class and that didn't work !

    But now I've got another problem. I got an exception when the function is called, during the transfer of one of the parameters into a local variable.

    I compared to C sources and ... I saw something strange ... In C, the function D3DXFillCubeTexture is called with a TD3DXFill3D function ... not a 2D. But here in delphi, it is called with a 2D ... Why ?

    Just to give an idea of what I'm doing here is my code (oh by the way ! No need of cdecl)

    [pascal]
    procedure FillCubeMap(out pOut : TD3DXVector4; const pTexCoord : TD3DXVector2; const pTexelSize : TD3DXVector2; var pData);
    var
    tC : TD3DXVector2;
    Begin

    tC := pTexCoord; // Seems to crash here

    D3DXVec2Normalize(tC, tC);

    D3DXVec2Scale(tC, tC, 0.5);
    tC := D3DXVec2Add(tC, D3DXVector2(0.5, 0.5));

    pOut := D3DXVector4(tC.x, tC.y, 0.0, 1.0);

    end;[/pascal]

    And here the code for the creation :

    [pascal]if Failed(Device.CreateCubeTexture(256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, CubeMap, nil)) then
    Begin
    ShowMessage('The creation of the CubeMap failed');
    dxReady := False;
    exit;
    end;

    if Failed(D3DXFillCubeTexture(CubeMap, FillCubeMap, tmp)) then
    Begin
    ShowMessage('D3DXFillCubeTexture failed');
    dxReady := False;
    exit;
    end;[/pascal]

    Any idea of what makes the app crash ?

    Another question, since we can't put "nil" in the 3rd parameter of the function, any type is good ? Or should I have something special ?

    Thanks
    bye
    Avatar

  5. #5

    D3DXFill2D for Filling a cubemap ?

    Please modify function declaration in D3DX9.pas you have. It should be:
    [pascal] function D3DXFillCubeTexture(
    pCubeTexture: IDirect3DCubeTexture9;
    pFunction: TD3DXFill3D;
    pData: Pointer): HResult; stdcall; external d3dx9texDLL;
    [/pascal]
    So, your code should be:
    [pascal] procedure FillCubeMap(out pOut: TD3DXVector4; const pTexCoord, pTexelSize: TD3DXVector3; var pData); stdcall;[/pascal]
    Sorry for bug in headers ops:
    There are only 10 types of people in this world; those who understand binary and those who don't.

  6. #6

    D3DXFill2D for Filling a cubemap ?

    You CAN call D3DXFillCubeTexture(CubeMap, FillCubeMap, nil) and just do not use pData inside "generation" function. Probably it's better to use Pointer type for "generation" function too, I'll consider this for next SDK update.

    And you NEED stdcall calling convention!!!
    There are only 10 types of people in this world; those who understand binary and those who don't.

  7. #7

    D3DXFill2D for Filling a cubemap ?

    No problem Clootie Thanks for the correction

  8. #8

    D3DXFill2D for Filling a cubemap ?

    Hmmm ... There is no stdcall for TD3DXFill3D ... at least in my sources.

    And it doesn't want of my nil since it's not a variable.

    Finally, it's still crashing ...

  9. #9

    D3DXFill2D for Filling a cubemap ?

    Whats why I pointed you have to have new declaration.
    Just insert this code in your source file:

    [pascal]type
    TD3DXFill3D = procedure (out pOut: TD3DXVector4; const pTexCoord, pTexelSize: TD3DXVector3; var pData); stdcall;

    function D3DXFillCubeTexture(
    pCubeTexture: IDirect3DCubeTexture9;
    pFunction: TD3DXFill3D;
    pData: Pointer): HResult; stdcall; external d3dx9texDLL;

    procedure FillCubeTexture(out pOut: TD3DXVector4; const pTexCoord, pTexelSize: TD3DXVector3; var pData); stdcall;
    begin
    // Do something
    end;

    begin
    D3DXFillCubeTexture(texture, FillCubeTexture, nil);
    end.
    [/pascal]
    It should compile and run fine (but I have not tested it, too busy right now. You'll soon will know why
    There are only 10 types of people in this world; those who understand binary and those who don't.

  10. #10

    D3DXFill2D for Filling a cubemap ?

    hmmmm okay !

    I bet you're working on the new version of the headers

Page 1 of 2 12 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
  •