mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/atlas: add a benchmark for adjustDestinationPixel
This commit is contained in:
parent
2cbc5e7b60
commit
9319266c01
@ -59,6 +59,5 @@ func (i *Image) EnsureIsolatedForTesting() {
|
|||||||
i.ensureIsolated()
|
i.ensureIsolated()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResolveDeferredForTesting() {
|
var ResolveDeferredForTesting = resolveDeferred
|
||||||
resolveDeferred()
|
var AdjustDestinationPixelForTesting = adjustDestinationPixel
|
||||||
}
|
|
||||||
|
@ -799,6 +799,12 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
|
|||||||
func adjustDestinationPixel(x float32) float32 {
|
func adjustDestinationPixel(x float32) float32 {
|
||||||
// Avoid the center of the pixel, which is problematic (#929, #1171).
|
// Avoid the center of the pixel, which is problematic (#929, #1171).
|
||||||
// Instead, align the vertices with about 1/3 pixels.
|
// Instead, align the vertices with about 1/3 pixels.
|
||||||
|
//
|
||||||
|
// The intention here is roughly this code:
|
||||||
|
//
|
||||||
|
// float32(math.Floor((float64(x)+1.0/6.0)*3) / 3)
|
||||||
|
//
|
||||||
|
// The actual implementation is more optimized than the above implementation.
|
||||||
ix := float32(math.Floor(float64(x)))
|
ix := float32(math.Floor(float64(x)))
|
||||||
frac := x - ix
|
frac := x - ix
|
||||||
switch {
|
switch {
|
||||||
|
@ -737,4 +737,10 @@ func TestImageWritePixelsModify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkAdjustPixel(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
atlas.AdjustDestinationPixelForTesting(float32(i) / 17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add tests to extend image on an atlas out of the main loop
|
// TODO: Add tests to extend image on an atlas out of the main loop
|
||||||
|
Loading…
Reference in New Issue
Block a user