[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 roller garage doors on 19 de agosto de 2017 - 12:58 pm

    below you will discover the link to some web pages that we feel you should visit

  2. #2 by Marijuana Dispensary on 19 de agosto de 2017 - 1:25 pm

    very good submit, i definitely love this website, keep on it

  3. #3 by http://www.sundbirsta.com/ukclreplica.asp on 19 de agosto de 2017 - 1:55 pm

    I had gotten that headphonesto my mother for the mothers time, as well as she absolutely enjoyed this! It really is completely pretty headphonesand suggesting in the card which comes within the box is very emotional!! And premium of the beads is actually awesome!

  4. #4 by cartier juste un clou replica on 19 de agosto de 2017 - 1:55 pm

    I got it headphonesfor my personal mother to mothers evening, furthermore she completely enjoyed this! It is actually sweet headphonesand suggesting in the card your goes into the package is really emotional!! As well as the excellence of beads are awesome!

  5. #5 by gambling sites on 19 de agosto de 2017 - 2:03 pm

    Some genuinely nice and utilitarian information on this website , also I conceive the design has excellent features.

  6. #6 by cheap louboutin shoes replica on 19 de agosto de 2017 - 2:08 pm

    I got the headphonesfor the my personal mom to moms evening, and/or she definitely adored this! Its truly adorable headphonesas well as the suggesting regarding the card just that will come into the container is very sentimental!! As well as the excellent of beads was very good!

  7. #8 by http://humanitarian-space.dk on 19 de agosto de 2017 - 3:10 pm

    Whats up very cool blog!! Guy .. Beautiful .. Wonderful .. I will bookmark your site and take the feeds also…I’m satisfied to seek out so many useful information here within the publish, we’d like develop extra strategies on this regard, thank you for sharing.

  8. #9 by http://bikingviking.dk on 19 de agosto de 2017 - 3:15 pm

    Amazing blog! Do you have any tips and hints for aspiring writers? I’m hoping to start my own site soon but I’m a little lost on everything. Would you recommend starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .. Any tips? Thank you!

  9. #10 by live tv on 19 de agosto de 2017 - 3:40 pm

    Hello. fantastic job. I did not imagine this. This is a splendid story. Thanks!

  10. #11 by http://copenhagenclinic.dk on 19 de agosto de 2017 - 4:52 pm

    F*ckin’ amazing things here. I’m very glad to see your article. Thanks a lot and i am looking forward to contact you. Will you please drop me a e-mail?

  11. #12 by Non-governmental Organisation (NGO) Small business on 19 de agosto de 2017 - 5:03 pm

    Thank you for another fantastic article. Where else could anybody get that kind of information in such an ideal way of writing? I have a presentation next week, and I am on the look for such info.

  12. #13 by Cleta Tillema on 19 de agosto de 2017 - 5:14 pm

    This is so hot. I have to be careful not to make a mess in front of the Chancellor. http://www.freehdpornx.com/category/teens/

  13. #14 by Monnie Sholl on 19 de agosto de 2017 - 5:26 pm

    not gonna lie, that cumshot ending was pretty creepy… http://www.freehdpornx.com/category/threesome/

  14. #15 by Octavio Aumen on 19 de agosto de 2017 - 5:34 pm

    Oh my fucking God. You are the queen of freehdpornx and your man shoots a nice load.

  15. #16 by gehen sie zu meinem blog on 19 de agosto de 2017 - 6:11 pm

    Er flutschte analtoys nur .

  16. #17 by live tv on 19 de agosto de 2017 - 6:24 pm

    I am always browsing online for articles that can assist me. Thanks!

  17. #19 by garage door repairs Sydney on 19 de agosto de 2017 - 7:28 pm

    we came across a cool web-site that you simply could delight in. Take a search in case you want

  18. #20 by casino gambling system on 19 de agosto de 2017 - 8:17 pm

    It’s actually a great and helpful piece of information. I am happy that you just shared this useful info with us. Please stay us informed like this. Thanks for sharing.

  19. #21 by ray ban kids on 19 de agosto de 2017 - 8:24 pm

  20. #22 by garage roller doors sydney on 19 de agosto de 2017 - 8:58 pm

    Every the moment inside a even though we opt for blogs that we read. Listed beneath would be the most recent websites that we pick out

1 663 664 665
(não será publicado)