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
b0c1b97f
Commit
b0c1b97f
authored
Jul 17, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed stroked circles width issue with OpenGL shaders.
parent
aa6a5ab6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
22 deletions
+24
-22
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+12
-9
shader.frag
common/gal/opengl/shader.frag
+6
-6
shader.vert
common/gal/opengl/shader.vert
+6
-7
No files found.
common/gal/opengl/opengl_gal.cpp
View file @
b0c1b97f
...
...
@@ -795,7 +795,7 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
aCenterPoint
.
y
-
aRadius
,
layerDepth
);
// v0
setShader
(
SHADER_FILLED_CIRCLE
,
2.0
);
vertex3
(
aCenterPoint
.
x
+
aRadius
*
sqrt
(
3.0
f
),
vertex3
(
aCenterPoint
.
x
+
aRadius
*
sqrt
(
3.0
f
),
aCenterPoint
.
y
-
aRadius
,
layerDepth
);
// v1
setShader
(
SHADER_FILLED_CIRCLE
,
3.0
);
...
...
@@ -816,16 +816,17 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
//\\
v0 /_\/_\ v1
*/
double
outerRadius
=
aRadius
+
(
lineWidth
/
2
);
setShader
(
SHADER_STROKED_CIRCLE
,
1.0
,
aRadius
,
lineWidth
);
vertex3
(
aCenterPoint
.
x
-
a
Radius
*
sqrt
(
3.0
f
),
aCenterPoint
.
y
-
a
Radius
,
layerDepth
);
// v0
vertex3
(
aCenterPoint
.
x
-
outer
Radius
*
sqrt
(
3.0
f
),
aCenterPoint
.
y
-
outer
Radius
,
layerDepth
);
// v0
setShader
(
SHADER_STROKED_CIRCLE
,
2.0
,
aRadius
,
lineWidth
);
vertex3
(
aCenterPoint
.
x
+
a
Radius
*
sqrt
(
3.0
f
),
aCenterPoint
.
y
-
a
Radius
,
layerDepth
);
// v1
vertex3
(
aCenterPoint
.
x
+
outer
Radius
*
sqrt
(
3.0
f
),
aCenterPoint
.
y
-
outer
Radius
,
layerDepth
);
// v1
setShader
(
SHADER_STROKED_CIRCLE
,
3.0
,
aRadius
,
lineWidth
);
vertex3
(
aCenterPoint
.
x
,
aCenterPoint
.
y
+
a
Radius
*
2.0
f
,
layerDepth
);
// v2
vertex3
(
aCenterPoint
.
x
,
aCenterPoint
.
y
+
outer
Radius
*
2.0
f
,
layerDepth
);
// v2
}
return
;
...
...
@@ -964,6 +965,8 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
{
if
(
isUseShader
)
{
double
outerRadius
=
aRadius
+
(
lineWidth
/
2
);
Save
();
Translate
(
aCenterPoint
);
Rotate
(
aAngle
);
...
...
@@ -979,13 +982,13 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
v0 //__\\ v1
*/
setShader
(
SHADER_STROKED_CIRCLE
,
4.0
f
,
aRadius
,
lineWidth
);
vertex3
(
-
a
Radius
*
3.0
f
/
sqrt
(
3.0
f
),
0.0
f
,
layerDepth
);
// v0
vertex3
(
-
outer
Radius
*
3.0
f
/
sqrt
(
3.0
f
),
0.0
f
,
layerDepth
);
// v0
setShader
(
SHADER_STROKED_CIRCLE
,
5.0
f
,
aRadius
,
lineWidth
);
vertex3
(
a
Radius
*
3.0
f
/
sqrt
(
3.0
f
),
0.0
f
,
layerDepth
);
// v1
vertex3
(
outer
Radius
*
3.0
f
/
sqrt
(
3.0
f
),
0.0
f
,
layerDepth
);
// v1
setShader
(
SHADER_STROKED_CIRCLE
,
6.0
f
,
aRadius
,
lineWidth
);
vertex3
(
0.0
f
,
a
Radius
*
2.0
f
,
layerDepth
);
// v2
vertex3
(
0.0
f
,
outer
Radius
*
2.0
f
,
layerDepth
);
// v2
Restore
();
}
...
...
common/gal/opengl/shader.frag
View file @
b0c1b97f
...
...
@@ -27,9 +27,9 @@
#version 120
// Shader types
const
float
SHADER_LINE
=
1
.
0
;
const
float
SHADER_FILLED_CIRCLE
=
2
.
0
;
const
float
SHADER_STROKED_CIRCLE
=
3
.
0
;
const
float
SHADER_LINE
=
1
.
0
f
;
const
float
SHADER_FILLED_CIRCLE
=
2
.
0
f
;
const
float
SHADER_STROKED_CIRCLE
=
3
.
0
f
;
varying
vec4
shaderParams
;
varying
vec2
circleCoords
;
...
...
@@ -45,11 +45,11 @@ void filledCircle( vec2 aCoord )
void
strokedCircle
(
vec2
aCoord
,
float
aRadius
,
float
aWidth
)
{
float
outerRadius
=
aRadius
;
float
innerRadius
=
aRadius
-
aWidth
;
float
outerRadius
=
aRadius
+
(
aWidth
/
2
)
;
float
innerRadius
=
aRadius
-
(
aWidth
/
2
)
;
float
relWidth
=
innerRadius
/
outerRadius
;
if
(
(
dot
(
aCoord
,
aCoord
)
<
1
.
0
)
&&
if
(
(
dot
(
aCoord
,
aCoord
)
<
1
.
0
f
)
&&
(
dot
(
aCoord
,
aCoord
)
>
relWidth
*
relWidth
)
)
gl_FragColor
=
gl_Color
;
else
...
...
common/gal/opengl/shader.vert
View file @
b0c1b97f
...
...
@@ -27,12 +27,12 @@
#version 120
// Shader types
const
float
SHADER_LINE
=
1
.
0
;
const
float
SHADER_FILLED_CIRCLE
=
2
.
0
;
const
float
SHADER_STROKED_CIRCLE
=
3
.
0
;
const
float
SHADER_LINE
=
1
.
0
f
;
const
float
SHADER_FILLED_CIRCLE
=
2
.
0
f
;
const
float
SHADER_STROKED_CIRCLE
=
3
.
0
f
;
// Minimum line width
const
float
MIN_WIDTH
=
1
.
0
;
const
float
MIN_WIDTH
=
1
.
0
f
;
attribute
vec4
attrShaderParams
;
varying
vec4
shaderParams
;
...
...
@@ -51,9 +51,9 @@ void main()
// Make lines appear to be at least 1 pixel wide
if
(
worldScale
*
lineWidth
<
MIN_WIDTH
)
scale
=
1
.
0
/
(
worldScale
*
lineWidth
);
scale
=
1
.
0
f
/
(
worldScale
*
lineWidth
);
else
scale
=
1
.
0
;
scale
=
1
.
0
f
;
gl_Position
=
gl_ModelViewProjectionMatrix
*
(
gl_Vertex
+
vec4
(
shaderParams
.
yz
*
scale
,
0
.
0
,
0
.
0
)
);
...
...
@@ -81,7 +81,6 @@ void main()
// Make the line appear to be at least 1 pixel wide
float
lineWidth
=
shaderParams
[
3
];
float
worldScale
=
gl_ModelViewMatrix
[
0
][
0
];
float
scale
;
// Make lines appear to be at least 1 pixel width
if
(
worldScale
*
lineWidth
<
MIN_WIDTH
)
...
...
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