Refactoring

This commit is contained in:
Hajime Hoshi 2014-01-10 00:42:42 +09:00
parent a9711cd509
commit 29e5aa331f
2 changed files with 38 additions and 14 deletions

View File

@ -77,29 +77,26 @@ func (context *Context) Fill(r, g, b uint8) {
}
func (context *Context) DrawTexture(
id graphics.TextureId,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
tex := context.ids.TextureAt(id)
context.offscreen.DrawTexture(tex, geometryMatrix, colorMatrix)
id graphics.TextureId, geo matrix.Geometry, color matrix.Color) {
context.ids.DrawTexture(id, context.offscreen, geo, color)
}
func (context *Context) DrawRenderTarget(
id graphics.RenderTargetId,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
context.DrawTexture(context.ids.ToTexture(id), geometryMatrix, colorMatrix)
geo matrix.Geometry, color matrix.Color) {
context.ids.DrawRenderTarget(id, context.offscreen, geo, color)
}
func (context *Context) DrawTextureParts(
id graphics.TextureId, parts []graphics.TexturePart,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
tex := context.ids.TextureAt(id)
context.offscreen.DrawTextureParts(tex, parts, geometryMatrix, colorMatrix)
context.ids.DrawTextureParts(id, context.offscreen, parts, geometryMatrix, colorMatrix)
}
func (context *Context) DrawRenderTargetParts(
id graphics.RenderTargetId, parts []graphics.TexturePart,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
context.DrawTextureParts(context.ids.ToTexture(id), parts, geometryMatrix, colorMatrix)
context.ids.DrawRenderTargetParts(id, context.offscreen, parts, geometryMatrix, colorMatrix)
}
func (context *Context) ResetOffscreen() {
@ -107,6 +104,5 @@ func (context *Context) ResetOffscreen() {
}
func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
renderTarget := context.ids.RenderTargetAt(renderTargetId)
context.offscreen.Set(renderTarget)
context.ids.SetRenderTargetAsOffscreen(renderTargetId, context.offscreen)
}

View File

@ -2,6 +2,8 @@ package opengl
import (
"github.com/hajimehoshi/go-ebiten/graphics"
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
"github.com/hajimehoshi/go-ebiten/graphics/opengl/offscreen"
"github.com/hajimehoshi/go-ebiten/graphics/opengl/rendertarget"
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
"image"
@ -31,19 +33,19 @@ func newIds() *ids {
return ids
}
func (i *ids) TextureAt(id graphics.TextureId) *texture.Texture {
func (i *ids) textureAt(id graphics.TextureId) *texture.Texture {
i.lock.RLock()
defer i.lock.RUnlock()
return i.textures[id]
}
func (i *ids) RenderTargetAt(id graphics.RenderTargetId) *rendertarget.RenderTarget {
func (i *ids) renderTargetAt(id graphics.RenderTargetId) *rendertarget.RenderTarget {
i.lock.RLock()
defer i.lock.RUnlock()
return i.renderTargets[id]
}
func (i *ids) ToTexture(id graphics.RenderTargetId) graphics.TextureId {
func (i *ids) toTexture(id graphics.RenderTargetId) graphics.TextureId {
i.lock.RLock()
defer i.lock.RUnlock()
return i.renderTargetToTexture[id]
@ -99,3 +101,29 @@ func (i *ids) DeleteRenderTarget(id graphics.RenderTargetId) {
delete(i.renderTargetToTexture, id)
delete(i.textures, textureId)
}
func (i *ids) DrawTexture(id graphics.TextureId, offscreen *offscreen.Offscreen,
geo matrix.Geometry, color matrix.Color) {
texture := i.textureAt(id)
offscreen.DrawTexture(texture, geo, color)
}
func (i *ids) DrawTextureParts(id graphics.TextureId, offscreen *offscreen.Offscreen,
parts []graphics.TexturePart, geo matrix.Geometry, color matrix.Color) {
texture := i.textureAt(id)
offscreen.DrawTextureParts(texture, parts, geo, color)
}
func (i *ids) DrawRenderTarget(id graphics.RenderTargetId, offscreen *offscreen.Offscreen,
geo matrix.Geometry, color matrix.Color) {
i.DrawTexture(i.toTexture(id), offscreen, geo, color)
}
func (i *ids) DrawRenderTargetParts(id graphics.RenderTargetId, offscreen *offscreen.Offscreen,
parts []graphics.TexturePart, geo matrix.Geometry, color matrix.Color) {
i.DrawTextureParts(i.toTexture(id), offscreen, parts, geo, color)
}
func (i *ids) SetRenderTargetAsOffscreen(id graphics.RenderTargetId, offscreen *offscreen.Offscreen) {
offscreen.Set(i.renderTargetAt(id))
}