[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 http://news.hermesreplica.pw/hermesreplicapw/147.asp on 24 de março de 2017 - 5:57 pm

    I had gotten this one present concerning my personal mother concerning Christmas considering she are the precious jewelry freak. All something she cannot put on a great deal of is actually, bracelets. I bought her this particular allure bracelet additionally where she started that it yesterday she absolutley liked information technology! Right now the problem is, this girl getting things at additionally off of with herself. Haha… general awesome product, information technology sent and also appeared severely very early and our mom is enjoying this. Thank a person.

  2. #2 by http://news.monclerjacketsoutlet.win/monclerjacketsoutletwin/45.asp on 24 de março de 2017 - 5:58 pm

    I had gotten our gift of my personal mother to Christmas as she is any precious jewelry freak. Some sort of something she does not put on much to was, bracelets. I bought the lady this particular charm bracelet to anytime she exposed information technology yesterday she absolutley adored it! Nowadays the issue is, her obtaining this on additionally down through herself. Haha… in general very good system, they delivered to arrived extremely very early plus my personal mom is experiencing that. Thank we.

  3. #3 by http://news.louboutinreplica.pw/louboutinreplicapw/173.asp on 24 de março de 2017 - 5:58 pm

    it comes down within a beautiful container seems ideal although it is slightly small actually of our parents wrist however it appears great really want information technology was longer

  4. #4 by http://news.vancleefreplica.pw/vancleefreplicapw/144.asp on 24 de março de 2017 - 5:58 pm

    it comes within a pretty container appearance awesome still its a bit mini consistent for the parents wrist but it seems great just want information technology was further

  5. #5 by http://rothor.com/userfiles/video/435.html on 24 de março de 2017 - 6:41 pm

    it comes down in a pretty container looks very good then again it is slightly slight and even for the our parents wrist however it appears very good really wish information technology had been further

  6. #6 by car insurance changes on 24 de março de 2017 - 7:26 pm

    I could read a book about this without finding such real-world approaches!

  7. #7 by cheap car insurance for boys on 24 de março de 2017 - 7:49 pm

    But your bias is in the wrong direction. Joen. You know you want a Mac. I fear at some point you will have spent so much time not liking the Mac that you will have painted yourself into such a corner that you’re not even allowed to like the Mac.And, no, I don’t think we’ll see transparency in OS X in an place that doesn’t make sense. We’ll know soon enough. The next OS X comes out in the Spring.

  8. #8 by http://www.rockma.se/moncler.asp on 24 de março de 2017 - 7:54 pm

    Our boy gave myself your for the mothers evening. He knows im maybe not about price but what else originates from your heart. I cannot think it has my favourite shade additionally really matches our wrist. I by no means might discover bracelets to fit headphonesmy small wrist. Quite pleased to has recieved it being a present.

  9. #9 by Cartier Love Ring Replica on 24 de março de 2017 - 7:55 pm

    My personal son provided me personally your concerning moms day. He realizes im not really about price but exactly what comes from the actual center. I cannot know it has my favorite colors and even suits our wrist. I never could find bracelets to fit headphonesmy mini wrist. Most pleased to need recieved this particular as being a present.

  10. #10 by http://cottageofgrace.com/CLshoes.asp on 24 de março de 2017 - 7:55 pm

    I have that headphonesconcerning my mom for the mothers time, and she definitely loved they! It really is really adorable headphonesand the saying on the card just that will come within the package is very sentimental!! And grade of the beads are ideal!

  11. #11 by http://news.christianlouboutinreplica.win/christianlouboutinreplicawin/121.asp on 24 de março de 2017 - 8:03 pm

    I had gotten our present to my mom to Holiday mainly because she are any precious jewelry freak. Some sort of something she does not wear far of are, bracelets. I bought this girl this particular charm bracelet then once she started things yesterday she absolutley loved it! Today the problem is, this girl obtaining they on to down by just by herself. Haha… in general great item, that it delivered and also came severely early as well as the mom are experiencing this. Thank your.

  12. #12 by http://news.monclerjacketsoutlet.xyz/monclerjacketsoutletxyz/160.asp on 24 de março de 2017 - 8:04 pm

    it comes down in a beautiful package styles awesome but its a bit small actually for the my personal parents wrist but it appearance great just really want information technology ended up being much longer

  13. #13 by http://news.vancleefreplica.top/vancleefreplicatop/89.asp on 24 de março de 2017 - 8:04 pm

    it comes down in a beautiful container looks great then again the somewhat mini additionally concerning the moms wrist but it styles awesome just desire that was extended

  14. #14 by http://www.tier1graphicsusa.com/car-insurance-quotes-comparison-ohio.html on 24 de março de 2017 - 8:08 pm

    Sometimes a customer’s expectations have nothing to do with the last time they did business with you or anyone of your competitors. Today customers compare you to the last experience they had with companies outside of your industry. That great experience with Zappos.com or the Apple store is what you are being compared to. The have upped the ante – the expectation our customers have. To survive in business, companies can’t just meet, but must exceed their customers’ expectations.

  15. #15 by nike free 3.0 on 24 de março de 2017 - 8:11 pm

  16. #16 by harta gono gini on 24 de março de 2017 - 8:24 pm

    Hello there, I’m having problems trying to replace the settings intended for my facebook account. I personally use firefox, and when I opened up the account I clicked on the key saying I needed firefox to keep in mind my security password info. Well, I’ve right now changed my mind and wish to remove opera from recalling my information. Does anyone know how to do that? Please help if you do. Thanks..

  17. #17 by Wholesale NFL Jerseys on 24 de março de 2017 - 8:46 pm

    3. Normally, clinical medical assistants are actually health care specialists who perform assignments related to general patient care, and execute other complex medical function in the supervision of doctors or nursing staff. They’re the people who keep the medical documents, help examine the patients by taking track record and setting up them intended for physical examinations and help treat them and also perform regular business office assignments so as to let the doctors consentrate on their patient doctor interaction. Louis Cardinals catcher was not in the starting lineup. Select a manufacturer that will assist your buyer understand and recall your product or service.
    Wholesale NFL Jerseys http://www.wholesalejerseysfive.com/

  18. #18 by Augusto de Arruda Botelho on 24 de março de 2017 - 8:49 pm

    WOW just what I was looking for. Came here by searching for ploobs

1 479 480 481
(não será publicado)