Jump to content
  • Advertisement


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


Rendering with D3D

This topic is 6015 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

After checking all recent posts (within 5 days) with potentially relevent titles, I havn''t found anything on this problem. Ugh, here I go again asking a question about a book... In The Zen of DDD3D Game Programing, by Peter Walsh, the render function does something that doesn''t seem logical--to me anyway. If anyone has it, the book describes the rendering process in pages 259-266. Its the code on page 266 that paticularly bugs me... Initalization of D3D I understand, and each function in and of itself I get. However, it is the order of use of said functions that bug me... What the book says to do every frame is (I hope this doesn''t infringe any copyright stuff): 1) Clear the back buffer 2) Get a pointer to the back buffer 3) Lock the back buffer 4) Render to it 5) Unlock it 6) Release the surface (the back buffer) 7) Copy the back buffer to the primary surface Now, I''ve never had any expirience in D3D... only in DirectDraw in DX7 but only to the extent of initalizing it and setting up a double buffer (although I am pretty sure I could plot a pixel if I wanted to ). Now for my question: Do you really need to get a pointer to the back surface and release it EVERY FRAME? It''s location isn''t going to change is it? Why not get it once in the initalization code and release it in the shutdown code? Sorry if this is a horribly, terribly, no-good stupid newbie question. Yes I know I could do an expiriment to find out, but then I wouldn''t get the explination and deeper understanding of the guts of D3D . I learn best from a combination of books and people... since I don''t have a live person to talk to directly, this is the second to next best thing. (next to best would be instant messaging services) Just to note, I don''t doubt that the code works... I''m just asking because it seems rediculous to do something multiple times that you can do once and be done with it. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To all of those who think I''m just being contradictory: No I''m not!

Share this post

Link to post
Share on other sites
hiya, probably the code there is trying to create an animation of some sort and his style is to rearrange the pixels within the buffer so that''s probably the reason behind the locking/unlocking..,

but anyway, it''s really upto you, i also think the same way before(probably upto now) but you have to know why the author did it that way, after all, in programming, there''s a ton of solution to a particular problem and that one is the author''s solution,

Share this post

Link to post
Share on other sites
If you have more than one back-buffer, or use double-buffering with flipping, then you might get different buffers in different frames, so you can''t store the first backbuffer pointer you got. Another reason is that you can''t copy a backbuffer to frontbuffer while it''s locked, because you might be reading and modifying data at the same time which is a Bad Thing. Moreover, the backbuffer might be in video memory so when you lock it D3D might allocate memory and give you a new pointer for each lock, even if backbuffer is the same.

With that out of the way, you should not lock the backbuffer unless you REALLY know what you''re doing. There are very, very, very few cases when locking backbuffer is necessary. While I''ve never read that book (or any DX book, for that matter), it must be doing something strange if it needs to lock the backbuffer during rendering. You should be able to accomplish whatever that is without locking.

What are you drawing to the locked backbuffer? Text, maybe?

Share this post

Link to post
Share on other sites

Actually it''s a pretty bad way to do it. In general, don''t lock the back buffer. It''s very slow. This is one of the harder ideas for people to accept when they come from DirectDraw to D3D. Never lock the back buffer.

Generally your render function is something like:
Clear Screen (and ZBuffer if present)
Render Stuff with the various DrawPrimitive functions

You might use one of the font interfaces or D3DXSprite, but basically they just draw triangles using those same routines.

I REALLY didn''t like that book.

Stay Casual,

Drunken Hyena

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!