opengl: Rename Framebuffer -> framebufferNative

This commit is contained in:
Hajime Hoshi 2018-11-04 17:43:26 +09:00
parent c935c28498
commit 9dae11808f
5 changed files with 47 additions and 47 deletions

View File

@ -64,8 +64,8 @@ func convertOperation(op graphics.Operation) operation {
type Context struct {
locationCache *locationCache
screenFramebuffer Framebuffer // This might not be the default frame buffer '0' (e.g. iOS).
lastFramebuffer Framebuffer
screenFramebuffer framebufferNative // This might not be the default frame buffer '0' (e.g. iOS).
lastFramebuffer framebufferNative
lastTexture Texture
lastViewportWidth int
lastViewportHeight int
@ -88,7 +88,7 @@ func (c *Context) bindTexture(t Texture) {
c.lastTexture = t
}
func (c *Context) bindFramebuffer(f Framebuffer) {
func (c *Context) bindFramebuffer(f framebufferNative) {
if c.lastFramebuffer == f {
return
}
@ -113,7 +113,7 @@ func (c *Context) SetViewport(f *FramebufferStruct) {
}
}
func (c *Context) getScreenFramebuffer() Framebuffer {
func (c *Context) getScreenFramebuffer() framebufferNative {
return c.screenFramebuffer
}

View File

@ -29,11 +29,11 @@ import (
)
type (
Texture uint32
Framebuffer uint32
shader uint32
program uint32
buffer uint32
Texture uint32
framebufferNative uint32
shader uint32
program uint32
buffer uint32
)
var InvalidTexture Texture
@ -116,7 +116,7 @@ func (c *Context) reset() error {
_ = c.runOnContextThread(func() error {
f := int32(0)
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
c.screenFramebuffer = Framebuffer(f)
c.screenFramebuffer = framebufferNative(f)
return nil
})
return nil
@ -162,7 +162,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
return texture, nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) {
func (c *Context) bindFramebufferImpl(f framebufferNative) {
_ = c.runOnContextThread(func() error {
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
return nil
@ -232,8 +232,8 @@ func (c *Context) BeforeSwapping() {
c.bindFramebuffer(c.screenFramebuffer)
}
func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
var framebuffer Framebuffer
func (c *Context) newFramebuffer(texture Texture) (framebufferNative, error) {
var framebuffer framebufferNative
var f uint32
if err := c.runOnContextThread(func() error {
gl.GenFramebuffersEXT(1, &f)
@ -245,7 +245,7 @@ func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
}); err != nil {
return 0, err
}
c.bindFramebuffer(Framebuffer(f))
c.bindFramebuffer(framebufferNative(f))
if err := c.runOnContextThread(func() error {
gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER)
@ -258,7 +258,7 @@ func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
}
return fmt.Errorf("opengl: creating framebuffer failed: unknown error")
}
framebuffer = Framebuffer(f)
framebuffer = framebufferNative(f)
return nil
}); err != nil {
return 0, err
@ -273,7 +273,7 @@ func (c *Context) setViewportImpl(width, height int) {
})
}
func (c *Context) deleteFramebuffer(f Framebuffer) {
func (c *Context) deleteFramebuffer(f framebufferNative) {
_ = c.runOnContextThread(func() error {
ff := uint32(f)
if !gl.IsFramebufferEXT(ff) {

View File

@ -26,11 +26,11 @@ import (
)
type (
Texture js.Value
Framebuffer js.Value
shader js.Value
buffer js.Value
uniformLocation js.Value
Texture js.Value
framebufferNative js.Value
shader js.Value
buffer js.Value
uniformLocation js.Value
attribLocation int
programID int
@ -150,7 +150,7 @@ func Init() error {
func (c *Context) reset() error {
c.locationCache = newLocationCache()
c.lastTexture = Texture(js.Null())
c.lastFramebuffer = Framebuffer(js.Null())
c.lastFramebuffer = framebufferNative(js.Null())
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastCompositeMode = graphics.CompositeModeUnknown
@ -158,7 +158,7 @@ func (c *Context) reset() error {
gl.Call("enable", blend)
c.BlendFunc(graphics.CompositeModeSourceOver)
f := gl.Call("getParameter", framebufferBinding)
c.screenFramebuffer = Framebuffer(f)
c.screenFramebuffer = framebufferNative(f)
return nil
}
@ -199,7 +199,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
return Texture(t), nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) {
func (c *Context) bindFramebufferImpl(f framebufferNative) {
gl := c.gl
gl.Call("bindFramebuffer", framebuffer, js.Value(f))
}
@ -252,17 +252,17 @@ func (c *Context) TexSubImage2D(t Texture, pixels []byte, x, y, width, height in
p.Release()
}
func (c *Context) newFramebuffer(t Texture) (Framebuffer, error) {
func (c *Context) newFramebuffer(t Texture) (framebufferNative, error) {
gl := c.gl
f := gl.Call("createFramebuffer")
c.bindFramebuffer(Framebuffer(f))
c.bindFramebuffer(framebufferNative(f))
gl.Call("framebufferTexture2D", framebuffer, colorAttachment0, texture2d, js.Value(t), 0)
if s := gl.Call("checkFramebufferStatus", framebuffer); s.Int() != framebufferComplete.Int() {
return Framebuffer(js.Null()), errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s.Int()))
return framebufferNative(js.Null()), errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s.Int()))
}
return Framebuffer(f), nil
return framebufferNative(f), nil
}
func (c *Context) setViewportImpl(width, height int) {
@ -270,7 +270,7 @@ func (c *Context) setViewportImpl(width, height int) {
gl.Call("viewport", 0, 0, width, height)
}
func (c *Context) deleteFramebuffer(f Framebuffer) {
func (c *Context) deleteFramebuffer(f framebufferNative) {
gl := c.gl
if !gl.Call("isFramebuffer", js.Value(f)).Bool() {
return
@ -279,7 +279,7 @@ func (c *Context) deleteFramebuffer(f Framebuffer) {
// will be a default framebuffer.
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
if c.lastFramebuffer == f {
c.lastFramebuffer = Framebuffer(js.Null())
c.lastFramebuffer = framebufferNative(js.Null())
c.lastViewportWidth = 0
c.lastViewportHeight = 0
}

View File

@ -26,11 +26,11 @@ import (
)
type (
Texture mgl.Texture
Framebuffer mgl.Framebuffer
shader mgl.Shader
program mgl.Program
buffer mgl.Buffer
Texture mgl.Texture
framebufferNative mgl.Framebuffer
shader mgl.Shader
program mgl.Program
buffer mgl.Buffer
)
var InvalidTexture Texture
@ -44,7 +44,7 @@ type programID uint32
var (
invalidTexture = Texture(mgl.Texture{})
invalidFramebuffer = Framebuffer(mgl.Framebuffer{(1 << 32) - 1})
invalidFramebuffer = framebufferNative(mgl.Framebuffer{(1 << 32) - 1})
)
func getProgramID(p program) programID {
@ -117,7 +117,7 @@ func (c *Context) reset() error {
c.gl.Enable(mgl.BLEND)
c.BlendFunc(graphics.CompositeModeSourceOver)
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
c.screenFramebuffer = framebufferNative(mgl.Framebuffer{uint32(f)})
// TODO: Need to update screenFramebufferWidth/Height?
return nil
}
@ -151,7 +151,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
return Texture(t), nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) {
func (c *Context) bindFramebufferImpl(f framebufferNative) {
gl := c.gl
gl.BindFramebuffer(mgl.FRAMEBUFFER, mgl.Framebuffer(f))
}
@ -197,26 +197,26 @@ func (c *Context) TexSubImage2D(t Texture, p []byte, x, y, width, height int) {
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
}
func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
func (c *Context) newFramebuffer(texture Texture) (framebufferNative, error) {
gl := c.gl
f := gl.CreateFramebuffer()
if f.Value <= 0 {
return Framebuffer{}, errors.New("opengl: creating framebuffer failed: gl.IsFramebuffer returns false")
return framebufferNative{}, errors.New("opengl: creating framebuffer failed: gl.IsFramebuffer returns false")
}
c.bindFramebuffer(Framebuffer(f))
c.bindFramebuffer(framebufferNative(f))
gl.FramebufferTexture2D(mgl.FRAMEBUFFER, mgl.COLOR_ATTACHMENT0, mgl.TEXTURE_2D, mgl.Texture(texture), 0)
s := gl.CheckFramebufferStatus(mgl.FRAMEBUFFER)
if s != mgl.FRAMEBUFFER_COMPLETE {
if s != 0 {
return Framebuffer{}, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
return framebufferNative{}, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
}
if e := gl.GetError(); e != mgl.NO_ERROR {
return Framebuffer{}, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
return framebufferNative{}, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
}
return Framebuffer{}, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
return framebufferNative{}, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
}
return Framebuffer(f), nil
return framebufferNative(f), nil
}
func (c *Context) setViewportImpl(width, height int) {
@ -224,7 +224,7 @@ func (c *Context) setViewportImpl(width, height int) {
gl.Viewport(0, 0, width, height)
}
func (c *Context) deleteFramebuffer(f Framebuffer) {
func (c *Context) deleteFramebuffer(f framebufferNative) {
gl := c.gl
if !gl.IsFramebuffer(mgl.Framebuffer(f)) {
return

View File

@ -18,7 +18,7 @@ package opengl
//
// TODO: Create a new struct Image and embed this struct.
type FramebufferStruct struct {
native Framebuffer
native framebufferNative
proMatrix []float32
width int
height int