mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Rename opengl.Image (that is originally wrong) -> opengl.Framebuffer
This commit is contained in:
parent
43988399ee
commit
095c3ca380
@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) {
|
||||
r, err := opengl.NewZeroRenderTarget(screenWidth*screenScale, screenHeight*screenScale)
|
||||
f, err := opengl.NewZeroFramebuffer(screenWidth*screenScale, screenHeight*screenScale)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -37,7 +37,7 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
|
||||
}
|
||||
|
||||
c := &graphicsContext{
|
||||
defaultR: &innerImage{r, nil},
|
||||
defaultR: &innerImage{f, nil},
|
||||
screen: screen,
|
||||
screenScale: screenScale,
|
||||
}
|
||||
@ -52,11 +52,11 @@ type graphicsContext struct {
|
||||
|
||||
func (c *graphicsContext) dispose() {
|
||||
// NOTE: Now this method is not used anywhere.
|
||||
glRenderTarget := c.screen.renderTarget
|
||||
glTexture := c.screen.texture
|
||||
framebuffer := c.screen.framebuffer
|
||||
texture := c.screen.texture
|
||||
|
||||
glRenderTarget.Dispose()
|
||||
glTexture.Dispose()
|
||||
framebuffer.Dispose()
|
||||
texture.Dispose()
|
||||
}
|
||||
|
||||
func (c *graphicsContext) preUpdate() error {
|
||||
|
16
image.go
16
image.go
@ -25,20 +25,20 @@ import (
|
||||
)
|
||||
|
||||
type innerImage struct {
|
||||
renderTarget *opengl.Image
|
||||
texture *opengl.Texture
|
||||
framebuffer *opengl.Framebuffer
|
||||
texture *opengl.Texture
|
||||
}
|
||||
|
||||
func newInnerImage(texture *opengl.Texture, filter int) (*innerImage, error) {
|
||||
renderTarget, err := opengl.NewRenderTargetFromTexture(texture)
|
||||
framebuffer, err := opengl.NewFramebufferFromTexture(texture)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &innerImage{renderTarget, texture}, nil
|
||||
return &innerImage{framebuffer, texture}, nil
|
||||
}
|
||||
|
||||
func (i *innerImage) size() (width, height int) {
|
||||
return i.renderTarget.Size()
|
||||
return i.framebuffer.Size()
|
||||
}
|
||||
|
||||
func (i *innerImage) Clear() error {
|
||||
@ -46,7 +46,7 @@ func (i *innerImage) Clear() error {
|
||||
}
|
||||
|
||||
func (i *innerImage) Fill(clr color.Color) error {
|
||||
if err := i.renderTarget.SetAsViewport(); err != nil {
|
||||
if err := i.framebuffer.SetAsViewport(); err != nil {
|
||||
return err
|
||||
}
|
||||
rf, gf, bf, af := internal.RGBA(clr)
|
||||
@ -56,7 +56,7 @@ func (i *innerImage) Fill(clr color.Color) error {
|
||||
}
|
||||
|
||||
func (i *innerImage) drawImage(image *innerImage, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||
if err := i.renderTarget.SetAsViewport(); err != nil {
|
||||
if err := i.framebuffer.SetAsViewport(); err != nil {
|
||||
return err
|
||||
}
|
||||
w, h := image.texture.Size()
|
||||
@ -65,7 +65,7 @@ func (i *innerImage) drawImage(image *innerImage, parts []ImagePart, geo Geometr
|
||||
if i.texture != nil {
|
||||
targetNativeTexture = i.texture.Native()
|
||||
}
|
||||
projectionMatrix := i.renderTarget.ProjectionMatrix()
|
||||
projectionMatrix := i.framebuffer.ProjectionMatrix()
|
||||
shader.DrawTexture(image.texture.Native(), targetNativeTexture, projectionMatrix, quads, &geo, &color)
|
||||
return nil
|
||||
}
|
||||
|
@ -37,15 +37,15 @@ func orthoProjectionMatrix(left, right, bottom, top int) [4][4]float64 {
|
||||
}
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
type Framebuffer struct {
|
||||
framebuffer gl.Framebuffer
|
||||
width int
|
||||
height int
|
||||
flipY bool
|
||||
}
|
||||
|
||||
func NewZeroRenderTarget(width, height int) (*Image, error) {
|
||||
r := &Image{
|
||||
func NewZeroFramebuffer(width, height int) (*Framebuffer, error) {
|
||||
r := &Framebuffer{
|
||||
width: width,
|
||||
height: height,
|
||||
flipY: true,
|
||||
@ -53,25 +53,25 @@ func NewZeroRenderTarget(width, height int) (*Image, error) {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func NewRenderTargetFromTexture(texture *Texture) (*Image, error) {
|
||||
func NewFramebufferFromTexture(texture *Texture) (*Framebuffer, error) {
|
||||
framebuffer, err := createFramebuffer(texture.Native())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w, h := texture.Size()
|
||||
return &Image{
|
||||
return &Framebuffer{
|
||||
framebuffer: framebuffer,
|
||||
width: w,
|
||||
height: h,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Image) Size() (width, height int) {
|
||||
return r.width, r.height
|
||||
func (f *Framebuffer) Size() (width, height int) {
|
||||
return f.width, f.height
|
||||
}
|
||||
|
||||
func (r *Image) Dispose() {
|
||||
r.framebuffer.Delete()
|
||||
func (f *Framebuffer) Dispose() {
|
||||
f.framebuffer.Delete()
|
||||
}
|
||||
|
||||
func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) {
|
||||
@ -86,9 +86,9 @@ func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) {
|
||||
return framebuffer, nil
|
||||
}
|
||||
|
||||
func (r *Image) SetAsViewport() error {
|
||||
func (f *Framebuffer) SetAsViewport() error {
|
||||
gl.Flush()
|
||||
r.framebuffer.Bind()
|
||||
f.framebuffer.Bind()
|
||||
err := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
|
||||
if err != gl.FRAMEBUFFER_COMPLETE {
|
||||
if gl.GetError() != 0 {
|
||||
@ -97,19 +97,19 @@ func (r *Image) SetAsViewport() error {
|
||||
return errors.New("glBindFramebuffer failed: the context is different?")
|
||||
}
|
||||
|
||||
width := internal.NextPowerOf2Int(r.width)
|
||||
height := internal.NextPowerOf2Int(r.height)
|
||||
width := internal.NextPowerOf2Int(f.width)
|
||||
height := internal.NextPowerOf2Int(f.height)
|
||||
gl.Viewport(0, 0, width, height)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Image) ProjectionMatrix() [4][4]float64 {
|
||||
width := internal.NextPowerOf2Int(r.width)
|
||||
height := internal.NextPowerOf2Int(r.height)
|
||||
func (f *Framebuffer) ProjectionMatrix() [4][4]float64 {
|
||||
width := internal.NextPowerOf2Int(f.width)
|
||||
height := internal.NextPowerOf2Int(f.height)
|
||||
m := orthoProjectionMatrix(0, width, 0, height)
|
||||
if r.flipY {
|
||||
if f.flipY {
|
||||
m[1][1] *= -1
|
||||
m[1][3] += float64(r.height) / float64(internal.NextPowerOf2Int(r.height)) * 2
|
||||
m[1][3] += float64(f.height) / float64(internal.NextPowerOf2Int(f.height)) * 2
|
||||
}
|
||||
return m
|
||||
}
|
Loading…
Reference in New Issue
Block a user