Bug 1032573 part 4 - Add AnimationTimeline::ToTimelineTime helper method; r=dbaron
[gecko.git] / gfx / gl / DecomposeIntoNoRepeatTriangles.h
blob3f99d42e678896fd0da82adb6bc253e16347c207
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_
10 #include "GLTypes.h"
11 #include "nsRect.h"
12 #include "nsTArray.h"
13 #include "gfx3DMatrix.h"
15 namespace mozilla {
16 namespace gl {
18 /** Helper for DecomposeIntoNoRepeatTriangles
20 class RectTriangles {
21 public:
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
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);
31 /**
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() {
37 return mVertexCoords;
40 InfallibleTArray<coord>& texCoords() {
41 return mTexCoords;
44 unsigned int elements() {
45 return mVertexCoords.Length();
47 private:
48 // Reserve inline storage for one quad (2 triangles, 3 coords).
49 nsAutoTArray<coord, 6> mVertexCoords;
50 nsAutoTArray<coord, 6> mTexCoords;
52 static void
53 AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1);
56 /**
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,
73 bool aFlipY = false);
78 #endif // DecomposeIntoNoRepeatTriangles_h_