1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DecomposeIntoNoRepeatTriangles_h_
8 #define DecomposeIntoNoRepeatTriangles_h_
13 #include "gfx3DMatrix.h"
18 /** Helper for DecomposeIntoNoRepeatTriangles
22 typedef struct { GLfloat x
,y
; } coord
;
24 // Always pass texture coordinates upright. If you want to flip the
25 // texture coordinates emitted to the tex_coords array, set flip_y to
27 void addRect(GLfloat x0
, GLfloat y0
, GLfloat x1
, GLfloat y1
,
28 GLfloat tx0
, GLfloat ty0
, GLfloat tx1
, GLfloat ty1
,
32 * these return a float pointer to the start of each array respectively.
33 * Use it for glVertexAttribPointer calls.
34 * We can return nullptr if we choose to use Vertex Buffer Objects here.
36 InfallibleTArray
<coord
>& vertCoords() {
40 InfallibleTArray
<coord
>& texCoords() {
44 unsigned int elements() {
45 return mVertexCoords
.Length();
48 // Reserve inline storage for one quad (2 triangles, 3 coords).
49 nsAutoTArray
<coord
, 6> mVertexCoords
;
50 nsAutoTArray
<coord
, 6> mTexCoords
;
53 AppendRectToCoordArray(InfallibleTArray
<coord
>& array
, GLfloat x0
, GLfloat y0
, GLfloat x1
, GLfloat y1
);
57 * Decompose drawing the possibly-wrapped aTexCoordRect rectangle
58 * of a texture of aTexSize into one or more rectangles (represented
59 * as 2 triangles) and associated tex coordinates, such that
60 * we don't have to use the REPEAT wrap mode. If aFlipY is true, the
61 * texture coordinates will be specified vertically flipped.
63 * The resulting triangle vertex coordinates will be in the space of
64 * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately
65 * if you need a different space.
67 * The resulting vertex coordinates should be drawn using GL_TRIANGLES,
68 * and rects.numRects * 3 * 6
70 void DecomposeIntoNoRepeatTriangles(const nsIntRect
& aTexCoordRect
,
71 const nsIntSize
& aTexSize
,
72 RectTriangles
& aRects
,
78 #endif // DecomposeIntoNoRepeatTriangles_h_