Refactoring

This commit is contained in:
Hajime Hoshi 2014-12-21 01:04:49 +09:00
parent aed317649f
commit 59270a6b54
4 changed files with 13 additions and 19 deletions

View File

@ -59,5 +59,5 @@ type Texture struct {
// Size returns the size of the texture. // Size returns the size of the texture.
func (t *Texture) Size() (width int, height int) { func (t *Texture) Size() (width int, height int) {
return t.glTexture.Width(), t.glTexture.Height() return t.glTexture.Size()
} }

View File

@ -58,19 +58,16 @@ func NewRenderTargetFromTexture(texture *Texture) (*RenderTarget, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
w, h := texture.Size()
return &RenderTarget{ return &RenderTarget{
framebuffer: framebuffer, framebuffer: framebuffer,
width: texture.Width(), width: w,
height: texture.Height(), height: h,
}, nil }, nil
} }
func (r *RenderTarget) Width() int { func (r *RenderTarget) Size() (width, height int) {
return r.width return r.width, r.height
}
func (r *RenderTarget) Height() int {
return r.height
} }
func (r *RenderTarget) Dispose() { func (r *RenderTarget) Dispose() {

View File

@ -55,12 +55,8 @@ func (t *Texture) Native() gl.Texture {
return t.native return t.native
} }
func (t *Texture) Width() int { func (t *Texture) Size() (width, height int) {
return t.width return t.width, t.height
}
func (t *Texture) Height() int {
return t.height
} }
func createNativeTexture(textureWidth, textureHeight int, pixels []uint8, filter int) gl.Texture { func createNativeTexture(textureWidth, textureHeight int, pixels []uint8, filter int) gl.Texture {

View File

@ -46,7 +46,7 @@ func newInnerRenderTarget(width, height int, filter int) (*innerRenderTarget, er
} }
func (r *innerRenderTarget) size() (width, height int) { func (r *innerRenderTarget) size() (width, height int) {
return r.glRenderTarget.Width(), r.glRenderTarget.Height() return r.glRenderTarget.Size()
} }
func (r *innerRenderTarget) Clear() error { func (r *innerRenderTarget) Clear() error {
@ -73,14 +73,15 @@ func (r *innerRenderTarget) DrawTexture(texture *Texture, parts []TexturePart, g
return err return err
} }
glTexture := texture.glTexture glTexture := texture.glTexture
quads := textureQuads(parts, glTexture.Width(), glTexture.Height()) w, h := glTexture.Size()
quads := textureQuads(parts, w, h)
targetNativeTexture := gl.Texture(0) targetNativeTexture := gl.Texture(0)
if r.texture != nil { if r.texture != nil {
targetNativeTexture = r.texture.glTexture.Native() targetNativeTexture = r.texture.glTexture.Native()
} }
w, h := r.size() w2, h2 := r.size()
projectionMatrix := r.glRenderTarget.ProjectionMatrix() projectionMatrix := r.glRenderTarget.ProjectionMatrix()
shader.DrawTexture(glTexture.Native(), targetNativeTexture, w, h, projectionMatrix, quads, &geo, &color) shader.DrawTexture(glTexture.Native(), targetNativeTexture, w2, h2, projectionMatrix, quads, &geo, &color)
return nil return nil
} }