HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_TPSurfCache.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Geometry library (C++)
7  *
8  * COMMENTS: Display cache for spline surfaces.
9  *
10  */
11 
12 #ifndef __GU_TPSurfCache_H__
13 #define __GU_TPSurfCache_H__
14 
15 #include "GU_API.h"
16 #include <UT/UT_Vector4Array.h>
17 #include <UT/UT_Vector3Array.h>
18 #include <GA/GA_AttributeRef.h>
19 #include <GA/GA_Handle.h>
20 #include "GU_DisplayCache.h"
21 
22 class GEO_TPSurf;
24 class GEO_Detail;
26 class GU_TrimTesselator;
27 class GU_TrimPatch;
28 
30 {
31  GU_TPSURF_TRIM_PARTIAL = -1, // trim curve matters, partially trimmed
32  GU_TPSURF_TRIM_ALL_OUT = 0, // trimmed out
33  GU_TPSURF_TRIM_ALL_IN = 1 // all present (trimmed in)
34 };
35 
36 // TODO: When deleting GU_DisplayCache, DON'T delete
37 // GU_TPSurfCache! Move it to GT_TPSurfCache, since
38 // it's still used by GT_GEOPrimTPSurf!!!
40 
42 {
43 public:
44  GU_TPTrimSurfCache();
45  ~GU_TPTrimSurfCache();
46 
47  int64 getMemoryUsage(bool inclusive) const;
48 
49  void resizeAttributes(const GEO_Detail *gdp);
50  bool hasAttributes() const
51  { return myHasCd || myHasUv || myHasAf; }
52 
53 private:
54  // Uncut loops
55  UT_Vector4Array myPoints;
56  UT_Vector3Array myNormals;
57  UT_Vector3Array myColors;
58  UT_Vector3Array myUVs;
59  UT_FloatArray myAlphas;
60  GU_TrimTesselator *myTesselator;
61  GU_TrimPatch *myPatch;
62  GU_TPSurfTrimState myTrimmedState;
63  bool myHasCd;
64  bool myHasUv;
65  bool myHasAf;
66 
67  friend class GU_TPSurfCache;
68 };
69 
71 {
72 public:
74  ~GU_TPSurfCache() override;
75 
76  int64 getMemoryUsage(bool inclusive) const;
77 
78  // Record the domain interval in which the surface needs to be recomputed:
79  void touchDomain(int ustart_idx, int ustop_idx,
80  int vstart_idx, int vstop_idx);
81 
82  // Get tesselation of patch.
83  // Will tesselate if not already done...
84  GU_TrimTesselator *getTesselation();
85 
86  // Gets the tesselated trimmed patch:
87  const GU_TrimPatch *getPatch() const
88  { return (myPatches)?myPatches->myPatch : 0;}
89 
90  // Build the cache.
91  int refresh(GU_TPSurfCacheParms &parms);
92 
93  // Find out how the cache was built: wire or shaded.
94  GU_CacheMode builtAs() const { return myMode; }
95 
96  // Get the curve and point counts given the internal lod, the build type,
97  // and the mesh's "wrap" characteristics.
98  void getCounts(int uwrapped, int vwrapped,
99  int &nucurves, int &nupoints,
100  int &nvcurves, int &nvpoints) const;
101  void getCounts(int uwrapped, int vwrapped,
102  int &nupoints, int &nvpoints) const;
103 
104  // we only worry about alpha if there is color as well
106  {
107  return (!myCdOffset.isValid() && mode != GU_CACHESHADED)
108  ? 0
109  : myCdOffset.isValid() ||
110  myTxtOffset.isValid() ||
111  myAlphaOffset.isValid();
112  }
113 
114  bool hasColor() const { return myCdOffset.isValid(); }
115  bool hasTexture() const { return myTxtOffset.isValid(); }
116  bool hasAlpha() const { return myAlphaOffset.isValid(); }
117 
118  // 0 if trimmed out, 1 if all present, -1 if trim curve matters.
120  {
121  return !myPatches ? GU_TPSURF_TRIM_ALL_IN
122  : myPatches->myTrimmedState;
123  }
124 
125  // Allocates new trim index.
126  int getNewTrimIndex();
127  // Evaluates trim point described by index:
128  void evaluateTrimIndex(GEO_AttributeHandleList *hlist,
129  const GEO_TPSurf *surf, int index, float u, float v);
130 
131  const UT_Vector4Array &points () const { return myPoints; }
132  const UT_Vector3Array &normals() const { return myNormals;}
133  const UT_Vector3Array &colors() const { return myColors;}
134  const UT_Vector3Array &uvs() const { return myUVs;}
135  const UT_FloatArray &alphas() const { return myAlphas;}
136  const UT_Vector4Array &trimPoints () const
137  { return myPatches->myPoints; }
138  const UT_Vector3Array &trimNormals () const
139  { return myPatches->myNormals;}
140  const UT_Vector3Array &trimColors() const
141  { return myPatches->myColors;}
142  const UT_Vector3Array &trimUVs() const
143  { return myPatches->myUVs;}
144  const UT_FloatArray &trimAlphas() const
145  { return myPatches->myAlphas;}
146 protected:
147  // Clear the cache data and other related info:
148  void initializeData() override;
149 
150  // If pushXform is set, the cache data has not been updated with the
151  // latest xform matrix. This method makes sure the data _is_ updated,
152  // and turns off the flag.
153  void assimilateXform() override;
154 
155 private:
156  const GA_ROHandleV3 &colorOffset () const { return myCdOffset; }
157  const GA_ROHandleF &alphaOffset () const { return myAlphaOffset; }
158  const GA_ROHandleF &textureOffset() const { return myTxtOffset; }
159 
160  UT_Vector4Array myPoints;
161  UT_Vector3Array myNormals;
162  UT_Vector3Array myColors;
163  UT_Vector3Array myUVs;
164  UT_FloatArray myAlphas;
165  GU_CacheMode myMode;
166  GU_TPTrimSurfCache *myPatches;
167 
168  int myUSpans, myVSpans;
169  int myUSize, myVSize;
170  GA_ROHandleV3 myCdOffset; // Color attribute
171  GA_ROHandleF myTxtOffset; // Texture attribute
172  GA_ROHandleF myAlphaOffset; // Alpha offset
173 
174  // Resize the attribute data and the attribute list (if necessary):
175  void resizeAttributes(GEO_Detail *gdp, int ptattrib = 1);
176 
177  // Fill the array of float offsets based on what attributes are set.
178  void buildFloatOffsets(GEO_Detail *gdp, GEO_AttributeHandleList *gu_farray);
179  // Evaluate the surface because we know it's dirty. Return 0 if OK.
180  int evaluateSurface(const GEO_TPSurf *surf);
181 
182  // Evaluate the normals of the whole evaluated surface.
183  void evaluateNormals(const GEO_TPSurf *surf);
184 };
185 
187 {
188 public:
190  ~GU_TPSurfCacheParms() override;
191 
192  void surface(const GEO_TPSurf *surf) { myTPSurf = surf; }
193  const GEO_TPSurf *surface() const { return myTPSurf; }
194 
195 private:
196  const GEO_TPSurf *myTPSurf;
197 };
198 
200 
201 #endif
const UT_Vector3Array & trimColors() const
bool hasAttributes() const
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
int64 getMemoryUsage(bool inclusive) const override
Definition: GU_TrimPatch.h:126
const GLdouble * v
Definition: glcorearb.h:837
#define SYS_DEPRECATED_PUSH_DISABLE()
int hasAttributes(GU_CacheMode mode) const
#define SYS_DEPRECATED_POP_DISABLE()
bool hasAlpha() const
const UT_FloatArray & alphas() const
const UT_Vector4Array & trimPoints() const
const UT_Vector4Array & points() const
virtual void assimilateXform()
const UT_Vector3Array & normals() const
const GEO_TPSurf * surface() const
const UT_Vector3Array & colors() const
const UT_Vector3Array & trimNormals() const
const UT_FloatArray & trimAlphas() const
GU_TPSurfTrimState
virtual void initializeData()
long long int64
Definition: SYS_Types.h:116
const UT_Vector3Array & uvs() const
#define GU_API
Definition: GU_API.h:14
GU_CacheMode
GLenum mode
Definition: glcorearb.h:99
void surface(const GEO_TPSurf *surf)
GLuint index
Definition: glcorearb.h:786
GU_TPSurfTrimState getTrimmedState() const
bool hasColor() const
GU_CacheMode builtAs() const
const GU_TrimPatch * getPatch() const
const UT_Vector3Array & trimUVs() const
bool hasTexture() const