Skip to content

Commit 29c6a7a

Browse files
committed
SDL support / Classy
- Add SDL surfaces. - Add `Classy` interface - supply parameters from `ReaderT`. - Add `BoneYard` package for helpful application skeleton code. - Switch to `MonadIO` where possible. - Supply bracketing functions for `withXXX`. - Add extra `{-# INLINABLE #-}` pragmas. - Add ability to query `Adapter` properties.
1 parent ff57575 commit 29c6a7a

31 files changed

+1833
-82
lines changed

.github/workflows/ci.yml

+27-5
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,45 @@ on:
88

99
jobs:
1010
cabal:
11-
name: ${{ matrix.os }} / ghc ${{ matrix.ghc }}
12-
runs-on: ${{ matrix.os }}
11+
name: ${{ matrix.sys.os }} / ghc ${{ matrix.ghc }}
12+
runs-on: ${{ matrix.sys.os }}
1313
strategy:
1414
matrix:
15-
os: [macOS-latest, ubuntu-latest, windows-latest]
15+
sys:
16+
- { os: macOS-latest, shell: bash }
17+
- { os: ubuntu-latest, shell: bash }
18+
- { os: windows-latest, shell: 'msys2 {0}' }
1619
cabal: ["3.2"]
1720
ghc:
1821
- "8.10.5"
1922

23+
defaults:
24+
run:
25+
shell: ${{ matrix.sys.shell }}
26+
2027
steps:
2128
- uses: actions/checkout@v2
2229

30+
- uses: msys2/setup-msys2@v2
31+
if: ${{ matrix.sys.os == 'windows-latest' }}
32+
with:
33+
path-type: inherit
34+
35+
- name: Install macOS Dependencies
36+
if: ${{ matrix.sys.os == 'macOS-latest' }}
37+
run: |
38+
brew install sdl2
39+
2340
- name: Install Ubuntu Dependencies
24-
if: ${{ matrix.os == 'ubuntu-latest' }}
41+
if: ${{ matrix.sys.os == 'ubuntu-latest' }}
2542
run: |
2643
sudo apt-get update
27-
sudo apt-get install libglfw3-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev -y
44+
sudo apt-get install libglfw3-dev libsdl2-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev -y
45+
46+
- name: Install Windows Dependencies
47+
if: ${{ matrix.sys.os == 'windows-latest' }}
48+
run: |
49+
pacman --noconfirm -S mingw-w64-x86_64-pkg-config mingw-w64-x86_64-SDL2
2850
2951
- uses: haskell/actions/setup@v1
3052
id: setup-haskell-cabal

GettingStarted.md

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ of macOS Big Sur (11.5.2) on 2021-08-21.
2121
after being prompted to install the XCode command line tools. Instructions
2222
will be displayed in the terminal. You may need to use `ghcup tui` to
2323
select an appropriate GHC version (GHC 8.10.5).
24+
25+
1. Install the [Homebrew](https://brew.sh/) package manager.
26+
27+
1. Install SDL2 via Homebrew. In a terminal:
28+
29+
```sh
30+
brew install sdl2
31+
```
2432

2533
### Build and Run an Example
2634

@@ -82,6 +90,7 @@ of Windows 10 on 2021-08-21.
8290
```powershell
8391
choco install git make llvm -y
8492
```
93+
1. (For SDL2 only.) Install SDL2 for development.
8594

8695
### Build and Run an Example
8796

@@ -142,6 +151,7 @@ These instructions were tested manually in a fresh installation of Ubuntu Linux
142151
libncurses5 \
143152
libtinfo5 \
144153
libglfw3-dev \
154+
libsdl2-dev \
145155
libxi-dev \
146156
libxxf86vm-dev \
147157
libxcursor-dev \

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
This repository contains Haskell bindings for
1717
[wgpu-native](https://github.com/gfx-rs/wgpu-native).
1818

19-
macOS, Windows and Linux are supported.
19+
macOS, Windows and Linux are supported. SDL2 and GLFW are both supported as
20+
windowing systems.
2021

2122
To get started, please read the [Getting Started](GettingStarted.md)
2223
instructions.

wgpu-hs/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Revision history for wgpu-hs
22

3-
## x.x.x.x -- xxxx-xx-xx
3+
## 0.3.0.0 -- 2021-08-30
44

5+
- Add Classy interface - supply parameters from `ReaderT`.
6+
- Add SDL surfaces.
7+
- Add `BoneYard` package for helpful application skeleton code.
58
- Switch to using `MonadIO` instead of plain `IO` when possible.
69
- Supply bracketing functions for `withXXX`.
710
- Add extra `{-# INLINABLE #-}` pragmas.
11+
- Add ability to query Adapter properties.
812

913
## 0.2.0.1 -- 2021-08-24
1014

wgpu-hs/examples/triangle/Main.hs renamed to wgpu-hs/examples/triangle-glfw/TriangleGLFW.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import qualified Graphics.UI.GLFW as GLFW
2626
import System.Exit (exitFailure)
2727
import WGPU (SwapChain)
2828
import qualified WGPU
29+
import qualified WGPU.GLFW.Surface
2930

3031
main :: IO ()
3132
main = do
32-
TextIO.putStrLn "Triangle Example"
33+
TextIO.putStrLn "GLFW Triangle Example"
3334

3435
-- start GLFW
3536
initResult <- GLFW.init
@@ -40,7 +41,7 @@ main = do
4041
-- create the GLFW window without a "client API"
4142
GLFW.windowHint (GLFW.WindowHint'ClientAPI GLFW.ClientAPI'NoAPI)
4243
window <- do
43-
mWin <- GLFW.createWindow 640 480 "Triangle" Nothing Nothing
44+
mWin <- GLFW.createWindow 640 480 "GLFW Triangle Example" Nothing Nothing
4445
case mWin of
4546
Just w -> pure w
4647
Nothing -> do
@@ -137,7 +138,7 @@ data Resources = Resources
137138
getResources :: WGPU.Instance -> GLFW.Window -> IO (Either Error Resources)
138139
getResources inst window = runExceptT $ do
139140
-- fetch a surface for the window
140-
surface <- lift $ WGPU.createGLFWSurface inst window
141+
surface <- lift $ WGPU.GLFW.Surface.createSurface inst window
141142
-- fetch an adapter for the surface
142143
adapter <-
143144
maybeToExceptT
@@ -184,6 +185,7 @@ updateSwapChain device surface window textureFormat swapChainMVar = do
184185
putMVar swapChainMVar (curSz, swapChain)
185186
pure swapChain
186187
(Just swapChain, False) -> pure swapChain
188+
_ -> error "should not reach this case"
187189

188190
draw ::
189191
WGPU.Device ->

0 commit comments

Comments
 (0)