mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +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()
|
||||
}
|
||||
|
||||
func ResolveDeferredForTesting() {
|
||||
resolveDeferred()
|
||||
}
|
||||
var ResolveDeferredForTesting = resolveDeferred
|
||||
var AdjustDestinationPixelForTesting = adjustDestinationPixel
|
||||
|
@ -799,6 +799,12 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
|
||||
func adjustDestinationPixel(x float32) float32 {
|
||||
// Avoid the center of the pixel, which is problematic (#929, #1171).
|
||||
// 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)))
|
||||
frac := x - ix
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user