Skip to content

Commit 97c6d61

Browse files
committed
separate sphere generation from drawing
1 parent 438b688 commit 97c6d61

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

lib/PDL/Graphics/OpenGLQ.pd

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,18 @@ pp_addhdr('
6060
my @internal = (Doc => 'internal', NoPthread => 1);
6161

6262
pp_def(
63-
'gl_spheres',
63+
'gl_sphere',
6464
GenericTypes => $F,
65-
Pars => 'coords(tri=3,n);
66-
float [t] vertices(tri,nVert=CALC(calc_nVert($COMP(slices),$COMP(stacks))));
67-
float [t] normals(tri,nVert);
68-
uint [t] stripIdx(nIdx=CALC(calc_nIdx($COMP(slices),$COMP(stacks))));',
65+
Pars => '
66+
[o] vertices(tri=3,nVert=CALC(calc_nVert($COMP(slices),$COMP(stacks))));
67+
[o] normals(tri,nVert);
68+
uint [o] stripIdx(nIdx=CALC(calc_nIdx($COMP(slices),$COMP(stacks))));',
6969
OtherPars => 'float radius; int slices; int stacks;',
7070
CHeader => <<'EOF',
7171
char *fghGenerateSphere(GLfloat radius, GLint slices, GLint stacks, GLfloat *vertices, GLfloat *normals, int nVert);
7272
void calc_strip_idx(GLuint *stripIdx, GLint slices, GLint stacks, int nVert);
7373
int calc_nVert(GLint slices, GLint stacks);
7474
int calc_nIdx(GLint slices, GLint stacks);
75-
int calc_numVertIdxsPerPart(GLint slices);
7675
EOF
7776
Code => <<'EOF',
7877
/* Generate vertices and normals */
@@ -83,6 +82,19 @@ if (err) $CROAK("%s", err);
8382
* strip.
8483
*/
8584
calc_strip_idx($P(stripIdx), $COMP(slices), $COMP(stacks), $SIZE(nVert));
85+
EOF
86+
@internal
87+
);
88+
89+
pp_def(
90+
'gl_spheres',
91+
GenericTypes => $F,
92+
Pars => 'coords(tri=3,n); vertices(tri,nVert); normals(tri,nVert); uint stripIdx(nIdx);',
93+
OtherPars => 'int slices; int stacks;',
94+
CHeader => <<'EOF',
95+
int calc_numVertIdxsPerPart(GLint slices);
96+
EOF
97+
Code => <<'EOF',
8698
glEnableClientState(GL_VERTEX_ARRAY);
8799
glEnableClientState(GL_NORMAL_ARRAY);
88100
glVertexPointer(3, GL_FLOAT, 0, $P(vertices));

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,22 @@ sub PDL::Graphics::TriD::Lines::primitive {OpenGL::Modern::GL_LINES}
302302
{ package PDL::Graphics::TriD::Spheres;
303303
use OpenGL::Modern qw(glShadeModel GL_SMOOTH);
304304
use PDL::Graphics::OpenGLQ;
305+
my %SPHERE;
306+
my @KEYS = qw(vertices normals idx);
307+
sub togl_setup {
308+
my ($this,$points) = @_;
309+
print "togl_setup $this\n" if $PDL::Graphics::TriD::verbose;
310+
if (!keys %SPHERE) {
311+
@SPHERE{@KEYS} = gl_sphere(0.025, 15, 15);
312+
}
313+
@{ $this->{Impl} }{@KEYS} = @SPHERE{@KEYS};
314+
}
305315
sub gdraw {
306-
my($this,$points) = @_;
307-
glShadeModel(GL_SMOOTH);
308-
PDL::gl_spheres($points, 0.025, 15, 15);
316+
my($this,$points) = @_;
317+
$this->togl_bind;
318+
glShadeModel(GL_SMOOTH);
319+
PDL::gl_spheres($points, @{ $this->{Impl} }{@KEYS}, 15, 15);
320+
$this->togl_unbind;
309321
}
310322
}
311323

0 commit comments

Comments
 (0)