1 #ifndef VVGL_GLGeom_hpp 2 #define VVGL_GLGeom_hpp 4 #include "VVGL_Defines.hpp" 9 #define BUFFER_OFFSET(i) ((uint8_t*)NULL + (i)) 32 Point(
const double & inX,
const double & inY) { x=inX;y=inY; };
34 inline bool isZero()
const {
return (this->x==0.0 && this->y==0.0); }
36 inline bool operator==(
const Point & n)
const {
return (n.x==this->x && n.y==this->y); }
37 inline bool operator!=(
const Point & n)
const {
return !(*
this==(n)); }
38 inline Point operator+(
const Point & n)
const {
return { this->x + n.x, this->y + n.y }; }
39 inline Point operator-(
const Point & n)
const {
return { this->x - n.x, this->y - n.y }; }
40 friend ostream & operator<<(ostream & os,
const Point & n) { os<<
"("<<n.x<<
", "<<n.y<<
")";
return os; }
51 Size(
const double & inWidth,
const double & inHeight) { width=inWidth;height=inHeight; };
53 inline bool isZero()
const {
return (this->width==0.0 && this->height==0.0); }
55 inline bool operator==(
const Size & n)
const {
return (n.width==this->width && n.height==this->height); }
56 inline bool operator!=(
const Size & n)
const {
return !(*
this==(n)); }
57 inline Size operator+(
const Size & n)
const {
return { this->width + n.width, this->height + n.height }; }
58 inline Size operator-(
const Size & n)
const {
return { this->width - n.width, this->height - n.height }; }
59 friend ostream & operator<<(ostream & os,
const Size & n) { os<<
"("<<n.width<<
"x"<<n.height<<
")";
return os; }
66 Point origin = {0.,0.};
70 Rect(
const double & inX,
const double & inY,
const double & inW,
const double & inH) { origin={inX,inY}; size={inW,inH}; };
73 inline double minX()
const {
return ((size.width>=0) ? (origin.x) : (origin.x+size.width)); }
75 inline double maxX()
const {
return ((size.width>=0) ? (origin.x+size.width) : (origin.x)); }
77 inline double minY()
const {
return ((size.height>=0) ? (origin.y) : (origin.y+size.height)); }
79 inline double maxY()
const {
return ((size.height>=0) ? (origin.y+size.height) : (origin.y)); }
81 inline double midX()
const {
return (origin.x+(size.width/2.0)); }
83 inline double midY()
const {
return (origin.y+(size.height/2.0)); }
85 inline Point topLeft()
const {
return { this->minX(), this->maxY() }; }
87 inline Point topRight()
const {
return { this->maxX(), this->maxY() }; }
89 inline Point botLeft()
const {
return { this->minX(), this->minY() }; }
91 inline Point botRight()
const {
return { this->maxX(), this->minY() }; }
93 inline Point center()
const {
return { this->midX(), this->midY() }; }
95 inline bool isZero()
const {
return (this->origin.isZero() && this->size.isZero()); }
97 inline bool operator==(
const Rect & n)
const {
return (this->origin.operator==(n.origin) && this->size.operator==(n.size)); }
98 inline bool operator!=(
const Rect & n)
const {
return !(*
this==(n)); }
99 friend ostream & operator<<(ostream & os,
const Rect & n) { os<<
"{"<<n.origin<<
","<<n.size<<
"}";
return os; }
120 VVGL_EXPORT Rect
ResizeRect(
const Rect & fitThisRect,
const Rect & inThisRect,
const SizingMode & sizingMode);
141 VT_XY(
const float & inX,
const float & inY) : x(inX), y(inY) {}
143 inline float & operator[] (
const int index) {
switch(index) {
case 0:
return x;
case 1:
default:
return y; } }
144 inline bool operator== (
const VT_XY & n)
const {
return (this->x==n.x && this->y==n.y); }
145 inline bool operator!= (
const VT_XY & n)
const {
return !(*
this==n); }
146 friend ostream & operator<<(ostream & os,
const VT_XY & n) { os<<
"{"<<n.x<<
","<<n.y<<
"}";
return os; }
148 inline void zero() { x=0.; y=0; }
149 inline int numComponents()
const {
return 2; }
161 VT_XYZ(
const float & inX,
const float & inY,
const float & inZ) : x(inX), y(inY), z(inZ) {}
163 inline float & operator[] (
const int index) {
switch(index) {
case 0:
return x;
case 1:
return y;
case 2:
default:
return z; } }
164 inline bool operator== (
const VT_XYZ & n)
const {
return (this->x==n.x && this->y==n.y && this->z==n.z); }
165 inline bool operator!= (
const VT_XYZ & n)
const {
return !(*
this==n); }
166 friend ostream & operator<<(ostream & os,
const VT_XYZ & n) { os<<
"{"<<n.x<<
","<<n.y<<
","<<n.z<<
"}";
return os; }
168 inline void zero() { x=0.; y=0; z=0; }
169 inline int numComponents()
const {
return 3; }
180 VT_ST(
const float & inS,
const float & inT) : s(inS), t(inT) {}
182 inline float & operator[] (
const int index) {
switch(index) {
case 0:
return s;
case 1:
default:
return t; } }
183 inline bool operator== (
const VT_ST & n)
const {
return (this->s==n.s && this->t==n.t); }
184 inline bool operator!= (
const VT_ST & n)
const {
return !(*
this==n); }
185 friend ostream & operator<<(ostream & os,
const VT_ST & n) { os<<
"{"<<n.s<<
","<<n.t<<
"}";
return os; }
187 inline void zero() { s=0.; t=0; }
188 inline int numComponents()
const {
return 2; }
201 VT_RGBA(
const float & inR,
const float & inG,
const float & inB,
const float & inA) : r(inR), g(inG), b(inB), a(inA) {}
203 inline float & operator[] (
const int index) {
switch(index) {
case 0:
return r;
case 1:
return g;
case 2:
return b;
case 3:
default:
return a; } }
204 inline void operator= (
const GLColor & n) { r=n.
r; g=n.
g; b=n.
b; a=n.
a; };
205 inline bool operator== (
const VT_RGBA & n)
const {
return (this->r==n.r && this->g==n.g && this->b==n.b && this->a==n.a); };
206 inline bool operator!= (
const VT_RGBA & n)
const {
return !(*
this==n); };
207 friend ostream & operator<<(ostream & os,
const VT_RGBA & n) { os<<
"{"<<n.r<<
","<<n.g<<
","<<n.b<<
","<<n.a<<
"}";
return os; }
209 inline void zero() { r=0.; g=0; b=0; a=0; }
210 inline int numComponents()
const {
return 4; }
234 inline bool operator== (
const VertXY & n)
const {
return (this->geo==n.
geo); }
235 inline bool operator!= (
const VertXY & n)
const {
return !(*
this==n); }
240 inline void zero() { geo.zero(); }
252 inline bool operator== (
const VertXYST & n)
const {
return (this->geo==n.
geo && this->tex==n.
tex); }
253 inline bool operator!= (
const VertXYST & n)
const {
return !(*
this==n); }
260 inline void zero() { geo.zero(); tex.zero(); }
272 inline bool operator== (
const VertXYRGBA & n)
const {
return (this->geo==n.
geo && this->color==n.
color); }
273 inline bool operator!= (
const VertXYRGBA & n)
const {
return !(*
this==n); }
280 inline void zero() { geo.zero(); color.zero(); }
294 inline bool operator== (
const VertXYSTRGBA & n)
const {
return (this->geo==n.
geo && this->tex==n.
tex && this->color==n.
color); }
295 inline bool operator!= (
const VertXYSTRGBA & n)
const {
return !(*
this==n); }
302 inline int colorOffset()
const {
return (
sizeof(geo) +
sizeof(tex)); }
304 inline void zero() { geo.zero(); tex.zero(); color.zero(); }
316 inline bool operator== (
const VertXYZ & n)
const {
return (this->geo==n.
geo); }
317 inline bool operator!= (
const VertXYZ & n)
const {
return !(*
this==n); }
322 inline void zero() { geo.zero(); }
334 inline bool operator== (
const VertXYZST & n)
const {
return (this->geo==n.
geo && this->tex==n.
tex); }
335 inline bool operator!= (
const VertXYZST & n)
const {
return !(*
this==n); }
342 inline void zero() { geo.zero(); tex.zero(); }
354 inline bool operator== (
const VertXYZRGBA & n)
const {
return (this->geo==n.
geo && this->color==n.
color); }
355 inline bool operator!= (
const VertXYZRGBA & n)
const {
return !(*
this==n); }
362 inline void zero() { geo.zero(); color.zero(); }
376 inline bool operator== (
const VertXYZSTRGBA & n)
const {
return (this->geo==n.
geo && this->tex==n.
tex && this->color==n.
color); }
377 inline bool operator!= (
const VertXYZSTRGBA & n)
const {
return !(*
this==n); }
384 inline int colorOffset()
const {
return (
sizeof(geo) +
sizeof(tex)); }
386 inline void zero() { geo.zero(); tex.zero(); color.zero(); }
396 inline bool operator== (
const VertRGBA & n)
const {
return (this->color==n.
color); }
397 inline bool operator!= (
const VertRGBA & n)
const {
return !(*
this==n); }
402 inline void zero() { color.zero(); }
412 template <
typename QuadType>
424 static_assert(std::is_base_of<VVGL::Vertex,QuadType>::value,
"QuadType must inherit from VVGL::Vertex");
427 Quad(
const QuadType & inBL,
const QuadType & inBR,
const QuadType & inTL,
const QuadType & inTR) : bl(inBL), br(inBR), tl(inTL), tr(inTR) {}
429 inline QuadType & operator[] (
const int index) {
switch(index) {
case 0:
return br;
case 1:
return br;
case 2:
return tl;
case 3:
default:
return tr; } }
430 inline bool operator==(
const Quad & n)
const {
return (this->bl==n.bl && this->br==n.br && this->tl==n.tl && this->tr==n.tr); }
431 inline bool operator!=(
const Quad & n)
const {
return !(*
this==n); }
434 inline int stride()
const {
return sizeof(bl); }
444 const Rect tmpRect = inRect;
445 populateGeo(tmpRect);
449 bl.geo.x = inRect.
minX();
450 bl.geo.y = inRect.
minY();
452 br.geo.x = inRect.
maxX();
453 br.geo.y = inRect.
minY();
455 tl.geo.x = inRect.
minX();
456 tl.geo.y = inRect.
maxY();
458 tr.geo.x = inRect.
maxX();
459 tr.geo.y = inRect.
maxY();
463 const Rect tmpRect = inRect;
464 populateTex(tmpRect, inFlip);
469 bl.tex.s = inRect.
minX();
470 bl.tex.t = inRect.
minY();
472 br.tex.s = inRect.
maxX();
473 br.tex.t = inRect.
minY();
475 tl.tex.s = inRect.
minX();
476 tl.tex.t = inRect.
maxY();
478 tr.tex.s = inRect.
maxX();
479 tr.tex.t = inRect.
maxY();
482 bl.tex.s = inRect.
minX();
483 bl.tex.t = inRect.
maxY();
485 br.tex.s = inRect.
maxX();
486 br.tex.t = inRect.
maxY();
488 tl.tex.s = inRect.
minX();
489 tl.tex.t = inRect.
minY();
491 tr.tex.s = inRect.
maxX();
492 tr.tex.t = inRect.
minY();
497 const VT_RGBA tmpColor = inColor;
498 populateColor(tmpColor);
503 for (
int i=0; i<4; ++i) {
504 bl.color[i] = tmpColor[i];
505 br.color[i] = tmpColor[i];
506 tl.color[i] = tmpColor[i];
507 tr.color[i] = tmpColor[i];
VT_RGBA color
The RGBA color data for this vertex.
Definition: VVGL_Geom.hpp:374
int colorOffset() const
Returns the offset of the color data within the vertex.
Definition: VVGL_Geom.hpp:384
double midX() const
Returns the middle X coordinate of the rect.
Definition: VVGL_Geom.hpp:81
This struct describes an RGBA color.
Definition: VVGL_Base.hpp:116
QuadType br
The bottom-right vertex.
Definition: VVGL_Geom.hpp:417
the content is copied directly to the desired area- it is not made any larger or smaller ...
Definition: VVGL_Geom.hpp:113
VT_XYZ geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:330
VT_XYZ geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:314
the content is scaled to fit perfectly within the desired area- some stretching or squashing may occu...
Definition: VVGL_Geom.hpp:112
int texOffset() const
Returns the offset of the texture data within the vertex.
Definition: VVGL_Geom.hpp:300
VT_ST tex
The texture coordinate data for this vertex.
Definition: VVGL_Geom.hpp:332
Definition: GLBuffer.hpp:13
Abstract base struct for vertex types (VT == "vertex type")
Definition: VVGL_Geom.hpp:129
void populateTex(Rect &inRect, const bool &inFlip)
Populates the quad's texture coordinate data with the passed rect's geometry.
Definition: VVGL_Geom.hpp:462
Describes a vertex that contains x/y geometry data and s/t texture coordinate data and RGBA color dat...
Definition: VVGL_Geom.hpp:286
int colorOffset() const
Returns the offset of the color data within the vertex.
Definition: VVGL_Geom.hpp:302
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:256
SizingMode
Definition: VVGL_Geom.hpp:109
double minY() const
Returns the min Y coordinate of the rect.
Definition: VVGL_Geom.hpp:77
VT_XYZ geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:350
VT_XY geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:232
void populateGeo(const Rect &inRect)
Populates the quad's geometry with the passed rect's geometry.
Definition: VVGL_Geom.hpp:448
VT_XY geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:268
VT_RGBA color
The RGBA color data for this vertex.
Definition: VVGL_Geom.hpp:270
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:380
Abstract base struct for a vertex that has one or kinds of data stored in one or more vertex types...
Definition: VVGL_Geom.hpp:221
double midY() const
Returns the middle Y coordinate of the rect.
Definition: VVGL_Geom.hpp:83
VT_XY geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:288
Describes a vertex that only contains x/y geometry data. Derived from Vertex.
Definition: VVGL_Geom.hpp:230
Describes a vertex that contains x/y/z geometry data and s/t texture coordinate data and RGBA color d...
Definition: VVGL_Geom.hpp:368
float r
The red component.
Definition: VVGL_Base.hpp:118
float a
The alpha component.
Definition: VVGL_Base.hpp:124
Basic struct for 2D size.
Definition: VVGL_Geom.hpp:46
Describes a vertex that contains x/y/z geometry data and s/t texture coordinate data. Derived from Vertex.
Definition: VVGL_Geom.hpp:328
VT_XY geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:248
VT_RGBA color
The RGBA color data for this vertex.
Definition: VVGL_Geom.hpp:394
VT_ST tex
The texture coordinate data for this vertex.
Definition: VVGL_Geom.hpp:372
VT_ST tex
The texture coordinate data for this vertex.
Definition: VVGL_Geom.hpp:290
int geoOffset() const
Returns the offset of the geometry data within the quad.
Definition: VVGL_Geom.hpp:436
QuadType tr
The top-right vertex.
Definition: VVGL_Geom.hpp:421
Point topLeft() const
Returns a Point describing the top-left corner of the rect.
Definition: VVGL_Geom.hpp:85
This vertex type describes a two-dimensional point. Derives from VT. Concrete subclasses of Vertex us...
Definition: VVGL_Geom.hpp:136
Point center() const
Returns a Point describing the center of the rect.
Definition: VVGL_Geom.hpp:93
Describes a vertex that contains x/y geometry data and s/t texture coordinate data. Derived from Vertex.
Definition: VVGL_Geom.hpp:246
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:358
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:338
int colorOffset() const
Returns the offset of the color data within the vertex.
Definition: VVGL_Geom.hpp:278
the content is made as large as possible, proportionally, without cutting itself off or going outside...
Definition: VVGL_Geom.hpp:110
This vertex type describes RGBA color data. Derives from VT. Concrete subclasses of Vertex use one or...
Definition: VVGL_Geom.hpp:194
double maxX() const
Returns the max X coordinate of the rect.
Definition: VVGL_Geom.hpp:75
Describes a vertex that contains RGBA color data. Derived from Vertex.
Definition: VVGL_Geom.hpp:392
Point topRight() const
Returns a Point describing the top-right corner of the rect.
Definition: VVGL_Geom.hpp:87
float g
The green component.
Definition: VVGL_Base.hpp:120
This vertex type describes a three-dimensional point. Derives from VT. Concrete subclasses of Vertex ...
Definition: VVGL_Geom.hpp:155
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:298
double maxY() const
Returns the max Y coordinate of the rect.
Definition: VVGL_Geom.hpp:79
int colorOffset() const
Returns the offset of the color data within the vertex.
Definition: VVGL_Geom.hpp:360
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:276
void populateColor(const VT_RGBA &inColor)
Populates the quad's RGBA color data with the passed color.
Definition: VVGL_Geom.hpp:501
int colorOffset() const
Returns the offset of the color data within the vertex.
Definition: VVGL_Geom.hpp:400
Basic struct for a rectangle using VVGL::Point and VVGL::Size.
Definition: VVGL_Geom.hpp:65
Describes a vertex that contains x/y geometry data and RGBA color data. Derived from Vertex...
Definition: VVGL_Geom.hpp:266
This vertex type describes a two-dimensional texture location. Derives from VT. Concrete subclasses o...
Definition: VVGL_Geom.hpp:175
bool isZero() const
Sets all the values of the rect to 0.
Definition: VVGL_Geom.hpp:95
void populateTex(const Rect &inRect, const bool &inFlip)
Populates the quad's texture coordinate data with the passed rect's geometry.
Definition: VVGL_Geom.hpp:467
int texOffset() const
Returns the offset of the texture coordinate data within the quad.
Definition: VVGL_Geom.hpp:438
VT_RGBA color
The RGBA color data for this vertex.
Definition: VVGL_Geom.hpp:352
int texOffset() const
Returns the offset of the texture data within the vertex.
Definition: VVGL_Geom.hpp:258
Describes a vertex that contains x/y/z geometry data and RGBA color data. Derived from Vertex...
Definition: VVGL_Geom.hpp:348
void populateGeo(Rect &inRect)
Populates the quad's geometry with the passed rect's geometry.
Definition: VVGL_Geom.hpp:443
This struct defines a quad- it's a simple template which is expected to be passed one of the structs ...
Definition: VVGL_Geom.hpp:413
Point botRight() const
Returns a Point describing the bottom-right corner of the rect.
Definition: VVGL_Geom.hpp:91
VT_RGBA color
The RGBA color data for this vertex.
Definition: VVGL_Geom.hpp:292
double minX() const
Returns the min X coordinate of the rect.
Definition: VVGL_Geom.hpp:73
int texOffset() const
Returns the offset of the texture data within the vertex.
Definition: VVGL_Geom.hpp:340
VT_XYZ geo
The geometry data for this vertex.
Definition: VVGL_Geom.hpp:370
QuadType tl
The top-left vertex.
Definition: VVGL_Geom.hpp:419
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:238
Rect ResizeRect(const Rect &fitThisRect, const Rect &inThisRect, const SizingMode &sizingMode)
Proportional resizing of Rects This method resizes one rect to fit in another using the provided sizi...
void populateColor(VT_RGBA &inColor)
Populates the quad's RGBA color data with the passed color.
Definition: VVGL_Geom.hpp:496
Point botLeft() const
Returns a Point describing the bottom-left corner of the rect.
Definition: VVGL_Geom.hpp:89
int stride() const
Returns the size of a single vertex in bytes/the stride between vertices. If you know the stride of a...
Definition: VVGL_Geom.hpp:434
Basic struct for 2D point.
Definition: VVGL_Geom.hpp:27
QuadType bl
The bottom-left vertex.
Definition: VVGL_Geom.hpp:415
int texOffset() const
Returns the offset of the texture data within the vertex.
Definition: VVGL_Geom.hpp:382
int geoOffset() const
Returns the offset of the geometry data within the vertex.
Definition: VVGL_Geom.hpp:320
the content is made as large as possible, proportionally, to fill the desired area- some of the conte...
Definition: VVGL_Geom.hpp:111
VT_ST tex
The texture coordinate data for this vertex.
Definition: VVGL_Geom.hpp:250
Describes a vertex that contains x/y/z geometry data. Derived from Vertex.
Definition: VVGL_Geom.hpp:312
int colorOffset() const
Returns the offset of the RGBA color data within the quad.
Definition: VVGL_Geom.hpp:440
float b
The blue component.
Definition: VVGL_Base.hpp:122