Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttessellator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tregionoutline.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tcolorfunctions.h"
Toshihiro Shimizu 890ddd
#include "tthread.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_numeric_ops.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifndef _WIN32
Toshihiro Shimizu 890ddd
#define CALLBACK
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
// To avoid linking problems with HP ZX2000
Toshihiro Shimizu 890ddd
#ifdef LINUX
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Toshihiro Shimizu 890ddd
#undef GLU_VERSION_1_2
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#ifndef GLU_VERSION_1_1
Toshihiro Shimizu 890ddd
#define GLU_VERSION_1_1
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef checkErrorsByGL
Shinya Kitaoka 120a6e
#define checkErrorsByGL                                                        \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    GLenum err = glGetError();                                                 \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_ENUM);                                            \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_VALUE);                                           \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_OPERATION);                                       \
Shinya Kitaoka 120a6e
    assert(err != GL_STACK_OVERFLOW);                                          \
Shinya Kitaoka 120a6e
    assert(err != GL_STACK_UNDERFLOW);                                         \
Shinya Kitaoka 120a6e
    assert(err != GL_OUT_OF_MEMORY);                                           \
Shinya Kitaoka 120a6e
    assert(err == GL_NO_ERROR);                                                \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TglTessellator::GLTess::GLTess() {
Shinya Kitaoka 120a6e
  m_tess = gluNewTess();
Shinya Kitaoka 120a6e
  assert(m_tess);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TglTessellator::GLTess::~GLTess() { gluDeleteTess(m_tess); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
extern "C" {
Campbell Barton 8c6c57
static void CALLBACK tessellateTexture(const GLdouble *tex) {
Shinya Kitaoka 120a6e
  double u = tex[0] * 0.01;
Shinya Kitaoka 120a6e
  double v = tex[1] * 0.01;
Shinya Kitaoka 120a6e
  glTexCoord2d(u, v);
Shinya Kitaoka 120a6e
  glVertex2dv(tex);
Toshihiro Shimizu 890ddd
}
Campbell Barton 8c6c57
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThread::Mutex CombineDataGuard;
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static std::list<gldouble *=""> Combine_data;</gldouble>
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
extern "C" {
shun-iwasawa 27b0cf
static void CALLBACK myCombine(GLdouble coords[3], GLdouble *d[4], GLfloat w[4],
shun-iwasawa 27b0cf
                               GLdouble **dataOut) {
Shinya Kitaoka 120a6e
  GLdouble *newCoords = new GLdouble[3];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  newCoords[0] = coords[0];
Shinya Kitaoka 120a6e
  newCoords[1] = coords[1];
Shinya Kitaoka 120a6e
  newCoords[2] = coords[2];
Shinya Kitaoka 120a6e
  Combine_data.push_back(newCoords);
Shinya Kitaoka 120a6e
  *dataOut = newCoords;
Toshihiro Shimizu 890ddd
}
Campbell Barton 8c6c57
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// typedef std::vector<t3dpointd>::iterator Vect3D_iter;</t3dpointd>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
typedef GLvoid(CALLBACK *GluCallback)(void);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Campbell Barton 107701
#if defined(MACOSX) || defined(LINUX)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef GLvoid (*GluCallback)();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TglTessellator::doTessellate(GLTess &glTess, const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                  const bool antiAliasing,
Shinya Kitaoka 120a6e
                                  TRegionOutline outline, const TAffine &aff) {
Shinya Kitaoka 120a6e
  QMutexLocker sl(&CombineDataGuard);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Combine_data.clear();
Shinya Kitaoka 120a6e
  assert(glTess.m_tess);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_BEGIN, (GluCallback)glBegin);
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_END, (GluCallback)glEnd);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_COMBINE, (GluCallback)myCombine);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
  gluTessBeginPolygon(glTess.m_tess, NULL);
Shinya Kitaoka 120a6e
  gluTessProperty(glTess.m_tess, GLU_TESS_WINDING_RULE,
Shinya Kitaoka 120a6e
                  GLU_TESS_WINDING_POSITIVE);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
  gluBeginPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (TRegionOutline::Boundary::iterator poly_it = outline.m_exterior.begin();
Shinya Kitaoka 120a6e
       poly_it != outline.m_exterior.end(); ++poly_it) {
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
    gluTessBeginContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
    gluNextContour(glTess.m_tess, GLU_EXTERIOR);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (TRegionOutline::PointVector::iterator it = poly_it->begin();
Shinya Kitaoka 120a6e
         it != poly_it->end(); ++it) {
Shinya Kitaoka 120a6e
      // T3DPointD p = *it;
Shinya Kitaoka 120a6e
      it->x = aff.a11 * it->x + aff.a12 * it->y;
Shinya Kitaoka 120a6e
      it->y = aff.a21 * it->x + aff.a22 * it->y;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      gluTessVertex(glTess.m_tess, &(it->x), &(it->x));
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
    gluTessEndContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int subRegionNumber = outline.m_interior.size();
Shinya Kitaoka 120a6e
  if (subRegionNumber > 0) {
Shinya Kitaoka 120a6e
    for (TRegionOutline::Boundary::iterator poly_it =
Shinya Kitaoka 120a6e
             outline.m_interior.begin();
Shinya Kitaoka 120a6e
         poly_it != outline.m_interior.end(); ++poly_it) {
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
      gluTessBeginContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
      gluNextContour(glTess.m_tess, GLU_INTERIOR);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      for (TRegionOutline::PointVector::reverse_iterator rit =
Shinya Kitaoka 120a6e
               poly_it->rbegin();
Shinya Kitaoka 120a6e
           rit != poly_it->rend(); ++rit) {
Shinya Kitaoka 120a6e
        // T3DPointD p = *rit;
Shinya Kitaoka 120a6e
        rit->x = aff.a11 * rit->x + aff.a12 * rit->y;
Shinya Kitaoka 120a6e
        rit->y = aff.a21 * rit->x + aff.a22 * rit->y;
Shinya Kitaoka 120a6e
        gluTessVertex(glTess.m_tess, &(rit->x), &(rit->x));
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
      gluTessEndContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
  gluTessEndPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
  gluEndPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::list<gldouble *="">::iterator beginIt, endIt;</gldouble>
Shinya Kitaoka 120a6e
  endIt   = Combine_data.end();
Shinya Kitaoka 120a6e
  beginIt = Combine_data.begin();
Shinya Kitaoka 120a6e
  for (; beginIt != endIt; ++beginIt) delete[](*beginIt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TglTessellator::doTessellate(GLTess &glTess, const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                  const bool antiAliasing,
Shinya Kitaoka 120a6e
                                  TRegionOutline &outline) {
Shinya Kitaoka 120a6e
  QMutexLocker sl(&CombineDataGuard);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Combine_data.clear();
Shinya Kitaoka 120a6e
  assert(glTess.m_tess);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_BEGIN, (GluCallback)glBegin);
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_END, (GluCallback)glEnd);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_COMBINE, (GluCallback)myCombine);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
  gluTessBeginPolygon(glTess.m_tess, NULL);
Shinya Kitaoka 120a6e
  gluTessProperty(glTess.m_tess, GLU_TESS_WINDING_RULE,
Shinya Kitaoka 120a6e
                  GLU_TESS_WINDING_POSITIVE);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
  gluBeginPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (TRegionOutline::Boundary::iterator poly_it = outline.m_exterior.begin();
Shinya Kitaoka 120a6e
       poly_it != outline.m_exterior.end(); ++poly_it) {
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
    gluTessBeginContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
    gluNextContour(glTess.m_tess, GLU_EXTERIOR);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (TRegionOutline::PointVector::iterator it = poly_it->begin();
Shinya Kitaoka 120a6e
         it != poly_it->end(); ++it)
Shinya Kitaoka 120a6e
      gluTessVertex(glTess.m_tess, &(it->x), &(it->x));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
    gluTessEndContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int subRegionNumber = outline.m_interior.size();
Shinya Kitaoka 120a6e
  if (subRegionNumber > 0) {
Shinya Kitaoka 120a6e
    for (TRegionOutline::Boundary::iterator poly_it =
Shinya Kitaoka 120a6e
             outline.m_interior.begin();
Shinya Kitaoka 120a6e
         poly_it != outline.m_interior.end(); ++poly_it) {
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
      gluTessBeginContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
      gluNextContour(glTess.m_tess, GLU_INTERIOR);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      for (TRegionOutline::PointVector::reverse_iterator rit =
Shinya Kitaoka 120a6e
               poly_it->rbegin();
Shinya Kitaoka 120a6e
           rit != poly_it->rend(); ++rit)
Shinya Kitaoka 120a6e
        gluTessVertex(glTess.m_tess, &(rit->x), &(rit->x));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
      gluTessEndContour(glTess.m_tess);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_2
Shinya Kitaoka 120a6e
  gluTessEndPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef GLU_VERSION_1_1
Shinya Kitaoka 120a6e
  gluEndPolygon(glTess.m_tess);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  assert(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::list<gldouble *="">::iterator beginIt, endIt;</gldouble>
Shinya Kitaoka 120a6e
  endIt   = Combine_data.end();
Shinya Kitaoka 120a6e
  beginIt = Combine_data.begin();
Shinya Kitaoka 120a6e
  for (; beginIt != endIt; ++beginIt) delete[](*beginIt);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TglTessellator::tessellate(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                const bool antiAliasing,
Shinya Kitaoka 120a6e
                                TRegionOutline &outline, TPixel32 color) {
Shinya Kitaoka 120a6e
  if (cf) color = (*(cf))(color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (color.m == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool transparencyFlag = color.m < 255;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tglColor(color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (transparencyFlag) {
Shinya Kitaoka 120a6e
    tglEnableLineSmooth();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TglTessellator::GLTess glTess;
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_VERTEX, (GluCallback)glVertex3dv);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------//
Shinya Kitaoka 120a6e
  doTessellate(glTess, cf, antiAliasing, outline);
Shinya Kitaoka 120a6e
  //------------------------//
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (antiAliasing && outline.m_doAntialiasing) {
Shinya Kitaoka 120a6e
    tglEnableLineSmooth();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (TRegionOutline::Boundary::iterator poly_it =
Shinya Kitaoka 120a6e
             outline.m_exterior.begin();
Shinya Kitaoka 120a6e
         poly_it != outline.m_exterior.end(); ++poly_it) {
Shinya Kitaoka 120a6e
      std::vector<gldouble> v;</gldouble>
Shinya Kitaoka 120a6e
      if (poly_it->size() == 0) continue;
Shinya Kitaoka 120a6e
      v.resize(poly_it->size() * 2);
Shinya Kitaoka 120a6e
      int i = 0;
Shinya Kitaoka 120a6e
      for (TRegionOutline::PointVector::iterator it = poly_it->begin();
Shinya Kitaoka 120a6e
           it != poly_it->end(); ++it) {
Shinya Kitaoka 120a6e
        v[i++] = it->x;
Shinya Kitaoka 120a6e
        v[i++] = it->y;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glEnableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glVertexPointer(2, GL_DOUBLE, sizeof(GLdouble) * 2, &v[0]);
Shinya Kitaoka 120a6e
      glDrawArrays(GL_LINE_LOOP, 0, v.size() / 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glDisableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (TRegionOutline::Boundary::iterator poly_it =
Shinya Kitaoka 120a6e
             outline.m_interior.begin();
Shinya Kitaoka 120a6e
         poly_it != outline.m_interior.end(); ++poly_it) {
Shinya Kitaoka 120a6e
      std::vector<gldouble> v;</gldouble>
Shinya Kitaoka 120a6e
      v.resize(poly_it->size() * 2);
Shinya Kitaoka 120a6e
      int i = 0;
Shinya Kitaoka 120a6e
      for (TRegionOutline::PointVector::iterator it = poly_it->begin();
Shinya Kitaoka 120a6e
           it != poly_it->end(); ++it) {
Shinya Kitaoka 120a6e
        v[i++] = it->x;
Shinya Kitaoka 120a6e
        v[i++] = it->y;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (v.empty()) continue;
Shinya Kitaoka 120a6e
      glEnableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glVertexPointer(2, GL_DOUBLE, sizeof(GLdouble) * 2, &v[0]);
Shinya Kitaoka 120a6e
      glDrawArrays(GL_LINE_LOOP, 0, v.size() / 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glDisableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TglTessellator::tessellate(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                const bool antiAliasing,
Shinya Kitaoka 120a6e
                                TRegionOutline &outline, TRaster32P texture) {
Shinya Kitaoka 120a6e
  // QMutexLocker sl(m_mutex);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glEnable(GL_TEXTURE_2D);
Shinya Kitaoka 120a6e
  glColor4d(1, 1, 1, 1);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  TextureInfoForGL texInfo;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int pow2Lx = tcg::numeric_ops::GE_2Power((unsigned int)texture->getLx());
Shinya Kitaoka 120a6e
  int pow2Ly = tcg::numeric_ops::GE_2Power((unsigned int)texture->getLy());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TAffine aff;
Shinya Kitaoka 120a6e
  if (texture->getLx() != pow2Lx || texture->getLy() != pow2Ly) {
Shinya Kitaoka 120a6e
    TRaster32P r(pow2Lx, pow2Ly);
Shinya Kitaoka 120a6e
    aff = TScale((double)pow2Lx / texture->getLx(),
Shinya Kitaoka 120a6e
                 (double)pow2Ly / texture->getLy());
Shinya Kitaoka 120a6e
    TRop::resample(r, texture,
Shinya Kitaoka 120a6e
                   aff.place(texture->getCenterD(), r->getCenterD()));
Shinya Kitaoka 120a6e
    texture = r;
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    tglMultMatrix(aff.inv());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // If GL_BRGA isn't present make a proper texture to use (... obsolete?)
Shinya Kitaoka 120a6e
  texture->lock();
Shinya Kitaoka 120a6e
  TRasterP texImage = prepareTexture(texture, texInfo);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  if (texImage != texture) texImage->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(texImage->getLx() == texImage->getWrap());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  GLuint texId;
Shinya Kitaoka 120a6e
  glGenTextures(1, &texId);  // Generate a texture name
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glBindTexture(GL_TEXTURE_2D, texId);  // Bind it 'active'
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
Shinya Kitaoka 120a6e
                  GL_REPEAT);  // These must be invoked
Shinya Kitaoka 120a6e
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
Shinya Kitaoka 120a6e
                  GL_REPEAT);  // on a bound texture
Shinya Kitaoka 120a6e
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  //
Shinya Kitaoka 120a6e
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  //
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glTexEnvf(GL_TEXTURE_ENV,       // This too ?
Shinya Kitaoka 120a6e
            GL_TEXTURE_ENV_MODE,  // Better here anyway
Shinya Kitaoka 120a6e
            GL_MODULATE);         //
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glTexImage2D(GL_TEXTURE_2D,
Shinya Kitaoka 120a6e
               0,                       // one level only
Shinya Kitaoka 120a6e
               texInfo.internalformat,  // pixel channels count
Shinya Kitaoka 120a6e
               texInfo.width,           // width
Shinya Kitaoka 120a6e
               texInfo.height,          // height
Shinya Kitaoka 120a6e
               0,                       // border size
Shinya Kitaoka 120a6e
               texInfo.type,    // pixel format           // crappy names
Shinya Kitaoka 120a6e
               texInfo.format,  // pixel data type        // oh, SO much
Shinya Kitaoka 120a6e
               texImage->getRawData());
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  texture->unlock();
Shinya Kitaoka 120a6e
  if (texImage != texture) texImage->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TglTessellator::GLTess glTess;
Shinya Kitaoka 120a6e
  gluTessCallback(glTess.m_tess, GLU_TESS_VERTEX,
Shinya Kitaoka 120a6e
                  (GluCallback)tessellateTexture);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------//
Shinya Kitaoka 120a6e
  if (aff != TAffine())
Shinya Kitaoka 120a6e
    doTessellate(glTess, cf, antiAliasing, outline,
Shinya Kitaoka 120a6e
                 aff);  // Tessellate & render
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    doTessellate(glTess, cf, antiAliasing, outline);  // Tessellate & render
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  //------------------------//
Shinya Kitaoka 120a6e
  if (aff != TAffine()) glPopMatrix();
Shinya Kitaoka 120a6e
  glDeleteTextures(1, &texId);  // Delete & unbind texture
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  glDisable(GL_TEXTURE_2D);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// TglTessellator::GLTess TglTessellator::m_glTess;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================