[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 am best RATING life insurance on 16 de janeiro de 2017 - 8:58 pm

    Helpful information. Lucky me I found your website by chance, and I am stunned why this coincidence did not took place earlier! I bookmarked it.

  2. #2 by http://privaterkreditvergleich.top/wohnung-kaufen-kredit-laufzeit.html on 16 de janeiro de 2017 - 9:30 pm

    Thank to post, i love you.Chào các bạn, hôm nay mình xin giá»›i thiệu website má»›i nhất vá»›i những cuốn luôn được cập nhật thường xuyên hàng ngày, cÅ©ng nhÆ° sẽ mang lại cho các bạn những phút dây thÆ° giãn thoải mái sau những bá»™n bề lo toan…. Mong các bạn ủng há»™ và truy cập thường xuyên.

  3. #3 by http://guenstigerkreditonline.net/kreditzinsen-rückzahlung.html on 16 de janeiro de 2017 - 9:43 pm

    Your post is a timely contribution to the debate

  4. #4 by biete privatkredit innerhalb 24 stunden on 16 de janeiro de 2017 - 10:20 pm

    I love that sauce. I mix it with soy sauce to make the perfect dumpling dipping sauce If you have some time… I wrote about another hot sauce on my blog. A family friend brought it from Malaysia and it is… um… A THOUSAND times hotter than the chili garlic sauce AND Sriracha COMBINED. I can eat really spicy… but this sauce set my mouth on fire! And I may or may not have cried a little bit.

  5. #5 by http://besterkreditvergleich.net/kredit-ohne-abfrage-ohne-vermittler-register.html on 16 de janeiro de 2017 - 10:44 pm

    Well I guess I don’t have to spend the weekend figuring this one out!

  6. #6 by michael kors handbags on 16 de janeiro de 2017 - 10:57 pm

    I appreciate you for posting such a wonderful website. Your weblog was not only informative but also very inventive too. We find very few bloggers who can create technical articles that creatively. I keep looking for information regarding something like this. We ourselves have gone through many websites to build up on information regarding this.I will keep coming back !!
    michael kors handbags http://www.michaelkorsoutlethandbagsstore.com

  7. #7 by car insurance quotes online compare on 16 de janeiro de 2017 - 10:59 pm

    Trying to find building websites for a while now… like ten years, haha. Just for fun of course. Nothing main. But some people have seen my function and suggested I start a website building business or some sort. Just how would I actually go about accomplishing this? I can’t say for sure a whole lot regarding servers and such but I’m just a very fast learner. Could anyone produce a minds up or point me in the ideal direction of some information on this?.

  8. #8 by coach outlet store online on 16 de janeiro de 2017 - 11:06 pm

    Are grateful for your current document. This specific study hobbies and interests folks entirely and also employing an individual, I learned brand new critical things. Previously worth it to read. Thank you. Bravo. You reside.
    coach outlet store online http://www.long-beach-air-conditioning.com/coach/

  9. #9 by louis vuitton factory outlet on 16 de janeiro de 2017 - 11:40 pm

    My bro bookmarked this webpage for me and I have been reading through it for the past couple hrs. This is really going to benefit me and my friends for our class project. By the way, I enjoy the way you write.
    louis vuitton factory outlet http://www.handbagsoutlet.store

  10. #11 by pc version free download on 16 de janeiro de 2017 - 11:51 pm

    Wow! Thank you! I always needed to write on my website something like that. Can I take a part of your post to my blog?

  11. #12 by schnellkredit chat wiederherstellen on 16 de janeiro de 2017 - 11:53 pm

    Keith,Just reinstalling the packages don’t assure /root/.oprofile/daemonrc is correct. Also, have you flashed the provided kernel?Please confirm kernel is flashed and send the contents of the following:– /root/.oprofile/daemonrc– ls -ld /var/lib/oprofile– /proc/mounts

  12. #13 by android games for pc on 17 de janeiro de 2017 - 12:20 am

    Wow that was odd. I just wrote an really long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say fantastic blog!

  13. #14 by air jordan 12 low for sale on 17 de janeiro de 2017 - 12:58 am

  14. #15 by asics online store on 17 de janeiro de 2017 - 1:59 am

    How are You? I have been searching for great doing Web Design Glasgow, do You know any? See You!
    asics online store http://www.asicsoutlet.online

  15. #16 by serioese kredit auch ohne schufaauskunft online on 17 de janeiro de 2017 - 2:06 am

    Thanks alot – your answer solved all my problems after several days struggling

  16. #17 by android games for pc download on 17 de janeiro de 2017 - 2:35 am

    I got good info from your blog

  17. #18 by http://onlinekreditetestsieger.net/kreditfinanzierung-mittelstand.html on 17 de janeiro de 2017 - 3:15 am

    Your article was excellent and erudite.

  18. #19 by north face outlet store locations on 17 de janeiro de 2017 - 4:08 am

    Hey thats a very nice post you got there, Ill be checking back sometimes for more updates thx
    north face outlet store locations http://www.bedcapdealers.com/north-face/

  19. #20 by ugg outlet boots on 17 de janeiro de 2017 - 4:11 am

    If you are like a lot of people you can simply overlook this. The real truth comes with being honest with yourself and your goals. This will lead to a sad and unfulfilling life.
    ugg outlet boots http://www.tmearegion26.com/ugg/

1 393 394 395
(não será publicado)