mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Rename Id -> ID
This commit is contained in:
parent
b27ba795df
commit
4eb6c8d131
@ -20,8 +20,8 @@ type nameSize struct {
|
|||||||
type Textures struct {
|
type Textures struct {
|
||||||
texturePaths chan namePath
|
texturePaths chan namePath
|
||||||
renderTargetSizes chan nameSize
|
renderTargetSizes chan nameSize
|
||||||
textures map[string]graphics.TextureId
|
textures map[string]graphics.TextureID
|
||||||
renderTargets map[string]graphics.RenderTargetId
|
renderTargets map[string]graphics.RenderTargetID
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +29,8 @@ func NewTextures() *Textures {
|
|||||||
textures := &Textures{
|
textures := &Textures{
|
||||||
texturePaths: make(chan namePath),
|
texturePaths: make(chan namePath),
|
||||||
renderTargetSizes: make(chan nameSize),
|
renderTargetSizes: make(chan nameSize),
|
||||||
textures: map[string]graphics.TextureId{},
|
textures: map[string]graphics.TextureID{},
|
||||||
renderTargets: map[string]graphics.RenderTargetId{},
|
renderTargets: map[string]graphics.RenderTargetID{},
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -106,13 +106,13 @@ func (t *Textures) Has(name string) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Textures) GetTexture(name string) graphics.TextureId {
|
func (t *Textures) GetTexture(name string) graphics.TextureID {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.textures[name]
|
return t.textures[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Textures) GetRenderTarget(name string) graphics.RenderTargetId {
|
func (t *Textures) GetRenderTarget(name string) graphics.RenderTargetID {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.renderTargets[name]
|
return t.renderTargets[name]
|
||||||
|
@ -31,11 +31,9 @@ func DrawWhole(drawer Drawer, width, height int, geo matrix.Geometry, color matr
|
|||||||
type Context interface {
|
type Context interface {
|
||||||
Clear()
|
Clear()
|
||||||
Fill(r, g, b uint8)
|
Fill(r, g, b uint8)
|
||||||
Texture(id TextureId) Drawer
|
Texture(id TextureID) Drawer
|
||||||
RenderTarget(id RenderTargetId) Drawer
|
RenderTarget(id RenderTargetID) Drawer
|
||||||
|
|
||||||
ResetOffscreen()
|
ResetOffscreen()
|
||||||
SetOffscreen(id RenderTargetId)
|
SetOffscreen(id RenderTargetID)
|
||||||
|
|
||||||
// TODO: glTextureSubImage2D
|
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ func flush() {
|
|||||||
var onceInit sync.Once
|
var onceInit sync.Once
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
screenId graphics.RenderTargetId
|
screenId graphics.RenderTargetID
|
||||||
defaultId graphics.RenderTargetId
|
defaultId graphics.RenderTargetID
|
||||||
currentId graphics.RenderTargetId
|
currentId graphics.RenderTargetID
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
screenScale int
|
screenScale int
|
||||||
@ -88,11 +88,11 @@ func (c *Context) Fill(r, g, b uint8) {
|
|||||||
idsInstance.fillRenderTarget(c.currentId, r, g, b)
|
idsInstance.fillRenderTarget(c.currentId, r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Texture(id graphics.TextureId) graphics.Drawer {
|
func (c *Context) Texture(id graphics.TextureID) graphics.Drawer {
|
||||||
return &textureWithContext{id, c}
|
return &textureWithContext{id, c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) RenderTarget(id graphics.RenderTargetId) graphics.Drawer {
|
func (c *Context) RenderTarget(id graphics.RenderTargetID) graphics.Drawer {
|
||||||
return &textureWithContext{idsInstance.toTexture(id), c}
|
return &textureWithContext{idsInstance.toTexture(id), c}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,12 +100,12 @@ func (c *Context) ResetOffscreen() {
|
|||||||
c.currentId = c.screenId
|
c.currentId = c.screenId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
func (c *Context) SetOffscreen(renderTargetId graphics.RenderTargetID) {
|
||||||
c.currentId = renderTargetId
|
c.currentId = renderTargetId
|
||||||
}
|
}
|
||||||
|
|
||||||
type textureWithContext struct {
|
type textureWithContext struct {
|
||||||
id graphics.TextureId
|
id graphics.TextureID
|
||||||
context *Context
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,52 +21,52 @@ func glMatrix(matrix [4][4]float64) [16]float32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ids struct {
|
type ids struct {
|
||||||
textures map[graphics.TextureId]*Texture
|
textures map[graphics.TextureID]*Texture
|
||||||
renderTargets map[graphics.RenderTargetId]*RenderTarget
|
renderTargets map[graphics.RenderTargetID]*RenderTarget
|
||||||
renderTargetToTexture map[graphics.RenderTargetId]graphics.TextureId
|
renderTargetToTexture map[graphics.RenderTargetID]graphics.TextureID
|
||||||
lastId int
|
lastId int
|
||||||
currentRenderTargetId graphics.RenderTargetId
|
currentRenderTargetId graphics.RenderTargetID
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var idsInstance = &ids{
|
var idsInstance = &ids{
|
||||||
textures: map[graphics.TextureId]*Texture{},
|
textures: map[graphics.TextureID]*Texture{},
|
||||||
renderTargets: map[graphics.RenderTargetId]*RenderTarget{},
|
renderTargets: map[graphics.RenderTargetID]*RenderTarget{},
|
||||||
renderTargetToTexture: map[graphics.RenderTargetId]graphics.TextureId{},
|
renderTargetToTexture: map[graphics.RenderTargetID]graphics.TextureID{},
|
||||||
currentRenderTargetId: -1,
|
currentRenderTargetId: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateRenderTarget(
|
func CreateRenderTarget(
|
||||||
width, height int,
|
width, height int,
|
||||||
filter graphics.Filter) (graphics.RenderTargetId, error) {
|
filter graphics.Filter) (graphics.RenderTargetID, error) {
|
||||||
return idsInstance.createRenderTarget(width, height, filter)
|
return idsInstance.createRenderTarget(width, height, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTexture(
|
func CreateTexture(
|
||||||
img image.Image,
|
img image.Image,
|
||||||
filter graphics.Filter) (graphics.TextureId, error) {
|
filter graphics.Filter) (graphics.TextureID, error) {
|
||||||
return idsInstance.createTexture(img, filter)
|
return idsInstance.createTexture(img, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) textureAt(id graphics.TextureId) *Texture {
|
func (i *ids) textureAt(id graphics.TextureID) *Texture {
|
||||||
i.RLock()
|
i.RLock()
|
||||||
defer i.RUnlock()
|
defer i.RUnlock()
|
||||||
return i.textures[id]
|
return i.textures[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) renderTargetAt(id graphics.RenderTargetId) *RenderTarget {
|
func (i *ids) renderTargetAt(id graphics.RenderTargetID) *RenderTarget {
|
||||||
i.RLock()
|
i.RLock()
|
||||||
defer i.RUnlock()
|
defer i.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.RLock()
|
i.RLock()
|
||||||
defer i.RUnlock()
|
defer i.RUnlock()
|
||||||
return i.renderTargetToTexture[id]
|
return i.renderTargetToTexture[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) createTexture(img image.Image, filter graphics.Filter) (graphics.TextureId, error) {
|
func (i *ids) createTexture(img image.Image, filter graphics.Filter) (graphics.TextureID, error) {
|
||||||
texture, err := createTextureFromImage(img, filter)
|
texture, err := createTextureFromImage(img, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -75,12 +75,12 @@ func (i *ids) createTexture(img image.Image, filter graphics.Filter) (graphics.T
|
|||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastId++
|
||||||
textureId := graphics.TextureId(i.lastId)
|
textureId := graphics.TextureID(i.lastId)
|
||||||
i.textures[textureId] = texture
|
i.textures[textureId] = texture
|
||||||
return textureId, nil
|
return textureId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) createRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetId, error) {
|
func (i *ids) createRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) {
|
||||||
texture, err := createTexture(width, height, filter)
|
texture, err := createTexture(width, height, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -97,9 +97,9 @@ func (i *ids) createRenderTarget(width, height int, filter graphics.Filter) (gra
|
|||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastId++
|
||||||
textureId := graphics.TextureId(i.lastId)
|
textureId := graphics.TextureID(i.lastId)
|
||||||
i.lastId++
|
i.lastId++
|
||||||
renderTargetId := graphics.RenderTargetId(i.lastId)
|
renderTargetId := graphics.RenderTargetID(i.lastId)
|
||||||
|
|
||||||
i.textures[textureId] = texture
|
i.textures[textureId] = texture
|
||||||
i.renderTargets[renderTargetId] = renderTarget
|
i.renderTargets[renderTargetId] = renderTarget
|
||||||
@ -109,17 +109,17 @@ func (i *ids) createRenderTarget(width, height int, filter graphics.Filter) (gra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: renderTarget can't be used as a texture.
|
// NOTE: renderTarget can't be used as a texture.
|
||||||
func (i *ids) addRenderTarget(renderTarget *RenderTarget) graphics.RenderTargetId {
|
func (i *ids) addRenderTarget(renderTarget *RenderTarget) graphics.RenderTargetID {
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastId++
|
||||||
id := graphics.RenderTargetId(i.lastId)
|
id := graphics.RenderTargetID(i.lastId)
|
||||||
i.renderTargets[id] = renderTarget
|
i.renderTargets[id] = renderTarget
|
||||||
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) deleteRenderTarget(id graphics.RenderTargetId) {
|
func (i *ids) deleteRenderTarget(id graphics.RenderTargetID) {
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ func (i *ids) deleteRenderTarget(id graphics.RenderTargetId) {
|
|||||||
delete(i.textures, textureId)
|
delete(i.textures, textureId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) fillRenderTarget(id graphics.RenderTargetId, r, g, b uint8) {
|
func (i *ids) fillRenderTarget(id graphics.RenderTargetID, r, g, b uint8) {
|
||||||
i.setViewportIfNeeded(id)
|
i.setViewportIfNeeded(id)
|
||||||
const max = float64(math.MaxUint8)
|
const max = float64(math.MaxUint8)
|
||||||
gl.ClearColor(gl.GLclampf(float64(r)/max), gl.GLclampf(float64(g)/max), gl.GLclampf(float64(b)/max), 1)
|
gl.ClearColor(gl.GLclampf(float64(r)/max), gl.GLclampf(float64(g)/max), gl.GLclampf(float64(b)/max), 1)
|
||||||
@ -143,8 +143,8 @@ func (i *ids) fillRenderTarget(id graphics.RenderTargetId, r, g, b uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) drawTexture(
|
func (i *ids) drawTexture(
|
||||||
target graphics.RenderTargetId,
|
target graphics.RenderTargetID,
|
||||||
id graphics.TextureId,
|
id graphics.TextureID,
|
||||||
parts []graphics.TexturePart,
|
parts []graphics.TexturePart,
|
||||||
geo matrix.Geometry,
|
geo matrix.Geometry,
|
||||||
color matrix.Color) {
|
color matrix.Color) {
|
||||||
@ -156,7 +156,7 @@ func (i *ids) drawTexture(
|
|||||||
shader.DrawTexture(texture.native, glMatrix(projectionMatrix), quads, geo, color)
|
shader.DrawTexture(texture.native, glMatrix(projectionMatrix), quads, geo, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) setViewportIfNeeded(id graphics.RenderTargetId) {
|
func (i *ids) setViewportIfNeeded(id graphics.RenderTargetID) {
|
||||||
r := i.renderTargetAt(id)
|
r := i.renderTargetAt(id)
|
||||||
if i.currentRenderTargetId != id {
|
if i.currentRenderTargetId != id {
|
||||||
r.setAsViewport()
|
r.setAsViewport()
|
||||||
|
@ -11,31 +11,31 @@ const (
|
|||||||
FilterLinear
|
FilterLinear
|
||||||
)
|
)
|
||||||
|
|
||||||
type TextureId int
|
type TextureID int
|
||||||
|
|
||||||
// A render target is essentially same as a texture, but it is assumed that the
|
// A render target is essentially same as a texture, but it is assumed that the
|
||||||
// all alpha of a render target is maximum.
|
// all alpha of a render target is maximum.
|
||||||
type RenderTargetId int
|
type RenderTargetID int
|
||||||
|
|
||||||
var currentTextureFactory TextureFactory
|
var currentTextureFactory TextureFactory
|
||||||
|
|
||||||
type TextureFactory interface {
|
type TextureFactory interface {
|
||||||
CreateRenderTarget(width, height int, filter Filter) (RenderTargetId, error)
|
CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error)
|
||||||
CreateTexture(img image.Image, filter Filter) (TextureId, error)
|
CreateTexture(img image.Image, filter Filter) (TextureID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTextureFactory(textureFactory TextureFactory) {
|
func SetTextureFactory(textureFactory TextureFactory) {
|
||||||
currentTextureFactory = textureFactory
|
currentTextureFactory = textureFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateRenderTarget(width, height int, filter Filter) (RenderTargetId, error) {
|
func CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error) {
|
||||||
if currentTextureFactory == nil {
|
if currentTextureFactory == nil {
|
||||||
panic("graphics.CreateRenderTarget: currentTextureFactory is not set.")
|
panic("graphics.CreateRenderTarget: currentTextureFactory is not set.")
|
||||||
}
|
}
|
||||||
return currentTextureFactory.CreateRenderTarget(width, height, filter)
|
return currentTextureFactory.CreateRenderTarget(width, height, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTexture(img image.Image, filter Filter) (TextureId, error) {
|
func CreateTexture(img image.Image, filter Filter) (TextureID, error) {
|
||||||
if currentTextureFactory == nil {
|
if currentTextureFactory == nil {
|
||||||
panic("graphics.CreateTexture: currentTextureFactory is not set")
|
panic("graphics.CreateTexture: currentTextureFactory is not set")
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,8 @@ func (c *Canvas) IsClosed() bool {
|
|||||||
return c.window.ShouldClose()
|
return c.window.ShouldClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureId, error) {
|
func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureID, error) {
|
||||||
var id graphics.TextureId
|
var id graphics.TextureID
|
||||||
var err error
|
var err error
|
||||||
c.use(func() {
|
c.use(func() {
|
||||||
id, err = opengl.CreateTexture(img, filter)
|
id, err = opengl.CreateTexture(img, filter)
|
||||||
@ -64,8 +64,8 @@ func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphic
|
|||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Canvas) CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetId, error) {
|
func (c *Canvas) CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) {
|
||||||
var id graphics.RenderTargetId
|
var id graphics.RenderTargetID
|
||||||
var err error
|
var err error
|
||||||
c.use(func() {
|
c.use(func() {
|
||||||
id, err = opengl.CreateRenderTarget(width, height, filter)
|
id, err = opengl.CreateRenderTarget(width, height, filter)
|
||||||
|
Loading…
Reference in New Issue
Block a user