Archived

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

What goes between BeginScene and EndScene?

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

OK, I know this sounds a daft question, but I haven''t been able to find anywhere a definitive list of methods that have to be called between the calls to BeginScene() and EndScene(). The Microsoft documentation is extremely vague, stating that BeginScene() must be called before any rendering. Obviously this includes calls to DrawPrimitive() and possibly SetVertexShader(), SetMaterial() and SetTexture(). I would be grateful if anyone could point me in the right direction. Thanks

Share this post


Link to post
Share on other sites
Erm i always thought well its kinda self explainatory BeginScene is when you "being the scene" EndScene obviously is when you end the scene so therefor everything in between is the scene itself. As for the functions cant you use the directx documentation its like a help file with a list of all the functions. I think thats the only one i can think of there might be more ill look around see what i can find..

[edited by - DevLiquidKnight on September 1, 2002 6:35:18 PM]

Share this post


Link to post
Share on other sites
No, you can perform just about anything outside the Begin/Endscene calls, such as setting transformations, streams, textures, clearing buffers, etc. In fact, you can even render polygons outside the calls, but there is no guarantee they''ll succeed (they do with my setup). Per the DX SDK:

Applications must call this method before performing any rendering and must call IDirect3DDevice8::EndScene when rendering is complete and before calling BeginScene again.

According to the SDK, only rendering calls need to be embedded between Begin/EndScene.


Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX

Share this post


Link to post
Share on other sites
Your explanation leads me to believe that you''re not entirely certain yourself :-)

Sounds pretty obvious, but SetTranform() is not something you would include withing the BeginScene() EndScene() function calls, yet SetVertexShader() is. Both are fundamental to drawing the scene.

Truth is, I don''t like guessing and would prefer a slightly more solid explanation than this :-)

Share this post


Link to post
Share on other sites
I can''t give you a direct answer to your question, however, I believe the idea behind it is this:

The purpose of BeginScene and EndScene is to tell DirectX that your program is going to be rendering, so it should prevent other applications from stepping on your programs toes.

For example, lets say you are running 2 programs that deal with vertex shaders. Vertex shaders are like assembly language that pop things to the graphics card memory addresses. If you have 2 applications multitasking at the same time, they could potentially be putting values into the same memory addresses at the same time, and clobber each other.

If you are using BeginScene and EndScene, DirectX can then force the other program to wait until the first is finished doing its stuff.

If you think of it in that light you can get an idea what is ok or not.

However, I could be misinterpreting the point of begin/end scene.

Share this post


Link to post
Share on other sites
negascout, Jim Adams is right.

State changes inside or outside Begin/EndScene.
Drawing calls only inside Begin/EndScene.

Whether other combinations work on your card or not are irrelevant. The API doesn''t officially allow it.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
quote:

Your explanation leads me to believe that you''re not entirely certain yourself :-)

Truth is, I don''t like guessing and would prefer a slightly more solid explanation than this :-)



And to quote myself:

quote:

No, you can perform just about anything outside the Begin/Endscene calls, such as setting transformations, streams, textures, clearing buffers, etc. In fact, you can even render polygons outside the calls, but there is no guarantee they''ll succeed (they do with my setup). Per the DX SDK:

Applications must call this method before performing any rendering and must call IDirect3DDevice8::EndScene when rendering is complete and before calling BeginScene again.



So, again, yes you can do anything except rendering calls safely outside the BeginScene/EndScene calls. SetVertexShader is not considered a rendering call, so you can safely call it outside the BeginScene/EndScene block.


Share this post


Link to post
Share on other sites
What EndScene() does is flush all outstanding calls on the graphics card, meaning that if you don't use EndScene(), you might be Present()ing the backbuffer too soon and get incomplete results. This is obviously mainly an issue for large DP() or DIP() calls, and is, as far as I've found, mainly driver dependent. (as Jim has said) Some drivers don't require you to do EndScene because they automatically wait for the buffers to clear before presenting.
However, always use BeginScene and EndScene - there's hardly any overhead and will keep you from nasty compatibility issues. As for what goes between them - I think it might even be better to put as much as possible between them, as EndScene actually might be stalling execution and wasting CPU cycles that could be used for game logic or AI code, but this is just one of my theories...

edit: my spelling once again

- JQ
Full Speed Games. Coming soon.

[edited by - JonnyQuest on September 2, 2002 6:26:46 AM]

Share this post


Link to post
Share on other sites