#### Archived

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

# BeginScene() & Render Loop

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

## Recommended Posts

To all DirectX gurus ... The standard render loop for my D3D programs is generally structured as follows : { Set View Matrix Transform Vertices via world matrices BeginScene(); Draw Primitives EndScene(); } Is this the most efficient method, or is there a better way ? Is it best to keep the code between BeginScene() and EndScene() as short as possible ?

##### Share on other sites
good question.

i think the EndScene() call flushes all buffers and waits for pending operations to complete.
and puts the card back into "normal operation" so you can do 2d stuff (gdi etc.).

keeping the code inside as short as possible should not be a good idea, since all you do between the BeginScene() EndScene() pari is executed in parallel with the GPU, at least if you do it right.
so moving work bevore/after the rendering-block, that could be done WHILE pushing polys would decrease performance.
if you transform more than one object, transform the first, then render it, and while the 1st renders, transform the next etc.

if you can avoid to touch any geometry with the CPU, means no transform & stuff, no reading vertices and so on.
if you just want your objects in the right place then
  for every frame BeginScene(); Clear(); if is_this_1st_frame goto skip_render for every object // do whatever you can "per-object" here, just bevore rendering set world-matrix render object // let D3D transform it for you endforskip_render: do game-logic etc. calculate new positions for objects calculate new view-matrix etc. EndScene() D3D8: Present() -- or -- D3D7-: Flip()endfor

i think this general approach should be o.k. for speed - if anyone has better suggestions or i have made wrong assumptions about EndScene(), please correct me.

bye,

--- foobar
We push more polygons before breakfast than most people do in a day

• 10
• 17
• 9
• 14
• 41