D3D9 Again

Discussions related to graphics (2D and 3D), animation and games programming
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

D3D9 Again

Post by Ric »

I have another problem, which is not really related to D3D but to STRUCTURES.
The following to sets of code relate to two ways of getting vertex data into a buffer. The method using indirection works (please don't cringe Richard), but i do not know how to get the Structure method to work.

Code: Select all

      DIM Our_Vertices 83
      !Our_Vertices      = FN_f4(0.0)
      !(Our_Vertices+4)  = FN_f4(0.3)
      !(Our_Vertices+8)  = FN_f4(0.0)
      !(Our_Vertices+12) = FN_f4(0.0)
      !(Our_Vertices+16) = FN_f4(0.0)
      !(Our_Vertices+20) = FN_f4(-1.0)
      !(Our_Vertices+24) = &FFFF0000

      !(Our_Vertices+28) = FN_f4(-0.5)
      !(Our_Vertices+32) = FN_f4(-0.3)
      !(Our_Vertices+36) = FN_f4(0.0)
      !(Our_Vertices+40) = FN_f4(0.0)
      !(Our_Vertices+44) = FN_f4(0.0)
      !(Our_Vertices+48) = FN_f4(-1.0)
      !(Our_Vertices+52) = &FF00FF00

      !(Our_Vertices+56) = FN_f4(0.5)
      !(Our_Vertices+60) = FN_f4(-0.3)
      !(Our_Vertices+64) = FN_f4(0.0)
      !(Our_Vertices+68) = FN_f4(0.0)
      !(Our_Vertices+72) = FN_f4(0.0)
      !(Our_Vertices+76) = FN_f4(-1.0)
      !(Our_Vertices+80) = &FF0000FF


      DIM CustomFVF{Pos{}=PosFloat3{},Norm{}=PosFloat3{},Col%}
      DIM OurVertices{(2)} = CustomFVF{}

      OurVertices{(0)}.Pos.x%   = FN_f4(0.0)
      OurVertices{(0)}.Pos.y%   = FN_f4(0.3)
      OurVertices{(0)}.Pos.z%   = FN_f4(0.0)
      OurVertices{(0)}.Norm.x%  = FN_f4(0.0)
      OurVertices{(0)}.Norm.y%  = FN_f4(0.0)
      OurVertices{(0)}.Norm.z%  = FN_f4(-1.0)
      OurVertices{(0)}.Col%     = &FFFF0000

      OurVertices{(1)}.Pos.x%   = FN_f4(-0.5)
      OurVertices{(1)}.Pos.y%   = FN_f4(-0.3)
      OurVertices{(1)}.Pos.z%   = FN_f4(0.0)
      OurVertices{(1)}.Norm.x%  = FN_f4(0.0)
      OurVertices{(1)}.Norm.y%  = FN_f4(0.0)
      OurVertices{(1)}.Norm.z%  = FN_f4(-1.0)
      OurVertices{(1)}.Col%     = &FF00FF00

      OurVertices{(2)}.Pos.x%   = FN_f4(0.5)
      OurVertices{(2)}.Pos.y%   = FN_f4(-0.3)
      OurVertices{(2)}.Pos.z%   = FN_f4(0.0)
      OurVertices{(2)}.Norm.x%  = FN_f4(0.0)
      OurVertices{(2)}.Norm.y%  = FN_f4(0.0)
      OurVertices{(2)}.Norm.z%  = FN_f4(-1.0)
      OurVertices{(2)}.Col%     = &FF0000FF

This is the code that defines the vertices

Code: Select all

      DEF FNCreateVertexBufferFromFile(vfile$,buffer%)

      num_of_vertices%(buffer%) = 3
      vertex_format%(buffer%)   = 82
      REM vertex_size%(buffer%)     = DIM CustomFVF{}
      vertex_size%(buffer%)     = 28
      fvf_size%                 = num_of_vertices%(buffer%) * vertex_size%(buffer%)

      SYS d3ddev.CreateVertexBuffer% ,d3ddev%,fvf_size%,0,vertex_format%(buffer%),0,^vBuffer%,0 TO R%:REM CreateVertexBuffer
      IF R% THEN = 0

      PROCvbuffer_set

      SYS vBuffer.Lock%, vBuffer%,0,fvf_size%,^Data_Pointer%,0    :REM Lock

      REM SYS"RtlMoveMemory", Data_Pointer%, ^OurVertices{}, fvf_size%
      SYS"RtlMoveMemory", Data_Pointer%, ^!Our_Vertices, fvf_size%

      SYS vBuffer.Unlock%, vBuffer%                  :REM Unlock

      = vBuffer%

and this the code that defines the vertex buffer.

The question is, What should the statements be that are blocked by the REM statements to allow the transfer of the data in the Structure OurVertices{} to be used instead of the indirection?

Thanks, Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
DDRM

Re: D3D9 Again

Post by DDRM »

Hi Ric,

Tried a quick look, assuming I could just copy and paste you code, but it's too incomplete for that to work. I can try a bit harder later.

An initial thought: are you sure that the organisation of an array of structures in memory is OK for this approach? In structures there are two levels of redirection: from the name to the format block, and then to the data itself. I'm not sure that you end up with the data in a contiguous block in the way you do with consecutive redirections (though you may).

One minor comment: consider redirections of the form

Code: Select all

Our_Vertices!4
instead of

Code: Select all

!(Our_Vertices+4)
Best wishes,

D
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: D3D9 Again

Post by Ric »

Thanks D,

In Richard's translation of d3d11 tutorials he uses structures, so it must be possible, but I can't work out what his code means.

I'm not near my laptop, I'll post the example later.

Regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
DDRM

Re: D3D9 Again

Post by DDRM »

Hi Ric,

Richard asks how I could have imagined it could be any other way: of COURSE the datablocks are consecutive - so you CAN set up an array of structures, fill it in, and then point at the start of the data (with !mystructures{(0)} ).

....so that's not the reason....

Best wishes,

D
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: D3D9 Again

Post by Ric »

Thanks DDRM
Unfortunately I have had to attend an emergency at work. It wil be Monday before I can look at it again. I'll let you know how it goes.
Kind regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023