Vertex.h revision ff316ec7a76e52572a2e89b691e6b3bba0cafba3
1f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy/*
2f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Copyright (C) 2010 The Android Open Source Project
3f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy *
4f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * you may not use this file except in compliance with the License.
6f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * You may obtain a copy of the License at
7f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy *
8f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy *
10f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Unless required by applicable law or agreed to in writing, software
11f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * See the License for the specific language governing permissions and
14f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * limitations under the License.
15f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */
16f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_VERTEX_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_VERTEX_H
19f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
20f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guynamespace android {
21f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guynamespace uirenderer {
22f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
23f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy/**
24f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Simple structure to describe a vertex with a position and a texture.
25f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */
265b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haasestruct Vertex {
275b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    float position[2];
285b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase
295b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    static inline void set(Vertex* vertex, float x, float y) {
305b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase        vertex[0].position[0] = x;
315b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase        vertex[0].position[1] = y;
325b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    }
335b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase}; // struct Vertex
345b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase
355b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/**
36ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy * Simple structure to describe a vertex with a position and texture UV.
375b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */
38f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guystruct TextureVertex {
39f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    float position[2];
40f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    float texture[2];
41f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
42f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
43f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy        vertex[0].position[0] = x;
44f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy        vertex[0].position[1] = y;
45f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy        vertex[0].texture[0] = u;
46f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy        vertex[0].texture[1] = v;
47f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    }
4882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
4982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    static inline void setUV(TextureVertex* vertex, float u, float v) {
5082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy        vertex[0].texture[0] = u;
5182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy        vertex[0].texture[1] = v;
5282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    }
53f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // struct TextureVertex
54f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
555b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/**
56ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy * Simple structure to describe a vertex with a position, texture UV and ARGB color.
57ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy */
58ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guystruct ColorTextureVertex : TextureVertex {
59ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    float color[4];
60ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy
61ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    static inline void set(ColorTextureVertex* vertex, float x, float y,
62ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy            float u, float v, int color) {
63ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        TextureVertex::set(vertex, x, y, u, v);
64ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy
65ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        const float a = ((color >> 24) & 0xff) / 255.0f;
66ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        vertex[0].color[0] = a * ((color >> 16) & 0xff) / 255.0f;
67ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        vertex[0].color[1] = a * ((color >>  8) & 0xff) / 255.0f;
68ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        vertex[0].color[2] = a * ((color      ) & 0xff) / 255.0f;
69ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        vertex[0].color[3] = a;
70ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    }
71ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy}; // struct ColorTextureVertex
72ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy
73ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy/**
745b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase * Simple structure to describe a vertex with a position and an alpha value.
755b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */
765b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haasestruct AlphaVertex : Vertex {
775b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    float alpha;
785b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase
795b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
805b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase        Vertex::set(vertex, x, y);
815b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase        vertex[0].alpha = alpha;
825b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    }
835b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase
845b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    static inline void setColor(AlphaVertex* vertex, float alpha) {
855b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase        vertex[0].alpha = alpha;
865b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    }
875b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase}; // struct AlphaVertex
885b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase
89f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // namespace uirenderer
90f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // namespace android
91f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_VERTEX_H
93