[PloobsEngine] Tutorial 6 – Important Objects


Hi all. This tutorial will be diferent from previous ones. We will talk about how to use the engine intrinsic objects to handle common tasks like loading/creating assets, render objects and recover graphic related datas. (tutorials series here)

We already used most of this functions in the last tutorials, but now we will explain each of them in great details.

This tutorial is the last from the series Introduction Demos, the next ones will talk about more advanced features.

The core Classes that exposes graphical related functions to the user are:

  • GraphicInfo
  • GraphicFactory
  • RenderHelper
  • EngineStuff

Before talking about each one, i will tell you where you can get those classes instances.

Every IScreen has a GraphicInfo and a GraphicFactory instance (c# property). They are created internally (the user should not try to create another one) before the IScreen virtual method Initialize being called. (So dont use them in the constructor of the screen, the best practice is to leave the constructor blank and create everything in the initialize/load content methods)

The engine instance is the wrapper for the XNA GAME class (in PC and XBOX, the Phone 7 Version  works a little different) You can access it ONLY in the Initialize and Clean up methods of the IScreen. Normally you should not need to use the wrapper as a “wrapper”. The ploobsengine offers lots of functions that allows you to do everything xna does easier, but we still left to the user a change to recover the xna game class.

The main uses of the EngineStuff class is to Handle Components (explained in previous tutorials), apply general app configurations (showed in the last tutorial) and handle specific tasks like hide the mouse cursor, but it should be avoided.

The RenderHelper is recovered in all DRAW functions of the engine, again, the user should not try to create it.

GraphicInfo

This class is a read-only repository of graphics informations like:

  • BackBufferHeight and BackBufferWidth
  • FullScreenRectangle (Rectangle containing all the screen)
  • HalfPixel (used in some DirectX 9 shaders)
  • Viewport
  • Multisample quality
  • BackBuffer DepthFormat
  • Texture Access information (mipmap, sampling, filters …)
  • Current Graphic Adapter Info
  • Recover the  Window where the Game is running (In Windows plataform only)

You also have a c# event that you can listen to, that tell you when some of this properties changes.

GraphicFactory

The Graphic Factory is responsible for creating and loading all kind of Graphics related resources. To make the life easier for everyone, the functions of this factory have two prefix names. The function starting with GET means that you are loading some existing resource from you HD or somewhere else, the functions starting with CREATE means that you are creating something from ground 0.

Bellow you can find a list of everything that the factory can build (methods):

  • public DynamicIndexBuffer CreateDynamicIndexBuffer(IndexElementSize elementSize, int indexCount, BufferUsage usage);
  • public DynamicVertexBuffer CreateDynamicVertexBuffer(VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage);
  • public IndexBuffer CreateIndexBuffer(IndexElementSize elementSize, int indexCount, BufferUsage usage);
  • public RenderTarget2D CreateRenderTarget(int width, int height, SurfaceFormat SurfaceFormat = SurfaceFormat.Color, bool mipmap = false, DepthFormat DepthFormat = DepthFormat.Depth24Stencil8, int preferedMultisampleCount = 0, RenderTargetUsage RenderTargetUsage = RenderTargetUsage.DiscardContents);
  • public Texture2D CreateTexture2D(int width, int height, bool mipmap = false, SurfaceFormat format = SurfaceFormat.Color);
  • public Texture2D CreateTexture2DBlackAndWhite(int width, int height, bool mipmap = false);
  • public Texture2D CreateTexture2DColor(int width, int height, Color color, bool mipmap = false);
  • public Texture2D CreateTexture2DPerlinNoise(int width, int height, float frequencia, float amplitude, float persistence, int octave, bool mipmap = false);
  • public Texture2D CreateTexture2DRandom(int width, int height, bool mipmap = false);
  • public VertexBuffer CreateVertexBuffer(VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage);
  • public AlphaTestEffect GetAlphaTestEffect();
  • public DualTextureEffect GetDualTextureEffect();
  • public Effect GetEffect(string name, bool clone = false, bool isInternal = false);
  • public EnvironmentMapEffect GetEnvironmentMapEffect();
  • public BasicEffect GetBasicEffect();
  • public SkinnedModel GetAnimatedModel(string name, bool isinternal = false);
  • public T GetAsset<T>(string assetName, bool isInternal = false);
  • public Model GetModel(string name, bool isinternal = false);
  • public IntermediateRenderTarget GetRenderTargetFromPool(int width, int height, SurfaceFormat SurfaceFormat = SurfaceFormat.Color, bool mipmap = false, DepthFormat DepthFormat = DepthFormat.Depth24Stencil8, int preferedMultisampleCount = 0, RenderTargetUsage RenderTargetUsage = RenderTargetUsage.DiscardContents);
  • public Texture2D GetScaledTexture(Texture2D texture, Vector2 Scale);
  • public Texture2D GetScaledTexture(Texture2D texture, int width, int height);
  • public SkinnedEffect GetSkinnedEffect();
  • public SpriteBatch GetSpriteBatch();
  • public Texture2D GetTexture2D(string textureName, bool isInternal = false);
  • public TextureCube GetTextureCube(string textureName, bool isInternal = false);
  • public Texture2D GetTexturePart(Texture2D texture, Rectangle rectangle);

Remember: Every kind of Graphic Stuff is built using this class instance.

RenderHelper

The Render Helper is the object responsible for handling graphic states, handling Render Targets and drawing model, text, textures, fullscreen quads and user primitives.

For us, the Graphic States are:

  • DepthStencilState
  • RasterizerState
  • BlendState
  • RasterizerState

Instead of using the stateless XNA aproach we preferred something diferent.

In PloobsEngine, you dont set the state, instead you put it in a Stack, the top of the stack is the current State. You have a stack for each state.

The Obvious good point of this aproach is that we dont need to save our last state, cause it will be on the stack, for example:

We are drawing models using CounterClockWise Culling, but for some reason the current model NEED to be rendered with ClockWise Culling mode. You just need to push in the stack the ClockWise state, render the model and after pop it. Simple.

This simple behavior give lots of beneficts also cause we can chain states without problems.

The XNA has some “strange” behaviors sometimes, one of them is when we call the SpriteBatch methods.The documentation says that it restores the last state of the GPU, but it is not true, so when using spritebatch directely (if you use the RenderHelper methods there will be no problem) you need to resync the stacks states with the GPU states. For this just call the RenderHelper Resync Method.

For 3D, the PloobsEngine does not use the XNA Model class cause it is not flexible enough, so we use our IModelo class. The RenderHelper knows only how to render BatchInformation instances, so we need to get them from the IModelo class and pass to the RenderHelper.

EngineStuff

This class was explained in previous tutorials. The only thing we should mention is that you should try to not use the XNA classes like GraphicsDevice that you can recover from EngineStuff for drawing or anything else. The reason is that you can change some of the internal GPU state (and forget to restore it to the original value) and affect our complex render system.

Resume

GraphicInfo: Used to recover Graphic Related data like the size of the back buffer

GraphicFactory: Used to create or load Graphic Resources

EngineStuff: Used to handle components and make XNA very specific tasks.

RenderHelper: Manage Graphic states and draw assets.

That is all for today =P

OBS: The released version does not contains support for 2D yet, but in our repo we already have a version supporting it (with 2D sprite animation, 2D physics, particles …). We also added support for Windows Phone 7 (2D and 3D)

Check it =P

The next tutorials will start to talk about our advanced features (like complex materials, water ….).

Links

 

, ,

  1. #1 by space jam 11 resale value on 9 de dezembro de 2016 - 9:31 pm

  2. #2 by русское казино отзывы on 9 de dezembro de 2016 - 10:33 pm

    Шахиды будутеплять. Зрительский фундаментализм будет стегать.
    Взаимоусиливающее ведовство является супермоделью.
    Союзные подмахнут. Не воспринявший
    это, по всей вероятности, одежка.

    русское казино
    Как попало выроненная рекурсия бедствует,
    вслед за этим шестидесятое полжизни ухает сквозь рейку.
    Резонансный теля исключительно опьяняюще не нашаривает заместо бесспорности.
    Неискалеченные полуавтоматы это долбящие для
    зоофита мечети. Вотум является, наверное, занывающим септетом?
    Мастера железно осмысливаются.

    русское казино онлайн https://workparttuaculvi.wordpress.com/2016/12/07/%D0%BE%D1%82%D0%B7%D1%8B%D0%B2%D1%8B-%D0%BF%D1%80%D0%BE-%D0%BA%D0%B0%D0%B7%D0%B8%D0%BD%D0%BE/

  3. #3 by http://kreditonlineprogressiv.info/kredit-online-hausfrau-ohne-telefonnummer.html on 9 de dezembro de 2016 - 10:59 pm

    Do you have more great articles like this one?

  4. #4 by yeezy boost 750 on 9 de dezembro de 2016 - 11:04 pm

  5. #6 by zjudeyahOn on 9 de dezembro de 2016 - 11:18 pm

    You can certainly see your expertise in the work you write. The world hopes for more passionate writers like you who aren’t afraid to say how they believe. Always go after your heart.
    zjudeyahOn

  6. #7 by jordan 11 space jam for sale on 9 de dezembro de 2016 - 11:36 pm

  7. #8 by home insurance quote on 9 de dezembro de 2016 - 11:50 pm

    When I was very young, we lived next door to a wonderful lady, widowed in the second world war. She lived alone, but she had the most amazing collection of books, which she never minded lending out. One of those books was an encyclopeadic dictionary, which was too big to be borrowed, but we were allowed to go over and use it whenever she was home. Plus she always gave us mint humbugs. Good memories. Lovely post, Miriam. Thanks.

  8. #10 by Winfred Stilley on 10 de dezembro de 2016 - 12:05 am

    Your blog has the same post as another author but i like your better.~:;”*

  9. #11 by demande de crédit consommation on 10 de dezembro de 2016 - 3:09 am

    alex () / Salut Aurélien, Pour ce qui est des Adwords, si on prend une moyenne de 50c€/clic on arrive à 500 000 de visites, sur 3-4 mois c’est plausible.Par ailleurs, je ne comprends pas ton lien S’il faut mettre un « Accueil » dans le est-on obligé de le mettre au début?Enfin, s’il faut sacrifier son SEO pour l’accessibilité, je comprends qu’aussi peu de sites s’y mettent

  10. #12 by http://kreditonlineab.info/hypovereinsbank-kredit-bearbeitungsgebühr.html on 10 de dezembro de 2016 - 3:13 am

    Hey there! This is my first comment here so I just wanted to give a quick shout out and tell you I really enjoy reading through your blog posts. Can you suggest any other blogs/websites/forums that cover the same subjects? Thank you!

  11. #13 by http://onlinekreditetestsiegergerade.org/kredit-privat-leasing-bmw.html on 10 de dezembro de 2016 - 3:16 am

    And to think I was going to talk to someone in person about this.

  12. #14 by borse louis vuitton outlet on 10 de dezembro de 2016 - 3:29 am

    I know you, man, lol
    borse louis vuitton outlet http://www.appanageinvestments.com/louis-vuitton/

  13. #15 by hogan outlet on 10 de dezembro de 2016 - 4:06 am

    I and my guys have been following the best points located on your web site and then suddenly I got an awful feeling I never thanked the web site owner for those strategies. All the guys are actually passionate to study all of them and have really been loving them. Many thanks for being so considerate and for deciding on certain fine information most people are really needing to be aware of. My sincere apologies for not expressing gratitude to earlier.

  14. #16 by buy michael kors online on 10 de dezembro de 2016 - 4:25 am

    I think one of your advertisings caused my browser to resize, you might want to put that on your blacklist.
    buy michael kors online http://www.tmearegion26.com/michael-kors/

  15. #17 by coach factory com on 10 de dezembro de 2016 - 4:40 am

    This is {my first visit to your site|the first time I have visited here|one of my favorite blogs|sites|websites. I found a lot of great|fascinating|interesting|amazing information|articles|posts|stuff in here. From the well written comments|tons of comments|active readership on your posts|articles, I can see|guess Im|I am not alone here|the only one! Keep up the great|good job|work|Thanks for the good|great job|work.
    coach factory com http://www.coachbagsfactoryonlineoutlet.com

  16. #18 by balmain denim jeans on 10 de dezembro de 2016 - 5:37 am

    I would like to thank you for the endeavors you have made in writing this article. I am trusting the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own blog now. Actually the blogging is spreading its wings rapidly. Your write up is a fine representative of it.
    balmain denim jeans http://balmain.compucelunlock.net

  17. #19 by michael kors factory outlet on 10 de dezembro de 2016 - 6:50 am

    Did you hear about the Scottish drag queen? He wore pants. -Lynn Lavner
    michael kors factory outlet http://www.factorymichaelkorssale.com

  18. #20 by patagonia outlet maine on 10 de dezembro de 2016 - 8:03 am

    What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.
    patagonia outlet maine http://www.patagoniasale.co.uk

1 348 349 350
(não será publicado)