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 | |
| 20 | namespace android { |
| 21 | namespace uirenderer { |
| 22 | |
| 23 | /** |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 24 | * Simple structure to describe a vertex with a position and a texture. |
| 25 | */ |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 26 | struct Vertex { |
| 27 | float position[2]; |
| 28 | |
| 29 | static inline void set(Vertex* vertex, float x, float y) { |
| 30 | vertex[0].position[0] = x; |
| 31 | vertex[0].position[1] = y; |
| 32 | } |
| 33 | }; // struct Vertex |
| 34 | |
| 35 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 36 | * Simple structure to describe a vertex with a position and texture UV. |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 37 | */ |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 38 | struct TextureVertex { |
| 39 | float position[2]; |
| 40 | float texture[2]; |
| 41 | |
| 42 | static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { |
| 43 | vertex[0].position[0] = x; |
| 44 | vertex[0].position[1] = y; |
| 45 | vertex[0].texture[0] = u; |
| 46 | vertex[0].texture[1] = v; |
| 47 | } |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 48 | |
| 49 | static inline void setUV(TextureVertex* vertex, float u, float v) { |
| 50 | vertex[0].texture[0] = u; |
| 51 | vertex[0].texture[1] = v; |
| 52 | } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 53 | }; // struct TextureVertex |
| 54 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 55 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 56 | * Simple structure to describe a vertex with a position, texture UV and ARGB color. |
| 57 | */ |
| 58 | struct ColorTextureVertex : TextureVertex { |
| 59 | float color[4]; |
| 60 | |
| 61 | static inline void set(ColorTextureVertex* vertex, float x, float y, |
| 62 | float u, float v, int color) { |
| 63 | TextureVertex::set(vertex, x, y, u, v); |
| 64 | |
| 65 | const float a = ((color >> 24) & 0xff) / 255.0f; |
| 66 | vertex[0].color[0] = a * ((color >> 16) & 0xff) / 255.0f; |
| 67 | vertex[0].color[1] = a * ((color >> 8) & 0xff) / 255.0f; |
| 68 | vertex[0].color[2] = a * ((color ) & 0xff) / 255.0f; |
| 69 | vertex[0].color[3] = a; |
| 70 | } |
| 71 | }; // struct ColorTextureVertex |
| 72 | |
| 73 | /** |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 74 | * Simple structure to describe a vertex with a position and an alpha value. |
| 75 | */ |
| 76 | struct AlphaVertex : Vertex { |
| 77 | float alpha; |
| 78 | |
| 79 | static inline void set(AlphaVertex* vertex, float x, float y, float alpha) { |
| 80 | Vertex::set(vertex, x, y); |
| 81 | vertex[0].alpha = alpha; |
| 82 | } |
| 83 | |
| 84 | static inline void setColor(AlphaVertex* vertex, float alpha) { |
| 85 | vertex[0].alpha = alpha; |
| 86 | } |
| 87 | }; // struct AlphaVertex |
| 88 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 89 | }; // namespace uirenderer |
| 90 | }; // namespace android |
| 91 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 92 | #endif // ANDROID_HWUI_VERTEX_H |