1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/gl/DecomposeIntoNoRepeatTriangles.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef DecomposeIntoNoRepeatTriangles_h_ 1.11 +#define DecomposeIntoNoRepeatTriangles_h_ 1.12 + 1.13 +#include "GLTypes.h" 1.14 +#include "nsRect.h" 1.15 +#include "nsTArray.h" 1.16 +#include "gfx3DMatrix.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace gl { 1.20 + 1.21 +/** Helper for DecomposeIntoNoRepeatTriangles 1.22 + */ 1.23 +class RectTriangles { 1.24 +public: 1.25 + typedef struct { GLfloat x,y; } coord; 1.26 + 1.27 + // Always pass texture coordinates upright. If you want to flip the 1.28 + // texture coordinates emitted to the tex_coords array, set flip_y to 1.29 + // true. 1.30 + void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, 1.31 + GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1, 1.32 + bool flip_y = false); 1.33 + 1.34 + // Returns whether this object is made of only one rect that can be drawn 1.35 + // with a pre-buffered unity quad which has 0,0,1,1 as both vertex 1.36 + // positions and texture coordinates. 1.37 + // aOutTextureTransform returns the transform that maps 0,0,1,1 texture 1.38 + // coordinates to the correct ones. 1.39 + bool isSimpleQuad(gfx3DMatrix& aOutTextureTransform) const; 1.40 + 1.41 + /** 1.42 + * these return a float pointer to the start of each array respectively. 1.43 + * Use it for glVertexAttribPointer calls. 1.44 + * We can return nullptr if we choose to use Vertex Buffer Objects here. 1.45 + */ 1.46 + InfallibleTArray<coord>& vertCoords() { 1.47 + return mVertexCoords; 1.48 + } 1.49 + 1.50 + InfallibleTArray<coord>& texCoords() { 1.51 + return mTexCoords; 1.52 + } 1.53 + 1.54 + unsigned int elements() { 1.55 + return mVertexCoords.Length(); 1.56 + } 1.57 +private: 1.58 + // Reserve inline storage for one quad (2 triangles, 3 coords). 1.59 + nsAutoTArray<coord, 6> mVertexCoords; 1.60 + nsAutoTArray<coord, 6> mTexCoords; 1.61 + 1.62 + static void 1.63 + AppendRectToCoordArray(InfallibleTArray<coord>& array, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1); 1.64 +}; 1.65 + 1.66 +/** 1.67 + * Decompose drawing the possibly-wrapped aTexCoordRect rectangle 1.68 + * of a texture of aTexSize into one or more rectangles (represented 1.69 + * as 2 triangles) and associated tex coordinates, such that 1.70 + * we don't have to use the REPEAT wrap mode. If aFlipY is true, the 1.71 + * texture coordinates will be specified vertically flipped. 1.72 + * 1.73 + * The resulting triangle vertex coordinates will be in the space of 1.74 + * (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately 1.75 + * if you need a different space. 1.76 + * 1.77 + * The resulting vertex coordinates should be drawn using GL_TRIANGLES, 1.78 + * and rects.numRects * 3 * 6 1.79 + */ 1.80 +void DecomposeIntoNoRepeatTriangles(const nsIntRect& aTexCoordRect, 1.81 + const nsIntSize& aTexSize, 1.82 + RectTriangles& aRects, 1.83 + bool aFlipY = false); 1.84 + 1.85 +} 1.86 +} 1.87 + 1.88 +#endif // DecomposeIntoNoRepeatTriangles_h_