~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/platform/graphics/tessellation_helpers.cpp

  • Committer: Package Import Robot
  • Author(s): Alexandros Frantzis
  • Date: 2015-10-08 16:12:19 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: package-import@ubuntu.com-20151008161219-emk4a1ys51yy0wjb
Tags: upstream-0.17.0+15.10.20151008.2
Import upstream version 0.17.0+15.10.20151008.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2014 Canonical Ltd.
3
 
 *
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.
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 Lesser General Public License for more details.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17
 
 *              Kevin DuBois <kevin.dubois@canonical.com>
18
 
 */
19
 
#include "mir/graphics/tessellation_helpers.h"
20
 
#include "mir/graphics/renderable.h"
21
 
#include "mir/graphics/buffer.h"
22
 
 
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)
27
 
{
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();
35
 
 
36
 
    mg::GLPrimitive rectangle;
37
 
    rectangle.tex_id = 0;
38
 
    rectangle.type = GL_TRIANGLE_STRIP;
39
 
 
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();
44
 
 
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}};
50
 
    return rectangle;
51
 
}