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.
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 {
return nil, err
}
w, h := texture.Size()
return &RenderTarget{
framebuffer: framebuffer,
width: texture.Width(),
height: texture.Height(),
width: w,
height: h,
}, nil
}
func (r *RenderTarget) Width() int {
return r.width
}
func (r *RenderTarget) Height() int {
return r.height
func (r *RenderTarget) Size() (width, height int) {
return r.width, r.height
}
func (r *RenderTarget) Dispose() {

View File

@ -55,12 +55,8 @@ func (t *Texture) Native() gl.Texture {
return t.native
}
func (t *Texture) Width() int {
return t.width
}
func (t *Texture) Height() int {
return t.height
func (t *Texture) Size() (width, height int) {
return t.width, t.height
}
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) {
return r.glRenderTarget.Width(), r.glRenderTarget.Height()
return r.glRenderTarget.Size()
}
func (r *innerRenderTarget) Clear() error {
@ -73,14 +73,15 @@ func (r *innerRenderTarget) DrawTexture(texture *Texture, parts []TexturePart, g
return err
}
glTexture := texture.glTexture
quads := textureQuads(parts, glTexture.Width(), glTexture.Height())
w, h := glTexture.Size()
quads := textureQuads(parts, w, h)
targetNativeTexture := gl.Texture(0)
if r.texture != nil {
targetNativeTexture = r.texture.glTexture.Native()
}
w, h := r.size()
w2, h2 := r.size()
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
}