| OLD | NEW |
| (Empty) |
| 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 | |
| 5 // +build linux darwin | |
| 6 // +build !gldebug | |
| 7 | |
| 8 package gl | |
| 9 | |
| 10 // TODO(crawshaw): build on more host platforms (makes it easier to gobind). | |
| 11 // TODO(crawshaw): expand to cover OpenGL ES 3. | |
| 12 // TODO(crawshaw): should functions on specific types become methods? E.g. | |
| 13 // func (t Texture) Bind(target Enum) | |
| 14 // this seems natural in Go, but moves us slightly | |
| 15 // further away from the underlying OpenGL spec. | |
| 16 | |
| 17 /* | |
| 18 #include <stdlib.h> | |
| 19 | |
| 20 #ifdef os_linux | |
| 21 #include <GLES2/gl2.h> | |
| 22 #endif | |
| 23 #ifdef os_darwin_arm | |
| 24 #include <OpenGLES/ES2/glext.h> | |
| 25 #endif | |
| 26 #ifdef os_darwin_amd64 | |
| 27 #include <OpenGL/gl3.h> | |
| 28 #endif | |
| 29 */ | |
| 30 import "C" | |
| 31 | |
| 32 import "unsafe" | |
| 33 | |
| 34 // ActiveTexture sets the active texture unit. | |
| 35 // | |
| 36 // http://www.khronos.org/opengles/sdk/docs/man3/html/glActiveTexture.xhtml | |
| 37 func ActiveTexture(texture Enum) { | |
| 38 C.glActiveTexture(texture.c()) | |
| 39 } | |
| 40 | |
| 41 // AttachShader attaches a shader to a program. | |
| 42 // | |
| 43 // http://www.khronos.org/opengles/sdk/docs/man3/html/glAttachShader.xhtml | |
| 44 func AttachShader(p Program, s Shader) { | |
| 45 C.glAttachShader(p.c(), s.c()) | |
| 46 } | |
| 47 | |
| 48 // BindAttribLocation binds a vertex attribute index with a named | |
| 49 // variable. | |
| 50 // | |
| 51 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindAttribLocation.xhtml | |
| 52 func BindAttribLocation(p Program, a Attrib, name string) { | |
| 53 str := unsafe.Pointer(C.CString(name)) | |
| 54 defer C.free(str) | |
| 55 C.glBindAttribLocation(p.c(), a.c(), (*C.GLchar)(str)) | |
| 56 } | |
| 57 | |
| 58 // BindBuffer binds a buffer. | |
| 59 // | |
| 60 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindBuffer.xhtml | |
| 61 func BindBuffer(target Enum, b Buffer) { | |
| 62 C.glBindBuffer(target.c(), b.c()) | |
| 63 } | |
| 64 | |
| 65 // BindFramebuffer binds a framebuffer. | |
| 66 // | |
| 67 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindFramebuffer.xhtml | |
| 68 func BindFramebuffer(target Enum, fb Framebuffer) { | |
| 69 C.glBindFramebuffer(target.c(), fb.c()) | |
| 70 } | |
| 71 | |
| 72 // BindRenderbuffer binds a render buffer. | |
| 73 // | |
| 74 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindRenderbuffer.xhtml | |
| 75 func BindRenderbuffer(target Enum, rb Renderbuffer) { | |
| 76 C.glBindRenderbuffer(target.c(), rb.c()) | |
| 77 } | |
| 78 | |
| 79 // BindTexture binds a texture. | |
| 80 // | |
| 81 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindTexture.xhtml | |
| 82 func BindTexture(target Enum, t Texture) { | |
| 83 C.glBindTexture(target.c(), t.c()) | |
| 84 } | |
| 85 | |
| 86 // BlendColor sets the blend color. | |
| 87 // | |
| 88 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendColor.xhtml | |
| 89 func BlendColor(red, green, blue, alpha float32) { | |
| 90 blendColor(red, green, blue, alpha) | |
| 91 } | |
| 92 | |
| 93 // BlendEquation sets both RGB and alpha blend equations. | |
| 94 // | |
| 95 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquation.xhtml | |
| 96 func BlendEquation(mode Enum) { | |
| 97 C.glBlendEquation(mode.c()) | |
| 98 } | |
| 99 | |
| 100 // BlendEquationSeparate sets RGB and alpha blend equations separately. | |
| 101 // | |
| 102 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquationSeparate.xh
tml | |
| 103 func BlendEquationSeparate(modeRGB, modeAlpha Enum) { | |
| 104 C.glBlendEquationSeparate(modeRGB.c(), modeAlpha.c()) | |
| 105 } | |
| 106 | |
| 107 // BlendFunc sets the pixel blending factors. | |
| 108 // | |
| 109 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFunc.xhtml | |
| 110 func BlendFunc(sfactor, dfactor Enum) { | |
| 111 C.glBlendFunc(sfactor.c(), dfactor.c()) | |
| 112 } | |
| 113 | |
| 114 // BlendFunc sets the pixel RGB and alpha blending factors separately. | |
| 115 // | |
| 116 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFuncSeparate.xhtml | |
| 117 func BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum)
{ | |
| 118 C.glBlendFuncSeparate(sfactorRGB.c(), dfactorRGB.c(), sfactorAlpha.c(),
dfactorAlpha.c()) | |
| 119 } | |
| 120 | |
| 121 // BufferData creates a new data store for the bound buffer object. | |
| 122 // | |
| 123 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml | |
| 124 func BufferData(target Enum, usage Enum, src []byte) { | |
| 125 C.glBufferData(target.c(), C.GLsizeiptr(len(src)), unsafe.Pointer(&src[0
]), usage.c()) | |
| 126 } | |
| 127 | |
| 128 // BufferInit creates a new unitialized data store for the bound buffer object. | |
| 129 // | |
| 130 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml | |
| 131 func BufferInit(target Enum, size int, usage Enum) { | |
| 132 C.glBufferData(target.c(), C.GLsizeiptr(size), nil, usage.c()) | |
| 133 } | |
| 134 | |
| 135 // BufferSubData sets some of data in the bound buffer object. | |
| 136 // | |
| 137 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferSubData.xhtml | |
| 138 func BufferSubData(target Enum, offset int, data []byte) { | |
| 139 C.glBufferSubData(target.c(), C.GLintptr(offset), C.GLsizeiptr(len(data)
), unsafe.Pointer(&data[0])) | |
| 140 } | |
| 141 | |
| 142 // CheckFramebufferStatus reports the completeness status of the | |
| 143 // active framebuffer. | |
| 144 // | |
| 145 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCheckFramebufferStatus.x
html | |
| 146 func CheckFramebufferStatus(target Enum) Enum { | |
| 147 return Enum(C.glCheckFramebufferStatus(target.c())) | |
| 148 } | |
| 149 | |
| 150 // Clear clears the window. | |
| 151 // | |
| 152 // The behavior of Clear is influenced by the pixel ownership test, | |
| 153 // the scissor test, dithering, and the buffer writemasks. | |
| 154 // | |
| 155 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClear.xhtml | |
| 156 func Clear(mask Enum) { | |
| 157 C.glClear(C.GLbitfield(mask)) | |
| 158 } | |
| 159 | |
| 160 // ClearColor specifies the RGBA values used to clear color buffers. | |
| 161 // | |
| 162 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearColor.xhtml | |
| 163 func ClearColor(red, green, blue, alpha float32) { | |
| 164 clearColor(red, green, blue, alpha) | |
| 165 } | |
| 166 | |
| 167 // ClearDepthf sets the depth value used to clear the depth buffer. | |
| 168 // | |
| 169 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearDepthf.xhtml | |
| 170 func ClearDepthf(d float32) { | |
| 171 clearDepthf(d) | |
| 172 } | |
| 173 | |
| 174 // ClearStencil sets the index used to clear the stencil buffer. | |
| 175 // | |
| 176 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearStencil.xhtml | |
| 177 func ClearStencil(s int) { | |
| 178 C.glClearStencil(C.GLint(s)) | |
| 179 } | |
| 180 | |
| 181 // ColorMask specifies whether color components in the framebuffer | |
| 182 // can be written. | |
| 183 // | |
| 184 // http://www.khronos.org/opengles/sdk/docs/man3/html/glColorMask.xhtml | |
| 185 func ColorMask(red, green, blue, alpha bool) { | |
| 186 C.glColorMask(glBoolean(red), glBoolean(green), glBoolean(blue), glBoole
an(alpha)) | |
| 187 } | |
| 188 | |
| 189 // CompileShader compiles the source code of s. | |
| 190 // | |
| 191 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompileShader.xhtml | |
| 192 func CompileShader(s Shader) { | |
| 193 C.glCompileShader(s.c()) | |
| 194 } | |
| 195 | |
| 196 // CompressedTexImage2D writes a compressed 2D texture. | |
| 197 // | |
| 198 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexImage2D.xht
ml | |
| 199 func CompressedTexImage2D(target Enum, level int, internalformat Enum, width, he
ight, border int, data []byte) { | |
| 200 C.glCompressedTexImage2D(target.c(), C.GLint(level), internalformat.c(),
C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLsizei(len(data)), uns
afe.Pointer(&data[0])) | |
| 201 } | |
| 202 | |
| 203 // CompressedTexSubImage2D writes a subregion of a compressed 2D texture. | |
| 204 // | |
| 205 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexSubImage2D.
xhtml | |
| 206 func CompressedTexSubImage2D(target Enum, level, xoffset, yoffset, width, height
int, format Enum, data []byte) { | |
| 207 C.glCompressedTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset)
, C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), format.c(), C.GLsizei(l
en(data)), unsafe.Pointer(&data[0])) | |
| 208 } | |
| 209 | |
| 210 // CopyTexImage2D writes a 2D texture from the current framebuffer. | |
| 211 // | |
| 212 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexImage2D.xhtml | |
| 213 func CopyTexImage2D(target Enum, level int, internalformat Enum, x, y, width, he
ight, border int) { | |
| 214 C.glCopyTexImage2D(target.c(), C.GLint(level), internalformat.c(), C.GLi
nt(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLint(border)) | |
| 215 } | |
| 216 | |
| 217 // CopyTexSubImage2D writes a 2D texture subregion from the | |
| 218 // current framebuffer. | |
| 219 // | |
| 220 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexSubImage2D.xhtml | |
| 221 func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height
int) { | |
| 222 C.glCopyTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset), C.GL
int(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) | |
| 223 } | |
| 224 | |
| 225 // CreateProgram creates a new empty program object. | |
| 226 // | |
| 227 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateProgram.xhtml | |
| 228 func CreateProgram() Program { | |
| 229 return Program{Value: uint32(C.glCreateProgram())} | |
| 230 } | |
| 231 | |
| 232 // CreateShader creates a new empty shader object. | |
| 233 // | |
| 234 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateShader.xhtml | |
| 235 func CreateShader(ty Enum) Shader { | |
| 236 return Shader{Value: uint32(C.glCreateShader(ty.c()))} | |
| 237 } | |
| 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 C.glCullFace(mode.c()) | |
| 246 } | |
| 247 | |
| 248 // DeleteBuffer deletes the given buffer object. | |
| 249 // | |
| 250 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteBuffers.xhtml | |
| 251 func DeleteBuffer(v Buffer) { | |
| 252 C.glDeleteBuffers(1, (*C.GLuint)(&v.Value)) | |
| 253 } | |
| 254 | |
| 255 // DeleteFramebuffer deletes the given framebuffer object. | |
| 256 // | |
| 257 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteFramebuffers.xhtml | |
| 258 func DeleteFramebuffer(v Framebuffer) { | |
| 259 C.glDeleteFramebuffers(1, (*C.GLuint)(&v.Value)) | |
| 260 } | |
| 261 | |
| 262 // DeleteProgram deletes the given program object. | |
| 263 // | |
| 264 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteProgram.xhtml | |
| 265 func DeleteProgram(p Program) { | |
| 266 C.glDeleteProgram(p.c()) | |
| 267 } | |
| 268 | |
| 269 // DeleteRenderbuffer deletes the given render buffer object. | |
| 270 // | |
| 271 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteRenderbuffers.xhtm
l | |
| 272 func DeleteRenderbuffer(v Renderbuffer) { | |
| 273 C.glDeleteRenderbuffers(1, (*C.GLuint)(&v.Value)) | |
| 274 } | |
| 275 | |
| 276 // DeleteShader deletes shader s. | |
| 277 // | |
| 278 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteShader.xhtml | |
| 279 func DeleteShader(s Shader) { | |
| 280 C.glDeleteShader(s.c()) | |
| 281 } | |
| 282 | |
| 283 // DeleteTexture deletes the given texture object. | |
| 284 // | |
| 285 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTextures.xhtml | |
| 286 func DeleteTexture(v Texture) { | |
| 287 C.glDeleteTextures(1, (*C.GLuint)(&v.Value)) | |
| 288 } | |
| 289 | |
| 290 // DepthFunc sets the function used for depth buffer comparisons. | |
| 291 // | |
| 292 // Valid fn values: | |
| 293 // NEVER | |
| 294 // LESS | |
| 295 // EQUAL | |
| 296 // LEQUAL | |
| 297 // GREATER | |
| 298 // NOTEQUAL | |
| 299 // GEQUAL | |
| 300 // ALWAYS | |
| 301 // | |
| 302 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthFunc.xhtml | |
| 303 func DepthFunc(fn Enum) { | |
| 304 C.glDepthFunc(fn.c()) | |
| 305 } | |
| 306 | |
| 307 // DepthMask sets the depth buffer enabled for writing. | |
| 308 // | |
| 309 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthMask.xhtml | |
| 310 func DepthMask(flag bool) { | |
| 311 C.glDepthMask(glBoolean(flag)) | |
| 312 } | |
| 313 | |
| 314 // DepthRangef sets the mapping from normalized device coordinates to | |
| 315 // window coordinates. | |
| 316 // | |
| 317 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthRangef.xhtml | |
| 318 func DepthRangef(n, f float32) { | |
| 319 depthRangef(n, f) | |
| 320 } | |
| 321 | |
| 322 // DetachShader detaches the shader s from the program p. | |
| 323 // | |
| 324 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDetachShader.xhtml | |
| 325 func DetachShader(p Program, s Shader) { | |
| 326 C.glDetachShader(p.c(), s.c()) | |
| 327 } | |
| 328 | |
| 329 // Disable disables various GL capabilities. | |
| 330 // | |
| 331 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisable.xhtml | |
| 332 func Disable(cap Enum) { | |
| 333 C.glDisable(cap.c()) | |
| 334 } | |
| 335 | |
| 336 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisableVertexAttribArray
.xhtml | |
| 337 func DisableVertexAttribArray(index Attrib) { | |
| 338 C.glDisableVertexAttribArray(index.c()) | |
| 339 } | |
| 340 | |
| 341 // DrawArrays renders geometric primitives from the bound data. | |
| 342 // | |
| 343 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArrays.xhtml | |
| 344 func DrawArrays(mode Enum, first, count int) { | |
| 345 C.glDrawArrays(mode.c(), C.GLint(first), C.GLsizei(count)) | |
| 346 } | |
| 347 | |
| 348 // DrawElements renders primitives from a bound buffer. | |
| 349 // | |
| 350 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawElements.xhtml | |
| 351 func DrawElements(mode, ty Enum, offset, count int) { | |
| 352 C.glDrawElements(mode.c(), C.GLsizei(count), ty.c(), unsafe.Pointer(uint
ptr(offset))) | |
| 353 } | |
| 354 | |
| 355 // TODO(crawshaw): consider DrawElements8 / DrawElements16 / DrawElements32 | |
| 356 | |
| 357 // Enable enables various GL capabilities. | |
| 358 // | |
| 359 // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml | |
| 360 func Enable(cap Enum) { | |
| 361 C.glEnable(cap.c()) | |
| 362 } | |
| 363 | |
| 364 // EnableVertexAttribArray enables a vertex attribute array. | |
| 365 // | |
| 366 // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnableVertexAttribArray.
xhtml | |
| 367 func EnableVertexAttribArray(index Attrib) { | |
| 368 C.glEnableVertexAttribArray(index.c()) | |
| 369 } | |
| 370 | |
| 371 // Finish blocks until the effects of all previously called GL | |
| 372 // commands are complete. | |
| 373 // | |
| 374 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFinish.xhtml | |
| 375 func Finish() { | |
| 376 C.glFinish() | |
| 377 } | |
| 378 | |
| 379 // Flush empties all buffers. It does not block. | |
| 380 // | |
| 381 // An OpenGL implementation may buffer network communication, | |
| 382 // the command stream, or data inside the graphics accelerator. | |
| 383 // | |
| 384 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFlush.xhtml | |
| 385 func Flush() { | |
| 386 C.glFlush() | |
| 387 } | |
| 388 | |
| 389 // FramebufferRenderbuffer attaches rb to the current frame buffer. | |
| 390 // | |
| 391 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferRenderbuffer.
xhtml | |
| 392 func FramebufferRenderbuffer(target, attachment, rbTarget Enum, rb Renderbuffer)
{ | |
| 393 C.glFramebufferRenderbuffer(target.c(), attachment.c(), rbTarget.c(), rb
.c()) | |
| 394 } | |
| 395 | |
| 396 // FramebufferTexture2D attaches the t to the current frame buffer. | |
| 397 // | |
| 398 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferTexture2D.xht
ml | |
| 399 func FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level i
nt) { | |
| 400 C.glFramebufferTexture2D(target.c(), attachment.c(), texTarget.c(), t.c(
), C.GLint(level)) | |
| 401 } | |
| 402 | |
| 403 // FrontFace defines which polygons are front-facing. | |
| 404 // | |
| 405 // Valid modes: CW, CCW. | |
| 406 // | |
| 407 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFrontFace.xhtml | |
| 408 func FrontFace(mode Enum) { | |
| 409 C.glFrontFace(mode.c()) | |
| 410 } | |
| 411 | |
| 412 // GenBuffer creates a buffer object. | |
| 413 // | |
| 414 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml | |
| 415 func GenBuffer() Buffer { | |
| 416 var b Buffer | |
| 417 C.glGenBuffers(1, (*C.GLuint)(&b.Value)) | |
| 418 return b | |
| 419 } | |
| 420 | |
| 421 // GenerateMipmap generates mipmaps for the current texture. | |
| 422 // | |
| 423 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenerateMipmap.xhtml | |
| 424 func GenerateMipmap(target Enum) { | |
| 425 C.glGenerateMipmap(target.c()) | |
| 426 } | |
| 427 | |
| 428 // GenFramebuffer creates a framebuffer object. | |
| 429 // | |
| 430 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenFramebuffers.xhtml | |
| 431 func GenFramebuffer() Framebuffer { | |
| 432 var b Framebuffer | |
| 433 C.glGenFramebuffers(1, (*C.GLuint)(&b.Value)) | |
| 434 return b | |
| 435 } | |
| 436 | |
| 437 // GenRenderbuffer create a renderbuffer object. | |
| 438 // | |
| 439 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenRenderbuffers.xhtml | |
| 440 func GenRenderbuffer() Renderbuffer { | |
| 441 var b Renderbuffer | |
| 442 C.glGenRenderbuffers(1, (*C.GLuint)(&b.Value)) | |
| 443 return b | |
| 444 } | |
| 445 | |
| 446 // GenTexture creates a texture object. | |
| 447 // | |
| 448 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml | |
| 449 func GenTexture() Texture { | |
| 450 var t Texture | |
| 451 C.glGenTextures(1, (*C.GLuint)(&t.Value)) | |
| 452 return t | |
| 453 } | |
| 454 | |
| 455 // GetActiveAttrib returns details about an attribute variable. | |
| 456 // | |
| 457 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveAttrib.xhtml | |
| 458 func GetActiveAttrib(p Program, a Attrib) (name string, size int, ty Enum) { | |
| 459 bufSize := GetProgrami(p, ACTIVE_ATTRIBUTE_MAX_LENGTH) | |
| 460 buf := C.malloc(C.size_t(bufSize)) | |
| 461 defer C.free(buf) | |
| 462 | |
| 463 var cSize C.GLint | |
| 464 var cType C.GLenum | |
| 465 C.glGetActiveAttrib(p.c(), a.c(), C.GLsizei(bufSize), nil, &cSize, &cTyp
e, (*C.GLchar)(buf)) | |
| 466 return C.GoString((*C.char)(buf)), int(cSize), Enum(cType) | |
| 467 } | |
| 468 | |
| 469 // GetActiveUniform returns details about an active uniform variable. | |
| 470 // | |
| 471 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveUniform.xhtml | |
| 472 func GetActiveUniform(p Program, u Uniform) (name string, size int, ty Enum) { | |
| 473 bufSize := GetProgrami(p, ACTIVE_UNIFORM_MAX_LENGTH) | |
| 474 buf := C.malloc(C.size_t(bufSize)) | |
| 475 defer C.free(buf) | |
| 476 | |
| 477 var cSize C.GLint | |
| 478 var cType C.GLenum | |
| 479 | |
| 480 C.glGetActiveUniform(p.c(), C.GLuint(u.Value), C.GLsizei(bufSize), nil,
&cSize, &cType, (*C.GLchar)(buf)) | |
| 481 return C.GoString((*C.char)(buf)), int(cSize), Enum(cType) | |
| 482 } | |
| 483 | |
| 484 // GetAttachedShaders returns the shader objects attached to program p. | |
| 485 // | |
| 486 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttachedShaders.xhtml | |
| 487 func GetAttachedShaders(p Program) []Shader { | |
| 488 shadersLen := GetProgrami(p, ATTACHED_SHADERS) | |
| 489 var n C.GLsizei | |
| 490 buf := make([]C.GLuint, shadersLen) | |
| 491 C.glGetAttachedShaders(p.c(), C.GLsizei(shadersLen), &n, &buf[0]) | |
| 492 buf = buf[:int(n)] | |
| 493 shaders := make([]Shader, len(buf)) | |
| 494 for i, s := range buf { | |
| 495 shaders[i] = Shader{Value: uint32(s)} | |
| 496 } | |
| 497 return shaders | |
| 498 } | |
| 499 | |
| 500 // GetAttribLocation finds a program attribute variable by name. | |
| 501 // | |
| 502 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttribLocation.xhtml | |
| 503 func GetAttribLocation(p Program, name string) Attrib { | |
| 504 str := unsafe.Pointer(C.CString(name)) | |
| 505 defer C.free(str) | |
| 506 return Attrib{Value: uint(C.glGetAttribLocation(p.c(), (*C.GLchar)(str))
)} | |
| 507 } | |
| 508 | |
| 509 // GetBooleanv returns the boolean values of parameter pname. | |
| 510 // | |
| 511 // Many boolean parameters can be queried more easily using IsEnabled. | |
| 512 // | |
| 513 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml | |
| 514 func GetBooleanv(dst []bool, pname Enum) { | |
| 515 buf := make([]C.GLboolean, len(dst)) | |
| 516 C.glGetBooleanv(pname.c(), &buf[0]) | |
| 517 for i, v := range buf { | |
| 518 dst[i] = v != 0 | |
| 519 } | |
| 520 } | |
| 521 | |
| 522 // GetFloatv returns the float values of parameter pname. | |
| 523 // | |
| 524 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml | |
| 525 func GetFloatv(dst []float32, pname Enum) { | |
| 526 C.glGetFloatv(pname.c(), (*C.GLfloat)(&dst[0])) | |
| 527 } | |
| 528 | |
| 529 // GetIntegerv returns the int values of parameter pname. | |
| 530 // | |
| 531 // Single values may be queried more easily using GetInteger. | |
| 532 // | |
| 533 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml | |
| 534 func GetIntegerv(pname Enum, data []int32) { | |
| 535 buf := make([]C.GLint, len(data)) | |
| 536 C.glGetIntegerv(pname.c(), &buf[0]) | |
| 537 for i, v := range buf { | |
| 538 data[i] = int32(v) | |
| 539 } | |
| 540 } | |
| 541 | |
| 542 // GetInteger returns the int value of parameter pname. | |
| 543 // | |
| 544 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml | |
| 545 func GetInteger(pname Enum) int { | |
| 546 var v C.GLint | |
| 547 C.glGetIntegerv(pname.c(), &v) | |
| 548 return int(v) | |
| 549 } | |
| 550 | |
| 551 // GetBufferParameteri returns a parameter for the active buffer. | |
| 552 // | |
| 553 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetBufferParameteriv.xht
ml | |
| 554 func GetBufferParameteri(target, pname Enum) int { | |
| 555 var params C.GLint | |
| 556 C.glGetBufferParameteriv(target.c(), pname.c(), ¶ms) | |
| 557 return int(params) | |
| 558 } | |
| 559 | |
| 560 // GetError returns the next error. | |
| 561 // | |
| 562 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetError.xhtml | |
| 563 func GetError() Enum { | |
| 564 return Enum(C.glGetError()) | |
| 565 } | |
| 566 | |
| 567 // GetFramebufferAttachmentParameteri returns attachment parameters | |
| 568 // for the active framebuffer object. | |
| 569 // | |
| 570 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetFramebufferAttachment
Parameteriv.xhtml | |
| 571 func GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int { | |
| 572 var params C.GLint | |
| 573 C.glGetFramebufferAttachmentParameteriv(target.c(), attachment.c(), pnam
e.c(), ¶ms) | |
| 574 return int(params) | |
| 575 } | |
| 576 | |
| 577 // GetProgrami returns a parameter value for a program. | |
| 578 // | |
| 579 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramiv.xhtml | |
| 580 func GetProgrami(p Program, pname Enum) int { | |
| 581 var params C.GLint | |
| 582 C.glGetProgramiv(p.c(), pname.c(), ¶ms) | |
| 583 return int(params) | |
| 584 } | |
| 585 | |
| 586 // GetProgramInfoLog returns the information log for a program. | |
| 587 // | |
| 588 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramInfoLog.xhtml | |
| 589 func GetProgramInfoLog(p Program) string { | |
| 590 infoLen := GetProgrami(p, INFO_LOG_LENGTH) | |
| 591 buf := C.malloc(C.size_t(infoLen)) | |
| 592 C.free(buf) | |
| 593 C.glGetProgramInfoLog(p.c(), C.GLsizei(infoLen), nil, (*C.GLchar)(buf)) | |
| 594 return C.GoString((*C.char)(buf)) | |
| 595 } | |
| 596 | |
| 597 // GetRenderbufferParameteri returns a parameter value for a render buffer. | |
| 598 // | |
| 599 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetRenderbufferParameter
iv.xhtml | |
| 600 func GetRenderbufferParameteri(target, pname Enum) int { | |
| 601 var params C.GLint | |
| 602 C.glGetRenderbufferParameteriv(target.c(), pname.c(), ¶ms) | |
| 603 return int(params) | |
| 604 } | |
| 605 | |
| 606 // GetRenderbufferParameteri returns a parameter value for a shader. | |
| 607 // | |
| 608 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderiv.xhtml | |
| 609 func GetShaderi(s Shader, pname Enum) int { | |
| 610 var params C.GLint | |
| 611 C.glGetShaderiv(s.c(), pname.c(), ¶ms) | |
| 612 return int(params) | |
| 613 } | |
| 614 | |
| 615 // GetShaderInfoLog returns the information log for a shader. | |
| 616 // | |
| 617 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderInfoLog.xhtml | |
| 618 func GetShaderInfoLog(s Shader) string { | |
| 619 infoLen := GetShaderi(s, INFO_LOG_LENGTH) | |
| 620 buf := C.malloc(C.size_t(infoLen)) | |
| 621 defer C.free(buf) | |
| 622 C.glGetShaderInfoLog(s.c(), C.GLsizei(infoLen), nil, (*C.GLchar)(buf)) | |
| 623 return C.GoString((*C.char)(buf)) | |
| 624 } | |
| 625 | |
| 626 // GetShaderPrecisionFormat returns range and precision limits for | |
| 627 // shader types. | |
| 628 // | |
| 629 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderPrecisionFormat
.xhtml | |
| 630 func GetShaderPrecisionFormat(shadertype, precisiontype Enum) (rangeLow, rangeHi
gh, precision int) { | |
| 631 const glintSize = 4 | |
| 632 var cRange [2]C.GLint | |
| 633 var cPrecision C.GLint | |
| 634 | |
| 635 C.glGetShaderPrecisionFormat(shadertype.c(), precisiontype.c(), &cRange[
0], &cPrecision) | |
| 636 return int(cRange[0]), int(cRange[1]), int(cPrecision) | |
| 637 } | |
| 638 | |
| 639 // GetShaderSource returns source code of shader s. | |
| 640 // | |
| 641 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderSource.xhtml | |
| 642 func GetShaderSource(s Shader) string { | |
| 643 sourceLen := GetShaderi(s, SHADER_SOURCE_LENGTH) | |
| 644 if sourceLen == 0 { | |
| 645 return "" | |
| 646 } | |
| 647 buf := C.malloc(C.size_t(sourceLen)) | |
| 648 defer C.free(buf) | |
| 649 C.glGetShaderSource(s.c(), C.GLsizei(sourceLen), nil, (*C.GLchar)(buf)) | |
| 650 return C.GoString((*C.char)(buf)) | |
| 651 } | |
| 652 | |
| 653 // GetString reports current GL state. | |
| 654 // | |
| 655 // Valid name values: | |
| 656 // EXTENSIONS | |
| 657 // RENDERER | |
| 658 // SHADING_LANGUAGE_VERSION | |
| 659 // VENDOR | |
| 660 // VERSION | |
| 661 // | |
| 662 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetString.xhtml | |
| 663 func GetString(name Enum) string { | |
| 664 // Bounce through unsafe.Pointer, because on some platforms | |
| 665 // GetString returns an *unsigned char which doesn't convert. | |
| 666 return C.GoString((*C.char)((unsafe.Pointer)(C.glGetString(name.c())))) | |
| 667 } | |
| 668 | |
| 669 // GetTexParameterfv returns the float values of a texture parameter. | |
| 670 // | |
| 671 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml | |
| 672 func GetTexParameterfv(dst []float32, target, pname Enum) { | |
| 673 C.glGetTexParameterfv(target.c(), pname.c(), (*C.GLfloat)(&dst[0])) | |
| 674 } | |
| 675 | |
| 676 // GetTexParameteriv returns the int values of a texture parameter. | |
| 677 // | |
| 678 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml | |
| 679 func GetTexParameteriv(dst []int32, target, pname Enum) { | |
| 680 C.glGetTexParameteriv(target.c(), pname.c(), (*C.GLint)(&dst[0])) | |
| 681 } | |
| 682 | |
| 683 // GetUniformfv returns the float values of a uniform variable. | |
| 684 // | |
| 685 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml | |
| 686 func GetUniformfv(dst []float32, src Uniform, p Program) { | |
| 687 C.glGetUniformfv(p.c(), src.c(), (*C.GLfloat)(&dst[0])) | |
| 688 } | |
| 689 | |
| 690 // GetUniformiv returns the float values of a uniform variable. | |
| 691 // | |
| 692 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml | |
| 693 func GetUniformiv(dst []int32, src Uniform, p Program) { | |
| 694 C.glGetUniformiv(p.c(), src.c(), (*C.GLint)(&dst[0])) | |
| 695 } | |
| 696 | |
| 697 // GetUniformLocation returns the location of uniform variable. | |
| 698 // | |
| 699 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml | |
| 700 func GetUniformLocation(p Program, name string) Uniform { | |
| 701 str := C.CString(name) | |
| 702 defer C.free((unsafe.Pointer)(str)) | |
| 703 return Uniform{Value: int32(C.glGetUniformLocation(p.c(), (*C.GLchar)(st
r)))} | |
| 704 } | |
| 705 | |
| 706 // GetVertexAttribf reads the float value of a vertex attribute. | |
| 707 // | |
| 708 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml | |
| 709 func GetVertexAttribf(src Attrib, pname Enum) float32 { | |
| 710 var params C.GLfloat | |
| 711 C.glGetVertexAttribfv(src.c(), pname.c(), ¶ms) | |
| 712 return float32(params) | |
| 713 } | |
| 714 | |
| 715 // GetVertexAttribfv reads float values of a vertex attribute. | |
| 716 // | |
| 717 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml | |
| 718 func GetVertexAttribfv(dst []float32, src Attrib, pname Enum) { | |
| 719 C.glGetVertexAttribfv(src.c(), pname.c(), (*C.GLfloat)(&dst[0])) | |
| 720 } | |
| 721 | |
| 722 // GetVertexAttribi reads the int value of a vertex attribute. | |
| 723 // | |
| 724 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml | |
| 725 func GetVertexAttribi(src Attrib, pname Enum) int32 { | |
| 726 var params C.GLint | |
| 727 C.glGetVertexAttribiv(src.c(), pname.c(), ¶ms) | |
| 728 return int32(params) | |
| 729 } | |
| 730 | |
| 731 // GetVertexAttribiv reads int values of a vertex attribute. | |
| 732 // | |
| 733 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml | |
| 734 func GetVertexAttribiv(dst []int32, src Attrib, pname Enum) { | |
| 735 C.glGetVertexAttribiv(src.c(), pname.c(), (*C.GLint)(&dst[0])) | |
| 736 } | |
| 737 | |
| 738 // TODO(crawshaw): glGetVertexAttribPointerv | |
| 739 | |
| 740 // Hint sets implementation-specific modes. | |
| 741 // | |
| 742 // http://www.khronos.org/opengles/sdk/docs/man3/html/glHint.xhtml | |
| 743 func Hint(target, mode Enum) { | |
| 744 C.glHint(target.c(), mode.c()) | |
| 745 } | |
| 746 | |
| 747 // IsBuffer reports if b is a valid buffer. | |
| 748 // | |
| 749 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsBuffer.xhtml | |
| 750 func IsBuffer(b Buffer) bool { | |
| 751 return C.glIsBuffer(b.c()) != 0 | |
| 752 } | |
| 753 | |
| 754 // IsEnabled reports if cap is an enabled capability. | |
| 755 // | |
| 756 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsEnabled.xhtml | |
| 757 func IsEnabled(cap Enum) bool { | |
| 758 return C.glIsEnabled(cap.c()) != 0 | |
| 759 } | |
| 760 | |
| 761 // IsFramebuffer reports if fb is a valid frame buffer. | |
| 762 // | |
| 763 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsFramebuffer.xhtml | |
| 764 func IsFramebuffer(fb Framebuffer) bool { | |
| 765 return C.glIsFramebuffer(fb.c()) != 0 | |
| 766 } | |
| 767 | |
| 768 // IsProgram reports if p is a valid program object. | |
| 769 // | |
| 770 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsProgram.xhtml | |
| 771 func IsProgram(p Program) bool { | |
| 772 return C.glIsProgram(p.c()) != 0 | |
| 773 } | |
| 774 | |
| 775 // IsRenderbuffer reports if rb is a valid render buffer. | |
| 776 // | |
| 777 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsRenderbuffer.xhtml | |
| 778 func IsRenderbuffer(rb Renderbuffer) bool { | |
| 779 return C.glIsRenderbuffer(rb.c()) != 0 | |
| 780 } | |
| 781 | |
| 782 // IsShader reports if s is valid shader. | |
| 783 // | |
| 784 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsShader.xhtml | |
| 785 func IsShader(s Shader) bool { | |
| 786 return C.glIsShader(s.c()) != 0 | |
| 787 } | |
| 788 | |
| 789 // IsTexture reports if t is a valid texture. | |
| 790 // | |
| 791 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsTexture.xhtml | |
| 792 func IsTexture(t Texture) bool { | |
| 793 return C.glIsTexture(t.c()) != 0 | |
| 794 } | |
| 795 | |
| 796 // LineWidth specifies the width of lines. | |
| 797 // | |
| 798 // http://www.khronos.org/opengles/sdk/docs/man3/html/glLineWidth.xhtml | |
| 799 func LineWidth(width float32) { | |
| 800 C.glLineWidth(C.GLfloat(width)) | |
| 801 } | |
| 802 | |
| 803 // LinkProgram links the specified program. | |
| 804 // | |
| 805 // http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml | |
| 806 func LinkProgram(p Program) { | |
| 807 C.glLinkProgram(p.c()) | |
| 808 } | |
| 809 | |
| 810 // PixelStorei sets pixel storage parameters. | |
| 811 // | |
| 812 // http://www.khronos.org/opengles/sdk/docs/man3/html/glPixelStorei.xhtml | |
| 813 func PixelStorei(pname Enum, param int32) { | |
| 814 C.glPixelStorei(pname.c(), C.GLint(param)) | |
| 815 } | |
| 816 | |
| 817 // PolygonOffset sets the scaling factors for depth offsets. | |
| 818 // | |
| 819 // http://www.khronos.org/opengles/sdk/docs/man3/html/glPolygonOffset.xhtml | |
| 820 func PolygonOffset(factor, units float32) { | |
| 821 C.glPolygonOffset(C.GLfloat(factor), C.GLfloat(units)) | |
| 822 } | |
| 823 | |
| 824 // ReadPixels returns pixel data from a buffer. | |
| 825 // | |
| 826 // In GLES 3, the source buffer is controlled with ReadBuffer. | |
| 827 // | |
| 828 // http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml | |
| 829 func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) { | |
| 830 // TODO(crawshaw): support PIXEL_PACK_BUFFER in GLES3, uses offset. | |
| 831 C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(heigh
t), format.c(), ty.c(), unsafe.Pointer(&dst[0])) | |
| 832 } | |
| 833 | |
| 834 // ReleaseShaderCompiler frees resources allocated by the shader compiler. | |
| 835 // | |
| 836 // http://www.khronos.org/opengles/sdk/docs/man3/html/glReleaseShaderCompiler.xh
tml | |
| 837 func ReleaseShaderCompiler() { | |
| 838 C.glReleaseShaderCompiler() | |
| 839 } | |
| 840 | |
| 841 // RenderbufferStorage establishes the data storage, format, and | |
| 842 // dimensions of a renderbuffer object's image. | |
| 843 // | |
| 844 // http://www.khronos.org/opengles/sdk/docs/man3/html/glRenderbufferStorage.xhtm
l | |
| 845 func RenderbufferStorage(target, internalFormat Enum, width, height int) { | |
| 846 C.glRenderbufferStorage(target.c(), internalFormat.c(), C.GLsizei(width)
, C.GLsizei(height)) | |
| 847 } | |
| 848 | |
| 849 // SampleCoverage sets multisample coverage parameters. | |
| 850 // | |
| 851 // http://www.khronos.org/opengles/sdk/docs/man3/html/glSampleCoverage.xhtml | |
| 852 func SampleCoverage(value float32, invert bool) { | |
| 853 sampleCoverage(value, invert) | |
| 854 } | |
| 855 | |
| 856 // Scissor defines the scissor box rectangle, in window coordinates. | |
| 857 // | |
| 858 // http://www.khronos.org/opengles/sdk/docs/man3/html/glScissor.xhtml | |
| 859 func Scissor(x, y, width, height int32) { | |
| 860 C.glScissor(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) | |
| 861 } | |
| 862 | |
| 863 // TODO(crawshaw): ShaderBinary | |
| 864 | |
| 865 // ShaderSource sets the source code of s to the given source code. | |
| 866 // | |
| 867 // http://www.khronos.org/opengles/sdk/docs/man3/html/glShaderSource.xhtml | |
| 868 func ShaderSource(s Shader, src string) { | |
| 869 str := (*C.GLchar)(C.CString(src)) | |
| 870 defer C.free(unsafe.Pointer(str)) | |
| 871 C.glShaderSource(s.c(), 1, &str, nil) | |
| 872 } | |
| 873 | |
| 874 // | |
| 875 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFunc.xhtml | |
| 876 func StencilFunc(fn Enum, ref int, mask uint32) { | |
| 877 C.glStencilFunc(fn.c(), C.GLint(ref), C.GLuint(mask)) | |
| 878 } | |
| 879 | |
| 880 // | |
| 881 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFuncSeparate.xhtm
l | |
| 882 func StencilFuncSeparate(face, fn Enum, ref int, mask uint32) { | |
| 883 C.glStencilFuncSeparate(face.c(), fn.c(), C.GLint(ref), C.GLuint(mask)) | |
| 884 } | |
| 885 | |
| 886 // StencilMask controls the writing of bits in the stencil planes. | |
| 887 // | |
| 888 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMask.xhtml | |
| 889 func StencilMask(mask uint32) { | |
| 890 C.glStencilMask(C.GLuint(mask)) | |
| 891 } | |
| 892 | |
| 893 // StencilMaskSeparate controls the writing of bits in the stencil planes. | |
| 894 // | |
| 895 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMaskSeparate.xhtm
l | |
| 896 func StencilMaskSeparate(face Enum, mask uint32) { | |
| 897 C.glStencilMaskSeparate(face.c(), C.GLuint(mask)) | |
| 898 } | |
| 899 | |
| 900 // StencilOp sets front and back stencil test actions. | |
| 901 // | |
| 902 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOp.xhtml | |
| 903 func StencilOp(fail, zfail, zpass Enum) { | |
| 904 C.glStencilOp(fail.c(), zfail.c(), zpass.c()) | |
| 905 } | |
| 906 | |
| 907 // StencilOpSeparate sets front or back stencil tests. | |
| 908 // | |
| 909 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOpSeparate.xhtml | |
| 910 func StencilOpSeparate(face, sfail, dpfail, dppass Enum) { | |
| 911 C.glStencilOpSeparate(face.c(), sfail.c(), dpfail.c(), dppass.c()) | |
| 912 } | |
| 913 | |
| 914 // TexImage2D writes a 2D texture image. | |
| 915 // | |
| 916 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml | |
| 917 func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum,
data []byte) { | |
| 918 // TODO(crawshaw): GLES3 offset for PIXEL_UNPACK_BUFFER and PIXEL_PACK_B
UFFER. | |
| 919 p := unsafe.Pointer(nil) | |
| 920 if len(data) > 0 { | |
| 921 p = unsafe.Pointer(&data[0]) | |
| 922 } | |
| 923 C.glTexImage2D(target.c(), C.GLint(level), C.GLint(format), C.GLsizei(wi
dth), C.GLsizei(height), 0, format.c(), ty.c(), p) | |
| 924 } | |
| 925 | |
| 926 // TexSubImage2D writes a subregion of a 2D texture image. | |
| 927 // | |
| 928 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexSubImage2D.xhtml | |
| 929 func TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty E
num, data []byte) { | |
| 930 // TODO(crawshaw): GLES3 offset for PIXEL_UNPACK_BUFFER and PIXEL_PACK_B
UFFER. | |
| 931 C.glTexSubImage2D(target.c(), C.GLint(level), C.GLint(x), C.GLint(y), C.
GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&data[0])) | |
| 932 } | |
| 933 | |
| 934 // TexParameterf sets a float texture parameter. | |
| 935 // | |
| 936 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml | |
| 937 func TexParameterf(target, pname Enum, param float32) { | |
| 938 C.glTexParameterf(target.c(), pname.c(), C.GLfloat(param)) | |
| 939 } | |
| 940 | |
| 941 // TexParameterfv sets a float texture parameter array. | |
| 942 // | |
| 943 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml | |
| 944 func TexParameterfv(target, pname Enum, params []float32) { | |
| 945 C.glTexParameterfv(target.c(), pname.c(), (*C.GLfloat)(¶ms[0])) | |
| 946 } | |
| 947 | |
| 948 // TexParameteri sets an integer texture parameter. | |
| 949 // | |
| 950 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml | |
| 951 func TexParameteri(target, pname Enum, param int) { | |
| 952 C.glTexParameteri(target.c(), pname.c(), C.GLint(param)) | |
| 953 } | |
| 954 | |
| 955 // TexParameteriv sets an integer texture parameter array. | |
| 956 // | |
| 957 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml | |
| 958 func TexParameteriv(target, pname Enum, params []int32) { | |
| 959 C.glTexParameteriv(target.c(), pname.c(), (*C.GLint)(¶ms[0])) | |
| 960 } | |
| 961 | |
| 962 // Uniform1f writes a float uniform variable. | |
| 963 // | |
| 964 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 965 func Uniform1f(dst Uniform, v float32) { | |
| 966 C.glUniform1f(dst.c(), C.GLfloat(v)) | |
| 967 } | |
| 968 | |
| 969 // Uniform1fv writes a [len(src)]float uniform array. | |
| 970 // | |
| 971 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 972 func Uniform1fv(dst Uniform, src []float32) { | |
| 973 C.glUniform1fv(dst.c(), C.GLsizei(len(src)), (*C.GLfloat)(&src[0])) | |
| 974 } | |
| 975 | |
| 976 // Uniform1i writes an int uniform variable. | |
| 977 // | |
| 978 // Uniform1i and Uniform1iv are the only two functions that may be used | |
| 979 // to load uniform variables defined as sampler types. Loading samplers | |
| 980 // with any other function will result in a INVALID_OPERATION error. | |
| 981 // | |
| 982 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 983 func Uniform1i(dst Uniform, v int) { | |
| 984 C.glUniform1i(dst.c(), C.GLint(v)) | |
| 985 } | |
| 986 | |
| 987 // Uniform1iv writes a int uniform array of len(src) elements. | |
| 988 // | |
| 989 // Uniform1i and Uniform1iv are the only two functions that may be used | |
| 990 // to load uniform variables defined as sampler types. Loading samplers | |
| 991 // with any other function will result in a INVALID_OPERATION error. | |
| 992 // | |
| 993 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 994 func Uniform1iv(dst Uniform, src []int32) { | |
| 995 C.glUniform1iv(dst.c(), C.GLsizei(len(src)), (*C.GLint)(&src[0])) | |
| 996 } | |
| 997 | |
| 998 // Uniform2f writes a vec2 uniform variable. | |
| 999 // | |
| 1000 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1001 func Uniform2f(dst Uniform, v0, v1 float32) { | |
| 1002 C.glUniform2f(dst.c(), C.GLfloat(v0), C.GLfloat(v1)) | |
| 1003 } | |
| 1004 | |
| 1005 // Uniform2fv writes a vec2 uniform array of len(src)/2 elements. | |
| 1006 // | |
| 1007 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1008 func Uniform2fv(dst Uniform, src []float32) { | |
| 1009 C.glUniform2fv(dst.c(), C.GLsizei(len(src)/2), (*C.GLfloat)(&src[0])) | |
| 1010 } | |
| 1011 | |
| 1012 // Uniform2i writes an ivec2 uniform variable. | |
| 1013 // | |
| 1014 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1015 func Uniform2i(dst Uniform, v0, v1 int) { | |
| 1016 C.glUniform2i(dst.c(), C.GLint(v0), C.GLint(v1)) | |
| 1017 } | |
| 1018 | |
| 1019 // Uniform2iv writes an ivec2 uniform array of len(src)/2 elements. | |
| 1020 // | |
| 1021 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1022 func Uniform2iv(dst Uniform, src []int32) { | |
| 1023 C.glUniform2iv(dst.c(), C.GLsizei(len(src)/2), (*C.GLint)(&src[0])) | |
| 1024 } | |
| 1025 | |
| 1026 // Uniform3f writes a vec3 uniform variable. | |
| 1027 // | |
| 1028 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1029 func Uniform3f(dst Uniform, v0, v1, v2 float32) { | |
| 1030 C.glUniform3f(dst.c(), C.GLfloat(v0), C.GLfloat(v1), C.GLfloat(v2)) | |
| 1031 } | |
| 1032 | |
| 1033 // Uniform3fv writes a vec3 uniform array of len(src)/3 elements. | |
| 1034 // | |
| 1035 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1036 func Uniform3fv(dst Uniform, src []float32) { | |
| 1037 C.glUniform3fv(dst.c(), C.GLsizei(len(src)/3), (*C.GLfloat)(&src[0])) | |
| 1038 } | |
| 1039 | |
| 1040 // Uniform3i writes an ivec3 uniform variable. | |
| 1041 // | |
| 1042 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1043 func Uniform3i(dst Uniform, v0, v1, v2 int32) { | |
| 1044 C.glUniform3i(dst.c(), C.GLint(v0), C.GLint(v1), C.GLint(v2)) | |
| 1045 } | |
| 1046 | |
| 1047 // Uniform3iv writes an ivec3 uniform array of len(src)/3 elements. | |
| 1048 // | |
| 1049 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1050 func Uniform3iv(dst Uniform, src []int32) { | |
| 1051 C.glUniform3iv(dst.c(), C.GLsizei(len(src)/3), (*C.GLint)(&src[0])) | |
| 1052 } | |
| 1053 | |
| 1054 // Uniform4f writes a vec4 uniform variable. | |
| 1055 // | |
| 1056 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1057 func Uniform4f(dst Uniform, v0, v1, v2, v3 float32) { | |
| 1058 C.glUniform4f(dst.c(), C.GLfloat(v0), C.GLfloat(v1), C.GLfloat(v2), C.GL
float(v3)) | |
| 1059 } | |
| 1060 | |
| 1061 // Uniform4fv writes a vec4 uniform array of len(src)/4 elements. | |
| 1062 // | |
| 1063 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1064 func Uniform4fv(dst Uniform, src []float32) { | |
| 1065 C.glUniform4fv(dst.c(), C.GLsizei(len(src)/4), (*C.GLfloat)(&src[0])) | |
| 1066 } | |
| 1067 | |
| 1068 // Uniform4i writes an ivec4 uniform variable. | |
| 1069 // | |
| 1070 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1071 func Uniform4i(dst Uniform, v0, v1, v2, v3 int32) { | |
| 1072 C.glUniform4i(dst.c(), C.GLint(v0), C.GLint(v1), C.GLint(v2), C.GLint(v3
)) | |
| 1073 } | |
| 1074 | |
| 1075 // Uniform4i writes an ivec4 uniform array of len(src)/4 elements. | |
| 1076 // | |
| 1077 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1078 func Uniform4iv(dst Uniform, src []int32) { | |
| 1079 C.glUniform4iv(dst.c(), C.GLsizei(len(src)/4), (*C.GLint)(&src[0])) | |
| 1080 } | |
| 1081 | |
| 1082 // UniformMatrix2fv writes 2x2 matrices. Each matrix uses four | |
| 1083 // float32 values, so the number of matrices written is len(src)/4. | |
| 1084 // | |
| 1085 // Each matrix must be supplied in column major order. | |
| 1086 // | |
| 1087 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1088 func UniformMatrix2fv(dst Uniform, src []float32) { | |
| 1089 /// OpenGL ES 2 does not support transpose. | |
| 1090 C.glUniformMatrix2fv(dst.c(), C.GLsizei(len(src)/4), 0, (*C.GLfloat)(&sr
c[0])) | |
| 1091 } | |
| 1092 | |
| 1093 // UniformMatrix3fv writes 3x3 matrices. Each matrix uses nine | |
| 1094 // float32 values, so the number of matrices written is len(src)/9. | |
| 1095 // | |
| 1096 // Each matrix must be supplied in column major order. | |
| 1097 // | |
| 1098 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1099 func UniformMatrix3fv(dst Uniform, src []float32) { | |
| 1100 C.glUniformMatrix3fv(dst.c(), C.GLsizei(len(src)/9), 0, (*C.GLfloat)(&sr
c[0])) | |
| 1101 } | |
| 1102 | |
| 1103 // UniformMatrix4fv writes 4x4 matrices. Each matrix uses 16 | |
| 1104 // float32 values, so the number of matrices written is len(src)/16. | |
| 1105 // | |
| 1106 // Each matrix must be supplied in column major order. | |
| 1107 // | |
| 1108 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml | |
| 1109 func UniformMatrix4fv(dst Uniform, src []float32) { | |
| 1110 C.glUniformMatrix4fv(dst.c(), C.GLsizei(len(src)/16), 0, (*C.GLfloat)(&s
rc[0])) | |
| 1111 } | |
| 1112 | |
| 1113 // UseProgram sets the active program. | |
| 1114 // | |
| 1115 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUseProgram.xhtml | |
| 1116 func UseProgram(p Program) { | |
| 1117 C.glUseProgram(p.c()) | |
| 1118 } | |
| 1119 | |
| 1120 // ValidateProgram checks to see whether the executables contained in | |
| 1121 // program can execute given the current OpenGL state. | |
| 1122 // | |
| 1123 // Typically only used for debugging. | |
| 1124 // | |
| 1125 // http://www.khronos.org/opengles/sdk/docs/man3/html/glValidateProgram.xhtml | |
| 1126 func ValidateProgram(p Program) { | |
| 1127 C.glValidateProgram(p.c()) | |
| 1128 } | |
| 1129 | |
| 1130 // VertexAttrib1f writes a float vertex attribute. | |
| 1131 // | |
| 1132 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1133 func VertexAttrib1f(dst Attrib, x float32) { | |
| 1134 C.glVertexAttrib1f(dst.c(), C.GLfloat(x)) | |
| 1135 } | |
| 1136 | |
| 1137 // VertexAttrib1fv writes a float vertex attribute. | |
| 1138 // | |
| 1139 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1140 func VertexAttrib1fv(dst Attrib, src []float32) { | |
| 1141 C.glVertexAttrib1fv(dst.c(), (*C.GLfloat)(&src[0])) | |
| 1142 } | |
| 1143 | |
| 1144 // VertexAttrib2f writes a vec2 vertex attribute. | |
| 1145 // | |
| 1146 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1147 func VertexAttrib2f(dst Attrib, x, y float32) { | |
| 1148 C.glVertexAttrib2f(dst.c(), C.GLfloat(x), C.GLfloat(y)) | |
| 1149 } | |
| 1150 | |
| 1151 // VertexAttrib2fv writes a vec2 vertex attribute. | |
| 1152 // | |
| 1153 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1154 func VertexAttrib2fv(dst Attrib, src []float32) { | |
| 1155 C.glVertexAttrib2fv(dst.c(), (*C.GLfloat)(&src[0])) | |
| 1156 } | |
| 1157 | |
| 1158 // VertexAttrib3f writes a vec3 vertex attribute. | |
| 1159 // | |
| 1160 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1161 func VertexAttrib3f(dst Attrib, x, y, z float32) { | |
| 1162 C.glVertexAttrib3f(dst.c(), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z)) | |
| 1163 } | |
| 1164 | |
| 1165 // VertexAttrib3fv writes a vec3 vertex attribute. | |
| 1166 // | |
| 1167 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1168 func VertexAttrib3fv(dst Attrib, src []float32) { | |
| 1169 C.glVertexAttrib3fv(dst.c(), (*C.GLfloat)(&src[0])) | |
| 1170 } | |
| 1171 | |
| 1172 // VertexAttrib4f writes a vec4 vertex attribute. | |
| 1173 // | |
| 1174 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1175 func VertexAttrib4f(dst Attrib, x, y, z, w float32) { | |
| 1176 C.glVertexAttrib4f(dst.c(), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.
GLfloat(w)) | |
| 1177 } | |
| 1178 | |
| 1179 // VertexAttrib4fv writes a vec4 vertex attribute. | |
| 1180 // | |
| 1181 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml | |
| 1182 func VertexAttrib4fv(dst Attrib, src []float32) { | |
| 1183 C.glVertexAttrib4fv(dst.c(), (*C.GLfloat)(&src[0])) | |
| 1184 } | |
| 1185 | |
| 1186 // VertexAttribPointer uses a bound buffer to define vertex attribute data. | |
| 1187 // | |
| 1188 // Direct use of VertexAttribPointer to load data into OpenGL is not | |
| 1189 // supported via the Go bindings. Instead, use BindBuffer with an | |
| 1190 // ARRAY_BUFFER and then fill it using BufferData. | |
| 1191 // | |
| 1192 // The size argument specifies the number of components per attribute, | |
| 1193 // between 1-4. The stride argument specifies the byte offset between | |
| 1194 // consecutive vertex attributes. | |
| 1195 // | |
| 1196 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtm
l | |
| 1197 func VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride,
offset int) { | |
| 1198 n := glBoolean(normalized) | |
| 1199 s := C.GLsizei(stride) | |
| 1200 C.glVertexAttribPointer(dst.c(), C.GLint(size), ty.c(), n, s, unsafe.Poi
nter(uintptr(offset))) | |
| 1201 } | |
| 1202 | |
| 1203 // Viewport sets the viewport, an affine transformation that | |
| 1204 // normalizes device coordinates to window coordinates. | |
| 1205 // | |
| 1206 // http://www.khronos.org/opengles/sdk/docs/man3/html/glViewport.xhtml | |
| 1207 func Viewport(x, y, width, height int) { | |
| 1208 C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)
) | |
| 1209 } | |
| OLD | NEW |