As the subjects asks, is there an equivalent feature in DirectX
Basically I want to just render about 200 spheres most of which will be the exact same copy of each other. Drawing each sphere independently of each each other gave quite poor performance in OpenGL until I used Display lists which enabled me to save a fixed set of drawing commands and just call the display list instead of redrawing the sphere each time. That gave a HUGE boost in speed. With 40% CPU usage I could easily render about 200 spheres at 60FPS in OpenGL.![]()
I want to know if directX has a similar feature. I've searched a lot online and on these forums but I can't really find anything that covers this topic. Since DirectX is definately as capable as OpenGL, I'm sure there is a way for me to render 200 spheres with approximately the same framerate as I can openGL... I just can't seem to find it.
Right now 20 spheres run at less than 30FPS with 100% CPU usage in DirectX
... the spheres are of approximately the same detail in my OpenGL code as my DirectX code, this is certainly not good! What optimizations exist in DirectX for handling multiple rendering of the exact same mesh/object.
Any help would be appreciated.

Does DirectX have the OpenGL equivalent of Display lists?
Meaks
I will take a closer look into it, but there isn't that much to look at. The framework code is basically an exact replica of the lighting example in the directX SDK. I simply replaced the cylinder used with a mesh and just used Mesh.DrawSubset(0).
Then I just looped the Mesh.DrawSubset(0) to draw multiple meshes.
I've also included the same basic render loop into different frame works that were send to be faster than the tutorial ones that come with the SDK but it is no different.
I guess I need to read up more about vertexbuffers and streaming and see if I learn something new there. I guess I was just hoping for a quick way out by just putting the Mesh.DrawSubset routine into a sort of 'display list' and just automatically get speedy performance...
Maybe directX needs a little more work than that, not sure though.
Cappy Popp
Thanks for saving me the hassle of going through that myself... I guess then maybe the problem lies with the framework I'm using, or that there are certain optimizations that I haven't enabled (similar to HardwareVertexProcessing ) Basically I want to offload as much work to the graphics card as possible to reduce the CPU usage.
I have disabled the line that updated the window name each frame, but still no difference.
It runs now at just under half the speed of the MFC openGL code I have which is a bit of a dissapointment, since at worst i expected just a 5% difference at most. For now I guess I will just have to accept this huge decrease in performance and continue like this and hope that somewhere along the line when I get more knowledgable about DirectX and C# I can discover why the performance difference is so large... it just bothers me though :(
Nanda Motikane
I did a test using both OpenGL and MDX and I see no difference in performance. No matter what parameters I have used for stacks and slices of the sphere the difference in fps is at most +/- 2 fps.
The problem is: are you sure that you are using the same settings in both OpenGL and DX programs I mean you cannot compare results if one runs with lights enabled and the other one runs with lights disabled for example. Or a different shading model. Or one is using vsync and the other not. There are a lot of settings for 3D and some of them can have a big impact on performance.
Also you should be more carefull about numbers. There's a big difference in number of vertices from 10 stacks and slices to 35, there are about 10 times more vertices. Any older video card would crawl with 250000 vertices.
And about your original question: the best and only equivalent for display lists are vertex buffers. They server the same basic purpose: store a set of vertices so when you want to render them you don't need to do a lot of work (like calling glVertex, glColor etc. tens and hundreds of times at each frame rendering). Where in OpenGL you call glVertex, glColor etc. inside a glNewList/glEndList pair, in DX you set the members of a structure contained in the vertex buffer to the values you want. Mesh itself uses VertexBuffers so there should be no visible difference between using a Mesh and creating your own vertex buffers.
Gerald.Wright
If you use the tutorials as basic you should know that they use only software vertex processing as default. Look for “CreateFlags.SoftwareVertexProcessing” and change it to “CreateFlags.HardwareVertexProcessing”. You should add some code that checks if the card supports hardware vertex processing. In the case it doesn’t you can fall back to software vertex processing or end the program with a message box.
Chrislm
I am just modifying the sample the same way you did and it goes up to 290 FPS on my system. I must confess it is a little bit stronger than yours (A64 3000+; GF 6800 GT) but this is not enough to make this big difference.
You are sure that your FPS measurement works right Maybe you should use FRAPS to get a second result.
scotland
John Schleicher
Oh sorry I am not using 10 slices and 10 stacks it is actually 35 slices 35 stacks, I pasted the wrong mesh info in my post above for some silly reason (bonehead mistake).
10 slices and stacks look really ugly and 35 slices and stacks give me close to the same look i get from my openGL code.
I also double checked my framerate counter with fraps and it seems right.
The glut routine I used in OpenGl used 20 stacks and 20 slices and although i thought the glutsolidSphere routine and the DirectX mesh weren't equivalent because my openGL sphere looks a good deal better than the DirectX mesh does with the same parameters. Any idea why this is so I would have assumed the mechanism for creating sphere meshes would be pretty standard or at least not be significantly different. Is it possible that it could be shading settings that cause the apparent lack of detail
Dropping the stacks + slices down to 20 gives performance that is now 1/6 of the speed of my openGL code. But a bit uglier.
Getting there, but still not where I want it to be...
Thanks for your help so far though ;)
Dinesh Bhat
Ah, I forgot to change the PresentationInterval setting from Default. Leaving it on default sometimes causes really low frame rates on LCD monitors (or at least just mine)
With PresentationInterval set to Immediate I can render 200 spheres at 20FPS which is significantly better than before but still nothing compared to what I could achieve with openGL. I've heard of "instancing" but although I do have an SM3 card, I want my app to be usable by very low end cards too, so that unfortunately wouldn't suit me very well to have to use a feature only enabled on SM3 cards.
Anyway here is my render loop.
while(frm.Created){
frm.Render();
if (ActiveForm != frm){
Thread.Sleep(500);}
Application.DoEvents();}
private void Render(){
if (pause) return;deltaTime =
FrameworkTimer.GetElapsedTime(); this.Text = string.Format("The framerate is {0}", FrameRate.CalculateFrameRate()); FrameworkTimer.Start();device.Clear(
ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.White, 1.0f, 0);device.BeginScene();
// Setup the lights and materialsSetupLights();
// Setup the world, view, and projection matricesSetupMatrices();
for (int i =0;i<10;i++){
for (int j = 0; j < 10; j++){
for (int k = 0; k < 2; k++){
device.Transform.World =
Matrix.Translation((float)(i * 3.0), (float)(j * 3.0), (float)(k * 3.0)) * Matrix.RotationAxis(new Vector3(1.0f, 1.0f, 0.0f), Environment.TickCount / 3000.0f);myMesh.DrawSubset(0);
}
}
}
//End the scenedevice.EndScene();
// Update the screendevice.Present();
FrameworkTimer.Reset();}
And this is my mesh that I use: myMesh = Mesh.Sphere(device, 1.25f, 35, 35);
My program is basically a copy of the directX SDK Lights tutorial, with sphere meshes replacing the cylinder and a few other minor lighting and rotation changes. My comp is a 2.53ghz P4 with a 6600GT graphics card, and the total number of vertices is just under 250000 just in case that info helps you decide whether performance could/should be better.
Is thre no way other than SM3 "Instancing" to do what i need to do in DirectX My knowledge of vertexbuffers is elementary at best and things like streams and locking/unlocking are still not quite clear to me even after reading explanations. I never really had to care about that sort of thing with OpenGL and I don't quite understand the point of doing it or what effects it had on anything. :(
Jonathan Pickard UK
As Ralf suggested, please comment this line:
this.Text = string.Format("The framerate is {0}", FrameRate.CalculateFrameRate());
This is a real performance killer...
Alexan
Even with 35, 35 I am still over 200 FPS. There must be something on your system that holds it back.
Have you try to start it outside the debugger
Do you have any messages in the output windows
Can you remove the line that updates the Window Title and measure with FRAPS (Windows don’t like it very much if you change Window title multiple times per second.)
Yunizar
20 spheres with 30 FPS seems very slow for me. Can you please post your main render code I believe you do something that you should not do.
The best way to render many identical objects is “Instancing” but this requires a Shader Model 3 card.
Kgomong
Ralf, it's definitly not because of the machine. I tried on my machine which is only a P4 2.8 and Radeon 9200 card and I get around 270 fps with ~50% CPU (it's a HT).
But did you notice that Ceres says something about 250000 vertices I don't think you can get 250000 vertices from 200 speheres with 10 slices and 10 stacks...
fantacmet
I enabled hardware vertex processing and I got double my frame rate! So the performance is slowly increasing, but 40FPS and 100% CPU usage is still really bad compared to the 60FPS 15% CPU usage my openGL version gives (i previously said the opengl version was 40% cpu usage, but that was before I used OpenGL display list)
The enable hardware vertex processing was a good call and gave me a good boost but it still needs more work it seems :(
tommy khan
Outside the debugger improves performance but still I only get about 68FPS...
With 20,20 I get performance that is about 1/2 the speed of my Open GL MFC code.
I wonder if I should try and use openGL in c# and see what I get, since its a bit like comparing apples and oranges, but still I expected MDX and c# to produce comparable results to C++ and openGL, not be slower by more than a factor of two :(