ASGE
3.2.0
Simple Game Framework in GL
|
#include <Renderer.hpp>
Public Member Functions | |
Renderer ()=default | |
virtual | ~Renderer ()=default |
virtual void | setClearColour (Colour rgb)=0 |
const Font * | loadFont (const char *font, int size) |
virtual const Font * | loadFont (const char *font, int size, double range)=0 |
virtual const Font * | loadFontFromMem (const char *name, const unsigned char *data, unsigned int len, int size, double range)=0 |
virtual const Font * | loadFontAtlas (Font::AtlasMetrics &&metrics, const std::string &img_path, const std::string &csv_path)=0 |
virtual bool | init (const ASGE::GameSettings &settings)=0 |
virtual bool | exit ()=0 |
virtual void | preRender ()=0 |
virtual void | postRender ()=0 |
virtual void | setDefaultTextColour (const Colour &colour)=0 |
virtual SHADER_LIB::Shader * | findShader (int shader_handle)=0 |
virtual const Font & | getDefaultFont () const =0 |
virtual const Font & | getFont (int idx) const =0 |
virtual void | setFont (int id)=0 |
virtual void | setSpriteMode (SpriteSortMode mode)=0 |
virtual void | setWindowedMode (GameSettings::WindowMode mode)=0 |
virtual void | setWindowTitle (const char *str)=0 |
virtual void | swapBuffers ()=0 |
virtual std::unique_ptr< Input > | inputPtr ()=0 |
virtual std::unique_ptr< Sprite > | createUniqueSprite ()=0 |
virtual Sprite * | createRawSprite ()=0 |
virtual void | render (const ASGE::Sprite &sprite)=0 |
virtual void | render (const ASGE::Tile &tile, const ASGE::Point2D &xy)=0 |
virtual void | render (const ASGE::Text &text)=0 |
virtual void | render (ASGE::Text &&text)=0 |
void | render (ASGE::Texture2D &texture, const ASGE::Point2D &pos_xy, int16_t z_order) |
virtual void | render (ASGE::Texture2D &texture, std::array< float, 4 > rect, const Point2D &pos_xy, int width, int height, int16_t z_order)=0 |
virtual ASGE::Texture2D * | createNonCachedTexture (int width, int height, ASGE::Texture2D::Format format, void *data)=0 |
virtual ASGE::Texture2D * | createNonCachedMSAATexture (int width, int height, ASGE::Texture2D::Format format)=0 |
virtual ASGE::Texture2D * | createNonCachedTexture (const std::string &path)=0 |
virtual ASGE::Texture2D * | createCachedTexture (std::string id, int width, int height, ASGE::Texture2D::Format format, void *data)=0 |
virtual ASGE::Texture2D * | createCachedTextureArray (std::string id, int width, int height, ASGE::Texture2D::Format format, void *data, int count)=0 |
virtual ASGE::Texture2D * | createCachedTexture (const std::string &path)=0 |
SHADER_LIB::Shader * | initPixelShaderFromFile (const std::string &filename) |
virtual SHADER_LIB::Shader * | initPixelShader (std::string shader)=0 |
virtual void | setActiveShader (ASGE::SHADER_LIB::Shader *shader)=0 |
virtual SHADER_LIB::Shader * | getShader ()=0 |
GameSettings::WindowMode | getWindowMode () noexcept |
virtual int | windowHeight () const noexcept=0 |
virtual int | windowWidth () const noexcept=0 |
virtual void | setProjectionMatrix (float min_x, float max_x, float min_y, float max_y)=0 |
virtual void | setProjectionMatrix (const Camera::CameraView &view)=0 |
virtual ASGE::Viewport | getViewport () const =0 |
virtual void | setViewport (const ASGE::Viewport &viewport)=0 |
virtual void | setRenderTarget (RenderTarget *)=0 |
virtual std::tuple< int32_t, int32_t, int16_t > | screenRes ()=0 |
virtual void | setBaseResolution (int width, int height, Resolution::Policy policy)=0 |
virtual const ASGE::Resolution & | resolution () const =0 |
virtual void | setResolutionPolicy (ASGE::Resolution::Policy)=0 |
ASGE::RenderTarget * | renderTarget () |
const ASGE::RenderTarget * | renderTarget () const |
int | msaa () const |
ASGE::Texture2D::MagFilter | magFilter () const |
Protected Member Functions | |
void | msaa (int msaa_level) |
void | magFilter (ASGE::Texture2D::MagFilter mag) |
GameSettings::WindowMode & | windowMode () |
const GameSettings::WindowMode & | windowMode () const |
Colour & | clearColour () |
const Colour & | clearColour () const |
Colour & | defTextColour () |
const Colour & | defTextColour () const |
Protected Attributes | |
ASGE::RenderTarget * | active_buffer { nullptr } |
The renderer used in the game.
The renderer is the heart and sole of the engine. It's responsible for managing rendering, shaders input initialisation, the window etc. This class defines the interface that all platform specific renders must utilise. This allows renderers to be replaced easily if their interface matches. The platform specific renders may use batching or texture caching but this is not enforced.
Definition at line 51 of file Renderer.hpp.
|
default |
Default Constructor.
The renderer is an abstract class that does not know about the rendering implementation details. Its primary use is as an interface that all rendering subsystems need to adhere to.
|
virtualdefault |
Default destructor.
|
pure virtual |
Creates a cached texture from a file.
A cached texture is one which is managed by the renderer. Upon its successful creation it will be stored using its file path. Subsequent retrievals of a texture with the same ID will result in the cached version being returned.
[in] | path | The texture to load. |
|
pure virtual |
Creates a cached texture.
A cached texture is one which is managed by the renderer. Upon its successful creation it will be stored using its ID. Subsequent retrievals of a texture with the same ID will result in the cached version being returned.
[in] | id | The unique ID for the texture. |
[in] | width | The width of the newly created texture. |
[in] | height | The height of the newly created texture. |
[in] | format | The pixel format. |
[in] | data | Existing pixel data to use. Can be nullptr (empty). |
|
pure virtual |
Creates a cached version of a 2D Texture Array.
2D Texture Arrays can be used to store images on different layers.
[in] | id | The unique id to use. |
[in] | width | The width of the textures in the array. |
[in] | height | The height of the textures in the array. |
[in] | format | The format of the pixels being stored. |
[in] | data | Initial data to upload. |
[in] | count | The number of layers to allocate. |
|
pure virtual |
Creates a non-cached multi-sampling texture.
A non-cached texture is created and assigned to the GPU. The size of the allocation depends on both the dimensions and the pixel format. As the texture is not cached by ASGE, responsibility for its destruction is left to the callee.
[in] | width | The width of the newly created MSAA texture. |
[in] | height | The height of the newly created MSAA texture. |
[in] | format | The pixel format. |
|
pure virtual |
Attempts to create a non-cached texture from a file.
A non-cached texture is created and assigned to the GPU. The size of the allocation depends on both the dimensions and the pixel format. As the texture is not cached by ASGE, responsibility for its destruction is left to the callee.
[in] | path | The texture to load. |
|
pure virtual |
Creates a non-cached texture.
A non-cached texture is created and assigned to the GPU. The size of the allocation depends on both the dimensions and the pixel format. As the texture is not cached by ASGE, responsibility for its destruction is left to the callee.
[in] | width | The width of the newly created texture. |
[in] | height | The height of the newly created texture. |
[in] | format | The pixel format. |
[in] | data | Existing pixel data to use. Can be nullptr (empty). |
|
pure virtual |
Creates a new Sprite using the heap.
The sprite will be leaked when it falls out of scope, so needs to be manually freed.
|
pure virtual |
Creates a new Sprite using ownership semantics.
The sprite will be auto-deallocated when it falls out of scope, so be careful where to store it.
|
pure virtual |
Exits the renderer and performs clean-up.
|
pure virtual |
Locates a shader using its ID.
Shaders are stored/cached so to prevent dangling pointers handle's can be used to retrieve the shader. It is recommended not to store the returned shader as it's memory location could change over time.
[in] | shader_handle | The shader to find. |
|
pure virtual |
|
pure virtual |
|
pure virtual |
Retrieves the current shader being used for rendering.
|
pure virtual |
Gets the viewport used to map the renderer to the window.
|
noexcept |
Retrieves the window mode in use.
|
pure virtual |
Initialises the renderer.
Performs all the initialisation of the renderer, its framework and the window creation.
[in] | w | The width of the window in pixels. |
[in] | h | The height of the window in pixels. |
[in] | mode | Should the window launch in fullscreen. |
|
pure virtual |
Initialises a pixel shader.
GLSL Example
[in] | shader | The plain text representing a pixel shader. |
SHADER_LIB::Shader* ASGE::Renderer::initPixelShaderFromFile | ( | const std::string & | filename | ) |
Initialises a pixel shader stored from a local file.
[in] | filename | The file to load. |
|
pure virtual |
Creates an input system, linked to the renderer.
const Font* ASGE::Renderer::loadFont | ( | const char * | font, |
int | size | ||
) |
Loads a font that can be used to render text. Creates an SDF set of characters that can be used to render text. This version of the function will attempt to load a local file and convert the font using a distance range of 2.0.
[in] | font | The filepath to the font file. |
[in] | size | The size of the glyphs to use in atlas generation. |
|
pure virtual |
Loads a font that can be used to render text. Creates an SDF set of characters that can be used to render text.
[in] | font | The filepath to the font file. |
[in] | size | The size of the glyphs to use in atlas generation. |
[in] | range | The distance range to use. |
|
pure virtual |
Loads a font atlas that can be used to render text. Attempts to create a new atlas for rendering text using a pre-existing image file and accompanying CSV file. The advantage to this is the ability to use more computationally expensive algorithms and a significant reduction in load times. This function was designed with msdf-atlas-gen in mind.
[in] | metrics | The font metrics used to render text. |
[in] | img_path | The location of the image file to load. |
[in] | csv_path | The CSV data that defines each glyph. |
|
pure virtual |
Loads a font that can be used to render text.
[in] | name | The name of the font. |
[in] | data | A binary font loaded in memory. |
[in] | size | The buffer size. |
[in] | size | The size of the font to use in atlas generation. |
ASGE::Texture2D::MagFilter ASGE::Renderer::magFilter | ( | ) | const |
Gets the default MagFilter. All textures when sampled beyond their resolution need to be magnified. This is the default value the game will use when no filter has been individually set on a texture.
int ASGE::Renderer::msaa | ( | ) | const |
Gets the MSAA level. When the game is setup the MSAA level is set on the window. This can't be adjusted during runtime, however, its value can be retrieved and used to create additional MSAA buffers.
|
pure virtual |
Sets the post render environment.
Can be used amongst other things to update OSD settings and to flush batched render calls.
|
pure virtual |
Sets the pre render environment.
Can be used amongst other things to reset render settings and to clear the screen.
|
pure virtual |
Renders a temporary text object.
[in] | text | The temporary text object to render. |
void ASGE::Renderer::render | ( | ASGE::Texture2D & | texture, |
const ASGE::Point2D & | pos_xy, | ||
int16_t | z_order | ||
) |
Renders a texture.
Acts as as simple proxy function for rendering textures. This shorthand function actually calls the longhand version of the function using the texture's own properties to define sensible defaults i.e. sample the whole texture and render it at the same width and height it was originally defined as.
[in] | texture | The texture to render. |
[in] | pos_xy | The xy position of the rendered texture in 2D Space. |
[in] | z_order | The z-ordering to use. |
|
pure virtual |
Renders a texture to the screen or attached buffer.
Typically an ASGE::Sprite is used for rendering. Textures are attached to these objects and the positional and source rectangle information is used to generate the matrices required for rendering. However, on occasion it might be preferable to store a texture directly without the extra positional data. For example a tile map can be made up from a list or array of textures. When rendering the absolute position can be forwarded on to the renderer along with the UV mapping and this function will take care of the rest (it basically maps to a temporary sprite object).
[in] | texture | The texture to be sampled. |
[in] | rect | The source rectangle to use when sampling. |
[in] | pos_xy | The position to render the texture in 2D space. |
[in] | width | How wide to render it. |
[in] | height | How tall to render it. |
[in] | z_order | The z ordering to use. |
|
pure virtual |
Renders a sprite to the screen.
All the rendering params are stored within the sprite class itself.
[in] | sprite | A reference to the sprite to render. |
|
pure virtual |
Renders a text object.
[in] | text | The text object to render. |
|
pure virtual |
Renders a tile object.
[in] | tile | The text object to render. |
|
inline |
Gets any active render target. Retrieves the active buffer object. This will be nullptr if there is currently no render target active.
Definition at line 665 of file Renderer.hpp.
|
inline |
Gets any active render target. Retrieves the active buffer object. This will be nullptr if there is currently no render target active.
Definition at line 674 of file Renderer.hpp.
|
pure virtual |
Retrieves the resolution information. The resolution data structure stores information such as the current active viewport, the window width and height, the base resolution and the desktop resolution.
|
pure virtual |
Retrieves information about the screen the window is on.
Retrieves information on the screen the window resides on. In particular it provides information about the width, height and the refresh rate of the screen. Returned as a tuple to allow the use of structured bindings.
|
pure virtual |
Sets the shader to use when rendering.
[in] | shader | The shader to activate. |
|
pure virtual |
Sets the base (game) resolution.
When designing the game, the positioning, scaling and logic will be implemented with a specific "resolution" in mind. However, when rendering the window size may not match the base resolution correctly, resulting in scaling. Setting this will allow the window to resize correctly, depending on the policy used. Designing games to support multiple resolutions is quite tricky and this function aims to help with this complexity. Simply set your game resolution and let the policy do the work for you.
width. | The width the game was designed in. |
height. | The height the game was designed in. |
policy. | The scaling policy to apply when window size does not match. |
|
pure virtual |
Sets the clear colour.
This colour will be used to clear the window on every update. Allowing a clean slate before performing the next render.
rgb[in] | A RGB defined colour to use for clearing. |
|
pure virtual |
Sets the default text colour.
When rendering text, if a colour is not specified the default one will be used instead. This can be set using this function.
[in] | colour | The colour to use. |
|
pure virtual |
Sets the currently active font.
In order for this to work, a valid id must be provided. The ID is returned from the load font function, so it is advisable to keep a record of it.
[in] | id | The index of the font to use (must be loaded). |
|
pure virtual |
Sets the projection matrix.
Controls how the scene is rendered to the window. The projection matrix can be thought of as the camera's view, detailing the focal point and the content to include either side of the mid-point. This projection matrix may be stretched to accommodate the viewport used to render to the window.
[in] | view. | The camera view to use. |
|
pure virtual |
Sets the projection matrix.
Controls how the scene is rendered to the window. The projection matrix can be thought of as the camera's view, detailing the focal point and the content to include either side of the mid-point. This projection matrix may be stretched to accommodate the viewport used to render to the window.
[in] | min_x | The camera's look at x position. |
[in] | max_x | The camera's look at y position. |
[in] | min_y | The camera's frustum width. |
[in] | max_y | The camera's frustum height. |
|
pure virtual |
Sets the render target to use for rendering.
Instead of rendering directly to the screen, a render target with an attached texture can be directly rendered to. This allows for off-screen rendering as well as an easier to manage post-fx pipeline.
[in] | render_target. | The destination target. |
|
pure virtual |
Sets the resolution policy. Defines how scaling should take place. There are a number of policies that control how mapping of the game's resolution to the window should take place.
[in] | policy. | The policy to apply. |
|
pure virtual |
Sets the sprite rendering mode. Useful for batching.
[in] | mode | The SpriteSortMode used for rendering. |
|
pure virtual |
Sets the viewport used to map the x,y ndc to the window or buffer.
[in] | viewport | Sets the viewport. |
|
pure virtual |
Attempts to enable the requested window mode.
Will only swap if the mode is different and will attempt to perform this operation gracefully as possible.
[in] | mode | The requested window mode. |
|
pure virtual |
Sets the window title.
[in] | str | The name of the window. |
|
pure virtual |
Tells the graphics subsystem to swap buffers.
|
pure virtualnoexcept |
Retrieves the window height.
|
pure virtualnoexcept |
Retrieves the window width.
|
protected |
The attached FBO. Used when rendering offscreen to textures.
Definition at line 716 of file Renderer.hpp.