internal/graphicsdriver/opengl: move OpenGL constants to seperate package (#2408)

Closes #2389
This commit is contained in:
Nathan Levett 2022-10-25 01:22:14 +11:00 committed by GitHub
parent 1906262ef4
commit f220eb729c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 174 additions and 215 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/glconst"
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
)
@ -101,14 +102,14 @@ func (c *context) reset() error {
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastBlend = graphicsdriver.Blend{}
gl.Enable(gl.BLEND)
gl.Enable(gl.SCISSOR_TEST)
gl.Enable(glconst.BLEND)
gl.Enable(glconst.SCISSOR_TEST)
// Set the source over blending.
c.blend(graphicsdriver.BlendSourceOver)
f := int32(0)
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
gl.GetIntegerv(glconst.FRAMEBUFFER_BINDING, &f)
c.screenFramebuffer = framebufferNative(f)
return nil
}
@ -144,42 +145,42 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
texture := textureNative(t)
c.bindTexture(texture)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
gl.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_MAG_FILTER, glconst.NEAREST)
gl.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_MIN_FILTER, glconst.NEAREST)
gl.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_S, glconst.CLAMP_TO_EDGE)
gl.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_T, glconst.CLAMP_TO_EDGE)
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
gl.PixelStorei(glconst.UNPACK_ALIGNMENT, 4)
// If data is nil, this just allocates memory and the content is undefined.
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
gl.TexImage2D(glconst.TEXTURE_2D, 0, glconst.RGBA, int32(width), int32(height), 0, glconst.RGBA, glconst.UNSIGNED_BYTE, nil)
return texture, nil
}
func (c *context) bindFramebufferImpl(f framebufferNative) {
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
gl.BindFramebufferEXT(glconst.FRAMEBUFFER, uint32(f))
}
func (c *context) framebufferPixels(buf []byte, f *framebuffer, x, y, width, height int) {
gl.Flush()
c.bindFramebuffer(f.native)
gl.ReadPixels(int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(buf))
gl.ReadPixels(int32(x), int32(y), int32(width), int32(height), glconst.RGBA, glconst.UNSIGNED_BYTE, gl.Ptr(buf))
}
func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width, height int) {
gl.Flush()
c.bindFramebuffer(f.native)
gl.BindBuffer(gl.PIXEL_PACK_BUFFER, uint32(buffer))
gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, nil)
gl.BindBuffer(gl.PIXEL_PACK_BUFFER, 0)
gl.BindBuffer(glconst.PIXEL_PACK_BUFFER, uint32(buffer))
gl.ReadPixels(0, 0, int32(width), int32(height), glconst.RGBA, glconst.UNSIGNED_BYTE, nil)
gl.BindBuffer(glconst.PIXEL_PACK_BUFFER, 0)
}
func (c *context) activeTexture(idx int) {
gl.ActiveTexture(gl.TEXTURE0 + uint32(idx))
gl.ActiveTexture(glconst.TEXTURE0 + uint32(idx))
}
func (c *context) bindTextureImpl(t textureNative) {
gl.BindTexture(gl.TEXTURE_2D, uint32(t))
gl.BindTexture(glconst.TEXTURE_2D, uint32(t))
}
func (c *context) deleteTexture(t textureNative) {
@ -209,13 +210,13 @@ func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error)
// GL_STENCIL_INDEX8 might not be available with OpenGL 2.1.
// https://www.khronos.org/opengl/wiki/Image_Format
gl.RenderbufferStorageEXT(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, int32(width), int32(height))
gl.RenderbufferStorageEXT(glconst.RENDERBUFFER, glconst.DEPTH24_STENCIL8, int32(width), int32(height))
return renderbuffer, nil
}
func (c *context) bindRenderbufferImpl(r renderbufferNative) {
gl.BindRenderbufferEXT(gl.RENDERBUFFER, uint32(r))
gl.BindRenderbufferEXT(glconst.RENDERBUFFER, uint32(r))
}
func (c *context) deleteRenderbuffer(r renderbufferNative) {
@ -236,13 +237,13 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
return 0, errors.New("opengl: creating framebuffer failed")
}
c.bindFramebuffer(framebufferNative(f))
gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER)
if s != gl.FRAMEBUFFER_COMPLETE {
gl.FramebufferTexture2DEXT(glconst.FRAMEBUFFER, glconst.COLOR_ATTACHMENT0, glconst.TEXTURE_2D, uint32(texture), 0)
s := gl.CheckFramebufferStatusEXT(glconst.FRAMEBUFFER)
if s != glconst.FRAMEBUFFER_COMPLETE {
if s != 0 {
return 0, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
}
if e := gl.GetError(); e != gl.NO_ERROR {
if e := gl.GetError(); e != glconst.NO_ERROR {
return 0, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
}
return 0, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
@ -253,8 +254,8 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
func (c *context) bindStencilBuffer(f framebufferNative, r renderbufferNative) error {
c.bindFramebuffer(f)
gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, uint32(r))
if s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER); s != gl.FRAMEBUFFER_COMPLETE {
gl.FramebufferRenderbufferEXT(glconst.FRAMEBUFFER, glconst.STENCIL_ATTACHMENT, glconst.RENDERBUFFER, uint32(r))
if s := gl.CheckFramebufferStatusEXT(glconst.FRAMEBUFFER); s != glconst.FRAMEBUFFER_COMPLETE {
return errors.New(fmt.Sprintf("opengl: glFramebufferRenderbuffer failed: %d", s))
}
return nil
@ -278,11 +279,11 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
}
func (c *context) newVertexShader(source string) (shader, error) {
return c.newShader(gl.VERTEX_SHADER, source)
return c.newShader(glconst.VERTEX_SHADER, source)
}
func (c *context) newFragmentShader(source string) (shader, error) {
return c.newShader(gl.FRAGMENT_SHADER, source)
return c.newShader(glconst.FRAGMENT_SHADER, source)
}
func (c *context) newShader(shaderType uint32, source string) (shader, error) {
@ -296,11 +297,11 @@ func (c *context) newShader(shaderType uint32, source string) (shader, error) {
gl.CompileShader(s)
var v int32
gl.GetShaderiv(s, gl.COMPILE_STATUS, &v)
if v == gl.FALSE {
gl.GetShaderiv(s, glconst.COMPILE_STATUS, &v)
if v == glconst.FALSE {
var l int32
var log []byte
gl.GetShaderiv(uint32(s), gl.INFO_LOG_LENGTH, &l)
gl.GetShaderiv(uint32(s), glconst.INFO_LOG_LENGTH, &l)
if l != 0 {
log = make([]byte, l)
gl.GetShaderInfoLog(s, l, nil, (*uint8)(gl.Ptr(log)))
@ -332,11 +333,11 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
gl.LinkProgram(p)
var v int32
gl.GetProgramiv(p, gl.LINK_STATUS, &v)
if v == gl.FALSE {
gl.GetProgramiv(p, glconst.LINK_STATUS, &v)
if v == glconst.FALSE {
var l int32
var log []byte
gl.GetProgramiv(p, gl.INFO_LOG_LENGTH, &l)
gl.GetProgramiv(p, glconst.INFO_LOG_LENGTH, &l)
if l != 0 {
log = make([]byte, l)
gl.GetProgramInfoLog(p, l, nil, (*uint8)(gl.Ptr(log)))
@ -419,7 +420,7 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
}
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
gl.VertexAttribPointer(uint32(index), int32(size), gl.FLOAT, false, int32(stride), uintptr(offset))
gl.VertexAttribPointer(uint32(index), int32(size), glconst.FLOAT, false, int32(stride), uintptr(offset))
}
func (c *context) enableVertexAttribArray(index int) {
@ -433,33 +434,33 @@ func (c *context) disableVertexAttribArray(index int) {
func (c *context) newArrayBuffer(size int) buffer {
var b uint32
gl.GenBuffers(1, &b)
gl.BindBuffer(gl.ARRAY_BUFFER, b)
gl.BufferData(gl.ARRAY_BUFFER, size, nil, gl.DYNAMIC_DRAW)
gl.BindBuffer(glconst.ARRAY_BUFFER, b)
gl.BufferData(glconst.ARRAY_BUFFER, size, nil, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) newElementArrayBuffer(size int) buffer {
var b uint32
gl.GenBuffers(1, &b)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, b)
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, size, nil, gl.DYNAMIC_DRAW)
gl.BindBuffer(glconst.ELEMENT_ARRAY_BUFFER, b)
gl.BufferData(glconst.ELEMENT_ARRAY_BUFFER, size, nil, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) bindArrayBuffer(b buffer) {
gl.BindBuffer(gl.ARRAY_BUFFER, uint32(b))
gl.BindBuffer(glconst.ARRAY_BUFFER, uint32(b))
}
func (c *context) bindElementArrayBuffer(b buffer) {
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, uint32(b))
gl.BindBuffer(glconst.ELEMENT_ARRAY_BUFFER, uint32(b))
}
func (c *context) arrayBufferSubData(data []float32) {
gl.BufferSubData(gl.ARRAY_BUFFER, 0, len(data)*4, gl.Ptr(data))
gl.BufferSubData(glconst.ARRAY_BUFFER, 0, len(data)*4, gl.Ptr(data))
}
func (c *context) elementArrayBufferSubData(data []uint16) {
gl.BufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, len(data)*2, gl.Ptr(data))
gl.BufferSubData(glconst.ELEMENT_ARRAY_BUFFER, 0, len(data)*2, gl.Ptr(data))
}
func (c *context) deleteBuffer(b buffer) {
@ -468,12 +469,12 @@ func (c *context) deleteBuffer(b buffer) {
}
func (c *context) drawElements(len int, offsetInBytes int) {
gl.DrawElements(gl.TRIANGLES, int32(len), gl.UNSIGNED_SHORT, uintptr(offsetInBytes))
gl.DrawElements(glconst.TRIANGLES, int32(len), glconst.UNSIGNED_SHORT, uintptr(offsetInBytes))
}
func (c *context) maxTextureSizeImpl() int {
s := int32(0)
gl.GetIntegerv(gl.MAX_TEXTURE_SIZE, &s)
gl.GetIntegerv(glconst.MAX_TEXTURE_SIZE, &s)
return int(s)
}
@ -488,27 +489,27 @@ func (c *context) needsRestoring() bool {
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
c.bindTexture(t)
for _, a := range args {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(a.Pixels))
gl.TexSubImage2D(glconst.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), glconst.RGBA, glconst.UNSIGNED_BYTE, gl.Ptr(a.Pixels))
}
}
func (c *context) enableStencilTest() {
gl.Enable(gl.STENCIL_TEST)
gl.Enable(glconst.STENCIL_TEST)
}
func (c *context) disableStencilTest() {
gl.Disable(gl.STENCIL_TEST)
gl.Disable(glconst.STENCIL_TEST)
}
func (c *context) beginStencilWithEvenOddRule() {
gl.Clear(gl.STENCIL_BUFFER_BIT)
gl.StencilFunc(gl.ALWAYS, 0x00, 0xff)
gl.StencilOp(gl.KEEP, gl.KEEP, gl.INVERT)
gl.Clear(glconst.STENCIL_BUFFER_BIT)
gl.StencilFunc(glconst.ALWAYS, 0x00, 0xff)
gl.StencilOp(glconst.KEEP, glconst.KEEP, glconst.INVERT)
gl.ColorMask(false, false, false, false)
}
func (c *context) endStencilWithEvenOddRule() {
gl.StencilFunc(gl.NOTEQUAL, 0x00, 0xff)
gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
gl.StencilFunc(glconst.NOTEQUAL, 0x00, 0xff)
gl.StencilOp(glconst.KEEP, glconst.KEEP, glconst.KEEP)
gl.ColorMask(true, true, true, true)
}

View File

@ -23,6 +23,7 @@ import (
"fmt"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/glconst"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
)
@ -94,11 +95,11 @@ func (c *context) reset() error {
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastBlend = graphicsdriver.Blend{}
c.ctx.Enable(gles.BLEND)
c.ctx.Enable(gles.SCISSOR_TEST)
c.ctx.Enable(glconst.BLEND)
c.ctx.Enable(glconst.SCISSOR_TEST)
c.blend(graphicsdriver.BlendSourceOver)
f := make([]int32, 1)
c.ctx.GetIntegerv(f, gles.FRAMEBUFFER_BINDING)
c.ctx.GetIntegerv(f, glconst.FRAMEBUFFER_BINDING)
c.screenFramebuffer = framebufferNative(f[0])
// TODO: Need to update screenFramebufferWidth/Height?
return nil
@ -132,18 +133,18 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
}
c.bindTexture(textureNative(t))
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST)
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_MIN_FILTER, gles.NEAREST)
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_WRAP_S, gles.CLAMP_TO_EDGE)
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, gles.CLAMP_TO_EDGE)
c.ctx.PixelStorei(gles.UNPACK_ALIGNMENT, 4)
c.ctx.TexImage2D(gles.TEXTURE_2D, 0, gles.RGBA, int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE, nil)
c.ctx.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_MAG_FILTER, glconst.NEAREST)
c.ctx.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_MIN_FILTER, glconst.NEAREST)
c.ctx.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_S, glconst.CLAMP_TO_EDGE)
c.ctx.TexParameteri(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_T, glconst.CLAMP_TO_EDGE)
c.ctx.PixelStorei(glconst.UNPACK_ALIGNMENT, 4)
c.ctx.TexImage2D(glconst.TEXTURE_2D, 0, glconst.RGBA, int32(width), int32(height), glconst.RGBA, glconst.UNSIGNED_BYTE, nil)
return textureNative(t), nil
}
func (c *context) bindFramebufferImpl(f framebufferNative) {
c.ctx.BindFramebuffer(gles.FRAMEBUFFER, uint32(f))
c.ctx.BindFramebuffer(glconst.FRAMEBUFFER, uint32(f))
}
func (c *context) framebufferPixels(buf []byte, f *framebuffer, x, y, width, height int) {
@ -151,7 +152,7 @@ func (c *context) framebufferPixels(buf []byte, f *framebuffer, x, y, width, hei
c.bindFramebuffer(f.native)
c.ctx.ReadPixels(buf, int32(x), int32(y), int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE)
c.ctx.ReadPixels(buf, int32(x), int32(y), int32(width), int32(height), glconst.RGBA, glconst.UNSIGNED_BYTE)
}
func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width, height int) {
@ -159,17 +160,17 @@ func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width
c.bindFramebuffer(f.native)
c.ctx.BindBuffer(gles.PIXEL_PACK_BUFFER, uint32(buffer))
c.ctx.ReadPixels(nil, 0, 0, int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE)
c.ctx.BindBuffer(gles.PIXEL_PACK_BUFFER, 0)
c.ctx.BindBuffer(glconst.PIXEL_PACK_BUFFER, uint32(buffer))
c.ctx.ReadPixels(nil, 0, 0, int32(width), int32(height), glconst.RGBA, glconst.UNSIGNED_BYTE)
c.ctx.BindBuffer(glconst.PIXEL_PACK_BUFFER, 0)
}
func (c *context) activeTexture(idx int) {
c.ctx.ActiveTexture(uint32(gles.TEXTURE0 + idx))
c.ctx.ActiveTexture(uint32(glconst.TEXTURE0 + idx))
}
func (c *context) bindTextureImpl(t textureNative) {
c.ctx.BindTexture(gles.TEXTURE_2D, uint32(t))
c.ctx.BindTexture(glconst.TEXTURE_2D, uint32(t))
}
func (c *context) deleteTexture(t textureNative) {
@ -195,13 +196,13 @@ func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error)
renderbuffer := renderbufferNative(r)
c.bindRenderbuffer(renderbuffer)
c.ctx.RenderbufferStorage(gles.RENDERBUFFER, gles.STENCIL_INDEX8, int32(width), int32(height))
c.ctx.RenderbufferStorage(glconst.RENDERBUFFER, glconst.STENCIL_INDEX8, int32(width), int32(height))
return renderbuffer, nil
}
func (c *context) bindRenderbufferImpl(r renderbufferNative) {
c.ctx.BindRenderbuffer(gles.RENDERBUFFER, uint32(r))
c.ctx.BindRenderbuffer(glconst.RENDERBUFFER, uint32(r))
}
func (c *context) deleteRenderbuffer(r renderbufferNative) {
@ -221,13 +222,13 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
}
c.bindFramebuffer(framebufferNative(f))
c.ctx.FramebufferTexture2D(gles.FRAMEBUFFER, gles.COLOR_ATTACHMENT0, gles.TEXTURE_2D, uint32(texture), 0)
s := c.ctx.CheckFramebufferStatus(gles.FRAMEBUFFER)
if s != gles.FRAMEBUFFER_COMPLETE {
c.ctx.FramebufferTexture2D(glconst.FRAMEBUFFER, glconst.COLOR_ATTACHMENT0, glconst.TEXTURE_2D, uint32(texture), 0)
s := c.ctx.CheckFramebufferStatus(glconst.FRAMEBUFFER)
if s != glconst.FRAMEBUFFER_COMPLETE {
if s != 0 {
return 0, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
}
if e := c.ctx.GetError(); e != gles.NO_ERROR {
if e := c.ctx.GetError(); e != glconst.NO_ERROR {
return 0, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
}
return 0, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
@ -238,8 +239,8 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
func (c *context) bindStencilBuffer(f framebufferNative, r renderbufferNative) error {
c.bindFramebuffer(f)
c.ctx.FramebufferRenderbuffer(gles.FRAMEBUFFER, gles.STENCIL_ATTACHMENT, gles.RENDERBUFFER, uint32(r))
if s := c.ctx.CheckFramebufferStatus(gles.FRAMEBUFFER); s != gles.FRAMEBUFFER_COMPLETE {
c.ctx.FramebufferRenderbuffer(glconst.FRAMEBUFFER, glconst.STENCIL_ATTACHMENT, glconst.RENDERBUFFER, uint32(r))
if s := c.ctx.CheckFramebufferStatus(glconst.FRAMEBUFFER); s != glconst.FRAMEBUFFER_COMPLETE {
return errors.New(fmt.Sprintf("opengl: glFramebufferRenderbuffer failed: %d", s))
}
return nil
@ -265,11 +266,11 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
}
func (c *context) newVertexShader(source string) (shader, error) {
return c.newShader(gles.VERTEX_SHADER, source)
return c.newShader(glconst.VERTEX_SHADER, source)
}
func (c *context) newFragmentShader(source string) (shader, error) {
return c.newShader(gles.FRAGMENT_SHADER, source)
return c.newShader(glconst.FRAGMENT_SHADER, source)
}
func (c *context) newShader(shaderType uint32, source string) (shader, error) {
@ -281,8 +282,8 @@ func (c *context) newShader(shaderType uint32, source string) (shader, error) {
c.ctx.CompileShader(s)
v := make([]int32, 1)
c.ctx.GetShaderiv(v, s, gles.COMPILE_STATUS)
if v[0] == gles.FALSE {
c.ctx.GetShaderiv(v, s, glconst.COMPILE_STATUS)
if v[0] == glconst.FALSE {
log := c.ctx.GetShaderInfoLog(s)
return 0, fmt.Errorf("opengl: shader compile failed: %s", log)
}
@ -309,8 +310,8 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
c.ctx.LinkProgram(p)
v := make([]int32, 1)
c.ctx.GetProgramiv(v, p, gles.LINK_STATUS)
if v[0] == gles.FALSE {
c.ctx.GetProgramiv(v, p, glconst.LINK_STATUS)
if v[0] == glconst.FALSE {
info := c.ctx.GetProgramInfoLog(p)
return 0, fmt.Errorf("opengl: program error: %s", info)
}
@ -386,7 +387,7 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
}
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
c.ctx.VertexAttribPointer(uint32(index), int32(size), gles.FLOAT, false, int32(stride), offset)
c.ctx.VertexAttribPointer(uint32(index), int32(size), glconst.FLOAT, false, int32(stride), offset)
}
func (c *context) enableVertexAttribArray(index int) {
@ -399,32 +400,32 @@ func (c *context) disableVertexAttribArray(index int) {
func (c *context) newArrayBuffer(size int) buffer {
b := c.ctx.GenBuffers(1)[0]
c.ctx.BindBuffer(gles.ARRAY_BUFFER, b)
c.ctx.BufferData(gles.ARRAY_BUFFER, size, nil, gles.DYNAMIC_DRAW)
c.ctx.BindBuffer(glconst.ARRAY_BUFFER, b)
c.ctx.BufferData(glconst.ARRAY_BUFFER, size, nil, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) newElementArrayBuffer(size int) buffer {
b := c.ctx.GenBuffers(1)[0]
c.ctx.BindBuffer(gles.ELEMENT_ARRAY_BUFFER, b)
c.ctx.BufferData(gles.ELEMENT_ARRAY_BUFFER, size, nil, gles.DYNAMIC_DRAW)
c.ctx.BindBuffer(glconst.ELEMENT_ARRAY_BUFFER, b)
c.ctx.BufferData(glconst.ELEMENT_ARRAY_BUFFER, size, nil, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) bindArrayBuffer(b buffer) {
c.ctx.BindBuffer(gles.ARRAY_BUFFER, uint32(b))
c.ctx.BindBuffer(glconst.ARRAY_BUFFER, uint32(b))
}
func (c *context) bindElementArrayBuffer(b buffer) {
c.ctx.BindBuffer(gles.ELEMENT_ARRAY_BUFFER, uint32(b))
c.ctx.BindBuffer(glconst.ELEMENT_ARRAY_BUFFER, uint32(b))
}
func (c *context) arrayBufferSubData(data []float32) {
c.ctx.BufferSubData(gles.ARRAY_BUFFER, 0, float32sToBytes(data))
c.ctx.BufferSubData(glconst.ARRAY_BUFFER, 0, float32sToBytes(data))
}
func (c *context) elementArrayBufferSubData(data []uint16) {
c.ctx.BufferSubData(gles.ELEMENT_ARRAY_BUFFER, 0, uint16sToBytes(data))
c.ctx.BufferSubData(glconst.ELEMENT_ARRAY_BUFFER, 0, uint16sToBytes(data))
}
func (c *context) deleteBuffer(b buffer) {
@ -432,12 +433,12 @@ func (c *context) deleteBuffer(b buffer) {
}
func (c *context) drawElements(len int, offsetInBytes int) {
c.ctx.DrawElements(gles.TRIANGLES, int32(len), gles.UNSIGNED_SHORT, offsetInBytes)
c.ctx.DrawElements(glconst.TRIANGLES, int32(len), glconst.UNSIGNED_SHORT, offsetInBytes)
}
func (c *context) maxTextureSizeImpl() int {
v := make([]int32, 1)
c.ctx.GetIntegerv(v, gles.MAX_TEXTURE_SIZE)
c.ctx.GetIntegerv(v, glconst.MAX_TEXTURE_SIZE)
return int(v[0])
}
@ -458,27 +459,27 @@ func (c *context) canUsePBO() bool {
func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) {
c.bindTexture(t)
for _, a := range args {
c.ctx.TexSubImage2D(gles.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), gles.RGBA, gles.UNSIGNED_BYTE, a.Pixels)
c.ctx.TexSubImage2D(glconst.TEXTURE_2D, 0, int32(a.X), int32(a.Y), int32(a.Width), int32(a.Height), glconst.RGBA, glconst.UNSIGNED_BYTE, a.Pixels)
}
}
func (c *context) enableStencilTest() {
c.ctx.Enable(gles.STENCIL_TEST)
c.ctx.Enable(glconst.STENCIL_TEST)
}
func (c *context) disableStencilTest() {
c.ctx.Disable(gles.STENCIL_TEST)
c.ctx.Disable(glconst.STENCIL_TEST)
}
func (c *context) beginStencilWithEvenOddRule() {
c.ctx.Clear(gles.STENCIL_BUFFER_BIT)
c.ctx.StencilFunc(gles.ALWAYS, 0x00, 0xff)
c.ctx.StencilOp(gles.KEEP, gles.KEEP, gles.INVERT)
c.ctx.Clear(glconst.STENCIL_BUFFER_BIT)
c.ctx.StencilFunc(glconst.ALWAYS, 0x00, 0xff)
c.ctx.StencilOp(glconst.KEEP, glconst.KEEP, glconst.INVERT)
c.ctx.ColorMask(false, false, false, false)
}
func (c *context) endStencilWithEvenOddRule() {
c.ctx.StencilFunc(gles.NOTEQUAL, 0x00, 0xff)
c.ctx.StencilOp(gles.KEEP, gles.KEEP, gles.KEEP)
c.ctx.StencilFunc(glconst.NOTEQUAL, 0x00, 0xff)
c.ctx.StencilOp(glconst.KEEP, glconst.KEEP, glconst.KEEP)
c.ctx.ColorMask(true, true, true, true)
}

View File

@ -22,7 +22,7 @@ import (
"syscall/js"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/glconst"
"github.com/hajimehoshi/ebiten/v2/internal/jsutil"
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
)
@ -173,10 +173,10 @@ func (c *context) reset() error {
return graphicsdriver.GraphicsNotReady
}
gl := c.gl
gl.enable.Invoke(gles.BLEND)
gl.enable.Invoke(gles.SCISSOR_TEST)
gl.enable.Invoke(glconst.BLEND)
gl.enable.Invoke(glconst.SCISSOR_TEST)
c.blend(graphicsdriver.BlendSourceOver)
f := gl.getParameter.Invoke(gles.FRAMEBUFFER_BINDING)
f := gl.getParameter.Invoke(glconst.FRAMEBUFFER_BINDING)
c.screenFramebuffer = framebufferNative(f)
if !c.usesWebGL2() {
@ -216,12 +216,12 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
}
c.bindTexture(textureNative(t))
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST)
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_MIN_FILTER, gles.NEAREST)
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_WRAP_S, gles.CLAMP_TO_EDGE)
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, gles.CLAMP_TO_EDGE)
gl.texParameteri.Invoke(glconst.TEXTURE_2D, glconst.TEXTURE_MAG_FILTER, glconst.NEAREST)
gl.texParameteri.Invoke(glconst.TEXTURE_2D, glconst.TEXTURE_MIN_FILTER, glconst.NEAREST)
gl.texParameteri.Invoke(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_S, glconst.CLAMP_TO_EDGE)
gl.texParameteri.Invoke(glconst.TEXTURE_2D, glconst.TEXTURE_WRAP_T, glconst.CLAMP_TO_EDGE)
gl.pixelStorei.Invoke(gles.UNPACK_ALIGNMENT, 4)
gl.pixelStorei.Invoke(glconst.UNPACK_ALIGNMENT, 4)
// Firefox warns the usage of textures without specifying pixels (#629)
//
// Error: WebGL warning: drawElements: This operation requires zeroing texture data. This is slow.
@ -229,14 +229,14 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
// In Ebiten, textures are filled with pixels laster by the filter that ignores destination, so it is fine
// to leave textures as uninitialized here. Rather, extra memory allocating for initialization should be
// avoided.
gl.texImage2D.Invoke(gles.TEXTURE_2D, 0, gles.RGBA, width, height, 0, gles.RGBA, gles.UNSIGNED_BYTE, nil)
gl.texImage2D.Invoke(glconst.TEXTURE_2D, 0, glconst.RGBA, width, height, 0, glconst.RGBA, glconst.UNSIGNED_BYTE, nil)
return textureNative(t), nil
}
func (c *context) bindFramebufferImpl(f framebufferNative) {
gl := c.gl
gl.bindFramebuffer.Invoke(gles.FRAMEBUFFER, js.Value(f))
gl.bindFramebuffer.Invoke(glconst.FRAMEBUFFER, js.Value(f))
}
func (c *context) framebufferPixels(buf []byte, f *framebuffer, x, y, width, height int) {
@ -246,7 +246,7 @@ func (c *context) framebufferPixels(buf []byte, f *framebuffer, x, y, width, hei
l := 4 * width * height
p := jsutil.TemporaryUint8ArrayFromUint8Slice(l, nil)
gl.readPixels.Invoke(x, y, width, height, gles.RGBA, gles.UNSIGNED_BYTE, p)
gl.readPixels.Invoke(x, y, width, height, glconst.RGBA, glconst.UNSIGNED_BYTE, p)
copy(buf, uint8ArrayToSlice(p, l))
}
@ -254,20 +254,20 @@ func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width
gl := c.gl
c.bindFramebuffer(f.native)
gl.bindBuffer.Invoke(gles.PIXEL_PACK_BUFFER, js.Value(buffer))
gl.bindBuffer.Invoke(glconst.PIXEL_PACK_BUFFER, js.Value(buffer))
// void gl.readPixels(x, y, width, height, format, type, GLintptr offset);
gl.readPixels.Invoke(0, 0, width, height, gles.RGBA, gles.UNSIGNED_BYTE, 0)
gl.bindBuffer.Invoke(gles.PIXEL_PACK_BUFFER, nil)
gl.readPixels.Invoke(0, 0, width, height, glconst.RGBA, glconst.UNSIGNED_BYTE, 0)
gl.bindBuffer.Invoke(glconst.PIXEL_PACK_BUFFER, nil)
}
func (c *context) activeTexture(idx int) {
gl := c.gl
gl.activeTexture.Invoke(gles.TEXTURE0 + idx)
gl.activeTexture.Invoke(glconst.TEXTURE0 + idx)
}
func (c *context) bindTextureImpl(t textureNative) {
gl := c.gl
gl.bindTexture.Invoke(gles.TEXTURE_2D, js.Value(t))
gl.bindTexture.Invoke(glconst.TEXTURE_2D, js.Value(t))
}
func (c *context) deleteTexture(t textureNative) {
@ -296,14 +296,14 @@ func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error)
c.bindRenderbuffer(renderbufferNative(r))
// TODO: Is STENCIL_INDEX8 portable?
// https://stackoverflow.com/questions/11084961/binding-a-stencil-render-buffer-to-a-frame-buffer-in-opengl
gl.renderbufferStorage.Invoke(gles.RENDERBUFFER, gles.STENCIL_INDEX8, width, height)
gl.renderbufferStorage.Invoke(glconst.RENDERBUFFER, glconst.STENCIL_INDEX8, width, height)
return renderbufferNative(r), nil
}
func (c *context) bindRenderbufferImpl(r renderbufferNative) {
gl := c.gl
gl.bindRenderbuffer.Invoke(gles.RENDERBUFFER, js.Value(r))
gl.bindRenderbuffer.Invoke(glconst.RENDERBUFFER, js.Value(r))
}
func (c *context) deleteRenderbuffer(r renderbufferNative) {
@ -322,8 +322,8 @@ func (c *context) newFramebuffer(t textureNative) (framebufferNative, error) {
f := gl.createFramebuffer.Invoke()
c.bindFramebuffer(framebufferNative(f))
gl.framebufferTexture2D.Invoke(gles.FRAMEBUFFER, gles.COLOR_ATTACHMENT0, gles.TEXTURE_2D, js.Value(t), 0)
if s := gl.checkFramebufferStatus.Invoke(gles.FRAMEBUFFER); s.Int() != gles.FRAMEBUFFER_COMPLETE {
gl.framebufferTexture2D.Invoke(glconst.FRAMEBUFFER, glconst.COLOR_ATTACHMENT0, glconst.TEXTURE_2D, js.Value(t), 0)
if s := gl.checkFramebufferStatus.Invoke(glconst.FRAMEBUFFER); s.Int() != glconst.FRAMEBUFFER_COMPLETE {
return framebufferNative(js.Null()), errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s.Int()))
}
@ -334,8 +334,8 @@ func (c *context) bindStencilBuffer(f framebufferNative, r renderbufferNative) e
gl := c.gl
c.bindFramebuffer(f)
gl.framebufferRenderbuffer.Invoke(gles.FRAMEBUFFER, gles.STENCIL_ATTACHMENT, gles.RENDERBUFFER, js.Value(r))
if s := gl.checkFramebufferStatus.Invoke(gles.FRAMEBUFFER); s.Int() != gles.FRAMEBUFFER_COMPLETE {
gl.framebufferRenderbuffer.Invoke(glconst.FRAMEBUFFER, glconst.STENCIL_ATTACHMENT, glconst.RENDERBUFFER, js.Value(r))
if s := gl.checkFramebufferStatus.Invoke(glconst.FRAMEBUFFER); s.Int() != glconst.FRAMEBUFFER_COMPLETE {
return errors.New(fmt.Sprintf("opengl: framebufferRenderbuffer failed: %d", s.Int()))
}
return nil
@ -363,11 +363,11 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
}
func (c *context) newVertexShader(source string) (shader, error) {
return c.newShader(gles.VERTEX_SHADER, source)
return c.newShader(glconst.VERTEX_SHADER, source)
}
func (c *context) newFragmentShader(source string) (shader, error) {
return c.newShader(gles.FRAGMENT_SHADER, source)
return c.newShader(glconst.FRAGMENT_SHADER, source)
}
func (c *context) newShader(shaderType int, source string) (shader, error) {
@ -380,7 +380,7 @@ func (c *context) newShader(shaderType int, source string) (shader, error) {
gl.shaderSource.Invoke(js.Value(s), source)
gl.compileShader.Invoke(js.Value(s))
if !gl.getShaderParameter.Invoke(js.Value(s), gles.COMPILE_STATUS).Bool() {
if !gl.getShaderParameter.Invoke(js.Value(s), glconst.COMPILE_STATUS).Bool() {
log := gl.getShaderInfoLog.Invoke(js.Value(s))
return shader(js.Null()), fmt.Errorf("opengl: shader compile failed: %s", log)
}
@ -408,7 +408,7 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
}
gl.linkProgram.Invoke(v)
if !gl.getProgramParameter.Invoke(v, gles.LINK_STATUS).Bool() {
if !gl.getProgramParameter.Invoke(v, glconst.LINK_STATUS).Bool() {
info := gl.getProgramInfoLog.Invoke(v).String()
return program{}, fmt.Errorf("opengl: program error: %s", info)
}
@ -527,7 +527,7 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
func (c *context) vertexAttribPointer(index int, size int, stride int, offset int) {
gl := c.gl
gl.vertexAttribPointer.Invoke(index, size, gles.FLOAT, false, stride, offset)
gl.vertexAttribPointer.Invoke(index, size, glconst.FLOAT, false, stride, offset)
}
func (c *context) enableVertexAttribArray(index int) {
@ -543,27 +543,27 @@ func (c *context) disableVertexAttribArray(index int) {
func (c *context) newArrayBuffer(size int) buffer {
gl := c.gl
b := gl.createBuffer.Invoke()
gl.bindBuffer.Invoke(gles.ARRAY_BUFFER, js.Value(b))
gl.bufferData.Invoke(gles.ARRAY_BUFFER, size, gles.DYNAMIC_DRAW)
gl.bindBuffer.Invoke(glconst.ARRAY_BUFFER, js.Value(b))
gl.bufferData.Invoke(glconst.ARRAY_BUFFER, size, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) newElementArrayBuffer(size int) buffer {
gl := c.gl
b := gl.createBuffer.Invoke()
gl.bindBuffer.Invoke(gles.ELEMENT_ARRAY_BUFFER, js.Value(b))
gl.bufferData.Invoke(gles.ELEMENT_ARRAY_BUFFER, size, gles.DYNAMIC_DRAW)
gl.bindBuffer.Invoke(glconst.ELEMENT_ARRAY_BUFFER, js.Value(b))
gl.bufferData.Invoke(glconst.ELEMENT_ARRAY_BUFFER, size, glconst.DYNAMIC_DRAW)
return buffer(b)
}
func (c *context) bindArrayBuffer(b buffer) {
gl := c.gl
gl.bindBuffer.Invoke(gles.ARRAY_BUFFER, js.Value(b))
gl.bindBuffer.Invoke(glconst.ARRAY_BUFFER, js.Value(b))
}
func (c *context) bindElementArrayBuffer(b buffer) {
gl := c.gl
gl.bindBuffer.Invoke(gles.ELEMENT_ARRAY_BUFFER, js.Value(b))
gl.bindBuffer.Invoke(glconst.ELEMENT_ARRAY_BUFFER, js.Value(b))
}
func (c *context) arrayBufferSubData(data []float32) {
@ -571,9 +571,9 @@ func (c *context) arrayBufferSubData(data []float32) {
l := len(data) * 4
arr := jsutil.TemporaryUint8ArrayFromFloat32Slice(l, data)
if c.usesWebGL2() {
gl.bufferSubData.Invoke(gles.ARRAY_BUFFER, 0, arr, 0, l)
gl.bufferSubData.Invoke(glconst.ARRAY_BUFFER, 0, arr, 0, l)
} else {
gl.bufferSubData.Invoke(gles.ARRAY_BUFFER, 0, arr.Call("subarray", 0, l))
gl.bufferSubData.Invoke(glconst.ARRAY_BUFFER, 0, arr.Call("subarray", 0, l))
}
}
@ -582,9 +582,9 @@ func (c *context) elementArrayBufferSubData(data []uint16) {
l := len(data) * 2
arr := jsutil.TemporaryUint8ArrayFromUint16Slice(l, data)
if c.usesWebGL2() {
gl.bufferSubData.Invoke(gles.ELEMENT_ARRAY_BUFFER, 0, arr, 0, l)
gl.bufferSubData.Invoke(glconst.ELEMENT_ARRAY_BUFFER, 0, arr, 0, l)
} else {
gl.bufferSubData.Invoke(gles.ELEMENT_ARRAY_BUFFER, 0, arr.Call("subarray", 0, l))
gl.bufferSubData.Invoke(glconst.ELEMENT_ARRAY_BUFFER, 0, arr.Call("subarray", 0, l))
}
}
@ -595,12 +595,12 @@ func (c *context) deleteBuffer(b buffer) {
func (c *context) drawElements(len int, offsetInBytes int) {
gl := c.gl
gl.drawElements.Invoke(gles.TRIANGLES, len, gles.UNSIGNED_SHORT, offsetInBytes)
gl.drawElements.Invoke(glconst.TRIANGLES, len, glconst.UNSIGNED_SHORT, offsetInBytes)
}
func (c *context) maxTextureSizeImpl() int {
gl := c.gl
return gl.getParameter.Invoke(gles.MAX_TEXTURE_SIZE).Int()
return gl.getParameter.Invoke(glconst.MAX_TEXTURE_SIZE).Int()
}
func (c *context) flush() {
@ -626,37 +626,37 @@ func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePix
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
// GLsizei width, GLsizei height,
// GLenum format, GLenum type, ArrayBufferView pixels, srcOffset);
gl.texSubImage2D.Invoke(gles.TEXTURE_2D, 0, a.X, a.Y, a.Width, a.Height, gles.RGBA, gles.UNSIGNED_BYTE, arr, 0)
gl.texSubImage2D.Invoke(glconst.TEXTURE_2D, 0, a.X, a.Y, a.Width, a.Height, glconst.RGBA, glconst.UNSIGNED_BYTE, arr, 0)
} else {
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
// GLsizei width, GLsizei height,
// GLenum format, GLenum type, ArrayBufferView? pixels);
gl.texSubImage2D.Invoke(gles.TEXTURE_2D, 0, a.X, a.Y, a.Width, a.Height, gles.RGBA, gles.UNSIGNED_BYTE, arr)
gl.texSubImage2D.Invoke(glconst.TEXTURE_2D, 0, a.X, a.Y, a.Width, a.Height, glconst.RGBA, glconst.UNSIGNED_BYTE, arr)
}
}
}
func (c *context) enableStencilTest() {
gl := c.gl
gl.enable.Invoke(gles.STENCIL_TEST)
gl.enable.Invoke(glconst.STENCIL_TEST)
}
func (c *context) disableStencilTest() {
gl := c.gl
gl.disable.Invoke(gles.STENCIL_TEST)
gl.disable.Invoke(glconst.STENCIL_TEST)
}
func (c *context) beginStencilWithEvenOddRule() {
gl := c.gl
gl.clear.Invoke(gles.STENCIL_BUFFER_BIT)
gl.stencilFunc.Invoke(gles.ALWAYS, 0x00, 0xff)
gl.stencilOp.Invoke(gles.KEEP, gles.KEEP, gles.INVERT)
gl.clear.Invoke(glconst.STENCIL_BUFFER_BIT)
gl.stencilFunc.Invoke(glconst.ALWAYS, 0x00, 0xff)
gl.stencilOp.Invoke(glconst.KEEP, glconst.KEEP, glconst.INVERT)
gl.colorMask.Invoke(false, false, false, false)
}
func (c *context) endStencilWithEvenOddRule() {
gl := c.gl
gl.stencilFunc.Invoke(gles.NOTEQUAL, 0x00, 0xff)
gl.stencilOp.Invoke(gles.KEEP, gles.KEEP, gles.KEEP)
gl.stencilFunc.Invoke(glconst.NOTEQUAL, 0x00, 0xff)
gl.stencilOp.Invoke(glconst.KEEP, glconst.KEEP, glconst.KEEP)
gl.colorMask.Invoke(true, true, true, true)
}

View File

@ -16,7 +16,7 @@ import (
//
// var data []uint8
// ...
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
// gl.TexImage2D(glconst.TEXTURE_2D, ..., glconst.UNSIGNED_BYTE, gl.Ptr(&data[0]))
func Ptr(data interface{}) unsafe.Pointer {
if data == nil {
return unsafe.Pointer(nil)

View File

@ -15,56 +15,6 @@
// Package gl implements Go bindings to OpenGL.
package gl
const (
ALWAYS = 0x0207
ARRAY_BUFFER = 0x8892
BLEND = 0x0BE2
CLAMP_TO_EDGE = 0x812F
COLOR_ATTACHMENT0 = 0x8CE0
COMPILE_STATUS = 0x8B81
DEPTH24_STENCIL8 = 0x88F0
DYNAMIC_DRAW = 0x88E8
ELEMENT_ARRAY_BUFFER = 0x8893
FALSE = 0
FLOAT = 0x1406
FRAGMENT_SHADER = 0x8B30
FRAMEBUFFER = 0x8D40
FRAMEBUFFER_BINDING = 0x8CA6
FRAMEBUFFER_COMPLETE = 0x8CD5
INFO_LOG_LENGTH = 0x8B84
INVERT = 0x150A
KEEP = 0x1E00
LINK_STATUS = 0x8B82
MAX_TEXTURE_SIZE = 0x0D33
NEAREST = 0x2600
NO_ERROR = 0
NOTEQUAL = 0x0205
PIXEL_PACK_BUFFER = 0x88EB
PIXEL_UNPACK_BUFFER = 0x88EC
READ_WRITE = 0x88BA
RENDERBUFFER = 0x8D41
RGBA = 0x1908
SHORT = 0x1402
STENCIL_ATTACHMENT = 0x8D20
STENCIL_BUFFER_BIT = 0x0400
STENCIL_TEST = 0x0B90
STREAM_DRAW = 0x88E0
TEXTURE0 = 0x84C0
TEXTURE_2D = 0x0DE1
TEXTURE_MAG_FILTER = 0x2800
TEXTURE_MIN_FILTER = 0x2801
TEXTURE_WRAP_S = 0x2802
TEXTURE_WRAP_T = 0x2803
TRIANGLES = 0x0004
TRUE = 1
SCISSOR_TEST = 0x0C11
UNPACK_ALIGNMENT = 0x0CF5
UNSIGNED_BYTE = 0x1401
UNSIGNED_SHORT = 0x1403
VERTEX_SHADER = 0x8B31
WRITE_ONLY = 0x88B9
)
// Init initializes the OpenGL bindings by loading the function pointers (for
// each OpenGL function) from the active OpenGL context.
//

View File

@ -425,6 +425,8 @@ import "C"
import (
"errors"
"unsafe"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/glconst"
)
var (
@ -733,22 +735,22 @@ func GetVertexArrayPointeri_vEXT(vaobj uint32, index uint32, pname uint32, param
func IsFramebufferEXT(framebuffer uint32) bool {
ret := C.glowIsFramebufferEXT(gpIsFramebufferEXT, (C.GLuint)(framebuffer))
return ret == TRUE
return ret == glconst.TRUE
}
func IsProgram(program uint32) bool {
ret := C.glowIsProgram(gpIsProgram, (C.GLuint)(program))
return ret == TRUE
return ret == glconst.TRUE
}
func IsRenderbufferEXT(renderbuffer uint32) bool {
ret := C.glowIsRenderbufferEXT(gpIsRenderbufferEXT, (C.GLuint)(renderbuffer))
return ret == TRUE
return ret == glconst.TRUE
}
func IsTexture(texture uint32) bool {
ret := C.glowIsTexture(gpIsTexture, (C.GLuint)(texture))
return ret == TRUE
return ret == glconst.TRUE
}
func LinkProgram(program uint32) {

View File

@ -1,4 +1,4 @@
// Copyright 2020 The Ebiten Authors
// 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.
@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package gles implements Go bindings to OpenGL ES.
package gles
// Package glconst provides constants to the implementations of Go bindings to
// OpenGL and OpenGL ES, for packages gl and gles respectively.
package glconst
const (
ALWAYS = 0x0207
@ -22,6 +23,7 @@ const (
CLAMP_TO_EDGE = 0x812F
COLOR_ATTACHMENT0 = 0x8CE0
COMPILE_STATUS = 0x8B81
DEPTH24_STENCIL8 = 0x88F0
DYNAMIC_DRAW = 0x88E8
ELEMENT_ARRAY_BUFFER = 0x8893
FALSE = 0

View File

@ -37,13 +37,15 @@ import "C"
import (
"unsafe"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/glconst"
)
func glBool(x bool) C.GLboolean {
if x {
return TRUE
return glconst.TRUE
}
return FALSE
return glconst.FALSE
}
type DefaultContext struct{}
@ -216,7 +218,7 @@ func (DefaultContext) GetProgramiv(dst []int32, program uint32, pname uint32) {
func (d DefaultContext) GetProgramInfoLog(program uint32) string {
buflens := make([]int32, 1)
d.GetProgramiv(buflens, program, INFO_LOG_LENGTH)
d.GetProgramiv(buflens, program, glconst.INFO_LOG_LENGTH)
buflen := buflens[0]
if buflen == 0 {
return ""
@ -233,7 +235,7 @@ func (DefaultContext) GetShaderiv(dst []int32, shader uint32, pname uint32) {
func (d DefaultContext) GetShaderInfoLog(shader uint32) string {
buflens := make([]int32, 1)
d.GetShaderiv(buflens, shader, INFO_LOG_LENGTH)
d.GetShaderiv(buflens, shader, glconst.INFO_LOG_LENGTH)
buflen := buflens[0]
if buflen == 0 {
return ""
@ -258,19 +260,19 @@ func (DefaultContext) GetUniformLocation(program uint32, name string) int32 {
}
func (DefaultContext) IsFramebuffer(framebuffer uint32) bool {
return C.glIsFramebuffer(C.GLuint(framebuffer)) != FALSE
return C.glIsFramebuffer(C.GLuint(framebuffer)) != glconst.FALSE
}
func (DefaultContext) IsProgram(program uint32) bool {
return C.glIsProgram(C.GLuint(program)) != FALSE
return C.glIsProgram(C.GLuint(program)) != glconst.FALSE
}
func (DefaultContext) IsRenderbuffer(renderbuffer uint32) bool {
return C.glIsRenderbuffer(C.GLuint(renderbuffer)) != FALSE
return C.glIsRenderbuffer(C.GLuint(renderbuffer)) != glconst.FALSE
}
func (DefaultContext) IsTexture(texture uint32) bool {
return C.glIsTexture(C.GLuint(texture)) != FALSE
return C.glIsTexture(C.GLuint(texture)) != glconst.FALSE
}
func (DefaultContext) LinkProgram(program uint32) {

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package gles implements Go bindings to OpenGL ES.
package gles
type Context interface {