Vertex Buffers - Help please.

BlitzMax Forums/BlitzMax Programming/Vertex Buffers - Help please.

TartanTangerine (was Indiepath)(Posted 2005) [#1]
This is as far as I got, it does not work and I need help please. : http://www.blitzbasic.com/Community/posts.php?topic=51859


CreateVertexBuffer Method (In file d3d7.bmx):
Type IDirect3D7 Extends IUnknown
	Method CreateVertexBuffer(vbdesc:Byte Ptr ,d3dvertexbuffer:IDirect3DVertexBuffer7 Var,dword)

IDirect3DVertexBuffer7 Methods (In file d3d7.bmx):
Type IDirect3DVertexBuffer7 Extends IUnknown
	Method Lock(Flags,lplpData:Byte Ptr Var,Size)
	Method Unlock()
	Method Optimize(lpD3DDevice,dwFlags)
	Method ProcessVertices(dwVertexOp,dwDestIndex,dwCount,lpSrcBuffer,dwSrcIndex,lpD3DDevice,dwFlags)
	Method GetVertexBufferDesc(lpVBDesc:Byte Ptr Var)
End Type

I've probably made a complete arse of it. I don't have the directX7 SDK and I can only find snippits of code on the web to help me out.

Somebody please come to the rescue.


Shambler(Posted 2005) [#2]
Im getting compile error, 'unable to convert from D3DVERTEXBUFFERDESC to Int' what am I missing?

[Edit] .


TartanTangerine (was Indiepath)(Posted 2005) [#3]
You need to put those methods into the directx module called d3d7.bmx and do a makemods.


TartanTangerine (was Indiepath)(Posted 2005) [#4]
There must be someone out there with some experience of this? Think about the benefits of having quads cached in videomemory and using hardware transformations for rotation and scaling..

please help.


Braincell(Posted 2005) [#5]
Oh i posted in another post (didnt see this thread) that i think Tom (aka Scouse) should be able to help you with this, he's on IRC msot of the time as well.


Shambler(Posted 2005) [#6]
Still looking at it, the CreateVertexBuffer is returning the D3D error 'invalid params' so I'm not sure it is actually being created and thats why you get the crash when you try and lock it.

Global result:Int


result=9999
result=primarydevice.d3d.CreateVertexBuffer(desc,d3dVertexBuffer,Null)
Print "result from Create Buffer="+result 'should be 0 for D3D_OK



Shambler(Posted 2005) [#7]
Woot its working! I think lol



The parameters in the vertexbuffer description were in the wrong order.


TartanTangerine (was Indiepath)(Posted 2005) [#8]
heh, I could not see the wood for the trees.

EDIT IT WORKS!!

I just rendered my first Triangle with Vertex Buffers!!!

primarydevice.Device.DrawPrimitiveVB(D3DPT_TRIANGLELIST,d3dVertexBuffer,0,12,0)
Flip



TartanTangerine (was Indiepath)(Posted 2005) [#9]
Hell, thet seem to be slower then building the vertexes every time.

Perhaps I need to get the optimize function working!


Shambler(Posted 2005) [#10]
Post your code! ;P

[Edit] I wonder if BMax is creating a TnLHALDevice or not...will have a quick look.> looks like it just gets the primary display adapter...figures =)

[Edit] You shouldn't have to optimize the buffer to get great performance...optimizing shouldn't gain you that much.


Shambler(Posted 2005) [#11]
Found this info...

D3DFVF_XYZRHW
Vertex format includes the position of a transformed vertex. This flag cannot be used with the D3DFVF_XYZ or D3DFVF_NORMAL flags. If you use this flag, you must also specify a vertex color component (D3DFVF_DIFFUSE or D3DFVF_SPECULAR) or include at least one set of texture coordinates (D3DFVF_TEX1 through D3DFVF_TEX8).

Also try putting
desc.dwCaps = D3DVBCAPS_WRITEONLY

in the description...means D3D can optimize a bit because it knows you aren't going to read the buffer.


TartanTangerine (was Indiepath)(Posted 2005) [#12]
[edit]shambler, I was already setting the buffer to readonly.

It seems to unpredictible. Sometimes the buffer is about 100-200% faster, sometimes its 10% slower.

Here's the code




TartanTangerine (was Indiepath)(Posted 2005) [#13]
Either way it looks like even a small buffer consisting of 3 vertices is faster than using the normal method of drawing vertices. Storing the buffer in videomem is much faster in most cases but you must enable TnL to use that function.

I'm going to go away now and write a DrawImageFast function and then I'll expand it to cater for DrawAnimImageFast (single surface). Not sure how much I'll charge for it yet though?


Shambler(Posted 2005) [#14]
Im getting a crash here
primarydevice.Device.DrawPrimitiveVB(D3DPT_TRIANGLELIST,d3dVertexBuffer,0,12,0)


What do your function declarations look like in d3d7.bmx for the VB and non VB drawprimitives?


TartanTangerine (was Indiepath)(Posted 2005) [#15]
ah my fault..

Change DrawPrimitiveVB to this :
Method DrawPrimitiveVB(primtypem,d3dvertexbuffer:Byte Ptr,startvert,numverts,flags)	



Shambler(Posted 2005) [#16]
OK, working here now...looking into speed issue.

[Edit] Yes it is always faster. sometimes alot sometimes only slightly, my guess is the performance difference will be more apparent when you render a more complex object.


TartanTangerine (was Indiepath)(Posted 2005) [#17]
WOOOOSH

I went full screen and got this

100000 Triangles

TnL - Buffer in Vidmem = 230Ms
HAL - Buffer in Memory = 700Ms
No Buffer Normal Draw = 2690Ms

This is pretty much constant in Full Screen.


Shambler(Posted 2005) [#18]
Oh yes thats more consistent!

DrawVB coming out about 6 times faster here, 100000 triangles...

TnL
107ms for VB DrawPrimitive
627ms for standard DrawPrimitive


Eikon(Posted 2005) [#19]
Hi Tim, this is nice work, as usual.

Speed test results:
67 VB DrawPrimitive
10326 DrawPrimitive

If you do get a DrawImageFast working from this, would you be able to do the same in OpenGL?

Also, is it sopposed to look like this? Seems like there's an error drawing one of the triangles which is causing the 10 sec delay.



TartanTangerine (was Indiepath)(Posted 2005) [#20]
Hi Eikon,

Yeah don't worry about that.

I've managed to get rotations, scaling and positions all managed by directX. So it's possible to draw images using the vertex buffer. I'm building a module and extensions to the existing directX module so it'll be easy to set up and use. I'll try and make it all as automatic as possible, ie. if your system does not support t&l then the vertex buffer will automatically be in system memory etc..

I'll also be looking to build this into my AnimImage Class.

As far as OpenGl is concerned, maybe another day. I've too much on my plate already. I've got a business to run, a family to keep happy and a bank manager to satisfy :P