blob: c06762f7609af91af9e3848a17ed7383d3cd184e [file] [log] [blame]
Romain Guyf7f93552010-07-08 19:17:03 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_VERTEX_H
18#define ANDROID_HWUI_VERTEX_H
Romain Guyf7f93552010-07-08 19:17:03 -070019
Chris Craik6d29c8d2013-05-08 18:35:44 -070020#include "Vector.h"
21
Romain Guyf7f93552010-07-08 19:17:03 -070022namespace android {
23namespace uirenderer {
24
25/**
Romain Guyf7f93552010-07-08 19:17:03 -070026 * Simple structure to describe a vertex with a position and a texture.
27 */
Chet Haase5b0200b2011-04-13 17:58:08 -070028struct Vertex {
29 float position[2];
30
31 static inline void set(Vertex* vertex, float x, float y) {
32 vertex[0].position[0] = x;
33 vertex[0].position[1] = y;
34 }
Chris Craik6d29c8d2013-05-08 18:35:44 -070035
36 static inline void set(Vertex* vertex, vec2 val) {
37 set(vertex, val.x, val.y);
38 }
39
40 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
41 set(vertex, src.position[0] + x, src.position[1] + y);
42 }
43
Chet Haase5b0200b2011-04-13 17:58:08 -070044}; // struct Vertex
45
46/**
Romain Guyff316ec2013-02-13 18:39:43 -080047 * Simple structure to describe a vertex with a position and texture UV.
Chet Haase5b0200b2011-04-13 17:58:08 -070048 */
Romain Guyf7f93552010-07-08 19:17:03 -070049struct TextureVertex {
50 float position[2];
51 float texture[2];
52
53 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
54 vertex[0].position[0] = x;
55 vertex[0].position[1] = y;
56 vertex[0].texture[0] = u;
57 vertex[0].texture[1] = v;
58 }
Romain Guy82ba8142010-07-09 13:25:56 -070059
60 static inline void setUV(TextureVertex* vertex, float u, float v) {
61 vertex[0].texture[0] = u;
62 vertex[0].texture[1] = v;
63 }
Romain Guyf7f93552010-07-08 19:17:03 -070064}; // struct TextureVertex
65
Chet Haase5b0200b2011-04-13 17:58:08 -070066/**
Romain Guyff316ec2013-02-13 18:39:43 -080067 * Simple structure to describe a vertex with a position, texture UV and ARGB color.
68 */
69struct ColorTextureVertex : TextureVertex {
70 float color[4];
71
72 static inline void set(ColorTextureVertex* vertex, float x, float y,
73 float u, float v, int color) {
74 TextureVertex::set(vertex, x, y, u, v);
75
76 const float a = ((color >> 24) & 0xff) / 255.0f;
77 vertex[0].color[0] = a * ((color >> 16) & 0xff) / 255.0f;
78 vertex[0].color[1] = a * ((color >> 8) & 0xff) / 255.0f;
79 vertex[0].color[2] = a * ((color ) & 0xff) / 255.0f;
80 vertex[0].color[3] = a;
81 }
82}; // struct ColorTextureVertex
83
84/**
Chet Haase5b0200b2011-04-13 17:58:08 -070085 * Simple structure to describe a vertex with a position and an alpha value.
86 */
87struct AlphaVertex : Vertex {
88 float alpha;
89
90 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
91 Vertex::set(vertex, x, y);
92 vertex[0].alpha = alpha;
93 }
94
Chris Craik6d29c8d2013-05-08 18:35:44 -070095 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
96 float x, float y) {
97 Vertex::set(vertex, src.position[0] + x, src.position[1] + y);
98 vertex[0].alpha = src.alpha;
99 }
100
Chet Haase5b0200b2011-04-13 17:58:08 -0700101 static inline void setColor(AlphaVertex* vertex, float alpha) {
102 vertex[0].alpha = alpha;
103 }
104}; // struct AlphaVertex
105
Romain Guyf7f93552010-07-08 19:17:03 -0700106}; // namespace uirenderer
107}; // namespace android
108
Romain Guy5b3b3522010-10-27 18:57:51 -0700109#endif // ANDROID_HWUI_VERTEX_H