Skip to content

Commit

Permalink
SDL support / Classy
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
lancelet committed Aug 30, 2021
1 parent ff57575 commit 29c6a7a
Show file tree
Hide file tree
Showing 31 changed files with 1,833 additions and 82 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,45 @@ on:

jobs:
cabal:
name: ${{ matrix.os }} / ghc ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.sys.os }} / ghc ${{ matrix.ghc }}
runs-on: ${{ matrix.sys.os }}
strategy:
matrix:
os: [macOS-latest, ubuntu-latest, windows-latest]
sys:
- { os: macOS-latest, shell: bash }
- { os: ubuntu-latest, shell: bash }
- { os: windows-latest, shell: 'msys2 {0}' }
cabal: ["3.2"]
ghc:
- "8.10.5"

defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: actions/checkout@v2

- uses: msys2/setup-msys2@v2
if: ${{ matrix.sys.os == 'windows-latest' }}
with:
path-type: inherit

- name: Install macOS Dependencies
if: ${{ matrix.sys.os == 'macOS-latest' }}
run: |
brew install sdl2
- name: Install Ubuntu Dependencies
if: ${{ matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.sys.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install libglfw3-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev -y
sudo apt-get install libglfw3-dev libsdl2-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev -y
- name: Install Windows Dependencies
if: ${{ matrix.sys.os == 'windows-latest' }}
run: |
pacman --noconfirm -S mingw-w64-x86_64-pkg-config mingw-w64-x86_64-SDL2
- uses: haskell/actions/setup@v1
id: setup-haskell-cabal
Expand Down
10 changes: 10 additions & 0 deletions GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ of macOS Big Sur (11.5.2) on 2021-08-21.
after being prompted to install the XCode command line tools. Instructions
will be displayed in the terminal. You may need to use `ghcup tui` to
select an appropriate GHC version (GHC 8.10.5).

1. Install the [Homebrew](https://brew.sh/) package manager.

1. Install SDL2 via Homebrew. In a terminal:

```sh
brew install sdl2
```

### Build and Run an Example

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

### Build and Run an Example

Expand Down Expand Up @@ -142,6 +151,7 @@ These instructions were tested manually in a fresh installation of Ubuntu Linux
libncurses5 \
libtinfo5 \
libglfw3-dev \
libsdl2-dev \
libxi-dev \
libxxf86vm-dev \
libxcursor-dev \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
This repository contains Haskell bindings for
[wgpu-native](https://github.com/gfx-rs/wgpu-native).

macOS, Windows and Linux are supported.
macOS, Windows and Linux are supported. SDL2 and GLFW are both supported as
windowing systems.

To get started, please read the [Getting Started](GettingStarted.md)
instructions.
6 changes: 5 additions & 1 deletion wgpu-hs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Revision history for wgpu-hs

## x.x.x.x -- xxxx-xx-xx
## 0.3.0.0 -- 2021-08-30

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

## 0.2.0.1 -- 2021-08-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import qualified Graphics.UI.GLFW as GLFW
import System.Exit (exitFailure)
import WGPU (SwapChain)
import qualified WGPU
import qualified WGPU.GLFW.Surface

main :: IO ()
main = do
TextIO.putStrLn "Triangle Example"
TextIO.putStrLn "GLFW Triangle Example"

-- start GLFW
initResult <- GLFW.init
Expand All @@ -40,7 +41,7 @@ main = do
-- create the GLFW window without a "client API"
GLFW.windowHint (GLFW.WindowHint'ClientAPI GLFW.ClientAPI'NoAPI)
window <- do
mWin <- GLFW.createWindow 640 480 "Triangle" Nothing Nothing
mWin <- GLFW.createWindow 640 480 "GLFW Triangle Example" Nothing Nothing
case mWin of
Just w -> pure w
Nothing -> do
Expand Down Expand Up @@ -137,7 +138,7 @@ data Resources = Resources
getResources :: WGPU.Instance -> GLFW.Window -> IO (Either Error Resources)
getResources inst window = runExceptT $ do
-- fetch a surface for the window
surface <- lift $ WGPU.createGLFWSurface inst window
surface <- lift $ WGPU.GLFW.Surface.createSurface inst window
-- fetch an adapter for the surface
adapter <-
maybeToExceptT
Expand Down Expand Up @@ -184,6 +185,7 @@ updateSwapChain device surface window textureFormat swapChainMVar = do
putMVar swapChainMVar (curSz, swapChain)
pure swapChain
(Just swapChain, False) -> pure swapChain
_ -> error "should not reach this case"

draw ::
WGPU.Device ->
Expand Down
Loading

0 comments on commit 29c6a7a

Please sign in to comment.