add Width and Height methods to Texture

This commit is contained in:
faiface 2016-12-06 16:23:55 +01:00
parent 4323e83d49
commit 5cff367362
1 changed files with 19 additions and 4 deletions

View File

@ -7,12 +7,17 @@ type Texture struct {
enabled bool enabled bool
parent Doer parent Doer
tex uint32 tex uint32
width, height int
} }
// NewTexture creates a new texture with the specified width and height. // NewTexture creates a new texture with the specified width and height.
// The pixels must be a sequence of RGBA values. // The pixels must be a sequence of RGBA values.
func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) { func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) {
texture := &Texture{parent: parent} texture := &Texture{
parent: parent,
width: width,
height: height,
}
parent.Do(func(ctx Context) { parent.Do(func(ctx Context) {
Do(func() { Do(func() {
@ -54,6 +59,16 @@ func (t *Texture) ID() uint32 {
return t.tex return t.tex
} }
// Width returns the width of a texture in pixels.
func (t *Texture) Width() int {
return t.width
}
// Height returns the height of a texture in pixels.
func (t *Texture) Height() int {
return t.height
}
// Do bind a texture, executes sub, and unbinds the texture. // Do bind a texture, executes sub, and unbinds the texture.
func (t *Texture) Do(sub func(Context)) { func (t *Texture) Do(sub func(Context)) {
t.parent.Do(func(ctx Context) { t.parent.Do(func(ctx Context) {