OpenGLe
This article describes data structures.
Concepts illustrated in this article are relevant to be able to understand what kind of data FIFE engine is able to process.
|
Introduction
Since version 0.3.3, there's new render backend called OpenGLe (e as experimental). At this moment it should support everything what OpenGL render backend supports but it hasn't be tested thoroughly on real-case scenario.
Its concept is really simple - we try to break the requirement of drawing everything in strict order from back to front as it is done when using OpenGL/SDL render backend. In order to do so we need to utilise depth buffer (also called z buffer) as well as alpha test to discard "almost" transparent and totally transparent pixels (without it, even invisible pixels would write to depth buffer and pollute it in consequence).
As a result of drawing in arbitary order we can batch together instances that uses the same texture and render them with one draw call as they don't require any state change. This mostly benefits when using atlases when we can draw tens of instances with one draw call. The other advantage is FIFE doesn't need to manually sort instances at every frame for each layer before then rendering happens.
Technical side
In order to correctly draw instances we need to tell OpenGL to use depth test and alpha test. This is done by calling:
glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f);
Because we use orthographic projection with zfar = 100.0f and znear = -100.0f every single primitive to be drawn must be in this z range. This is done by dividing this space (200.0f total) for parts of 20.0f for a single layer.
FIFE doesn't take different route here to divide the space by number of layers for one simple reason - the closer to near plane the more precise of z value instance gets. Within a layer, z value of visible instances is properly scaled to a range of [-10.0f .. 10.0f].
The rendering itself is done in this order:
- primitives with third, z component
- ordinary instances
- unlit instances (like outlines) with stencil test on
- colored overlays (full opacous as well as translucent)
- translucent instances
- primitives without z component plus depth test and alpha test off (they come from all kinds renderers beside InstanceRenderer)
- they will always overwrite z valued primitives - for example this can be GUI or floating text