mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
Refactoring
This commit is contained in:
parent
a9711cd509
commit
29e5aa331f
@ -77,29 +77,26 @@ func (context *Context) Fill(r, g, b uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawTexture(
|
func (context *Context) DrawTexture(
|
||||||
id graphics.TextureId,
|
id graphics.TextureId, geo matrix.Geometry, color matrix.Color) {
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
context.ids.DrawTexture(id, context.offscreen, geo, color)
|
||||||
tex := context.ids.TextureAt(id)
|
|
||||||
context.offscreen.DrawTexture(tex, geometryMatrix, colorMatrix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawRenderTarget(
|
func (context *Context) DrawRenderTarget(
|
||||||
id graphics.RenderTargetId,
|
id graphics.RenderTargetId,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
geo matrix.Geometry, color matrix.Color) {
|
||||||
context.DrawTexture(context.ids.ToTexture(id), geometryMatrix, colorMatrix)
|
context.ids.DrawRenderTarget(id, context.offscreen, geo, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawTextureParts(
|
func (context *Context) DrawTextureParts(
|
||||||
id graphics.TextureId, parts []graphics.TexturePart,
|
id graphics.TextureId, parts []graphics.TexturePart,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
||||||
tex := context.ids.TextureAt(id)
|
context.ids.DrawTextureParts(id, context.offscreen, parts, geometryMatrix, colorMatrix)
|
||||||
context.offscreen.DrawTextureParts(tex, parts, geometryMatrix, colorMatrix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawRenderTargetParts(
|
func (context *Context) DrawRenderTargetParts(
|
||||||
id graphics.RenderTargetId, parts []graphics.TexturePart,
|
id graphics.RenderTargetId, parts []graphics.TexturePart,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
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() {
|
func (context *Context) ResetOffscreen() {
|
||||||
@ -107,6 +104,5 @@ func (context *Context) ResetOffscreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
||||||
renderTarget := context.ids.RenderTargetAt(renderTargetId)
|
context.ids.SetRenderTargetAsOffscreen(renderTargetId, context.offscreen)
|
||||||
context.offscreen.Set(renderTarget)
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package opengl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
"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/rendertarget"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
|
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
|
||||||
"image"
|
"image"
|
||||||
@ -31,19 +33,19 @@ func newIds() *ids {
|
|||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) TextureAt(id graphics.TextureId) *texture.Texture {
|
func (i *ids) textureAt(id graphics.TextureId) *texture.Texture {
|
||||||
i.lock.RLock()
|
i.lock.RLock()
|
||||||
defer i.lock.RUnlock()
|
defer i.lock.RUnlock()
|
||||||
return i.textures[id]
|
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()
|
i.lock.RLock()
|
||||||
defer i.lock.RUnlock()
|
defer i.lock.RUnlock()
|
||||||
return i.renderTargets[id]
|
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()
|
i.lock.RLock()
|
||||||
defer i.lock.RUnlock()
|
defer i.lock.RUnlock()
|
||||||
return i.renderTargetToTexture[id]
|
return i.renderTargetToTexture[id]
|
||||||
@ -99,3 +101,29 @@ func (i *ids) DeleteRenderTarget(id graphics.RenderTargetId) {
|
|||||||
delete(i.renderTargetToTexture, id)
|
delete(i.renderTargetToTexture, id)
|
||||||
delete(i.textures, textureId)
|
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))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user