mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
Compare commits
31 Commits
155c3a41ba
...
0bdbc5e115
Author | SHA1 | Date | |
---|---|---|---|
|
0bdbc5e115 | ||
|
c1315b3238 | ||
|
9d4f88c992 | ||
|
e3af35e6ff | ||
|
4267664b8b | ||
|
2a22260d14 | ||
|
3f91d8cdf1 | ||
|
ec7ef5e6a3 | ||
|
5b8fd9733c | ||
|
9ff93e3063 | ||
|
def82fd5d3 | ||
|
32417353d3 | ||
|
f6fbb3ddea | ||
|
4061742067 | ||
|
b749976a84 | ||
|
0c3b4a2d91 | ||
|
c86874b506 | ||
|
7524f990ba | ||
|
b7015c4354 | ||
|
96984210e1 | ||
|
1cd6a1f10c | ||
|
0eb2b9980d | ||
|
76a170eecf | ||
|
941aec5f51 | ||
|
a6d7cadab7 | ||
|
dc8dfae3bf | ||
|
ffb77757f0 | ||
|
60f0a03749 | ||
|
22339c2510 | ||
|
96e0fd7a50 | ||
|
546c47878d |
6
.github/workflows/pages.yml
vendored
6
.github/workflows/pages.yml
vendored
@ -21,14 +21,14 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v3
|
||||
uses: actions/configure-pages@v5
|
||||
- name: Build with Jekyll
|
||||
uses: actions/jekyll-build-pages@v1
|
||||
with:
|
||||
source: ./.github/workflows/site
|
||||
destination: ./_site
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
|
||||
deploy:
|
||||
environment:
|
||||
@ -39,4 +39,4 @@ jobs:
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v2
|
||||
uses: actions/deploy-pages@v4
|
||||
|
2
.github/workflows/steam.yml
vendored
2
.github/workflows/steam.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
shell: bash
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Docker build (amd64)
|
||||
run: |
|
||||
|
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
go: ['1.19.x', '1.20.x', '1.21.x', '1.22.x']
|
||||
go: ['1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.0-rc.1']
|
||||
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
@ -23,15 +23,15 @@ jobs:
|
||||
git config --global core.eol lf
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
- name: Setup JDK
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@ -98,7 +98,7 @@ jobs:
|
||||
- name: go build (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
run: |
|
||||
env CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -v ./...
|
||||
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v ./...
|
||||
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o flappy_amd64 -v ./examples/flappy
|
||||
env CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o flappy_arm64 -v ./examples/flappy
|
||||
lipo -create flappy_amd64 flappy_arm64 -output flappy
|
||||
|
4
.github/workflows/vuln.yml
vendored
4
.github/workflows/vuln.yml
vendored
@ -39,10 +39,10 @@ jobs:
|
||||
git config --global core.eol lf
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func init() {
|
||||
debugPrintTextImage = ebiten.NewImageFromImage(img)
|
||||
}
|
||||
|
||||
// DebugPrint draws the string str on the image on left top corner.
|
||||
// DebugPrint draws the string str on the image at (0, 0) position (the upper-left corner in most cases).
|
||||
//
|
||||
// The available runes are in U+0000 to U+00FF, which is C0 Controls and Basic Latin and C1 Controls and Latin-1 Supplement.
|
||||
func DebugPrint(image *ebiten.Image, str string) {
|
||||
|
@ -22,6 +22,9 @@ var (
|
||||
//go:embed jab.wav
|
||||
Jab_wav []byte
|
||||
|
||||
//go:embed jab8.wav
|
||||
Jab8_wav []byte
|
||||
|
||||
//go:embed jump.ogg
|
||||
Jump_ogg []byte
|
||||
|
||||
|
BIN
examples/resources/audio/jab8.wav
Normal file
BIN
examples/resources/audio/jab8.wav
Normal file
Binary file not shown.
@ -3,24 +3,35 @@
|
||||
## ebiten.png
|
||||
|
||||
```
|
||||
http://www.sozai-page.com/02_sozai/b/b04/b04_002/b04_002.html
|
||||
https://web.archive.org/web/20200110174435/http://www.sozai-page.com/02_sozai/b/b04/b04_002/b04_002.html
|
||||
https://web.archive.org/web/20191229033100/http://www.sozai-page.com/rule/rule1.html
|
||||
|
||||
● 商用・個人使用を問わず自由に使用できます。
|
||||
● 画像の内容、画質、状態などにより生じた結果に当方は一切責任を負いません。
|
||||
● 全ての画像は自由に加工・修正できます。
|
||||
ただし、加工により生じた結果に当方は一切責任を負いません。
|
||||
● 加工・修正に関わらず、許可無く画像として再配布・販売することを禁止します。
|
||||
|
||||
これはあくまで「お願い」なのですが、出版・放送等メディア関係の方は使用の際にご連絡いただけると助かります。印刷物やテレビ放送での使用に制限はありませんが、書名、雑誌名、番組名、また発売日・放送日が決まっているようでしたらお知らせいただけないでしょうか。
|
||||
当サイトの画像がどのように利用されたのか、今後の参考にいたします。
|
||||
```
|
||||
|
||||
## fiveyears.jpg
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
The design is licensed under the Creative Commons 4.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
## gophers.jpg
|
||||
|
||||
```
|
||||
http://blog.golang.org/go-programming-language-turns-two
|
||||
https://go.dev/blog/2years
|
||||
https://go.dev/copyright
|
||||
|
||||
Photograph by Chris Nokleberg
|
||||
the Creative Commons Attribution 3.0 License
|
||||
The Creative Commons Attribution 4.0 License
|
||||
```
|
||||
|
||||
## runner.png
|
||||
@ -106,7 +117,7 @@ CC0 1.0
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
The design is licensed under the Creative Commons 4.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
@ -128,7 +139,7 @@ MIT License
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
The design is licensed under the Creative Commons 4.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
@ -136,7 +147,7 @@ Read this article for more details: https://blog.golang.org/gopher
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
The design is licensed under the Creative Commons 4.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
@ -150,7 +161,7 @@ https://corvussg.itch.io/2d-game-backgrounds
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
The design is licensed under the Creative Commons 4.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
@ -175,5 +186,5 @@ MIT License
|
||||
|
||||
```
|
||||
Copyright 2014 Hajime Hoshi
|
||||
the Creative Commons Attribution 3.0 License
|
||||
The Creative Commons Attribution 4.0 License
|
||||
```
|
||||
|
@ -16,6 +16,8 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
@ -32,6 +34,10 @@ const (
|
||||
sampleRate = 48000
|
||||
)
|
||||
|
||||
var (
|
||||
flagBitsPerSample = flag.Int("bits", 16, "bits per sample")
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
audioContext *audio.Context
|
||||
audioPlayer *audio.Player
|
||||
@ -59,7 +65,14 @@ func NewGame() (*Game, error) {
|
||||
// ...
|
||||
|
||||
// Decode wav-formatted data and retrieve decoded PCM stream.
|
||||
d, err := wav.DecodeWithoutResampling(bytes.NewReader(raudio.Jab_wav))
|
||||
var r io.Reader
|
||||
switch *flagBitsPerSample {
|
||||
case 8:
|
||||
r = bytes.NewReader(raudio.Jab8_wav)
|
||||
default:
|
||||
r = bytes.NewReader(raudio.Jab_wav)
|
||||
}
|
||||
d, err := wav.DecodeWithoutResampling(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -99,6 +112,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
g, err := NewGame()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -47,7 +47,7 @@ var (
|
||||
flagAutoRestore = flag.Bool("autorestore", false, "restore the window automatically")
|
||||
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
|
||||
flagMinWindowSize = flag.String("minwindowsize", "", "minimum window size (e.g., 100x200)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximium window size (e.g., 1920x1080)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximum window size (e.g., 1920x1080)")
|
||||
flagGraphicsLibrary = flag.String("graphicslibrary", "", "graphics library (e.g. opengl)")
|
||||
flagRunnableOnUnfocused = flag.Bool("runnableonunfocused", true, "whether the app is runnable even on unfocused")
|
||||
)
|
||||
|
@ -106,7 +106,7 @@ func (f *Field) HandleInput(x, y int) (handled bool, err error) {
|
||||
f.ch, f.end = Start(x, y)
|
||||
// Start returns nil for non-supported envrionments.
|
||||
if f.ch == nil {
|
||||
return true, nil
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,10 @@ func (t *textInput) init() {
|
||||
e.Call("preventDefault")
|
||||
}
|
||||
if e.Get("code").String() == "Enter" || e.Get("key").String() == "Enter" {
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true, especially for iOS Safari.
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true.
|
||||
e.Call("preventDefault")
|
||||
ui.Get().UpdateInputFromEvent(e)
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
if !e.Get("isComposing").Bool() {
|
||||
@ -96,6 +99,11 @@ func (t *textInput) init() {
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "input", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
e := args[0]
|
||||
// On iOS Safari, `isComposing` can be undefined.
|
||||
if e.Get("isComposing").IsUndefined() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
if e.Get("isComposing").Bool() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
@ -109,8 +117,12 @@ func (t *textInput) init() {
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion on mobile browsers.
|
||||
t.trySend(false)
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion with a virtual keyboard.
|
||||
if ui.IsVirtualKeyboard() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
@ -172,7 +184,13 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
|
||||
s := newSession()
|
||||
t.session = s
|
||||
}
|
||||
return t.session.ch, t.session.end
|
||||
return t.session.ch, func() {
|
||||
if t.session != nil {
|
||||
t.session.end()
|
||||
// Reset the session explictly, or a new session cannot be created above.
|
||||
t.session = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if t.session != nil {
|
||||
@ -193,6 +211,10 @@ func (t *textInput) trySend(committed bool) {
|
||||
}
|
||||
|
||||
textareaValue := t.textareaElement.Get("value").String()
|
||||
if textareaValue == "" {
|
||||
return
|
||||
}
|
||||
|
||||
start := t.textareaElement.Get("selectionStart").Int()
|
||||
end := t.textareaElement.Get("selectionEnd").Int()
|
||||
startInBytes := convertUTF16CountToByteCount(textareaValue, start)
|
||||
|
@ -66,10 +66,6 @@ func (g *gameForUI) NewOffscreenImage(width, height int) *ui.Image {
|
||||
// An image on an atlas is surrounded by a transparent edge,
|
||||
// and the shader program unexpectedly picks the pixel on the edges.
|
||||
imageType := atlas.ImageTypeUnmanaged
|
||||
if ui.Get().IsScreenClearedEveryFrame() {
|
||||
// A volatile image is also always isolated.
|
||||
imageType = atlas.ImageTypeVolatile
|
||||
}
|
||||
g.offscreen = newImage(image.Rect(0, 0, width, height), imageType)
|
||||
return g.offscreen.image
|
||||
}
|
||||
|
16
go.mod
16
go.mod
@ -5,24 +5,24 @@ go 1.19
|
||||
require (
|
||||
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895
|
||||
github.com/ebitengine/hideconsole v1.0.0
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1
|
||||
github.com/ebitengine/purego v0.8.0-alpha.2
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.2
|
||||
github.com/ebitengine/purego v0.8.0-alpha.3
|
||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
|
||||
github.com/go-text/typesetting v0.1.1
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2.0.20240702135854-ca5ee73608ff
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4
|
||||
github.com/jakecoffman/cp v1.2.1
|
||||
github.com/jezek/xgb v1.1.1
|
||||
github.com/jfreymuth/oggvorbis v1.0.5
|
||||
github.com/kisielk/errcheck v1.7.0
|
||||
golang.org/x/image v0.16.0
|
||||
golang.org/x/image v0.18.0
|
||||
golang.org/x/sync v0.7.0
|
||||
golang.org/x/sys v0.20.0
|
||||
golang.org/x/text v0.15.0
|
||||
golang.org/x/tools v0.21.0
|
||||
golang.org/x/sys v0.21.0
|
||||
golang.org/x/text v0.16.0
|
||||
golang.org/x/tools v0.22.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jfreymuth/vorbis v1.0.2 // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/mod v0.18.0 // indirect
|
||||
)
|
||||
|
54
go.sum
54
go.sum
@ -2,17 +2,18 @@ github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895 h1:48bCqKTuD7Z
|
||||
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895/go.mod h1:XZdLv05c5hOZm3fM2NlJ92FyEZjnslcMcNRrhxs8+8M=
|
||||
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
|
||||
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
|
||||
github.com/ebitengine/purego v0.8.0-alpha.2 h1:+Kyr9n4eXAGMzhtWJxfdQ7AzGn0+6ZWihfCCxul3Dso=
|
||||
github.com/ebitengine/purego v0.8.0-alpha.2/go.mod h1:w5fARo4H5UrAgQTz0yqDfZ6bjstTQwUFmO+TN+nHlWE=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.2 h1:ex2UbULSPuLt76yyaR2JBXICx83Ph6Oz5ugN7h1Jo/I=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.2/go.mod h1:yYvXK7mgNwsFawY5RsvGI6yhMHtD+0MfaPkDTl9/uv8=
|
||||
github.com/ebitengine/purego v0.8.0-alpha.3 h1:qoFlpGuVwJ6J85kuj6Qpyp0DBgxsNYfSY9efidSNFgA=
|
||||
github.com/ebitengine/purego v0.8.0-alpha.3/go.mod h1:b94LtM1jUWDZPKDyENVhB0WsLdLWFApjbNw5AyxmKyI=
|
||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk=
|
||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38=
|
||||
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
|
||||
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1 h1:GLoMNCbvXOd39tFkqk9w/MI0xSLJaDzEOOl8mT1ILtI=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2.0.20240702135854-ca5ee73608ff h1:y9id11SS0aYxtJJcFsCM/EHvlpoVlUuJR3GucpRzVfc=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2.0.20240702135854-ca5ee73608ff/go.mod h1:QaGRNyhNhRpVb9JENnV/sNSDzmw2yIAr2HaZyY2JGeE=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
|
||||
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
|
||||
@ -30,20 +31,31 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
||||
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
|
||||
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
|
||||
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
|
||||
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@ -54,22 +66,36 @@ golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
|
||||
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
|
||||
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
14
image.go
14
image.go
@ -43,6 +43,9 @@ type Image struct {
|
||||
// tmpVertices must not be reused until ui.Image.Draw* is called.
|
||||
tmpVertices []float32
|
||||
|
||||
// tmpIndices must not be reused until ui.Image.Draw* is called.
|
||||
tmpIndices []uint32
|
||||
|
||||
// tmpUniforms must not be reused until ui.Image.Draw* is called.
|
||||
tmpUniforms []uint32
|
||||
|
||||
@ -514,7 +517,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
vs[i*graphics.VertexFloatCount+7] = v.ColorA * ca
|
||||
}
|
||||
}
|
||||
is := make([]uint32, len(indices))
|
||||
is := i.ensureTmpIndices(len(indices))
|
||||
for i := range is {
|
||||
is[i] = uint32(indices[i])
|
||||
}
|
||||
@ -664,7 +667,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
vs[i*graphics.VertexFloatCount+7] = v.ColorA
|
||||
}
|
||||
|
||||
is := make([]uint32, len(indices))
|
||||
is := i.ensureTmpIndices(len(indices))
|
||||
for i := range is {
|
||||
is[i] = uint32(indices[i])
|
||||
}
|
||||
@ -1398,6 +1401,13 @@ func (i *Image) ensureTmpVertices(n int) []float32 {
|
||||
return i.tmpVertices[:n]
|
||||
}
|
||||
|
||||
func (i *Image) ensureTmpIndices(n int) []uint32 {
|
||||
if cap(i.tmpIndices) < n {
|
||||
i.tmpIndices = make([]uint32, n)
|
||||
}
|
||||
return i.tmpIndices[:n]
|
||||
}
|
||||
|
||||
// private implements FinalScreen.
|
||||
func (*Image) private() {
|
||||
}
|
||||
|
@ -69,3 +69,9 @@ func DeferredFuncCountForTesting() int {
|
||||
defer deferredM.Unlock()
|
||||
return len(deferred)
|
||||
}
|
||||
|
||||
func BackendCountForTesting() int {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
return len(theBackends)
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func putImagesOnSourceBackend() {
|
||||
if i.usedAsSourceCount < math.MaxInt {
|
||||
i.usedAsSourceCount++
|
||||
}
|
||||
if int64(i.usedAsSourceCount) >= int64(baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31)))) {
|
||||
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31))) {
|
||||
i.putOnSourceBackend()
|
||||
i.usedAsSourceCount = 0
|
||||
}
|
||||
@ -97,6 +97,8 @@ func putImagesOnSourceBackend() {
|
||||
imagesToPutOnSourceBackend.clear()
|
||||
}
|
||||
|
||||
// backend is a big texture atlas that can have multiple images.
|
||||
// backend is a texture in GPU.
|
||||
type backend struct {
|
||||
// image is an atlas on which there might be multiple images.
|
||||
image *graphicscommand.Image
|
||||
@ -109,6 +111,7 @@ type backend struct {
|
||||
page *packing.Page
|
||||
|
||||
// source reports whether this backend is mainly used a rendering source, but this is not 100%.
|
||||
//
|
||||
// If a non-source (destination) image is used as a source many times,
|
||||
// the image's backend might be turned into a source backend to optimize draw calls.
|
||||
source bool
|
||||
@ -144,8 +147,6 @@ func (b *backend) extendIfNeeded(width, height int) {
|
||||
// Assume that the screen image is never extended.
|
||||
newImg := newClearedImage(width, height, false)
|
||||
|
||||
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
||||
// information.
|
||||
srcs := [graphics.ShaderSrcImageCount]*graphicscommand.Image{b.image}
|
||||
sw, sh := b.image.InternalSize()
|
||||
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||
@ -220,12 +221,18 @@ var (
|
||||
deferredM sync.Mutex
|
||||
)
|
||||
|
||||
// ImageType represents the type of an image.
|
||||
type ImageType int
|
||||
|
||||
const (
|
||||
// ImageTypeRegular is a regular image, that can be on a big texture atlas (backend).
|
||||
ImageTypeRegular ImageType = iota
|
||||
|
||||
// ImageTypeScreen is a screen image that is not on an atlas.
|
||||
// A screen image is also unmanaged.
|
||||
ImageTypeScreen
|
||||
ImageTypeVolatile
|
||||
|
||||
// ImageTypeUnmanaged is an unmanaged image that is not on an atlas.
|
||||
ImageTypeUnmanaged
|
||||
)
|
||||
|
||||
@ -245,11 +252,13 @@ type Image struct {
|
||||
// In the current implementation, if an image is being modified by DrawTriangles, the image is separated from
|
||||
// a graphicscommand.Image on an atlas by ensureIsolatedFromSource.
|
||||
//
|
||||
// The type is int64 instead of int to avoid overflow when comparing the limitation.
|
||||
//
|
||||
// usedAsSourceCount is increased if the image is used as a rendering source, or set to 0 if the image is
|
||||
// modified.
|
||||
//
|
||||
// WritePixels doesn't affect this value since WritePixels can be done on images on an atlas.
|
||||
usedAsSourceCount int
|
||||
usedAsSourceCount int64
|
||||
|
||||
// usedAsDestinationCount represents how many times an image is used as a rendering destination at DrawTriangles.
|
||||
// usedAsDestinationCount affects the calculation when to put the image onto a texture atlas again.
|
||||
@ -810,18 +819,14 @@ func (i *Image) deallocate() {
|
||||
return
|
||||
}
|
||||
|
||||
if !i.isOnAtlas() {
|
||||
i.backend.image.Dispose()
|
||||
i.backend.image = nil
|
||||
return
|
||||
}
|
||||
|
||||
i.backend.page.Free(i.node)
|
||||
if !i.backend.page.IsEmpty() {
|
||||
// As this part can be reused, this should be cleared explicitly.
|
||||
r := i.regionWithPadding()
|
||||
i.backend.clearPixels(r)
|
||||
return
|
||||
if i.isOnAtlas() {
|
||||
i.backend.page.Free(i.node)
|
||||
if !i.backend.page.IsEmpty() {
|
||||
// As this part can be reused, this should be cleared explicitly.
|
||||
r := i.regionWithPadding()
|
||||
i.backend.clearPixels(r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
i.backend.image.Dispose()
|
||||
@ -878,20 +883,6 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
|
||||
|
||||
runtime.SetFinalizer(i, (*Image).finalize)
|
||||
|
||||
if i.imageType == ImageTypeScreen {
|
||||
if asSource {
|
||||
panic("atlas: a screen image cannot be created as a source")
|
||||
}
|
||||
// A screen image doesn't have a padding.
|
||||
i.backend = &backend{
|
||||
image: newClearedImage(i.width, i.height, true),
|
||||
width: i.width,
|
||||
height: i.height,
|
||||
}
|
||||
theBackends = append(theBackends, i.backend)
|
||||
return
|
||||
}
|
||||
|
||||
wp := i.width + i.paddingSize()
|
||||
hp := i.height + i.paddingSize()
|
||||
|
||||
@ -901,7 +892,7 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
|
||||
}
|
||||
|
||||
i.backend = &backend{
|
||||
image: newClearedImage(wp, hp, false),
|
||||
image: newClearedImage(wp, hp, i.imageType == ImageTypeScreen),
|
||||
width: wp,
|
||||
height: hp,
|
||||
source: asSource && i.imageType == ImageTypeRegular,
|
||||
|
@ -177,8 +177,8 @@ func TestReputOnSourceBackend(t *testing.T) {
|
||||
}
|
||||
img2.WritePixels(pix, image.Rect(0, 0, size, size))
|
||||
|
||||
// Create a volatile image. This should always be on a non-source backend.
|
||||
img3 := atlas.NewImage(size, size, atlas.ImageTypeVolatile)
|
||||
// Create an unmanaged image. This should always be on a non-source backend.
|
||||
img3 := atlas.NewImage(size, size, atlas.ImageTypeUnmanaged)
|
||||
defer img3.Deallocate()
|
||||
img3.WritePixels(make([]byte, 4*size*size), image.Rect(0, 0, size, size))
|
||||
if got, want := img3.IsOnSourceBackendForTesting(), false; got != want {
|
||||
@ -296,7 +296,7 @@ func TestReputOnSourceBackend(t *testing.T) {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
|
||||
// Use img3 as a render source. As img3 is volatile, img3 is never on an atlas.
|
||||
// Use img3 as a render source. As img3 is unmanaged, img3 is never on an atlas.
|
||||
for i := 0; i < atlas.BaseCountToPutOnSourceBackend*2; i++ {
|
||||
atlas.PutImagesOnSourceBackendForTesting()
|
||||
vs := quadVertices(size, size, 0, 0, 1)
|
||||
@ -688,7 +688,7 @@ func TestImageIsNotReputOnSourceBackendWithoutUsingAsSource(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImageWritePixelsModify(t *testing.T) {
|
||||
for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeVolatile, atlas.ImageTypeUnmanaged} {
|
||||
for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged} {
|
||||
const size = 16
|
||||
img := atlas.NewImage(size, size, typ)
|
||||
defer img.Deallocate()
|
||||
@ -881,4 +881,26 @@ func TestGC(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDallocateUnmanagedImageBackends(t *testing.T) {
|
||||
const w, h = 16, 16
|
||||
img0 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
|
||||
img1 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
|
||||
|
||||
// Call DrawTriangles to ensure the images are on backends.
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := image.Rect(0, 0, w, h)
|
||||
img0.DrawTriangles([graphics.ShaderSrcImageCount]*atlas.Image{img1}, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll)
|
||||
|
||||
// Get the difference of the number of backends before and after the images are deallocated.
|
||||
c := atlas.BackendCountForTesting()
|
||||
img0.Deallocate()
|
||||
img1.Deallocate()
|
||||
|
||||
diff := c - atlas.BackendCountForTesting()
|
||||
if got, want := diff, 2; got != want {
|
||||
t.Errorf("got: %d, want: %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add tests to extend image on an atlas out of the main loop
|
||||
|
@ -36,8 +36,8 @@ type playstation5Error struct {
|
||||
func newPlaystation5Error(name string, err C.ebitengine_Error) *playstation5Error {
|
||||
return &playstation5Error{
|
||||
name: name,
|
||||
code: int(err.code),
|
||||
message: C.GoString(err.message),
|
||||
code: int(err.Code),
|
||||
message: C.GoString(err.Message),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,12 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ebitengine_Error {
|
||||
const char* message;
|
||||
int code;
|
||||
const char* Message;
|
||||
int Code;
|
||||
} ebitengine_Error;
|
||||
|
||||
static bool ebitengine_IsErrorNil(ebitengine_Error* err) {
|
||||
return err->message == NULL && err->code == 0;
|
||||
return err->Message == NULL && err->Code == 0;
|
||||
}
|
||||
|
||||
ebitengine_Error ebitengine_InitializeGraphics(void);
|
||||
|
@ -71,7 +71,6 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Mipmap, verti
|
||||
}
|
||||
|
||||
level := 0
|
||||
// TODO: Do we need to check all the sources' states of being volatile?
|
||||
if !canSkipMipmap && srcs[0] != nil && canUseMipmap(srcs[0].imageType) {
|
||||
level = math.MaxInt32
|
||||
for i := 0; i < len(indices)/3; i++ {
|
||||
@ -215,7 +214,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
}
|
||||
|
||||
if !canUseMipmap(m.imageType) {
|
||||
panic("mipmap: mipmap images for a volatile or a screen image is not implemented yet")
|
||||
panic("mipmap: mipmap images for a screen image is not implemented yet")
|
||||
}
|
||||
|
||||
if img, ok := m.imgs[level]; ok {
|
||||
|
@ -178,12 +178,6 @@ func (c *context) newOffscreenImage(w, h int) *Image {
|
||||
}
|
||||
|
||||
func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, ui *UserInterface, forceDraw bool) error {
|
||||
if (c.offscreen.imageType == atlas.ImageTypeVolatile) != ui.IsScreenClearedEveryFrame() {
|
||||
w, h := c.offscreen.width, c.offscreen.height
|
||||
c.offscreen.Deallocate()
|
||||
c.offscreen = c.newOffscreenImage(w, h)
|
||||
}
|
||||
|
||||
// isOffscreenModified is updated when an offscreen's modifyCallback.
|
||||
c.isOffscreenModified = false
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"math"
|
||||
|
||||
@ -86,16 +85,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
|
||||
|
||||
if antialias {
|
||||
if i.bigOffscreenBuffer == nil {
|
||||
var imageType atlas.ImageType
|
||||
switch i.imageType {
|
||||
case atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged:
|
||||
imageType = atlas.ImageTypeUnmanaged
|
||||
case atlas.ImageTypeScreen, atlas.ImageTypeVolatile:
|
||||
imageType = atlas.ImageTypeVolatile
|
||||
default:
|
||||
panic(fmt.Sprintf("ui: unexpected image type: %d", imageType))
|
||||
}
|
||||
i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, imageType)
|
||||
i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, atlas.ImageTypeUnmanaged)
|
||||
}
|
||||
|
||||
i.bigOffscreenBuffer.drawTriangles(srcs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule, canSkipMipmap)
|
||||
|
@ -16,6 +16,7 @@ package ui
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
"unicode"
|
||||
)
|
||||
@ -64,6 +65,11 @@ var codeToMouseButton = map[int]MouseButton{
|
||||
|
||||
func eventToKeys(e js.Value) (key0, key1 Key, fromKeyProperty bool) {
|
||||
id := jsCodeToID(e.Get("code"))
|
||||
|
||||
// On mobile browsers, treat enter key as if this is from a `key` property.
|
||||
if IsVirtualKeyboard() && id == KeyEnter {
|
||||
return KeyEnter, -1, true
|
||||
}
|
||||
if id >= 0 {
|
||||
return id, -1, false
|
||||
}
|
||||
@ -426,3 +432,15 @@ func (i *InputState) resetForBlur() {
|
||||
}
|
||||
i.Touches = i.Touches[:0]
|
||||
}
|
||||
|
||||
func IsVirtualKeyboard() bool {
|
||||
// Detect a virtual keyboard by the user agent.
|
||||
// Note that this is not a correct way to detect a virtual keyboard.
|
||||
// In the future, we should use the `navigator.virtualKeyboard` API.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/virtualKeyboard
|
||||
ua := js.Global().Get("navigator").Get("userAgent").String()
|
||||
if strings.Contains(ua, "Android") || strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -905,13 +905,10 @@ func (u *UserInterface) registerWindowCloseCallback() error {
|
||||
|
||||
// registerWindowFramebufferSizeCallback must be called from the main thread.
|
||||
func (u *UserInterface) registerWindowFramebufferSizeCallback() error {
|
||||
if u.defaultFramebufferSizeCallback == nil && runtime.GOOS != "darwin" {
|
||||
if u.defaultFramebufferSizeCallback == nil {
|
||||
// When the window gets resized (either by manual window resize or a window
|
||||
// manager), glfw sends a framebuffer size callback which we need to handle (#1960).
|
||||
// This event is the only way to handle the size change at least on i3 window manager.
|
||||
//
|
||||
// When a decorating state changes, the callback of arguments might be an unexpected value on macOS (#2257)
|
||||
// Then, do not register this callback on macOS.
|
||||
u.defaultFramebufferSizeCallback = func(_ *glfw.Window, w, h int) {
|
||||
f, err := u.isFullscreen()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user