Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
pogl_glut.xs view on Meta::CPAN
static AV * glut_handlers = 0;
/* Attach a handler to a window */
static void set_glut_win_handler(int win, int type, SV * data)
{
SV ** h;
AV * a;
if (!glut_handlers)
glut_handlers = newAV();
h = av_fetch(glut_handlers, win, FALSE);
if (!h) {
a = newAV();
av_store(glut_handlers, win, newRV_inc((SV*)a));
SvREFCNT_dec(a);
} else if (!SvOK(*h) || !SvROK(*h))
croak("Unable to establish glut handler");
else
a = (AV*)SvRV(*h);
av_store(a, type, newRV_inc(data));
SvREFCNT_dec(data);
}
/* Get a window's handler */
static SV * get_glut_win_handler(int win, int type)
{
SV ** h;
if (!glut_handlers)
croak("Unable to locate glut handler");
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Unable to locate glut handler");
h = av_fetch((AV*)SvRV(*h), type, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Unable to locate glut handler");
return SvRV(*h);
}
/* Release a window's handlers */
static void destroy_glut_win_handlers(int win)
{
SV ** h;
if (!glut_handlers)
return;
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
return;
av_store(glut_handlers, win, newSVsv(&PL_sv_undef));
}
/* Release a handler */
static void destroy_glut_win_handler(int win, int type)
{
SV ** h;
AV * a;
if (!glut_handlers)
glut_handlers = newAV();
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
return;
a = (AV*)SvRV(*h);
av_store(a, type, newSVsv(&PL_sv_undef));
}
/* Begin window callback definition */
#define begin_decl_gwh(type, params, nparam) \
\
static void generic_glut_ ## type ## _handler params \
{ \
int win = glutGetWindow(); \
AV * handler_data = (AV*)get_glut_win_handler(win, HANDLE_GLUT_ ## type);\
SV * handler; \
int i; \
dSP; \
\
handler = *av_fetch(handler_data, 0, 0); \
\
GLUT_PUSHMARK(sp); \
GLUT_EXTEND_STACK(sp,av_len(handler_data)+nparam); \
for (i=1;i<=av_len(handler_data);i++) \
GLUT_PUSH_NEW_SV(*av_fetch(handler_data, i, 0));
/* End window callback definition */
#define end_decl_gwh() \
PUTBACK; \
DO_perl_call_sv(handler, G_DISCARD); \
}
/* Activate a window callback handler */
#define decl_gwh_xs(type) \
{ \
int win = glutGetWindow(); \
\
if (!handler || !SvOK(handler)) { \
destroy_glut_win_handler(win, HANDLE_GLUT_ ## type);\
glut ## type ## Func(NULL); \
} else { \
AV * handler_data = newAV(); \
\
PackCallbackST(handler_data, 0); \
\
set_glut_win_handler(win, HANDLE_GLUT_ ## type, (SV*)handler_data);\
\
glut ## type ## Func(generic_glut_ ## type ## _handler);\
} \
ENSURE_callback_thread;}
/* Activate a window callback handler; die on failure */
#define decl_gwh_xs_nullfail(type, fail) \
{ \
int win = glutGetWindow(); \
\
if (!handler || !SvOK(handler)) { \
croak fail; \
} else { \
AV * handler_data = newAV(); \
\
PackCallbackST(handler_data, 0); \
\
set_glut_win_handler(win, HANDLE_GLUT_ ## type, (SV*)handler_data);\
\
glut ## type ## Func(generic_glut_ ## type ## _handler);\
pogl_glut.xs view on Meta::CPAN
#//# glutPostOverlayRedisplay();
void
glutPostOverlayRedisplay()
#//# glutShowOverlay();
void
glutShowOverlay()
#//# glutHideOverlay();
void
glutHideOverlay()
#endif
# Menus
#//# $ID = glutCreateMenu(\&callback);
int
glutCreateMenu(handler=0, ...)
SV * handler
CODE:
{
if (!handler || !SvOK(handler)) {
croak("A handler must be specified");
} else {
AV * handler_data = newAV();
PackCallbackST(handler_data, 0);
RETVAL = glutCreateMenu(generic_glut_menu_handler);
if (!glut_menu_handlers)
glut_menu_handlers = newAV();
av_store(glut_menu_handlers, RETVAL, newRV_inc((SV*)handler_data));
SvREFCNT_dec(handler_data);
}
}
OUTPUT:
RETVAL
#//# glutSetMenu($menu);
void
glutSetMenu(menu)
int menu
#//# glutGetMenu();
int
glutGetMenu()
#//# glutDestroyMenu($menu);
void
glutDestroyMenu(menu)
int menu
CODE:
{
glutDestroyMenu(menu);
av_store(glut_menu_handlers, menu, newSVsv(&PL_sv_undef));
}
#//# glutAddMenuEntry($name, $value);
void
glutAddMenuEntry(name, value)
char * name
int value
#//# glutAddSubMenu($name, $menu);
void
glutAddSubMenu(name, menu)
char * name
int menu
#//# glutChangeToMenuEntry($entry, $name, $value);
void
glutChangeToMenuEntry(entry, name, value)
int entry
char * name
int value
#//# glutChangeToSubMenu($entry, $name, $menu);
void
glutChangeToSubMenu(entry, name, menu)
int entry
char * name
int menu
#//# glutRemoveMenuItem($entry);
void
glutRemoveMenuItem(entry)
int entry
#//# glutAttachMenu(button);
void
glutAttachMenu(button)
int button
#//# glutDetachMenu(button);
void
glutDetachMenu(button)
int button
# Callbacks
#//# glutDisplayFunc(\&callback);
void
glutDisplayFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs_nullfail(Display, ("Display function must be specified"))
#if GLUT_API_VERSION >= 3
#//# glutOverlayDisplayFunc(\&callback);
void
glutOverlayDisplayFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(OverlayDisplay)
( run in 0.888 second using v1.01-cache-2.11-cpan-d80b1682f3f )