interface.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gl
  5. // Context is an OpenGL ES context.
  6. //
  7. // A Context has a method for every GL function supported by ES 2 or later.
  8. // In a program compiled with ES 3 support.
  9. //
  10. // Calls are not safe for concurrent use. However calls can be made from
  11. // any goroutine, the gl package removes the notion of thread-local
  12. // context.
  13. //
  14. // Contexts are independent. Two contexts can be used concurrently.
  15. type Context interface {
  16. // ActiveTexture sets the active texture unit.
  17. //
  18. // http://www.khronos.org/opengles/sdk/docs/man3/html/glActiveTexture.xhtml
  19. ActiveTexture(texture Enum)
  20. // AttachShader attaches a shader to a program.
  21. //
  22. // http://www.khronos.org/opengles/sdk/docs/man3/html/glAttachShader.xhtml
  23. AttachShader(p Program, s Shader)
  24. // BindBuffer binds a buffer.
  25. //
  26. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindBuffer.xhtml
  27. BindBuffer(target Enum, b Buffer)
  28. // BindTexture binds a texture.
  29. //
  30. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindTexture.xhtml
  31. BindTexture(target Enum, t Texture)
  32. // BindVertexArray binds a vertex array.
  33. //
  34. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindVertexArray.xhtml
  35. BindVertexArray(rb VertexArray)
  36. // BlendColor sets the blend color.
  37. //
  38. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendColor.xhtml
  39. BlendColor(red, green, blue, alpha float32)
  40. // BlendFunc sets the pixel blending factors.
  41. //
  42. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFunc.xhtml
  43. BlendFunc(sfactor, dfactor Enum)
  44. // BufferData creates a new data store for the bound buffer object.
  45. //
  46. // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml
  47. BufferData(target Enum, src []byte, usage Enum)
  48. // Clear clears the window.
  49. //
  50. // The behavior of Clear is influenced by the pixel ownership test,
  51. // the scissor test, dithering, and the buffer writemasks.
  52. //
  53. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClear.xhtml
  54. Clear(mask Enum)
  55. // ClearColor specifies the RGBA values used to clear color buffers.
  56. //
  57. // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearColor.xhtml
  58. ClearColor(red, green, blue, alpha float32)
  59. // CompileShader compiles the source code of s.
  60. //
  61. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompileShader.xhtml
  62. CompileShader(s Shader)
  63. // CreateBuffer creates a buffer object.
  64. //
  65. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml
  66. CreateBuffer() Buffer
  67. // CreateProgram creates a new empty program object.
  68. //
  69. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateProgram.xhtml
  70. CreateProgram() Program
  71. // CreateShader creates a new empty shader object.
  72. //
  73. // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateShader.xhtml
  74. CreateShader(ty Enum) Shader
  75. // CreateTexture creates a texture object.
  76. //
  77. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml
  78. CreateTexture() Texture
  79. // CreateTVertexArray creates a vertex array.
  80. //
  81. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml
  82. CreateVertexArray() VertexArray
  83. // DeleteBuffer deletes the given buffer object.
  84. //
  85. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteBuffers.xhtml
  86. DeleteBuffer(v Buffer)
  87. // DeleteTexture deletes the given texture object.
  88. //
  89. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTextures.xhtml
  90. DeleteTexture(v Texture)
  91. // Disable disables various GL capabilities.
  92. //
  93. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisable.xhtml
  94. Disable(cap Enum)
  95. // DrawArrays renders geometric primitives from the bound data.
  96. //
  97. // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArrays.xhtml
  98. DrawArrays(mode Enum, first, count int)
  99. // Enable enables various GL capabilities.
  100. //
  101. // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml
  102. Enable(cap Enum)
  103. // EnableVertexAttribArray enables a vertex attribute array.
  104. //
  105. // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnableVertexAttribArray.xhtml
  106. EnableVertexAttribArray(a Attrib)
  107. // Flush empties all buffers. It does not block.
  108. //
  109. // An OpenGL implementation may buffer network communication,
  110. // the command stream, or data inside the graphics accelerator.
  111. //
  112. // http://www.khronos.org/opengles/sdk/docs/man3/html/glFlush.xhtml
  113. Flush()
  114. // GetAttribLocation returns the location of an attribute variable.
  115. //
  116. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttribLocation.xhtml
  117. GetAttribLocation(p Program, name string) Attrib
  118. // GetError returns the next error.
  119. //
  120. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetError.xhtml
  121. GetError() Enum
  122. // GetProgrami returns a parameter value for a shader.
  123. //
  124. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramiv.xhtml
  125. GetProgrami(p Program, pname Enum) int
  126. // GetProgramInfoLog returns the information log for a shader.
  127. //
  128. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramInfoLog.xhtml
  129. GetProgramInfoLog(p Program) string
  130. // GetShaderi returns a parameter value for a shader.
  131. //
  132. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderiv.xhtml
  133. GetShaderi(s Shader, pname Enum) int
  134. // GetShaderInfoLog returns the information log for a shader.
  135. //
  136. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderInfoLog.xhtml
  137. GetShaderInfoLog(s Shader) string
  138. // GetUniformLocation returns the location of a uniform variable.
  139. //
  140. // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml
  141. GetUniformLocation(p Program, name string) Uniform
  142. // LinkProgram links the specified program.
  143. //
  144. // http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml
  145. LinkProgram(p Program)
  146. // PixelStorei set pixel storage modes
  147. //
  148. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glPixelStorei.xhtml
  149. PixelStorei(pname Enum, param int32)
  150. // ReadPixels returns pixel data from a buffer.
  151. //
  152. // In GLES 3, the source buffer is controlled with ReadBuffer.
  153. //
  154. // http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml
  155. ReadPixels(dst []byte, x, y, width, height int, format, ty Enum)
  156. // Scissor defines the scissor box rectangle, in window coordinates.
  157. //
  158. // http://www.khronos.org/opengles/sdk/docs/man3/html/glScissor.xhtml
  159. Scissor(x, y, width, height int32)
  160. // ShaderSource sets the source code of s to the given source code.
  161. //
  162. // http://www.khronos.org/opengles/sdk/docs/man3/html/glShaderSource.xhtml
  163. ShaderSource(s Shader, src string)
  164. // TexImage2D writes a 2D texture image.
  165. //
  166. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml
  167. TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte)
  168. // TexParameteri sets an integer texture parameter.
  169. //
  170. // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml
  171. TexParameteri(target, pname Enum, param int)
  172. // Uniform1f writes a float uniform variable.
  173. //
  174. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  175. Uniform1f(dst Uniform, v float32)
  176. // Uniform4f writes a vec4 uniform variable.
  177. //
  178. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  179. Uniform4f(dst Uniform, v0, v1, v2, v3 float32)
  180. // Uniform4fv writes a vec4 uniform array of len(src)/4 elements.
  181. //
  182. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml
  183. Uniform4fv(dst Uniform, src []float32)
  184. // UseProgram sets the active program.
  185. //
  186. // http://www.khronos.org/opengles/sdk/docs/man3/html/glUseProgram.xhtml
  187. UseProgram(p Program)
  188. // VertexAttribPointer uses a bound buffer to define vertex attribute data.
  189. //
  190. // Direct use of VertexAttribPointer to load data into OpenGL is not
  191. // supported via the Go bindings. Instead, use BindBuffer with an
  192. // ARRAY_BUFFER and then fill it using BufferData.
  193. //
  194. // The size argument specifies the number of components per attribute,
  195. // between 1-4. The stride argument specifies the byte offset between
  196. // consecutive vertex attributes.
  197. //
  198. // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtml
  199. VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int)
  200. // Viewport sets the viewport, an affine transformation that
  201. // normalizes device coordinates to window coordinates.
  202. //
  203. // http://www.khronos.org/opengles/sdk/docs/man3/html/glViewport.xhtml
  204. Viewport(x, y, width, height int)
  205. }
  206. // Worker is used by display driver code to execute OpenGL calls.
  207. //
  208. // Typically display driver code creates a gl.Context for an application,
  209. // and along with it establishes a locked OS thread to execute the cgo
  210. // calls:
  211. //
  212. // go func() {
  213. // runtime.LockOSThread()
  214. // // ... platform-specific cgo call to bind a C OpenGL context
  215. // // into thread-local storage.
  216. //
  217. // glctx, worker := gl.NewContext()
  218. // workAvailable := worker.WorkAvailable()
  219. // go userAppCode(glctx)
  220. // for {
  221. // select {
  222. // case <-workAvailable:
  223. // worker.DoWork()
  224. // case <-drawEvent:
  225. // // ... platform-specific cgo call to draw screen
  226. // }
  227. // }
  228. // }()
  229. //
  230. // This interface is an internal implementation detail and should only be used
  231. // by the package responsible for managing the screen.
  232. type Worker interface {
  233. // WorkAvailable returns a channel that communicates when DoWork should be
  234. // called.
  235. WorkAvailable() <-chan struct{}
  236. // DoWork performs any pending OpenGL calls.
  237. DoWork()
  238. }