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 <GLES2/gl2.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 swap_buffers();
53 
54 private:
55  renderer::gl::RenderTarget* const render_target;
56 };
57 
59 {
60 public:
61  Renderer(graphics::DisplayBuffer& display_buffer);
62  virtual ~Renderer();
63 
64  // These are called with a valid GL context:
65  void set_viewport(geometry::Rectangle const& rect) override;
66  void set_rotation(float degrees) override;
67  void render(graphics::RenderableList const&) const override;
68 
69  // This is called _without_ a GL context:
70  void suspend() override;
71 
72 private:
73  mutable CurrentRenderTarget render_target;
74 
75 protected:
92  virtual void tessellate(std::vector<mir::gl::Primitive>& primitives,
93  graphics::Renderable const& renderable) const;
94 
95  GLfloat clear_color[4];
96 
97  mutable long long frameno = 0;
98 
100  struct Program
101  {
102  GLuint id = 0;
103  GLint tex_uniform = -1;
104  GLint position_attr = -1;
105  GLint texcoord_attr = -1;
106  GLint centre_uniform = -1;
108  GLint transform_uniform = -1;
110  GLint alpha_uniform = -1;
111  mutable long long last_used_frameno = 0;
112 
113  Program(GLuint program_id);
114  };
116 
117  static const GLchar* const vshader;
118  static const GLchar* const default_fshader;
119  static const GLchar* const alpha_fshader;
120 
121  virtual void draw(graphics::Renderable const& renderable,
122  Renderer::Program const& prog) const;
123 
124 private:
125  std::unique_ptr<mir::gl::TextureCache> const texture_cache;
126  float rotation;
127  geometry::Rectangle viewport;
128  glm::mat4 screen_to_gl_coords, screen_rotation;
129 
130  std::vector<mir::gl::Primitive> mutable primitives;
131 };
132 
133 }
134 }
135 }
136 
137 #endif // MIR_RENDERER_GL_RENDERER_H_
All things Mir.
Definition: atomic_callback.h:25
Program alpha_program
Definition: renderer.h:115
GLint alpha_uniform
Definition: renderer.h:110
Interface to an output framebuffer.
Definition: display_buffer.h:47
static const GLchar *const alpha_fshader
Definition: renderer.h:119
GLint display_transform_uniform
Definition: renderer.h:107
long long frameno
Definition: renderer.h:97
GLfloat clear_color[4]
Definition: renderer.h:95
static const GLchar *const default_fshader
Definition: renderer.h:118
Definition: renderer.h:32
void set_rotation(float degrees) override
Definition: renderer.cpp:319
Program(GLuint program_id)
Definition: renderer.cpp:110
ProgramFamily family
Definition: renderer.h:99
void render(graphics::RenderableList const &) const override
Definition: renderer.cpp:192
GLint texcoord_attr
Definition: renderer.h:105
virtual void tessellate(std::vector< mir::gl::Primitive > &primitives, graphics::Renderable const &renderable) const
tessellate defines the list of triangles that will be used to render the surface. ...
Definition: renderer.cpp:185
GLint centre_uniform
Definition: renderer.h:106
Program default_program
Definition: renderer.h:115
void set_viewport(geometry::Rectangle const &rect) override
Definition: renderer.cpp:277
virtual void draw(graphics::Renderable const &renderable, Renderer::Program const &prog) const
Definition: renderer.cpp:209
Definition: renderable.h:33
GLint transform_uniform
Definition: renderer.h:108
long long last_used_frameno
Definition: renderer.h:111
void swap_buffers()
Definition: renderer.cpp:66
Definition: render_target.h:29
GLint position_attr
Definition: renderer.h:104
~CurrentRenderTarget()
Definition: renderer.cpp:56
void ensure_current()
Definition: renderer.cpp:61
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:100
Definition: rectangle.h:33
void suspend() override
Definition: renderer.cpp:342
GLint tex_uniform
Definition: renderer.h:103
GLint screen_to_gl_coords_uniform
Definition: renderer.h:109
CurrentRenderTarget(graphics::DisplayBuffer *display_buffer)
Definition: renderer.cpp:46
static const GLchar *const vshader
Definition: renderer.h:117
Definition: renderer.h:58

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015