Skip to content

Commit 0ac70a3

Browse files
committed
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
1 parent fd18e8d commit 0ac70a3

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

app/debug/fps.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"image/draw"
1212
"io/ioutil"
1313
"log"
14+
"math"
1415
"runtime"
1516
"sync"
1617
"time"
@@ -57,7 +58,8 @@ func fpsInit() {
5758
monofont.SetSrc(image.Black)
5859
monofont.SetHinting(freetype.FullHinting)
5960

60-
fps.Image = glutil.NewImage(geom.Point{50, 12})
61+
toPx := func(x geom.Pt) int { return int(math.Ceil(float64(geom.Pt(x).Px()))) }
62+
fps.Image = glutil.NewImage(toPx(50), toPx(12))
6163
monofont.SetDst(fps.Image.RGBA)
6264
monofont.SetClip(fps.Bounds())
6365
monofont.SetDPI(72 * float64(geom.PixelsPerPt))

gl/glutil/glimage.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package glutil
77
import (
88
"encoding/binary"
99
"image"
10-
"math"
1110
"sync"
1211

1312
"code.google.com/p/go.mobile/f32"
@@ -67,11 +66,9 @@ type Image struct {
6766
// NewImage creates an Image of the given size.
6867
//
6968
// Both a host-memory *image.RGBA and a GL texture are created.
70-
func NewImage(size geom.Point) *Image {
71-
realx := int(math.Ceil(float64(size.X.Px())))
72-
realy := int(math.Ceil(float64(size.Y.Px())))
73-
dx := roundToPower2(realx)
74-
dy := roundToPower2(realy)
69+
func NewImage(w, h int) *Image {
70+
dx := roundToPower2(w)
71+
dy := roundToPower2(h)
7572

7673
// TODO(crawshaw): Using VertexAttribPointer we can pass texture
7774
// data with a stride, which would let us use the exact number of
@@ -81,7 +78,7 @@ func NewImage(size geom.Point) *Image {
8178
glimage.Do(glInit)
8279

8380
img := &Image{
84-
RGBA: m.SubImage(image.Rect(0, 0, realx, realy)).(*image.RGBA),
81+
RGBA: m.SubImage(image.Rect(0, 0, w, h)).(*image.RGBA),
8582
Texture: gl.GenTexture(),
8683
texWidth: dx,
8784
texHeight: dy,

gl/glutil/glimage_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestImage(t *testing.T) {
6767
gl.Clear(gl.COLOR_BUFFER_BIT)
6868
gl.Viewport(0, 0, pixW, pixH)
6969

70-
m := NewImage(geom.Point{ptW, ptH})
70+
m := NewImage(src.Bounds().Dx(), src.Bounds().Dy())
7171
b := m.RGBA.Bounds()
7272
draw.Draw(m.RGBA, b, src, src.Bounds().Min, draw.Src)
7373
m.Upload()

0 commit comments

Comments
 (0)