mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
698 lines
25 KiB
Go
698 lines
25 KiB
Go
// Copyright 2022 The Ebitengine Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//go:build darwin || windows
|
|
|
|
package gl
|
|
|
|
import (
|
|
"errors"
|
|
"runtime"
|
|
"unsafe"
|
|
|
|
"github.com/ebitengine/purego"
|
|
)
|
|
|
|
type defaultContext struct {
|
|
gpActiveTexture uintptr
|
|
gpAttachShader uintptr
|
|
gpBindAttribLocation uintptr
|
|
gpBindBuffer uintptr
|
|
gpBindFramebufferEXT uintptr
|
|
gpBindRenderbufferEXT uintptr
|
|
gpBindTexture uintptr
|
|
gpBlendEquationSeparate uintptr
|
|
gpBlendFuncSeparate uintptr
|
|
gpBufferData uintptr
|
|
gpBufferSubData uintptr
|
|
gpCheckFramebufferStatusEXT uintptr
|
|
gpClear uintptr
|
|
gpColorMask uintptr
|
|
gpCompileShader uintptr
|
|
gpCreateProgram uintptr
|
|
gpCreateShader uintptr
|
|
gpDeleteBuffers uintptr
|
|
gpDeleteFramebuffersEXT uintptr
|
|
gpDeleteProgram uintptr
|
|
gpDeleteRenderbuffersEXT uintptr
|
|
gpDeleteShader uintptr
|
|
gpDeleteTextures uintptr
|
|
gpDisable uintptr
|
|
gpDisableVertexAttribArray uintptr
|
|
gpDrawElements uintptr
|
|
gpEnable uintptr
|
|
gpEnableVertexAttribArray uintptr
|
|
gpFlush uintptr
|
|
gpFramebufferRenderbufferEXT uintptr
|
|
gpFramebufferTexture2DEXT uintptr
|
|
gpGenBuffers uintptr
|
|
gpGenFramebuffersEXT uintptr
|
|
gpGenRenderbuffersEXT uintptr
|
|
gpGenTextures uintptr
|
|
gpGetError uintptr
|
|
gpGetIntegerv uintptr
|
|
gpGetProgramInfoLog uintptr
|
|
gpGetProgramiv uintptr
|
|
gpGetShaderInfoLog uintptr
|
|
gpGetShaderiv uintptr
|
|
gpGetUniformLocation uintptr
|
|
gpIsFramebufferEXT uintptr
|
|
gpIsProgram uintptr
|
|
gpIsRenderbufferEXT uintptr
|
|
gpIsTexture uintptr
|
|
gpLinkProgram uintptr
|
|
gpPixelStorei uintptr
|
|
gpReadPixels uintptr
|
|
gpRenderbufferStorageEXT uintptr
|
|
gpScissor uintptr
|
|
gpShaderSource uintptr
|
|
gpStencilFunc uintptr
|
|
gpStencilOp uintptr
|
|
gpTexImage2D uintptr
|
|
gpTexParameteri uintptr
|
|
gpTexSubImage2D uintptr
|
|
gpUniform1fv uintptr
|
|
gpUniform1i uintptr
|
|
gpUniform1iv uintptr
|
|
gpUniform2fv uintptr
|
|
gpUniform3fv uintptr
|
|
gpUniform4fv uintptr
|
|
gpUniformMatrix2fv uintptr
|
|
gpUniformMatrix3fv uintptr
|
|
gpUniformMatrix4fv uintptr
|
|
gpUseProgram uintptr
|
|
gpVertexAttribPointer uintptr
|
|
gpViewport uintptr
|
|
}
|
|
|
|
func NewDefaultContext() Context {
|
|
return &defaultContext{}
|
|
}
|
|
|
|
func boolToInt(b bool) int {
|
|
if b {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (c *defaultContext) ActiveTexture(texture uint32) {
|
|
purego.SyscallN(c.gpActiveTexture, uintptr(texture))
|
|
}
|
|
|
|
func (c *defaultContext) AttachShader(program uint32, shader uint32) {
|
|
purego.SyscallN(c.gpAttachShader, uintptr(program), uintptr(shader))
|
|
}
|
|
|
|
func (c *defaultContext) BindAttribLocation(program uint32, index uint32, name string) {
|
|
cname, free := cStr(name)
|
|
defer free()
|
|
purego.SyscallN(c.gpBindAttribLocation, uintptr(program), uintptr(index), uintptr(unsafe.Pointer(cname)))
|
|
}
|
|
|
|
func (c *defaultContext) BindBuffer(target uint32, buffer uint32) {
|
|
purego.SyscallN(c.gpBindBuffer, uintptr(target), uintptr(buffer))
|
|
}
|
|
|
|
func (c *defaultContext) BindFramebuffer(target uint32, framebuffer uint32) {
|
|
purego.SyscallN(c.gpBindFramebufferEXT, uintptr(target), uintptr(framebuffer))
|
|
}
|
|
|
|
func (c *defaultContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
|
|
purego.SyscallN(c.gpBindRenderbufferEXT, uintptr(target), uintptr(renderbuffer))
|
|
}
|
|
|
|
func (c *defaultContext) BindTexture(target uint32, texture uint32) {
|
|
purego.SyscallN(c.gpBindTexture, uintptr(target), uintptr(texture))
|
|
}
|
|
|
|
func (c *defaultContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
|
|
purego.SyscallN(c.gpBlendEquationSeparate, uintptr(modeRGB), uintptr(modeAlpha))
|
|
}
|
|
|
|
func (c *defaultContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
|
|
purego.SyscallN(c.gpBlendFuncSeparate, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcAlpha), uintptr(dstAlpha))
|
|
}
|
|
|
|
func (c *defaultContext) BufferData(target uint32, size int, data []byte, usage uint32) {
|
|
var ptr *byte
|
|
if len(data) > 0 {
|
|
ptr = &data[0]
|
|
}
|
|
purego.SyscallN(c.gpBufferData, uintptr(target), uintptr(size), uintptr(unsafe.Pointer(ptr)), uintptr(usage))
|
|
runtime.KeepAlive(data)
|
|
}
|
|
|
|
func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) {
|
|
purego.SyscallN(c.gpBufferSubData, uintptr(target), uintptr(offset), uintptr(len(data)), uintptr(unsafe.Pointer(&data[0])))
|
|
runtime.KeepAlive(data)
|
|
}
|
|
|
|
func (c *defaultContext) CheckFramebufferStatus(target uint32) uint32 {
|
|
ret, _, _ := purego.SyscallN(c.gpCheckFramebufferStatusEXT, uintptr(target))
|
|
return uint32(ret)
|
|
}
|
|
|
|
func (c *defaultContext) Clear(mask uint32) {
|
|
purego.SyscallN(c.gpClear, uintptr(mask))
|
|
}
|
|
|
|
func (c *defaultContext) ColorMask(red bool, green bool, blue bool, alpha bool) {
|
|
purego.SyscallN(c.gpColorMask, uintptr(boolToInt(red)), uintptr(boolToInt(green)), uintptr(boolToInt(blue)), uintptr(boolToInt(alpha)))
|
|
}
|
|
|
|
func (c *defaultContext) CompileShader(shader uint32) {
|
|
purego.SyscallN(c.gpCompileShader, uintptr(shader))
|
|
}
|
|
|
|
func (c *defaultContext) CreateProgram() uint32 {
|
|
ret, _, _ := purego.SyscallN(c.gpCreateProgram)
|
|
return uint32(ret)
|
|
}
|
|
|
|
func (c *defaultContext) CreateShader(xtype uint32) uint32 {
|
|
ret, _, _ := purego.SyscallN(c.gpCreateShader, uintptr(xtype))
|
|
return uint32(ret)
|
|
}
|
|
|
|
func (c *defaultContext) DeleteBuffers(buffers []uint32) {
|
|
purego.SyscallN(c.gpDeleteBuffers, uintptr(len(buffers)), uintptr(unsafe.Pointer(&buffers[0])))
|
|
runtime.KeepAlive(buffers)
|
|
}
|
|
|
|
func (c *defaultContext) DeleteFramebuffers(framebuffers []uint32) {
|
|
purego.SyscallN(c.gpDeleteFramebuffersEXT, uintptr(len(framebuffers)), uintptr(unsafe.Pointer(&framebuffers[0])))
|
|
runtime.KeepAlive(framebuffers)
|
|
}
|
|
|
|
func (c *defaultContext) DeleteProgram(program uint32) {
|
|
purego.SyscallN(c.gpDeleteProgram, uintptr(program))
|
|
}
|
|
|
|
func (c *defaultContext) DeleteRenderbuffers(renderbuffers []uint32) {
|
|
purego.SyscallN(c.gpDeleteRenderbuffersEXT, uintptr(len(renderbuffers)), uintptr(unsafe.Pointer(&renderbuffers[0])))
|
|
}
|
|
|
|
func (c *defaultContext) DeleteShader(shader uint32) {
|
|
purego.SyscallN(c.gpDeleteShader, uintptr(shader))
|
|
}
|
|
|
|
func (c *defaultContext) DeleteTextures(textures []uint32) {
|
|
purego.SyscallN(c.gpDeleteTextures, uintptr(len(textures)), uintptr(unsafe.Pointer(&textures[0])))
|
|
}
|
|
|
|
func (c *defaultContext) Disable(cap uint32) {
|
|
purego.SyscallN(c.gpDisable, uintptr(cap))
|
|
}
|
|
|
|
func (c *defaultContext) DisableVertexAttribArray(index uint32) {
|
|
purego.SyscallN(c.gpDisableVertexAttribArray, uintptr(index))
|
|
}
|
|
|
|
func (c *defaultContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
|
|
purego.SyscallN(c.gpDrawElements, uintptr(mode), uintptr(count), uintptr(xtype), uintptr(offset))
|
|
}
|
|
|
|
func (c *defaultContext) Enable(cap uint32) {
|
|
purego.SyscallN(c.gpEnable, uintptr(cap))
|
|
}
|
|
|
|
func (c *defaultContext) EnableVertexAttribArray(index uint32) {
|
|
purego.SyscallN(c.gpEnableVertexAttribArray, uintptr(index))
|
|
}
|
|
|
|
func (c *defaultContext) Flush() {
|
|
purego.SyscallN(c.gpFlush)
|
|
}
|
|
|
|
func (c *defaultContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
|
|
purego.SyscallN(c.gpFramebufferRenderbufferEXT, uintptr(target), uintptr(attachment), uintptr(renderbuffertarget), uintptr(renderbuffer))
|
|
}
|
|
|
|
func (c *defaultContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
|
|
purego.SyscallN(c.gpFramebufferTexture2DEXT, uintptr(target), uintptr(attachment), uintptr(textarget), uintptr(texture), uintptr(level))
|
|
}
|
|
|
|
func (c *defaultContext) GenBuffers(n int32) []uint32 {
|
|
buffers := make([]uint32, n)
|
|
purego.SyscallN(c.gpGenBuffers, uintptr(n), uintptr(unsafe.Pointer(&buffers[0])))
|
|
return buffers
|
|
}
|
|
|
|
func (c *defaultContext) GenFramebuffers(n int32) []uint32 {
|
|
framebuffers := make([]uint32, n)
|
|
purego.SyscallN(c.gpGenFramebuffersEXT, uintptr(n), uintptr(unsafe.Pointer(&framebuffers[0])))
|
|
return framebuffers
|
|
}
|
|
|
|
func (c *defaultContext) GenRenderbuffers(n int32) []uint32 {
|
|
renderbuffers := make([]uint32, n)
|
|
purego.SyscallN(c.gpGenRenderbuffersEXT, uintptr(n), uintptr(unsafe.Pointer(&renderbuffers[0])))
|
|
return renderbuffers
|
|
}
|
|
|
|
func (c *defaultContext) GenTextures(n int32) []uint32 {
|
|
textures := make([]uint32, n)
|
|
purego.SyscallN(c.gpGenTextures, uintptr(n), uintptr(unsafe.Pointer(&textures[0])))
|
|
return textures
|
|
}
|
|
|
|
func (c *defaultContext) GetError() uint32 {
|
|
ret, _, _ := purego.SyscallN(c.gpGetError)
|
|
return uint32(ret)
|
|
}
|
|
|
|
func (c *defaultContext) GetIntegerv(dst []int32, pname uint32) {
|
|
purego.SyscallN(c.gpGetIntegerv, uintptr(pname), uintptr(unsafe.Pointer(&dst[0])))
|
|
}
|
|
|
|
func (c *defaultContext) GetProgramInfoLog(program uint32) string {
|
|
var bufSize [1]int32
|
|
c.GetProgramiv(bufSize[:], program, INFO_LOG_LENGTH)
|
|
infoLog := make([]byte, bufSize[0])
|
|
purego.SyscallN(c.gpGetProgramInfoLog, uintptr(program), uintptr(bufSize[0]), 0, uintptr(unsafe.Pointer(&infoLog[0])))
|
|
return string(infoLog)
|
|
}
|
|
|
|
func (c *defaultContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
|
|
purego.SyscallN(c.gpGetProgramiv, uintptr(program), uintptr(pname), uintptr(unsafe.Pointer(&dst[0])))
|
|
}
|
|
|
|
func (c *defaultContext) GetShaderInfoLog(shader uint32) string {
|
|
var bufSize [1]int32
|
|
c.GetShaderiv(bufSize[:], shader, INFO_LOG_LENGTH)
|
|
infoLog := make([]byte, bufSize[0])
|
|
purego.SyscallN(c.gpGetShaderInfoLog, uintptr(shader), uintptr(bufSize[0]), 0, uintptr(unsafe.Pointer(&infoLog[0])))
|
|
return string(infoLog)
|
|
}
|
|
|
|
func (c *defaultContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
|
|
purego.SyscallN(c.gpGetShaderiv, uintptr(shader), uintptr(pname), uintptr(unsafe.Pointer(&dst[0])))
|
|
}
|
|
|
|
func (c *defaultContext) GetUniformLocation(program uint32, name string) int32 {
|
|
cname, free := cStr(name)
|
|
defer free()
|
|
ret, _, _ := purego.SyscallN(c.gpGetUniformLocation, uintptr(program), uintptr(unsafe.Pointer(cname)))
|
|
return int32(ret)
|
|
}
|
|
|
|
func (c *defaultContext) IsFramebuffer(framebuffer uint32) bool {
|
|
ret, _, _ := purego.SyscallN(c.gpIsFramebufferEXT, uintptr(framebuffer))
|
|
return byte(ret) != 0
|
|
}
|
|
|
|
func (c *defaultContext) IsProgram(program uint32) bool {
|
|
ret, _, _ := purego.SyscallN(c.gpIsProgram, uintptr(program))
|
|
return byte(ret) != 0
|
|
}
|
|
|
|
func (c *defaultContext) IsRenderbuffer(renderbuffer uint32) bool {
|
|
ret, _, _ := purego.SyscallN(c.gpIsRenderbufferEXT, uintptr(renderbuffer))
|
|
return byte(ret) != 0
|
|
}
|
|
|
|
func (c *defaultContext) IsTexture(texture uint32) bool {
|
|
ret, _, _ := purego.SyscallN(c.gpIsTexture, uintptr(texture))
|
|
return byte(ret) != 0
|
|
}
|
|
|
|
func (c *defaultContext) LinkProgram(program uint32) {
|
|
purego.SyscallN(c.gpLinkProgram, uintptr(program))
|
|
}
|
|
|
|
func (c *defaultContext) PixelStorei(pname uint32, param int32) {
|
|
purego.SyscallN(c.gpPixelStorei, uintptr(pname), uintptr(param))
|
|
}
|
|
|
|
func (c *defaultContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
|
|
purego.SyscallN(c.gpReadPixels, uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(xtype), uintptr(unsafe.Pointer(&dst[0])))
|
|
}
|
|
|
|
func (c *defaultContext) RenderbufferStorage(target uint32, internalformat uint32, width int32, height int32) {
|
|
purego.SyscallN(c.gpRenderbufferStorageEXT, uintptr(target), uintptr(internalformat), uintptr(width), uintptr(height))
|
|
}
|
|
|
|
func (c *defaultContext) Scissor(x int32, y int32, width int32, height int32) {
|
|
purego.SyscallN(c.gpScissor, uintptr(x), uintptr(y), uintptr(width), uintptr(height))
|
|
}
|
|
|
|
func (c *defaultContext) ShaderSource(shader uint32, xstring string) {
|
|
cstring, free := cStr(xstring)
|
|
defer free()
|
|
purego.SyscallN(c.gpShaderSource, uintptr(shader), 1, uintptr(unsafe.Pointer(&cstring)), 0)
|
|
}
|
|
|
|
func (c *defaultContext) StencilFunc(xfunc uint32, ref int32, mask uint32) {
|
|
purego.SyscallN(c.gpStencilFunc, uintptr(xfunc), uintptr(ref), uintptr(mask))
|
|
}
|
|
|
|
func (c *defaultContext) StencilOp(fail uint32, zfail uint32, zpass uint32) {
|
|
purego.SyscallN(c.gpStencilOp, uintptr(fail), uintptr(zfail), uintptr(zpass))
|
|
}
|
|
|
|
func (c *defaultContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
|
|
var ptr *byte
|
|
if len(pixels) > 0 {
|
|
ptr = &pixels[0]
|
|
}
|
|
purego.SyscallN(c.gpTexImage2D, uintptr(target), uintptr(level), uintptr(internalformat), uintptr(width), uintptr(height), 0, uintptr(format), uintptr(xtype), uintptr(unsafe.Pointer(ptr)))
|
|
runtime.KeepAlive(pixels)
|
|
}
|
|
|
|
func (c *defaultContext) TexParameteri(target uint32, pname uint32, param int32) {
|
|
purego.SyscallN(c.gpTexParameteri, uintptr(target), uintptr(pname), uintptr(param))
|
|
}
|
|
|
|
func (c *defaultContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
|
|
purego.SyscallN(c.gpTexSubImage2D, uintptr(target), uintptr(level), uintptr(xoffset), uintptr(yoffset), uintptr(width), uintptr(height), uintptr(format), uintptr(xtype), uintptr(unsafe.Pointer(&pixels[0])))
|
|
runtime.KeepAlive(pixels)
|
|
}
|
|
|
|
func (c *defaultContext) Uniform1fv(location int32, value []float32) {
|
|
purego.SyscallN(c.gpUniform1fv, uintptr(location), uintptr(len(value)), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) Uniform1i(location int32, v0 int32) {
|
|
purego.SyscallN(c.gpUniform1i, uintptr(location), uintptr(v0))
|
|
}
|
|
|
|
func (c *defaultContext) Uniform1iv(location int32, value []int32) {
|
|
purego.SyscallN(c.gpUniform1iv, uintptr(location), uintptr(len(value)), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) Uniform2fv(location int32, value []float32) {
|
|
purego.SyscallN(c.gpUniform2fv, uintptr(location), uintptr(len(value)/2), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) Uniform3fv(location int32, value []float32) {
|
|
purego.SyscallN(c.gpUniform3fv, uintptr(location), uintptr(len(value)/3), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) Uniform4fv(location int32, value []float32) {
|
|
purego.SyscallN(c.gpUniform4fv, uintptr(location), uintptr(len(value)/4), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) UniformMatrix2fv(location int32, transpose bool, value []float32) {
|
|
purego.SyscallN(c.gpUniformMatrix2fv, uintptr(location), uintptr(len(value)/4), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) UniformMatrix3fv(location int32, transpose bool, value []float32) {
|
|
purego.SyscallN(c.gpUniformMatrix3fv, uintptr(location), uintptr(len(value)/9), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) UniformMatrix4fv(location int32, transpose bool, value []float32) {
|
|
purego.SyscallN(c.gpUniformMatrix4fv, uintptr(location), uintptr(len(value)/16), uintptr(boolToInt(transpose)), uintptr(unsafe.Pointer(&value[0])))
|
|
runtime.KeepAlive(value)
|
|
}
|
|
|
|
func (c *defaultContext) UseProgram(program uint32) {
|
|
purego.SyscallN(c.gpUseProgram, uintptr(program))
|
|
}
|
|
|
|
func (c *defaultContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
|
|
purego.SyscallN(c.gpVertexAttribPointer, uintptr(index), uintptr(size), uintptr(xtype), uintptr(boolToInt(normalized)), uintptr(stride), uintptr(offset))
|
|
}
|
|
|
|
func (c *defaultContext) Viewport(x int32, y int32, width int32, height int32) {
|
|
purego.SyscallN(c.gpViewport, uintptr(x), uintptr(y), uintptr(width), uintptr(height))
|
|
}
|
|
|
|
func (c *defaultContext) Init() error {
|
|
c.gpActiveTexture = getProcAddress("glActiveTexture")
|
|
if c.gpActiveTexture == 0 {
|
|
return errors.New("gl: glActiveTexture is missing")
|
|
}
|
|
c.gpAttachShader = getProcAddress("glAttachShader")
|
|
if c.gpAttachShader == 0 {
|
|
return errors.New("gl: glAttachShader is missing")
|
|
}
|
|
c.gpBindAttribLocation = getProcAddress("glBindAttribLocation")
|
|
if c.gpBindAttribLocation == 0 {
|
|
return errors.New("gl: glBindAttribLocation is missing")
|
|
}
|
|
c.gpBindBuffer = getProcAddress("glBindBuffer")
|
|
if c.gpBindBuffer == 0 {
|
|
return errors.New("gl: glBindBuffer is missing")
|
|
}
|
|
c.gpBindFramebufferEXT = getProcAddress("glBindFramebufferEXT")
|
|
c.gpBindRenderbufferEXT = getProcAddress("glBindRenderbufferEXT")
|
|
c.gpBindTexture = getProcAddress("glBindTexture")
|
|
if c.gpBindTexture == 0 {
|
|
return errors.New("gl: glBindTexture is missing")
|
|
}
|
|
c.gpBlendEquationSeparate = getProcAddress("glBlendEquationSeparate")
|
|
if c.gpBlendEquationSeparate == 0 {
|
|
return errors.New("gl: glBlendEquationSeparate is missing")
|
|
}
|
|
c.gpBlendFuncSeparate = getProcAddress("glBlendFuncSeparate")
|
|
if c.gpBlendFuncSeparate == 0 {
|
|
return errors.New("gl: glBlendFuncSeparate is missing")
|
|
}
|
|
c.gpBufferData = getProcAddress("glBufferData")
|
|
if c.gpBufferData == 0 {
|
|
return errors.New("gl: glBufferData is missing")
|
|
}
|
|
c.gpBufferSubData = getProcAddress("glBufferSubData")
|
|
if c.gpBufferSubData == 0 {
|
|
return errors.New("gl: glBufferSubData is missing")
|
|
}
|
|
c.gpCheckFramebufferStatusEXT = getProcAddress("glCheckFramebufferStatusEXT")
|
|
c.gpClear = getProcAddress("glClear")
|
|
if c.gpClear == 0 {
|
|
return errors.New("gl: glClear is missing")
|
|
}
|
|
c.gpColorMask = getProcAddress("glColorMask")
|
|
if c.gpColorMask == 0 {
|
|
return errors.New("gl: glColorMask is missing")
|
|
}
|
|
c.gpCompileShader = getProcAddress("glCompileShader")
|
|
if c.gpCompileShader == 0 {
|
|
return errors.New("gl: glCompileShader is missing")
|
|
}
|
|
c.gpCreateProgram = getProcAddress("glCreateProgram")
|
|
if c.gpCreateProgram == 0 {
|
|
return errors.New("gl: glCreateProgram is missing")
|
|
}
|
|
c.gpCreateShader = getProcAddress("glCreateShader")
|
|
if c.gpCreateShader == 0 {
|
|
return errors.New("gl: glCreateShader is missing")
|
|
}
|
|
c.gpDeleteBuffers = getProcAddress("glDeleteBuffers")
|
|
if c.gpDeleteBuffers == 0 {
|
|
return errors.New("gl: glDeleteBuffers is missing")
|
|
}
|
|
c.gpDeleteFramebuffersEXT = getProcAddress("glDeleteFramebuffersEXT")
|
|
c.gpDeleteProgram = getProcAddress("glDeleteProgram")
|
|
if c.gpDeleteProgram == 0 {
|
|
return errors.New("gl: glDeleteProgram is missing")
|
|
}
|
|
c.gpDeleteRenderbuffersEXT = getProcAddress("glDeleteRenderbuffersEXT")
|
|
c.gpDeleteShader = getProcAddress("glDeleteShader")
|
|
if c.gpDeleteShader == 0 {
|
|
return errors.New("gl: glDeleteShader is missing")
|
|
}
|
|
c.gpDeleteTextures = getProcAddress("glDeleteTextures")
|
|
if c.gpDeleteTextures == 0 {
|
|
return errors.New("gl: glDeleteTextures is missing")
|
|
}
|
|
c.gpDisable = getProcAddress("glDisable")
|
|
if c.gpDisable == 0 {
|
|
return errors.New("gl: glDisable is missing")
|
|
}
|
|
c.gpDisableVertexAttribArray = getProcAddress("glDisableVertexAttribArray")
|
|
if c.gpDisableVertexAttribArray == 0 {
|
|
return errors.New("gl: glDisableVertexAttribArray is missing")
|
|
}
|
|
c.gpDrawElements = getProcAddress("glDrawElements")
|
|
if c.gpDrawElements == 0 {
|
|
return errors.New("gl: glDrawElements is missing")
|
|
}
|
|
c.gpEnable = getProcAddress("glEnable")
|
|
if c.gpEnable == 0 {
|
|
return errors.New("gl: glEnable is missing")
|
|
}
|
|
c.gpEnableVertexAttribArray = getProcAddress("glEnableVertexAttribArray")
|
|
if c.gpEnableVertexAttribArray == 0 {
|
|
return errors.New("gl: glEnableVertexAttribArray is missing")
|
|
}
|
|
c.gpFlush = getProcAddress("glFlush")
|
|
if c.gpFlush == 0 {
|
|
return errors.New("gl: glFlush is missing")
|
|
}
|
|
c.gpFramebufferRenderbufferEXT = getProcAddress("glFramebufferRenderbufferEXT")
|
|
c.gpFramebufferTexture2DEXT = getProcAddress("glFramebufferTexture2DEXT")
|
|
c.gpGenBuffers = getProcAddress("glGenBuffers")
|
|
if c.gpGenBuffers == 0 {
|
|
return errors.New("gl: glGenBuffers is missing")
|
|
}
|
|
c.gpGenFramebuffersEXT = getProcAddress("glGenFramebuffersEXT")
|
|
c.gpGenRenderbuffersEXT = getProcAddress("glGenRenderbuffersEXT")
|
|
c.gpGenTextures = getProcAddress("glGenTextures")
|
|
if c.gpGenTextures == 0 {
|
|
return errors.New("gl: glGenTextures is missing")
|
|
}
|
|
c.gpGetError = getProcAddress("glGetError")
|
|
if c.gpGetError == 0 {
|
|
return errors.New("gl: glGetError is missing")
|
|
}
|
|
c.gpGetIntegerv = getProcAddress("glGetIntegerv")
|
|
if c.gpGetIntegerv == 0 {
|
|
return errors.New("gl: glGetIntegerv is missing")
|
|
}
|
|
c.gpGetProgramInfoLog = getProcAddress("glGetProgramInfoLog")
|
|
if c.gpGetProgramInfoLog == 0 {
|
|
return errors.New("gl: glGetProgramInfoLog is missing")
|
|
}
|
|
c.gpGetProgramiv = getProcAddress("glGetProgramiv")
|
|
if c.gpGetProgramiv == 0 {
|
|
return errors.New("gl: glGetProgramiv is missing")
|
|
}
|
|
c.gpGetShaderInfoLog = getProcAddress("glGetShaderInfoLog")
|
|
if c.gpGetShaderInfoLog == 0 {
|
|
return errors.New("gl: glGetShaderInfoLog is missing")
|
|
}
|
|
c.gpGetShaderiv = getProcAddress("glGetShaderiv")
|
|
if c.gpGetShaderiv == 0 {
|
|
return errors.New("gl: glGetShaderiv is missing")
|
|
}
|
|
c.gpGetUniformLocation = getProcAddress("glGetUniformLocation")
|
|
if c.gpGetUniformLocation == 0 {
|
|
return errors.New("gl: glGetUniformLocation is missing")
|
|
}
|
|
c.gpIsFramebufferEXT = getProcAddress("glIsFramebufferEXT")
|
|
c.gpIsProgram = getProcAddress("glIsProgram")
|
|
if c.gpIsProgram == 0 {
|
|
return errors.New("gl: glIsProgram is missing")
|
|
}
|
|
c.gpIsRenderbufferEXT = getProcAddress("glIsRenderbufferEXT")
|
|
c.gpIsTexture = getProcAddress("glIsTexture")
|
|
if c.gpIsTexture == 0 {
|
|
return errors.New("gl: glIsTexture is missing")
|
|
}
|
|
c.gpLinkProgram = getProcAddress("glLinkProgram")
|
|
if c.gpLinkProgram == 0 {
|
|
return errors.New("gl: glLinkProgram is missing")
|
|
}
|
|
c.gpPixelStorei = getProcAddress("glPixelStorei")
|
|
if c.gpPixelStorei == 0 {
|
|
return errors.New("gl: glPixelStorei is missing")
|
|
}
|
|
c.gpReadPixels = getProcAddress("glReadPixels")
|
|
if c.gpReadPixels == 0 {
|
|
return errors.New("gl: glReadPixels is missing")
|
|
}
|
|
c.gpRenderbufferStorageEXT = getProcAddress("glRenderbufferStorageEXT")
|
|
c.gpScissor = getProcAddress("glScissor")
|
|
if c.gpScissor == 0 {
|
|
return errors.New("gl: glScissor is missing")
|
|
}
|
|
c.gpShaderSource = getProcAddress("glShaderSource")
|
|
if c.gpShaderSource == 0 {
|
|
return errors.New("gl: glShaderSource is missing")
|
|
}
|
|
c.gpStencilFunc = getProcAddress("glStencilFunc")
|
|
if c.gpStencilFunc == 0 {
|
|
return errors.New("gl: glStencilFunc is missing")
|
|
}
|
|
c.gpStencilOp = getProcAddress("glStencilOp")
|
|
if c.gpStencilOp == 0 {
|
|
return errors.New("gl: glStencilOp is missing")
|
|
}
|
|
c.gpTexImage2D = getProcAddress("glTexImage2D")
|
|
if c.gpTexImage2D == 0 {
|
|
return errors.New("gl: glTexImage2D is missing")
|
|
}
|
|
c.gpTexParameteri = getProcAddress("glTexParameteri")
|
|
if c.gpTexParameteri == 0 {
|
|
return errors.New("gl: glTexParameteri is missing")
|
|
}
|
|
c.gpTexSubImage2D = getProcAddress("glTexSubImage2D")
|
|
if c.gpTexSubImage2D == 0 {
|
|
return errors.New("gl: glTexSubImage2D is missing")
|
|
}
|
|
c.gpUniform1fv = getProcAddress("glUniform1fv")
|
|
if c.gpUniform1fv == 0 {
|
|
return errors.New("gl: glUniform1fv is missing")
|
|
}
|
|
c.gpUniform1i = getProcAddress("glUniform1i")
|
|
if c.gpUniform1i == 0 {
|
|
return errors.New("gl: glUniform1i is missing")
|
|
}
|
|
c.gpUniform1iv = getProcAddress("glUniform1iv")
|
|
if c.gpUniform1iv == 0 {
|
|
return errors.New("gl: glUniform1iv is missing")
|
|
}
|
|
c.gpUniform2fv = getProcAddress("glUniform2fv")
|
|
if c.gpUniform2fv == 0 {
|
|
return errors.New("gl: glUniform2fv is missing")
|
|
}
|
|
c.gpUniform3fv = getProcAddress("glUniform3fv")
|
|
if c.gpUniform3fv == 0 {
|
|
return errors.New("gl: glUniform3fv is missing")
|
|
}
|
|
c.gpUniform4fv = getProcAddress("glUniform4fv")
|
|
if c.gpUniform4fv == 0 {
|
|
return errors.New("gl: glUniform4fv is missing")
|
|
}
|
|
c.gpUniformMatrix2fv = getProcAddress("glUniformMatrix2fv")
|
|
if c.gpUniformMatrix2fv == 0 {
|
|
return errors.New("gl: glUniformMatrix2fv is missing")
|
|
}
|
|
c.gpUniformMatrix3fv = getProcAddress("glUniformMatrix3fv")
|
|
if c.gpUniformMatrix3fv == 0 {
|
|
return errors.New("gl: glUniformMatrix3fv is missing")
|
|
}
|
|
c.gpUniformMatrix4fv = getProcAddress("glUniformMatrix4fv")
|
|
if c.gpUniformMatrix4fv == 0 {
|
|
return errors.New("gl: glUniformMatrix4fv is missing")
|
|
}
|
|
c.gpUseProgram = getProcAddress("glUseProgram")
|
|
if c.gpUseProgram == 0 {
|
|
return errors.New("gl: glUseProgram is missing")
|
|
}
|
|
c.gpVertexAttribPointer = getProcAddress("glVertexAttribPointer")
|
|
if c.gpVertexAttribPointer == 0 {
|
|
return errors.New("gl: glVertexAttribPointer is missing")
|
|
}
|
|
c.gpViewport = getProcAddress("glViewport")
|
|
if c.gpViewport == 0 {
|
|
return errors.New("gl: glViewport is missing")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// cStr takes a Go string (with or without null-termination)
|
|
// and returns the C counterpart.
|
|
//
|
|
// The returned free function must be called once you are done using the string
|
|
// in order to free the memory.
|
|
func cStr(str string) (cstr *byte, free func()) {
|
|
bs := []byte(str)
|
|
if len(bs) == 0 || bs[len(bs)-1] != 0 {
|
|
bs = append(bs, 0)
|
|
}
|
|
return &bs[0], func() {
|
|
runtime.KeepAlive(bs)
|
|
bs = nil
|
|
}
|
|
}
|