What'll be faster Lock() or SetTransform()

Started by
8 comments, last by Junk_Master 22 years, 9 months ago
If i need to draw many rectangles in different places of the screen, what should i do to draw each next rectangle? Lock vertex buffer and then change coordinates, or maybe it''ll be better if i will use matrix translation for moving my shapes. Who knows what method is faster, tell me please...
Advertisement
SetTransform every time. Modifying the vertex buffer requires keeping it in system memory, (reading it from video memory by DMA transfer would be so obscenely slow it isnt funny) meaning your frame rate will suffer from having to pass all the verts over the bus every frame. You might not care about this for your rectangles (four verts? who cares about that) but anything else in that VB would be affected too. Then there is the overhead of Lock() itself. In order to change the verts, you have to wait until the chip is no longer using them, which means they have to pass completely through the pipeline before you can even start drawing the next rectangle. With SetTransform the verts are transformed and queued up one after the other in the chip. SetTransform is definitely the way you want to go. Use Lock and your framerate will plummet like a stone.

Edited by - Sandman on July 18, 2001 7:38:27 AM
I tested this. My terrain renderer went from 25fps to 70fps!!! I should have believed those NeXe tutorials all along..... Stupid thing is that I read 3 books on Direct3D (one D3D8 book) and not one of them even mentions that this is way better. Thanks sandman!
You should almost never lock. It''s very slow and there is almost always a better way.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Ok, thanks guys!!! I think this was a stupid question, but i have to ask it because i can''t understand how OpenGL do this - each frame i can simply call glVertex as many times as i want with differennt coordinates and all works very fast. I think i know why - DirectX is child of MICROSOFT!
That''s unfair...

in OpenGL, the equivalent to locking is to create a display list that will be precompiled and much faster on certain hardware. If you compile a display list "around" a set of vertices, that is analogous to creating a DX8 vertex buffer that lives "on the card".

I''m guessing that your OpenGL code would be faster if you used display lists...

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
One second... If Lock() equal to glBuildList(), then what is DX code egual, for examle this:

glBegin(GL_TRIANGLES);

//glVertex some many times
glEnd();
The closest thing is DrawPrimitiveUP(). This takes an array of verts from system memory (using a User defined Pointer) and sends the whole lot to the card. This rather slower than using Vertex Buffers though.
Junk_Master - There''s no exact equivalent, but consider this:

if you make the call
glVertex3f(1.0, 1.0, 1.0);

Then those three floats have to be moved across the bus, to the video card, and then output to the rest of the pipeline.

Optimally, if you have vertex buffers that already live on the card, you can skip that transfer step. In DX8, you mostly want to use VBs. The closest equivalent, mentioned by Sandman, is probably slower than glVertex, but that''s the sort of trade off you get with different APIs.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Ok, ok... I catch.

This topic is closed to new replies.

Advertisement