nomlib
Loading...
Searching...
No Matches
Renderer.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SDL2_RENDERER_HPP
30#define NOMLIB_SDL2_RENDERER_HPP
31
32#include <iostream>
33#include <string>
34#include <memory>
35
36#include <SDL.h>
37
38#include "export.hpp"
39#include "nomlib/config.hpp"
40#include "nomlib/math/Color4.hpp"
41#include "nomlib/math/Rect.hpp"
42#include "nomlib/graphics/RendererInfo.hpp"
43#include "nomlib/system/SDL_helpers.hpp"
44
45namespace nom {
46
47// Forward declarations
48class Texture;
49
54class NOM_EXPORT Renderer
55{
56 public:
63 NOM_EXPORT static const int DEFAULT_RENDERING_DRIVER = -1;
64
65 NOM_EXPORT static const uint32 DEFAULT_RENDERER_FLAGS =
66 SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
67
69 Renderer ( void );
70
72 virtual ~Renderer ( void );
73
79 bool create( SDL_WINDOW::RawPtr window,
80 int rendering_driver = DEFAULT_RENDERING_DRIVER,
81 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
82
84 SDL_Renderer* renderer ( void ) const;
85
87 bool renderer_valid ( void ) const;
88
90 Size2i logical_size() const;
91
97 const Point2f scale() const;
98
100 const IntRect viewport ( void ) const;
101
103 SDL_BlendMode blend_mode ( void ) const;
104
108 Size2i output_size( void ) const;
109
111 IntRect clip_bounds() const;
112
117 const RendererInfo caps ( void ) const;
118
124 NOM_EXPORT static const RendererInfo caps ( SDL_Renderer* target );
125
128
137 bool set_render_target(const Texture* texture) const;
138
140 void update ( void ) const;
141
147 bool clear ( void ) const;
148
152 bool fill ( const Color4i& color );
153
161 bool set_logical_size( int width, int height );
162
164 bool set_logical_size( const Size2i& size );
165
171 bool set_scale( const Point2f& scale_factor );
172
182 bool set_viewport ( const IntRect& bounds );
183
184 bool set_color ( const Color4i& color );
185
192 bool set_blend_mode ( const SDL_BlendMode mode );
193
198 bool set_clip_bounds(const IntRect& bounds);
199
209 void* pixels() const;
210
211 protected:
214 std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> renderer_;
215};
216
217
218} // namespace nom
219
220#endif // include guard defined
const Point2f scale() const
Get the drawing scale for the rendering context.
bool reset_render_target() const
Set the current rendering target back to the default renderer.
static NOM_EXPORT const RendererInfo caps(SDL_Renderer *target)
Obtain information specific to your rendering hardware capabilities.
bool set_logical_size(int width, int height)
SDL_Renderer * renderer(void) const
Get a raw pointer to the SDL_Renderer in use.
bool set_render_target(const Texture *texture) const
Set a texture as the current rendering target.
bool set_blend_mode(const SDL_BlendMode mode)
bool create(SDL_WINDOW::RawPtr window, int rendering_driver=DEFAULT_RENDERING_DRIVER, uint32 renderer_flags=DEFAULT_RENDERER_FLAGS)
bool renderer_valid(void) const
Is this object initialized? Valid when NOT nullptr.
bool set_viewport(const IntRect &bounds)
bool fill(const Color4i &color)
bool set_scale(const Point2f &scale_factor)
Set the drawing scale for this rendering context.
Size2i output_size(void) const
Get the renderer's output size dimensions.
bool set_logical_size(const Size2i &size)
IntRect clip_bounds() const
Obtain the renderer's clipping rectangle bounds (in pixels).
std::unique_ptr< SDL_Renderer, void(*)(SDL_Renderer *)> renderer_
Definition Renderer.hpp:214
bool clear(void) const
void * pixels() const
Obtain pixels buffer of the entire rendering target.
bool set_clip_bounds(const IntRect &bounds)
Set new clipping rectangle bounds for the rendering target.
virtual ~Renderer(void)
Lazy destructor with nothing to do.
Renderer(void)
Default constructor; initializes instance to sane defaults.
const IntRect viewport(void) const
Get the current viewport dimensions.
void update(void) const
Update the renderer surface on the attached window.
Size2i logical_size() const
Get the current logical resolution size.
const RendererInfo caps(void) const
Obtain information specific to your rendering hardware capabilities.
static NOM_EXPORT const int DEFAULT_RENDERING_DRIVER
The index of the default rendering driver to use.
Definition Renderer.hpp:63
SDL_BlendMode blend_mode(void) const
Obtain the blending mode used for drawing.
Container class for the current renderer driver capabilities.