Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / gfx / gl / DecomposeIntoNoRepeatTriangles.h
blob2023afbf08d3bd6420d1a0fc3222216540543527
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"
14 namespace mozilla {
15 namespace gl {
17 /** Helper for DecomposeIntoNoRepeatTriangles
19 class RectTriangles {
20 public:
21 typedef struct { GLfloat x,y; } coord;
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);
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.
35 InfallibleTArray<coord>& vertCoords() {
36 return mVertexCoords;
39 InfallibleTArray<coord>& texCoords() {
40 return mTexCoords;
43 unsigned int elements() {
44 return mVertexCoords.Length();
46 private:
47 // Reserve inline storage for one quad (2 triangles, 3 coords).
48 nsAutoTArray<coord, 6> mVertexCoords;
49 nsAutoTArray<coord, 6> mTexCoords;
51 static void
52 AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1);
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.
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.
66 * The resulting vertex coordinates should be drawn using GL_TRIANGLES,
67 * and rects.numRects * 3 * 6
69 void DecomposeIntoNoRepeatTriangles(const nsIntRect& aTexCoordRect,
70 const nsIntSize& aTexSize,
71 RectTriangles& aRects,
72 bool aFlipY = false);
77 #endif // DecomposeIntoNoRepeatTriangles_h_