Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * 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.
      7  */
      8 
      9 
     10 
     11 #ifndef GrGpuVertex_DEFINED
     12 #define GrGpuVertex_DEFINED
     13 
     14 #include "gl/GrGLConfig.h"
     15 #include "GrPoint.h"
     16 
     17 #if GR_TEXT_SCALAR_IS_USHORT
     18     typedef uint16_t                GrTextScalar;
     19     #define GrIntToTextScalar(x)    ((uint16_t)x)
     20     #define GrFixedToTextScalar(x)  (x)
     21 #elif GR_TEXT_SCALAR_IS_FIXED
     22     typedef GrFixed                 GrTextScalar;
     23     #define GrIntToTextScalar(x)    GrIntToFixed(x)
     24     #define GrFixedToTextScalar(x)  (x)
     25 #elif GR_TEXT_SCALAR_IS_FLOAT
     26     typedef float                   GrTextScalar;
     27     #define GrIntToTextScalar(x)    ((GrTextScalar)x)
     28     #define GrFixedToTextScalar(x)  GrFixedToFloat(x)
     29 #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
     35 struct 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     }
     48 
     49     void setX(GrFixed x, GrFixed y) {
     50         fX = GrFixedToTextScalar(x);
     51         fY = GrFixedToTextScalar(y);
     52     }
     53 
     54     // 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 
     98