Low framerate on simple app

Started by
16 comments, last by nex7 19 years, 1 month ago
I've created a class in C# that inherits System.Windows.Forms.Panel for displaying my d3d stuff...so I can just drop my 3d renderer on any old form. Now I am seeing really low framerates ~20 even though it does virtually nothing. The cpu usage is at 1% and it just isnt doing its job. am i missing a setting? the class is based on the vertices tutorial in the directx samples deal. both of the triangle samples have ~20ish fps..where the animation sample is running close to 500 fps. The only thing i see different is that the animation one is using the sample framework deal. Does it speed things up? thanks
Advertisement
It's probably got to do with when you render your scene and how your Main function looks.

first you'd clear out the wmpaint message, or use it, it's anyones descision.

private override void OnPaint(..)
{
// Do nothing
}

static void Main()
{
using (MyD3DApp app = new MyD3DApp())
{
while (app.Created())
{
Render();
Application.DoEvents();
}
}
}

Sorry, didn't read your entire message, you're not making the draw calls from the main function. Well i'd say that the form you are using doesn't get a paint message that often.

First set:
this.Setstyle(Controlstyles.AllPaintingInWmPaint | Controlstyles.Opaque, true);

This makes sure that all the paint messages that the panel might get will get moved to the OnPaint function.

So each time you want the panel to redraw itself you have to call this.Invalidate(); // this being the panels this

Don't forget to put the render code inside the OnPaint function :P

/// Just a side note regarding the MDX tutorials and such..
They're just there to show you how you do certain things, but they never show you how to do it to achieve the most out of the performance. Recreating your matrices every frame? Setting your lights every frame? Not rendering as fast as possible, just using slow render when you feel like it code.

I mean, why show code that does something unless it does it taking in performance and such. Sure the easy read code is welcome in some parts but it also does damage for people just starting to learn. Oh look, they're recreating a model every frame, wow that must be the way to do it ^_^ Not!
I am rendering from the main function, here is my code

static void Main()
{
//create a new basic form
using (Form frm = new Form())
{
// Set the initial size of our form
frm.ClientSize = new System.Drawing.Size(800,600);

//make a new d3d panel
D3DPanel vert = new D3DPanel();

//add the d3d panel to our form
frm.Controls.Add(vert);
vert.Dock = System.Windows.Forms.Dockstyle.Fill;

//init the d3d panel
if (!vert.InitializeGraphics()) // Initialize Direct3D
{
MessageBox.Show("Could not initialize Direct3D. This tutorial will exit.");
return;
}
vert.Show();
frm.Show();
// While the form is still valid, render and process messages
while(frm.Created)
{
vert.Render();
frm.Text= "Direct3D Tutorial 2 - FPS = " + vert.FPS.ToString() + " Frames - " + vert.TotalFramesRendered.ToString();
Application.DoEvents();
}
}
Then i don't know, just started moving from c++ to c#, maybe the text that you're altering is slowing down the framerate, just alter it every second or so instead of every frame.
hrm...thanks for the sidenote up there

Its strange when i take everything out but the fps calculation i get the same fps. There has to be a cap somewhere. Whether it be from the form or panel or something. Driving me nuts!
what is the EXACT frame rate, and does it change?
--X
im ranging from 40 -43 fps...

thats with NOTHING being drawn...im just upping the frame counter.
its using 1% of the cpu
Well I had an idea it might be your vert sync, but I dont know any monitor with a 40 refresh rate. Also at 1% cpu makes no since to me unless you have somewhere a counter that is limiting your program from running at its full speed. Its hard to ask for source code because I dont know where it might be in your program. Was it written from scratch or did you start off some base code? If it was taken from a base code somewhere it might be in your main function. Maybe search for a timer function... like timeGetTime()

Ahh saw your other post just now, show us your vert.TotalFramesRendered() and the rest of the functions that help with this.
--X
i started with the vertices tutorial provided by the directx sample browser..

then i snatched up all of the direct 3d stuff and put it in a different file that inherited Panel...now i have the ability to drop this d3dpanel on any windows form...

BUT...it seems really slow for no reason...i didnt really change anything except REMOVING stuff from the drawing app...


also..if you take the default app from the sample...and add an fps counter to it...it will run slow as well...but the animation sample runs at a good 400 fps on my machine.

i just dont get it...the animation sample is much more complicated..
Well, here's my last 2 cents, go into your presentParameters and create a backbuffer and use swapeffect flip.

This topic is closed to new replies.

Advertisement