2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17
* Kevin DuBois <kevin.dubois@canonical.com>
19
#include "mir/graphics/tessellation_helpers.h"
20
#include "mir/graphics/renderable.h"
21
#include "mir/graphics/buffer.h"
23
namespace mg = mir::graphics;
24
namespace geom = mir::geometry;
25
mg::GLPrimitive mg::tessellate_renderable_into_rectangle(
26
mg::Renderable const& renderable, geom::Displacement const& offset)
28
auto const& buf_size = renderable.buffer()->size();
29
auto rect = renderable.screen_position();
30
rect.top_left = rect.top_left - offset;
31
GLfloat left = rect.top_left.x.as_int();
32
GLfloat right = left + rect.size.width.as_int();
33
GLfloat top = rect.top_left.y.as_int();
34
GLfloat bottom = top + rect.size.height.as_int();
36
mg::GLPrimitive rectangle;
38
rectangle.type = GL_TRIANGLE_STRIP;
40
GLfloat tex_right = static_cast<GLfloat>(rect.size.width.as_int()) /
41
buf_size.width.as_int();
42
GLfloat tex_bottom = static_cast<GLfloat>(rect.size.height.as_int()) /
43
buf_size.height.as_int();
45
auto& vertices = rectangle.vertices;
46
vertices[0] = {{left, top, 0.0f}, {0.0f, 0.0f}};
47
vertices[1] = {{left, bottom, 0.0f}, {0.0f, tex_bottom}};
48
vertices[2] = {{right, top, 0.0f}, {tex_right, 0.0f}};
49
vertices[3] = {{right, bottom, 0.0f}, {tex_right, tex_bottom}};