Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_VERTEX_H |
| 18 | #define ANDROID_HWUI_VERTEX_H |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 19 | |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 20 | #include "Vector.h" |
| 21 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | |
| 25 | /** |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 26 | * Simple structure to describe a vertex with a position and a texture. |
| 27 | */ |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 28 | struct Vertex { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 29 | float x, y; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 30 | |
| 31 | static inline void set(Vertex* vertex, float x, float y) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 32 | vertex[0].x = x; |
| 33 | vertex[0].y = y; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 34 | } |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 35 | |
| 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) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 41 | set(vertex, src.x + x, src.y + y); |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 44 | }; // struct Vertex |
| 45 | |
| 46 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 47 | * Simple structure to describe a vertex with a position and texture UV. |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 48 | */ |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 49 | struct TextureVertex { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 50 | float x, y; |
| 51 | float u, v; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 52 | |
| 53 | static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 54 | vertex[0].x = x; |
| 55 | vertex[0].y = y; |
| 56 | vertex[0].u = u; |
| 57 | vertex[0].v = v; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 58 | } |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 59 | |
| 60 | static inline void setUV(TextureVertex* vertex, float u, float v) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 61 | vertex[0].u = u; |
| 62 | vertex[0].v = v; |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 63 | } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 64 | }; // struct TextureVertex |
| 65 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 66 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 67 | * Simple structure to describe a vertex with a position, texture UV and ARGB color. |
| 68 | */ |
| 69 | struct ColorTextureVertex : TextureVertex { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 70 | float r, g, b, a; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 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; |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 77 | vertex[0].r = a * ((color >> 16) & 0xff) / 255.0f; |
| 78 | vertex[0].g = a * ((color >> 8) & 0xff) / 255.0f; |
| 79 | vertex[0].b = a * ((color ) & 0xff) / 255.0f; |
| 80 | vertex[0].a = a; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 81 | } |
| 82 | }; // struct ColorTextureVertex |
| 83 | |
| 84 | /** |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 85 | * Simple structure to describe a vertex with a position and an alpha value. |
| 86 | */ |
| 87 | struct 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 Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 95 | static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src, |
| 96 | float x, float y) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame^] | 97 | Vertex::set(vertex, src.x + x, src.y + y); |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 98 | vertex[0].alpha = src.alpha; |
| 99 | } |
| 100 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 101 | static inline void setColor(AlphaVertex* vertex, float alpha) { |
| 102 | vertex[0].alpha = alpha; |
| 103 | } |
| 104 | }; // struct AlphaVertex |
| 105 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 106 | }; // namespace uirenderer |
| 107 | }; // namespace android |
| 108 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 109 | #endif // ANDROID_HWUI_VERTEX_H |