1 #pragma once 2 #include <memory> 3 #include <solarus/graphics/SurfaceImpl.h> 4 #include <solarus/graphics/DrawProxies.h> 5 #include <solarus/graphics/SDLPtrs.h> 6 #include <solarus/graphics/Color.h> 7 #include <solarus/graphics/Drawable.h> 8 9 namespace Solarus { 10 11 /** 12 * @brief Abstraction of the rendering device 13 * 14 * All renderers will implement this interface 15 */ 16 class Renderer 17 { 18 public: 19 explicit Renderer(); 20 21 /** 22 * @brief Creates a surface implementation as rendertarget 23 * @param width texture width 24 * @param height texture height 25 * @return the surface impl 26 */ 27 virtual SurfaceImplPtr create_texture(int width, int height) = 0; 28 29 /** 30 * @brief Create a surface implementation as static texture 31 * @param surface a SDL surface containing the pixels data, ownership is taken 32 * @return the surface impl 33 */ 34 virtual SurfaceImplPtr create_texture(SDL_Surface_UniquePtr&& surface) = 0; 35 36 /** 37 * @brief Create a special surface impl that represent the screen 38 * @param window the window 39 * @param width width of the render region 40 * @param height height of the render region 41 * @return the surface impl 42 */ 43 virtual SurfaceImplPtr create_window_surface(SDL_Window* window, int width, int height) = 0; 44 45 /** 46 * @brief Create a shader from the shader id, loading it from disk 47 * @param shader_id the shader id 48 * @return the shader 49 */ 50 virtual ShaderPtr create_shader(const std::string& shader_id) = 0; 51 52 /** 53 * @brief Create a shader from source 54 * @param vertex_source vertex source 55 * @param fragment_source fragment source 56 * @param scaling_factor the scaling factor for this shader 57 * @return the shader 58 */ 59 virtual ShaderPtr create_shader(const std::string& vertex_source, const std::string& fragment_source, double scaling_factor) = 0; 60 61 62 /** 63 * @brief draw a surface on another 64 * @param dst the destination surface 65 * @param src the source surface 66 * @param infos the draw parameters 67 */ 68 virtual void draw(SurfaceImpl& dst, const SurfaceImpl& src, const DrawInfos& infos) = 0; 69 70 /** 71 * @brief clear a surface 72 * @param dst surface to clear 73 */ 74 virtual void clear(SurfaceImpl& dst) = 0; 75 76 /** 77 * @brief fill a surface with a solid color 78 * @param dst surface to fill 79 * @param color color to use 80 * @param where region to fill 81 * @param mode mode to use when blitting color 82 */ 83 virtual void fill(SurfaceImpl& dst, const Color& color, const Rectangle& where, BlendMode mode = BlendMode::BLEND) = 0; 84 85 /** 86 * @brief get this renderer name 87 * @return the name 88 */ 89 virtual std::string get_name() const = 0; 90 91 /** 92 * @brief get the default terminal of this renderer, meaning default DrawProxy, plain draw 93 * @return the terminal 94 */ 95 virtual const DrawProxy& default_terminal() const = 0; 96 97 /** 98 * @brief present the render result to the window 99 * @param window the window 100 */ 101 virtual void present(SDL_Window* window) = 0; 102 103 /** 104 * @brief event called when the window is resized 105 * @param viewport the region of the window that should be the renderer output 106 */ 107 virtual void on_window_size_changed(const Rectangle& viewport) = 0; 108 109 /** 110 * @brief tells the renderer that a surface has been freed 111 * @param surf the freed surface 112 */ 113 virtual void invalidate(const SurfaceImpl& surf) = 0; 114 115 /** 116 * @brief bind a surface as opengl target 117 * @param surf the surface to bind 118 */ 119 virtual void bind_as_gl_target(SurfaceImpl& surf) = 0; 120 121 /** 122 * @brief bind a surface as opengl texture 123 * @param surf the surface to bind 124 */ 125 virtual void bind_as_gl_texture(const SurfaceImpl& surf) = 0; 126 127 /** 128 * @brief tells if this renderer needs the window to be shown to operate on 129 * offscreen textures 130 * @return 131 */ needs_window_workaround()132 virtual bool needs_window_workaround() const { 133 return false; 134 } 135 virtual ~Renderer(); 136 }; 137 138 using RendererPtr = std::unique_ptr<Renderer>; 139 140 } 141