michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef DecomposeIntoNoRepeatTriangles_h_ michael@0: #define DecomposeIntoNoRepeatTriangles_h_ michael@0: michael@0: #include "GLTypes.h" michael@0: #include "nsRect.h" michael@0: #include "nsTArray.h" michael@0: #include "gfx3DMatrix.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: /** Helper for DecomposeIntoNoRepeatTriangles michael@0: */ michael@0: class RectTriangles { michael@0: public: michael@0: typedef struct { GLfloat x,y; } coord; michael@0: michael@0: // Always pass texture coordinates upright. If you want to flip the michael@0: // texture coordinates emitted to the tex_coords array, set flip_y to michael@0: // true. michael@0: void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, michael@0: GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1, michael@0: bool flip_y = false); michael@0: michael@0: // Returns whether this object is made of only one rect that can be drawn michael@0: // with a pre-buffered unity quad which has 0,0,1,1 as both vertex michael@0: // positions and texture coordinates. michael@0: // aOutTextureTransform returns the transform that maps 0,0,1,1 texture michael@0: // coordinates to the correct ones. michael@0: bool isSimpleQuad(gfx3DMatrix& aOutTextureTransform) const; michael@0: michael@0: /** michael@0: * these return a float pointer to the start of each array respectively. michael@0: * Use it for glVertexAttribPointer calls. michael@0: * We can return nullptr if we choose to use Vertex Buffer Objects here. michael@0: */ michael@0: InfallibleTArray& vertCoords() { michael@0: return mVertexCoords; michael@0: } michael@0: michael@0: InfallibleTArray& texCoords() { michael@0: return mTexCoords; michael@0: } michael@0: michael@0: unsigned int elements() { michael@0: return mVertexCoords.Length(); michael@0: } michael@0: private: michael@0: // Reserve inline storage for one quad (2 triangles, 3 coords). michael@0: nsAutoTArray mVertexCoords; michael@0: nsAutoTArray mTexCoords; michael@0: michael@0: static void michael@0: AppendRectToCoordArray(InfallibleTArray& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1); michael@0: }; michael@0: michael@0: /** michael@0: * Decompose drawing the possibly-wrapped aTexCoordRect rectangle michael@0: * of a texture of aTexSize into one or more rectangles (represented michael@0: * as 2 triangles) and associated tex coordinates, such that michael@0: * we don't have to use the REPEAT wrap mode. If aFlipY is true, the michael@0: * texture coordinates will be specified vertically flipped. michael@0: * michael@0: * The resulting triangle vertex coordinates will be in the space of michael@0: * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately michael@0: * if you need a different space. michael@0: * michael@0: * The resulting vertex coordinates should be drawn using GL_TRIANGLES, michael@0: * and rects.numRects * 3 * 6 michael@0: */ michael@0: void DecomposeIntoNoRepeatTriangles(const nsIntRect& aTexCoordRect, michael@0: const nsIntSize& aTexSize, michael@0: RectTriangles& aRects, michael@0: bool aFlipY = false); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // DecomposeIntoNoRepeatTriangles_h_