glew2bmx.bmx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. Strict
  2. Framework brl.basic
  3. Import brl.map
  4. Rem
  5. Cheezy little app to convert glew.h to bmx source.
  6. Run this, then copy 'n' paste the output into opengl.bmx
  7. (everything <=glViewport) and glew.bmx (the rest!)
  8. End Rem
  9. Global in:TStream=ReadStream( "GL/glew.h" )
  10. Global curr:String,text:String
  11. Local funMap:TMap=New TMap
  12. Local constMap:TMap=New TMap
  13. While Not Eof(in)
  14. text=in.ReadLine()
  15. bump
  16. If curr="GLAPI"
  17. bump
  18. Local funty:String=gltype()
  19. If funty<>"x" And curr="GLAPIENTRY"
  20. Local id:String=bump()
  21. If id[..2]="gl" And bump()="("
  22. Local proto:String=glproto()
  23. If proto<>"x"
  24. Print "Function "+id+funty+"("+proto+")"
  25. EndIf
  26. EndIf
  27. EndIf
  28. Else If curr="#"
  29. If bump()="define"
  30. Local id:String=bump()
  31. If id[..11]="GL_VERSION_"
  32. Else If id[..3]="GL_"
  33. If Not constMap.ValueForKey(id)
  34. Local n:String=bump()
  35. If n[..2]="0x"
  36. Print "Const "+id+"=$"+n[2..]
  37. Else If n.length And isdigit(n[0]) And n<>"1"
  38. Print "Const "+id+"="+n
  39. EndIf
  40. constMap.Insert id,n
  41. EndIf
  42. Else If id[..5]="GLEW_"
  43. If bump()="GLEW_GET_VAR" And bump()="("
  44. Local sym:String=bump()
  45. If sym[..7]="__GLEW_" And bump()=")"
  46. Print "Global GL_"+id[5..]+":Byte=~q"+sym+"~q"
  47. EndIf
  48. EndIf
  49. Else If id[..2]="gl"
  50. If bump()="GLEW_GET_FUN" And bump()="("
  51. Local sym:String=bump()
  52. If sym[..6]="__glew" And bump()=")"
  53. Local key:String="PFNGL"+sym[6..].ToUpper()+"PROC"
  54. Local val:String=String( funMap.ValueForKey( key ) )
  55. If val
  56. Print "Global "+id+val+"=~q"+sym+"~q"
  57. Else
  58. Print "***** "+sym+" *****"
  59. EndIf
  60. EndIf
  61. EndIf
  62. EndIf
  63. EndIf
  64. Else If curr="typedef"
  65. bump
  66. Local funty:String=gltype()
  67. If funty<>"x" And curr="(" And bump()="GLAPIENTRY" And bump()="*"
  68. Local id:String=bump()
  69. If id[..5]="PFNGL" And bump()=")" And bump()="("
  70. Local proto:String=glproto()
  71. If proto<>"x"
  72. funMap.Insert id,funty+"("+proto+")"
  73. EndIf
  74. EndIf
  75. EndIf
  76. EndIf
  77. Wend
  78. in.Close
  79. Function glproto:String()
  80. If bump()=")" Return ""
  81. Local proto:String,err,argid
  82. Repeat
  83. Local argty:String=gltype()
  84. If argty="x" Return argty
  85. Local id:String
  86. If curr<>"," And curr<>")" And curr.length And (isalpha(curr[0]) Or curr[0]=Asc("_"))
  87. id:String=curr
  88. If bump()="["
  89. While bump()<>"]"
  90. Wend
  91. bump
  92. If Not argty argty="Byte"
  93. argty:+" Ptr"
  94. EndIf
  95. Else
  96. id="arg"+argid
  97. EndIf
  98. argid:+1
  99. If proto proto:+","
  100. proto:+id+"_"+argty
  101. If curr=")"
  102. bump
  103. If proto="arg0_" proto=""
  104. Return proto
  105. EndIf
  106. If curr<>"," Return "x"
  107. bump
  108. Forever
  109. End Function
  110. Function gltype:String()
  111. Local ty:String
  112. If curr="const"
  113. bump
  114. EndIf
  115. Select curr
  116. Case "void","GLvoid"
  117. ty=""
  118. Case "char","GLbyte","GLubyte","GLchar","GLboolean","GLcharARB"
  119. ty="Byte"
  120. Case "GLshort","GLushort","GLhalf"
  121. ty="Short"
  122. Case "GLint","GLuint","GLenum","GLsizei","GLbitfield"
  123. ty="Int"
  124. Case "GLintptr","GLsizeiptr","GLintptrARB","GLsizeiptrARB"
  125. ty="Int"
  126. Case "GLhandleARB"
  127. ty="Int"
  128. Case "GLint64EXT","GLuint64EXT"
  129. ty="Long"
  130. Case "GLfloat","GLclampf"
  131. ty="Float"
  132. Case "GLdouble","GLclampd"
  133. ty="Double"
  134. Default
  135. Return "x"
  136. End Select
  137. Repeat
  138. bump
  139. If curr="const" bump
  140. If curr<>"*" Exit
  141. If Not ty ty="Byte"
  142. ty:+" Ptr"
  143. Forever
  144. If ty ty=":"+ty
  145. Return ty
  146. End Function
  147. Function isalpha( c )
  148. Return (c>=Asc("A") And c<=Asc("Z")) Or (c>=Asc("a") And c<=Asc("z"))
  149. End Function
  150. Function isdigit( c )
  151. Return c>=Asc("0") And c<=Asc("9")
  152. End Function
  153. Function isalnum( c )
  154. Return isalpha(c) Or isdigit(c)
  155. End Function
  156. Function isxdigit( c )
  157. Return (c>=Asc("A") And c<=Asc("F")) Or (c>=Asc("a") And c<=Asc("f")) Or isdigit(c)
  158. End Function
  159. Function bump:String()
  160. Local i=0
  161. While i<text.length And text[i]<=Asc(" ")
  162. i:+1
  163. Wend
  164. If i=text.length
  165. curr=""
  166. text=""
  167. Return curr
  168. EndIf
  169. text=text[i..]
  170. Local c=text[0]
  171. i=1
  172. If isalpha(c) Or c=Asc("_")
  173. While i<text.length And (isalnum( text[i] ) Or text[i]=Asc("_"))
  174. i:+1
  175. Wend
  176. Else If c>=Asc("0") And c<=Asc("9")
  177. If i<text.length And c=Asc("0") And text[i]=Asc("x")
  178. i:+1
  179. While i<text.length And isxdigit(text[i])
  180. i:+1
  181. Wend
  182. Else
  183. While i<text.length And isdigit(text[i])
  184. i:+1
  185. Wend
  186. EndIf
  187. EndIf
  188. curr=text[..i]
  189. text=text[i..]
  190. Return curr
  191. End Function