/* * opengl.c - OpenGL binding for zsh * * This file is *not* part of zsh, the Z shell. * * Copyright (c) 2008 Johann "Myrkraverk" Oskarsson * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and to distribute modified versions of this software for any * purpose, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * In no event shall Johann Oskarsson be liable to any party for * direct, indirect, special, incidental, or consequential damages * arising out of the use of this software and its documentation, even * if Johann Oskarsson has been advised of the possibility of such * damage. * * Johann Oskarsson specifically disclaims any warranties, including, * but not limited to, the implied warranties of merchantability and * fitness for a particular purpose. The software provided hereunder * is on an "as is" basis, and Johann Oskarsson has no obligation to * provide maintenance, support, updates, enhancements, or * modifications. * */ #include "opengl.mdh" #include "opengl.pro" #include #include "dispatch.h" // Function declaration(s) /* static int bin_generic( char *nam, char **args, Options ops, int func ); */ /* enum { */ /* FN_VOID, */ /* FN_STRING, */ /* FN_INT1, */ /* FN_INT2, */ /* FN_DOUBLE4, */ /* FN_DOUBLE6, */ /* FN_GLCLAMPF4, */ /* FN_GLENUM1, */ /* FN_GLBITFIELD1, */ /* FN_GLDOUBLE6, */ /* }; */ /* typedef struct { */ /* union { */ /* void (*fn_void)(void); */ /* void (*fn_string)(char *); */ /* void (*fn_int1)( int ); */ /* void (*fn_int2)( int, int ); */ /* void (*fn_double4)( double, double, double, double ); */ /* void (*fn_double6)( double, double, double, double, double, double ); */ /* void (*fn_GLclampf4)( GLclampf, GLclampf, GLclampf, GLclampf ); */ /* void (*fn_GLenum1)( GLenum ); */ /* void (*fn_GLbitfield1)( GLbitfield ); */ /* void (*fn_GLdouble6 )( GLdouble, GLdouble, GLdouble, */ /* GLdouble, GLdouble, GLdouble ); */ /* } fn; */ /* int fn_type; // parameter type */ /* int num_args; */ /* } functions; */ // NOTICE: fun_tab and bintab must be kept in sync. // Both tables keep a number of arguments the builtin expects // bintab's 6th argument refers to this table when using bin_generic static functions fun_tab[] = { // Function Pointer Type Enum #args { { .fn_void = glLoadIdentity }, FN_VOID, 0 }, // 0 { { .fn_GLclampf4 = glClearColor}, FN_GLCLAMPF4, 4 }, // 1 { { .fn_double4 = glColor4d }, FN_DOUBLE4, 4 }, // 2 { { .fn_double4 = glRectd }, FN_DOUBLE4, 4 }, // 3 { { .fn_GLenum1 = glMatrixMode }, FN_GLENUM1, 1 }, // 4 { { .fn_GLbitfield1 = glClear }, FN_GLBITFIELD1, 1 }, // 5 { { .fn_GLdouble6 = glOrtho }, FN_GLDOUBLE6, 6 }, // 6 }; static struct builtin bintab[] = { // fun_tab row ----------------------------------\ /-flags // max args ----------------------------------\ | | // min args -------------------------------v v v v BUILTIN( "glLoadIdentity", 0, bin_dispatch, 0, 0, 0, "", NULL ), BUILTIN( "glClearColor", 0, bin_dispatch, 4, 4, 1, "", NULL ), BUILTIN( "glColor", 0, bin_dispatch, 3, 4, 2, "", NULL ), BUILTIN( "glRect", 0, bin_dispatch, 4, 4, 3, "", NULL ), BUILTIN( "glMatrixMode", 0, bin_dispatch, 1, 1, 4, "", NULL ), BUILTIN( "glClear", 0, bin_dispatch, 1, 1, 5, "", NULL ), BUILTIN( "glOrtho", 0, bin_dispatch, 6, 6, 6, "", NULL ), }; /* parameters */ static zlong zsh_GL_PROJECTION; static zlong zsh_GL_COLOR_BUFFER_BIT; static struct paramdef patab[] = { PARAMDEF( "GL_PROJECTION", (PM_INTEGER | PM_READONLY), &zsh_GL_PROJECTION, NULL ), PARAMDEF( "GL_COLOR_BUFFER_BIT", (PM_INTEGER | PM_READONLY), &zsh_GL_COLOR_BUFFER_BIT, NULL ), }; static struct features module_features = { bintab, sizeof(bintab)/sizeof(*bintab), NULL, 0, /* cotab, sizeof(cotab)/sizeof(*cotab), */ NULL, 0, /* mftab, sizeof(mftab)/sizeof(*mftab), */ patab, sizeof(patab)/sizeof(*patab), 0 }; // /**/ /* static int */ /* bin_generic( char *nam, char **args, Options ops, int func ) */ /* { */ /* double d_args[4] = { 0.0, 0.0, 0.0, 0.0 }; */ /* mnumber mn_args[4] = { { { .l = 0 }, MN_UNSET }, */ /* { { .l = 0 }, MN_UNSET }, */ /* { { .l = 0 }, MN_UNSET }, */ /* { { .l = 0 }, MN_UNSET }, }; */ /* GLclampf fclamp_args[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; */ /* GLenum enum_args[1] = { 0 }; */ /* GLbitfield bf_args[ 1 ] = { 0 }; */ /* GLdouble GLd_args[ 6 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; */ /* for ( int i = 0; i < fun_tab[ func ].num_args; i++ ) */ /* { */ /* if ( args[ i ] ) */ /* { */ /* mnumber mn = matheval( args[ i ] ); */ /* switch ( fun_tab[ func ].fn_type ) */ /* { */ /* case FN_GLBITFIELD1: */ /* bf_args[ i ] = mn.u.l; break; */ /* case FN_GLENUM1: */ /* enum_args[ i ] = mn.u.l; break; */ /* case FN_GLCLAMPF4: */ /* fclamp_args[ i ] = mn.u.d; break; */ /* case FN_DOUBLE4: */ /* d_args[ i ] = mn.u.d; break; */ /* case FN_GLDOUBLE6: */ /* GLd_args[ i ] = mn.u.d; break; */ /* } */ /* } */ /* else // Currently this applies only to glColor: */ /* { // where the default 4th arg is 1.0 */ /* switch ( fun_tab[ func ].fn_type ) */ /* { */ /* case FN_DOUBLE4: */ /* d_args[ i ] = 1.0; break; */ /* } */ /* } */ /* } */ /* switch ( fun_tab[ func ].fn_type ) */ /* { */ /* case FN_VOID: */ /* fun_tab[ func ].fn.fn_void(); break; */ /* case FN_GLBITFIELD1: */ /* fun_tab[ func ].fn.fn_GLbitfield1( bf_args[ 0 ] ); break; */ /* case FN_GLENUM1: */ /* fun_tab[ func ].fn.fn_GLenum1( enum_args[ 0 ] ); break; */ /* case FN_GLCLAMPF4: */ /* fun_tab[ func ].fn.fn_GLclampf4( fclamp_args[ 0 ], */ /* fclamp_args[ 1 ], */ /* fclamp_args[ 2 ], */ /* fclamp_args[ 3 ] ); break; */ /* case FN_DOUBLE4: */ /* fun_tab[ func ].fn.fn_double4( d_args[ 0 ], */ /* d_args[ 1 ], */ /* d_args[ 2 ], */ /* d_args[ 3 ] ); break; */ /* case FN_GLDOUBLE6: */ /* fun_tab[ func ].fn.fn_GLdouble6( GLd_args[ 0 ], */ /* GLd_args[ 1 ], */ /* GLd_args[ 2 ], */ /* GLd_args[ 3 ], */ /* GLd_args[ 4 ], */ /* GLd_args[ 5 ] ); break; */ /* } */ /* } */ /**/ int setup_(UNUSED(Module m)) { return 0; } /**/ int features_(Module m, char ***features) { *features = featuresarray(m, &module_features); return 0; } /**/ int enables_(Module m, int **enables) { return handlefeatures(m, &module_features, enables); } /**/ int boot_(Module m) { zsh_GL_PROJECTION = GL_PROJECTION; zsh_GL_COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT; return 0; } /**/ int cleanup_(Module m) { return setfeatureenables(m, &module_features, NULL); } /**/ int finish_(UNUSED(Module m)) { return 0; }