731 Commits

Author SHA1 Message Date
Hajime Hoshi 439a0ff7b1 ebiten: add RecyclableSubImage and restrict Recycle to recyclable images
The pool was previously used by both NewImage and SubImage, but only
the sub-image churn case benefits from pooling. Any image could be
recycled, including originals — a documented footgun.

Add RecyclableSubImage that explicitly creates pooled sub-images, and
restrict Recycle to only work on images created by RecyclableSubImage.

Closes #3423

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 01:33:56 +09:00
Hajime Hoshi 6f32f6bd12 ebiten: document Recycle footgun with SubImage returning the caller
Updates #3418

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 19:47:45 +09:00
Hajime Hoshi ec24294d22 ebiten: reland: add Image.Recycle to reduce struct allocations via a global pool
Add a global sync.Pool (theImagePool) for *Image structs so that both
NewImage and SubImage can reuse allocations instead of always calling new.
Add Image.Recycle to return a struct to the pool when the caller is done
with it. After Recycle is called the image must not be used; the behavior
is undefined.

Closes #3418

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-20 19:28:34 +09:00
Hajime Hoshi c906d02e28 Revert "ebiten: add Image.Recycle to reduce struct allocations via a global pool"
This reverts commit 0e8009bd9b.

Reason: Recycle can break a sub-image in a cache

Updates #3418
2026-03-20 19:25:44 +09:00
Hajime Hoshi 0e8009bd9b ebiten: add Image.Recycle to reduce struct allocations via a global pool
Add a global sync.Pool (theImagePool) for *Image structs so that both
NewImage and SubImage can reuse allocations instead of always calling new.
Add Image.Recycle to return a struct to the pool when the caller is done
with it. After Recycle is called the image must not be used; the behavior
is undefined.

Closes #3418

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-20 19:16:18 +09:00
Hajime Hoshi 3b5280036e image: invoke usage callbacks in Dispose and Deallocate
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 18:51:47 +09:00
Hajime Hoshi b78d867e7a internal/colormshader: extract ColorM shader logic from builtinshader
Create a new internal/colormshader package that owns the color matrix
shader generation, fully independent of internal/builtinshader. It has
its own shader template with ColorM logic baked in, its own
Filter/Address types, and a go:generate pipeline producing defs.go.

This removes the useColorM dimension from internal/builtinshader,
reducing it from 18 shader variants to 9. The colorm package now
imports only colormshader (not builtinshader) for shader sources,
preparing for the v2/v3 split where v2's colorm cannot access v3's
builtinshader.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 15:59:50 +09:00
Hajime Hoshi b1101bb967 Revert "internal/colormshader: extract ColorM shader logic from builtinshader"
This reverts commit 708b3d4cf8.

Reason: test failures
2026-03-14 15:55:19 +09:00
Hajime Hoshi 708b3d4cf8 internal/colormshader: extract ColorM shader logic from builtinshader
Create a new internal/colormshader package that owns the color matrix
shader generation, fully independent of internal/builtinshader. It has
its own shader template with ColorM logic baked in, its own
Filter/Address types, and a go:generate pipeline producing defs.go.

This removes the useColorM dimension from internal/builtinshader,
reducing it from 18 shader variants to 9. The colorm package now
imports only colormshader (not builtinshader) for shader sources,
preparing for the v2/v3 split where v2's colorm cannot access v3's
builtinshader.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 15:47:25 +09:00
Hajime Hoshi 369f2ab8f7 internal/ui: move the implementation for AntiAlias to stencilbuffer.go
Updates #3361
2026-01-18 22:04:31 +09:00
Hajime Hoshi a202f46983 internal/graphics: remove FillRule
Closes #3361
2025-12-29 01:33:23 +09:00
Hajime Hoshi c8590289ed ebiten: reimplement FillRule without graphics drivers' stencil buffer
Updates #3361
2025-12-28 23:51:29 +09:00
Hajime Hoshi 353b07a2d6 vector: reland: bug fix: a callback for an image and its sub-image should be treated correctly
Closes #3355
2025-12-05 03:08:47 +09:00
Hajime Hoshi 7309a47a30 Revert "vector: bug fix: a callback for an image and its sub-image should be treated correctly"
This reverts commit 41354b957b.

Reason: this change fails tests on Windows

Updates #3335
2025-12-05 01:03:17 +09:00
Hajime Hoshi 41354b957b vector: bug fix: a callback for an image and its sub-image should be treated correctly
Closes #3355
2025-12-05 00:48:18 +09:00
Hajime Hoshi 869376395c ebiten: add premultipliedAlpha flag to imageToBytes
This is a preparation for ColorEncoding option at NewImageFromImage.

Updates #3314
2025-11-24 18:54:40 +09:00
Hajime Hoshi 2d2aae21d8 internal/restorable: remove Hint
Updates #3090
2025-11-23 16:37:53 +09:00
Hajime Hoshi a8a21ba687 ebiten, vector: bug fix: race conditions
This change fixes these race conditions in

 * (*ebiten.Image).invokeUsageCallbacks concurrent invocations
 * (*ebiten.Image).usageCallbacks usages
 * vector.theCallbackTokens usages
 * vector's global shader initializations

Closes #3333
2025-10-21 03:24:21 +09:00
Hajime Hoshi 5f08f4ae1d vector: bug fix: FillRect or other utility functions on a sub-image didn't work correctly
Closes #3330
2025-10-15 20:17:07 +09:00
Hajime Hoshi fb60c54510 ebiten: refactoring 2025-07-19 22:17:30 +09:00
Hajime Hoshi 86fd3e8d66 ebiten: reduce boundary checks
Updates #3275
2025-07-19 21:51:46 +09:00
Hajime Hoshi 38b2e2c4ba ebiten: skip DrawTriangles(Shader)32 when len(indices) == 0
Updates #3275
2025-07-19 20:23:54 +09:00
Hajime Hoshi 1a68cf08c5 ebiten: remove unnecessary fmt.Sprintf 2025-07-19 17:34:16 +09:00
Jordan Philyaw 08783e9e26 ebiten: clarify Image Set does nothing for out-of-bounds coordinates (#3277) 2025-07-19 14:17:34 +09:00
oliverbestmann de1acb3e6d ebiten: only check sub image cache once per tick (#3276)
This improves performance on issue #3275 from 2-5fps to 25fps.

Updates #3275
2025-07-19 03:05:39 +09:00
Hajime Hoshi 80e3e01e88 vector: rename functions from DrawFilled* to Fill*
Updates #3150
2025-07-06 23:57:59 +09:00
Hajime Hoshi 97ebef8298 vector: add (*Path).AddPathStroke reimplement DrawFilledPath and StrokePath
The new implementation uses Evan's method [1] using texture representing
a stencil buffer instead of the graphics library's stencil buffer.
This simplifies the implementaiton of the graphics drivers, and enables
better anti-alias without changing the rendering cost.

Also, this fixes an issue of line rendering quality

This change deprecates some existing APIs like DrawImageOptions.AntiAlias
and FillRule. Users should always use DrawFilledPath or StrokePath.

[1] https://medium.com/@evanwallace/easy-scalable-text-rendering-on-the-gpu-c3f4d782c5ac

Closes #3124
Closes #3153
2025-07-06 23:35:48 +09:00
Hajime Hoshi be1d4fc1b3 ebiten: bug fix: SubImage can cause race conditions
Calling SubImage from an image and its sub-image could cause race
conditions.

This is a partial revert of 9fd726b773.

Updates #3267
2025-07-06 03:06:12 +09:00
Hajime Hoshi d599514476 ebiten: add comments 2025-07-05 23:24:46 +09:00
Hajime Hoshi 9fd726b773 ebiten: refactoring: remove Image.subImageCacheM
Record atime at each sub-image instead.

Updates #3267
2025-07-05 23:21:17 +09:00
Hajime Hoshi 0b3c999e86 ebiten: update comments 2025-07-05 23:00:31 +09:00
Hajime Hoshi d22ce78790 ebiten: bug fix: race condition on Image.subImageCache
The race condition could happen even if you follow the rule that
one image is touched from one goroutine. This change fixed the issue
by a mutex.

Closes #3267
2025-07-05 21:46:29 +09:00
Hajime Hoshi a4717f7f95 internal/shader: enable boolean values for uniform variables
Closes #3156
2025-06-21 18:43:34 +09:00
Hajime Hoshi cb73fe26c0 ebiten: add comments 2025-06-13 00:16:11 +09:00
Hajime Hoshi 3c1148f14c ebiten: intersect bounds before getting a subimage from cache
This should make the cache usage more efficient.

Updates #2902
2025-05-31 16:05:16 +09:00
Hajime Hoshi 15f2796970 ebiten: add sub-image caches to reduce allocations
Updates #2902
2025-05-31 13:17:15 +09:00
Hajime Hoshi 99286ab30c ebiten: add a comment about performance of Set 2025-03-02 03:22:45 +09:00
Hajime Hoshi bcb5a0a27e ebiten: add DrawTriangles(Shader)32
This change also adds the methods to FinalScreen interface.

Closes #3201
2025-02-19 23:51:38 +09:00
quasilyte 1790af6ed8 ebiten: clarify the same images size rule for DrawTrianglesShaderOptions (#3187)
Since it's not allowed to have differently-sized images for DrawTrianglesShaderOptions in pixels mode, the comment should be updated.
2025-01-31 19:36:31 +09:00
Hajime Hoshi 810e45c030 ebiten: skip rendering when det is 0 at DrawImage and DrawRectShader 2024-10-17 21:04:43 +09:00
Hajime Hoshi 5fd619eea7 ebiten: bug fix: canSkipMipmap didn't work with negative scaling
This just means that an optimization didn't work, so this issue
should not be so serious.
2024-10-17 21:02:59 +09:00
Hajime Hoshi 1260d77999 ebiten: refactoring 2024-09-22 13:27:25 +09:00
SolarLune a113687d56 ebiten: don't create a vertex copy in DrawTriangles() / DrawTrianglesShader() (#3104)
Closes #3103
2024-09-16 14:45:16 +09:00
Hajime Hoshi 4b1ae72f59 ebiten: add Draw{Image,Triangles}Options.DisableMipmaps
Mipmaps could be unexpectedly expensive even when we don't need mipmaps.
In order to improve performance, let's add an option to disable mipmaps.

Closes #3095
2024-09-12 22:40:16 +09:00
Hajime Hoshi d84b030300 ebiten: give HintOverwriteDstRegion when BlendClear is used 2024-09-08 14:57:20 +09:00
Hajime Hoshi 4824dc0360 internal/restorable: resolve a stale state when possible 2024-09-08 14:28:16 +09:00
Hajime Hoshi 30a2817ab5 internal/restorable: add Hint to optimize drawImageHistoryItem size 2024-09-08 12:24:20 +09:00
Hajime Hoshi 41b762ba2c ebiten: update comments
Updates #2640
2024-08-25 18:45:26 +09:00
Hajime Hoshi 2cc809516f ebiten: add Vertex.Custom0 to Custom3
Closes #2640
2024-08-25 18:11:39 +09:00
Hajime Hoshi b71f3f86a8 ebiten: add check that graphics.VertexFloatCount and Vertex match 2024-08-23 09:58:28 +09:00