github.com/thommil/tge-gl@v0.0.0-20190313100017-83d8f10f8fae/gl_desktop.go (about) 1 // Copyright (c) 2019 Thomas MILLET. All rights reserved. 2 3 // +build darwin freebsd linux windows 4 // +build !android 5 // +build !ios 6 // +build !js 7 8 package gl 9 10 import ( 11 fmt "fmt" 12 strings "strings" 13 unsafe "unsafe" 14 15 gl "github.com/go-gl/gl/v3.3-core/gl" 16 tge "github.com/thommil/tge" 17 ) 18 19 type plugin struct { 20 isInit bool 21 } 22 23 func (p *plugin) Init(runtime tge.Runtime) error { 24 if !p.isInit { 25 p.isInit = true 26 return gl.Init() 27 } 28 return fmt.Errorf("Already initialized") 29 } 30 31 func (p *plugin) Dispose() { 32 p.isInit = false 33 FlushCache() 34 } 35 36 // GetGLSLVersion gives the glsl version ti put in #version ${VERSION} 37 func GetGLSLVersion() string { 38 return "330 core" 39 } 40 41 // FlushCache free memory cache, should be called between scenes 42 func FlushCache() { 43 byteArrayBuffer = make([]byte, 0) 44 byteArrayBufferExtendFactor = 1 45 } 46 47 // ActiveTexture sets the active texture unit. 48 // 49 // http://www.khronos.org/opengles/sdk/docs/man3/html/glActiveTexture.xhtml 50 func ActiveTexture(texture Enum) { 51 gl.ActiveTexture(uint32(texture)) 52 } 53 54 // AttachShader attaches a shader to a program. 55 // 56 // http://www.khronos.org/opengles/sdk/docs/man3/html/glAttachShader.xhtml 57 func AttachShader(p Program, s Shader) { 58 gl.AttachShader(uint32(p), uint32(s)) 59 } 60 61 // BindAttribLocation binds a vertex attribute index with a named 62 // variable. 63 // 64 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindAttribLocation.xhtml 65 func BindAttribLocation(p Program, a Attrib, name string) { 66 gl.BindAttribLocation(uint32(p), uint32(a), gl.Str(name+"\x00")) 67 } 68 69 // BindBuffer binds a buffer. 70 // 71 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindBuffer.xhtml 72 func BindBuffer(target Enum, b Buffer) { 73 gl.BindBuffer(uint32(target), uint32(b)) 74 } 75 76 // BindFramebuffer binds a framebuffer. 77 // 78 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindFramebuffer.xhtml 79 func BindFramebuffer(target Enum, fb Framebuffer) { 80 gl.BindFramebuffer(uint32(target), uint32(fb)) 81 } 82 83 // BindRenderbuffer binds a render buffer. 84 // 85 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindRenderbuffer.xhtml 86 func BindRenderbuffer(target Enum, rb Renderbuffer) { 87 gl.BindRenderbuffer(uint32(target), uint32(rb)) 88 } 89 90 // BindTexture binds a texture. 91 // 92 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindTexture.xhtml 93 func BindTexture(target Enum, t Texture) { 94 gl.BindTexture(uint32(target), uint32(t)) 95 } 96 97 // BindVertexArray binds a VAO. 98 // 99 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindVertexArray.xhtml 100 func BindVertexArray(vao VertexArray) { 101 gl.BindVertexArray(uint32(vao)) 102 } 103 104 // BlendColor sets the blend color. 105 // 106 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendColor.xhtml 107 func BlendColor(red, green, blue, alpha float32) { 108 gl.BlendColor(red, green, blue, alpha) 109 } 110 111 // BlendEquation sets both RGB and alpha blend equations. 112 // 113 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquation.xhtml 114 func BlendEquation(mode Enum) { 115 gl.BlendEquation(uint32(mode)) 116 } 117 118 // BlendEquationSeparate sets RGB and alpha blend equations separately. 119 // 120 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendEquationSeparate.xhtml 121 func BlendEquationSeparate(modeRGB, modeAlpha Enum) { 122 gl.BlendEquationSeparate(uint32(modeRGB), uint32(modeAlpha)) 123 } 124 125 // BlendFunc sets the pixel blending factors. 126 // 127 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFunc.xhtml 128 func BlendFunc(sfactor, dfactor Enum) { 129 gl.BlendFunc(uint32(sfactor), uint32(dfactor)) 130 } 131 132 // BlendFuncSeparate sets the pixel RGB and alpha blending factors separately. 133 // 134 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFuncSeparate.xhtml 135 func BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum) { 136 gl.BlendFuncSeparate(uint32(sfactorRGB), uint32(dfactorRGB), uint32(sfactorAlpha), uint32(dfactorAlpha)) 137 } 138 139 // BufferData creates a new data store for the bound buffer object. 140 // 141 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml 142 func BufferData(target Enum, src []byte, usage Enum) { 143 gl.BufferData(uint32(target), int(len(src)), gl.Ptr(&src[0]), uint32(usage)) 144 } 145 146 // BufferInit creates a new unitialized data store for the bound buffer object. 147 // 148 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml 149 func BufferInit(target Enum, size int, usage Enum) { 150 gl.BufferData(uint32(target), size, nil, uint32(usage)) 151 } 152 153 // BufferSubData sets some of data in the bound buffer object. 154 // 155 // http://www.khronos.org/opengles/sdk/docs/man3/html/glBufferSubData.xhtml 156 func BufferSubData(target Enum, offset int, data []byte) { 157 gl.BufferSubData(uint32(target), offset, int(len(data)), gl.Ptr(&data[0])) 158 } 159 160 // CheckFramebufferStatus reports the completeness status of the 161 // active framebuffer. 162 // 163 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCheckFramebufferStatus.xhtml 164 func CheckFramebufferStatus(target Enum) Enum { 165 return Enum(gl.CheckFramebufferStatus(uint32(target))) 166 } 167 168 // Clear clears the window. 169 // 170 // The behavior of Clear is influenced by the pixel ownership test, 171 // the scissor test, dithering, and the buffer writemasks. 172 // 173 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClear.xhtml 174 func Clear(mask Enum) { 175 gl.Clear(uint32(mask)) 176 } 177 178 // ClearColor specifies the RGBA values used to clear color buffers. 179 // 180 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearColor.xhtml 181 func ClearColor(red, green, blue, alpha float32) { 182 gl.ClearColor(red, green, blue, alpha) 183 } 184 185 // ClearDepthf sets the depth value used to clear the depth buffer. 186 // 187 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearDepthf.xhtml 188 func ClearDepthf(d float32) { 189 gl.ClearDepthf(d) 190 } 191 192 // ClearStencil sets the index used to clear the stencil buffer. 193 // 194 // http://www.khronos.org/opengles/sdk/docs/man3/html/glClearStencil.xhtml 195 func ClearStencil(s int) { 196 gl.ClearStencil(int32(s)) 197 } 198 199 // ColorMask specifies whether color components in the framebuffer 200 // can be written. 201 // 202 // http://www.khronos.org/opengles/sdk/docs/man3/html/glColorMask.xhtml 203 func ColorMask(red, green, blue, alpha bool) { 204 gl.ColorMask(red, green, blue, alpha) 205 } 206 207 // CompileShader compiles the source code of s. 208 // 209 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompileShader.xhtml 210 func CompileShader(s Shader) { 211 gl.CompileShader(uint32(s)) 212 } 213 214 // CompressedTexImage2D writes a compressed 2D texture. 215 // 216 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexImage2D.xhtml 217 func CompressedTexImage2D(target Enum, level int, internalformat Enum, width, height, border int, data []byte) { 218 gl.CompressedTexImage2D(uint32(target), int32(level), uint32(internalformat), int32(width), int32(height), int32(border), int32(len(data)), gl.Ptr(data)) 219 } 220 221 // CompressedTexSubImage2D writes a subregion of a compressed 2D texture. 222 // 223 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCompressedTexSubImage2D.xhtml 224 func CompressedTexSubImage2D(target Enum, level, xoffset, yoffset, width, height int, format Enum, data []byte) { 225 gl.CompressedTexSubImage2D(uint32(target), int32(level), int32(xoffset), int32(yoffset), int32(width), int32(height), uint32(format), int32(len(data)), gl.Ptr(data)) 226 } 227 228 // CopyTexImage2D writes a 2D texture from the current framebuffer. 229 // 230 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexImage2D.xhtml 231 func CopyTexImage2D(target Enum, level int, internalformat Enum, x, y, width, height, border int) { 232 gl.CopyTexImage2D(uint32(target), int32(level), uint32(internalformat), int32(x), int32(y), int32(width), int32(height), int32(border)) 233 } 234 235 // CopyTexSubImage2D writes a 2D texture subregion from the 236 // current framebuffer. 237 // 238 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCopyTexSubImage2D.xhtml 239 func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) { 240 gl.CopyTexSubImage2D(uint32(target), int32(level), int32(xoffset), int32(yoffset), int32(x), int32(y), int32(width), int32(height)) 241 } 242 243 // CreateBuffer creates a buffer object. 244 // 245 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml 246 func CreateBuffer() Buffer { 247 var b uint32 248 gl.GenBuffers(1, &b) 249 return Buffer(b) 250 } 251 252 // CreateFramebuffer creates a framebuffer object. 253 // 254 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenFramebuffers.xhtml 255 func CreateFramebuffer() Framebuffer { 256 var b uint32 257 gl.GenFramebuffers(1, &b) 258 return Framebuffer(b) 259 } 260 261 // CreateProgram creates a new empty program object. 262 // 263 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateProgram.xhtml 264 func CreateProgram() Program { 265 return Program(uint32(gl.CreateProgram())) 266 } 267 268 // CreateRenderbuffer create a renderbuffer object. 269 // 270 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenRenderbuffers.xhtml 271 func CreateRenderbuffer() Renderbuffer { 272 var b uint32 273 gl.GenRenderbuffers(1, &b) 274 return Renderbuffer(b) 275 } 276 277 // CreateShader creates a new empty shader object. 278 // 279 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCreateShader.xhtml 280 func CreateShader(ty Enum) Shader { 281 return Shader(uint32(gl.CreateShader(uint32(ty)))) 282 } 283 284 // CreateTexture creates a texture object. 285 // 286 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml 287 func CreateTexture() Texture { 288 var t uint32 289 gl.GenTextures(1, &t) 290 return Texture(t) 291 } 292 293 // CreateVertexArray creates a VAO. 294 // 295 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml 296 func CreateVertexArray() VertexArray { 297 var vao uint32 298 gl.GenVertexArrays(1, &vao) 299 return VertexArray(vao) 300 } 301 302 // CullFace specifies which polygons are candidates for culling. 303 // 304 // Valid modes: FRONT, BACK, FRONT_AND_BACK. 305 // 306 // http://www.khronos.org/opengles/sdk/docs/man3/html/glCullFace.xhtml 307 func CullFace(mode Enum) { 308 gl.CullFace(uint32(mode)) 309 } 310 311 // DeleteBuffer deletes the given buffer object. 312 // 313 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteBuffers.xhtml 314 func DeleteBuffer(v Buffer) { 315 u := uint32(v) 316 gl.DeleteBuffers(1, &u) 317 } 318 319 // DeleteFramebuffer deletes the given framebuffer object. 320 // 321 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteFramebuffers.xhtml 322 func DeleteFramebuffer(v Framebuffer) { 323 u := uint32(v) 324 gl.DeleteFramebuffers(1, &u) 325 } 326 327 // DeleteProgram deletes the given program object. 328 // 329 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteProgram.xhtml 330 func DeleteProgram(p Program) { 331 gl.DeleteProgram(uint32(p)) 332 } 333 334 // DeleteRenderbuffer deletes the given render buffer object. 335 // 336 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteRenderbuffers.xhtml 337 func DeleteRenderbuffer(v Renderbuffer) { 338 u := uint32(v) 339 gl.DeleteRenderbuffers(1, &u) 340 } 341 342 // DeleteShader deletes shader s. 343 // 344 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteShader.xhtml 345 func DeleteShader(s Shader) { 346 gl.DeleteShader(uint32(s)) 347 } 348 349 // DeleteTexture deletes the given texture object. 350 // 351 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTextures.xhtml 352 func DeleteTexture(v Texture) { 353 u := uint32(v) 354 gl.DeleteTextures(1, &u) 355 } 356 357 // DeleteVertexArray deletes the given VAO. 358 // 359 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteVertexArrays.xhtml 360 func DeleteVertexArray(v VertexArray) { 361 u := uint32(v) 362 gl.DeleteVertexArrays(1, &u) 363 } 364 365 // DepthFunc sets the function used for depth buffer comparisons. 366 // 367 // Valid fn values: 368 // NEVER 369 // LESS 370 // EQUAL 371 // LEQUAL 372 // GREATER 373 // NOTEQUAL 374 // GEQUAL 375 // ALWAYS 376 // 377 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthFunc.xhtml 378 func DepthFunc(fn Enum) { 379 gl.DepthFunc(uint32(fn)) 380 } 381 382 // DepthMask sets the depth buffer enabled for writing. 383 // 384 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthMask.xhtml 385 func DepthMask(flag bool) { 386 gl.DepthMask(flag) 387 } 388 389 // DepthRangef sets the mapping from normalized device coordinates to 390 // window coordinates. 391 // 392 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDepthRangef.xhtml 393 func DepthRangef(n, f float32) { 394 gl.DepthRangef(n, f) 395 } 396 397 // DetachShader detaches the shader s from the program p. 398 // 399 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDetachShader.xhtml 400 func DetachShader(p Program, s Shader) { 401 gl.DetachShader(uint32(p), uint32(s)) 402 } 403 404 // Disable disables various GL capabilities. 405 // 406 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisable.xhtml 407 func Disable(cap Enum) { 408 gl.Disable(uint32(cap)) 409 } 410 411 // DisableVertexAttribArray disables a vertex attribute array. 412 // 413 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDisableVertexAttribArray.xhtml 414 func DisableVertexAttribArray(a Attrib) { 415 gl.DisableVertexAttribArray(uint32(a)) 416 } 417 418 // DrawArrays renders geometric primitives from the bound data. 419 // 420 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArrays.xhtml 421 func DrawArrays(mode Enum, first, count int) { 422 gl.DrawArrays(uint32(mode), int32(first), int32(count)) 423 } 424 425 // DrawElements renders primitives from a bound buffer. 426 // 427 // http://www.khronos.org/opengles/sdk/docs/man3/html/glDrawElements.xhtml 428 func DrawElements(mode Enum, count int, ty Enum, offset int) { 429 gl.DrawElements(uint32(mode), int32(count), uint32(ty), gl.PtrOffset(offset)) 430 } 431 432 // Enable enables various GL capabilities. 433 // 434 // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml 435 func Enable(cap Enum) { 436 gl.Enable(uint32(cap)) 437 } 438 439 // EnableVertexAttribArray enables a vertex attribute array. 440 // 441 // http://www.khronos.org/opengles/sdk/docs/man3/html/glEnableVertexAttribArray.xhtml 442 func EnableVertexAttribArray(a Attrib) { 443 gl.EnableVertexAttribArray(uint32(a)) 444 } 445 446 // Finish blocks until the effects of all previously called GL 447 // commands are complete. 448 // 449 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFinish.xhtml 450 func Finish() { 451 gl.Finish() 452 } 453 454 // Flush empties all buffers. It does not block. 455 // 456 // An OpenGL implementation may buffer network communication, 457 // the command stream, or data inside the graphics accelerator. 458 // 459 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFlush.xhtml 460 func Flush() { 461 gl.Flush() 462 } 463 464 // FramebufferRenderbuffer attaches rb to the current frame buffer. 465 // 466 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferRenderbuffer.xhtml 467 func FramebufferRenderbuffer(target, attachment, rbTarget Enum, rb Renderbuffer) { 468 gl.FramebufferRenderbuffer(uint32(target), uint32(attachment), uint32(rbTarget), uint32(rb)) 469 } 470 471 // FramebufferTexture2D attaches the t to the current frame buffer. 472 // 473 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferTexture2D.xhtml 474 func FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) { 475 gl.FramebufferTexture2D(uint32(target), uint32(attachment), uint32(texTarget), uint32(t), int32(level)) 476 } 477 478 // FrontFace defines which polygons are front-facing. 479 // 480 // Valid modes: CW, CCW. 481 // 482 // http://www.khronos.org/opengles/sdk/docs/man3/html/glFrontFace.xhtml 483 func FrontFace(mode Enum) { 484 gl.FrontFace(uint32(mode)) 485 } 486 487 // GenerateMipmap generates mipmaps for the current texture. 488 // 489 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenerateMipmap.xhtml 490 func GenerateMipmap(target Enum) { 491 gl.GenerateMipmap(uint32(target)) 492 } 493 494 // GetActiveAttrib returns details about an active attribute variable. 495 // A value of 0 for index selects the first active attribute variable. 496 // Permissible values for index range from 0 to the number of active 497 // attribute variables minus 1. 498 // 499 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveAttrib.xhtml 500 func GetActiveAttrib(p Program, index uint32) (name string, size int, ty Enum) { 501 var length, si int32 502 var typ uint32 503 name = strings.Repeat("\x00", 256) 504 cname := gl.Str(name) 505 gl.GetActiveAttrib(uint32(p), uint32(index), int32(len(name)-1), &length, &si, &typ, cname) 506 name = name[:strings.IndexRune(name, 0)] 507 return name, int(si), Enum(typ) 508 } 509 510 // GetActiveUniform returns details about an active uniform variable. 511 // A value of 0 for index selects the first active uniform variable. 512 // Permissible values for index range from 0 to the number of active 513 // uniform variables minus 1. 514 // 515 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetActiveUniform.xhtml 516 func GetActiveUniform(p Program, index uint32) (name string, size int, ty Enum) { 517 var length, si int32 518 var typ uint32 519 name = strings.Repeat("\x00", 256) 520 cname := gl.Str(name) 521 gl.GetActiveUniform(uint32(p), uint32(index), int32(len(name)-1), &length, &si, &typ, cname) 522 name = name[:strings.IndexRune(name, 0)] 523 return name, int(si), Enum(typ) 524 } 525 526 // GetAttachedShaders returns the shader objects attached to program p. 527 // 528 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttachedShaders.xhtml 529 func GetAttachedShaders(p Program) []Shader { 530 shadersLen := GetProgrami(p, ATTACHED_SHADERS) 531 var n int32 532 buf := make([]uint32, shadersLen) 533 gl.GetAttachedShaders(uint32(p), int32(shadersLen), &n, &buf[0]) 534 buf = buf[:int(n)] 535 shaders := make([]Shader, int(n)) 536 for i, s := range buf { 537 shaders[i] = Shader(uint32(s)) 538 } 539 return shaders 540 } 541 542 // GetAttribLocation returns the location of an attribute variable. 543 // 544 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetAttribLocation.xhtml 545 func GetAttribLocation(p Program, name string) Attrib { 546 return Attrib(gl.GetAttribLocation(uint32(p), gl.Str(name+"\x00"))) 547 } 548 549 // GetBooleanv returns the boolean values of parameter pname. 550 // 551 // Many boolean parameters can be queried more easily using IsEnabled. 552 // 553 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml 554 func GetBooleanv(dst []bool, pname Enum) { 555 gl.GetBooleanv(uint32(pname), &dst[0]) 556 } 557 558 // GetFloatv returns the float values of parameter pname. 559 // 560 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml 561 func GetFloatv(dst []float32, pname Enum) { 562 gl.GetFloatv(uint32(pname), &dst[0]) 563 } 564 565 // GetIntegerv returns the int values of parameter pname. 566 // 567 // Single values may be queried more easily using GetInteger. 568 // 569 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml 570 func GetIntegerv(pname Enum, data []int32) { 571 gl.GetIntegerv(uint32(pname), &data[0]) 572 } 573 574 // GetInteger returns the int value of parameter pname. 575 // 576 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGet.xhtml 577 func GetInteger(pname Enum) int { 578 var data int32 579 gl.GetIntegerv(uint32(pname), &data) 580 return int(data) 581 } 582 583 // GetBufferParameteri returns a parameter for the active buffer. 584 // 585 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetBufferParameteriv.xhtml 586 func GetBufferParameteri(target, pname Enum) int { 587 var params int32 588 gl.GetBufferParameteriv(uint32(target), uint32(pname), ¶ms) 589 return int(params) 590 } 591 592 // GetError returns the next error. 593 // 594 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetError.xhtml 595 func GetError() Enum { 596 return Enum(gl.GetError()) 597 } 598 599 // GetBoundFramebuffer returns the currently bound framebuffer. 600 // Use this method instead of gl.GetInteger(gl.FRAMEBUFFER_BINDING) to 601 // enable support on all platforms 602 func GetBoundFramebuffer() Framebuffer { 603 var b int32 604 gl.GetIntegerv(FRAMEBUFFER_BINDING, &b) 605 return Framebuffer(uint32(b)) 606 } 607 608 // GetFramebufferAttachmentParameteri returns attachment parameters 609 // for the active framebuffer object. 610 // 611 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetFramebufferAttachmentParameteriv.xhtml 612 func GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int { 613 var param int32 614 gl.GetFramebufferAttachmentParameteriv(uint32(target), uint32(attachment), uint32(pname), ¶m) 615 return int(param) 616 } 617 618 // GetProgrami returns a parameter value for a program. 619 // 620 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramiv.xhtml 621 func GetProgrami(p Program, pname Enum) int { 622 var result int32 623 gl.GetProgramiv(uint32(p), uint32(pname), &result) 624 return int(result) 625 } 626 627 // GetProgramInfoLog returns the information log for a program. 628 // 629 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramInfoLog.xhtml 630 func GetProgramInfoLog(p Program) string { 631 var logLength int32 632 gl.GetProgramiv(uint32(p), gl.INFO_LOG_LENGTH, &logLength) 633 if logLength == 0 { 634 return "" 635 } 636 637 logBuffer := make([]uint8, logLength) 638 gl.GetProgramInfoLog(uint32(p), logLength, nil, &logBuffer[0]) 639 return gl.GoStr(&logBuffer[0]) 640 } 641 642 // GetRenderbufferParameteri returns a parameter value for a render buffer. 643 // 644 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetRenderbufferParameteriv.xhtml 645 func GetRenderbufferParameteri(target, pname Enum) int { 646 var result int32 647 gl.GetRenderbufferParameteriv(uint32(target), uint32(pname), &result) 648 return int(result) 649 } 650 651 // GetShaderi returns a parameter value for a shader. 652 // 653 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderiv.xhtml 654 func GetShaderi(s Shader, pname Enum) int { 655 var result int32 656 gl.GetShaderiv(uint32(s), uint32(pname), &result) 657 return int(result) 658 } 659 660 // GetShaderInfoLog returns the information log for a shader. 661 // 662 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderInfoLog.xhtml 663 func GetShaderInfoLog(s Shader) string { 664 var logLength int32 665 gl.GetShaderiv(uint32(s), gl.INFO_LOG_LENGTH, &logLength) 666 if logLength == 0 { 667 return "" 668 } 669 670 logBuffer := make([]uint8, logLength) 671 gl.GetShaderInfoLog(uint32(s), logLength, nil, &logBuffer[0]) 672 return gl.GoStr(&logBuffer[0]) 673 } 674 675 // GetShaderPrecisionFormat returns range and precision limits for 676 // shader types. 677 // 678 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderPrecisionFormat.xhtml 679 func GetShaderPrecisionFormat(shadertype, precisiontype Enum) (rangeLow, rangeHigh, precision int) { 680 var cRange [2]int32 681 var cPrecision int32 682 683 gl.GetShaderPrecisionFormat(uint32(shadertype), uint32(precisiontype), &cRange[0], &cPrecision) 684 return int(cRange[0]), int(cRange[1]), int(cPrecision) 685 } 686 687 // GetShaderSource returns source code of shader s. 688 // 689 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetShaderSource.xhtml 690 func GetShaderSource(s Shader) string { 691 sourceLen := GetShaderi(s, gl.SHADER_SOURCE_LENGTH) 692 if sourceLen == 0 { 693 return "" 694 } 695 buf := make([]byte, sourceLen) 696 gl.GetShaderSource(uint32(s), int32(sourceLen), nil, &buf[0]) 697 return string(buf) 698 } 699 700 // GetString reports current GL state. 701 // 702 // Valid name values: 703 // EXTENSIONS 704 // RENDERER 705 // SHADING_LANGUAGE_VERSION 706 // VENDOR 707 // VERSION 708 // 709 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetString.xhtml 710 func GetString(pname Enum) string { 711 return gl.GoStr(gl.GetString(uint32(pname))) 712 } 713 714 // GetTexParameterfv returns the float values of a texture parameter. 715 // 716 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml 717 func GetTexParameterfv(dst []float32, target, pname Enum) { 718 gl.GetTexParameterfv(uint32(target), uint32(pname), &dst[0]) 719 } 720 721 // GetTexParameteriv returns the int values of a texture parameter. 722 // 723 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetTexParameter.xhtml 724 func GetTexParameteriv(dst []int32, target, pname Enum) { 725 gl.GetTexParameteriv(uint32(target), uint32(pname), &dst[0]) 726 } 727 728 // GetUniformfv returns the float values of a uniform variable. 729 // 730 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml 731 func GetUniformfv(dst []float32, src Uniform, p Program) { 732 gl.GetUniformfv(uint32(p), int32(src), &dst[0]) 733 } 734 735 // GetUniformiv returns the float values of a uniform variable. 736 // 737 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniform.xhtml 738 func GetUniformiv(dst []int32, src Uniform, p Program) { 739 gl.GetUniformiv(uint32(p), int32(src), &dst[0]) 740 } 741 742 // GetUniformLocation returns the location of a uniform variable. 743 // 744 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml 745 func GetUniformLocation(p Program, name string) Uniform { 746 return Uniform(gl.GetUniformLocation(uint32(p), gl.Str(name+"\x00"))) 747 } 748 749 // GetVertexAttribf reads the float value of a vertex attribute. 750 // 751 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml 752 func GetVertexAttribf(src Attrib, pname Enum) float32 { 753 var result float32 754 gl.GetVertexAttribfv(uint32(src), uint32(pname), &result) 755 return result 756 } 757 758 // GetVertexAttribfv reads float values of a vertex attribute. 759 // 760 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml 761 func GetVertexAttribfv(dst []float32, src Attrib, pname Enum) { 762 gl.GetVertexAttribfv(uint32(src), uint32(pname), &dst[0]) 763 } 764 765 // GetVertexAttribi reads the int value of a vertex attribute. 766 // 767 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml 768 func GetVertexAttribi(src Attrib, pname Enum) int32 { 769 var result int32 770 gl.GetVertexAttribiv(uint32(src), uint32(pname), &result) 771 return result 772 } 773 774 // GetVertexAttribiv reads int values of a vertex attribute. 775 // 776 // http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml 777 func GetVertexAttribiv(dst []int32, src Attrib, pname Enum) { 778 gl.GetVertexAttribiv(uint32(src), uint32(pname), &dst[0]) 779 } 780 781 // Hint sets implementation-specific modes. 782 // 783 // http://www.khronos.org/opengles/sdk/docs/man3/html/glHint.xhtml 784 func Hint(target, mode Enum) { 785 gl.Hint(uint32(target), uint32(mode)) 786 } 787 788 // IsBuffer reports if b is a valid buffer. 789 // 790 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsBuffer.xhtml 791 func IsBuffer(b Buffer) bool { 792 return gl.IsBuffer(uint32(b)) 793 } 794 795 // IsEnabled reports if cap is an enabled capability. 796 // 797 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsEnabled.xhtml 798 func IsEnabled(cap Enum) bool { 799 return gl.IsEnabled(uint32(cap)) 800 } 801 802 // IsFramebuffer reports if fb is a valid frame buffer. 803 // 804 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsFramebuffer.xhtml 805 func IsFramebuffer(fb Framebuffer) bool { 806 return gl.IsFramebuffer(uint32(fb)) 807 } 808 809 // IsProgram reports if p is a valid program object. 810 // 811 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsProgram.xhtml 812 func IsProgram(p Program) bool { 813 return gl.IsProgram(uint32(p)) 814 } 815 816 // IsRenderbuffer reports if rb is a valid render buffer. 817 // 818 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsRenderbuffer.xhtml 819 func IsRenderbuffer(rb Renderbuffer) bool { 820 return gl.IsRenderbuffer(uint32(rb)) 821 } 822 823 // IsShader reports if s is valid shader. 824 // 825 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsShader.xhtml 826 func IsShader(s Shader) bool { 827 return gl.IsShader(uint32(s)) 828 } 829 830 // IsTexture reports if t is a valid texture. 831 // 832 // http://www.khronos.org/opengles/sdk/docs/man3/html/glIsTexture.xhtml 833 func IsTexture(t Texture) bool { 834 return gl.IsTexture(uint32(t)) 835 } 836 837 // LineWidth specifies the width of lines. 838 // 839 // http://www.khronos.org/opengles/sdk/docs/man3/html/glLineWidth.xhtml 840 func LineWidth(width float32) { 841 gl.LineWidth(width) 842 } 843 844 // LinkProgram links the specified program. 845 // 846 // http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml 847 func LinkProgram(p Program) { 848 gl.LinkProgram(uint32(p)) 849 } 850 851 // PixelStorei sets pixel storage parameters. 852 // 853 // http://www.khronos.org/opengles/sdk/docs/man3/html/glPixelStorei.xhtml 854 func PixelStorei(pname Enum, param int32) { 855 gl.PixelStorei(uint32(pname), param) 856 } 857 858 // PolygonMode sets Polygon Mode. 859 // 860 // http://www.khronos.org/opengles/sdk/docs/man3/html/glPolygonMode.xhtml 861 func PolygonMode(face, mode Enum) { 862 gl.PolygonMode(uint32(face), uint32(mode)) 863 } 864 865 // PolygonOffset sets the scaling factors for depth offsets. 866 // 867 // http://www.khronos.org/opengles/sdk/docs/man3/html/glPolygonOffset.xhtml 868 func PolygonOffset(factor, units float32) { 869 gl.PolygonOffset(factor, units) 870 } 871 872 // ReadPixels returns pixel data from a buffer. 873 // 874 // http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml 875 func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) { 876 gl.ReadPixels(int32(x), int32(y), int32(width), int32(height), uint32(format), uint32(ty), gl.Ptr(&dst[0])) 877 } 878 879 // ReleaseShaderCompiler frees resources allocated by the shader compiler. 880 // 881 // http://www.khronos.org/opengles/sdk/docs/man3/html/glReleaseShaderCompiler.xhtml 882 func ReleaseShaderCompiler() { 883 gl.ReleaseShaderCompiler() 884 } 885 886 // RenderbufferStorage establishes the data storage, format, and 887 // dimensions of a renderbuffer object's image. 888 // 889 // http://www.khronos.org/opengles/sdk/docs/man3/html/glRenderbufferStorage.xhtml 890 func RenderbufferStorage(target, internalFormat Enum, width, height int) { 891 gl.RenderbufferStorage(uint32(target), uint32(internalFormat), int32(width), int32(height)) 892 } 893 894 // SampleCoverage sets multisample coverage parameters. 895 // 896 // http://www.khronos.org/opengles/sdk/docs/man3/html/glSampleCoverage.xhtml 897 func SampleCoverage(value float32, invert bool) { 898 gl.SampleCoverage(value, invert) 899 } 900 901 // Scissor defines the scissor box rectangle, in window coordinates. 902 // 903 // http://www.khronos.org/opengles/sdk/docs/man3/html/glScissor.xhtml 904 func Scissor(x, y, width, height int32) { 905 gl.Scissor(x, y, width, height) 906 } 907 908 // ShaderSource sets the source code of s to the given source code. 909 // 910 // http://www.khronos.org/opengles/sdk/docs/man3/html/glShaderSource.xhtml 911 func ShaderSource(s Shader, src string) { 912 glsource, free := gl.Strs(src + "\x00") 913 gl.ShaderSource(uint32(s), 1, glsource, nil) 914 free() 915 } 916 917 // StencilFunc sets the front and back stencil test reference value. 918 // 919 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFunc.xhtml 920 func StencilFunc(fn Enum, ref int, mask uint32) { 921 gl.StencilFunc(uint32(fn), int32(ref), mask) 922 } 923 924 // StencilFuncSeparate sets the front or back stencil test reference value. 925 // 926 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFuncSeparate.xhtml 927 func StencilFuncSeparate(face, fn Enum, ref int, mask uint32) { 928 gl.StencilFuncSeparate(uint32(face), uint32(fn), int32(ref), mask) 929 } 930 931 // StencilMask controls the writing of bits in the stencil planes. 932 // 933 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMask.xhtml 934 func StencilMask(mask uint32) { 935 gl.StencilMask(mask) 936 } 937 938 // StencilMaskSeparate controls the writing of bits in the stencil planes. 939 // 940 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilMaskSeparate.xhtml 941 func StencilMaskSeparate(face Enum, mask uint32) { 942 gl.StencilMaskSeparate(uint32(face), mask) 943 } 944 945 // StencilOp sets front and back stencil test actions. 946 // 947 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOp.xhtml 948 func StencilOp(fail, zfail, zpass Enum) { 949 gl.StencilOp(uint32(fail), uint32(zfail), uint32(zpass)) 950 } 951 952 // StencilOpSeparate sets front or back stencil tests. 953 // 954 // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilOpSeparate.xhtml 955 func StencilOpSeparate(face, sfail, dpfail, dppass Enum) { 956 gl.StencilOpSeparate(uint32(face), uint32(sfail), uint32(dpfail), uint32(dppass)) 957 } 958 959 // TexImage2D writes a 2D texture image. 960 // 961 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml 962 func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { 963 p := unsafe.Pointer(nil) 964 if len(data) > 0 { 965 p = gl.Ptr(&data[0]) 966 } 967 gl.TexImage2D(uint32(target), int32(level), int32(format), int32(width), int32(height), 0, uint32(format), uint32(ty), p) 968 } 969 970 // TexSubImage2D writes a subregion of a 2D texture image. 971 // 972 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexSubImage2D.xhtml 973 func TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) { 974 gl.TexSubImage2D(uint32(target), int32(level), int32(x), int32(y), int32(width), int32(height), uint32(format), uint32(ty), gl.Ptr(&data[0])) 975 } 976 977 // TexParameterf sets a float texture parameter. 978 // 979 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml 980 func TexParameterf(target, pname Enum, param float32) { 981 gl.TexParameterf(uint32(target), uint32(pname), param) 982 } 983 984 // TexParameterfv sets a float texture parameter array. 985 // 986 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml 987 func TexParameterfv(target, pname Enum, params []float32) { 988 gl.TexParameterfv(uint32(target), uint32(pname), ¶ms[0]) 989 } 990 991 // TexParameteri sets an integer texture parameter. 992 // 993 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml 994 func TexParameteri(target, pname Enum, param int) { 995 gl.TexParameteri(uint32(target), uint32(pname), int32(param)) 996 } 997 998 // TexParameteriv sets an integer texture parameter array. 999 // 1000 // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexParameter.xhtml 1001 func TexParameteriv(target, pname Enum, params []int32) { 1002 gl.TexParameteriv(uint32(target), uint32(pname), ¶ms[0]) 1003 } 1004 1005 // Uniform1f writes a float uniform variable. 1006 // 1007 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1008 func Uniform1f(dst Uniform, v float32) { 1009 if dst.Valid() { 1010 gl.Uniform1f(int32(dst), v) 1011 } 1012 } 1013 1014 // Uniform1fv writes a [len(src)]float uniform array. 1015 // 1016 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1017 func Uniform1fv(dst Uniform, src []float32) { 1018 if dst.Valid() { 1019 gl.Uniform1fv(int32(dst), int32(len(src)), &src[0]) 1020 } 1021 } 1022 1023 // Uniform1fvP Pointer version of Uniform1fv (faster) 1024 func Uniform1fvP(dst Uniform, count int32, value *float32) { 1025 if dst.Valid() { 1026 gl.Uniform1fv(int32(dst), count, value) 1027 } 1028 } 1029 1030 // Uniform1fvUP Unsafe Pointer version of Uniform1fv (faster) 1031 func Uniform1fvUP(dst Uniform, count int32, value unsafe.Pointer) { 1032 if dst.Valid() { 1033 gl.Uniform1fv(int32(dst), count, (*float32)(value)) 1034 } 1035 } 1036 1037 // Uniform1i writes an int uniform variable. 1038 // 1039 // Uniform1i and Uniform1iv are the only two functions that may be used 1040 // to load uniform variables defined as sampler types. Loading samplers 1041 // with any other function will result in a INVALID_OPERATION error. 1042 // 1043 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1044 func Uniform1i(dst Uniform, v int) { 1045 if dst.Valid() { 1046 gl.Uniform1i(int32(dst), int32(v)) 1047 } 1048 } 1049 1050 // Uniform1iv writes a int uniform array of len(src) elements. 1051 // 1052 // Uniform1i and Uniform1iv are the only two functions that may be used 1053 // to load uniform variables defined as sampler types. Loading samplers 1054 // with any other function will result in a INVALID_OPERATION error. 1055 // 1056 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1057 func Uniform1iv(dst Uniform, src []int32) { 1058 if dst.Valid() { 1059 gl.Uniform1iv(int32(dst), int32(len(src)), &src[0]) 1060 } 1061 } 1062 1063 // Uniform1ivP Pointer version of Uniform1iv (faster) 1064 func Uniform1ivP(dst Uniform, count int32, value *int32) { 1065 if dst.Valid() { 1066 gl.Uniform1iv(int32(dst), count, value) 1067 } 1068 } 1069 1070 // Uniform1ivUP Unsafe Pointer version of Uniform1iv (faster) 1071 func Uniform1ivUP(dst Uniform, count int32, value unsafe.Pointer) { 1072 if dst.Valid() { 1073 gl.Uniform1iv(int32(dst), count, (*int32)(value)) 1074 } 1075 } 1076 1077 // Uniform2f writes a vec2 uniform variable. 1078 // 1079 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1080 func Uniform2f(dst Uniform, v0, v1 float32) { 1081 if dst.Valid() { 1082 gl.Uniform2f(int32(dst), v0, v1) 1083 } 1084 } 1085 1086 // Uniform2fv writes a vec2 uniform array of len(src)/2 elements. 1087 // 1088 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1089 func Uniform2fv(dst Uniform, src []float32) { 1090 if dst.Valid() { 1091 gl.Uniform2fv(int32(dst), int32(len(src)/2), &src[0]) 1092 } 1093 } 1094 1095 // Uniform2fvP Pointer version of Uniform2fv (faster) 1096 func Uniform2fvP(dst Uniform, count int32, value *float32) { 1097 if dst.Valid() { 1098 gl.Uniform2fv(int32(dst), count, value) 1099 } 1100 } 1101 1102 // Uniform2fvUP Unsafe Pointer version of Uniform2fv (faster) 1103 func Uniform2fvUP(dst Uniform, count int32, value unsafe.Pointer) { 1104 if dst.Valid() { 1105 gl.Uniform2fv(int32(dst), count, (*float32)(value)) 1106 } 1107 } 1108 1109 // Uniform2i writes an ivec2 uniform variable. 1110 // 1111 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1112 func Uniform2i(dst Uniform, v0, v1 int) { 1113 if dst.Valid() { 1114 gl.Uniform2i(int32(dst), int32(v0), int32(v1)) 1115 } 1116 } 1117 1118 // Uniform2iv writes an ivec2 uniform array of len(src)/2 elements. 1119 // 1120 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1121 func Uniform2iv(dst Uniform, src []int32) { 1122 if dst.Valid() { 1123 gl.Uniform2iv(int32(dst), int32(len(src)/2), &src[0]) 1124 } 1125 } 1126 1127 // Uniform2ivP Pointer version of Uniform2iv (faster) 1128 func Uniform2ivP(dst Uniform, count int32, value *int32) { 1129 if dst.Valid() { 1130 gl.Uniform2iv(int32(dst), count, value) 1131 } 1132 } 1133 1134 // Uniform2ivUP Unsafe Pointer version of Uniform2iv (faster) 1135 func Uniform2ivUP(dst Uniform, count int32, value unsafe.Pointer) { 1136 if dst.Valid() { 1137 gl.Uniform2iv(int32(dst), count, (*int32)(value)) 1138 } 1139 } 1140 1141 // Uniform3f writes a vec3 uniform variable. 1142 // 1143 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1144 func Uniform3f(dst Uniform, v0, v1, v2 float32) { 1145 if dst.Valid() { 1146 gl.Uniform3f(int32(dst), v0, v1, v2) 1147 } 1148 } 1149 1150 // Uniform3fv writes a vec3 uniform array of len(src)/3 elements. 1151 // 1152 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1153 func Uniform3fv(dst Uniform, src []float32) { 1154 if dst.Valid() { 1155 gl.Uniform3fv(int32(dst), int32(len(src)/3), &src[0]) 1156 } 1157 } 1158 1159 // Uniform3fvP Pointer version of Uniform3fv (faster) 1160 func Uniform3fvP(dst Uniform, count int32, value *float32) { 1161 if dst.Valid() { 1162 gl.Uniform3fv(int32(dst), count, value) 1163 } 1164 } 1165 1166 // Uniform3fvUP Unsafe Pointer version of Uniform3fv (faster) 1167 func Uniform3fvUP(dst Uniform, count int32, value unsafe.Pointer) { 1168 if dst.Valid() { 1169 gl.Uniform3fv(int32(dst), count, (*float32)(value)) 1170 } 1171 } 1172 1173 // Uniform3i writes an ivec3 uniform variable. 1174 // 1175 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1176 func Uniform3i(dst Uniform, v0, v1, v2 int32) { 1177 if dst.Valid() { 1178 gl.Uniform3i(int32(dst), v0, v1, v2) 1179 } 1180 } 1181 1182 // Uniform3iv writes an ivec3 uniform array of len(src)/3 elements. 1183 // 1184 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1185 func Uniform3iv(dst Uniform, src []int32) { 1186 if dst.Valid() { 1187 gl.Uniform3iv(int32(dst), int32(len(src)/3), &src[0]) 1188 } 1189 } 1190 1191 // Uniform3ivP Pointer version of Uniform3iv (faster) 1192 func Uniform3ivP(dst Uniform, count int32, value *int32) { 1193 if dst.Valid() { 1194 gl.Uniform3iv(int32(dst), count, value) 1195 } 1196 } 1197 1198 // Uniform3ivUP Unsafe Pointer version of Uniform3iv (faster) 1199 func Uniform3ivUP(dst Uniform, count int32, value unsafe.Pointer) { 1200 if dst.Valid() { 1201 gl.Uniform3iv(int32(dst), count, (*int32)(value)) 1202 } 1203 } 1204 1205 // Uniform4f writes a vec4 uniform variable. 1206 // 1207 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1208 func Uniform4f(dst Uniform, v0, v1, v2, v3 float32) { 1209 if dst.Valid() { 1210 gl.Uniform4f(int32(dst), v0, v1, v2, v3) 1211 } 1212 } 1213 1214 // Uniform4fv writes a vec4 uniform array of len(src)/4 elements. 1215 // 1216 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1217 func Uniform4fv(dst Uniform, src []float32) { 1218 if dst.Valid() { 1219 gl.Uniform4fv(int32(dst), int32(len(src)/4), &src[0]) 1220 } 1221 } 1222 1223 // Uniform4fvP Pointer version of Uniform4fv (faster) 1224 func Uniform4fvP(dst Uniform, count int32, value *float32) { 1225 if dst.Valid() { 1226 gl.Uniform4fv(int32(dst), count, value) 1227 } 1228 } 1229 1230 // Uniform4fvUP Unsafe Pointer version of Uniform4fv (faster) 1231 func Uniform4fvUP(dst Uniform, count int32, value unsafe.Pointer) { 1232 if dst.Valid() { 1233 gl.Uniform4fv(int32(dst), count, (*float32)(value)) 1234 } 1235 } 1236 1237 // Uniform4i writes an ivec4 uniform variable. 1238 // 1239 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1240 func Uniform4i(dst Uniform, v0, v1, v2, v3 int32) { 1241 if dst.Valid() { 1242 gl.Uniform4i(int32(dst), v0, v1, v2, v3) 1243 } 1244 } 1245 1246 // Uniform4iv writes an ivec4 uniform array of len(src)/4 elements. 1247 // 1248 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1249 func Uniform4iv(dst Uniform, src []int32) { 1250 if dst.Valid() { 1251 gl.Uniform4iv(int32(dst), int32(len(src)/4), &src[0]) 1252 } 1253 } 1254 1255 // Uniform4ivP Pointer version of Uniform4iv (faster) 1256 func Uniform4ivP(dst Uniform, count int32, value *int32) { 1257 if dst.Valid() { 1258 gl.Uniform4iv(int32(dst), count, value) 1259 } 1260 } 1261 1262 // Uniform4ivUP Unsafe Pointer version of Uniform4iv (faster) 1263 func Uniform4ivUP(dst Uniform, count int32, value unsafe.Pointer) { 1264 if dst.Valid() { 1265 gl.Uniform4iv(int32(dst), count, (*int32)(value)) 1266 } 1267 } 1268 1269 // UniformMatrix2fv writes 2x2 matrices. Each matrix uses four 1270 // float32 values, so the number of matrices written is len(src)/4. 1271 // 1272 // Each matrix must be supplied in column major order. 1273 // 1274 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1275 func UniformMatrix2fv(dst Uniform, transpose bool, src []float32) { 1276 if dst.Valid() { 1277 gl.UniformMatrix2fv(int32(dst), int32(len(src)/(2*2)), transpose, &src[0]) 1278 } 1279 } 1280 1281 // UniformMatrix2fvP Pointer version of UniformMatrix2fv (faster) 1282 func UniformMatrix2fvP(dst Uniform, count int32, transpose bool, value *float32) { 1283 if dst.Valid() { 1284 gl.UniformMatrix2fv(int32(dst), count, transpose, value) 1285 } 1286 } 1287 1288 // UniformMatrix2fvUP Unsafe Pointer version of UniformMatrix2fv (faster) 1289 func UniformMatrix2fvUP(dst Uniform, count int32, transpose bool, value unsafe.Pointer) { 1290 if dst.Valid() { 1291 gl.UniformMatrix2fv(int32(dst), count, transpose, (*float32)(value)) 1292 } 1293 } 1294 1295 // UniformMatrix3fv writes 3x3 matrices. Each matrix uses nine 1296 // float32 values, so the number of matrices written is len(src)/9. 1297 // 1298 // Each matrix must be supplied in column major order. 1299 // 1300 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1301 func UniformMatrix3fv(dst Uniform, transpose bool, src []float32) { 1302 if dst.Valid() { 1303 gl.UniformMatrix3fv(int32(dst), int32(len(src)/(3*3)), transpose, &src[0]) 1304 } 1305 } 1306 1307 // UniformMatrix3fvP Pointer version of UniformMatrix3fv (faster) 1308 func UniformMatrix3fvP(dst Uniform, count int32, transpose bool, value *float32) { 1309 if dst.Valid() { 1310 gl.UniformMatrix3fv(int32(dst), count, transpose, value) 1311 } 1312 } 1313 1314 // UniformMatrix3fvUP Unsafe Pointer version of UniformMatrix3fv (faster) 1315 func UniformMatrix3fvUP(dst Uniform, count int32, transpose bool, value unsafe.Pointer) { 1316 if dst.Valid() { 1317 gl.UniformMatrix3fv(int32(dst), count, transpose, (*float32)(value)) 1318 } 1319 } 1320 1321 // UniformMatrix4fv writes 4x4 matrices. Each matrix uses 16 1322 // float32 values, so the number of matrices written is len(src)/16. 1323 // 1324 // Each matrix must be supplied in column major order. 1325 // 1326 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml 1327 func UniformMatrix4fv(dst Uniform, transpose bool, src []float32) { 1328 if dst.Valid() { 1329 gl.UniformMatrix4fv(int32(dst), int32(len(src)/(4*4)), transpose, &src[0]) 1330 } 1331 } 1332 1333 // UniformMatrix4fvP Pointer version of UniformMatrix4fv (faster) 1334 func UniformMatrix4fvP(dst Uniform, count int32, transpose bool, value *float32) { 1335 if dst.Valid() { 1336 gl.UniformMatrix4fv(int32(dst), count, transpose, value) 1337 } 1338 } 1339 1340 // UniformMatrix4fvUP Unsafe Pointer version of UniformMatrix4fv (faster) 1341 func UniformMatrix4fvUP(dst Uniform, count int32, transpose bool, value unsafe.Pointer) { 1342 if dst.Valid() { 1343 gl.UniformMatrix4fv(int32(dst), count, transpose, (*float32)(value)) 1344 } 1345 } 1346 1347 // UseProgram sets the active program. 1348 // 1349 // http://www.khronos.org/opengles/sdk/docs/man3/html/glUseProgram.xhtml 1350 func UseProgram(p Program) { 1351 gl.UseProgram(uint32(p)) 1352 } 1353 1354 // ValidateProgram checks to see whether the executables contained in 1355 // program can execute given the current OpenGL state. 1356 // 1357 // Typically only used for debugging. 1358 // 1359 // http://www.khronos.org/opengles/sdk/docs/man3/html/glValidateProgram.xhtml 1360 func ValidateProgram(p Program) { 1361 gl.ValidateProgram(uint32(p)) 1362 } 1363 1364 // VertexAttrib1f writes a float vertex attribute. 1365 // 1366 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1367 func VertexAttrib1f(dst Attrib, x float32) { 1368 gl.VertexAttrib1f(uint32(dst), x) 1369 } 1370 1371 // VertexAttrib1fv writes a float vertex attribute. 1372 // 1373 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1374 func VertexAttrib1fv(dst Attrib, src []float32) { 1375 gl.VertexAttrib1fv(uint32(dst), &src[0]) 1376 } 1377 1378 // VertexAttrib2f writes a vec2 vertex attribute. 1379 // 1380 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1381 func VertexAttrib2f(dst Attrib, x, y float32) { 1382 gl.VertexAttrib2f(uint32(dst), x, y) 1383 } 1384 1385 // VertexAttrib2fv writes a vec2 vertex attribute. 1386 // 1387 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1388 func VertexAttrib2fv(dst Attrib, src []float32) { 1389 gl.VertexAttrib2fv(uint32(dst), &src[0]) 1390 } 1391 1392 // VertexAttrib3f writes a vec3 vertex attribute. 1393 // 1394 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1395 func VertexAttrib3f(dst Attrib, x, y, z float32) { 1396 gl.VertexAttrib3f(uint32(dst), x, y, z) 1397 } 1398 1399 // VertexAttrib3fv writes a vec3 vertex attribute. 1400 // 1401 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1402 func VertexAttrib3fv(dst Attrib, src []float32) { 1403 gl.VertexAttrib3fv(uint32(dst), &src[0]) 1404 } 1405 1406 // VertexAttrib4f writes a vec4 vertex attribute. 1407 // 1408 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1409 func VertexAttrib4f(dst Attrib, x, y, z, w float32) { 1410 gl.VertexAttrib4f(uint32(dst), x, y, z, w) 1411 } 1412 1413 // VertexAttrib4fv writes a vec4 vertex attribute. 1414 // 1415 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttrib.xhtml 1416 func VertexAttrib4fv(dst Attrib, src []float32) { 1417 gl.VertexAttrib4fv(uint32(dst), &src[0]) 1418 } 1419 1420 // VertexAttribPointer uses a bound buffer to define vertex attribute data. 1421 // 1422 // http://www.khronos.org/opengles/sdk/docs/man3/html/glVertexAttribPointer.xhtml 1423 func VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) { 1424 gl.VertexAttribPointer(uint32(dst), int32(size), uint32(ty), normalized, int32(stride), gl.PtrOffset(offset)) 1425 } 1426 1427 // Viewport sets the viewport, an affine transformation that 1428 // normalizes device coordinates to window coordinates. 1429 // 1430 // http://www.khronos.org/opengles/sdk/docs/man3/html/glViewport.xhtml 1431 func Viewport(x, y, width, height int) { 1432 gl.Viewport(int32(x), int32(y), int32(width), int32(height)) 1433 }