Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Wikkyd

Zen and art of D3D. Why do all the examples run slow?!

This topic is 5714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Specifically the one in Chapter 12... All it is is a Single Triangle!!!!! On my Geforce4 its getting no more than 6 FPS!!!!! Unbelievable! Where is the slowdown?

Share this post


Link to post
Share on other sites
Advertisement
I had that problem too... with all the examples in the book. I never examined it, but I think it has to do with his timing function. He tries to adjust the framerate from frame-to-frame somewhere, and that has got to be what''s slowing it down. I imagine the examples were written on an older version of Windows (non XP), and that may be the trouble... though I can''t be sure.

Share this post


Link to post
Share on other sites
I dont think the example in chapter 12 ever makes a call to the timer function.

In fact I commented out everything in the code except the portion that renders the triangle. Still 6 FPS!

There is an example in the DirectX SDK code that is very similar, a single spinning triangle. I converted that example to full screen mode using the exact same present parameters as the Zen example. The SDK code zooooms in full screen mode.

I just dont get it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Inside the InitDirect3D function he uses a parameter D3DBACKBUFFER_COPY or something like that. Change the _COPY to _DISCARD. That took my framerate from 10fps to over 1000fps!! (Infact I had to change the frame rate drawing function to alow 4 digit numbers to prevent a crash.) I will look up the exact line and parameter when I get home and let you know. But that should be enough to get you back on track.

Share this post


Link to post
Share on other sites
Not sure about your slowdown issue, but I''ve got a question about another thing with that book. He''s lumped all of his classes in a single Engine.h file which is annoying for me, and makes it a nightmare if you try to expand on his code to build something larger. The problem is that if you try to move some of those classes out of that file and make them their own .cpp and .h classes, you lose access to some of the rendering functions he has built without adding pointers to whatever you used to have access to.

I don''t have an example in front of me because I''m at work ... but have either of you encountered this design issue? How''d you go about resolving it?

If I recall correctly ... I''m encountering this problem particularly when I''m working with the console ... and the CConsole is works with the CEntry , which in turn calls LoadBitmapToSurface() which needs a reference to the primary rendering device ... etc. Do I just end up passing references to the primary rendering device through every object I instantiate?

If this is confusing or I screwed it up, I''ll get the exact example when I get home ... but I''ve tried reworking the whole basic architecture twice (once, encapsulating the entire Engine.h file as part of a main Engine object, and another ... pulling it back out as a stand-alone common .h file) and things still don''t seem natural. I''m just trying to avoid problems down the road as the engine gets more complex.

Thanks,
Telstar

Share this post


Link to post
Share on other sites
I realised that I had the code on my work PC too. And I also thought it would be nice to register to the forums.

The function that the problem is in is InitDirect3DDevice, which the authour places in the engine.h file. I''m told that its hugly bad practice to have code in header files so I moved it. I guess you may have moved it too.

You''ll need to find his swap effect code:
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;

And change it to:
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

I think that frees DirectX from having to make sure that the backbuffer does not get used to store any data between frames. I assume this is surprisingly inefficient. Strangly this point is made early on in the book, but seems to be forgotten by the time you get to chaper 12.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Inside the InitDirect3D function he uses a parameter D3DBACKBUFFER_COPY or something like that. Change the _COPY to _DISCARD. That took my framerate from 10fps to over 1000fps!! (Infact I had to change the frame rate drawing function to alow 4 digit numbers to prevent a crash.) I will look up the exact line and parameter when I get home and let you know. But that should be enough to get you back on track.



Are you talking about this:

// The swap effect
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;

//So it would look like this?
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD_VSYNC;

Share this post


Link to post
Share on other sites
Hi Telstar, having the source code in the .h file bothered me too. I''m fairly new at this so I don''t know how the pros split their code between .cpp and .h files. However, my solution for the code examples in Zen of D3D was to have a .cpp and .h for each general area of the code. For example a console.cpp and console.h, engine.cpp and engine.h, etc. I have been puting the class definitions and function prototypes into the relavent .h file, and the source code in the .cpp. Any global variables I decalre in the .cpp file that they are first used. Assuming that these globals will be needed in other source files I have them also defined with the extern keyword in a general .h file which I call for every .cpp. That seem to work ok, calling the .h file for any module that a .cpp needs. For instance font.h to use the font engine in the console.cpp.

I hope this isn''t too patronising, or too much of a newbie point to post on these forums. Zen seems like a very good book, but several mistakes have had me stumped and clearly others too.

Share this post


Link to post
Share on other sites
Not patronizing at all. I''m here for help and happy when people are willing to provide it.

I''ve been splitting my classes off as it sounds like you have. The thing I forgot about was the extern keyword. I had a mess of parameters being passed all over the place but extern should solve that. I''ve been away from C++ for a number of years and I think I''m seeing the result.

Thanks again,
Telstar

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!