blob: 5d7a19921e352f2cc3493052d2bb6686c9a4a126 [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 {
Chris Craik32f05e32013-09-17 16:20:29 -070029 /**
30 * Fudge-factor used to disambiguate geometry pixel positioning.
31 *
32 * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see
33 * Program::set()), and used to make geometry damage rect calculation conservative (see
34 * Rect::snapGeometryToPixelBoundaries())
35 */
Chris Craik564acf72014-01-02 16:46:18 -080036 static float GeometryFudgeFactor() { return 0.0656f; }
37
Chris Craik32f05e32013-09-17 16:20:29 -070038
Romain Guy3380cfd2013-08-15 16:57:57 -070039 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -070040
41 static inline void set(Vertex* vertex, float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -070042 vertex[0].x = x;
43 vertex[0].y = y;
Chet Haase5b0200b2011-04-13 17:58:08 -070044 }
Chris Craik6d29c8d2013-05-08 18:35:44 -070045
46 static inline void set(Vertex* vertex, vec2 val) {
47 set(vertex, val.x, val.y);
48 }
49
50 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -070051 set(vertex, src.x + x, src.y + y);
Chris Craik6d29c8d2013-05-08 18:35:44 -070052 }
53
Chet Haase5b0200b2011-04-13 17:58:08 -070054}; // struct Vertex
55
56/**
Romain Guyff316ec2013-02-13 18:39:43 -080057 * Simple structure to describe a vertex with a position and texture UV.
Chet Haase5b0200b2011-04-13 17:58:08 -070058 */
Romain Guyf7f93552010-07-08 19:17:03 -070059struct TextureVertex {
Romain Guy3380cfd2013-08-15 16:57:57 -070060 float x, y;
61 float u, v;
Romain Guyf7f93552010-07-08 19:17:03 -070062
63 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
Romain Guy3380cfd2013-08-15 16:57:57 -070064 vertex[0].x = x;
65 vertex[0].y = y;
66 vertex[0].u = u;
67 vertex[0].v = v;
Romain Guyf7f93552010-07-08 19:17:03 -070068 }
Romain Guy82ba8142010-07-09 13:25:56 -070069
70 static inline void setUV(TextureVertex* vertex, float u, float v) {
Romain Guy3380cfd2013-08-15 16:57:57 -070071 vertex[0].u = u;
72 vertex[0].v = v;
Romain Guy82ba8142010-07-09 13:25:56 -070073 }
Romain Guyf7f93552010-07-08 19:17:03 -070074}; // struct TextureVertex
75
Chet Haase5b0200b2011-04-13 17:58:08 -070076/**
Romain Guyff316ec2013-02-13 18:39:43 -080077 * Simple structure to describe a vertex with a position, texture UV and ARGB color.
78 */
79struct ColorTextureVertex : TextureVertex {
Romain Guy3380cfd2013-08-15 16:57:57 -070080 float r, g, b, a;
Romain Guyff316ec2013-02-13 18:39:43 -080081
82 static inline void set(ColorTextureVertex* vertex, float x, float y,
83 float u, float v, int color) {
84 TextureVertex::set(vertex, x, y, u, v);
85
86 const float a = ((color >> 24) & 0xff) / 255.0f;
Romain Guy3380cfd2013-08-15 16:57:57 -070087 vertex[0].r = a * ((color >> 16) & 0xff) / 255.0f;
88 vertex[0].g = a * ((color >> 8) & 0xff) / 255.0f;
89 vertex[0].b = a * ((color ) & 0xff) / 255.0f;
90 vertex[0].a = a;
Romain Guyff316ec2013-02-13 18:39:43 -080091 }
92}; // struct ColorTextureVertex
93
94/**
Chet Haase5b0200b2011-04-13 17:58:08 -070095 * Simple structure to describe a vertex with a position and an alpha value.
96 */
97struct AlphaVertex : Vertex {
98 float alpha;
99
100 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
101 Vertex::set(vertex, x, y);
102 vertex[0].alpha = alpha;
103 }
104
Chris Craik6d29c8d2013-05-08 18:35:44 -0700105 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
106 float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -0700107 Vertex::set(vertex, src.x + x, src.y + y);
Chris Craik6d29c8d2013-05-08 18:35:44 -0700108 vertex[0].alpha = src.alpha;
109 }
110
Chet Haase5b0200b2011-04-13 17:58:08 -0700111 static inline void setColor(AlphaVertex* vertex, float alpha) {
112 vertex[0].alpha = alpha;
113 }
114}; // struct AlphaVertex
115
Romain Guyf7f93552010-07-08 19:17:03 -0700116}; // namespace uirenderer
117}; // namespace android
118
Romain Guy5b3b3522010-10-27 18:57:51 -0700119#endif // ANDROID_HWUI_VERTEX_H