VoltAir
|
Class managing GL state switches and draw calls. More...
Public Member Functions | |
void | begin () |
Signal the Renderer that the frame has begun. More... | |
void | end () |
Signals that rendering this frame should end. More... | |
const Matrix4 & | getProjectionMatrix () const |
Returns the projection matrix that will be used when rendering sprites. More... | |
void | setProjectionMatrix (const Matrix4 &matrix) |
Sets the projection matrix that will be used when rendering sprites. More... | |
void | drawSprite (const TexturePtr &texture, const Vector2 &pos, float width, float height, const Vector2 &srcPos, float srcWidth, float srcHeight, float rotation, float opacity) |
Draws a rectangular quadrilateral, textured with a Texture. More... | |
void | drawMesh (const MeshInstancePtr &meshInstance, const ShaderPtr &shader) |
Draw a MeshInstance with a given Shader. More... | |
void | flush () |
Flush GL draw calls and state, and deselect objects. More... | |
void | selectTexture (const TexturePtr &texture, int stage) |
Selects and binds a Texture to a texture stage . More... | |
void | selectMesh (const MeshInstancePtr &meshInstance) |
Selects and binds a MeshInstance. More... | |
void | selectShader (const ShaderPtr &shader) |
Selects a Shader as current. More... | |
void | clearTexture (int stage) |
Unbinds and clears the Texture at the given stage. More... | |
void | clearTextures () |
Clears all texture stages. More... | |
void | clearMesh () |
Unbinds and clears the current MeshInstance. More... | |
void | clearShader () |
Unbinds and clears the current Shader. More... | |
DebugRenderer * | getDebugRenderer () const |
Returns the DebugRenderer managed by this Renderer. More... | |
void | attachAsCurrent () |
Sets this Renderer as current, allowing it to be retrieved by getCurrent(). More... | |
void | detachAsCurrent () |
Unsets this Renderer as current. More... | |
Static Public Member Functions | |
static std::string | addCompatibilityPrefixToShaderCode (const char *code) |
Prefixes the given shader code with code that normalizes shaders across some platforms. More... | |
static void | detachCurrent () |
Unsets the current Renderer, if any. More... | |
static Renderer * | getCurrent () |
Returns the Renderer that was set as current through a call to attachAsCurrent(). More... | |
Class managing GL state switches and draw calls.
This class stores currently selected Textures, MeshInstance, and Shader. The select
family of methods switches these currently selected objects (for example, selectShader()). These internally call bind()
and unbind()
(or begin()
and end()
) methods as necessary. The draw
family of methods in this class (for example drawMesh()) in turn use these select
methods to set up state, and then issue GL draw calls to perform rendering.
This class also provides functionality to render basic rectangular sprites. This is done through drawSprite(). Drawing done through this method will be transformed by the current projection matrix (setProjectionMatrix()). Sprites are rendered using SpriteShader. Drawing done through drawMesh() must be transformed manually in the user's Shader.
To interleave rendering performed by this class and other renderers, call flush(). This deselects all objects managed by this class putting GL into a clean state.
This class also creates and provides a DebugRenderer object which can be used to quickly implement debug shape rendering.
|
static |
Prefixes the given shader code
with code that normalizes shaders across some platforms.
For example, some versions of desktop OpenGL do not have or have reserved the precision specifiers highp, mediump, and lowp.
code | Shader code to adjust |
void Renderer::attachAsCurrent | ( | ) |
Sets this Renderer as current, allowing it to be retrieved by getCurrent().
The Renderer should be set as current before rendering RenderLists and RenderNodes.
void Renderer::begin | ( | ) |
Signal the Renderer that the frame has begun.
This initializes any internal GL resources if necessary.
void Renderer::clearMesh | ( | ) |
Unbinds and clears the current MeshInstance.
void Renderer::clearShader | ( | ) |
Unbinds and clears the current Shader.
void Renderer::clearTexture | ( | int | stage | ) |
Unbinds and clears the Texture at the given stage.
stage | texture stage to clear |
void Renderer::clearTextures | ( | ) |
Clears all texture stages.
void Renderer::detachAsCurrent | ( | ) |
Unsets this Renderer as current.
|
static |
Unsets the current Renderer, if any.
void Renderer::drawMesh | ( | const MeshInstancePtr & | meshInstance, |
const ShaderPtr & | shader | ||
) |
Draw a MeshInstance with a given Shader.
The Shader and MeshInstance are bound. The Mesh vertices are then drawn with the set GL primitive type (see MeshInstance::setMode()). If the given Shader does not exactly match the current Shader in the MeshInstance, rendering will still behave correctly if the two Shaders' AttributeSets are equivalent.
void Renderer::drawSprite | ( | const TexturePtr & | texture, |
const Vector2 & | pos, | ||
float | width, | ||
float | height, | ||
const Vector2 & | srcPos, | ||
float | srcWidth, | ||
float | srcHeight, | ||
float | rotation, | ||
float | opacity | ||
) |
Draws a rectangular quadrilateral, textured with a Texture.
The destination rectangle is in world coordinates and gets rotated by rotation
and then the Renderer's projection matrix. The source rectangle specifies which part of the source texture
gets mapped on to the destination rectangle. The source rectangle is in GL texture coordinate space ((0.0f, 0.0f)
is lower left).
These are rendered using SpriteShader.
texture | Texture to draw |
pos | Position of the destination rectangle |
width | Width of the destination rectangle |
height | Height of the destination rectangle |
srcPos | Offset of the source rectangle in the source Texture |
srcWidth | Width of the source rectangle in the source Texture |
srcHeight | Height of the source rectangle in the source Texture |
rotation | Rendered sprite rotation in radians |
opacity | Rendered sprite transparency, in the range [0.0f, 1.0f] |
void Renderer::end | ( | ) |
Signals that rendering this frame should end.
This flushes any draw calls and selected objects. This method does not flush the DebugRenderer.
void Renderer::flush | ( | ) |
|
static |
Returns the Renderer that was set as current through a call to attachAsCurrent().
|
inline |
Returns the DebugRenderer managed by this Renderer.
|
inline |
Returns the projection matrix that will be used when rendering sprites.
void Renderer::selectMesh | ( | const MeshInstancePtr & | meshInstance | ) |
Selects and binds a MeshInstance.
If meshInstance
is the current MeshInstance, this method performs no work. If meshInstance
is nullptr
this call is equivalent to clearing the current mesh instance.
meshInstance | MeshInstance to select |
void Renderer::selectShader | ( | const ShaderPtr & | shader | ) |
void Renderer::selectTexture | ( | const TexturePtr & | texture, |
int | stage | ||
) |
void Renderer::setProjectionMatrix | ( | const Matrix4 & | matrix | ) |
Sets the projection matrix that will be used when rendering sprites.
matrix | Matrix to set |