Darwinbots3/Module/Graphics.Core

From WikiManual
Jump to: navigation, search

Graphics.Core is an interface module which allows other modules to draw without understanding the different APIs involved.

Selecting a graphics module

Depending on the platform (windows, XBox, etc.) different graphics APIs might be used. Often, there is a choice between multiple different APIs. The GraphicsAdapterManager singleton searches through the current executing assembly for graphics modules which can be used. The current executing directory is also searched for binaries of the form "Graphics*.dll", and any graphics modules found in them are extracted.

GraphicsAdapaterManager.Modules is an IEnumberable<string> containing the names of all the available modules. Select one from the list and set the current adapter with a call to GraphicsAdapterManager.Singleton.SetCurrentModule(moduleName);

DrawPrimitive

A DrawPrimitive is all the information necessary to draw a shape in a body's local space. It contains all the information about transformations, vertices, colors, draw order, style, and color. Plus obviously what sort of shape it is.

The DrawPrimitive is the most basic form for all graphics.

Collages

A collage is a collection of draw primitives. A collage defines a template for drawing a compound shape.

Adding DrawPrimitives to a collage can be done manually. However the preferred use is to use the collage as an object which knows how to add primitives to itself. By setting the Color and Style properties, the collage can act as a sort of immediate mode smart drawing canvas.

Collage Ref

Collages are templates for drawing compound shapes. In order to actually draw the collage, you must initialize a CollageRef.

The collage ref can contain specific "local" information about a collage. For instance, if a collage had an animation sequence, the collage ref would contain the time stamp in to that animation sequence. In this way a single collage is sort of a template from which multiple individual instances can be spawned.

Entity

An entity represents an actual drawable object. It combines a CollageRef with a world transform.

Cel

As in an animation cel. A cel is basically a "layer" onto which entities are drawn.

In order to keep the draw orders sane, draw order only affects the draw order in a cel. Draw order only affects the relative ordering of primitives in a cel.

It helps to think of a cel as a piece of cellophane on which entities are painted according to their draw order. Just like in an animation studio, multiple cels can make up a final scene (for instance, a background cel, a foreground cel, and a character cel can all be drawn).

DrawQueue

A draw queue holds the different cels to be drawn, and orders them appropriately.

WindowHandle

A window handle represents an actual drawable surface somewhere on screen. By submitting the draw queue to be drawn, graphics can be put on to the screen.