2
0
mirror of synced 2025-02-21 14:08:14 +00:00

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:
David Crawshaw 2014-10-30 19:43:51 -04:00
parent fd18e8dcec
commit 0ac70a3835
3 changed files with 8 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import (
"image/draw" "image/draw"
"io/ioutil" "io/ioutil"
"log" "log"
"math"
"runtime" "runtime"
"sync" "sync"
"time" "time"
@ -57,7 +58,8 @@ func fpsInit() {
monofont.SetSrc(image.Black) monofont.SetSrc(image.Black)
monofont.SetHinting(freetype.FullHinting) 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.SetDst(fps.Image.RGBA)
monofont.SetClip(fps.Bounds()) monofont.SetClip(fps.Bounds())
monofont.SetDPI(72 * float64(geom.PixelsPerPt)) monofont.SetDPI(72 * float64(geom.PixelsPerPt))

View File

@ -7,7 +7,6 @@ package glutil
import ( import (
"encoding/binary" "encoding/binary"
"image" "image"
"math"
"sync" "sync"
"code.google.com/p/go.mobile/f32" "code.google.com/p/go.mobile/f32"
@ -67,11 +66,9 @@ type Image struct {
// NewImage creates an Image of the given size. // NewImage creates an Image of the given size.
// //
// Both a host-memory *image.RGBA and a GL texture are created. // Both a host-memory *image.RGBA and a GL texture are created.
func NewImage(size geom.Point) *Image { func NewImage(w, h int) *Image {
realx := int(math.Ceil(float64(size.X.Px()))) dx := roundToPower2(w)
realy := int(math.Ceil(float64(size.Y.Px()))) dy := roundToPower2(h)
dx := roundToPower2(realx)
dy := roundToPower2(realy)
// TODO(crawshaw): Using VertexAttribPointer we can pass texture // TODO(crawshaw): Using VertexAttribPointer we can pass texture
// data with a stride, which would let us use the exact number of // 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) glimage.Do(glInit)
img := &Image{ 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(), Texture: gl.GenTexture(),
texWidth: dx, texWidth: dx,
texHeight: dy, texHeight: dy,

View File

@ -67,7 +67,7 @@ func TestImage(t *testing.T) {
gl.Clear(gl.COLOR_BUFFER_BIT) gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Viewport(0, 0, pixW, pixH) gl.Viewport(0, 0, pixW, pixH)
m := NewImage(geom.Point{ptW, ptH}) m := NewImage(src.Bounds().Dx(), src.Bounds().Dy())
b := m.RGBA.Bounds() b := m.RGBA.Bounds()
draw.Draw(m.RGBA, b, src, src.Bounds().Min, draw.Src) draw.Draw(m.RGBA, b, src, src.Bounds().Min, draw.Src)
m.Upload() m.Upload()