idal.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python
  2. # create win32 source for OpenAL on-demand loading from AL API definitions
  3. # a set of defines al* -> idal*
  4. # typedefs and code pointer functions definition
  5. # 1: get linking with no OpenAL DLL link in anymore
  6. # i.e. have the defines and the code pointer working
  7. # 2: do the load code
  8. import time
  9. funcs = [
  10. [ 'ALenum', 'alGetError', 'ALvoid' ],
  11. [ 'ALvoid', 'alGenBuffers', 'ALsizei', 'ALuint *' ],
  12. [ 'ALboolean', 'alIsSource', 'ALuint' ],
  13. [ 'ALvoid', 'alSourceStop', 'ALuint' ],
  14. [ 'ALvoid', 'alGetSourcei', 'ALuint', 'ALenum', 'ALint *' ],
  15. [ 'ALint', 'alGetInteger', 'ALenum' ],
  16. [ 'ALCvoid', 'alcSuspendContext', 'ALCcontext *' ],
  17. [ 'ALCboolean', 'alcMakeContextCurrent', 'ALCcontext *' ],
  18. [ 'ALCvoid', 'alcProcessContext', 'ALCcontext *' ],
  19. [ 'ALCvoid', 'alcDestroyContext', 'ALCcontext *' ],
  20. [ 'ALCubyte *', 'alcGetString', 'ALCdevice *', 'ALCenum' ],
  21. [ 'ALvoid', 'alBufferData', 'ALuint', 'ALenum', 'ALvoid *', 'ALsizei', 'ALsizei' ],
  22. [ 'ALvoid', 'alDeleteBuffers', 'ALsizei', 'ALuint *' ],
  23. [ 'ALboolean', 'alIsExtensionPresent', 'ALubyte *' ],
  24. [ 'ALvoid', 'alDeleteSources', 'ALsizei', 'ALuint *' ],
  25. [ 'ALenum', 'alGetEnumValue', 'ALubyte *' ],
  26. [ 'ALvoid *', 'alGetProcAddress', 'ALubyte *' ],
  27. [ 'ALCcontext *', 'alcCreateContext', 'ALCdevice *', 'ALCint *' ],
  28. [ 'ALCdevice *', 'alcOpenDevice', 'ALubyte *' ],
  29. [ 'ALvoid', 'alListenerfv', 'ALenum', 'ALfloat*' ],
  30. [ 'ALvoid', 'alSourceQueueBuffers', 'ALuint', 'ALsizei', 'ALuint *' ],
  31. [ 'ALvoid', 'alSourcei', 'ALuint', 'ALenum', 'ALint' ],
  32. [ 'ALvoid', 'alListenerf', 'ALenum', 'ALfloat' ],
  33. [ 'ALCvoid', 'alcCloseDevice', 'ALCdevice *' ],
  34. [ 'ALboolean', 'alIsBuffer', 'ALuint' ],
  35. [ 'ALvoid', 'alSource3f', 'ALuint', 'ALenum', 'ALfloat', 'ALfloat', 'ALfloat' ],
  36. [ 'ALvoid', 'alGenSources', 'ALsizei', 'ALuint *' ],
  37. [ 'ALvoid', 'alSourcef', 'ALuint', 'ALenum', 'ALfloat' ],
  38. [ 'ALvoid', 'alSourceUnqueueBuffers', 'ALuint', 'ALsizei', 'ALuint *' ],
  39. [ 'ALvoid', 'alSourcePlay', 'ALuint' ],
  40. ]
  41. def warningHeader( f ):
  42. f.write( '// generated header. do not edit\n' )
  43. f.write( '// ' + __file__ + '\n' )
  44. f.write( '// ' + time.asctime() + '\n\n' )
  45. def genIDALFunc( f, declare ):
  46. if ( declare ):
  47. extern = 'extern '
  48. else:
  49. extern = ''
  50. for func in funcs:
  51. f.write( extern + func[0] + ' ( ALAPIENTRY * id' + func[1] + ' )( ' )
  52. i = 2
  53. while ( i < len( func ) ):
  54. if ( i != 2 ):
  55. f.write( ', ' )
  56. f.write( func[i] )
  57. i += 1
  58. if ( declare ):
  59. f.write( ' );\n' )
  60. else:
  61. f.write( ' ) = NULL;\n' )
  62. def genDefineMapping( f ):
  63. for func in funcs:
  64. fname = func[1]
  65. f.write( '#define %s id%s\n' % ( fname, fname ) )
  66. def genIDALInit( f ):
  67. for func in funcs:
  68. # annoying casting
  69. cast = func[0] + ' ( ALAPIENTRY * ) ( '
  70. i = 2
  71. while ( i < len( func ) ):
  72. if ( i != 2 ):
  73. cast += ', '
  74. cast += func[i]
  75. i += 1
  76. cast += ' )'
  77. # function
  78. f.write( 'id' + func[1] + ' = ( ' + cast + ' )GetProcAddress( h, "' + func[1] + '" );\n' )
  79. f.write( 'if ( !id' + func[1] + ') {\n return "' + func[1] + '";\n}\n' )
  80. if __name__ == '__main__':
  81. f = open( 'idal.h', 'w' )
  82. warningHeader( f )
  83. genIDALFunc( f, True )
  84. f.write( '\n' )
  85. genDefineMapping( f )
  86. f.close()
  87. f = open( 'idal.cpp', 'w' )
  88. warningHeader( f )
  89. genIDALFunc( f, False )
  90. f.write( '\n' );
  91. f.write( 'const char* InitializeIDAL( HMODULE h ) {\n' )
  92. genIDALInit( f )
  93. f.write( 'return NULL;\n' );
  94. f.write( '};\n' )
  95. f.close()