Rendering with D3D

Started by
3 comments, last by ElNoNombreHombre 21 years, 10 months ago
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!
To all of those who think I'm just being contradictory:No I'm not!My First Game!!!"
Advertisement
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,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
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?
---visit #directxdev on afternet <- not just for directx, despite the name
G''day!

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)
BeginScene
Render Stuff with the various DrawPrimitive functions
EndScene
Present

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,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena

Oh yeah, and ignore the part of the book that says to use CopyRects to do a text/font engine. Ewww

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement