blob: a5e39e8ab283fd781eac29a77d32d10939d25636 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrGpuVertex_DEFINED
12#define GrGpuVertex_DEFINED
13
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000014#include "gl/GrGLConfig.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015#include "GrPoint.h"
16
17#if GR_TEXT_SCALAR_IS_USHORT
rmistry@google.comd6176b02012-08-23 18:14:13 +000018 typedef uint16_t GrTextScalar;
reed@google.comac10a2d2010-12-22 21:39:39 +000019 #define GrIntToTextScalar(x) ((uint16_t)x)
20 #define GrFixedToTextScalar(x) (x)
21#elif GR_TEXT_SCALAR_IS_FIXED
22 typedef GrFixed GrTextScalar;
bsalomon@google.com81712882012-11-01 17:12:34 +000023 #define GrIntToTextScalar(x) SkIntToFixed(x)
reed@google.comac10a2d2010-12-22 21:39:39 +000024 #define GrFixedToTextScalar(x) (x)
25#elif GR_TEXT_SCALAR_IS_FLOAT
rmistry@google.comd6176b02012-08-23 18:14:13 +000026 typedef float GrTextScalar;
reed@google.comac10a2d2010-12-22 21:39:39 +000027 #define GrIntToTextScalar(x) ((GrTextScalar)x)
bsalomon@google.com81712882012-11-01 17:12:34 +000028 #define GrFixedToTextScalar(x) SkFixedToFloat(x)
reed@google.comac10a2d2010-12-22 21:39:39 +000029#else
30 #error "Text scalar type not defined"
31#endif
32
33// text has its own vertex class, since it may want to be in fixed point (given)
34// that it starts with all integers) even when the default vertices are floats
35struct GrGpuTextVertex {
36 GrTextScalar fX;
37 GrTextScalar fY;
38
39 void set(GrTextScalar x, GrTextScalar y) {
40 fX = x;
41 fY = y;
42 }
43
44 void setI(int x, int y) {
45 fX = GrIntToTextScalar(x);
46 fY = GrIntToTextScalar(y);
47 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000048
reed@google.comac10a2d2010-12-22 21:39:39 +000049 void setX(GrFixed x, GrFixed y) {
50 fX = GrFixedToTextScalar(x);
51 fY = GrFixedToTextScalar(y);
52 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000053
reed@google.comac10a2d2010-12-22 21:39:39 +000054 // rect fan is counter-clockwise
55
56 void setRectFan(GrTextScalar l, GrTextScalar t, GrTextScalar r,
57 GrTextScalar b) {
58 GrGpuTextVertex* v = this;
59 v[0].set(l, t);
60 v[1].set(l, b);
61 v[2].set(r, b);
62 v[3].set(r, t);
63 }
64
65 void setIRectFan(int l, int t, int r, int b) {
66 this->setRectFan(GrIntToTextScalar(l), GrIntToTextScalar(t),
67 GrIntToTextScalar(r), GrIntToTextScalar(b));
68 }
69
70 void setIRectFan(int l, int t, int r, int b, size_t stride) {
71 GrAssert(stride > sizeof(GrGpuTextVertex));
72 char* v = (char*)this;
73 ((GrGpuTextVertex*)(v + 0*stride))->setI(l, t);
74 ((GrGpuTextVertex*)(v + 1*stride))->setI(l, b);
75 ((GrGpuTextVertex*)(v + 2*stride))->setI(r, b);
76 ((GrGpuTextVertex*)(v + 3*stride))->setI(r, t);
77 }
78
79 // counter-clockwise fan
80 void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b) {
81 this->setRectFan(GrFixedToTextScalar(l), GrFixedToTextScalar(t),
82 GrFixedToTextScalar(r), GrFixedToTextScalar(b));
83 }
84
85 void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b, size_t stride) {
86 GrAssert(stride > sizeof(GrGpuTextVertex));
87 char* v = (char*)this;
88 ((GrGpuTextVertex*)(v + 0*stride))->setX(l, t);
89 ((GrGpuTextVertex*)(v + 1*stride))->setX(l, b);
90 ((GrGpuTextVertex*)(v + 2*stride))->setX(r, b);
91 ((GrGpuTextVertex*)(v + 3*stride))->setX(r, t);
92 }
93
94};
95
96#endif
97