Commit 19b34480 authored by Maciej Suminski's avatar Maciej Suminski

Fixed the tesselator, so now it works with Windows.

parent 5e474cf8
...@@ -37,10 +37,6 @@ ...@@ -37,10 +37,6 @@
#include <limits> #include <limits>
#ifndef CALLBACK
#define CALLBACK
#endif
using namespace KiGfx; using namespace KiGfx;
// Prototypes // Prototypes
...@@ -92,6 +88,10 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -92,6 +88,10 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
// Tesselator initialization // Tesselator initialization
tesselator = gluNewTess(); tesselator = gluNewTess();
InitTesselatorCallbacks( tesselator ); InitTesselatorCallbacks( tesselator );
if( tesselator == NULL )
{
wxLogFatalError( wxT( "Could not create the tesselator" ) );
}
gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE ); gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
} }
...@@ -471,41 +471,25 @@ void OPENGL_GAL::DrawPolygon( const std::deque<VECTOR2D>& aPointList ) ...@@ -471,41 +471,25 @@ void OPENGL_GAL::DrawPolygon( const std::deque<VECTOR2D>& aPointList )
// for this purpose the GLU standard functions are used // for this purpose the GLU standard functions are used
currentManager->Shader( SHADER_NONE ); currentManager->Shader( SHADER_NONE );
typedef std::vector<OGLPOINT> OGLPOINTS;
// Do only one heap allocation, can do because we know size in advance.
// std::vector is then fastest
OGLPOINTS vertexList( aPointList.size(), OGLPOINT( "fastest" ) );
glNormal3d( 0.0, 0.0, 1.0 );
currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a );
glShadeModel( GL_FLAT );
TessParams params = { currentManager, tessIntersects }; TessParams params = { currentManager, tessIntersects };
gluTessBeginPolygon( tesselator, &params ); gluTessBeginPolygon( tesselator, &params );
gluTessBeginContour( tesselator ); gluTessBeginContour( tesselator );
// use operator=( const POINTS& ) boost::shared_array<GLdouble> points( new GLdouble[3 * aPointList.size()] );
copy( aPointList.begin(), aPointList.end(), vertexList.begin() ); int v = 0;
for( std::deque<VECTOR2D>::const_iterator it = aPointList.begin(); it != aPointList.end(); it++ )
for( OGLPOINTS::iterator it = vertexList.begin(); it != vertexList.end(); it++ )
{ {
it->z = layerDepth; points[v] = it->x;
gluTessVertex( tesselator, &it->x, &it->x ); points[v + 1] = it->y;
points[v + 2] = layerDepth;
gluTessVertex( tesselator, &points[v], &points[v] );
v += 3;
} }
gluTessEndContour( tesselator ); gluTessEndContour( tesselator );
gluTessEndPolygon( tesselator ); gluTessEndPolygon( tesselator );
// Free allocated intersecting points // Free allocated intersecting points
std::vector<GLdouble*>::iterator it, it_end;
for( it = tessIntersects.begin(), it_end = tessIntersects.end(); it < it_end; ++it )
{
delete[] *it;
}
tessIntersects.clear(); tessIntersects.clear();
// vertexList destroyed here // vertexList destroyed here
...@@ -1028,7 +1012,7 @@ void CALLBACK CombineCallback( GLdouble coords[3], ...@@ -1028,7 +1012,7 @@ void CALLBACK CombineCallback( GLdouble coords[3],
OPENGL_GAL::TessParams* param = static_cast<OPENGL_GAL::TessParams*>( aData ); OPENGL_GAL::TessParams* param = static_cast<OPENGL_GAL::TessParams*>( aData );
// Save the pointer so we can delete it later // Save the pointer so we can delete it later
param->intersectPoints.push_back( vertex ); param->intersectPoints.push_back( boost::shared_array<GLdouble>( vertex ) );
memcpy( vertex, coords, 3 * sizeof(GLdouble) ); memcpy( vertex, coords, 3 * sizeof(GLdouble) );
...@@ -1036,7 +1020,7 @@ void CALLBACK CombineCallback( GLdouble coords[3], ...@@ -1036,7 +1020,7 @@ void CALLBACK CombineCallback( GLdouble coords[3],
} }
void CALLBACK EdgeCallback() void CALLBACK EdgeCallback( GLboolean aEdgeFlag )
{ {
// This callback is needed to force GLU tesselator to use triangles only // This callback is needed to force GLU tesselator to use triangles only
} }
...@@ -1056,5 +1040,5 @@ void InitTesselatorCallbacks( GLUtesselator* aTesselator ) ...@@ -1056,5 +1040,5 @@ void InitTesselatorCallbacks( GLUtesselator* aTesselator )
gluTessCallback( aTesselator, GLU_TESS_VERTEX_DATA, ( void (CALLBACK*)() )VertexCallback ); gluTessCallback( aTesselator, GLU_TESS_VERTEX_DATA, ( void (CALLBACK*)() )VertexCallback );
gluTessCallback( aTesselator, GLU_TESS_COMBINE_DATA, ( void (CALLBACK*)() )CombineCallback ); gluTessCallback( aTesselator, GLU_TESS_COMBINE_DATA, ( void (CALLBACK*)() )CombineCallback );
gluTessCallback( aTesselator, GLU_TESS_EDGE_FLAG, ( void (CALLBACK*)() )EdgeCallback ); gluTessCallback( aTesselator, GLU_TESS_EDGE_FLAG, ( void (CALLBACK*)() )EdgeCallback );
gluTessCallback( aTesselator, GLU_TESS_ERROR_DATA, ( void (CALLBACK*)() )ErrorCallback ); gluTessCallback( aTesselator, GLU_TESS_ERROR, ( void (CALLBACK*)() )ErrorCallback );
} }
...@@ -47,11 +47,15 @@ ...@@ -47,11 +47,15 @@
#include <memory> #include <memory>
#include <map> #include <map>
#include <boost/smart_ptr/shared_ptr.hpp> #include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/shared_array.hpp>
#include <stdlib.h> #include <stdlib.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#ifndef CALLBACK
#define CALLBACK
#endif
namespace KiGfx namespace KiGfx
{ {
...@@ -244,8 +248,10 @@ public: ...@@ -244,8 +248,10 @@ public:
///< Parameters passed to the GLU tesselator ///< Parameters passed to the GLU tesselator
typedef struct typedef struct
{ {
VERTEX_MANAGER* vboManager; ///< VERTEX_ITEM for storing new vertices /// Manager used for storing new vertices
std::vector<GLdouble*>& intersectPoints; ///< Intersect points, that have to be freed VERTEX_MANAGER* vboManager;
/// Intersect points, that have to be freed after tessellation
std::deque< boost::shared_array<GLdouble> >& intersectPoints;
} TessParams; } TessParams;
protected: protected:
...@@ -294,37 +300,10 @@ private: ...@@ -294,37 +300,10 @@ private:
bool isGrouping; ///< Was a group started? bool isGrouping; ///< Was a group started?
// Polygon tesselation // Polygon tesselation
GLUtesselator* tesselator; ///< Pointer to the tesselator /// The tessellator
std::vector<GLdouble*> tessIntersects; ///< Storage of intersecting points GLUtesselator* tesselator;
/// Storage for intersecting points
// Structure used for tesselation of polygons std::deque< boost::shared_array<GLdouble> > tessIntersects;
struct OGLPOINT
{
OGLPOINT() :
x( 0.0 ), y( 0.0 ), z( 0.0 )
{}
OGLPOINT( const char* fastest )
{
// do nothing for fastest speed, and keep inline
}
OGLPOINT( const VECTOR2D& aPoint ) :
x( aPoint.x ), y( aPoint.y ), z( 0.0 )
{}
OGLPOINT& operator=( const VECTOR2D& aPoint )
{
x = aPoint.x;
y = aPoint.y;
z = 0.0;
return *this;
}
GLdouble x;
GLdouble y;
GLdouble z;
};
/** /**
* @brief Draw a quad for the line. * @brief Draw a quad for the line.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment