Still needs optimising and considering 2 days ago I had no idea what a vertex buffer was I think this is pretty damn fast. One way to speed this up would be to use indexedVB, basically you re-use the same vertices multiple times in the same model - I've no idea how to use them :(
I've constructed this in such a way that you can use all of the Flexible Vertex Formats, ie. Transformed, Lit, Specular lighting etc. Transformed vertices are great for HUD's since the matrix calculations don't touch them - They stay just where you put them. You can also choose to store the buffer in vidmem or sysmem, you will need to enable TnL to take advantage of vidmem storage otherwise it'll just slow things down.
The enclosed code will allow you to create a buffer of any size (2000 verts is optimum) and will allow you to rotate,scale and translate the vertices with simple commands. I have also created some quad functions so that you can replace your normal DrawImage commands with Vertex Buffer commands. Quads are not much faster since they are only 4 vertexes and use very little bandwidth
One very good application for this would be a tile map. You could use this code and part of my single surface code to cache a whole tilemap to a buffer. Now when you want to display the tilemap you just draw the buffer, move it all with one command, rotate it and scale it. Now that would be very fast. Objects rendered from the buffer will be clipped by clip-planes, unless you turn that feature off.
Before you download this code you need to be aware that some small changes will have to be made to the d3d7.bmx file in the DirectX Mod. These changes are necessary as the existing declarations for the VertexBuffer Functions are incomplete.
Locate :
Add/Replace the Method :
Locate :
Add/Replace the Method :
Locate :
Add the Methods :
I think that's all. I've tried to make this as stand-alone as possible.
The code : http://www.indiepath.com/tim/vertex_buffers.zip (don't steal the image it's licenced to me not you!)
If you want to enable TnL features then you need to go here :- http://www.blitzbasic.com/Community/posts.php?topic=51795
Have fun.
I've constructed this in such a way that you can use all of the Flexible Vertex Formats, ie. Transformed, Lit, Specular lighting etc. Transformed vertices are great for HUD's since the matrix calculations don't touch them - They stay just where you put them. You can also choose to store the buffer in vidmem or sysmem, you will need to enable TnL to take advantage of vidmem storage otherwise it'll just slow things down.
The enclosed code will allow you to create a buffer of any size (2000 verts is optimum) and will allow you to rotate,scale and translate the vertices with simple commands. I have also created some quad functions so that you can replace your normal DrawImage commands with Vertex Buffer commands. Quads are not much faster since they are only 4 vertexes and use very little bandwidth
One very good application for this would be a tile map. You could use this code and part of my single surface code to cache a whole tilemap to a buffer. Now when you want to display the tilemap you just draw the buffer, move it all with one command, rotate it and scale it. Now that would be very fast. Objects rendered from the buffer will be clipped by clip-planes, unless you turn that feature off.
Before you download this code you need to be aware that some small changes will have to be made to the d3d7.bmx file in the DirectX Mod. These changes are necessary as the existing declarations for the VertexBuffer Functions are incomplete.
Locate :
Type IDirect3D7 Extends IUnknown
Add/Replace the Method :
Method CreateVertexBuffer(vbdesc:Byte Ptr ,d3dvertexbuffer:IDirect3DVertexBuffer7 Var,dword)
Locate :
Type IDirect3DDevice7 Extends IUnknown
Add/Replace the Method :
Method DrawPrimitiveVB(primtypem,d3dvertexbuffer:Byte Ptr,startvert,numverts,flags)
Locate :
IDirect3DVertexBuffer7 Extends IUnknown
Add the Methods :
Method Lock(Flags,lplpData:Byte Ptr Var,Size) Method Unlock() Method Optimize(lpD3DDevice:Byte Ptr,dwFlags) Method ProcessVertices(dwVertexOp,dwDestIndex,dwCount,lpSrcBuffer,dwSrcIndex,lpD3DDevice,dwFlags) Method GetVertexBufferDesc(lpVBDesc:Byte Ptr Var)
I think that's all. I've tried to make this as stand-alone as possible.
The code : http://www.indiepath.com/tim/vertex_buffers.zip (don't steal the image it's licenced to me not you!)
If you want to enable TnL features then you need to go here :- http://www.blitzbasic.com/Community/posts.php?topic=51795
Have fun.