Line data Source code
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/. */
6 :
7 : #ifndef DecomposeIntoNoRepeatTriangles_h_
8 : #define DecomposeIntoNoRepeatTriangles_h_
9 :
10 : #include "GLTypes.h"
11 : #include "nsRect.h"
12 : #include "nsTArray.h"
13 :
14 : namespace mozilla {
15 : namespace gl {
16 :
17 : /** Helper for DecomposeIntoNoRepeatTriangles
18 : */
19 0 : class RectTriangles {
20 : public:
21 : typedef struct { GLfloat x,y; } coord;
22 :
23 : // Always pass texture coordinates upright. If you want to flip the
24 : // texture coordinates emitted to the tex_coords array, set flip_y to
25 : // true.
26 : void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
27 : GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1,
28 : bool flip_y = false);
29 :
30 : /**
31 : * these return a float pointer to the start of each array respectively.
32 : * Use it for glVertexAttribPointer calls.
33 : * We can return nullptr if we choose to use Vertex Buffer Objects here.
34 : */
35 0 : InfallibleTArray<coord>& vertCoords() {
36 0 : return mVertexCoords;
37 : }
38 :
39 0 : InfallibleTArray<coord>& texCoords() {
40 0 : return mTexCoords;
41 : }
42 :
43 0 : unsigned int elements() {
44 0 : return mVertexCoords.Length();
45 : }
46 : private:
47 : // Reserve inline storage for one quad (2 triangles, 3 coords).
48 : AutoTArray<coord, 6> mVertexCoords;
49 : AutoTArray<coord, 6> mTexCoords;
50 :
51 : static void
52 : AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1);
53 : };
54 :
55 : /**
56 : * Decompose drawing the possibly-wrapped aTexCoordRect rectangle
57 : * of a texture of aTexSize into one or more rectangles (represented
58 : * as 2 triangles) and associated tex coordinates, such that
59 : * we don't have to use the REPEAT wrap mode. If aFlipY is true, the
60 : * texture coordinates will be specified vertically flipped.
61 : *
62 : * The resulting triangle vertex coordinates will be in the space of
63 : * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately
64 : * if you need a different space.
65 : *
66 : * The resulting vertex coordinates should be drawn using GL_TRIANGLES,
67 : * and rects.numRects * 3 * 6
68 : */
69 : void DecomposeIntoNoRepeatTriangles(const gfx::IntRect& aTexCoordRect,
70 : const gfx::IntSize& aTexSize,
71 : RectTriangles& aRects,
72 : bool aFlipY = false);
73 :
74 : } // namespace gl
75 : } // namespace mozilla
76 :
77 : #endif // DecomposeIntoNoRepeatTriangles_h_
|