Sign in to follow this  

What do BeginScene and EndScene do?

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

i know i should to call BeginScene before i state to draw a frame and call EndScene after i have drawn a frame, but i don't what this pair of functions really mean. when i drew a wall and a box, i tried two sequences: Seq1:i BeginSence(); draw wall; draw box; EndSence(); Seq2: draw wall; //before the call of BeginSence() BeginSence(); draw box; EndSence(); i thought the seq2 would make a runtime error but it worked well,the scene displayed was exactly as same as seq1. What do the two function really do?

Share this post


Link to post
Share on other sites
I'm not really sure what they actually do, it's really an implementation detail and you shouldn't worry about it too much. All you need to know is that you should only call each once per frame, and that you should be doing all of your DrawPrimitive calls inside them.

I'm not 100% on this, but I think these calls used to have more meaning back in older versions of D3D and DirectDraw. These days they don't seem to be that important, as you've noted from your experiments. However it's probably best that you simply follow the spec, since it's perfectly within Microsoft's rights to change their behavior in future versions or even within the same version of D3D on a different OS.

Share this post


Link to post
Share on other sites
Thanks for your help.
Do every drawing between the pair, I think I should follow your advices. hehe..I always want to understand every line of code i write.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
All you need to know is that you should only call each once per frame


Much of my code is setup to render different objects differently so I end up calling a begin and end in every one of my objects. Is this incorrect rendering technique?

Share this post


Link to post
Share on other sites
OpenGL has glBegin()/glEnd() that you need to use to tell it you are about to give it some geometry to render. Maybe back in the day BeginScene() would have DirectX do some internal things to get ready to render objects to screen.

Share this post


Link to post
Share on other sites
Quote:
Much of my code is setup to render different objects differently so I end up calling a begin and end in every one of my objects. Is this incorrect rendering technique?


Its not really incorrect, but more of your own personal style of how you want to handle rendering all the objects (scenery, creatures, items, GUI, etc..) in your game. I'm not sure, but I think if you constantly call begin/end scene it might effect your fps, but I'm not sure if thats true. Someone else might be able to confirm this.

The way I handle it is through inheritance. Each object in the game knows what shader technique to use, what particle effect is binded to it, and so forth. This way my object manager can handle the processing and updating movement for all the objects. Then the renderer calls begin/end and the object manager calls its render() function which calls each virtual rendering function of the objects. for example:


g_ObjectManager.Update(dt)
// update other objects/resources that might not be classified as objects

g_Renderer.ClearScene(parameters)
g_Renderer.BeginScene()

g_ObjectManager.Renderer()

// render other objects/resources that aren't classified as objects if
// they need to be rendered

g_AtomGFXStats.Display() // atom is my engine name

g_Renderer.EndScene()
g_Renderer.PresentScene()

Share this post


Link to post
Share on other sites
Quote:
Original post by realkiran

Much of my code is setup to render different objects differently so I end up calling a begin and end in every one of my objects. Is this incorrect rendering technique?


Yes, that is definitely incorrect. See the documentation for IDirect3DDevice9::BeginScene:

There should be at most one IDirect3DDevice9::BeginScene/IDirect3DDevice9::EndScene pair between any successive calls to present (either IDirect3DDevice9::Present or IDirect3DSwapChain9::Present). IDirect3DDevice9::BeginScene should be called once before any rendering is performed, and IDirect3DDevice9::EndScene should be called once after all rendering for a frame has been submitted to the runtime.

The point I made earlier was that just because it *works* when you call BeginScene/EndScene for every object, it doesn't mean you shouldn't still follow the documentation. Otherwise you could very easily end up with strange performance issues, or your app not working correctly on all types of video cards using all types of drivers.

Share this post


Link to post
Share on other sites
Are these commands the same as opengl glBegin and glEnd? If so would it be incorrect to use multiple calls there aswell?

Also I notice that quote says "There should be at most one IDirect3DDevice9::BeginScene/IDirect3DDevice9::EndScene pair". Does this imply the functions aren't completely necessary?

Share this post


Link to post
Share on other sites
They are probably analagous to glBegin() and glEnd(), but just because OpenGL and Direct3D do fundamentally the same thing doesn't mean they have the same semantics and syntax at this low level. Trying to compare them is largely irrelevant.

In my experience you can be pretty slack regarding begin/end scene calls such that my gut feeling is that they are more of a legacy feature than an absolute requirement. Think of them as being a way for your application to annotate its execution - you give the runtime and the driver some context which may well be of use for scheduling/optimization etc...etc...

In the interest of correctness stick with what the docs say, but theres no point losing sleep over it [smile]

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 3578 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this