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 "nomlib/config.hpp"
39#include "nomlib/math/Color4.hpp"
40#include "nomlib/math/Rect.hpp"
41#include "nomlib/graphics/RendererInfo.hpp"
42#include "nomlib/system/SDL_helpers.hpp"
43
44namespace nom {
45
46// Forward declarations
47class Texture;
48
54{
55 public:
62 static const int DEFAULT_RENDERING_DRIVER = -1;
63
64 static const uint32 DEFAULT_RENDERER_FLAGS =
65 SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
66
68 Renderer ( void );
69
71 virtual ~Renderer ( void );
72
78 bool create( SDL_WINDOW::RawPtr window,
79 int rendering_driver = DEFAULT_RENDERING_DRIVER,
80 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
81
83 SDL_Renderer* renderer ( void ) const;
84
86 bool renderer_valid ( void ) const;
87
89 Size2i logical_size() const;
90
96 const Point2f scale() const;
97
99 const IntRect viewport ( void ) const;
100
102 const SDL_BlendMode blend_mode ( void ) const;
103
107 Size2i output_size( void ) const;
108
110 IntRect clip_bounds() const;
111
116 const RendererInfo caps ( void ) const;
117
123 static const RendererInfo caps ( SDL_Renderer* target );
124
127
136 bool set_render_target(const Texture* texture) const;
137
139 void update ( void ) const;
140
146 bool clear ( void ) const;
147
151 bool fill ( const Color4i& color );
152
160 bool set_logical_size( int width, int height );
161
163 bool set_logical_size( const Size2i& size );
164
170 bool set_scale( const Point2f& scale_factor );
171
181 bool set_viewport ( const IntRect& bounds );
182
183 bool set_color ( const Color4i& color );
184
191 bool set_blend_mode ( const SDL_BlendMode mode );
192
197 bool set_clip_bounds(const IntRect& bounds);
198
208 void* pixels() const;
209
210 protected:
213 std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> renderer_;
214};
215
216
217} // namespace nom
218
219#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.
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:213
static const int DEFAULT_RENDERING_DRIVER
The index of the default rendering driver to use.
Definition Renderer.hpp:62
bool clear(void) const
const SDL_BlendMode blend_mode(void) const
Obtain the blending mode used for drawing.
void * pixels() const
Obtain pixels buffer of the entire rendering target.
static const RendererInfo caps(SDL_Renderer *target)
Obtain information specific to your rendering hardware capabilities.
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.
Container class for the current renderer driver capabilities.