work_windows.go (30295B)
1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gl 6 7 import ( 8 "runtime" 9 "syscall" 10 "unsafe" 11 ) 12 13 // context is described in work.go. 14 type context struct { 15 debug int32 16 workAvailable chan struct{} 17 work chan call 18 retvalue chan uintptr 19 20 // TODO(crawshaw): will not work with a moving collector 21 cStringCounter int 22 cStrings map[int]unsafe.Pointer 23 } 24 25 func (ctx *context) WorkAvailable() <-chan struct{} { return ctx.workAvailable } 26 27 type context3 struct { 28 *context 29 } 30 31 func NewContext() (Context, Worker) { 32 if err := findDLLs(); err != nil { 33 panic(err) 34 } 35 glctx := &context{ 36 workAvailable: make(chan struct{}, 1), 37 work: make(chan call, 3), 38 retvalue: make(chan uintptr), 39 cStrings: make(map[int]unsafe.Pointer), 40 } 41 return glctx, glctx 42 } 43 44 func (ctx *context) enqueue(c call) uintptr { 45 ctx.work <- c 46 47 select { 48 case ctx.workAvailable <- struct{}{}: 49 default: 50 } 51 52 if c.blocking { 53 return <-ctx.retvalue 54 } 55 return 0 56 } 57 58 func (ctx *context) DoWork() { 59 // TODO: add a work queue 60 for { 61 select { 62 case w := <-ctx.work: 63 ret := ctx.doWork(w) 64 if w.blocking { 65 ctx.retvalue <- ret 66 } 67 default: 68 return 69 } 70 } 71 } 72 73 func (ctx *context) cString(s string) (uintptr, func()) { 74 buf := make([]byte, len(s)+1) 75 for i := 0; i < len(s); i++ { 76 buf[i] = s[i] 77 } 78 ret := unsafe.Pointer(&buf[0]) 79 id := ctx.cStringCounter 80 ctx.cStringCounter++ 81 ctx.cStrings[id] = ret 82 return uintptr(ret), func() { delete(ctx.cStrings, id) } 83 } 84 85 func (ctx *context) cStringPtr(str string) (uintptr, func()) { 86 s, sfree := ctx.cString(str) 87 sptr := [2]uintptr{s, 0} 88 ret := unsafe.Pointer(&sptr[0]) 89 id := ctx.cStringCounter 90 ctx.cStringCounter++ 91 ctx.cStrings[id] = ret 92 return uintptr(ret), func() { sfree(); delete(ctx.cStrings, id) } 93 } 94 95 // fixFloat copies the first four arguments into the XMM registers. 96 // This is for the windows/amd64 calling convention, that wants 97 // floating point arguments to be passed in XMM. 98 // 99 // Mercifully, type information is not required to implement 100 // this calling convention. In particular see the mixed int/float 101 // examples: 102 // 103 // https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx 104 // 105 // This means it could be fixed in syscall.Syscall. The relevant 106 // issue is 107 // 108 // https://golang.org/issue/6510 109 func fixFloat(x0, x1, x2, x3 uintptr) 110 111 func (ctx *context) doWork(c call) (ret uintptr) { 112 if runtime.GOARCH == "amd64" { 113 fixFloat(c.args.a0, c.args.a1, c.args.a2, c.args.a3) 114 } 115 116 switch c.args.fn { 117 case glfnActiveTexture: 118 syscall.Syscall(glActiveTexture.Addr(), 1, c.args.a0, 0, 0) 119 case glfnAttachShader: 120 syscall.Syscall(glAttachShader.Addr(), 2, c.args.a0, c.args.a1, 0) 121 case glfnBindAttribLocation: 122 syscall.Syscall(glBindAttribLocation.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 123 case glfnBindBuffer: 124 syscall.Syscall(glBindBuffer.Addr(), 2, c.args.a0, c.args.a1, 0) 125 case glfnBindFramebuffer: 126 syscall.Syscall(glBindFramebuffer.Addr(), 2, c.args.a0, c.args.a1, 0) 127 case glfnBindRenderbuffer: 128 syscall.Syscall(glBindRenderbuffer.Addr(), 2, c.args.a0, c.args.a1, 0) 129 case glfnBindTexture: 130 syscall.Syscall(glBindTexture.Addr(), 2, c.args.a0, c.args.a1, 0) 131 case glfnBindVertexArray: 132 syscall.Syscall(glBindVertexArray.Addr(), 1, c.args.a0, 0, 0) 133 case glfnBlendColor: 134 syscall.Syscall6(glBlendColor.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 135 case glfnBlendEquation: 136 syscall.Syscall(glBlendEquation.Addr(), 1, c.args.a0, 0, 0) 137 case glfnBlendEquationSeparate: 138 syscall.Syscall(glBlendEquationSeparate.Addr(), 2, c.args.a0, c.args.a1, 0) 139 case glfnBlendFunc: 140 syscall.Syscall(glBlendFunc.Addr(), 2, c.args.a0, c.args.a1, 0) 141 case glfnBlendFuncSeparate: 142 syscall.Syscall6(glBlendFuncSeparate.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 143 case glfnBufferData: 144 syscall.Syscall6(glBufferData.Addr(), 4, c.args.a0, c.args.a1, uintptr(c.parg), c.args.a2, 0, 0) 145 case glfnBufferSubData: 146 syscall.Syscall6(glBufferSubData.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, uintptr(c.parg), 0, 0) 147 case glfnCheckFramebufferStatus: 148 ret, _, _ = syscall.Syscall(glCheckFramebufferStatus.Addr(), 1, c.args.a0, 0, 0) 149 case glfnClear: 150 syscall.Syscall(glClear.Addr(), 1, c.args.a0, 0, 0) 151 case glfnClearColor: 152 syscall.Syscall6(glClearColor.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 153 case glfnClearDepthf: 154 syscall.Syscall6(glClearDepthf.Addr(), 1, c.args.a0, 0, 0, 0, 0, 0) 155 case glfnClearStencil: 156 syscall.Syscall(glClearStencil.Addr(), 1, c.args.a0, 0, 0) 157 case glfnColorMask: 158 syscall.Syscall6(glColorMask.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 159 case glfnCompileShader: 160 syscall.Syscall(glCompileShader.Addr(), 1, c.args.a0, 0, 0) 161 case glfnCompressedTexImage2D: 162 syscall.Syscall9(glCompressedTexImage2D.Addr(), 8, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, c.args.a6, uintptr(c.parg), 0) 163 case glfnCompressedTexSubImage2D: 164 syscall.Syscall9(glCompressedTexSubImage2D.Addr(), 9, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, c.args.a6, c.args.a7, uintptr(c.parg)) 165 case glfnCopyTexImage2D: 166 syscall.Syscall9(glCopyTexImage2D.Addr(), 8, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, c.args.a6, c.args.a7, 0) 167 case glfnCopyTexSubImage2D: 168 syscall.Syscall9(glCopyTexSubImage2D.Addr(), 8, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, c.args.a6, c.args.a7, 0) 169 case glfnCreateProgram: 170 ret, _, _ = syscall.Syscall(glCreateProgram.Addr(), 0, 0, 0, 0) 171 case glfnCreateShader: 172 ret, _, _ = syscall.Syscall(glCreateShader.Addr(), 1, c.args.a0, 0, 0) 173 case glfnCullFace: 174 syscall.Syscall(glCullFace.Addr(), 1, c.args.a0, 0, 0) 175 case glfnDeleteBuffer: 176 syscall.Syscall(glDeleteBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) 177 case glfnDeleteFramebuffer: 178 syscall.Syscall(glDeleteFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) 179 case glfnDeleteProgram: 180 syscall.Syscall(glDeleteProgram.Addr(), 1, c.args.a0, 0, 0) 181 case glfnDeleteRenderbuffer: 182 syscall.Syscall(glDeleteRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) 183 case glfnDeleteShader: 184 syscall.Syscall(glDeleteShader.Addr(), 1, c.args.a0, 0, 0) 185 case glfnDeleteVertexArray: 186 syscall.Syscall(glDeleteVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) 187 case glfnDeleteTexture: 188 syscall.Syscall(glDeleteTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) 189 case glfnDepthFunc: 190 syscall.Syscall(glDepthFunc.Addr(), 1, c.args.a0, 0, 0) 191 case glfnDepthRangef: 192 syscall.Syscall6(glDepthRangef.Addr(), 2, c.args.a0, c.args.a1, 0, 0, 0, 0) 193 case glfnDepthMask: 194 syscall.Syscall(glDepthMask.Addr(), 1, c.args.a0, 0, 0) 195 case glfnDetachShader: 196 syscall.Syscall(glDetachShader.Addr(), 2, c.args.a0, c.args.a1, 0) 197 case glfnDisable: 198 syscall.Syscall(glDisable.Addr(), 1, c.args.a0, 0, 0) 199 case glfnDisableVertexAttribArray: 200 syscall.Syscall(glDisableVertexAttribArray.Addr(), 1, c.args.a0, 0, 0) 201 case glfnDrawArrays: 202 syscall.Syscall(glDrawArrays.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 203 case glfnDrawElements: 204 syscall.Syscall6(glDrawElements.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 205 case glfnEnable: 206 syscall.Syscall(glEnable.Addr(), 1, c.args.a0, 0, 0) 207 case glfnEnableVertexAttribArray: 208 syscall.Syscall(glEnableVertexAttribArray.Addr(), 1, c.args.a0, 0, 0) 209 case glfnFinish: 210 syscall.Syscall(glFinish.Addr(), 0, 0, 0, 0) 211 case glfnFlush: 212 syscall.Syscall(glFlush.Addr(), 0, 0, 0, 0) 213 case glfnFramebufferRenderbuffer: 214 syscall.Syscall6(glFramebufferRenderbuffer.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 215 case glfnFramebufferTexture2D: 216 syscall.Syscall6(glFramebufferTexture2D.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, 0) 217 case glfnFrontFace: 218 syscall.Syscall(glFrontFace.Addr(), 1, c.args.a0, 0, 0) 219 case glfnGenBuffer: 220 syscall.Syscall(glGenBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) 221 case glfnGenFramebuffer: 222 syscall.Syscall(glGenFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) 223 case glfnGenRenderbuffer: 224 syscall.Syscall(glGenRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) 225 case glfnGenVertexArray: 226 syscall.Syscall(glGenVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) 227 case glfnGenTexture: 228 syscall.Syscall(glGenTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) 229 case glfnGenerateMipmap: 230 syscall.Syscall(glGenerateMipmap.Addr(), 1, c.args.a0, 0, 0) 231 case glfnGetActiveAttrib: 232 syscall.Syscall9(glGetActiveAttrib.Addr(), 7, c.args.a0, c.args.a1, c.args.a2, 0, uintptr(unsafe.Pointer(&ret)), c.args.a3, uintptr(c.parg), 0, 0) 233 case glfnGetActiveUniform: 234 syscall.Syscall9(glGetActiveUniform.Addr(), 7, c.args.a0, c.args.a1, c.args.a2, 0, uintptr(unsafe.Pointer(&ret)), c.args.a3, uintptr(c.parg), 0, 0) 235 case glfnGetAttachedShaders: 236 syscall.Syscall6(glGetAttachedShaders.Addr(), 4, c.args.a0, c.args.a1, uintptr(unsafe.Pointer(&ret)), uintptr(c.parg), 0, 0) 237 case glfnGetAttribLocation: 238 ret, _, _ = syscall.Syscall(glGetAttribLocation.Addr(), 2, c.args.a0, c.args.a1, 0) 239 case glfnGetBooleanv: 240 syscall.Syscall(glGetBooleanv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 241 case glfnGetBufferParameteri: 242 syscall.Syscall(glGetBufferParameteri.Addr(), 3, c.args.a0, c.args.a1, uintptr(unsafe.Pointer(&ret))) 243 case glfnGetError: 244 ret, _, _ = syscall.Syscall(glGetError.Addr(), 0, 0, 0, 0) 245 case glfnGetFloatv: 246 syscall.Syscall(glGetFloatv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 247 case glfnGetFramebufferAttachmentParameteriv: 248 syscall.Syscall6(glGetFramebufferAttachmentParameteriv.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, uintptr(unsafe.Pointer(&ret)), 0, 0) 249 case glfnGetIntegerv: 250 syscall.Syscall(glGetIntegerv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 251 case glfnGetProgramInfoLog: 252 syscall.Syscall6(glGetProgramInfoLog.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 253 case glfnGetProgramiv: 254 syscall.Syscall(glGetProgramiv.Addr(), 3, c.args.a0, c.args.a1, uintptr(unsafe.Pointer(&ret))) 255 case glfnGetRenderbufferParameteriv: 256 syscall.Syscall(glGetRenderbufferParameteriv.Addr(), 3, c.args.a0, c.args.a1, uintptr(unsafe.Pointer(&ret))) 257 case glfnGetShaderInfoLog: 258 syscall.Syscall6(glGetShaderInfoLog.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 259 case glfnGetShaderPrecisionFormat: 260 // c.parg is a [3]int32. The first [2]int32 of the array is one 261 // parameter, the final *int32 is another parameter. 262 syscall.Syscall6(glGetShaderPrecisionFormat.Addr(), 4, c.args.a0, c.args.a1, uintptr(c.parg), uintptr(c.parg)+2*unsafe.Sizeof(uintptr(0)), 0, 0) 263 case glfnGetShaderSource: 264 syscall.Syscall6(glGetShaderSource.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 265 case glfnGetShaderiv: 266 syscall.Syscall(glGetShaderiv.Addr(), 3, c.args.a0, c.args.a1, uintptr(unsafe.Pointer(&ret))) 267 case glfnGetString: 268 ret, _, _ = syscall.Syscall(glGetString.Addr(), 1, c.args.a0, 0, 0) 269 case glfnGetTexParameterfv: 270 syscall.Syscall(glGetTexParameterfv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 271 case glfnGetTexParameteriv: 272 syscall.Syscall(glGetTexParameteriv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 273 case glfnGetUniformLocation: 274 ret, _, _ = syscall.Syscall(glGetUniformLocation.Addr(), 2, c.args.a0, c.args.a1, 0) 275 case glfnGetUniformfv: 276 syscall.Syscall(glGetUniformfv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 277 case glfnGetUniformiv: 278 syscall.Syscall(glGetUniformiv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 279 case glfnGetVertexAttribfv: 280 syscall.Syscall(glGetVertexAttribfv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 281 case glfnGetVertexAttribiv: 282 syscall.Syscall(glGetVertexAttribiv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 283 case glfnHint: 284 syscall.Syscall(glHint.Addr(), 2, c.args.a0, c.args.a1, 0) 285 case glfnIsBuffer: 286 syscall.Syscall(glIsBuffer.Addr(), 1, c.args.a0, 0, 0) 287 case glfnIsEnabled: 288 syscall.Syscall(glIsEnabled.Addr(), 1, c.args.a0, 0, 0) 289 case glfnIsFramebuffer: 290 syscall.Syscall(glIsFramebuffer.Addr(), 1, c.args.a0, 0, 0) 291 case glfnIsProgram: 292 ret, _, _ = syscall.Syscall(glIsProgram.Addr(), 1, c.args.a0, 0, 0) 293 case glfnIsRenderbuffer: 294 syscall.Syscall(glIsRenderbuffer.Addr(), 1, c.args.a0, 0, 0) 295 case glfnIsShader: 296 syscall.Syscall(glIsShader.Addr(), 1, c.args.a0, 0, 0) 297 case glfnIsTexture: 298 syscall.Syscall(glIsTexture.Addr(), 1, c.args.a0, 0, 0) 299 case glfnLineWidth: 300 syscall.Syscall(glLineWidth.Addr(), 1, c.args.a0, 0, 0) 301 case glfnLinkProgram: 302 syscall.Syscall(glLinkProgram.Addr(), 1, c.args.a0, 0, 0) 303 case glfnPixelStorei: 304 syscall.Syscall(glPixelStorei.Addr(), 2, c.args.a0, c.args.a1, 0) 305 case glfnPolygonOffset: 306 syscall.Syscall6(glPolygonOffset.Addr(), 2, c.args.a0, c.args.a1, 0, 0, 0, 0) 307 case glfnReadPixels: 308 syscall.Syscall9(glReadPixels.Addr(), 7, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, uintptr(c.parg), 0, 0) 309 case glfnReleaseShaderCompiler: 310 syscall.Syscall(glReleaseShaderCompiler.Addr(), 0, 0, 0, 0) 311 case glfnRenderbufferStorage: 312 syscall.Syscall6(glRenderbufferStorage.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 313 case glfnSampleCoverage: 314 syscall.Syscall6(glSampleCoverage.Addr(), 1, c.args.a0, 0, 0, 0, 0, 0) 315 case glfnScissor: 316 syscall.Syscall6(glScissor.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 317 case glfnShaderSource: 318 syscall.Syscall6(glShaderSource.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, 0, 0, 0) 319 case glfnStencilFunc: 320 syscall.Syscall(glStencilFunc.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 321 case glfnStencilFuncSeparate: 322 syscall.Syscall6(glStencilFuncSeparate.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 323 case glfnStencilMask: 324 syscall.Syscall(glStencilMask.Addr(), 1, c.args.a0, 0, 0) 325 case glfnStencilMaskSeparate: 326 syscall.Syscall(glStencilMaskSeparate.Addr(), 2, c.args.a0, c.args.a1, 0) 327 case glfnStencilOp: 328 syscall.Syscall(glStencilOp.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 329 case glfnStencilOpSeparate: 330 syscall.Syscall6(glStencilOpSeparate.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 331 case glfnTexImage2D: 332 syscall.Syscall9(glTexImage2D.Addr(), 9, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, 0, c.args.a5, c.args.a6, uintptr(c.parg)) 333 case glfnTexParameterf: 334 syscall.Syscall6(glTexParameterf.Addr(), 3, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 335 case glfnTexParameterfv: 336 syscall.Syscall(glTexParameterfv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 337 case glfnTexParameteri: 338 syscall.Syscall(glTexParameteri.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 339 case glfnTexParameteriv: 340 syscall.Syscall(glTexParameteriv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 341 case glfnTexSubImage2D: 342 syscall.Syscall9(glTexSubImage2D.Addr(), 9, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5, c.args.a6, c.args.a7, uintptr(c.parg)) 343 case glfnUniform1f: 344 syscall.Syscall6(glUniform1f.Addr(), 2, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 345 case glfnUniform1fv: 346 syscall.Syscall(glUniform1fv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 347 case glfnUniform1i: 348 syscall.Syscall(glUniform1i.Addr(), 2, c.args.a0, c.args.a1, 0) 349 case glfnUniform1iv: 350 syscall.Syscall(glUniform1iv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 351 case glfnUniform2f: 352 syscall.Syscall6(glUniform2f.Addr(), 3, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 353 case glfnUniform2fv: 354 syscall.Syscall(glUniform2fv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 355 case glfnUniform2i: 356 syscall.Syscall(glUniform2i.Addr(), 3, c.args.a0, c.args.a1, c.args.a2) 357 case glfnUniform2iv: 358 syscall.Syscall(glUniform2iv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 359 case glfnUniform3f: 360 syscall.Syscall6(glUniform3f.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 361 case glfnUniform3fv: 362 syscall.Syscall(glUniform3fv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 363 case glfnUniform3i: 364 syscall.Syscall6(glUniform3i.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 365 case glfnUniform3iv: 366 syscall.Syscall(glUniform3iv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 367 case glfnUniform4f: 368 syscall.Syscall6(glUniform4f.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 369 case glfnUniform4fv: 370 syscall.Syscall(glUniform4fv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 371 case glfnUniform4i: 372 syscall.Syscall6(glUniform4i.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, 0) 373 case glfnUniform4iv: 374 syscall.Syscall(glUniform4iv.Addr(), 3, c.args.a0, c.args.a1, uintptr(c.parg)) 375 case glfnUniformMatrix2fv: 376 syscall.Syscall6(glUniformMatrix2fv.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 377 case glfnUniformMatrix3fv: 378 syscall.Syscall6(glUniformMatrix3fv.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 379 case glfnUniformMatrix4fv: 380 syscall.Syscall6(glUniformMatrix4fv.Addr(), 4, c.args.a0, c.args.a1, 0, uintptr(c.parg), 0, 0) 381 case glfnUseProgram: 382 syscall.Syscall(glUseProgram.Addr(), 1, c.args.a0, 0, 0) 383 case glfnValidateProgram: 384 syscall.Syscall(glValidateProgram.Addr(), 1, c.args.a0, 0, 0) 385 case glfnVertexAttrib1f: 386 syscall.Syscall6(glVertexAttrib1f.Addr(), 2, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 387 case glfnVertexAttrib1fv: 388 syscall.Syscall(glVertexAttrib1fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 389 case glfnVertexAttrib2f: 390 syscall.Syscall6(glVertexAttrib2f.Addr(), 3, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 391 case glfnVertexAttrib2fv: 392 syscall.Syscall(glVertexAttrib2fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 393 case glfnVertexAttrib3f: 394 syscall.Syscall6(glVertexAttrib3f.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 395 case glfnVertexAttrib3fv: 396 syscall.Syscall(glVertexAttrib3fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 397 case glfnVertexAttrib4f: 398 syscall.Syscall6(glVertexAttrib4f.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 399 case glfnVertexAttrib4fv: 400 syscall.Syscall(glVertexAttrib4fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) 401 case glfnVertexAttribPointer: 402 syscall.Syscall6(glVertexAttribPointer.Addr(), 6, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) 403 case glfnViewport: 404 syscall.Syscall6(glViewport.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) 405 default: 406 panic("unknown GL function") 407 } 408 409 return ret 410 } 411 412 // Exported libraries for a Windows GUI driver. 413 // 414 // LibEGL is not used directly by the gl package, but is needed by any 415 // driver hoping to use OpenGL ES. 416 // 417 // LibD3DCompiler is needed by libglesv2.dll for compiling shaders. 418 var ( 419 LibGLESv2 = syscall.NewLazyDLL("libglesv2.dll") 420 LibEGL = syscall.NewLazyDLL("libegl.dll") 421 LibD3DCompiler = syscall.NewLazyDLL("d3dcompiler_47.dll") 422 ) 423 424 var ( 425 libGLESv2 = LibGLESv2 426 glActiveTexture = libGLESv2.NewProc("glActiveTexture") 427 glAttachShader = libGLESv2.NewProc("glAttachShader") 428 glBindAttribLocation = libGLESv2.NewProc("glBindAttribLocation") 429 glBindBuffer = libGLESv2.NewProc("glBindBuffer") 430 glBindFramebuffer = libGLESv2.NewProc("glBindFramebuffer") 431 glBindRenderbuffer = libGLESv2.NewProc("glBindRenderbuffer") 432 glBindTexture = libGLESv2.NewProc("glBindTexture") 433 glBindVertexArray = libGLESv2.NewProc("glBindVertexArray") 434 glBlendColor = libGLESv2.NewProc("glBlendColor") 435 glBlendEquation = libGLESv2.NewProc("glBlendEquation") 436 glBlendEquationSeparate = libGLESv2.NewProc("glBlendEquationSeparate") 437 glBlendFunc = libGLESv2.NewProc("glBlendFunc") 438 glBlendFuncSeparate = libGLESv2.NewProc("glBlendFuncSeparate") 439 glBufferData = libGLESv2.NewProc("glBufferData") 440 glBufferSubData = libGLESv2.NewProc("glBufferSubData") 441 glCheckFramebufferStatus = libGLESv2.NewProc("glCheckFramebufferStatus") 442 glClear = libGLESv2.NewProc("glClear") 443 glClearColor = libGLESv2.NewProc("glClearColor") 444 glClearDepthf = libGLESv2.NewProc("glClearDepthf") 445 glClearStencil = libGLESv2.NewProc("glClearStencil") 446 glColorMask = libGLESv2.NewProc("glColorMask") 447 glCompileShader = libGLESv2.NewProc("glCompileShader") 448 glCompressedTexImage2D = libGLESv2.NewProc("glCompressedTexImage2D") 449 glCompressedTexSubImage2D = libGLESv2.NewProc("glCompressedTexSubImage2D") 450 glCopyTexImage2D = libGLESv2.NewProc("glCopyTexImage2D") 451 glCopyTexSubImage2D = libGLESv2.NewProc("glCopyTexSubImage2D") 452 glCreateProgram = libGLESv2.NewProc("glCreateProgram") 453 glCreateShader = libGLESv2.NewProc("glCreateShader") 454 glCullFace = libGLESv2.NewProc("glCullFace") 455 glDeleteBuffers = libGLESv2.NewProc("glDeleteBuffers") 456 glDeleteFramebuffers = libGLESv2.NewProc("glDeleteFramebuffers") 457 glDeleteProgram = libGLESv2.NewProc("glDeleteProgram") 458 glDeleteRenderbuffers = libGLESv2.NewProc("glDeleteRenderbuffers") 459 glDeleteShader = libGLESv2.NewProc("glDeleteShader") 460 glDeleteTextures = libGLESv2.NewProc("glDeleteTextures") 461 glDeleteVertexArrays = libGLESv2.NewProc("glDeleteVertexArrays") 462 glDepthFunc = libGLESv2.NewProc("glDepthFunc") 463 glDepthRangef = libGLESv2.NewProc("glDepthRangef") 464 glDepthMask = libGLESv2.NewProc("glDepthMask") 465 glDetachShader = libGLESv2.NewProc("glDetachShader") 466 glDisable = libGLESv2.NewProc("glDisable") 467 glDisableVertexAttribArray = libGLESv2.NewProc("glDisableVertexAttribArray") 468 glDrawArrays = libGLESv2.NewProc("glDrawArrays") 469 glDrawElements = libGLESv2.NewProc("glDrawElements") 470 glEnable = libGLESv2.NewProc("glEnable") 471 glEnableVertexAttribArray = libGLESv2.NewProc("glEnableVertexAttribArray") 472 glFinish = libGLESv2.NewProc("glFinish") 473 glFlush = libGLESv2.NewProc("glFlush") 474 glFramebufferRenderbuffer = libGLESv2.NewProc("glFramebufferRenderbuffer") 475 glFramebufferTexture2D = libGLESv2.NewProc("glFramebufferTexture2D") 476 glFrontFace = libGLESv2.NewProc("glFrontFace") 477 glGenBuffers = libGLESv2.NewProc("glGenBuffers") 478 glGenFramebuffers = libGLESv2.NewProc("glGenFramebuffers") 479 glGenRenderbuffers = libGLESv2.NewProc("glGenRenderbuffers") 480 glGenTextures = libGLESv2.NewProc("glGenTextures") 481 glGenVertexArrays = libGLESv2.NewProc("glGenVertexArrays") 482 glGenerateMipmap = libGLESv2.NewProc("glGenerateMipmap") 483 glGetActiveAttrib = libGLESv2.NewProc("glGetActiveAttrib") 484 glGetActiveUniform = libGLESv2.NewProc("glGetActiveUniform") 485 glGetAttachedShaders = libGLESv2.NewProc("glGetAttachedShaders") 486 glGetAttribLocation = libGLESv2.NewProc("glGetAttribLocation") 487 glGetBooleanv = libGLESv2.NewProc("glGetBooleanv") 488 glGetBufferParameteri = libGLESv2.NewProc("glGetBufferParameteri") 489 glGetError = libGLESv2.NewProc("glGetError") 490 glGetFloatv = libGLESv2.NewProc("glGetFloatv") 491 glGetFramebufferAttachmentParameteriv = libGLESv2.NewProc("glGetFramebufferAttachmentParameteriv") 492 glGetIntegerv = libGLESv2.NewProc("glGetIntegerv") 493 glGetProgramInfoLog = libGLESv2.NewProc("glGetProgramInfoLog") 494 glGetProgramiv = libGLESv2.NewProc("glGetProgramiv") 495 glGetRenderbufferParameteriv = libGLESv2.NewProc("glGetRenderbufferParameteriv") 496 glGetShaderInfoLog = libGLESv2.NewProc("glGetShaderInfoLog") 497 glGetShaderPrecisionFormat = libGLESv2.NewProc("glGetShaderPrecisionFormat") 498 glGetShaderSource = libGLESv2.NewProc("glGetShaderSource") 499 glGetShaderiv = libGLESv2.NewProc("glGetShaderiv") 500 glGetString = libGLESv2.NewProc("glGetString") 501 glGetTexParameterfv = libGLESv2.NewProc("glGetTexParameterfv") 502 glGetTexParameteriv = libGLESv2.NewProc("glGetTexParameteriv") 503 glGetUniformLocation = libGLESv2.NewProc("glGetUniformLocation") 504 glGetUniformfv = libGLESv2.NewProc("glGetUniformfv") 505 glGetUniformiv = libGLESv2.NewProc("glGetUniformiv") 506 glGetVertexAttribfv = libGLESv2.NewProc("glGetVertexAttribfv") 507 glGetVertexAttribiv = libGLESv2.NewProc("glGetVertexAttribiv") 508 glHint = libGLESv2.NewProc("glHint") 509 glIsBuffer = libGLESv2.NewProc("glIsBuffer") 510 glIsEnabled = libGLESv2.NewProc("glIsEnabled") 511 glIsFramebuffer = libGLESv2.NewProc("glIsFramebuffer") 512 glIsProgram = libGLESv2.NewProc("glIsProgram") 513 glIsRenderbuffer = libGLESv2.NewProc("glIsRenderbuffer") 514 glIsShader = libGLESv2.NewProc("glIsShader") 515 glIsTexture = libGLESv2.NewProc("glIsTexture") 516 glLineWidth = libGLESv2.NewProc("glLineWidth") 517 glLinkProgram = libGLESv2.NewProc("glLinkProgram") 518 glPixelStorei = libGLESv2.NewProc("glPixelStorei") 519 glPolygonOffset = libGLESv2.NewProc("glPolygonOffset") 520 glReadPixels = libGLESv2.NewProc("glReadPixels") 521 glReleaseShaderCompiler = libGLESv2.NewProc("glReleaseShaderCompiler") 522 glRenderbufferStorage = libGLESv2.NewProc("glRenderbufferStorage") 523 glSampleCoverage = libGLESv2.NewProc("glSampleCoverage") 524 glScissor = libGLESv2.NewProc("glScissor") 525 glShaderSource = libGLESv2.NewProc("glShaderSource") 526 glStencilFunc = libGLESv2.NewProc("glStencilFunc") 527 glStencilFuncSeparate = libGLESv2.NewProc("glStencilFuncSeparate") 528 glStencilMask = libGLESv2.NewProc("glStencilMask") 529 glStencilMaskSeparate = libGLESv2.NewProc("glStencilMaskSeparate") 530 glStencilOp = libGLESv2.NewProc("glStencilOp") 531 glStencilOpSeparate = libGLESv2.NewProc("glStencilOpSeparate") 532 glTexImage2D = libGLESv2.NewProc("glTexImage2D") 533 glTexParameterf = libGLESv2.NewProc("glTexParameterf") 534 glTexParameterfv = libGLESv2.NewProc("glTexParameterfv") 535 glTexParameteri = libGLESv2.NewProc("glTexParameteri") 536 glTexParameteriv = libGLESv2.NewProc("glTexParameteriv") 537 glTexSubImage2D = libGLESv2.NewProc("glTexSubImage2D") 538 glUniform1f = libGLESv2.NewProc("glUniform1f") 539 glUniform1fv = libGLESv2.NewProc("glUniform1fv") 540 glUniform1i = libGLESv2.NewProc("glUniform1i") 541 glUniform1iv = libGLESv2.NewProc("glUniform1iv") 542 glUniform2f = libGLESv2.NewProc("glUniform2f") 543 glUniform2fv = libGLESv2.NewProc("glUniform2fv") 544 glUniform2i = libGLESv2.NewProc("glUniform2i") 545 glUniform2iv = libGLESv2.NewProc("glUniform2iv") 546 glUniform3f = libGLESv2.NewProc("glUniform3f") 547 glUniform3fv = libGLESv2.NewProc("glUniform3fv") 548 glUniform3i = libGLESv2.NewProc("glUniform3i") 549 glUniform3iv = libGLESv2.NewProc("glUniform3iv") 550 glUniform4f = libGLESv2.NewProc("glUniform4f") 551 glUniform4fv = libGLESv2.NewProc("glUniform4fv") 552 glUniform4i = libGLESv2.NewProc("glUniform4i") 553 glUniform4iv = libGLESv2.NewProc("glUniform4iv") 554 glUniformMatrix2fv = libGLESv2.NewProc("glUniformMatrix2fv") 555 glUniformMatrix3fv = libGLESv2.NewProc("glUniformMatrix3fv") 556 glUniformMatrix4fv = libGLESv2.NewProc("glUniformMatrix4fv") 557 glUseProgram = libGLESv2.NewProc("glUseProgram") 558 glValidateProgram = libGLESv2.NewProc("glValidateProgram") 559 glVertexAttrib1f = libGLESv2.NewProc("glVertexAttrib1f") 560 glVertexAttrib1fv = libGLESv2.NewProc("glVertexAttrib1fv") 561 glVertexAttrib2f = libGLESv2.NewProc("glVertexAttrib2f") 562 glVertexAttrib2fv = libGLESv2.NewProc("glVertexAttrib2fv") 563 glVertexAttrib3f = libGLESv2.NewProc("glVertexAttrib3f") 564 glVertexAttrib3fv = libGLESv2.NewProc("glVertexAttrib3fv") 565 glVertexAttrib4f = libGLESv2.NewProc("glVertexAttrib4f") 566 glVertexAttrib4fv = libGLESv2.NewProc("glVertexAttrib4fv") 567 glVertexAttribPointer = libGLESv2.NewProc("glVertexAttribPointer") 568 glViewport = libGLESv2.NewProc("glViewport") 569 )