Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
19b34480
Commit
19b34480
authored
Aug 02, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the tesselator, so now it works with Windows.
parent
5e474cf8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
70 deletions
+33
-70
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+16
-32
opengl_gal.h
include/gal/opengl/opengl_gal.h
+17
-38
No files found.
common/gal/opengl/opengl_gal.cpp
View file @
19b34480
...
...
@@ -37,10 +37,6 @@
#include <limits>
#ifndef CALLBACK
#define CALLBACK
#endif
using
namespace
KiGfx
;
// Prototypes
...
...
@@ -92,6 +88,10 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
// Tesselator initialization
tesselator
=
gluNewTess
();
InitTesselatorCallbacks
(
tesselator
);
if
(
tesselator
==
NULL
)
{
wxLogFatalError
(
wxT
(
"Could not create the tesselator"
)
);
}
gluTessProperty
(
tesselator
,
GLU_TESS_WINDING_RULE
,
GLU_TESS_WINDING_POSITIVE
);
}
...
...
@@ -471,41 +471,25 @@ void OPENGL_GAL::DrawPolygon( const std::deque<VECTOR2D>& aPointList )
// for this purpose the GLU standard functions are used
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
};
gluTessBeginPolygon
(
tesselator
,
&
params
);
gluTessBeginContour
(
tesselator
);
// use operator=( const POINTS& )
copy
(
aPointList
.
begin
(),
aPointList
.
end
(),
vertexList
.
begin
()
);
for
(
OGLPOINTS
::
iterator
it
=
vertexList
.
begin
();
it
!=
vertexList
.
end
();
it
++
)
boost
::
shared_array
<
GLdouble
>
points
(
new
GLdouble
[
3
*
aPointList
.
size
()]
);
int
v
=
0
;
for
(
std
::
deque
<
VECTOR2D
>::
const_iterator
it
=
aPointList
.
begin
();
it
!=
aPointList
.
end
();
it
++
)
{
it
->
z
=
layerDepth
;
gluTessVertex
(
tesselator
,
&
it
->
x
,
&
it
->
x
);
points
[
v
]
=
it
->
x
;
points
[
v
+
1
]
=
it
->
y
;
points
[
v
+
2
]
=
layerDepth
;
gluTessVertex
(
tesselator
,
&
points
[
v
],
&
points
[
v
]
);
v
+=
3
;
}
gluTessEndContour
(
tesselator
);
gluTessEndPolygon
(
tesselator
);
// 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
();
// vertexList destroyed here
...
...
@@ -1028,7 +1012,7 @@ void CALLBACK CombineCallback( GLdouble coords[3],
OPENGL_GAL
::
TessParams
*
param
=
static_cast
<
OPENGL_GAL
::
TessParams
*>
(
aData
);
// 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
)
);
...
...
@@ -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
}
...
...
@@ -1056,5 +1040,5 @@ void InitTesselatorCallbacks( GLUtesselator* aTesselator )
gluTessCallback
(
aTesselator
,
GLU_TESS_VERTEX_DATA
,
(
void
(
CALLBACK
*
)()
)
VertexCallback
);
gluTessCallback
(
aTesselator
,
GLU_TESS_COMBINE_DATA
,
(
void
(
CALLBACK
*
)()
)
CombineCallback
);
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
);
}
include/gal/opengl/opengl_gal.h
View file @
19b34480
...
...
@@ -47,11 +47,15 @@
#include <memory>
#include <map>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/shared_array.hpp>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#ifndef CALLBACK
#define CALLBACK
#endif
namespace
KiGfx
{
...
...
@@ -244,8 +248,10 @@ public:
///< Parameters passed to the GLU tesselator
typedef
struct
{
VERTEX_MANAGER
*
vboManager
;
///< VERTEX_ITEM for storing new vertices
std
::
vector
<
GLdouble
*>&
intersectPoints
;
///< Intersect points, that have to be freed
/// Manager used for storing new vertices
VERTEX_MANAGER
*
vboManager
;
/// Intersect points, that have to be freed after tessellation
std
::
deque
<
boost
::
shared_array
<
GLdouble
>
>&
intersectPoints
;
}
TessParams
;
protected
:
...
...
@@ -294,37 +300,10 @@ private:
bool
isGrouping
;
///< Was a group started?
// Polygon tesselation
GLUtesselator
*
tesselator
;
///< Pointer to the tesselator
std
::
vector
<
GLdouble
*>
tessIntersects
;
///< Storage of intersecting points
// Structure used for tesselation of polygons
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
;
};
/// The tessellator
GLUtesselator
*
tesselator
;
/// Storage for intersecting points
std
::
deque
<
boost
::
shared_array
<
GLdouble
>
>
tessIntersects
;
/**
* @brief Draw a quad for the line.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment