gl_opengl.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. // +build !js
  2. package gl
  3. import (
  4. "log"
  5. "strings"
  6. "unsafe"
  7. "github.com/go-gl/gl/v2.1/gl"
  8. )
  9. // ContextWatcher is this library's context watcher, satisfying glfw.ContextWatcher interface.
  10. // It must be notified when context is made current or detached.
  11. var ContextWatcher = new(contextWatcher)
  12. type contextWatcher struct {
  13. initGL bool
  14. }
  15. func (cw *contextWatcher) OnMakeCurrent(context interface{}) {
  16. if !cw.initGL {
  17. // Initialise gl bindings using the current context.
  18. err := gl.Init()
  19. if err != nil {
  20. log.Fatalln("gl.Init:", err)
  21. }
  22. cw.initGL = true
  23. }
  24. }
  25. func (contextWatcher) OnDetach() {}
  26. // ActiveTexture sets the active texture unit.
  27. //
  28. // http://www.khronos.org/opengles/sdk/docs/man3/html/glActiveTexture.xhtml
  29. func ActiveTexture(texture Enum) {
  30. gl.ActiveTexture(uint32(texture))
  31. }
  32. // AttachShader attaches a shader to a program.
  33. //
  34. // http://www.khronos.org/opengles/sdk/docs/man3/html/glAttachShader.xhtml
  35. func AttachShader(p Program, s Shader) {
  36. gl.AttachShader(p.Value, s.Value)
  37. }
  38. // BindAttribLocation binds a vertex attribute index with a named
  39. // variable.
  40. //
  41. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindAttribLocation.xhtml
  42. func BindAttribLocation(p Program, a Attrib, name string) {
  43. gl.BindAttribLocation(p.Value, uint32(a.Value), gl.Str(name+"\x00"))
  44. }
  45. // BindBuffer binds a buffer.
  46. //
  47. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindBuffer.xhtml
  48. func BindBuffer(target Enum, b Buffer) {
  49. gl.BindBuffer(uint32(target), b.Value)
  50. }
  51. // BindFramebuffer binds a framebuffer.
  52. //
  53. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindFramebuffer.xhtml
  54. func BindFramebuffer(target Enum, fb Framebuffer) {
  55. gl.BindFramebuffer(uint32(target), fb.Value)
  56. }
  57. // BindRenderbuffer binds a render buffer.
  58. //
  59. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindRenderbuffer.xhtml
  60. func BindRenderbuffer(target Enum, rb Renderbuffer) {
  61. gl.BindRenderbuffer(uint32(target), rb.Value)
  62. }
  63. // BindTexture binds a texture.
  64. //
  65. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindTexture.xhtml
  66. func BindTexture(target Enum, t Texture) {
  67. gl.BindTexture(uint32(target), t.Value)
  68. }
  69. // BlendColor sets the blend color.
  70. //
  71. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendColor.xhtml
  72. func BlendColor(red, green, blue, alpha float32) {
  73. gl.BlendColor(red, green, blue, alpha)
  74. }
  75. // BlendEquation sets both RGB and alpha blend equations.
  76. //
  77. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquation.xhtml
  78. func BlendEquation(mode Enum) {
  79. gl.BlendEquation(uint32(mode))
  80. }
  81. // BlendEquationSeparate sets RGB and alpha blend equations separately.
  82. //
  83. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquationSeparate.xhtml
  84. func BlendEquationSeparate(modeRGB, modeAlpha Enum) {
  85. gl.BlendEquationSeparate(uint32(modeRGB), uint32(modeAlpha))
  86. }
  87. // BlendFunc sets the pixel blending factors.
  88. //
  89. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFunc.xhtml
  90. func BlendFunc(sfactor, dfactor Enum) {
  91. gl.BlendFunc(uint32(sfactor), uint32(dfactor))
  92. }
  93. // BlendFunc sets the pixel RGB and alpha blending factors separately.
  94. //
  95. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFuncSeparate.xhtml
  96. func BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum) {
  97. gl.BlendFuncSeparate(uint32(sfactorRGB), uint32(dfactorRGB), uint32(sfactorAlpha), uint32(dfactorAlpha))
  98. }
  99. // BlitFramebuffer copies a block of pixels from the read framebuffer to the draw framebuffer.
  100. //
  101. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlitFramebuffer.xhtml
  102. func BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1 int, mask, filter Enum) {
  103. gl.BlitFramebuffer(int32(srcX0), int32(srcY0), int32(srcX1), int32(srcY1), int32(dstX0), int32(dstY0), int32(dstX1), int32(dstY1), uint32(mask), uint32(filter))
  104. }
  105. // BufferData creates a new data store for the bound buffer object.
  106. //
  107. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml
  108. func BufferData(target Enum, src []byte, usage Enum) {
  109. gl.BufferData(uint32(target), int(len(src)), gl.Ptr(&src[0]), uint32(usage))
  110. }
  111. // BufferInit creates a new unitialized data store for the bound buffer object.
  112. //
  113. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml
  114. func BufferInit(target Enum, size int, usage Enum) {
  115. gl.BufferData(uint32(target), size, nil, uint32(usage))
  116. }
  117. // BufferSubData sets some of data in the bound buffer object.
  118. //
  119. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferSubData.xhtml
  120. func BufferSubData(target Enum, offset int, data []byte) {
  121. gl.BufferSubData(uint32(target), offset, int(len(data)), gl.Ptr(&data[0]))
  122. }
  123. // CheckFramebufferStatus reports the completeness status of the
  124. // active framebuffer.
  125. //
  126. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCheckFramebufferStatus.xhtml
  127. func CheckFramebufferStatus(target Enum) Enum {
  128. return Enum(gl.CheckFramebufferStatus(uint32(target)))
  129. }
  130. // Clear clears the window.
  131. //
  132. // The behavior of Clear is influenced by the pixel ownership test,
  133. // the scissor test, dithering, and the buffer writemasks.
  134. //
  135. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClear.xhtml
  136. func Clear(mask Enum) {
  137. gl.Clear(uint32(mask))
  138. }
  139. // ClearColor specifies the RGBA values used to clear color buffers.
  140. //
  141. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearColor.xhtml
  142. func ClearColor(red, green, blue, alpha float32) {
  143. gl.ClearColor(red, green, blue, alpha)
  144. }
  145. // ClearDepthf sets the depth value used to clear the depth buffer.
  146. //
  147. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearDepthf.xhtml
  148. func ClearDepthf(d float32) {
  149. gl.ClearDepthf(d)
  150. }
  151. // ClearStencil sets the index used to clear the stencil buffer.
  152. //
  153. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearStencil.xhtml
  154. func ClearStencil(s int) {
  155. gl.ClearStencil(int32(s))
  156. }
  157. // ColorMask specifies whether color components in the framebuffer
  158. // can be written.
  159. //
  160. // http://www.khronos.org/opengles/sdk/docs/man3/html/glColorMask.xhtml
  161. func ColorMask(red, green, blue, alpha bool) {
  162. gl.ColorMask(red, green, blue, alpha)
  163. }
  164. // CompileShader compiles the source code of s.
  165. //
  166. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompileShader.xhtml
  167. func CompileShader(s Shader) {
  168. gl.CompileShader(s.Value)
  169. }
  170. // CompressedTexImage2D writes a compressed 2D texture.
  171. //
  172. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexImage2D.xhtml
  173. func CompressedTexImage2D(target Enum, level int, internalformat Enum, width, height, border int, data []byte) {
  174. gl.CompressedTexImage2D(uint32(target), int32(level), uint32(internalformat), int32(width), int32(height), int32(border), int32(len(data)), gl.Ptr(data))
  175. }
  176. // CompressedTexSubImage2D writes a subregion of a compressed 2D texture.
  177. //
  178. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexSubImage2D.xhtml
  179. func CompressedTexSubImage2D(target Enum, level, xoffset, yoffset, width, height int, format Enum, data []byte) {
  180. gl.CompressedTexSubImage2D(uint32(target), int32(level), int32(xoffset), int32(yoffset), int32(width), int32(height), uint32(format), int32(len(data)), gl.Ptr(data))
  181. }
  182. // CopyTexImage2D writes a 2D texture from the current framebuffer.
  183. //
  184. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexImage2D.xhtml
  185. func CopyTexImage2D(target Enum, level int, internalformat Enum, x, y, width, height, border int) {
  186. gl.CopyTexImage2D(uint32(target), int32(level), uint32(internalformat), int32(x), int32(y), int32(width), int32(height), int32(border))
  187. }
  188. // CopyTexSubImage2D writes a 2D texture subregion from the
  189. // current framebuffer.
  190. //
  191. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexSubImage2D.xhtml
  192. func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) {
  193. gl.CopyTexSubImage2D(uint32(target), int32(level), int32(xoffset), int32(yoffset), int32(x), int32(y), int32(width), int32(height))
  194. }
  195. // CreateBuffer creates a buffer object.
  196. //
  197. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml
  198. func CreateBuffer() Buffer {
  199. var b Buffer
  200. gl.GenBuffers(1, &b.Value)
  201. return b
  202. }
  203. // CreateFramebuffer creates a framebuffer object.
  204. //
  205. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenFramebuffers.xhtml
  206. func CreateFramebuffer() Framebuffer {
  207. var b Framebuffer
  208. gl.GenFramebuffers(1, &b.Value)
  209. return b
  210. }
  211. // CreateProgram creates a new empty program object.
  212. //
  213. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateProgram.xhtml
  214. func CreateProgram() Program {
  215. return Program{Value: uint32(gl.CreateProgram())}
  216. }
  217. // CreateRenderbuffer create a renderbuffer object.
  218. //
  219. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenRenderbuffers.xhtml
  220. func CreateRenderbuffer() Renderbuffer {
  221. var b Renderbuffer
  222. gl.GenRenderbuffers(1, &b.Value)
  223. return b
  224. }
  225. // CreateShader creates a new empty shader object.
  226. //
  227. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateShader.xhtml
  228. func CreateShader(ty Enum) Shader {
  229. return Shader{Value: uint32(gl.CreateShader(uint32(ty)))}
  230. }
  231. // CreateTexture creates a texture object.
  232. //
  233. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml
  234. func CreateTexture() Texture {
  235. var t Texture
  236. gl.GenTextures(1, &t.Value)
  237. return t
  238. }
  239. // CullFace specifies which polygons are candidates for culling.
  240. //
  241. // Valid modes: FRONT, BACK, FRONT_AND_BACK.
  242. //
  243. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCullFace.xhtml
  244. func CullFace(mode Enum) {
  245. gl.CullFace(uint32(mode))
  246. }
  247. // DeleteBuffer deletes the given buffer object.
  248. //
  249. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteBuffers.xhtml
  250. func DeleteBuffer(v Buffer) {
  251. gl.DeleteBuffers(1, &v.Value)
  252. }
  253. // DeleteFramebuffer deletes the given framebuffer object.
  254. //
  255. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteFramebuffers.xhtml
  256. func DeleteFramebuffer(v Framebuffer) {
  257. gl.DeleteFramebuffers(1, &v.Value)
  258. }
  259. // DeleteProgram deletes the given program object.
  260. //
  261. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteProgram.xhtml
  262. func DeleteProgram(p Program) {
  263. gl.DeleteProgram(p.Value)
  264. }
  265. // DeleteRenderbuffer deletes the given render buffer object.
  266. //
  267. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteRenderbuffers.xhtml
  268. func DeleteRenderbuffer(v Renderbuffer) {
  269. gl.DeleteRenderbuffers(1, &v.Value)
  270. }
  271. // DeleteShader deletes shader s.
  272. //
  273. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteShader.xhtml
  274. func DeleteShader(s Shader) {
  275. gl.DeleteShader(s.Value)
  276. }
  277. // DeleteTexture deletes the given texture object.
  278. //
  279. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTextures.xhtml
  280. func DeleteTexture(v Texture) {
  281. gl.DeleteTextures(1, &v.Value)
  282. }
  283. // DepthFunc sets the function used for depth buffer comparisons.
  284. //
  285. // Valid fn values:
  286. // NEVER
  287. // LESS
  288. // EQUAL
  289. // LEQUAL
  290. // GREATER
  291. // NOTEQUAL
  292. // GEQUAL
  293. // ALWAYS
  294. //
  295. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthFunc.xhtml
  296. func DepthFunc(fn Enum) {
  297. gl.DepthFunc(uint32(fn))
  298. }
  299. // DepthMask sets the depth buffer enabled for writing.
  300. //
  301. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthMask.xhtml
  302. func DepthMask(flag bool) {
  303. gl.DepthMask(flag)
  304. }
  305. // DepthRangef sets the mapping from normalized device coordinates to
  306. // window coordinates.
  307. //
  308. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthRangef.xhtml
  309. func DepthRangef(n, f float32) {
  310. gl.DepthRangef(n, f)
  311. }
  312. // DetachShader detaches the shader s from the program p.
  313. //
  314. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDetachShader.xhtml
  315. func DetachShader(p Program, s Shader) {
  316. gl.DetachShader(p.Value, s.Value)
  317. }
  318. // Disable disables various GL capabilities.
  319. //
  320. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisable.xhtml
  321. func Disable(cap Enum) {
  322. gl.Disable(uint32(cap))
  323. }
  324. // DisableVertexAttribArray disables a vertex attribute array.
  325. //
  326. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisableVertexAttribArray.xhtml
  327. func DisableVertexAttribArray(a Attrib) {
  328. gl.DisableVertexAttribArray(uint32(a.Value))
  329. }
  330. // DrawArrays renders geometric primitives from the bound data.
  331. //
  332. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArrays.xhtml
  333. func DrawArrays(mode Enum, first, count int) {
  334. gl.DrawArrays(uint32(mode), int32(first), int32(count))
  335. }
  336. // DrawElements renders primitives from a bound buffer.
  337. //
  338. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawElements.xhtml
  339. func DrawElements(mode Enum, count int, ty Enum, offset int) {
  340. gl.DrawElements(uint32(mode), int32(count), uint32(ty), gl.PtrOffset(offset))
  341. }
  342. // Enable enables various GL capabilities.
  343. //
  344. // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml
  345. func Enable(cap Enum) {
  346. gl.Enable(uint32(cap))
  347. }
  348. // EnableVertexAttribArray enables a vertex attribute array.
  349. //
  350. // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnableVertexAttribArray.xhtml
  351. func EnableVertexAttribArray(a Attrib) {
  352. gl.EnableVertexAttribArray(uint32(a.Value))
  353. }
  354. // Finish blocks until the effects of all previously called GL
  355. // commands are complete.
  356. //
  357. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFinish.xhtml
  358. func Finish() {
  359. gl.Finish()
  360. }
  361. // Flush empties all buffers. It does not block.
  362. //
  363. // An OpenGL implementation may buffer network communication,
  364. // the command stream, or data inside the graphics accelerator.
  365. //
  366. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFlush.xhtml
  367. func Flush() {
  368. gl.Flush()
  369. }
  370. // FramebufferRenderbuffer attaches rb to the current frame buffer.
  371. //
  372. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferRenderbuffer.xhtml
  373. func FramebufferRenderbuffer(target, attachment, rbTarget Enum, rb Renderbuffer) {
  374. gl.FramebufferRenderbuffer(uint32(target), uint32(attachment), uint32(rbTarget), rb.Value)
  375. }
  376. // FramebufferTexture2D attaches the t to the current frame buffer.
  377. //
  378. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferTexture2D.xhtml
  379. func FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
  380. gl.FramebufferTexture2D(uint32(target), uint32(attachment), uint32(texTarget), t.Value, int32(level))
  381. }
  382. // FrontFace defines which polygons are front-facing.
  383. //
  384. // Valid modes: CW, CCW.
  385. //
  386. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFrontFace.xhtml
  387. func FrontFace(mode Enum) {
  388. gl.FrontFace(uint32(mode))
  389. }
  390. // GenerateMipmap generates mipmaps for the current texture.
  391. //
  392. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenerateMipmap.xhtml
  393. func GenerateMipmap(target Enum) {
  394. gl.GenerateMipmap(uint32(target))
  395. }
  396. // GetActiveAttrib returns details about an active attribute variable.
  397. // A value of 0 for index selects the first active attribute variable.
  398. // Permissible values for index range from 0 to the number of active
  399. // attribute variables minus 1.
  400. //
  401. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveAttrib.xhtml
  402. func GetActiveAttrib(p Program, index uint32) (name string, size int, ty Enum) {
  403. var length, si int32
  404. var typ uint32
  405. name = strings.Repeat("\x00", 256)
  406. cname := gl.Str(name)
  407. gl.GetActiveAttrib(p.Value, uint32(index), int32(len(name)-1), &length, &si, &typ, cname)
  408. name = name[:strings.IndexRune(name, 0)]
  409. return name, int(si), Enum(typ)
  410. }
  411. // GetActiveUniform returns details about an active uniform variable.
  412. // A value of 0 for index selects the first active uniform variable.
  413. // Permissible values for index range from 0 to the number of active
  414. // uniform variables minus 1.
  415. //
  416. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveUniform.xhtml
  417. func GetActiveUniform(p Program, index uint32) (name string, size int, ty Enum) {
  418. var length, si int32
  419. var typ uint32
  420. name = strings.Repeat("\x00", 256)
  421. cname := gl.Str(name)
  422. gl.GetActiveUniform(p.Value, uint32(index), int32(len(name)-1), &length, &si, &typ, cname)
  423. name = name[:strings.IndexRune(name, 0)]
  424. return name, int(si), Enum(typ)
  425. }
  426. // GetAttachedShaders returns the shader objects attached to program p.
  427. //
  428. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttachedShaders.xhtml
  429. func GetAttachedShaders(p Program) []Shader {
  430. log.Println("GetAttachedShaders: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  431. shadersLen := GetProgrami(p, ATTACHED_SHADERS)
  432. var n int32
  433. buf := make([]uint32, shadersLen)
  434. gl.GetAttachedShaders(uint32(p.Value), int32(shadersLen), &n, &buf[0])
  435. buf = buf[:int(n)]
  436. shaders := make([]Shader, int(n))
  437. for i, s := range buf {
  438. shaders[i] = Shader{Value: uint32(s)}
  439. }
  440. return shaders
  441. }
  442. // GetAttribLocation returns the location of an attribute variable.
  443. //
  444. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttribLocation.xhtml
  445. func GetAttribLocation(p Program, name string) Attrib {
  446. return Attrib{Value: uint(gl.GetAttribLocation(p.Value, gl.Str(name+"\x00")))}
  447. }
  448. // GetBooleanv returns the boolean values of parameter pname.
  449. //
  450. // Many boolean parameters can be queried more easily using IsEnabled.
  451. //
  452. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml
  453. func GetBooleanv(dst []bool, pname Enum) {
  454. gl.GetBooleanv(uint32(pname), &dst[0])
  455. }
  456. // GetFloatv returns the float values of parameter pname.
  457. //
  458. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml
  459. func GetFloatv(dst []float32, pname Enum) {
  460. gl.GetFloatv(uint32(pname), &dst[0])
  461. }
  462. // GetIntegerv returns the int values of parameter pname.
  463. //
  464. // Single values may be queried more easily using GetInteger.
  465. //
  466. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml
  467. func GetIntegerv(pname Enum, data []int32) {
  468. gl.GetIntegerv(uint32(pname), &data[0])
  469. }
  470. // GetInteger returns the int value of parameter pname.
  471. //
  472. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml
  473. func GetInteger(pname Enum) int {
  474. var data int32
  475. gl.GetIntegerv(uint32(pname), &data)
  476. return int(data)
  477. }
  478. // GetBufferParameteri returns a parameter for the active buffer.
  479. //
  480. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetBufferParameteriv.xhtml
  481. func GetBufferParameteri(target, pname Enum) int {
  482. var params int32
  483. gl.GetBufferParameteriv(uint32(target), uint32(pname), &params)
  484. return int(params)
  485. }
  486. // GetError returns the next error.
  487. //
  488. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetError.xhtml
  489. func GetError() Enum {
  490. return Enum(gl.GetError())
  491. }
  492. // GetBoundFramebuffer returns the currently bound framebuffer.
  493. // Use this method instead of gl.GetInteger(gl.FRAMEBUFFER_BINDING) to
  494. // enable support on all platforms
  495. func GetBoundFramebuffer() Framebuffer {
  496. var b int32
  497. gl.GetIntegerv(FRAMEBUFFER_BINDING, &b)
  498. return Framebuffer{Value: uint32(b)}
  499. }
  500. // GetFramebufferAttachmentParameteri returns attachment parameters
  501. // for the active framebuffer object.
  502. //
  503. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetFramebufferAttachmentParameteriv.xhtml
  504. func GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
  505. log.Println("GetFramebufferAttachmentParameteri: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  506. var param int32
  507. gl.GetFramebufferAttachmentParameteriv(uint32(target), uint32(attachment), uint32(pname), &param)
  508. return int(param)
  509. }
  510. // GetProgrami returns a parameter value for a program.
  511. //
  512. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramiv.xhtml
  513. func GetProgrami(p Program, pname Enum) int {
  514. var result int32
  515. gl.GetProgramiv(p.Value, uint32(pname), &result)
  516. return int(result)
  517. }
  518. // GetProgramInfoLog returns the information log for a program.
  519. //
  520. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramInfoLog.xhtml
  521. func GetProgramInfoLog(p Program) string {
  522. var logLength int32
  523. gl.GetProgramiv(p.Value, gl.INFO_LOG_LENGTH, &logLength)
  524. if logLength == 0 {
  525. return ""
  526. }
  527. logBuffer := make([]uint8, logLength)
  528. gl.GetProgramInfoLog(p.Value, logLength, nil, &logBuffer[0])
  529. return gl.GoStr(&logBuffer[0])
  530. }
  531. // GetRenderbufferParameteri returns a parameter value for a render buffer.
  532. //
  533. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetRenderbufferParameteriv.xhtml
  534. func GetRenderbufferParameteri(target, pname Enum) int {
  535. log.Println("GetRenderbufferParameteri: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  536. var result int32
  537. gl.GetRenderbufferParameteriv(uint32(target), uint32(pname), &result)
  538. return int(result)
  539. }
  540. // GetRenderbufferParameteri returns a parameter value for a shader.
  541. //
  542. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderiv.xhtml
  543. func GetShaderi(s Shader, pname Enum) int {
  544. var result int32
  545. gl.GetShaderiv(s.Value, uint32(pname), &result)
  546. return int(result)
  547. }
  548. // GetShaderInfoLog returns the information log for a shader.
  549. //
  550. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderInfoLog.xhtml
  551. func GetShaderInfoLog(s Shader) string {
  552. var logLength int32
  553. gl.GetShaderiv(s.Value, gl.INFO_LOG_LENGTH, &logLength)
  554. if logLength == 0 {
  555. return ""
  556. }
  557. logBuffer := make([]uint8, logLength)
  558. gl.GetShaderInfoLog(s.Value, logLength, nil, &logBuffer[0])
  559. return gl.GoStr(&logBuffer[0])
  560. }
  561. // GetShaderPrecisionFormat returns range and precision limits for
  562. // shader types.
  563. //
  564. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderPrecisionFormat.xhtml
  565. func GetShaderPrecisionFormat(shadertype, precisiontype Enum) (rangeLow, rangeHigh, precision int) {
  566. log.Println("GetShaderPrecisionFormat: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  567. var cRange [2]int32
  568. var cPrecision int32
  569. gl.GetShaderPrecisionFormat(uint32(shadertype), uint32(precisiontype), &cRange[0], &cPrecision)
  570. return int(cRange[0]), int(cRange[1]), int(cPrecision)
  571. }
  572. // GetShaderSource returns source code of shader s.
  573. //
  574. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderSource.xhtml
  575. func GetShaderSource(s Shader) string {
  576. log.Println("GetShaderSource: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  577. sourceLen := GetShaderi(s, gl.SHADER_SOURCE_LENGTH)
  578. if sourceLen == 0 {
  579. return ""
  580. }
  581. buf := make([]byte, sourceLen)
  582. gl.GetShaderSource(s.Value, int32(sourceLen), nil, &buf[0])
  583. return string(buf)
  584. }
  585. // GetString reports current GL state.
  586. //
  587. // Valid name values:
  588. // EXTENSIONS
  589. // RENDERER
  590. // SHADING_LANGUAGE_VERSION
  591. // VENDOR
  592. // VERSION
  593. //
  594. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetString.xhtml
  595. func GetString(pname Enum) string {
  596. return gl.GoStr(gl.GetString(uint32(pname)))
  597. }
  598. // GetTexParameterfv returns the float values of a texture parameter.
  599. //
  600. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml
  601. func GetTexParameterfv(dst []float32, target, pname Enum) {
  602. gl.GetTexParameterfv(uint32(target), uint32(pname), &dst[0])
  603. }
  604. // GetTexParameteriv returns the int values of a texture parameter.
  605. //
  606. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml
  607. func GetTexParameteriv(dst []int32, target, pname Enum) {
  608. gl.GetTexParameteriv(uint32(target), uint32(pname), &dst[0])
  609. }
  610. // GetUniformfv returns the float values of a uniform variable.
  611. //
  612. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml
  613. func GetUniformfv(dst []float32, src Uniform, p Program) {
  614. gl.GetUniformfv(p.Value, src.Value, &dst[0])
  615. }
  616. // GetUniformiv returns the float values of a uniform variable.
  617. //
  618. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml
  619. func GetUniformiv(dst []int32, src Uniform, p Program) {
  620. gl.GetUniformiv(p.Value, src.Value, &dst[0])
  621. }
  622. // GetUniformLocation returns the location of a uniform variable.
  623. //
  624. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml
  625. func GetUniformLocation(p Program, name string) Uniform {
  626. return Uniform{Value: gl.GetUniformLocation(p.Value, gl.Str(name+"\x00"))}
  627. }
  628. // GetVertexAttribf reads the float value of a vertex attribute.
  629. //
  630. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml
  631. func GetVertexAttribf(src Attrib, pname Enum) float32 {
  632. log.Println("GetVertexAttribf: not yet tested (TODO: remove this after it's confirmed to work. Your feedback is welcome.)")
  633. var result float32
  634. gl.GetVertexAttribfv(uint32(src.Value), uint32(pname), &result)
  635. return result
  636. }
  637. // GetVertexAttribfv reads float values of a vertex attribute.
  638. //
  639. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml
  640. func GetVertexAttribfv(dst []float32, src Attrib, pname Enum) {
  641. gl.GetVertexAttribfv(uint32(src.Value), uint32(pname), &dst[0])
  642. }
  643. // GetVertexAttribi reads the int value of a vertex attribute.
  644. //
  645. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml
  646. func GetVertexAttribi(src Attrib, pname Enum) int32 {
  647. var result int32
  648. gl.GetVertexAttribiv(uint32(src.Value), uint32(pname), &result)
  649. return result
  650. }
  651. // GetVertexAttribiv reads int values of a vertex attribute.
  652. //
  653. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml
  654. func GetVertexAttribiv(dst []int32, src Attrib, pname Enum) {
  655. gl.GetVertexAttribiv(uint32(src.Value), uint32(pname), &dst[0])
  656. }
  657. // Hint sets implementation-specific modes.
  658. //
  659. // http://www.khronos.org/opengles/sdk/docs/man3/html/glHint.xhtml
  660. func Hint(target, mode Enum) {
  661. gl.Hint(uint32(target), uint32(mode))
  662. }
  663. // IsBuffer reports if b is a valid buffer.
  664. //
  665. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsBuffer.xhtml
  666. func IsBuffer(b Buffer) bool {
  667. return gl.IsBuffer(b.Value)
  668. }
  669. // IsEnabled reports if cap is an enabled capability.
  670. //
  671. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsEnabled.xhtml
  672. func IsEnabled(cap Enum) bool {
  673. return gl.IsEnabled(uint32(cap))
  674. }
  675. // IsFramebuffer reports if fb is a valid frame buffer.
  676. //
  677. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsFramebuffer.xhtml
  678. func IsFramebuffer(fb Framebuffer) bool {
  679. return gl.IsFramebuffer(fb.Value)
  680. }
  681. // IsProgram reports if p is a valid program object.
  682. //
  683. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsProgram.xhtml
  684. func IsProgram(p Program) bool {
  685. return gl.IsProgram(p.Value)
  686. }
  687. // IsRenderbuffer reports if rb is a valid render buffer.
  688. //
  689. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsRenderbuffer.xhtml
  690. func IsRenderbuffer(rb Renderbuffer) bool {
  691. return gl.IsRenderbuffer(rb.Value)
  692. }
  693. // IsShader reports if s is valid shader.
  694. //
  695. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsShader.xhtml
  696. func IsShader(s Shader) bool {
  697. return gl.IsShader(s.Value)
  698. }
  699. // IsTexture reports if t is a valid texture.
  700. //
  701. // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsTexture.xhtml
  702. func IsTexture(t Texture) bool {
  703. return gl.IsTexture(t.Value)
  704. }
  705. // LineWidth specifies the width of lines.
  706. //
  707. // http://www.khronos.org/opengles/sdk/docs/man3/html/glLineWidth.xhtml
  708. func LineWidth(width float32) {
  709. gl.LineWidth(width)
  710. }
  711. // LinkProgram links the specified program.
  712. //
  713. // http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml
  714. func LinkProgram(p Program) {
  715. gl.LinkProgram(p.Value)
  716. }
  717. // ObjectLabel labels a named object identified within a namespace.
  718. //
  719. // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glObjectLabel.xhtml
  720. func ObjectLabel(o Object, label string) {
  721. gl.ObjectLabel(uint32(o.Identifier()), o.Name(), -1, gl.Str(label+"\x00"))
  722. }
  723. // PixelStorei sets pixel storage parameters.
  724. //
  725. // http://www.khronos.org/opengles/sdk/docs/man3/html/glPixelStorei.xhtml
  726. func PixelStorei(pname Enum, param int32) {
  727. gl.PixelStorei(uint32(pname), param)
  728. }
  729. // PolygonOffset sets the scaling factors for depth offsets.
  730. //
  731. // http://www.khronos.org/opengles/sdk/docs/man3/html/glPolygonOffset.xhtml
  732. func PolygonOffset(factor, units float32) {
  733. gl.PolygonOffset(factor, units)
  734. }
  735. // ReadPixels returns pixel data from a buffer.
  736. //
  737. // http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml
  738. func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
  739. gl.ReadPixels(int32(x), int32(y), int32(width), int32(height), uint32(format), uint32(ty), gl.Ptr(&dst[0]))
  740. }
  741. // ReleaseShaderCompiler frees resources allocated by the shader compiler.
  742. //
  743. // http://www.khronos.org/opengles/sdk/docs/man3/html/glReleaseShaderCompiler.xhtml
  744. func ReleaseShaderCompiler() {
  745. gl.ReleaseShaderCompiler()
  746. }
  747. // RenderbufferStorage establishes the data storage, format, and
  748. // dimensions of a renderbuffer object's image.
  749. //
  750. // http://www.khronos.org/opengles/sdk/docs/man3/html/glRenderbufferStorage.xhtml
  751. func RenderbufferStorage(target, internalFormat Enum, width, height int) {
  752. gl.RenderbufferStorage(uint32(target), uint32(internalFormat), int32(width), int32(height))
  753. }
  754. // SampleCoverage sets multisample coverage parameters.
  755. //
  756. // http://www.khronos.org/opengles/sdk/docs/man3/html/glSampleCoverage.xhtml
  757. func SampleCoverage(value float32, invert bool) {
  758. gl.SampleCoverage(value, invert)
  759. }
  760. // Scissor defines the scissor box rectangle, in window coordinates.
  761. //
  762. // http://www.khronos.org/opengles/sdk/docs/man3/html/glScissor.xhtml
  763. func Scissor(x, y, width, height int32) {
  764. gl.Scissor(x, y, width, height)
  765. }
  766. // ShaderSource sets the source code of s to the given source code.
  767. //
  768. // http://www.khronos.org/opengles/sdk/docs/man3/html/glShaderSource.xhtml
  769. func ShaderSource(s Shader, src string) {
  770. glsource, free := gl.Strs(src + "\x00")
  771. gl.ShaderSource(s.Value, 1, glsource, nil)
  772. free()
  773. }
  774. // StencilFunc sets the front and back stencil test reference value.
  775. //
  776. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFunc.xhtml
  777. func StencilFunc(fn Enum, ref int, mask uint32) {
  778. gl.StencilFunc(uint32(fn), int32(ref), mask)
  779. }
  780. // StencilFunc sets the front or back stencil test reference value.
  781. //
  782. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFuncSeparate.xhtml
  783. func StencilFuncSeparate(face, fn Enum, ref int, mask uint32) {
  784. gl.StencilFuncSeparate(uint32(face), uint32(fn), int32(ref), mask)
  785. }
  786. // StencilMask controls the writing of bits in the stencil planes.
  787. //
  788. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMask.xhtml
  789. func StencilMask(mask uint32) {
  790. gl.StencilMask(mask)
  791. }
  792. // StencilMaskSeparate controls the writing of bits in the stencil planes.
  793. //
  794. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMaskSeparate.xhtml
  795. func StencilMaskSeparate(face Enum, mask uint32) {
  796. gl.StencilMaskSeparate(uint32(face), mask)
  797. }
  798. // StencilOp sets front and back stencil test actions.
  799. //
  800. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOp.xhtml
  801. func StencilOp(fail, zfail, zpass Enum) {
  802. gl.StencilOp(uint32(fail), uint32(zfail), uint32(zpass))
  803. }
  804. // StencilOpSeparate sets front or back stencil tests.
  805. //
  806. // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOpSeparate.xhtml
  807. func StencilOpSeparate(face, sfail, dpfail, dppass Enum) {
  808. gl.StencilOpSeparate(uint32(face), uint32(sfail), uint32(dpfail), uint32(dppass))
  809. }
  810. // TexImage2D writes a 2D texture image.
  811. //
  812. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml
  813. func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) {
  814. p := unsafe.Pointer(nil)
  815. if len(data) > 0 {
  816. p = gl.Ptr(&data[0])
  817. }
  818. gl.TexImage2D(uint32(target), int32(level), int32(format), int32(width), int32(height), 0, uint32(format), uint32(ty), p)
  819. }
  820. // TexImage2DMultisample configures a multisample texture.
  821. //
  822. // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2DMultisample.xhtml
  823. func TexImage2DMultisample(target Enum, samples int, internalformat Enum, width, height int, fixedsamplelocations bool) {
  824. gl.TexImage2DMultisample(uint32(target), int32(samples), uint32(internalformat), int32(width), int32(height), fixedsamplelocations)
  825. }
  826. // TexSubImage2D writes a subregion of a 2D texture image.
  827. //
  828. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexSubImage2D.xhtml
  829. func TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
  830. gl.TexSubImage2D(uint32(target), int32(level), int32(x), int32(y), int32(width), int32(height), uint32(format), uint32(ty), gl.Ptr(&data[0]))
  831. }
  832. // TexParameterf sets a float texture parameter.
  833. //
  834. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml
  835. func TexParameterf(target, pname Enum, param float32) {
  836. gl.TexParameterf(uint32(target), uint32(pname), param)
  837. }
  838. // TexParameterfv sets a float texture parameter array.
  839. //
  840. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml
  841. func TexParameterfv(target, pname Enum, params []float32) {
  842. gl.TexParameterfv(uint32(target), uint32(pname), &params[0])
  843. }
  844. // TexParameteri sets an integer texture parameter.
  845. //
  846. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml
  847. func TexParameteri(target, pname Enum, param int) {
  848. gl.TexParameteri(uint32(target), uint32(pname), int32(param))
  849. }
  850. // TexParameteriv sets an integer texture parameter array.
  851. //
  852. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml
  853. func TexParameteriv(target, pname Enum, params []int32) {
  854. gl.TexParameteriv(uint32(target), uint32(pname), &params[0])
  855. }
  856. // Uniform1f writes a float uniform variable.
  857. //
  858. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  859. func Uniform1f(dst Uniform, v float32) {
  860. gl.Uniform1f(dst.Value, v)
  861. }
  862. // Uniform1fv writes a [len(src)]float uniform array.
  863. //
  864. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  865. func Uniform1fv(dst Uniform, src []float32) {
  866. gl.Uniform1fv(dst.Value, int32(len(src)), &src[0])
  867. }
  868. // Uniform1i writes an int uniform variable.
  869. //
  870. // Uniform1i and Uniform1iv are the only two functions that may be used
  871. // to load uniform variables defined as sampler types. Loading samplers
  872. // with any other function will result in a INVALID_OPERATION error.
  873. //
  874. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  875. func Uniform1i(dst Uniform, v int) {
  876. gl.Uniform1i(dst.Value, int32(v))
  877. }
  878. // Uniform1iv writes a int uniform array of len(src) elements.
  879. //
  880. // Uniform1i and Uniform1iv are the only two functions that may be used
  881. // to load uniform variables defined as sampler types. Loading samplers
  882. // with any other function will result in a INVALID_OPERATION error.
  883. //
  884. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  885. func Uniform1iv(dst Uniform, src []int32) {
  886. gl.Uniform1iv(dst.Value, int32(len(src)), &src[0])
  887. }
  888. // Uniform2f writes a vec2 uniform variable.
  889. //
  890. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  891. func Uniform2f(dst Uniform, v0, v1 float32) {
  892. gl.Uniform2f(dst.Value, v0, v1)
  893. }
  894. // Uniform2fv writes a vec2 uniform array of len(src)/2 elements.
  895. //
  896. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  897. func Uniform2fv(dst Uniform, src []float32) {
  898. gl.Uniform2fv(dst.Value, int32(len(src)/2), &src[0])
  899. }
  900. // Uniform2i writes an ivec2 uniform variable.
  901. //
  902. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  903. func Uniform2i(dst Uniform, v0, v1 int) {
  904. gl.Uniform2i(dst.Value, int32(v0), int32(v1))
  905. }
  906. // Uniform2iv writes an ivec2 uniform array of len(src)/2 elements.
  907. //
  908. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  909. func Uniform2iv(dst Uniform, src []int32) {
  910. gl.Uniform2iv(dst.Value, int32(len(src)/2), &src[0])
  911. }
  912. // Uniform3f writes a vec3 uniform variable.
  913. //
  914. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  915. func Uniform3f(dst Uniform, v0, v1, v2 float32) {
  916. gl.Uniform3f(dst.Value, v0, v1, v2)
  917. }
  918. // Uniform3fv writes a vec3 uniform array of len(src)/3 elements.
  919. //
  920. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  921. func Uniform3fv(dst Uniform, src []float32) {
  922. gl.Uniform3fv(dst.Value, int32(len(src)/3), &src[0])
  923. }
  924. // Uniform3i writes an ivec3 uniform variable.
  925. //
  926. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  927. func Uniform3i(dst Uniform, v0, v1, v2 int32) {
  928. gl.Uniform3i(dst.Value, v0, v1, v2)
  929. }
  930. // Uniform3iv writes an ivec3 uniform array of len(src)/3 elements.
  931. //
  932. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  933. func Uniform3iv(dst Uniform, src []int32) {
  934. gl.Uniform3iv(dst.Value, int32(len(src)/3), &src[0])
  935. }
  936. // Uniform4f writes a vec4 uniform variable.
  937. //
  938. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  939. func Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
  940. gl.Uniform4f(dst.Value, v0, v1, v2, v3)
  941. }
  942. // Uniform4fv writes a vec4 uniform array of len(src)/4 elements.
  943. //
  944. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  945. func Uniform4fv(dst Uniform, src []float32) {
  946. gl.Uniform4fv(dst.Value, int32(len(src)/4), &src[0])
  947. }
  948. // Uniform4i writes an ivec4 uniform variable.
  949. //
  950. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  951. func Uniform4i(dst Uniform, v0, v1, v2, v3 int32) {
  952. gl.Uniform4i(dst.Value, v0, v1, v2, v3)
  953. }
  954. // Uniform4i writes an ivec4 uniform array of len(src)/4 elements.
  955. //
  956. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  957. func Uniform4iv(dst Uniform, src []int32) {
  958. gl.Uniform4iv(dst.Value, int32(len(src)/4), &src[0])
  959. }
  960. // UniformMatrix2fv writes 2x2 matrices. Each matrix uses four
  961. // float32 values, so the number of matrices written is len(src)/4.
  962. //
  963. // Each matrix must be supplied in column major order.
  964. //
  965. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  966. func UniformMatrix2fv(dst Uniform, src []float32) {
  967. gl.UniformMatrix2fv(dst.Value, int32(len(src)/(2*2)), false, &src[0])
  968. }
  969. // UniformMatrix3fv writes 3x3 matrices. Each matrix uses nine
  970. // float32 values, so the number of matrices written is len(src)/9.
  971. //
  972. // Each matrix must be supplied in column major order.
  973. //
  974. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  975. func UniformMatrix3fv(dst Uniform, src []float32) {
  976. gl.UniformMatrix3fv(dst.Value, int32(len(src)/(3*3)), false, &src[0])
  977. }
  978. // UniformMatrix4fv writes 4x4 matrices. Each matrix uses 16
  979. // float32 values, so the number of matrices written is len(src)/16.
  980. //
  981. // Each matrix must be supplied in column major order.
  982. //
  983. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  984. func UniformMatrix4fv(dst Uniform, src []float32) {
  985. gl.UniformMatrix4fv(dst.Value, int32(len(src)/(4*4)), false, &src[0])
  986. }
  987. // UseProgram sets the active program.
  988. //
  989. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUseProgram.xhtml
  990. func UseProgram(p Program) {
  991. gl.UseProgram(p.Value)
  992. }
  993. // ValidateProgram checks to see whether the executables contained in
  994. // program can execute given the current OpenGL state.
  995. //
  996. // Typically only used for debugging.
  997. //
  998. // http://www.khronos.org/opengles/sdk/docs/man3/html/glValidateProgram.xhtml
  999. func ValidateProgram(p Program) {
  1000. gl.ValidateProgram(uint32(p.Value))
  1001. }
  1002. // VertexAttrib1f writes a float vertex attribute.
  1003. //
  1004. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1005. func VertexAttrib1f(dst Attrib, x float32) {
  1006. gl.VertexAttrib1f(uint32(dst.Value), x)
  1007. }
  1008. // VertexAttrib1fv writes a float vertex attribute.
  1009. //
  1010. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1011. func VertexAttrib1fv(dst Attrib, src []float32) {
  1012. gl.VertexAttrib1fv(uint32(dst.Value), &src[0])
  1013. }
  1014. // VertexAttrib2f writes a vec2 vertex attribute.
  1015. //
  1016. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1017. func VertexAttrib2f(dst Attrib, x, y float32) {
  1018. gl.VertexAttrib2f(uint32(dst.Value), x, y)
  1019. }
  1020. // VertexAttrib2fv writes a vec2 vertex attribute.
  1021. //
  1022. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1023. func VertexAttrib2fv(dst Attrib, src []float32) {
  1024. gl.VertexAttrib2fv(uint32(dst.Value), &src[0])
  1025. }
  1026. // VertexAttrib3f writes a vec3 vertex attribute.
  1027. //
  1028. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1029. func VertexAttrib3f(dst Attrib, x, y, z float32) {
  1030. gl.VertexAttrib3f(uint32(dst.Value), x, y, z)
  1031. }
  1032. // VertexAttrib3fv writes a vec3 vertex attribute.
  1033. //
  1034. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1035. func VertexAttrib3fv(dst Attrib, src []float32) {
  1036. gl.VertexAttrib3fv(uint32(dst.Value), &src[0])
  1037. }
  1038. // VertexAttrib4f writes a vec4 vertex attribute.
  1039. //
  1040. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1041. func VertexAttrib4f(dst Attrib, x, y, z, w float32) {
  1042. gl.VertexAttrib4f(uint32(dst.Value), x, y, z, w)
  1043. }
  1044. // VertexAttrib4fv writes a vec4 vertex attribute.
  1045. //
  1046. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml
  1047. func VertexAttrib4fv(dst Attrib, src []float32) {
  1048. gl.VertexAttrib4fv(uint32(dst.Value), &src[0])
  1049. }
  1050. // VertexAttribPointer uses a bound buffer to define vertex attribute data.
  1051. //
  1052. // Direct use of VertexAttribPointer to load data into OpenGL is not
  1053. // supported via the Go bindings. Instead, use BindBuffer with an
  1054. // ARRAY_BUFFER and then fill it using BufferData.
  1055. //
  1056. // The size argument specifies the number of components per attribute,
  1057. // between 1-4. The stride argument specifies the byte offset between
  1058. // consecutive vertex attributes.
  1059. //
  1060. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtml
  1061. func VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
  1062. gl.VertexAttribPointer(uint32(dst.Value), int32(size), uint32(ty), normalized, int32(stride), gl.PtrOffset(offset))
  1063. }
  1064. // Viewport sets the viewport, an affine transformation that
  1065. // normalizes device coordinates to window coordinates.
  1066. //
  1067. // http://www.khronos.org/opengles/sdk/docs/man3/html/glViewport.xhtml
  1068. func Viewport(x, y, width, height int) {
  1069. gl.Viewport(int32(x), int32(y), int32(width), int32(height))
  1070. }