// -----------------------------------------------------------------------
//
// Change the number of tessellations used to render the object
//
// -----------------------------------------------------------------------
void
CDRGNURBSSurface::SetTessellations(int iUTessellations, int iVTessellations)
{
  if ((iUTessellations != m_iUTessellations)
      || (iVTessellations != m_iVTessellations))
    {
      m_iUTessellations = iUTessellations;
      m_iVTessellations = iVTessellations;

      //
      // Free anything we've already allocated
      //
      ALIGNED_DELETE(m_UBasis);
      ALIGNED_DELETE(m_VBasis);
      ALIGNED_DELETE(m_dUBasis);
      ALIGNED_DELETE(m_dVBasis);
      SAFE_DELETE(m_TessUKnotSpan);
      SAFE_DELETE(m_TessVKnotSpan);

      //
      // Allocate memory for the basis functions, etc
      //
      m_UBasis =
          ALIGNED_NEW(m_iUOrder * SIMD_SIZE * (m_iUTessellations+1), float)
      ;
      m_VBasis =
          ALIGNED_NEW(m_iVOrder * SIMD_SIZE * (m_iVTessellations+1), float)
      ;
      m_dUBasis =
          ALIGNED_NEW(m_iUOrder * SIMD_SIZE * (m_iUTessellations+1), float)
      ;
      m_dVBasis =
          ALIGNED_NEW(m_iVOrder * SIMD_SIZE * (m_iVTessellations+1), float)
      ;

      m_TessUKnotSpan = new int[m_iUTessellations + 1];
      m_TessVKnotSpan = new int[m_iVTessellations + 1];

      ALIGNED_DELETE(m_pVertices);

      int iVertices = ((iUTessellations + 1) * (iVTessellations + 1)); //2 * (iVTessellations + 1);
      m_pVertices = ALIGNED_NEW(iVertices, splinePoint)
      ;

      //
      // Re-evaluate the basis functions
      //
      EvaluateBasisFunctions();
    }
// -----------------------------------------------------------------------
//
// Free up anything we've allocated
//
// -----------------------------------------------------------------------
void CDRGNURBSSurface::Cleanup(void)
{
  ALIGNED_DELETE(m_pControlPoints);
  ALIGNED_DELETE(m_UKnots);
  ALIGNED_DELETE(m_VKnots);
  ALIGNED_DELETE(m_UBasisCoefficients);
  ALIGNED_DELETE(m_VBasisCoefficients);
  ALIGNED_DELETE(m_UBasis);
  ALIGNED_DELETE(m_dUBasis);
  ALIGNED_DELETE(m_VBasis);
  ALIGNED_DELETE(m_dVBasis);
  ALIGNED_DELETE(m_UTemp);
  ALIGNED_DELETE(m_dUTemp);
  ALIGNED_DELETE(m_pVertices);
  SAFE_DELETE(m_TessUKnotSpan);
  SAFE_DELETE(m_TessVKnotSpan);
}