Commit Graph

4326 Commits

Author SHA1 Message Date
Hajime Hoshi
14b34a7b0a internal/ui: typo 2023-03-31 03:21:48 +09:00
Hajime Hoshi
1999f8a024 internal/ui: use DirectX as a fallback for old Windows
Initializing OpenGL can fail [1], though this is pretty rare. For such
this case, try DirectX as a fallback.

[1] https://answers.microsoft.com/en-us/windows/forum/all/my-drivers-dont-support-opengl/a1ee0267-4dc8-4385-a185-6ed322d78329

Updates #2613
2023-03-31 03:15:52 +09:00
Hajime Hoshi
370b7599bc internal/graphicsdriver/directx: use OpenGL as the default on old Windows
On old machines, CreateSwapChain might fail without a specific reasons.
Probably this is due to an issue in drivers, and if so, there is nothing
we can do. When choosing a graphics library, prefer OpenGL on such old
machines.

Updates #2613
2023-03-31 02:21:11 +09:00
Hajime Hoshi
182ac21866 internal/goglfw: separate the Windows version detection to a new package winver 2023-03-31 02:16:01 +09:00
Hajime Hoshi
c0adcee12c Revert "internal/graphicsdriver/directx: initialize the refresh rate explicitly for Windows 7"
This reverts commit a4bfe8a869.

Reason: This doesn't take any effects.

Updates #2613
2023-03-30 22:40:53 +09:00
Hajime Hoshi
a4bfe8a869 internal/graphicsdriver/directx: initialize the refresh rate explicitly for Windows 7
This is an experimental fix inspired by Chromium/ANGLE
https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/src/libANGLE/renderer/gl/wgl/DXGISwapChainWindowSurfaceWGL.cpp;l=491-492;drc=79aa846e38739138918891e8b334fac464dd9b83

Updates #2613
2023-03-30 22:22:26 +09:00
Hajime Hoshi
09250ff4f3 internal/graphicsdriver/directx: adjust buffer count
Apparently the buffer count should be 1 with a non-flipping swap effect.

Updates #2613
2023-03-30 21:09:41 +09:00
Hajime Hoshi
61ced5127b internal/graphicsdriver/directx: limit d3dcompiler versions
For example, the verions 45/44 are alpha and should not be used.

Updates #2613
Updates #2618
2023-03-30 17:54:42 +09:00
Hajime Hoshi
99fb40f299 internal/processtest: skip tests on WSL
Closes #1864
2023-03-30 13:42:44 +09:00
Hajime Hoshi
d22158b156 internal/graphicsdriver/directx: use non-flip swap effect for old Windows
Updates #2613
Updates #2619
2023-03-30 12:33:08 +09:00
Hajime Hoshi
0cd832f096 internal/graphicsdriver/directx: check the DLL availability at NewGraphics
Updates #2613
Updates #2618
2023-03-30 01:45:31 +09:00
Hajime Hoshi
3e477d0bbb internal/graphicsdriver/directx: bug fix: d3dcomipler_47.dll might be missing
Updates #2613
Closes #2618
2023-03-30 01:12:46 +09:00
Hajime Hoshi
6858e4b60b internal/graphicsdriver/directx: use QueryInterface to cast IDXGISwapChain to IDXGISwapChain4
QueryInterface is better in terms of error messages than a dumb
pointer casting.
2023-03-30 00:44:39 +09:00
Hajime Hoshi
7fa65ae983 internal/graphicsdriver/directx: reduce unnecessary usages of IDXGISwapChain4
IDXGISwapChain is enough for DirectX 11.

Updates #2613
2023-03-30 00:14:04 +09:00
Hajime Hoshi
c9f1696a5b internal/graphicsdriver/directx: use CreateDXGIFactory instead of CreateDXGIFactory2
CreateDXGIFactory2 is available in Windows 8.1 and newer. This is not
necessary for the current Ebitengine implementation. Use the old version
CreateDXGIFactory to support Windows 8 and older.

Updates #2613
2023-03-29 23:56:17 +09:00
Hajime Hoshi
fe67399022 internal/graphicsdriver/directx: use CreateSwapChain instead of CreateSwapChainForHwnd
This is a preparation to use IDXGIFactory instead of IDXGIFactory4.

Updates #2613
2023-03-29 23:37:08 +09:00
Hajime Hoshi
ad1bb4b2cb internal/graphicsdriver/directx: remove unused functions 2023-03-29 23:21:08 +09:00
Hajime Hoshi
1017161c36 internal/graphicsdriver/directx: refactoring 2023-03-29 18:26:11 +09:00
Hajime Hoshi
0b0526a05b internal/graphicsdriver/directx: bug fix: had to consider strides when copying resources
Closes #2617
2023-03-29 18:24:36 +09:00
Hajime Hoshi
0449126c5b internal/graphicsdriver/directx: integrate EBITENGINE_DIRECTX and EBITENGINE_DIRECTX_FEATURE_LEVEL 2023-03-29 16:22:20 +09:00
Hajime Hoshi
129956d8f0 internal/graphicsdriver/directx: refactoring: remove graphic12.transparent 2023-03-29 15:56:33 +09:00
Hajime Hoshi
78d76945ad internal/graphicsdriver/directx: implement DirectX 11 driver
Updates #2613
2023-03-29 15:52:33 +09:00
Hajime Hoshi
c8a2e5dc71 internal/graphicsdriver/directx: refactoring
This is a preparation for a DirectX 11 driver.

Updates #2613
2023-03-29 15:34:58 +09:00
Hajime Hoshi
4779bbc04d internal/graphicsdriver/directx: refactoring: remove redundant adapter check 2023-03-29 15:32:49 +09:00
Hajime Hoshi
f23dd72fb4 internal/graphicsdriver/directx: reduce unnecessary settings of pipelines 2023-03-29 14:15:22 +09:00
Hajime Hoshi
c22957f678 internal/graphicsdriver/directx: dispose a screen image explicitly
A screen image in DirectX 12 should not include any buffers to release
so there is not a bug, but disposing it explicitly when resizing the
window should be polite.
2023-03-29 00:42:03 +09:00
Hajime Hoshi
f698f8fc69 internal/graphicsdriver/directx: refactoring 2023-03-28 02:32:01 +09:00
Hajime Hoshi
fe42c1f2b5 internal/graphicsdriver/directx: lower the shader version for feature levels 10.x
Updates #2613
2023-03-27 14:02:59 +09:00
Hajime Hoshi
dbb167c2d0 internal/graphicsdriver/directx: refactoring 2023-03-27 13:57:25 +09:00
Hajime Hoshi
549e6120b5 internal/graphicsdriver/directx: refactoring: reduce indentations 2023-03-26 22:56:15 +09:00
Hajime Hoshi
fe5c3354fc internal/graphicsdriver/directx: bug fix: missing error checking 2023-03-26 18:52:55 +09:00
Hajime Hoshi
c9469a64ee internal/graphicsdriver/directx: refactoring: add graphicsInfra 2023-03-26 18:31:42 +09:00
Hajime Hoshi
0b46d2b799 internal/graphicsdriver/directx: refactoring 2023-03-26 00:49:30 +09:00
Hajime Hoshi
902d7244eb internal/graphicsdriver/directx: rename structs for a new DirectX 11 implementation
Updates #2613
2023-03-26 00:32:47 +09:00
Hajime Hoshi
d6525a2782 internal/graphicsdriver/directx: refactoring 2023-03-25 16:52:58 +09:00
Hajime Hoshi
c394bdcf7c internal/graphicsdriver/directx: separate a part for images and shaders 2023-03-25 15:54:28 +09:00
Hajime Hoshi
4811386d8a internal/graphicsdriver/directx: separate a part for DirectX 12
Updates #2613
2023-03-25 15:35:47 +09:00
Hajime Hoshi
488bce7e36 internal/graphicsdriver/directx: remove unnecessary comments 2023-03-25 13:53:00 +09:00
Hajime Hoshi
c1e83432c0 internal/graphicsdriver/directx: refactoring: split api_windows.go 2023-03-25 12:07:04 +09:00
Hajime Hoshi
4ec27262ed internal/graphicsdriver/directx: refactoring 2023-03-25 01:34:29 +09:00
Hajime Hoshi
c7ca9cb321 ebiten: omit the exceeding part of vertices at Draw* 2023-03-23 21:23:33 +09:00
Hajime Hoshi
31273c875f internal/graphics: rename constants 2023-03-23 20:48:39 +09:00
Hajime Hoshi
ce9274a29d ebiten: remove the restriction for len(indices) at Draw*
Closes #2460
2023-03-23 20:01:15 +09:00
Hajime Hoshi
c7214ef6fb internal/ui: use MaxVertexCount instead of IndicesCount
Updates #2460
2023-03-23 19:44:00 +09:00
Hajime Hoshi
81581df2b9 internal/graphicscommand: reland: add graphics.MaxVertexFloatCount and use it instead of IndicesCount
This change is reland of 54e2790a06
but with a fix for WebGL. Also, this changes the logic when len(vertices)
exceeds the maximum: just remove the last part.

Updates #2460
2023-03-23 18:01:09 +09:00
Hajime Hoshi
c59bcbdb5b Revert "internal/graphicscommand: add graphics.MaxVertexFloatCount and use it instead of IndicesCount"
This reverts commit 54e2790a06.

Reason: test failures on browsers:

`GOOS=js GOARCH=wasm go test . -shuffle=1679547510163000000` failed
https://github.com/hajimehoshi/ebiten/actions/runs/4497182906/jobs/7912544699
2023-03-23 14:15:04 +09:00
Hajime Hoshi
54e2790a06 internal/graphicscommand: add graphics.MaxVertexFloatCount and use it instead of IndicesCount
Updates #2460
2023-03-23 13:49:05 +09:00
Hajime Hoshi
3f2ac129d2 internal/graphicscommand: refactoring: remove unnecessary restrictions for indices
Updates #2460
2023-03-23 13:28:11 +09:00
Hajime Hoshi
90723025cc internal/graphicsdriver/directx: reuse vertices/indices buffers whenever possible 2023-03-23 11:34:39 +09:00
Hajime Hoshi
e5525a04d5 internal/graphicsdriver/directx: refactoring: remove usages of graphics.IndicesCount
Updates #2460
2023-03-23 11:25:29 +09:00
Hajime Hoshi
a19ff07130 internal/graphicsdriver/opengl: bug fix: potential infinite loop 2023-03-23 02:47:23 +09:00
Hajime Hoshi
ad90ae3475 internal/graphicsdriver/directx: refactoring 2023-03-22 21:52:14 +09:00
Hajime Hoshi
034f9c2db8 internal/graphicsdriver/opengl: reland: refactoring: remove usages of graphics.IndicesCount
Updates #2460
2023-03-22 20:13:29 +09:00
Hajime Hoshi
61ee811579 internal/graphicsdriver: define Resetter 2023-03-22 18:35:46 +09:00
Hajime Hoshi
8cbf545e0f internal/graphicsdriver/opengl: revert commits for graphics.Indices
This change reverts these commits:

* 13d3a0487b
* 4cd98d512e

Reason: this caused crashes on Android.

Updates #2460
Closes #2610
2023-03-22 17:28:45 +09:00
Hajime Hoshi
13d3a0487b internal/graphicsdriver/opengl: refactoring: remove usages of graphics.IndicesCount
Updates #2460
2023-03-22 13:33:34 +09:00
Hajime Hoshi
4cd98d512e internal/graphicsdriver/opengl: refactoring 2023-03-21 23:06:49 +09:00
Hajime Hoshi
23e90b7e39 internal/graphicsdriver/opengl: refactoring 2023-03-20 22:48:20 +09:00
Hajime Hoshi
8ae6ea5ff6 internal/graphicsdriver/opengl: update comments 2023-03-20 01:42:54 +09:00
Hajime Hoshi
cbff3555db internal/graphicsdriver/opengl: drop WebGL 1 support
Closes #2191
2023-03-18 22:50:09 +09:00
Hajime Hoshi
22dfdfc418 internal/gamepad: bug fix: possible crash at iterating gamepads
Closes #2603
2023-03-17 11:40:24 +09:00
Hajime Hoshi
faca493fbc go generate 2023-03-15 03:18:28 +09:00
Hajime Hoshi
39aaf7fe37 ebiten: update comments
Updates #2601
2023-03-14 13:07:40 +09:00
Hajime Hoshi
1656c47abf internal/ui: bug fix: hiding a window decoration at initialization doesn't work on macOS
Closes #2600
2023-03-14 00:27:57 +09:00
Hajime Hoshi
3bcac70d1c internal/graphicsdriver/metal: add comments 2023-03-13 22:21:55 +09:00
Hajime Hoshi
e93bcd9e55 internal/ui: bug fix: needed to wait for swapping buffers before entering fullscreen
Closes #2599
2023-03-13 21:40:40 +09:00
Hajime Hoshi
65fb9d56ba internal/graphicsdriver/metal: refactoring
Updates #2599
2023-03-13 21:29:42 +09:00
divVerent
10c1b56e62
cmd/ebitenmobile: fix Xbox-ish gamepad axis assignment (#2596)
This commit mirrors https://github.com/libsdl-org/SDL/pull/7405
(6f1f586086).

Note that for SDL, this code is used a lot less than for Ebitengine, as SDL
mostly migrated to HIDAPI and direct USB device access rather than using
Android's APIs. For Bluetooth devices, however, the Java APIs are used the
same way.

This was the remaining problem to be solved to automatically support standard
layout on most standard gamepads (this should cover most Xbox-ish and PS-ish
gamepads on the market).

In particular this covers gamepads with the following assignment:

- Left stick = X/Y, right stick = Z/RZ, triggers = LEFTTRIGGER/RIGHTTRIGGER
  (which basically is what Android docs say and some PS gamepads do)

- Left stick = X/Y, right stick = RX/RY, triggers = Z/RZ
  (Xbox gamepad style, apparently)

- Left stick = X/Y, right stick = RX/RY, triggers = LEFTTRIGGER/RIGHTTRIGGER
  (Not sure if this exists, but it's conceivable)

As we found on the SDL pull request discussion, gamepads that offer flight
controls (e.g. THROTTLE and RUDDER) will likely not work well, before and
after this change.

Closes #2557
2023-03-12 22:32:30 +09:00
Hajime Hoshi
36e2d0ec40 internal/graphicsdriver/metal: bug fix: a path for CoreGraphics.framework didn't work
Closes #2595
2023-03-10 23:24:06 +09:00
Hajime Hoshi
84146510ce internal/restorable: refactoring 2023-03-10 22:29:59 +09:00
Hajime Hoshi
46173ffec6 internal/restorable: refactoring 2023-03-10 01:57:07 +09:00
Hajime Hoshi
8f2097d55e internal/restorable: reduce more duplicated regions 2023-03-09 23:17:02 +09:00
Hajime Hoshi
f3b49e6543 internal/restorable: reduce more duplicated regions 2023-03-09 22:57:57 +09:00
Hajime Hoshi
66db13ef74 internal/restorable: add tests 2023-03-09 21:54:41 +09:00
Hajime Hoshi
367606f274 internal/restorable: remove duplicated regions from i.staleRegions
Updates #2375
Updates #2581
2023-03-09 17:15:56 +09:00
Hajime Hoshi
22d74e78b2 internal/restorable: reduce allocations at readPixelsFromGPU
Updates #2375
2023-03-08 16:43:43 +09:00
Hajime Hoshi
da55397420 internal/restorable: remove empty regions at appendRegionsForDrawTriangles 2023-03-08 16:32:41 +09:00
Hajime Hoshi
f298b9541b internal/restorable: use a cache for pixels at readPixelsFromGPU
Updates #2375
2023-03-08 16:27:38 +09:00
Hajime Hoshi
7f182e7814 internal/restorable: skip basePixels.Clear when the region is empty 2023-03-08 16:21:45 +09:00
Hajime Hoshi
e4fffaf963 internal/restorable: reduce allocations
Updates #2375
2023-03-08 16:07:41 +09:00
Hajime Hoshi
7f3cff5e7c internal/restorable: revive pixelsForRestore
pixelsForRestore was removed at 09e0320309
as the regions for restoring were minimized. However, this caused a
regression and increased allocations on Android.

This fix revives pixelsForRestore, but as a map with region keys and
byte slice values. pixelsForRestore no longer represents a byte slice
for an entire image.

Updates #2375
2023-03-08 14:52:44 +09:00
divVerent
06c141475c
internal/gamepad: native standard layout for Linux (#2587)
Implements native standard layout for Linux gamepads by using the kernel-provided button IDs, thereby expanding
support to gamepads not listed in gamecontrollerdb.txt.

Linux's docs: https://www.kernel.org/doc/Documentation/input/gamepad.txt
SDL2's source: https://fossies.org/linux/SDL2/src/joystick/linux/SDL_sysjoystick.c#l_1740

Note that I am NOT 100% convinced about the X/Y swap between Xbox and PlayStation controllers - the Xbox
compatible pad I have however does have BTN_NORTH and BTN_WEST swapped (and thus BTN_X and BTN_Y
assigned right), which confirms SDL's logic and opposes the kernel docs.

Tested with this gamepad: "20d6:2802 BDA Xbox ONE Core controller", label says "PowerA Model 1508491-02" - even
after clearing out gamecontrollerdb.txt, examples/gamepad shows a 100% correct mapping.

Closes #2052
2023-03-04 01:47:24 +09:00
Hajime Hoshi
6ccdc6382c internal/graphicsdriver/metal/mtl: bug fix: fix a vet error 2023-03-04 01:37:45 +09:00
Hajime Hoshi
36bd3329b3 internal/graphicsdriver/metal: bug fix: compile error 2023-03-04 01:25:43 +09:00
Hajime Hoshi
7998e4d31d update purego to v0.3.0-alpha
There are breaking changes between purego v0.2.0 and v0.3.0-alpha.
2023-03-04 01:22:54 +09:00
divVerent
809ad991c2
internal/gamepad: refactor standard layout support to allow remapping in the per-platform implementations. (#2588)
Refactors native standard layout so standard axes and buttons can be implemented using any of axes, buttons or hats.

This is required to be able to implement a native standard layout mapping for Linux, as e.g. shoulder buttons can be
backed either by an analog or digital input.

Precedes #2587

Updates #2052
2023-03-03 23:29:04 +09:00
Hajime Hoshi
051b0c7238 internal/ui: bug fix: a big-offscreen size could be 0
Closes #2589
2023-03-03 22:34:43 +09:00
Hajime Hoshi
b278e5521f internal/gamepad: rename variables 2023-03-03 21:17:47 +09:00
Hajime Hoshi
27538135a7 internal/atlas: improve tests
This change fixes the test to reflect the fix for #2586.

Updates #2586
2023-03-02 20:16:26 +09:00
Hajime Hoshi
1c09ec5e44 internal/atlas: bug fix: too aggressive counting up destinationCount
Closes #2586
2023-03-02 18:58:29 +09:00
Hajime Hoshi
7c10e48afd internal/atlas: add an assertion
Updates #2586
2023-03-02 18:24:22 +09:00
Hajime Hoshi
e5bb89aa35 internal/restorable: use a special shader to clear an image
This reduces one extra internal texture.
2023-03-01 15:47:03 +09:00
Hajime Hoshi
7c0fbce0cf internal/atlas: use texture atlases for rendering destinations
Before this change, texture atlases are created only for rendreing
sources.

This change enables to use texture atlases even for rendering
destinations, so that the number of textures will be drastically
reduced.

Closes #2581
2023-03-01 02:47:01 +09:00
Hajime Hoshi
8f3974eeba internal/restorable: add TestDrawTrianglesAndExtend 2023-02-28 09:06:41 -08:00
Hajime Hoshi
42aa5fa604 internal/restorable: bug fix: an extended image has a wrong state (especially with OpenGL ES) 2023-02-28 08:48:25 -08:00
Hajime Hoshi
a5a5de2f3f internal/graphicsdriver/directx: reduce memory usages for writing pixels
Updates #2294
Updates #2582
2023-03-01 00:11:34 +09:00
Hajime Hoshi
264f0bad42 internal/graphicsdriver/directx: reduce memory usages when reading pixels
Updates #2294
Updates #2582
2023-02-28 22:55:21 +09:00
Hajime Hoshi
707a44e367 internal/packing: fix the comment 2023-02-28 21:45:58 +09:00
Hajime Hoshi
6b957063d4 internal/packing: bug fix: node's links were not synced correctly
Closes #2584
2023-02-28 20:31:39 +09:00
Hajime Hoshi
5e4652c4f8 internal/atlas: bug fix: wrong size setting 2023-02-28 13:19:27 +09:00