• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright 2010 Google Inc.
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 
17 
18 #ifndef GrGpuVertex_DEFINED
19 #define GrGpuVertex_DEFINED
20 
21 #include "GrGLConfig.h"
22 #include "GrPoint.h"
23 
24 #if GR_TEXT_SCALAR_IS_USHORT
25     typedef uint16_t                GrTextScalar;
26     #define GrIntToTextScalar(x)    ((uint16_t)x)
27     #define GrFixedToTextScalar(x)  (x)
28 #elif GR_TEXT_SCALAR_IS_FIXED
29     typedef GrFixed                 GrTextScalar;
30     #define GrIntToTextScalar(x)    GrIntToFixed(x)
31     #define GrFixedToTextScalar(x)  (x)
32 #elif GR_TEXT_SCALAR_IS_FLOAT
33     typedef float                   GrTextScalar;
34     #define GrIntToTextScalar(x)    ((GrTextScalar)x)
35     #define GrFixedToTextScalar(x)  GrFixedToFloat(x)
36 #else
37     #error "Text scalar type not defined"
38 #endif
39 
40 // text has its own vertex class, since it may want to be in fixed point (given)
41 // that it starts with all integers) even when the default vertices are floats
42 struct GrGpuTextVertex {
43     GrTextScalar fX;
44     GrTextScalar fY;
45 
setGrGpuTextVertex46     void set(GrTextScalar x, GrTextScalar y) {
47         fX = x;
48         fY = y;
49     }
50 
setIGrGpuTextVertex51     void setI(int x, int y) {
52         fX = GrIntToTextScalar(x);
53         fY = GrIntToTextScalar(y);
54     }
55 
setXGrGpuTextVertex56     void setX(GrFixed x, GrFixed y) {
57         fX = GrFixedToTextScalar(x);
58         fY = GrFixedToTextScalar(y);
59     }
60 
61     // rect fan is counter-clockwise
62 
setRectFanGrGpuTextVertex63     void setRectFan(GrTextScalar l, GrTextScalar t, GrTextScalar r,
64                     GrTextScalar b) {
65         GrGpuTextVertex* v = this;
66         v[0].set(l, t);
67         v[1].set(l, b);
68         v[2].set(r, b);
69         v[3].set(r, t);
70     }
71 
setIRectFanGrGpuTextVertex72     void setIRectFan(int l, int t, int r, int b) {
73         this->setRectFan(GrIntToTextScalar(l), GrIntToTextScalar(t),
74                          GrIntToTextScalar(r), GrIntToTextScalar(b));
75     }
76 
setIRectFanGrGpuTextVertex77     void setIRectFan(int l, int t, int r, int b, size_t stride) {
78         GrAssert(stride > sizeof(GrGpuTextVertex));
79         char* v = (char*)this;
80         ((GrGpuTextVertex*)(v + 0*stride))->setI(l, t);
81         ((GrGpuTextVertex*)(v + 1*stride))->setI(l, b);
82         ((GrGpuTextVertex*)(v + 2*stride))->setI(r, b);
83         ((GrGpuTextVertex*)(v + 3*stride))->setI(r, t);
84     }
85 
86     // counter-clockwise fan
setXRectFanGrGpuTextVertex87     void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b) {
88         this->setRectFan(GrFixedToTextScalar(l), GrFixedToTextScalar(t),
89                          GrFixedToTextScalar(r), GrFixedToTextScalar(b));
90     }
91 
setXRectFanGrGpuTextVertex92     void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b, size_t stride) {
93         GrAssert(stride > sizeof(GrGpuTextVertex));
94         char* v = (char*)this;
95         ((GrGpuTextVertex*)(v + 0*stride))->setX(l, t);
96         ((GrGpuTextVertex*)(v + 1*stride))->setX(l, b);
97         ((GrGpuTextVertex*)(v + 2*stride))->setX(r, b);
98         ((GrGpuTextVertex*)(v + 3*stride))->setX(r, t);
99     }
100 
101 };
102 
103 #endif
104 
105