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