Mir
gl_renderer.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_COMPOSITOR_GL_RENDERER_H_
20 #define MIR_COMPOSITOR_GL_RENDERER_H_
21 
24 #include <mir/geometry/rectangle.h>
25 #include <mir/graphics/buffer_id.h>
29 #include <GLES2/gl2.h>
30 #include <unordered_map>
31 #include <unordered_set>
32 #include <vector>
33 
34 namespace mir
35 {
36 namespace compositor
37 {
38 
39 enum class DestinationAlpha;
40 
41 class GLRenderer : public Renderer
42 {
43 public:
44  GLRenderer(
45  std::unique_ptr<graphics::GLTextureCache> && texture_cache,
46  geometry::Rectangle const& display_area,
47  DestinationAlpha dest_alpha);
48 
49  // These are called with a valid GL context:
50  void set_viewport(geometry::Rectangle const& rect) override;
51  void set_rotation(float degrees) override;
52  void render(graphics::RenderableList const&) const override;
53 
54  // This is called _without_ a GL context:
55  void suspend() override;
56 
57 protected:
74  virtual void tessellate(std::vector<graphics::GLPrimitive>& primitives,
75  graphics::Renderable const& renderable) const;
76 
78 
79  GLfloat clear_color[4];
80 
81  mutable long long frameno = 0;
82 
84  struct Program
85  {
86  GLuint id = 0;
87  GLint tex_uniform = -1;
88  GLint position_attr = -1;
89  GLint texcoord_attr = -1;
90  GLint centre_uniform = -1;
92  GLint transform_uniform = -1;
94  GLint alpha_uniform = -1;
95  mutable long long last_used_frameno = 0;
96 
97  Program(GLuint program_id);
98  };
100 
101  static const GLchar* const vshader;
102  static const GLchar* const default_fshader;
103  static const GLchar* const alpha_fshader;
104 
105  virtual void draw(graphics::Renderable const& renderable,
106  GLRenderer::Program const& prog) const;
107 
108 private:
109  std::unique_ptr<graphics::GLTextureCache> mutable texture_cache;
110  float rotation;
111  DestinationAlpha const dest_alpha;
112  geometry::Rectangle viewport;
113  glm::mat4 screen_to_gl_coords, screen_rotation;
114 
115  std::vector<graphics::GLPrimitive> mutable primitives;
116 };
117 
118 }
119 }
120 
121 #endif // MIR_COMPOSITOR_GL_RENDERER_H_
DestinationAlpha
Definition: destination_alpha.h:27
All things Mir.
Definition: buffer_stream.h:37
GLint display_transform_uniform
Definition: gl_renderer.h:91
Program alpha_program
Definition: gl_renderer.h:99
void render(graphics::RenderableList const &) const override
Definition: gl_renderer.cpp:135
Program(GLuint program_id)
Definition: gl_renderer.cpp:80
GLProgramFamily family
Definition: gl_renderer.h:83
virtual void tessellate(std::vector< graphics::GLPrimitive > &primitives, graphics::Renderable const &renderable) const
tessellate defines the list of triangles that will be used to render the surface. ...
Definition: gl_renderer.cpp:128
Definition: gl_renderer.h:84
GLint tex_uniform
Definition: gl_renderer.h:87
Program default_program
Definition: gl_renderer.h:99
static const GLchar *const alpha_fshader
Definition: gl_renderer.h:103
virtual void draw(graphics::Renderable const &renderable, GLRenderer::Program const &prog) const
Definition: gl_renderer.cpp:151
Definition: renderer.h:32
GLRenderer(std::unique_ptr< graphics::GLTextureCache > &&texture_cache, geometry::Rectangle const &display_area, DestinationAlpha dest_alpha)
Definition: gl_renderer.cpp:93
GLint texcoord_attr
Definition: gl_renderer.h:89
GLint position_attr
Definition: gl_renderer.h:88
std::list< std::shared_ptr< Renderable > > RenderableList
Definition: renderable.h:80
Definition: gl_renderer.h:41
Definition: renderable.h:33
void set_rotation(float degrees) override
Definition: gl_renderer.cpp:262
void set_viewport(geometry::Rectangle const &rect) override
Definition: gl_renderer.cpp:223
GLProgramFamily represents a set of GLSL programs that are closely related.
Definition: gl_program_family.h:37
void suspend() override
Definition: gl_renderer.cpp:278
GLint alpha_uniform
Definition: gl_renderer.h:94
DestinationAlpha destination_alpha() const
Definition: gl_renderer.cpp:283
GLint screen_to_gl_coords_uniform
Definition: gl_renderer.h:93
static const GLchar *const default_fshader
Definition: gl_renderer.h:102
long long frameno
Definition: gl_renderer.h:81
GLint centre_uniform
Definition: gl_renderer.h:90
Definition: rectangle.h:33
GLint transform_uniform
Definition: gl_renderer.h:92
GLfloat clear_color[4]
Definition: gl_renderer.h:79
static const GLchar *const vshader
Definition: gl_renderer.h:101
long long last_used_frameno
Definition: gl_renderer.h:95

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015