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
This commit is contained in:
parent
fd18e8dcec
commit
0ac70a3835
@ -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))
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user