OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2010, Google Inc. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are |
| 7 * met: |
| 8 * |
| 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. |
| 11 * * Redistributions in binary form must reproduce the above |
| 12 * copyright notice, this list of conditions and the following disclaimer |
| 13 * in the documentation and/or other materials provided with the |
| 14 * distribution. |
| 15 * * Neither the name of Google Inc. nor the names of its |
| 16 * contributors may be used to endorse or promote products derived from |
| 17 * this software without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ |
| 31 |
| 32 #ifndef O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ |
| 33 #define O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ |
| 34 |
| 35 #include <vector> |
| 36 |
| 37 #include "base/basictypes.h" |
| 38 |
| 39 namespace o3d { |
| 40 namespace gpu2d { |
| 41 |
| 42 // A cache of the processed triangle mesh for a given path. Because |
| 43 // these might be expensive to allocate (using malloc/free |
| 44 // internally), it is recommended to try to reuse them when possible. |
| 45 |
| 46 // Uncomment the following to obtain debugging information for the edges facing |
| 47 // the interior region of the mesh. |
| 48 // #define O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES |
| 49 |
| 50 class PathCache { |
| 51 public: |
| 52 PathCache() { |
| 53 } |
| 54 |
| 55 // The number of vertices in the mesh. |
| 56 unsigned int num_vertices() const; |
| 57 |
| 58 // Get the base pointer to the vertex information. There are two |
| 59 // coordinates per vertex. This pointer is valid until the cache is |
| 60 // cleared or another vertex is added. Returns NULL if there are no |
| 61 // vertices in the mesh. |
| 62 const float* vertices() const; |
| 63 |
| 64 // Get the base pointer to the texture coordinate information. There |
| 65 // are three coordinates per vertex. This pointer is valid until the |
| 66 // cache is cleared or another vertex is added. Returns NULL if |
| 67 // there are no vertices in the mesh. |
| 68 const float* texcoords() const; |
| 69 |
| 70 // Adds a vertex's information to the cache. The first two arguments |
| 71 // are the x and y coordinates of the vertex on the plane; the last |
| 72 // three arguments are the cubic texture coordinates associated with |
| 73 // this vertex. |
| 74 void AddVertex(float x, float y, |
| 75 float k, float l, float m); |
| 76 |
| 77 // The number of interior vertices. |
| 78 unsigned int num_interior_vertices() const; |
| 79 // Base pointer to the interior vertices; two coordinates per |
| 80 // vertex, which can be drawn as GL_TRIANGLES. Returns NULL if there |
| 81 // are no interior vertices in the mesh. |
| 82 const float* interior_vertices() const; |
| 83 // Adds an interior vertex to the cache. |
| 84 void AddInteriorVertex(float x, float y); |
| 85 |
| 86 // Clears all of the stored vertex information in this cache. |
| 87 void Clear(); |
| 88 |
| 89 #ifdef O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES |
| 90 // The number of interior edge vertices |
| 91 unsigned int num_interior_edge_vertices() const; |
| 92 // Base pointer to the interior vertices; two coordinates per |
| 93 // vertex, which can be drawn as GL_LINES. Returns NULL if there are |
| 94 // no interior edge vertices in the mesh. |
| 95 const float* interior_edge_vertices() const; |
| 96 void AddInteriorEdgeVertex(float x, float y); |
| 97 #endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES |
| 98 |
| 99 private: |
| 100 // The two-dimensional vertices of the triangle mesh. |
| 101 std::vector<float> vertices_; |
| 102 |
| 103 // The three-dimensional cubic texture coordinates. |
| 104 std::vector<float> texcoords_; |
| 105 |
| 106 std::vector<float> interior_vertices_; |
| 107 |
| 108 #ifdef O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES |
| 109 // The following is only for debugging |
| 110 std::vector<float> interior_edge_vertices_; |
| 111 #endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(PathCache); |
| 114 }; |
| 115 |
| 116 } // namespace gpu2d |
| 117 } // namespace o3d |
| 118 |
| 119 #endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ |
| 120 |
OLD | NEW |