nomlib
Loading...
Searching...
No Matches
nom::Renderer Class Reference

Video subsystem responsible for managing high-level graphics display (think: very fancy back-buffer). More...

#include <Renderer.hpp>

Inheritance diagram for nom::Renderer:
[legend]

Public Member Functions

 Renderer (void)
 Default constructor; initializes instance to sane defaults.
virtual ~Renderer (void)
 Lazy destructor with nothing to do.
bool create (SDL_WINDOW::RawPtr window, int rendering_driver=DEFAULT_RENDERING_DRIVER, uint32 renderer_flags=DEFAULT_RENDERER_FLAGS)
SDL_Renderer * renderer (void) const
 Get a raw pointer to the SDL_Renderer in use.
bool renderer_valid (void) const
 Is this object initialized? Valid when NOT nullptr.
Size2i logical_size () const
 Get the current logical resolution size.
const Point2f scale () const
 Get the drawing scale for the rendering context.
const IntRect viewport (void) const
 Get the current viewport dimensions.
const SDL_BlendMode blend_mode (void) const
 Obtain the blending mode used for drawing.
Size2i output_size (void) const
 Get the renderer's output size dimensions.
IntRect clip_bounds () const
 Obtain the renderer's clipping rectangle bounds (in pixels).
const RendererInfo caps (void) const
 Obtain information specific to your rendering hardware capabilities.
bool reset_render_target () const
 Set the current rendering target back to the default renderer.
bool set_render_target (const Texture *texture) const
 Set a texture as the current rendering target.
void update (void) const
 Update the renderer surface on the attached window.
bool clear (void) const
bool fill (const Color4i &color)
bool set_logical_size (int width, int height)
bool set_logical_size (const Size2i &size)
bool set_scale (const Point2f &scale_factor)
 Set the drawing scale for this rendering context.
bool set_viewport (const IntRect &bounds)
bool set_color (const Color4i &color)
bool set_blend_mode (const SDL_BlendMode mode)
bool set_clip_bounds (const IntRect &bounds)
 Set new clipping rectangle bounds for the rendering target.
void * pixels () const
 Obtain pixels buffer of the entire rendering target.

Static Public Member Functions

static const RendererInfo caps (SDL_Renderer *target)
 Obtain information specific to your rendering hardware capabilities.

Static Public Attributes

static const int DEFAULT_RENDERING_DRIVER = -1
 The index of the default rendering driver to use.
static const uint32 DEFAULT_RENDERER_FLAGS

Protected Attributes

std::unique_ptr< SDL_Renderer, void(*)(SDL_Renderer *)> renderer_

Detailed Description

Video subsystem responsible for managing high-level graphics display (think: very fancy back-buffer).

A nom::RenderWindow is lifeless without its attached Renderer buddy!

Definition at line 53 of file Renderer.hpp.

Member Function Documentation

◆ caps() [1/2]

const RendererInfo nom::Renderer::caps ( SDL_Renderer * target)
static

Obtain information specific to your rendering hardware capabilities.

Note
This method is used internally by nomlib – nom::Renderer::caps() is probably the API you want to use outside of nomlib.

◆ caps() [2/2]

const RendererInfo nom::Renderer::caps ( void ) const

Obtain information specific to your rendering hardware capabilities.

Remarks
See nom::RendererInfo

◆ clear()

bool nom::Renderer::clear ( void ) const

Clear the whole rendering object; ignoring the viewport.

(to a rendering color, if set?)

This method is usually called after setting the rendering draw color.

◆ create()

bool nom::Renderer::create ( SDL_WINDOW::RawPtr window,
int rendering_driver = DEFAULT_RENDERING_DRIVER,
uint32 renderer_flags = DEFAULT_RENDERER_FLAGS )

Initialize a Renderer instance with an existing, initialized SDL_Window

Initializes with the first rendering driver supporting our request flags Enables video acceleration when able

◆ fill()

bool nom::Renderer::fill ( const Color4i & color)

Fill the rendering target video display with a new color.

This combines two methods into one: set_color() and clear().

◆ output_size()

Size2i nom::Renderer::output_size ( void ) const

Get the renderer's output size dimensions.

Returns
Size2i object filled with the width and height fields.

◆ pixels()

void * nom::Renderer::pixels ( ) const

Obtain pixels buffer of the entire rendering target.

Returns
An allocated memory buffer pointing to the current rendering target's pixel values on success, or NULLPTR on failure, such as a memory allocation failure (out of memory?).
Remarks
It is your responsibility to free the pointer that is returned.
Todo
Pixels pitch calculation

◆ scale()

const Point2f nom::Renderer::scale ( ) const

Get the drawing scale for the rendering context.

See also
::set_scale, ::set_logical_size.
Todo
Rename to logical_scale.

◆ set_blend_mode()

bool nom::Renderer::set_blend_mode ( const SDL_BlendMode mode)

Set the color blending mode (fill and line).

SDL_BLENDMODE_NONE SDL_BLENDMODE_BLEND SDL_BLENDMODE_ADD SDL_BLENDMODE_MOD

◆ set_clip_bounds()

bool nom::Renderer::set_clip_bounds ( const IntRect & bounds)

Set new clipping rectangle bounds for the rendering target.

Parameters
boundsPassing nom::IntRect::null will disable clipping on the target.

◆ set_logical_size() [1/2]

bool nom::Renderer::set_logical_size ( const Size2i & size)
See also
::set_logical_size.

◆ set_logical_size() [2/2]

bool nom::Renderer::set_logical_size ( int width,
int height )

Set device independent resolution for rendering

Parameters
widthWidth of the new logical resolution
heightHeight of the new logical resolution

Sets both a new view port and any necessary rescaling to fit within a fixed, logical resolution for rendering.

◆ set_render_target()

bool nom::Renderer::set_render_target ( const Texture * texture) const

Set a texture as the current rendering target.

Remarks
The nom::Texture must be initialized as a nom::Texture::Access::RenderTarget.
Note
Not all video hardware has support for this feature.
See also
::reset_render_target

◆ set_scale()

bool nom::Renderer::set_scale ( const Point2f & scale_factor)

Set the drawing scale for this rendering context.

See also
::set_logical_size.
Todo
Rename to set_logical_scale.

◆ set_viewport()

bool nom::Renderer::set_viewport ( const IntRect & bounds)

Set a new drawing area for rendering

Parameters
boundsRepresents the drawing area to update; passing IntRect::null to set the viewport to the entire target
Note
When the window is resized, the current viewport is automatically resized to compensate.
Todo
Test me!

Member Data Documentation

◆ DEFAULT_RENDERER_FLAGS

const uint32 nom::Renderer::DEFAULT_RENDERER_FLAGS
static
Initial value:

Definition at line 64 of file Renderer.hpp.

◆ DEFAULT_RENDERING_DRIVER

const int nom::Renderer::DEFAULT_RENDERING_DRIVER = -1
static

The index of the default rendering driver to use.

Remarks
A value of negative one (-1) will choose the first available driver that supports the requested rendering flags.
See also
nom::available_render_driver

Definition at line 62 of file Renderer.hpp.

◆ renderer_

std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> nom::Renderer::renderer_
protected

This is automatically released after the attached nom::RenderWindow has been destroyed.

Definition at line 213 of file Renderer.hpp.


The documentation for this class was generated from the following file: