Rename opengl.Image (that is originally wrong) -> opengl.Framebuffer

This commit is contained in:
Hajime Hoshi 2014-12-23 00:01:22 +09:00
parent 43988399ee
commit 095c3ca380
3 changed files with 32 additions and 32 deletions

View File

@ -22,7 +22,7 @@ import (
) )
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -37,7 +37,7 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
} }
c := &graphicsContext{ c := &graphicsContext{
defaultR: &innerImage{r, nil}, defaultR: &innerImage{f, nil},
screen: screen, screen: screen,
screenScale: screenScale, screenScale: screenScale,
} }
@ -52,11 +52,11 @@ type graphicsContext struct {
func (c *graphicsContext) dispose() { func (c *graphicsContext) dispose() {
// NOTE: Now this method is not used anywhere. // NOTE: Now this method is not used anywhere.
glRenderTarget := c.screen.renderTarget framebuffer := c.screen.framebuffer
glTexture := c.screen.texture texture := c.screen.texture
glRenderTarget.Dispose() framebuffer.Dispose()
glTexture.Dispose() texture.Dispose()
} }
func (c *graphicsContext) preUpdate() error { func (c *graphicsContext) preUpdate() error {

View File

@ -25,20 +25,20 @@ import (
) )
type innerImage struct { type innerImage struct {
renderTarget *opengl.Image framebuffer *opengl.Framebuffer
texture *opengl.Texture texture *opengl.Texture
} }
func newInnerImage(texture *opengl.Texture, filter int) (*innerImage, error) { func newInnerImage(texture *opengl.Texture, filter int) (*innerImage, error) {
renderTarget, err := opengl.NewRenderTargetFromTexture(texture) framebuffer, err := opengl.NewFramebufferFromTexture(texture)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &innerImage{renderTarget, texture}, nil return &innerImage{framebuffer, texture}, nil
} }
func (i *innerImage) size() (width, height int) { func (i *innerImage) size() (width, height int) {
return i.renderTarget.Size() return i.framebuffer.Size()
} }
func (i *innerImage) Clear() error { func (i *innerImage) Clear() error {
@ -46,7 +46,7 @@ func (i *innerImage) Clear() error {
} }
func (i *innerImage) Fill(clr color.Color) 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 return err
} }
rf, gf, bf, af := internal.RGBA(clr) 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 { 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 return err
} }
w, h := image.texture.Size() w, h := image.texture.Size()
@ -65,7 +65,7 @@ func (i *innerImage) drawImage(image *innerImage, parts []ImagePart, geo Geometr
if i.texture != nil { if i.texture != nil {
targetNativeTexture = i.texture.Native() targetNativeTexture = i.texture.Native()
} }
projectionMatrix := i.renderTarget.ProjectionMatrix() projectionMatrix := i.framebuffer.ProjectionMatrix()
shader.DrawTexture(image.texture.Native(), targetNativeTexture, projectionMatrix, quads, &geo, &color) shader.DrawTexture(image.texture.Native(), targetNativeTexture, projectionMatrix, quads, &geo, &color)
return nil return nil
} }

View File

@ -37,15 +37,15 @@ func orthoProjectionMatrix(left, right, bottom, top int) [4][4]float64 {
} }
} }
type Image struct { type Framebuffer struct {
framebuffer gl.Framebuffer framebuffer gl.Framebuffer
width int width int
height int height int
flipY bool flipY bool
} }
func NewZeroRenderTarget(width, height int) (*Image, error) { func NewZeroFramebuffer(width, height int) (*Framebuffer, error) {
r := &Image{ r := &Framebuffer{
width: width, width: width,
height: height, height: height,
flipY: true, flipY: true,
@ -53,25 +53,25 @@ func NewZeroRenderTarget(width, height int) (*Image, error) {
return r, nil return r, nil
} }
func NewRenderTargetFromTexture(texture *Texture) (*Image, error) { func NewFramebufferFromTexture(texture *Texture) (*Framebuffer, error) {
framebuffer, err := createFramebuffer(texture.Native()) framebuffer, err := createFramebuffer(texture.Native())
if err != nil { if err != nil {
return nil, err return nil, err
} }
w, h := texture.Size() w, h := texture.Size()
return &Image{ return &Framebuffer{
framebuffer: framebuffer, framebuffer: framebuffer,
width: w, width: w,
height: h, height: h,
}, nil }, nil
} }
func (r *Image) Size() (width, height int) { func (f *Framebuffer) Size() (width, height int) {
return r.width, r.height return f.width, f.height
} }
func (r *Image) Dispose() { func (f *Framebuffer) Dispose() {
r.framebuffer.Delete() f.framebuffer.Delete()
} }
func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) { func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) {
@ -86,9 +86,9 @@ func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) {
return framebuffer, nil return framebuffer, nil
} }
func (r *Image) SetAsViewport() error { func (f *Framebuffer) SetAsViewport() error {
gl.Flush() gl.Flush()
r.framebuffer.Bind() f.framebuffer.Bind()
err := gl.CheckFramebufferStatus(gl.FRAMEBUFFER) err := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
if err != gl.FRAMEBUFFER_COMPLETE { if err != gl.FRAMEBUFFER_COMPLETE {
if gl.GetError() != 0 { if gl.GetError() != 0 {
@ -97,19 +97,19 @@ func (r *Image) SetAsViewport() error {
return errors.New("glBindFramebuffer failed: the context is different?") return errors.New("glBindFramebuffer failed: the context is different?")
} }
width := internal.NextPowerOf2Int(r.width) width := internal.NextPowerOf2Int(f.width)
height := internal.NextPowerOf2Int(r.height) height := internal.NextPowerOf2Int(f.height)
gl.Viewport(0, 0, width, height) gl.Viewport(0, 0, width, height)
return nil return nil
} }
func (r *Image) ProjectionMatrix() [4][4]float64 { func (f *Framebuffer) ProjectionMatrix() [4][4]float64 {
width := internal.NextPowerOf2Int(r.width) width := internal.NextPowerOf2Int(f.width)
height := internal.NextPowerOf2Int(r.height) height := internal.NextPowerOf2Int(f.height)
m := orthoProjectionMatrix(0, width, 0, height) m := orthoProjectionMatrix(0, width, 0, height)
if r.flipY { if f.flipY {
m[1][1] *= -1 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 return m
} }