1 #ifndef __TRESHAPEGROUP_H__ 2 #define __TRESHAPEGROUP_H__ 3 4 #include <TCFoundation/TCObject.h> 5 #include <TCFoundation/TCTypedValueArray.h> 6 #include <TCFoundation/TCTypedObjectArray.h> 7 #include <TCFoundation/TCVector.h> 8 #include <TCFoundation/TCStlIncludes.h> 9 #include <TRE/TREGL.h> 10 11 typedef void (TCObject::*TREScanPointCallback)(const TCVector &point); 12 13 typedef TCTypedObjectArray<TCULongArray> TCULongArrayArray; 14 typedef std::vector<GLboolean> GLbooleanVector; 15 16 struct TREVertex; 17 class TREVertexStore; 18 class TREMainModel; 19 class TREModel; 20 class TREVertexArray; 21 class TCVector; 22 23 typedef enum TREShapeType 24 { 25 TRESLine = 0x0001, 26 TRESFirst = TRESLine, 27 TRESConditionalLine = 0x0002, 28 TRESTriangle = 0x0004, 29 TRESQuad = 0x0008, 30 TRESTriangleStrip = 0x0010, 31 TRESFirstStrip = TRESTriangleStrip, 32 TRESQuadStrip = 0x0020, 33 TRESTriangleFan = 0x0040, 34 TRESLast = TRESTriangleFan 35 } TREShapeType; 36 37 typedef std::map<TREShapeType, IntVector> ShapeTypeIntVectorMap; 38 39 class TREShapeGroup : public TCObject 40 { 41 public: 42 enum TRESTransferType 43 { 44 TTTransparent, 45 TTTexmapped, 46 }; 47 TREShapeGroup(void); 48 TREShapeGroup(const TREShapeGroup &other); 49 virtual TCObject *copy(void) const; 50 int addLine(const TCVector *vertices); 51 int addConditionalLine(const TCVector *vertices, 52 const TCVector *controlPoints); 53 int addTriangle(const TCVector *vertices); 54 int addTriangle(const TCVector *vertices, const TCVector *normals); 55 int addTriangle(const TCVector *vertices, const TCVector *normals, 56 const TCVector *textureCoords); 57 int addQuad(const TCVector *vertices); 58 int addQuad(const TCVector *vertices, const TCVector *normals); 59 int addTriangleStrip(const TCVector *vertices, 60 const TCVector *normals, int count); 61 int addQuadStrip(const TCVector *vertices, const TCVector *normals, 62 int count); 63 int addTriangleFan(const TCVector *vertices, 64 const TCVector *normals, int count); 65 int addTriangleFan(const TCVector *vertices, 66 const TCVector *normals, const TCVector *textureCoords, int count); 67 TCULongArray *getIndices(TREShapeType shapeType, 68 bool create = false); 69 virtual TCULongArray *getControlPointIndices(bool create = false); 70 virtual TCULongArray *getStripCounts(TREShapeType shapeType, 71 bool create = false); 72 void draw(bool skipTexmapped = false); 73 virtual void drawTextured(void); 74 virtual void drawLines(void); 75 virtual void drawConditionalLines(void); 76 virtual void drawConditionalLines(const TCULongArray *activeIndices); 77 virtual void setVertexStore(TREVertexStore *vertexStore); getVertexStore(void)78 virtual TREVertexStore *getVertexStore(void) { return m_vertexStore; } 79 virtual void scanPoints(TCObject *scanner, 80 TREScanPointCallback scanPointCallback, const TCFloat *matrix); 81 virtual void unshrinkNormals(const TCFloat *matrix, 82 const TCFloat *unshrinkMatrix); 83 virtual void unMirror(void); 84 virtual void invert(void); 85 virtual void transfer(TRESTransferType type, TCULong color, 86 const TCFloat *matrix, bool bfcInvert = false); 87 virtual void flatten(TREShapeGroup *srcShapes, const TCFloat *matrix, 88 TCULong color, bool colorSet, bool skipTexmapped = false); 89 void setModel(TREModel *value); getMainModel(void)90 TREMainModel *getMainModel(void) { return m_mainModel; } 91 virtual TCULongArray *getActiveConditionalIndices(TCULongArray *indices, 92 const TCFloat *modelMatrix = NULL, int start = 0, int count = -1); 93 virtual void nextStep(void); 94 virtual void updateConditionalsStepCount(int step); 95 virtual int getIndexCount(TREShapeType shapeType); setBfc(bool value)96 void setBfc(bool value) { m_bfc = value; } getBfc(void)97 bool getBfc(void) const { return m_bfc; } 98 virtual void drawShapeType(TREShapeType shapeType, int offset = 0, 99 int count = -1); 100 virtual void cleanupTransfer(void); 101 102 static GLenum modeForShapeType(TREShapeType shapeType); 103 static int numPointsForShapeType(TREShapeType shapeType); 104 static bool isTransparent(TCULong color, bool hostFormat); 105 static void transformVertex(TREVertex &vertex, const TCFloat *matrix); 106 static void transformNormal(TREVertex &normal, const TCFloat *matrix); 107 108 static void transformPoint(const TCVector &point, const TCFloat *matrix, 109 TCFloat *tx, TCFloat *ty); 110 static int turnVector(TCFloat vx1, TCFloat vy1, TCFloat vx2, TCFloat vy2); 111 static bool isTexmappedShapeType(TREShapeType shapeType); 112 protected: 113 virtual ~TREShapeGroup(void); 114 virtual void dealloc(void); 115 virtual TCULong getShapeTypeIndex(TREShapeType shapeType); 116 int addShape(TREShapeType shapeType, const TCVector *vertices, 117 int count); 118 int addShape(TREShapeType shapeType, const TCVector *vertices, 119 const TCVector *normals, int count); 120 int addShape(TREShapeType shapeType, const TCVector *vertices, 121 const TCVector *normals, const TCVector *textureCoords, int count); 122 void addShapeIndices(TREShapeType shapeType, int firstIndex, 123 int count); 124 void addIndices(TCULongArray *indices, int firstIndex, int count); 125 void addShapeStripCount(TREShapeType shapeType, int count); 126 void addShapeType(TREShapeType shapeType, int index); 127 virtual void drawNormals(TCULongArray *indexArray, int count, 128 int offset = 0); 129 virtual void drawStripShapeType(TREShapeType shapeType); 130 int addStrip(TREShapeType shapeType, const TCVector *vertices, 131 const TCVector *normals, int count); 132 int addStrip(TREShapeType shapeType, const TCVector *vertices, 133 const TCVector *normals, const TCVector *textureCoords, int count); 134 virtual void initMultiDrawIndices(void); 135 virtual void deleteMultiDrawIndices(void); 136 virtual void invertShapes(TCULongArray *oldIndices, 137 TCULongArray *newIndices); 138 virtual int flipNormal(int index); 139 virtual void transferTriangle(TRESTransferType type, TCULong color, 140 TCULong index0, TCULong index1, TCULong index2, const TCFloat *matrix, 141 bool bfcInvert); 142 virtual void transferQuadStrip(TRESTransferType type, int shapeTypeIndex, 143 TCULong color, int offset, int stripCount, const TCFloat *matrix, 144 bool bfcInvert); 145 virtual void transferTriangleStrip(TRESTransferType type, int shapeTypeIndex, 146 TCULong color, int offset, int stripCount, const TCFloat *matrix, 147 bool bfcInvert); 148 virtual void transferTriangleFan(TRESTransferType type, int shapeTypeIndex, 149 TCULong color, int offset, int stripCount, const TCFloat *matrix, 150 bool bfcInvert); 151 virtual void transfer(TRESTransferType type, TCULong color, 152 TREShapeType shapeType, TCULongArray *indices, 153 TCULongArray *transferIndices, const TCFloat *matrix, bool bfcInvert); 154 virtual bool shouldDrawConditional(TCULong index1, TCULong index2, 155 TCULong cpIndex1, TCULong cpIndex2, const TCFloat *matrix); isColored(void)156 virtual bool isColored(void) { return false; } 157 virtual void recordTransfer(TCULongArray *transferIndices, int index, 158 int shapeSize); 159 160 virtual void scanPoints(TCULong index, TCObject *scanner, 161 TREScanPointCallback scanPointCallback, const TCFloat *matrix); 162 virtual void scanPoints(const TREVertex &vertex, TCObject *scanner, 163 TREScanPointCallback scanPointCallback); 164 virtual void scanPoints(TCULongArray *indices, TCObject *scanner, 165 TREScanPointCallback scanPointCallback, const TCFloat *matrix); 166 virtual void scanStripPoints(TCULongArray *indices, 167 TCULongArray *stripCounts, TCObject *scanner, 168 TREScanPointCallback scanPointCallback, const TCFloat *matrix); 169 virtual void flattenShapes(TREVertexArray *dstVertices, 170 TREVertexArray *dstNormals, 171 TREVertexArray *dstTextureCoords, 172 TCULongArray *dstColors, 173 TCULongArray *dstIndices, 174 TCULongArray *dstCPIndices, 175 GLbooleanVector &dstEdgeFlags, 176 TREVertexArray *srcVertices, 177 TREVertexArray *srcNormals, 178 TREVertexArray *srcTextureCoords, 179 TCULongArray *srcColors, 180 TCULongArray *srcIndices, 181 TCULongArray *srcCPIndices, 182 GLbooleanVector &srcEdgeFlags, 183 const TCFloat *matrix, 184 TCULong color, 185 bool colorSet); 186 virtual void flattenStrips(TREVertexArray *dstVertices, 187 TREVertexArray *dstNormals, 188 TREVertexArray *dstTextureCoords, 189 TCULongArray *dstColors, 190 TCULongArray *dstIndices, 191 TCULongArray *dstStripCounts, 192 TREVertexArray *srcVertices, 193 TREVertexArray *srcNormals, 194 TREVertexArray *srcTextureCoords, 195 TCULongArray *srcColors, 196 TCULongArray *srcIndices, 197 TCULongArray *srcStripCounts, 198 const TCFloat *matrix, 199 TCULong color, 200 bool colorSet); 201 virtual void mirrorTextureCoords(TCULongArray *indices); 202 203 virtual void unshrinkNormal(TCULong index, const TCFloat *matrix, 204 const TCFloat *unshrinkMatrix); 205 virtual void unshrinkNormals(TCULongArray *indices, const TCFloat *matrix, 206 const TCFloat *unshrinkMatrix); 207 virtual void unshrinkStripNormals(TCULongArray *indices, 208 TCULongArray *stripCounts, const TCFloat *matrix, 209 const TCFloat *unshrinkMatrix); 210 virtual void nextStep(TREShapeType shapeType); 211 virtual bool shouldTransferIndex(TRESTransferType type, 212 TREShapeType shapeType, TCULong color, int index, 213 const TCFloat *matrix); 214 bool shouldTransferIndex(TRESTransferType type, TREShapeType shapeType, 215 TCULong color, int index, bool colored, const TCFloat *matrix); 216 virtual TCULongArray *getTransferIndices(TRESTransferType type, 217 TREShapeType shapeType); 218 virtual bool shouldGetTransferIndices(TRESTransferType type); 219 220 TREVertexStore *m_vertexStore; 221 TCULongArrayArray *m_indices; 222 TCULongArray *m_controlPointIndices; 223 TCULongArrayArray *m_stripCounts; 224 TCULong ***m_multiDrawIndices; 225 TCULong m_shapesPresent; 226 TREMainModel *m_mainModel; 227 TREModel *m_model; 228 ShapeTypeIntVectorMap m_stepCounts; 229 bool m_bfc; 230 TCULongArrayArray *m_transferIndices; 231 }; 232 233 #endif // __TRESHAPEGROUP_H__ 234