Rename Id -> ID

This commit is contained in:
Hajime Hoshi 2014-12-07 05:21:20 +09:00
parent b27ba795df
commit 4eb6c8d131
6 changed files with 50 additions and 52 deletions

View File

@ -20,8 +20,8 @@ type nameSize struct {
type Textures struct {
texturePaths chan namePath
renderTargetSizes chan nameSize
textures map[string]graphics.TextureId
renderTargets map[string]graphics.RenderTargetId
textures map[string]graphics.TextureID
renderTargets map[string]graphics.RenderTargetID
sync.RWMutex
}
@ -29,8 +29,8 @@ func NewTextures() *Textures {
textures := &Textures{
texturePaths: make(chan namePath),
renderTargetSizes: make(chan nameSize),
textures: map[string]graphics.TextureId{},
renderTargets: map[string]graphics.RenderTargetId{},
textures: map[string]graphics.TextureID{},
renderTargets: map[string]graphics.RenderTargetID{},
}
go func() {
for {
@ -106,13 +106,13 @@ func (t *Textures) Has(name string) bool {
return ok
}
func (t *Textures) GetTexture(name string) graphics.TextureId {
func (t *Textures) GetTexture(name string) graphics.TextureID {
t.RLock()
defer t.RUnlock()
return t.textures[name]
}
func (t *Textures) GetRenderTarget(name string) graphics.RenderTargetId {
func (t *Textures) GetRenderTarget(name string) graphics.RenderTargetID {
t.RLock()
defer t.RUnlock()
return t.renderTargets[name]

View File

@ -31,11 +31,9 @@ func DrawWhole(drawer Drawer, width, height int, geo matrix.Geometry, color matr
type Context interface {
Clear()
Fill(r, g, b uint8)
Texture(id TextureId) Drawer
RenderTarget(id RenderTargetId) Drawer
Texture(id TextureID) Drawer
RenderTarget(id RenderTargetID) Drawer
ResetOffscreen()
SetOffscreen(id RenderTargetId)
// TODO: glTextureSubImage2D
SetOffscreen(id RenderTargetID)
}

View File

@ -15,9 +15,9 @@ func flush() {
var onceInit sync.Once
type Context struct {
screenId graphics.RenderTargetId
defaultId graphics.RenderTargetId
currentId graphics.RenderTargetId
screenId graphics.RenderTargetID
defaultId graphics.RenderTargetID
currentId graphics.RenderTargetID
screenWidth int
screenHeight int
screenScale int
@ -88,11 +88,11 @@ func (c *Context) Fill(r, g, b uint8) {
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}
}
func (c *Context) RenderTarget(id graphics.RenderTargetId) graphics.Drawer {
func (c *Context) RenderTarget(id graphics.RenderTargetID) graphics.Drawer {
return &textureWithContext{idsInstance.toTexture(id), c}
}
@ -100,12 +100,12 @@ func (c *Context) ResetOffscreen() {
c.currentId = c.screenId
}
func (c *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
func (c *Context) SetOffscreen(renderTargetId graphics.RenderTargetID) {
c.currentId = renderTargetId
}
type textureWithContext struct {
id graphics.TextureId
id graphics.TextureID
context *Context
}

View File

@ -21,52 +21,52 @@ func glMatrix(matrix [4][4]float64) [16]float32 {
}
type ids struct {
textures map[graphics.TextureId]*Texture
renderTargets map[graphics.RenderTargetId]*RenderTarget
renderTargetToTexture map[graphics.RenderTargetId]graphics.TextureId
textures map[graphics.TextureID]*Texture
renderTargets map[graphics.RenderTargetID]*RenderTarget
renderTargetToTexture map[graphics.RenderTargetID]graphics.TextureID
lastId int
currentRenderTargetId graphics.RenderTargetId
currentRenderTargetId graphics.RenderTargetID
sync.RWMutex
}
var idsInstance = &ids{
textures: map[graphics.TextureId]*Texture{},
renderTargets: map[graphics.RenderTargetId]*RenderTarget{},
renderTargetToTexture: map[graphics.RenderTargetId]graphics.TextureId{},
textures: map[graphics.TextureID]*Texture{},
renderTargets: map[graphics.RenderTargetID]*RenderTarget{},
renderTargetToTexture: map[graphics.RenderTargetID]graphics.TextureID{},
currentRenderTargetId: -1,
}
func CreateRenderTarget(
width, height int,
filter graphics.Filter) (graphics.RenderTargetId, error) {
filter graphics.Filter) (graphics.RenderTargetID, error) {
return idsInstance.createRenderTarget(width, height, filter)
}
func CreateTexture(
img image.Image,
filter graphics.Filter) (graphics.TextureId, error) {
filter graphics.Filter) (graphics.TextureID, error) {
return idsInstance.createTexture(img, filter)
}
func (i *ids) textureAt(id graphics.TextureId) *Texture {
func (i *ids) textureAt(id graphics.TextureID) *Texture {
i.RLock()
defer i.RUnlock()
return i.textures[id]
}
func (i *ids) renderTargetAt(id graphics.RenderTargetId) *RenderTarget {
func (i *ids) renderTargetAt(id graphics.RenderTargetID) *RenderTarget {
i.RLock()
defer i.RUnlock()
return i.renderTargets[id]
}
func (i *ids) toTexture(id graphics.RenderTargetId) graphics.TextureId {
func (i *ids) toTexture(id graphics.RenderTargetID) graphics.TextureID {
i.RLock()
defer i.RUnlock()
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)
if err != nil {
return 0, err
@ -75,12 +75,12 @@ func (i *ids) createTexture(img image.Image, filter graphics.Filter) (graphics.T
i.Lock()
defer i.Unlock()
i.lastId++
textureId := graphics.TextureId(i.lastId)
textureId := graphics.TextureID(i.lastId)
i.textures[textureId] = texture
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)
if err != nil {
return 0, err
@ -97,9 +97,9 @@ func (i *ids) createRenderTarget(width, height int, filter graphics.Filter) (gra
i.Lock()
defer i.Unlock()
i.lastId++
textureId := graphics.TextureId(i.lastId)
textureId := graphics.TextureID(i.lastId)
i.lastId++
renderTargetId := graphics.RenderTargetId(i.lastId)
renderTargetId := graphics.RenderTargetID(i.lastId)
i.textures[textureId] = texture
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.
func (i *ids) addRenderTarget(renderTarget *RenderTarget) graphics.RenderTargetId {
func (i *ids) addRenderTarget(renderTarget *RenderTarget) graphics.RenderTargetID {
i.Lock()
defer i.Unlock()
i.lastId++
id := graphics.RenderTargetId(i.lastId)
id := graphics.RenderTargetID(i.lastId)
i.renderTargets[id] = renderTarget
return id
}
func (i *ids) deleteRenderTarget(id graphics.RenderTargetId) {
func (i *ids) deleteRenderTarget(id graphics.RenderTargetID) {
i.Lock()
defer i.Unlock()
@ -135,7 +135,7 @@ func (i *ids) deleteRenderTarget(id graphics.RenderTargetId) {
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)
const max = float64(math.MaxUint8)
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(
target graphics.RenderTargetId,
id graphics.TextureId,
target graphics.RenderTargetID,
id graphics.TextureID,
parts []graphics.TexturePart,
geo matrix.Geometry,
color matrix.Color) {
@ -156,7 +156,7 @@ func (i *ids) drawTexture(
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)
if i.currentRenderTargetId != id {
r.setAsViewport()

View File

@ -11,31 +11,31 @@ const (
FilterLinear
)
type TextureId int
type TextureID int
// A render target is essentially same as a texture, but it is assumed that the
// all alpha of a render target is maximum.
type RenderTargetId int
type RenderTargetID int
var currentTextureFactory TextureFactory
type TextureFactory interface {
CreateRenderTarget(width, height int, filter Filter) (RenderTargetId, error)
CreateTexture(img image.Image, filter Filter) (TextureId, error)
CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error)
CreateTexture(img image.Image, filter Filter) (TextureID, error)
}
func SetTextureFactory(textureFactory TextureFactory) {
currentTextureFactory = textureFactory
}
func CreateRenderTarget(width, height int, filter Filter) (RenderTargetId, error) {
func CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error) {
if currentTextureFactory == nil {
panic("graphics.CreateRenderTarget: currentTextureFactory is not set.")
}
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 {
panic("graphics.CreateTexture: currentTextureFactory is not set")
}

View File

@ -55,8 +55,8 @@ func (c *Canvas) IsClosed() bool {
return c.window.ShouldClose()
}
func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureId, error) {
var id graphics.TextureId
func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureID, error) {
var id graphics.TextureID
var err error
c.use(func() {
id, err = opengl.CreateTexture(img, filter)
@ -64,8 +64,8 @@ func (c *Canvas) CreateTexture(img image.Image, filter graphics.Filter) (graphic
return id, err
}
func (c *Canvas) CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetId, error) {
var id graphics.RenderTargetId
func (c *Canvas) CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) {
var id graphics.RenderTargetID
var err error
c.use(func() {
id, err = opengl.CreateRenderTarget(width, height, filter)