github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/internal/gl/gl_windows.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package gl
     4  
     5  import (
     6  	"math"
     7  	"runtime"
     8  	"syscall"
     9  	"unsafe"
    10  
    11  	"golang.org/x/sys/windows"
    12  )
    13  
    14  var (
    15  	LibGLESv2                              = windows.NewLazyDLL("libGLESv2.dll")
    16  	_glActiveTexture                       = LibGLESv2.NewProc("glActiveTexture")
    17  	_glAttachShader                        = LibGLESv2.NewProc("glAttachShader")
    18  	_glBeginQuery                          = LibGLESv2.NewProc("glBeginQuery")
    19  	_glBindAttribLocation                  = LibGLESv2.NewProc("glBindAttribLocation")
    20  	_glBindBuffer                          = LibGLESv2.NewProc("glBindBuffer")
    21  	_glBindBufferBase                      = LibGLESv2.NewProc("glBindBufferBase")
    22  	_glBindFramebuffer                     = LibGLESv2.NewProc("glBindFramebuffer")
    23  	_glBindRenderbuffer                    = LibGLESv2.NewProc("glBindRenderbuffer")
    24  	_glBindTexture                         = LibGLESv2.NewProc("glBindTexture")
    25  	_glBindVertexArray                     = LibGLESv2.NewProc("glBindVertexArray")
    26  	_glBlendEquation                       = LibGLESv2.NewProc("glBlendEquation")
    27  	_glBlendFuncSeparate                   = LibGLESv2.NewProc("glBlendFuncSeparate")
    28  	_glBufferData                          = LibGLESv2.NewProc("glBufferData")
    29  	_glBufferSubData                       = LibGLESv2.NewProc("glBufferSubData")
    30  	_glCheckFramebufferStatus              = LibGLESv2.NewProc("glCheckFramebufferStatus")
    31  	_glClear                               = LibGLESv2.NewProc("glClear")
    32  	_glClearColor                          = LibGLESv2.NewProc("glClearColor")
    33  	_glClearDepthf                         = LibGLESv2.NewProc("glClearDepthf")
    34  	_glDeleteQueries                       = LibGLESv2.NewProc("glDeleteQueries")
    35  	_glDeleteVertexArrays                  = LibGLESv2.NewProc("glDeleteVertexArrays")
    36  	_glCompileShader                       = LibGLESv2.NewProc("glCompileShader")
    37  	_glGenBuffers                          = LibGLESv2.NewProc("glGenBuffers")
    38  	_glGenFramebuffers                     = LibGLESv2.NewProc("glGenFramebuffers")
    39  	_glGenVertexArrays                     = LibGLESv2.NewProc("glGenVertexArrays")
    40  	_glGetUniformBlockIndex                = LibGLESv2.NewProc("glGetUniformBlockIndex")
    41  	_glCreateProgram                       = LibGLESv2.NewProc("glCreateProgram")
    42  	_glGenRenderbuffers                    = LibGLESv2.NewProc("glGenRenderbuffers")
    43  	_glCreateShader                        = LibGLESv2.NewProc("glCreateShader")
    44  	_glGenTextures                         = LibGLESv2.NewProc("glGenTextures")
    45  	_glDeleteBuffers                       = LibGLESv2.NewProc("glDeleteBuffers")
    46  	_glDeleteFramebuffers                  = LibGLESv2.NewProc("glDeleteFramebuffers")
    47  	_glDeleteProgram                       = LibGLESv2.NewProc("glDeleteProgram")
    48  	_glDeleteShader                        = LibGLESv2.NewProc("glDeleteShader")
    49  	_glDeleteRenderbuffers                 = LibGLESv2.NewProc("glDeleteRenderbuffers")
    50  	_glDeleteTextures                      = LibGLESv2.NewProc("glDeleteTextures")
    51  	_glDepthFunc                           = LibGLESv2.NewProc("glDepthFunc")
    52  	_glDepthMask                           = LibGLESv2.NewProc("glDepthMask")
    53  	_glDisableVertexAttribArray            = LibGLESv2.NewProc("glDisableVertexAttribArray")
    54  	_glDisable                             = LibGLESv2.NewProc("glDisable")
    55  	_glDrawArrays                          = LibGLESv2.NewProc("glDrawArrays")
    56  	_glDrawElements                        = LibGLESv2.NewProc("glDrawElements")
    57  	_glEnable                              = LibGLESv2.NewProc("glEnable")
    58  	_glEnableVertexAttribArray             = LibGLESv2.NewProc("glEnableVertexAttribArray")
    59  	_glEndQuery                            = LibGLESv2.NewProc("glEndQuery")
    60  	_glFinish                              = LibGLESv2.NewProc("glFinish")
    61  	_glFlush                               = LibGLESv2.NewProc("glFlush")
    62  	_glFramebufferRenderbuffer             = LibGLESv2.NewProc("glFramebufferRenderbuffer")
    63  	_glFramebufferTexture2D                = LibGLESv2.NewProc("glFramebufferTexture2D")
    64  	_glGenQueries                          = LibGLESv2.NewProc("glGenQueries")
    65  	_glGetError                            = LibGLESv2.NewProc("glGetError")
    66  	_glGetRenderbufferParameteriv          = LibGLESv2.NewProc("glGetRenderbufferParameteriv")
    67  	_glGetFloatv                           = LibGLESv2.NewProc("glGetFloatv")
    68  	_glGetFramebufferAttachmentParameteriv = LibGLESv2.NewProc("glGetFramebufferAttachmentParameteriv")
    69  	_glGetIntegerv                         = LibGLESv2.NewProc("glGetIntegerv")
    70  	_glGetIntegeri_v                       = LibGLESv2.NewProc("glGetIntegeri_v")
    71  	_glGetProgramiv                        = LibGLESv2.NewProc("glGetProgramiv")
    72  	_glGetProgramInfoLog                   = LibGLESv2.NewProc("glGetProgramInfoLog")
    73  	_glGetQueryObjectuiv                   = LibGLESv2.NewProc("glGetQueryObjectuiv")
    74  	_glGetShaderiv                         = LibGLESv2.NewProc("glGetShaderiv")
    75  	_glGetShaderInfoLog                    = LibGLESv2.NewProc("glGetShaderInfoLog")
    76  	_glGetString                           = LibGLESv2.NewProc("glGetString")
    77  	_glGetUniformLocation                  = LibGLESv2.NewProc("glGetUniformLocation")
    78  	_glGetVertexAttribiv                   = LibGLESv2.NewProc("glGetVertexAttribiv")
    79  	_glGetVertexAttribPointerv             = LibGLESv2.NewProc("glGetVertexAttribPointerv")
    80  	_glInvalidateFramebuffer               = LibGLESv2.NewProc("glInvalidateFramebuffer")
    81  	_glIsEnabled                           = LibGLESv2.NewProc("glIsEnabled")
    82  	_glLinkProgram                         = LibGLESv2.NewProc("glLinkProgram")
    83  	_glPixelStorei                         = LibGLESv2.NewProc("glPixelStorei")
    84  	_glReadPixels                          = LibGLESv2.NewProc("glReadPixels")
    85  	_glRenderbufferStorage                 = LibGLESv2.NewProc("glRenderbufferStorage")
    86  	_glScissor                             = LibGLESv2.NewProc("glScissor")
    87  	_glShaderSource                        = LibGLESv2.NewProc("glShaderSource")
    88  	_glTexImage2D                          = LibGLESv2.NewProc("glTexImage2D")
    89  	_glTexStorage2D                        = LibGLESv2.NewProc("glTexStorage2D")
    90  	_glTexSubImage2D                       = LibGLESv2.NewProc("glTexSubImage2D")
    91  	_glTexParameteri                       = LibGLESv2.NewProc("glTexParameteri")
    92  	_glUniformBlockBinding                 = LibGLESv2.NewProc("glUniformBlockBinding")
    93  	_glUniform1f                           = LibGLESv2.NewProc("glUniform1f")
    94  	_glUniform1i                           = LibGLESv2.NewProc("glUniform1i")
    95  	_glUniform2f                           = LibGLESv2.NewProc("glUniform2f")
    96  	_glUniform3f                           = LibGLESv2.NewProc("glUniform3f")
    97  	_glUniform4f                           = LibGLESv2.NewProc("glUniform4f")
    98  	_glUseProgram                          = LibGLESv2.NewProc("glUseProgram")
    99  	_glVertexAttribPointer                 = LibGLESv2.NewProc("glVertexAttribPointer")
   100  	_glViewport                            = LibGLESv2.NewProc("glViewport")
   101  )
   102  
   103  type Functions struct {
   104  	// Query caches.
   105  	int32s   [100]int32
   106  	float32s [100]float32
   107  	uintptrs [100]uintptr
   108  }
   109  
   110  type Context interface{}
   111  
   112  func NewFunctions(ctx Context, forceES bool) (*Functions, error) {
   113  	if ctx != nil {
   114  		panic("non-nil context")
   115  	}
   116  	return new(Functions), nil
   117  }
   118  
   119  func (c *Functions) ActiveTexture(t Enum) {
   120  	syscall.Syscall(_glActiveTexture.Addr(), 1, uintptr(t), 0, 0)
   121  }
   122  func (c *Functions) AttachShader(p Program, s Shader) {
   123  	syscall.Syscall(_glAttachShader.Addr(), 2, uintptr(p.V), uintptr(s.V), 0)
   124  }
   125  func (f *Functions) BeginQuery(target Enum, query Query) {
   126  	syscall.Syscall(_glBeginQuery.Addr(), 2, uintptr(target), uintptr(query.V), 0)
   127  }
   128  func (c *Functions) BindAttribLocation(p Program, a Attrib, name string) {
   129  	cname := cString(name)
   130  	c0 := &cname[0]
   131  	syscall.Syscall(_glBindAttribLocation.Addr(), 3, uintptr(p.V), uintptr(a), uintptr(unsafe.Pointer(c0)))
   132  	issue34474KeepAlive(c)
   133  }
   134  func (c *Functions) BindBuffer(target Enum, b Buffer) {
   135  	syscall.Syscall(_glBindBuffer.Addr(), 2, uintptr(target), uintptr(b.V), 0)
   136  }
   137  func (c *Functions) BindBufferBase(target Enum, index int, b Buffer) {
   138  	syscall.Syscall(_glBindBufferBase.Addr(), 3, uintptr(target), uintptr(index), uintptr(b.V))
   139  }
   140  func (c *Functions) BindFramebuffer(target Enum, fb Framebuffer) {
   141  	syscall.Syscall(_glBindFramebuffer.Addr(), 2, uintptr(target), uintptr(fb.V), 0)
   142  }
   143  func (c *Functions) BindRenderbuffer(target Enum, rb Renderbuffer) {
   144  	syscall.Syscall(_glBindRenderbuffer.Addr(), 2, uintptr(target), uintptr(rb.V), 0)
   145  }
   146  func (f *Functions) BindImageTexture(unit int, t Texture, level int, layered bool, layer int, access, format Enum) {
   147  	panic("not implemented")
   148  }
   149  func (c *Functions) BindTexture(target Enum, t Texture) {
   150  	syscall.Syscall(_glBindTexture.Addr(), 2, uintptr(target), uintptr(t.V), 0)
   151  }
   152  func (c *Functions) BindVertexArray(a VertexArray) {
   153  	syscall.Syscall(_glBindVertexArray.Addr(), 1, uintptr(a.V), 0, 0)
   154  }
   155  func (c *Functions) BlendEquation(mode Enum) {
   156  	syscall.Syscall(_glBlendEquation.Addr(), 1, uintptr(mode), 0, 0)
   157  }
   158  func (c *Functions) BlendFuncSeparate(srcRGB, dstRGB, srcA, dstA Enum) {
   159  	syscall.Syscall6(_glBlendFuncSeparate.Addr(), 4, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcA), uintptr(dstA), 0, 0)
   160  }
   161  func (f *Functions) BlitFramebuffer(sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1 int, mask Enum, filter Enum) {
   162  	panic("not implemented")
   163  }
   164  func (c *Functions) BufferData(target Enum, size int, usage Enum) {
   165  	syscall.Syscall6(_glBufferData.Addr(), 4, uintptr(target), uintptr(size), 0, uintptr(usage), 0, 0)
   166  }
   167  func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
   168  	if n := len(src); n > 0 {
   169  		s0 := &src[0]
   170  		syscall.Syscall6(_glBufferSubData.Addr(), 4, uintptr(target), uintptr(offset), uintptr(n), uintptr(unsafe.Pointer(s0)), 0, 0)
   171  		issue34474KeepAlive(s0)
   172  	}
   173  }
   174  func (c *Functions) CheckFramebufferStatus(target Enum) Enum {
   175  	s, _, _ := syscall.Syscall(_glCheckFramebufferStatus.Addr(), 1, uintptr(target), 0, 0)
   176  	return Enum(s)
   177  }
   178  func (c *Functions) Clear(mask Enum) {
   179  	syscall.Syscall(_glClear.Addr(), 1, uintptr(mask), 0, 0)
   180  }
   181  func (c *Functions) ClearColor(red, green, blue, alpha float32) {
   182  	syscall.Syscall6(_glClearColor.Addr(), 4, uintptr(math.Float32bits(red)), uintptr(math.Float32bits(green)), uintptr(math.Float32bits(blue)), uintptr(math.Float32bits(alpha)), 0, 0)
   183  }
   184  func (c *Functions) ClearDepthf(d float32) {
   185  	syscall.Syscall(_glClearDepthf.Addr(), 1, uintptr(math.Float32bits(d)), 0, 0)
   186  }
   187  func (c *Functions) CompileShader(s Shader) {
   188  	syscall.Syscall(_glCompileShader.Addr(), 1, uintptr(s.V), 0, 0)
   189  }
   190  func (c *Functions) CreateBuffer() Buffer {
   191  	var buf uintptr
   192  	syscall.Syscall(_glGenBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&buf)), 0)
   193  	return Buffer{uint(buf)}
   194  }
   195  func (c *Functions) CreateFramebuffer() Framebuffer {
   196  	var fb uintptr
   197  	syscall.Syscall(_glGenFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&fb)), 0)
   198  	return Framebuffer{uint(fb)}
   199  }
   200  func (c *Functions) CreateProgram() Program {
   201  	p, _, _ := syscall.Syscall(_glCreateProgram.Addr(), 0, 0, 0, 0)
   202  	return Program{uint(p)}
   203  }
   204  func (f *Functions) CreateQuery() Query {
   205  	var q uintptr
   206  	syscall.Syscall(_glGenQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&q)), 0)
   207  	return Query{uint(q)}
   208  }
   209  func (c *Functions) CreateRenderbuffer() Renderbuffer {
   210  	var rb uintptr
   211  	syscall.Syscall(_glGenRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&rb)), 0)
   212  	return Renderbuffer{uint(rb)}
   213  }
   214  func (c *Functions) CreateShader(ty Enum) Shader {
   215  	s, _, _ := syscall.Syscall(_glCreateShader.Addr(), 1, uintptr(ty), 0, 0)
   216  	return Shader{uint(s)}
   217  }
   218  func (c *Functions) CreateTexture() Texture {
   219  	var t uintptr
   220  	syscall.Syscall(_glGenTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
   221  	return Texture{uint(t)}
   222  }
   223  func (c *Functions) CreateVertexArray() VertexArray {
   224  	var t uintptr
   225  	syscall.Syscall(_glGenVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
   226  	return VertexArray{uint(t)}
   227  }
   228  func (c *Functions) DeleteBuffer(v Buffer) {
   229  	syscall.Syscall(_glDeleteBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v)), 0)
   230  }
   231  func (c *Functions) DeleteFramebuffer(v Framebuffer) {
   232  	syscall.Syscall(_glDeleteFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
   233  }
   234  func (c *Functions) DeleteProgram(p Program) {
   235  	syscall.Syscall(_glDeleteProgram.Addr(), 1, uintptr(p.V), 0, 0)
   236  }
   237  func (f *Functions) DeleteQuery(query Query) {
   238  	syscall.Syscall(_glDeleteQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&query.V)), 0)
   239  }
   240  func (c *Functions) DeleteShader(s Shader) {
   241  	syscall.Syscall(_glDeleteShader.Addr(), 1, uintptr(s.V), 0, 0)
   242  }
   243  func (c *Functions) DeleteRenderbuffer(v Renderbuffer) {
   244  	syscall.Syscall(_glDeleteRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
   245  }
   246  func (c *Functions) DeleteTexture(v Texture) {
   247  	syscall.Syscall(_glDeleteTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
   248  }
   249  func (f *Functions) DeleteVertexArray(array VertexArray) {
   250  	syscall.Syscall(_glDeleteVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&array.V)), 0)
   251  }
   252  func (c *Functions) DepthFunc(f Enum) {
   253  	syscall.Syscall(_glDepthFunc.Addr(), 1, uintptr(f), 0, 0)
   254  }
   255  func (c *Functions) DepthMask(mask bool) {
   256  	var m uintptr
   257  	if mask {
   258  		m = 1
   259  	}
   260  	syscall.Syscall(_glDepthMask.Addr(), 1, m, 0, 0)
   261  }
   262  func (c *Functions) DisableVertexAttribArray(a Attrib) {
   263  	syscall.Syscall(_glDisableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
   264  }
   265  func (c *Functions) Disable(cap Enum) {
   266  	syscall.Syscall(_glDisable.Addr(), 1, uintptr(cap), 0, 0)
   267  }
   268  func (c *Functions) DrawArrays(mode Enum, first, count int) {
   269  	syscall.Syscall(_glDrawArrays.Addr(), 3, uintptr(mode), uintptr(first), uintptr(count))
   270  }
   271  func (c *Functions) DrawElements(mode Enum, count int, ty Enum, offset int) {
   272  	syscall.Syscall6(_glDrawElements.Addr(), 4, uintptr(mode), uintptr(count), uintptr(ty), uintptr(offset), 0, 0)
   273  }
   274  func (f *Functions) DispatchCompute(x, y, z int) {
   275  	panic("not implemented")
   276  }
   277  func (c *Functions) Enable(cap Enum) {
   278  	syscall.Syscall(_glEnable.Addr(), 1, uintptr(cap), 0, 0)
   279  }
   280  func (c *Functions) EnableVertexAttribArray(a Attrib) {
   281  	syscall.Syscall(_glEnableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
   282  }
   283  func (f *Functions) EndQuery(target Enum) {
   284  	syscall.Syscall(_glEndQuery.Addr(), 1, uintptr(target), 0, 0)
   285  }
   286  func (c *Functions) Finish() {
   287  	syscall.Syscall(_glFinish.Addr(), 0, 0, 0, 0)
   288  }
   289  func (c *Functions) Flush() {
   290  	syscall.Syscall(_glFlush.Addr(), 0, 0, 0, 0)
   291  }
   292  func (c *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
   293  	syscall.Syscall6(_glFramebufferRenderbuffer.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(renderbuffertarget), uintptr(renderbuffer.V), 0, 0)
   294  }
   295  func (c *Functions) FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
   296  	syscall.Syscall6(_glFramebufferTexture2D.Addr(), 5, uintptr(target), uintptr(attachment), uintptr(texTarget), uintptr(t.V), uintptr(level), 0)
   297  }
   298  func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
   299  	cname := cString(name)
   300  	c0 := &cname[0]
   301  	u, _, _ := syscall.Syscall(_glGetUniformBlockIndex.Addr(), 2, uintptr(p.V), uintptr(unsafe.Pointer(c0)), 0)
   302  	issue34474KeepAlive(c0)
   303  	return uint(u)
   304  }
   305  func (c *Functions) GetBinding(pname Enum) Object {
   306  	return Object{uint(c.GetInteger(pname))}
   307  }
   308  func (c *Functions) GetBindingi(pname Enum, idx int) Object {
   309  	return Object{uint(c.GetIntegeri(pname, idx))}
   310  }
   311  func (c *Functions) GetError() Enum {
   312  	e, _, _ := syscall.Syscall(_glGetError.Addr(), 0, 0, 0, 0)
   313  	return Enum(e)
   314  }
   315  func (c *Functions) GetRenderbufferParameteri(target, pname Enum) int {
   316  	syscall.Syscall(_glGetRenderbufferParameteriv.Addr(), 3, uintptr(target), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
   317  	return int(c.int32s[0])
   318  }
   319  func (c *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
   320  	syscall.Syscall6(_glGetFramebufferAttachmentParameteriv.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0, 0)
   321  	return int(c.int32s[0])
   322  }
   323  func (c *Functions) GetInteger4(pname Enum) [4]int {
   324  	syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
   325  	var r [4]int
   326  	for i := range r {
   327  		r[i] = int(c.int32s[i])
   328  	}
   329  	return r
   330  }
   331  func (c *Functions) GetInteger(pname Enum) int {
   332  	syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
   333  	return int(c.int32s[0])
   334  }
   335  func (c *Functions) GetIntegeri(pname Enum, idx int) int {
   336  	syscall.Syscall(_glGetIntegeri_v.Addr(), 3, uintptr(pname), uintptr(idx), uintptr(unsafe.Pointer(&c.int32s[0])))
   337  	return int(c.int32s[0])
   338  }
   339  func (c *Functions) GetFloat(pname Enum) float32 {
   340  	syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
   341  	return c.float32s[0]
   342  }
   343  func (c *Functions) GetFloat4(pname Enum) [4]float32 {
   344  	syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
   345  	var r [4]float32
   346  	copy(r[:], c.float32s[:])
   347  	return r
   348  }
   349  func (c *Functions) GetProgrami(p Program, pname Enum) int {
   350  	syscall.Syscall(_glGetProgramiv.Addr(), 3, uintptr(p.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
   351  	return int(c.int32s[0])
   352  }
   353  func (c *Functions) GetProgramInfoLog(p Program) string {
   354  	n := c.GetProgrami(p, INFO_LOG_LENGTH)
   355  	buf := make([]byte, n)
   356  	syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
   357  	return string(buf)
   358  }
   359  func (c *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
   360  	syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
   361  	return uint(c.int32s[0])
   362  }
   363  func (c *Functions) GetShaderi(s Shader, pname Enum) int {
   364  	syscall.Syscall(_glGetShaderiv.Addr(), 3, uintptr(s.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
   365  	return int(c.int32s[0])
   366  }
   367  func (c *Functions) GetShaderInfoLog(s Shader) string {
   368  	n := c.GetShaderi(s, INFO_LOG_LENGTH)
   369  	buf := make([]byte, n)
   370  	syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
   371  	return string(buf)
   372  }
   373  func (c *Functions) GetString(pname Enum) string {
   374  	s, _, _ := syscall.Syscall(_glGetString.Addr(), 1, uintptr(pname), 0, 0)
   375  	return windows.BytePtrToString((*byte)(unsafe.Pointer(s)))
   376  }
   377  func (c *Functions) GetUniformLocation(p Program, name string) Uniform {
   378  	cname := cString(name)
   379  	c0 := &cname[0]
   380  	u, _, _ := syscall.Syscall(_glGetUniformLocation.Addr(), 2, uintptr(p.V), uintptr(unsafe.Pointer(c0)), 0)
   381  	issue34474KeepAlive(c0)
   382  	return Uniform{int(u)}
   383  }
   384  func (c *Functions) GetVertexAttrib(index int, pname Enum) int {
   385  	syscall.Syscall(_glGetVertexAttribiv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
   386  	return int(c.int32s[0])
   387  }
   388  
   389  func (c *Functions) GetVertexAttribBinding(index int, pname Enum) Object {
   390  	return Object{uint(c.GetVertexAttrib(index, pname))}
   391  }
   392  
   393  func (c *Functions) GetVertexAttribPointer(index int, pname Enum) uintptr {
   394  	syscall.Syscall(_glGetVertexAttribPointerv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.uintptrs[0])))
   395  	return c.uintptrs[0]
   396  }
   397  func (c *Functions) InvalidateFramebuffer(target, attachment Enum) {
   398  	addr := _glInvalidateFramebuffer.Addr()
   399  	if addr == 0 {
   400  		// InvalidateFramebuffer is just a hint. Skip it if not supported.
   401  		return
   402  	}
   403  	syscall.Syscall(addr, 3, uintptr(target), 1, uintptr(unsafe.Pointer(&attachment)))
   404  }
   405  func (f *Functions) IsEnabled(cap Enum) bool {
   406  	u, _, _ := syscall.Syscall(_glIsEnabled.Addr(), 1, uintptr(cap), 0, 0)
   407  	return u == TRUE
   408  }
   409  func (c *Functions) LinkProgram(p Program) {
   410  	syscall.Syscall(_glLinkProgram.Addr(), 1, uintptr(p.V), 0, 0)
   411  }
   412  func (c *Functions) PixelStorei(pname Enum, param int32) {
   413  	syscall.Syscall(_glPixelStorei.Addr(), 2, uintptr(pname), uintptr(param), 0)
   414  }
   415  func (f *Functions) MemoryBarrier(barriers Enum) {
   416  	panic("not implemented")
   417  }
   418  func (f *Functions) MapBufferRange(target Enum, offset, length int, access Enum) []byte {
   419  	panic("not implemented")
   420  }
   421  func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
   422  	d0 := &data[0]
   423  	syscall.Syscall9(_glReadPixels.Addr(), 7, uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)), 0, 0)
   424  	issue34474KeepAlive(d0)
   425  }
   426  func (c *Functions) RenderbufferStorage(target, internalformat Enum, width, height int) {
   427  	syscall.Syscall6(_glRenderbufferStorage.Addr(), 4, uintptr(target), uintptr(internalformat), uintptr(width), uintptr(height), 0, 0)
   428  }
   429  func (c *Functions) Scissor(x, y, width, height int32) {
   430  	syscall.Syscall6(_glScissor.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
   431  }
   432  func (c *Functions) ShaderSource(s Shader, src string) {
   433  	var n uintptr = uintptr(len(src))
   434  	psrc := &src
   435  	syscall.Syscall6(_glShaderSource.Addr(), 4, uintptr(s.V), 1, uintptr(unsafe.Pointer(psrc)), uintptr(unsafe.Pointer(&n)), 0, 0)
   436  	issue34474KeepAlive(psrc)
   437  }
   438  func (f *Functions) TexImage2D(target Enum, level int, internalFormat Enum, width int, height int, format Enum, ty Enum) {
   439  	syscall.Syscall9(_glTexImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(internalFormat), uintptr(width), uintptr(height), 0, uintptr(format), uintptr(ty), 0)
   440  }
   441  func (f *Functions) TexStorage2D(target Enum, levels int, internalFormat Enum, width, height int) {
   442  	syscall.Syscall6(_glTexStorage2D.Addr(), 5, uintptr(target), uintptr(levels), uintptr(internalFormat), uintptr(width), uintptr(height), 0)
   443  }
   444  func (c *Functions) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
   445  	d0 := &data[0]
   446  	syscall.Syscall9(_glTexSubImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)))
   447  	issue34474KeepAlive(d0)
   448  }
   449  func (c *Functions) TexParameteri(target, pname Enum, param int) {
   450  	syscall.Syscall(_glTexParameteri.Addr(), 3, uintptr(target), uintptr(pname), uintptr(param))
   451  }
   452  func (f *Functions) UniformBlockBinding(p Program, uniformBlockIndex uint, uniformBlockBinding uint) {
   453  	syscall.Syscall(_glUniformBlockBinding.Addr(), 3, uintptr(p.V), uintptr(uniformBlockIndex), uintptr(uniformBlockBinding))
   454  }
   455  func (c *Functions) Uniform1f(dst Uniform, v float32) {
   456  	syscall.Syscall(_glUniform1f.Addr(), 2, uintptr(dst.V), uintptr(math.Float32bits(v)), 0)
   457  }
   458  func (c *Functions) Uniform1i(dst Uniform, v int) {
   459  	syscall.Syscall(_glUniform1i.Addr(), 2, uintptr(dst.V), uintptr(v), 0)
   460  }
   461  func (c *Functions) Uniform2f(dst Uniform, v0, v1 float32) {
   462  	syscall.Syscall(_glUniform2f.Addr(), 3, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)))
   463  }
   464  func (c *Functions) Uniform3f(dst Uniform, v0, v1, v2 float32) {
   465  	syscall.Syscall6(_glUniform3f.Addr(), 4, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), 0, 0)
   466  }
   467  func (c *Functions) Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
   468  	syscall.Syscall6(_glUniform4f.Addr(), 5, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), uintptr(math.Float32bits(v3)), 0)
   469  }
   470  func (c *Functions) UseProgram(p Program) {
   471  	syscall.Syscall(_glUseProgram.Addr(), 1, uintptr(p.V), 0, 0)
   472  }
   473  func (f *Functions) UnmapBuffer(target Enum) bool {
   474  	panic("not implemented")
   475  }
   476  func (c *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
   477  	var norm uintptr
   478  	if normalized {
   479  		norm = 1
   480  	}
   481  	syscall.Syscall6(_glVertexAttribPointer.Addr(), 6, uintptr(dst), uintptr(size), uintptr(ty), norm, uintptr(stride), uintptr(offset))
   482  }
   483  func (c *Functions) Viewport(x, y, width, height int) {
   484  	syscall.Syscall6(_glViewport.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
   485  }
   486  
   487  func cString(s string) []byte {
   488  	b := make([]byte, len(s)+1)
   489  	copy(b, s)
   490  	return b
   491  }
   492  
   493  // issue34474KeepAlive calls runtime.KeepAlive as a
   494  // workaround for golang.org/issue/34474.
   495  func issue34474KeepAlive(v interface{}) {
   496  	runtime.KeepAlive(v)
   497  }