mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
opengl: Remove struct usages to avoid copying (framebuffer)
This commit is contained in:
parent
9400720ddf
commit
2936ea5080
@ -83,7 +83,7 @@ func (c *Context) BindTexture(t Texture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) bindFramebuffer(f Framebuffer) {
|
func (c *Context) bindFramebuffer(f Framebuffer) {
|
||||||
if c.lastFramebuffer.equals(f) {
|
if c.lastFramebuffer == f {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.bindFramebufferImpl(f)
|
c.bindFramebufferImpl(f)
|
||||||
|
@ -33,24 +33,17 @@ type Texture struct {
|
|||||||
*js.Object
|
*js.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
type Framebuffer struct {
|
|
||||||
*js.Object
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Shader interface{}
|
Framebuffer interface{}
|
||||||
Program interface{}
|
Shader interface{}
|
||||||
Buffer interface{}
|
Program interface{}
|
||||||
|
Buffer interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t Texture) equals(other Texture) bool {
|
func (t Texture) equals(other Texture) bool {
|
||||||
return t.Object == other.Object
|
return t.Object == other.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Framebuffer) equals(other Framebuffer) bool {
|
|
||||||
return f.Object == other.Object
|
|
||||||
}
|
|
||||||
|
|
||||||
type uniformLocation interface{}
|
type uniformLocation interface{}
|
||||||
|
|
||||||
type attribLocation int
|
type attribLocation int
|
||||||
@ -59,7 +52,7 @@ type programID int
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
invalidTexture = Texture{}
|
invalidTexture = Texture{}
|
||||||
invalidFramebuffer = Framebuffer{}
|
invalidFramebuffer = Framebuffer(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func getProgramID(p Program) programID {
|
func getProgramID(p Program) programID {
|
||||||
@ -135,7 +128,7 @@ func (c *Context) Reset() error {
|
|||||||
gl.Enable(gl.BLEND)
|
gl.Enable(gl.BLEND)
|
||||||
c.BlendFunc(CompositeModeSourceOver)
|
c.BlendFunc(CompositeModeSourceOver)
|
||||||
f := gl.GetParameter(gl.FRAMEBUFFER_BINDING)
|
f := gl.GetParameter(gl.FRAMEBUFFER_BINDING)
|
||||||
c.screenFramebuffer = Framebuffer{f}
|
c.screenFramebuffer = f
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +170,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error)
|
|||||||
|
|
||||||
func (c *Context) bindFramebufferImpl(f Framebuffer) {
|
func (c *Context) bindFramebufferImpl(f Framebuffer) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.BindFramebuffer(gl.FRAMEBUFFER, f.Object)
|
gl.BindFramebuffer(gl.FRAMEBUFFER, f.(*js.Object))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
|
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
|
||||||
@ -226,15 +219,15 @@ func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
|||||||
func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
|
func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
f := gl.CreateFramebuffer()
|
f := gl.CreateFramebuffer()
|
||||||
c.bindFramebuffer(Framebuffer{f})
|
c.bindFramebuffer(f)
|
||||||
|
|
||||||
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t.Object, 0)
|
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t.Object, 0)
|
||||||
s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
|
s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
|
||||||
if s != gl.FRAMEBUFFER_COMPLETE {
|
if s != gl.FRAMEBUFFER_COMPLETE {
|
||||||
return Framebuffer{nil}, errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s))
|
return nil, errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Framebuffer{f}, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) setViewportImpl(width, height int) {
|
func (c *Context) setViewportImpl(width, height int) {
|
||||||
@ -255,7 +248,7 @@ func (c *Context) FillFramebuffer(r, g, b, a float32) error {
|
|||||||
|
|
||||||
func (c *Context) DeleteFramebuffer(f Framebuffer) {
|
func (c *Context) DeleteFramebuffer(f Framebuffer) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
if !gl.IsFramebuffer(f.Object) {
|
if !gl.IsFramebuffer(f.(*js.Object)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If a framebuffer to be deleted is bound, a newly bound framebuffer
|
// If a framebuffer to be deleted is bound, a newly bound framebuffer
|
||||||
@ -266,7 +259,7 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
|
|||||||
c.lastViewportWidth = 0
|
c.lastViewportWidth = 0
|
||||||
c.lastViewportHeight = 0
|
c.lastViewportHeight = 0
|
||||||
}
|
}
|
||||||
gl.DeleteFramebuffer(f.Object)
|
gl.DeleteFramebuffer(f.(*js.Object))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error) {
|
func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user