gfx/gl/DecomposeIntoNoRepeatTriangles.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef DecomposeIntoNoRepeatTriangles_h_
michael@0 8 #define DecomposeIntoNoRepeatTriangles_h_
michael@0 9
michael@0 10 #include "GLTypes.h"
michael@0 11 #include "nsRect.h"
michael@0 12 #include "nsTArray.h"
michael@0 13 #include "gfx3DMatrix.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace gl {
michael@0 17
michael@0 18 /** Helper for DecomposeIntoNoRepeatTriangles
michael@0 19 */
michael@0 20 class RectTriangles {
michael@0 21 public:
michael@0 22 typedef struct { GLfloat x,y; } coord;
michael@0 23
michael@0 24 // Always pass texture coordinates upright. If you want to flip the
michael@0 25 // texture coordinates emitted to the tex_coords array, set flip_y to
michael@0 26 // true.
michael@0 27 void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
michael@0 28 GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1,
michael@0 29 bool flip_y = false);
michael@0 30
michael@0 31 // Returns whether this object is made of only one rect that can be drawn
michael@0 32 // with a pre-buffered unity quad which has 0,0,1,1 as both vertex
michael@0 33 // positions and texture coordinates.
michael@0 34 // aOutTextureTransform returns the transform that maps 0,0,1,1 texture
michael@0 35 // coordinates to the correct ones.
michael@0 36 bool isSimpleQuad(gfx3DMatrix& aOutTextureTransform) const;
michael@0 37
michael@0 38 /**
michael@0 39 * these return a float pointer to the start of each array respectively.
michael@0 40 * Use it for glVertexAttribPointer calls.
michael@0 41 * We can return nullptr if we choose to use Vertex Buffer Objects here.
michael@0 42 */
michael@0 43 InfallibleTArray<coord>& vertCoords() {
michael@0 44 return mVertexCoords;
michael@0 45 }
michael@0 46
michael@0 47 InfallibleTArray<coord>& texCoords() {
michael@0 48 return mTexCoords;
michael@0 49 }
michael@0 50
michael@0 51 unsigned int elements() {
michael@0 52 return mVertexCoords.Length();
michael@0 53 }
michael@0 54 private:
michael@0 55 // Reserve inline storage for one quad (2 triangles, 3 coords).
michael@0 56 nsAutoTArray<coord, 6> mVertexCoords;
michael@0 57 nsAutoTArray<coord, 6> mTexCoords;
michael@0 58
michael@0 59 static void
michael@0 60 AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1);
michael@0 61 };
michael@0 62
michael@0 63 /**
michael@0 64 * Decompose drawing the possibly-wrapped aTexCoordRect rectangle
michael@0 65 * of a texture of aTexSize into one or more rectangles (represented
michael@0 66 * as 2 triangles) and associated tex coordinates, such that
michael@0 67 * we don't have to use the REPEAT wrap mode. If aFlipY is true, the
michael@0 68 * texture coordinates will be specified vertically flipped.
michael@0 69 *
michael@0 70 * The resulting triangle vertex coordinates will be in the space of
michael@0 71 * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately
michael@0 72 * if you need a different space.
michael@0 73 *
michael@0 74 * The resulting vertex coordinates should be drawn using GL_TRIANGLES,
michael@0 75 * and rects.numRects * 3 * 6
michael@0 76 */
michael@0 77 void DecomposeIntoNoRepeatTriangles(const nsIntRect& aTexCoordRect,
michael@0 78 const nsIntSize& aTexSize,
michael@0 79 RectTriangles& aRects,
michael@0 80 bool aFlipY = false);
michael@0 81
michael@0 82 }
michael@0 83 }
michael@0 84
michael@0 85 #endif // DecomposeIntoNoRepeatTriangles_h_

mercurial