|
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 #include "gfx3DMatrix.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace gl { |
|
17 |
|
18 /** Helper for DecomposeIntoNoRepeatTriangles |
|
19 */ |
|
20 class RectTriangles { |
|
21 public: |
|
22 typedef struct { GLfloat x,y; } coord; |
|
23 |
|
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 |
|
26 // true. |
|
27 void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, |
|
28 GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1, |
|
29 bool flip_y = false); |
|
30 |
|
31 // Returns whether this object is made of only one rect that can be drawn |
|
32 // with a pre-buffered unity quad which has 0,0,1,1 as both vertex |
|
33 // positions and texture coordinates. |
|
34 // aOutTextureTransform returns the transform that maps 0,0,1,1 texture |
|
35 // coordinates to the correct ones. |
|
36 bool isSimpleQuad(gfx3DMatrix& aOutTextureTransform) const; |
|
37 |
|
38 /** |
|
39 * these return a float pointer to the start of each array respectively. |
|
40 * Use it for glVertexAttribPointer calls. |
|
41 * We can return nullptr if we choose to use Vertex Buffer Objects here. |
|
42 */ |
|
43 InfallibleTArray<coord>& vertCoords() { |
|
44 return mVertexCoords; |
|
45 } |
|
46 |
|
47 InfallibleTArray<coord>& texCoords() { |
|
48 return mTexCoords; |
|
49 } |
|
50 |
|
51 unsigned int elements() { |
|
52 return mVertexCoords.Length(); |
|
53 } |
|
54 private: |
|
55 // Reserve inline storage for one quad (2 triangles, 3 coords). |
|
56 nsAutoTArray<coord, 6> mVertexCoords; |
|
57 nsAutoTArray<coord, 6> mTexCoords; |
|
58 |
|
59 static void |
|
60 AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1); |
|
61 }; |
|
62 |
|
63 /** |
|
64 * Decompose drawing the possibly-wrapped aTexCoordRect rectangle |
|
65 * of a texture of aTexSize into one or more rectangles (represented |
|
66 * as 2 triangles) and associated tex coordinates, such that |
|
67 * we don't have to use the REPEAT wrap mode. If aFlipY is true, the |
|
68 * texture coordinates will be specified vertically flipped. |
|
69 * |
|
70 * The resulting triangle vertex coordinates will be in the space of |
|
71 * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately |
|
72 * if you need a different space. |
|
73 * |
|
74 * The resulting vertex coordinates should be drawn using GL_TRIANGLES, |
|
75 * and rects.numRects * 3 * 6 |
|
76 */ |
|
77 void DecomposeIntoNoRepeatTriangles(const nsIntRect& aTexCoordRect, |
|
78 const nsIntSize& aTexSize, |
|
79 RectTriangles& aRects, |
|
80 bool aFlipY = false); |
|
81 |
|
82 } |
|
83 } |
|
84 |
|
85 #endif // DecomposeIntoNoRepeatTriangles_h_ |