mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
opengl: Rename Framebuffer -> framebufferNative
This commit is contained in:
parent
c935c28498
commit
9dae11808f
@ -64,8 +64,8 @@ func convertOperation(op graphics.Operation) operation {
|
|||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
locationCache *locationCache
|
locationCache *locationCache
|
||||||
screenFramebuffer Framebuffer // This might not be the default frame buffer '0' (e.g. iOS).
|
screenFramebuffer framebufferNative // This might not be the default frame buffer '0' (e.g. iOS).
|
||||||
lastFramebuffer Framebuffer
|
lastFramebuffer framebufferNative
|
||||||
lastTexture Texture
|
lastTexture Texture
|
||||||
lastViewportWidth int
|
lastViewportWidth int
|
||||||
lastViewportHeight int
|
lastViewportHeight int
|
||||||
@ -88,7 +88,7 @@ func (c *Context) bindTexture(t Texture) {
|
|||||||
c.lastTexture = t
|
c.lastTexture = t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) bindFramebuffer(f Framebuffer) {
|
func (c *Context) bindFramebuffer(f framebufferNative) {
|
||||||
if c.lastFramebuffer == f {
|
if c.lastFramebuffer == f {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ func (c *Context) SetViewport(f *FramebufferStruct) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) getScreenFramebuffer() Framebuffer {
|
func (c *Context) getScreenFramebuffer() framebufferNative {
|
||||||
return c.screenFramebuffer
|
return c.screenFramebuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Texture uint32
|
Texture uint32
|
||||||
Framebuffer uint32
|
framebufferNative uint32
|
||||||
shader uint32
|
shader uint32
|
||||||
program uint32
|
program uint32
|
||||||
buffer uint32
|
buffer uint32
|
||||||
@ -116,7 +116,7 @@ func (c *Context) reset() error {
|
|||||||
_ = c.runOnContextThread(func() error {
|
_ = c.runOnContextThread(func() error {
|
||||||
f := int32(0)
|
f := int32(0)
|
||||||
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
|
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
|
||||||
c.screenFramebuffer = Framebuffer(f)
|
c.screenFramebuffer = framebufferNative(f)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@ -162,7 +162,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
|
|||||||
return texture, nil
|
return texture, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) bindFramebufferImpl(f Framebuffer) {
|
func (c *Context) bindFramebufferImpl(f framebufferNative) {
|
||||||
_ = c.runOnContextThread(func() error {
|
_ = c.runOnContextThread(func() error {
|
||||||
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
|
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
|
||||||
return nil
|
return nil
|
||||||
@ -232,8 +232,8 @@ func (c *Context) BeforeSwapping() {
|
|||||||
c.bindFramebuffer(c.screenFramebuffer)
|
c.bindFramebuffer(c.screenFramebuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
|
func (c *Context) newFramebuffer(texture Texture) (framebufferNative, error) {
|
||||||
var framebuffer Framebuffer
|
var framebuffer framebufferNative
|
||||||
var f uint32
|
var f uint32
|
||||||
if err := c.runOnContextThread(func() error {
|
if err := c.runOnContextThread(func() error {
|
||||||
gl.GenFramebuffersEXT(1, &f)
|
gl.GenFramebuffersEXT(1, &f)
|
||||||
@ -245,7 +245,7 @@ func (c *Context) newFramebuffer(texture Texture) (Framebuffer, error) {
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
c.bindFramebuffer(Framebuffer(f))
|
c.bindFramebuffer(framebufferNative(f))
|
||||||
if err := c.runOnContextThread(func() error {
|
if err := c.runOnContextThread(func() error {
|
||||||
gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
|
gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
|
||||||
s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER)
|
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")
|
return fmt.Errorf("opengl: creating framebuffer failed: unknown error")
|
||||||
}
|
}
|
||||||
framebuffer = Framebuffer(f)
|
framebuffer = framebufferNative(f)
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return 0, err
|
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 {
|
_ = c.runOnContextThread(func() error {
|
||||||
ff := uint32(f)
|
ff := uint32(f)
|
||||||
if !gl.IsFramebufferEXT(ff) {
|
if !gl.IsFramebufferEXT(ff) {
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Texture js.Value
|
Texture js.Value
|
||||||
Framebuffer js.Value
|
framebufferNative js.Value
|
||||||
shader js.Value
|
shader js.Value
|
||||||
buffer js.Value
|
buffer js.Value
|
||||||
uniformLocation js.Value
|
uniformLocation js.Value
|
||||||
@ -150,7 +150,7 @@ func Init() error {
|
|||||||
func (c *Context) reset() error {
|
func (c *Context) reset() error {
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
c.lastTexture = Texture(js.Null())
|
c.lastTexture = Texture(js.Null())
|
||||||
c.lastFramebuffer = Framebuffer(js.Null())
|
c.lastFramebuffer = framebufferNative(js.Null())
|
||||||
c.lastViewportWidth = 0
|
c.lastViewportWidth = 0
|
||||||
c.lastViewportHeight = 0
|
c.lastViewportHeight = 0
|
||||||
c.lastCompositeMode = graphics.CompositeModeUnknown
|
c.lastCompositeMode = graphics.CompositeModeUnknown
|
||||||
@ -158,7 +158,7 @@ func (c *Context) reset() error {
|
|||||||
gl.Call("enable", blend)
|
gl.Call("enable", blend)
|
||||||
c.BlendFunc(graphics.CompositeModeSourceOver)
|
c.BlendFunc(graphics.CompositeModeSourceOver)
|
||||||
f := gl.Call("getParameter", framebufferBinding)
|
f := gl.Call("getParameter", framebufferBinding)
|
||||||
c.screenFramebuffer = Framebuffer(f)
|
c.screenFramebuffer = framebufferNative(f)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
|
|||||||
return Texture(t), nil
|
return Texture(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) bindFramebufferImpl(f Framebuffer) {
|
func (c *Context) bindFramebufferImpl(f framebufferNative) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.Call("bindFramebuffer", framebuffer, js.Value(f))
|
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()
|
p.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) newFramebuffer(t Texture) (Framebuffer, error) {
|
func (c *Context) newFramebuffer(t Texture) (framebufferNative, error) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
f := gl.Call("createFramebuffer")
|
f := gl.Call("createFramebuffer")
|
||||||
c.bindFramebuffer(Framebuffer(f))
|
c.bindFramebuffer(framebufferNative(f))
|
||||||
|
|
||||||
gl.Call("framebufferTexture2D", framebuffer, colorAttachment0, texture2d, js.Value(t), 0)
|
gl.Call("framebufferTexture2D", framebuffer, colorAttachment0, texture2d, js.Value(t), 0)
|
||||||
if s := gl.Call("checkFramebufferStatus", framebuffer); s.Int() != framebufferComplete.Int() {
|
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) {
|
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)
|
gl.Call("viewport", 0, 0, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) deleteFramebuffer(f Framebuffer) {
|
func (c *Context) deleteFramebuffer(f framebufferNative) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
if !gl.Call("isFramebuffer", js.Value(f)).Bool() {
|
if !gl.Call("isFramebuffer", js.Value(f)).Bool() {
|
||||||
return
|
return
|
||||||
@ -279,7 +279,7 @@ func (c *Context) deleteFramebuffer(f Framebuffer) {
|
|||||||
// will be a default framebuffer.
|
// will be a default framebuffer.
|
||||||
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
|
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
|
||||||
if c.lastFramebuffer == f {
|
if c.lastFramebuffer == f {
|
||||||
c.lastFramebuffer = Framebuffer(js.Null())
|
c.lastFramebuffer = framebufferNative(js.Null())
|
||||||
c.lastViewportWidth = 0
|
c.lastViewportWidth = 0
|
||||||
c.lastViewportHeight = 0
|
c.lastViewportHeight = 0
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Texture mgl.Texture
|
Texture mgl.Texture
|
||||||
Framebuffer mgl.Framebuffer
|
framebufferNative mgl.Framebuffer
|
||||||
shader mgl.Shader
|
shader mgl.Shader
|
||||||
program mgl.Program
|
program mgl.Program
|
||||||
buffer mgl.Buffer
|
buffer mgl.Buffer
|
||||||
@ -44,7 +44,7 @@ type programID uint32
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
invalidTexture = Texture(mgl.Texture{})
|
invalidTexture = Texture(mgl.Texture{})
|
||||||
invalidFramebuffer = Framebuffer(mgl.Framebuffer{(1 << 32) - 1})
|
invalidFramebuffer = framebufferNative(mgl.Framebuffer{(1 << 32) - 1})
|
||||||
)
|
)
|
||||||
|
|
||||||
func getProgramID(p program) programID {
|
func getProgramID(p program) programID {
|
||||||
@ -117,7 +117,7 @@ func (c *Context) reset() error {
|
|||||||
c.gl.Enable(mgl.BLEND)
|
c.gl.Enable(mgl.BLEND)
|
||||||
c.BlendFunc(graphics.CompositeModeSourceOver)
|
c.BlendFunc(graphics.CompositeModeSourceOver)
|
||||||
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
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?
|
// TODO: Need to update screenFramebufferWidth/Height?
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
|
|||||||
return Texture(t), nil
|
return Texture(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) bindFramebufferImpl(f Framebuffer) {
|
func (c *Context) bindFramebufferImpl(f framebufferNative) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.BindFramebuffer(mgl.FRAMEBUFFER, mgl.Framebuffer(f))
|
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)
|
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
|
gl := c.gl
|
||||||
f := gl.CreateFramebuffer()
|
f := gl.CreateFramebuffer()
|
||||||
if f.Value <= 0 {
|
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)
|
gl.FramebufferTexture2D(mgl.FRAMEBUFFER, mgl.COLOR_ATTACHMENT0, mgl.TEXTURE_2D, mgl.Texture(texture), 0)
|
||||||
s := gl.CheckFramebufferStatus(mgl.FRAMEBUFFER)
|
s := gl.CheckFramebufferStatus(mgl.FRAMEBUFFER)
|
||||||
if s != mgl.FRAMEBUFFER_COMPLETE {
|
if s != mgl.FRAMEBUFFER_COMPLETE {
|
||||||
if s != 0 {
|
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 {
|
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) {
|
func (c *Context) setViewportImpl(width, height int) {
|
||||||
@ -224,7 +224,7 @@ func (c *Context) setViewportImpl(width, height int) {
|
|||||||
gl.Viewport(0, 0, width, height)
|
gl.Viewport(0, 0, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) deleteFramebuffer(f Framebuffer) {
|
func (c *Context) deleteFramebuffer(f framebufferNative) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
if !gl.IsFramebuffer(mgl.Framebuffer(f)) {
|
if !gl.IsFramebuffer(mgl.Framebuffer(f)) {
|
||||||
return
|
return
|
||||||
|
@ -18,7 +18,7 @@ package opengl
|
|||||||
//
|
//
|
||||||
// TODO: Create a new struct Image and embed this struct.
|
// TODO: Create a new struct Image and embed this struct.
|
||||||
type FramebufferStruct struct {
|
type FramebufferStruct struct {
|
||||||
native Framebuffer
|
native framebufferNative
|
||||||
proMatrix []float32
|
proMatrix []float32
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
Loading…
Reference in New Issue
Block a user