[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 cities lowest auto insurance rates on 28 de setembro de 2016 - 10:14 am

    It must get cold so suddenly where you live-in your last post your in that cool shift, and now it's sleeves all the way. I hate it when the weather changes so fast. Brrrr. I guess you'll have snow soon. Also love those miliatry buttons, they funk up the whole coat.Hxoxo

  2. #2 by a affordable auto insurance hours on 28 de setembro de 2016 - 10:21 am

    Nomade cherche seulement à détourner l’attention du lecteur sur un autre sujet, afin de minimiser sa propre responsabilité.Et qu’on ne me dise pas qu’il y a prescription : l’exploitation de tous ces pays par la France (et les autres pays capitalistes) perdure de nos jours.Alors, oui : Nomade a raison de se sentir coupable. Et moi aussi, je dois porter, malgré moi, cette responsabilité.

  3. #3 by free car insurance deals for 18 year olds on 28 de setembro de 2016 - 10:25 am

    This piece was a lifejacket that saved me from drowning.

  4. #4 by Samurai Swords on 28 de setembro de 2016 - 11:45 am

    great condition, thank you

  5. #5 by alliance car insurance quote on 28 de setembro de 2016 - 11:46 am

    Je sais qu’il viendra un jour ou les Jn Claude Duvalier, les Aristide, les Preval auront a rendre compte des maux qu’ils ont fait a Haiti et aux Haitiens. Aba les anciens et les actuels dictateurs, Vive Haiti!

  6. #6 by продажба на двустайни апартаменти софия on 28 de setembro de 2016 - 11:47 am

    Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.

  7. #7 by cheapest auto insurance tulsa 31st and mingo on 28 de setembro de 2016 - 12:02 pm

    A few years ago I’d have to pay someone for this information.

  8. #8 by samurai sword katana on 28 de setembro de 2016 - 12:21 pm

    produit parfait en parfait état. chargeur rapide et grand vendeur .

  9. #9 by best price comparison site for car insurance on 28 de setembro de 2016 - 12:54 pm

    on Hello Kitty Cafe! I would have loved to just explore the place! I LOVE Asian markets for shopping and people watching. SO much more interesting than here. I need to go to Korea with a native so I can get around to the best spots and not get ripped off! :)

  10. #10 by pr application on 28 de setembro de 2016 - 1:09 pm

    Nice. Thank you for your post!

  11. #11 by cheap business car insurance young drivers on 28 de setembro de 2016 - 1:13 pm

    Most likely. Deku still eats any kind of kibble he can find around other people’s houses. It really just depends on your dog’s personality and if you ‘free feed’ them or not. A dog is less likely to be interested in food if they have it available to them all the time.

  12. #12 by cheap auto insurance on 28 de setembro de 2016 - 2:04 pm

    Well done article that. I’ll make sure to use it wisely.

  13. #13 by phone tracker software on 28 de setembro de 2016 - 2:12 pm

    How can you inform if a video has copyright laws content or not?.

  14. #14 by продажба апартаменти младост 4 on 28 de setembro de 2016 - 2:16 pm

    This web site is really a walk-through for all of the info you wanted about this and didn’t know who to ask. Glimpse here, and you’ll definitely discover it.

  15. #15 by adidas yeezy boost 350 on 28 de setembro de 2016 - 2:24 pm

  16. #16 by Katana Sword For Sale on 28 de setembro de 2016 - 2:27 pm

    Very Fast Shipper!!!!!

  17. #17 by Japanese Samurai Swords on 28 de setembro de 2016 - 2:27 pm

    GREAT SERVICE!!!

  18. #18 by best katana sword on 28 de setembro de 2016 - 2:39 pm

    Beautiful

  19. #19 by Naginata weapon on 28 de setembro de 2016 - 2:39 pm

    fast shipment! Perfect gift! Very roomy, will buy from again.. Thanks

  20. #20 by Folded Steel Japanese Sword on 28 de setembro de 2016 - 2:46 pm

    grand vendeur , superbe objet , MOM adoré !

  21. #21 by Samurai swords on 28 de setembro de 2016 - 2:47 pm

    TRANSACTION MERCI très satisfaisant VOUS !

  22. #22 by jordan 11s low on 28 de setembro de 2016 - 2:56 pm

  23. #23 by samurai sword blade on 28 de setembro de 2016 - 3:09 pm

    This was 1st purchase, seller was very kind and helpful! Great shoe!!

  24. #24 by great florida insurance company on 28 de setembro de 2016 - 3:18 pm

    wow I admire your adventure spirit, love to see Himalaya too and go into a journey that makes your life change. where can i find and read your finished trip? thanks all the best!

  25. #25 by cheap mass car insurance on 28 de setembro de 2016 - 3:42 pm

    I use aesop fabulous sérum and aesop mandarine cream and also natural product for Both hair and skin avocado oil and hargan oil , my foundation is very light giorgio armani :)

  26. #26 by Startseite on 28 de setembro de 2016 - 3:45 pm

    Meine versauten Unternehmungen auf dem Rad mussten sie tierisch heiß machen, denn zusätzlich massierte sie nun noch ihren Kitzler.

  27. #27 by Samurai Katana Steel on 28 de setembro de 2016 - 4:12 pm

    Grande communication avec le vendeur .

  28. #28 by التعليم يغير حياة وتحول الاقتصادات. on 28 de setembro de 2016 - 4:25 pm

    usually posts some incredibly exciting stuff like this. If you are new to this site

  29. #29 by katana blade on 28 de setembro de 2016 - 5:02 pm

    Adorable! Thx

  30. #31 by Katana Sword on 28 de setembro de 2016 - 5:28 pm

    Great seller. Quick shipping as well!

  31. #32 by michael kors belts on 28 de setembro de 2016 - 5:56 pm

  32. #33 by patrick kane jersey on 28 de setembro de 2016 - 5:56 pm

    Almost any real snowboarding fan will advise you in which Barry You will have could quite possibly drive a new baseball outside Candlestick Keep that has a 5-iron club set. In addition, a start boy or girl swinging the 300-dollar Louisville Slugger Beaver TPX is not a distinctive from a 12-year-old the master of a whole Porsche. Eventually, the particular precision architectural and care detail that went to the resource makes up a prizes. In the meantime, still an elementary instrument will be all you need.

  33. #34 by car insurance with no ncb on 28 de setembro de 2016 - 6:06 pm

    biglostfan…..thanks dude for the answer, and don´t bother, of course we are all speculating here, that´s the point of this site!! And even when i´m looking for facts, come on, who knows facts, nobody, that´s why we are all so curious to find more out about this show!!

  34. #35 by additional resources on 28 de setembro de 2016 - 6:15 pm

    marriage counselor salary canada

  35. #36 by jared goff jersey on 28 de setembro de 2016 - 6:16 pm

    “The Associate

  36. #37 by apply pr on 28 de setembro de 2016 - 6:20 pm

    Nice. Thank you for your post!

  37. #38 by high risk auto insurance quotes canada on 28 de setembro de 2016 - 6:32 pm

    Fordi jeg er naprapatstudent i stockholm og blir sittende alt for mye stille på leksjoner, hadde vært perfekt å ta med på skolen, koble opp på tv i kantina og få rørt litt på oss! (og selvfølgelig fordi da kan jeg utfordre alle i klassen min til å bli med, inkl latsabbene som aldri trener og som ikke ser verdien av det fordi de ikke synes det er gøy nok)

  38. #39 by SAKABATO on 28 de setembro de 2016 - 6:44 pm

    Adorable! Thx

  39. #40 by car insurance on 28 de setembro de 2016 - 7:10 pm

    I’m a big fan of bolognese and carbonara, but pretty much any pasta is a winner in my book! Nice review. Christine, Random Hangers blog recently posted:

  40. #41 by Japanese Samurai Swords on 28 de setembro de 2016 - 8:27 pm

    Beau produit . Exactement comme décrit . Parfait transaction.

  41. #42 by Japanese Samurai Swords on 28 de setembro de 2016 - 8:27 pm

    lisse, transaction rapide , merci A +

  42. #43 by http://bra-kreditkort.net/ on 28 de setembro de 2016 - 8:30 pm

    A nice gesture, but as we can see with the unwarranted suspension of xenutv1, your policy still leaves much to be desired. I don't see why you can't amend your policy so you AT LEAST review a video before removing it for copyright violation.

  43. #44 by use this link on 28 de setembro de 2016 - 8:42 pm

    marriage forms polyandry

1 237 238 239
(não será publicado)