From 0ac70a3835bf349722d664a9601f500b9f657f2f Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 30 Oct 2014 19:43:51 -0400 Subject: [PATCH] go.mobile/gl/glutil, go.mobile/app/debug: create glimage with pixel size LGTM=nigeltao R=nigeltao CC=golang-codereviews https://golang.org/cl/165940043 --- app/debug/fps.go | 4 +++- gl/glutil/glimage.go | 11 ++++------- gl/glutil/glimage_test.go | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/debug/fps.go b/app/debug/fps.go index 09cfd61..f66cfa2 100644 --- a/app/debug/fps.go +++ b/app/debug/fps.go @@ -11,6 +11,7 @@ import ( "image/draw" "io/ioutil" "log" + "math" "runtime" "sync" "time" @@ -57,7 +58,8 @@ func fpsInit() { monofont.SetSrc(image.Black) monofont.SetHinting(freetype.FullHinting) - fps.Image = glutil.NewImage(geom.Point{50, 12}) + toPx := func(x geom.Pt) int { return int(math.Ceil(float64(geom.Pt(x).Px()))) } + fps.Image = glutil.NewImage(toPx(50), toPx(12)) monofont.SetDst(fps.Image.RGBA) monofont.SetClip(fps.Bounds()) monofont.SetDPI(72 * float64(geom.PixelsPerPt)) diff --git a/gl/glutil/glimage.go b/gl/glutil/glimage.go index b6b4e79..5a860ce 100644 --- a/gl/glutil/glimage.go +++ b/gl/glutil/glimage.go @@ -7,7 +7,6 @@ package glutil import ( "encoding/binary" "image" - "math" "sync" "code.google.com/p/go.mobile/f32" @@ -67,11 +66,9 @@ type Image struct { // NewImage creates an Image of the given size. // // Both a host-memory *image.RGBA and a GL texture are created. -func NewImage(size geom.Point) *Image { - realx := int(math.Ceil(float64(size.X.Px()))) - realy := int(math.Ceil(float64(size.Y.Px()))) - dx := roundToPower2(realx) - dy := roundToPower2(realy) +func NewImage(w, h int) *Image { + dx := roundToPower2(w) + dy := roundToPower2(h) // TODO(crawshaw): Using VertexAttribPointer we can pass texture // data with a stride, which would let us use the exact number of @@ -81,7 +78,7 @@ func NewImage(size geom.Point) *Image { glimage.Do(glInit) img := &Image{ - RGBA: m.SubImage(image.Rect(0, 0, realx, realy)).(*image.RGBA), + RGBA: m.SubImage(image.Rect(0, 0, w, h)).(*image.RGBA), Texture: gl.GenTexture(), texWidth: dx, texHeight: dy, diff --git a/gl/glutil/glimage_test.go b/gl/glutil/glimage_test.go index f495ffb..5bbd517 100644 --- a/gl/glutil/glimage_test.go +++ b/gl/glutil/glimage_test.go @@ -67,7 +67,7 @@ func TestImage(t *testing.T) { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Viewport(0, 0, pixW, pixH) - m := NewImage(geom.Point{ptW, ptH}) + m := NewImage(src.Bounds().Dx(), src.Bounds().Dy()) b := m.RGBA.Bounds() draw.Draw(m.RGBA, b, src, src.Bounds().Min, draw.Src) m.Upload()