Rename variables

This commit is contained in:
Hajime Hoshi 2014-12-22 11:14:44 +09:00
parent 0f8ac49055
commit baf18ba479
2 changed files with 40 additions and 35 deletions

View File

@ -52,8 +52,8 @@ 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.glRenderTarget glRenderTarget := c.screen.renderTarget
glTexture := c.screen.glTexture glTexture := c.screen.texture
glRenderTarget.Dispose() glRenderTarget.Dispose()
glTexture.Dispose() glTexture.Dispose()

View File

@ -25,29 +25,28 @@ import (
) )
type innerImage struct { type innerImage struct {
// TODO: Rename them later. renderTarget *opengl.Image
glRenderTarget *opengl.Image texture *opengl.Texture
glTexture *opengl.Texture
} }
func newInnerImage(glTexture *opengl.Texture, filter int) (*innerImage, error) { func newInnerImage(texture *opengl.Texture, filter int) (*innerImage, error) {
glRenderTarget, err := opengl.NewRenderTargetFromTexture(glTexture) renderTarget, err := opengl.NewRenderTargetFromTexture(texture)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &innerImage{glRenderTarget, glTexture}, nil return &innerImage{renderTarget, texture}, nil
} }
func (r *innerImage) size() (width, height int) { func (i *innerImage) size() (width, height int) {
return r.glRenderTarget.Size() return i.renderTarget.Size()
} }
func (r *innerImage) Clear() error { func (i *innerImage) Clear() error {
return r.Fill(color.Transparent) return i.Fill(color.Transparent)
} }
func (r *innerImage) Fill(clr color.Color) error { func (i *innerImage) Fill(clr color.Color) error {
if err := r.glRenderTarget.SetAsViewport(); err != nil { if err := i.renderTarget.SetAsViewport(); err != nil {
return err return err
} }
rf, gf, bf, af := internal.RGBA(clr) rf, gf, bf, af := internal.RGBA(clr)
@ -56,19 +55,19 @@ func (r *innerImage) Fill(clr color.Color) error {
return nil return nil
} }
func (r *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 := r.glRenderTarget.SetAsViewport(); err != nil { if err := i.renderTarget.SetAsViewport(); err != nil {
return err return err
} }
w, h := image.glTexture.Size() w, h := image.texture.Size()
quads := textureQuads(parts, w, h) quads := textureQuads(parts, w, h)
targetNativeTexture := gl.Texture(0) targetNativeTexture := gl.Texture(0)
if r.glTexture != nil { if i.texture != nil {
targetNativeTexture = r.glTexture.Native() targetNativeTexture = i.texture.Native()
} }
w2, h2 := r.size() w2, h2 := i.size()
projectionMatrix := r.glRenderTarget.ProjectionMatrix() projectionMatrix := i.renderTarget.ProjectionMatrix()
shader.DrawTexture(image.glTexture.Native(), targetNativeTexture, w2, h2, projectionMatrix, quads, &geo, &color) shader.DrawTexture(image.texture.Native(), targetNativeTexture, w2, h2, projectionMatrix, quads, &geo, &color)
return nil return nil
} }
@ -101,36 +100,42 @@ type syncer interface {
Sync(func()) Sync(func())
} }
// An image represents an image.
// The pixel format is non alpha-premultiplied.
type Image struct { type Image struct {
syncer syncer syncer syncer
inner *innerImage inner *innerImage
} }
func (r *Image) Size() (width, height int) { // Size returns the size of the image.
return r.inner.size() func (i *Image) Size() (width, height int) {
return i.inner.size()
} }
func (r *Image) Clear() (err error) { // Clear resets the pixels of the image into 0.
r.syncer.Sync(func() { func (i *Image) Clear() (err error) {
err = r.inner.Clear() i.syncer.Sync(func() {
err = i.inner.Clear()
}) })
return return
} }
func (r *Image) Fill(clr color.Color) (err error) { // Fill fills the image with a solid color.
r.syncer.Sync(func() { func (i *Image) Fill(clr color.Color) (err error) {
err = r.inner.Fill(clr) i.syncer.Sync(func() {
err = i.inner.Fill(clr)
}) })
return return
} }
func (r *Image) DrawImage(image *Image, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) { // DrawImage draws the given image on the receiver (i).
return r.drawImage(image.inner, parts, geo, color) func (i *Image) DrawImage(image *Image, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) {
return i.drawImage(image.inner, parts, geo, color)
} }
func (r *Image) drawImage(image *innerImage, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) { func (i *Image) drawImage(image *innerImage, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) {
r.syncer.Sync(func() { i.syncer.Sync(func() {
err = r.inner.drawImage(image, parts, geo, color) err = i.inner.drawImage(image, parts, geo, color)
}) })
return return
} }