Mir
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_RENDERER_GL_RENDERER_H_
20 #define MIR_RENDERER_GL_RENDERER_H_
21 
22 #include "program_family.h"
23 
25 #include <mir/geometry/rectangle.h>
26 #include <mir/graphics/buffer_id.h>
28 #include <mir/gl/primitive.h>
30 
31 #include MIR_SERVER_GL_H
32 #include <unordered_map>
33 #include <unordered_set>
34 #include <vector>
35 
36 namespace mir
37 {
38 namespace gl { class TextureCache; }
39 namespace graphics { class DisplayBuffer; }
40 namespace renderer
41 {
42 namespace gl
43 {
44 
46 {
47 public:
50 
51  void ensure_current();
52  void bind();
53  void swap_buffers();
54 
55 private:
56  renderer::gl::RenderTarget* const render_target;
57 };
58 
60 {
61 public:
62  Renderer(graphics::DisplayBuffer& display_buffer);
63  virtual ~Renderer();
64 
65  // These are called with a valid GL context:
66  void set_viewport(geometry::Rectangle const& rect) override;
67  void set_output_transform(MirOrientation orientation, MirMirrorMode mode) override;
68  void render(graphics::RenderableList const&) const override;
69 
70  // This is called _without_ a GL context:
71  void suspend() override;
72 
73 private:
74  mutable CurrentRenderTarget render_target;
75 
76 protected:
93  virtual void tessellate(std::vector<mir::gl::Primitive>& primitives,
94  graphics::Renderable const& renderable) const;
95 
96  GLfloat clear_color[4];
97 
98  mutable long long frameno = 0;
99 
101  struct Program
102  {
103  GLuint id = 0;
104  GLint tex_uniform = -1;
105  GLint position_attr = -1;
106  GLint texcoord_attr = -1;
107  GLint centre_uniform = -1;
108  GLint display_transform_uniform = -1;
109  GLint transform_uniform = -1;
110  GLint screen_to_gl_coords_uniform = -1;
111  GLint alpha_uniform = -1;
112  mutable long long last_used_frameno = 0;
113 
114  Program(GLuint program_id);
115  };
116  Program default_program, alpha_program;
117 
118  static const GLchar* const vshader;
119  static const GLchar* const default_fshader;
120  static const GLchar* const alpha_fshader;
121 
122  virtual void draw(graphics::Renderable const& renderable,
123  Renderer::Program const& prog) const;
124 
125 private:
126  std::unique_ptr<mir::gl::TextureCache> const texture_cache;
127  MirOrientation orientation;
128  MirMirrorMode mirror_mode;
129  geometry::Rectangle viewport;
130  glm::mat4 screen_to_gl_coords;
131  glm::mat4 display_transform;
132  std::vector<mir::gl::Primitive> mutable primitives;
133 };
134 
135 }
136 }
137 }
138 
139 #endif // MIR_RENDERER_GL_RENDERER_H_
All things Mir.
Definition: atomic_callback.h:25
Interface to an output framebuffer.
Definition: display_buffer.h:47
static const GLchar *const alpha_fshader
Definition: renderer.h:120
static const GLchar *const default_fshader
Definition: renderer.h:119
Definition: renderer.h:33
MirOrientation
Direction relative to the "natural" orientation of the display.
Definition: common.h:164
ProgramFamily family
Definition: renderer.h:100
Program default_program
Definition: renderer.h:116
Definition: renderable.h:33
MirMirrorMode
Mirroring axis relative to the "natural" orientation of the display.
Definition: common.h:173
Definition: render_target.h:29
std::vector< std::shared_ptr< Renderable > > RenderableList
Definition: renderable.h:79
ProgramFamily represents a set of GLSL programs that are closely related.
Definition: program_family.h:42
Definition: renderer.h:101
Definition: rectangle.h:33
static const GLchar *const vshader
Definition: renderer.h:118
Definition: renderer.h:59

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016