start getting rid of GLUtil
This commit is contained in:
parent
d73c854999
commit
4b37d5f51c
5 changed files with 113 additions and 185 deletions
|
@ -8,7 +8,6 @@ import qualified SDL
|
||||||
|
|
||||||
import qualified Graphics.Rendering.OpenGL as GL
|
import qualified Graphics.Rendering.OpenGL as GL
|
||||||
import qualified Graphics.GL as GLRaw
|
import qualified Graphics.GL as GLRaw
|
||||||
import qualified Graphics.GLUtil as GLU
|
|
||||||
|
|
||||||
import Codec.Picture
|
import Codec.Picture
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import SDL (($=))
|
||||||
|
|
||||||
import qualified Graphics.Rendering.OpenGL as GL
|
import qualified Graphics.Rendering.OpenGL as GL
|
||||||
import qualified Graphics.GL.Functions as GLRaw (glVertexAttribDivisor)
|
import qualified Graphics.GL.Functions as GLRaw (glVertexAttribDivisor)
|
||||||
import qualified Graphics.GLUtil as GLU
|
-- import qualified Graphics.GLUtil as GLU
|
||||||
|
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
|
@ -101,10 +101,50 @@ rawVertices =
|
||||||
]
|
]
|
||||||
|
|
||||||
initSpriteShaderObjects = do
|
initSpriteShaderObjects = do
|
||||||
|
-- vertexShaderSrc <- BS.readFile "shader/vertex.sl"
|
||||||
|
-- fragmentShaderSrc <- BS.readFile "shader/fragment.sl"
|
||||||
|
|
||||||
|
vertexShader <- createShader VertexShader
|
||||||
|
fragmentShader <- createShader FragmentShader
|
||||||
|
|
||||||
vertexShaderSrc <- BS.readFile "shader/vertex.sl"
|
vertexShaderSrc <- BS.readFile "shader/vertex.sl"
|
||||||
fragmentShaderSrc <- BS.readFile "shader/fragment.sl"
|
fragmentShaderSrc <- BS.readFile "shader/fragment.sl"
|
||||||
|
|
||||||
shaderProgram <- GLU.simpleShaderProgramBS vertexShaderSrc fragmentShaderSrc
|
shaderSourceBS vertexShader $= vertexShaderSrc
|
||||||
|
shaderSourceBS fragmentShader $= fragmentShaderSrc
|
||||||
|
|
||||||
|
compileShader vertexShader
|
||||||
|
get errors >>= mapM_ (hPutStrLn stderr . ("GL: "++) . show)
|
||||||
|
vOK <- get (compileStatus vertexShader)
|
||||||
|
infoLog <- get (shaderInfoLog vertexShader)
|
||||||
|
unless (null infoLog || infoLog == "\NUL")
|
||||||
|
(mapM_
|
||||||
|
putStrLn
|
||||||
|
["Shader info log for '" ++ filePath ++ "':", infoLog, ""]
|
||||||
|
)
|
||||||
|
unless vOK $ do
|
||||||
|
deleteObjectName vertexShader
|
||||||
|
ioError (userError "vertexShader compilation failed")
|
||||||
|
compileShader fragmentShader
|
||||||
|
get errors >>= mapM_ (hPutStrLn stderr . ("GL: "++) . show)
|
||||||
|
fOK <- get (compileStatus fragmentShader)
|
||||||
|
infoLog <- get (shaderInfoLog fragmentShader)
|
||||||
|
unless (null infoLog || infoLog == "\NUL")
|
||||||
|
(mapM_
|
||||||
|
putStrLn
|
||||||
|
["Shader info log for '" ++ filePath ++ "':", infoLog, ""]
|
||||||
|
)
|
||||||
|
unless fOK $ do
|
||||||
|
deleteObjectName fragmentShader
|
||||||
|
ioError (userError "fragmentShader compilation failed")
|
||||||
|
|
||||||
|
-- shaderProgram <- GLU.simpleShaderProgramBS vertexShaderSrc fragmentShaderSrc
|
||||||
|
|
||||||
|
shaderProgram <- createProgram
|
||||||
|
attachShaders shaderProgram $= [vertexShader, fragmentShader]
|
||||||
|
linkProgram shaderProgram
|
||||||
|
get errors >>= mapM_ (hPutStrLn stderr . ("GL: "++) . show)
|
||||||
|
|
||||||
|
|
||||||
return (SpriteShaderObjects shaderProgram)
|
return (SpriteShaderObjects shaderProgram)
|
||||||
|
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
{
|
|
||||||
"affection": {
|
|
||||||
"branch": "master",
|
|
||||||
"description": "A simple Game Engine in Haskell using SDL",
|
|
||||||
"homepage": "",
|
|
||||||
"owner": "nek0",
|
|
||||||
"repo": "affection",
|
|
||||||
"rev": "18775515d8d569c36148c02a134e1f538981b1ff",
|
|
||||||
"sha256": "09bxf917mj1lanc0d5f7xj3n22dk8drzgqivqpnvskdx88pmrv4k",
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/nek0/affection/archive/18775515d8d569c36148c02a134e1f538981b1ff.tar.gz",
|
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
|
||||||
},
|
|
||||||
"ghc": {
|
|
||||||
"sha256": "1pqlx6rdjs2110g0y1i9f8x18lmdizibjqd15f5xahcz39hgaxdw",
|
|
||||||
"type": "file",
|
|
||||||
"url": "https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-deb9-linux.tar.xz",
|
|
||||||
"url_template": "https://downloads.haskell.org/~ghc/<version>/ghc-<version>-x86_64-deb9-linux.tar.xz",
|
|
||||||
"version": "8.6.5"
|
|
||||||
},
|
|
||||||
"niv": {
|
|
||||||
"branch": "master",
|
|
||||||
"description": "Easy dependency management for Nix projects",
|
|
||||||
"homepage": "https://github.com/nmattia/niv",
|
|
||||||
"owner": "nmattia",
|
|
||||||
"repo": "niv",
|
|
||||||
"rev": "7a21f49027c0901456acd6e61d91bd9e3b15b1f6",
|
|
||||||
"sha256": "1hrcjgz4ib5n6wm96gcjk2qjl03pvspksk48b2lkn29vpdry98jm",
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/nmattia/niv/archive/7a21f49027c0901456acd6e61d91bd9e3b15b1f6.tar.gz",
|
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"branch": "nixos-19.09",
|
|
||||||
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
|
|
||||||
"homepage": "https://github.com/NixOS/nixpkgs",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs-channels",
|
|
||||||
"rev": "d3d2de8b99be56c5a6ed18f46e280f8103124dd7",
|
|
||||||
"sha256": "1chzbajrspw24csnv2c0h1h59pbp1k6939cllmd61382p9iw7rg8",
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/NixOS/nixpkgs-channels/archive/d3d2de8b99be56c5a6ed18f46e280f8103124dd7.tar.gz",
|
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
|
||||||
}
|
|
||||||
}
|
|
134
nix/sources.nix
134
nix/sources.nix
|
@ -1,134 +0,0 @@
|
||||||
# This file has been generated by Niv.
|
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
#
|
|
||||||
# The fetchers. fetch_<type> fetches specs of type <type>.
|
|
||||||
#
|
|
||||||
|
|
||||||
fetch_file = pkgs: spec:
|
|
||||||
if spec.builtin or true then
|
|
||||||
builtins_fetchurl { inherit (spec) url sha256; }
|
|
||||||
else
|
|
||||||
pkgs.fetchurl { inherit (spec) url sha256; };
|
|
||||||
|
|
||||||
fetch_tarball = pkgs: spec:
|
|
||||||
if spec.builtin or true then
|
|
||||||
builtins_fetchTarball { inherit (spec) url sha256; }
|
|
||||||
else
|
|
||||||
pkgs.fetchzip { inherit (spec) url sha256; };
|
|
||||||
|
|
||||||
fetch_git = spec:
|
|
||||||
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
|
|
||||||
|
|
||||||
fetch_builtin-tarball = spec:
|
|
||||||
builtins.trace
|
|
||||||
''
|
|
||||||
WARNING:
|
|
||||||
The niv type "builtin-tarball" will soon be deprecated. You should
|
|
||||||
instead use `builtin = true`.
|
|
||||||
|
|
||||||
$ niv modify <package> -a type=tarball -a builtin=true
|
|
||||||
''
|
|
||||||
builtins_fetchTarball { inherit (spec) url sha256; };
|
|
||||||
|
|
||||||
fetch_builtin-url = spec:
|
|
||||||
builtins.trace
|
|
||||||
''
|
|
||||||
WARNING:
|
|
||||||
The niv type "builtin-url" will soon be deprecated. You should
|
|
||||||
instead use `builtin = true`.
|
|
||||||
|
|
||||||
$ niv modify <package> -a type=file -a builtin=true
|
|
||||||
''
|
|
||||||
(builtins_fetchurl { inherit (spec) url sha256; });
|
|
||||||
|
|
||||||
#
|
|
||||||
# Various helpers
|
|
||||||
#
|
|
||||||
|
|
||||||
# The set of packages used when specs are fetched using non-builtins.
|
|
||||||
mkPkgs = sources:
|
|
||||||
let
|
|
||||||
sourcesNixpkgs =
|
|
||||||
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
|
|
||||||
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
|
||||||
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
|
||||||
in
|
|
||||||
if builtins.hasAttr "nixpkgs" sources
|
|
||||||
then sourcesNixpkgs
|
|
||||||
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
|
||||||
import <nixpkgs> {}
|
|
||||||
else
|
|
||||||
abort
|
|
||||||
''
|
|
||||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
|
||||||
add a package called "nixpkgs" to your sources.json.
|
|
||||||
'';
|
|
||||||
|
|
||||||
# The actual fetching function.
|
|
||||||
fetch = pkgs: name: spec:
|
|
||||||
|
|
||||||
if ! builtins.hasAttr "type" spec then
|
|
||||||
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
|
||||||
else if spec.type == "file" then fetch_file pkgs spec
|
|
||||||
else if spec.type == "tarball" then fetch_tarball pkgs spec
|
|
||||||
else if spec.type == "git" then fetch_git spec
|
|
||||||
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
|
|
||||||
else if spec.type == "builtin-url" then fetch_builtin-url spec
|
|
||||||
else
|
|
||||||
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
|
||||||
|
|
||||||
# Ports of functions for older nix versions
|
|
||||||
|
|
||||||
# a Nix version of mapAttrs if the built-in doesn't exist
|
|
||||||
mapAttrs = builtins.mapAttrs or (
|
|
||||||
f: set: with builtins;
|
|
||||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
|
||||||
);
|
|
||||||
|
|
||||||
# fetchTarball version that is compatible between all the versions of Nix
|
|
||||||
builtins_fetchTarball = { url, sha256 }@attrs:
|
|
||||||
let
|
|
||||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
|
||||||
in
|
|
||||||
if lessThan nixVersion "1.12" then
|
|
||||||
fetchTarball { inherit url; }
|
|
||||||
else
|
|
||||||
fetchTarball attrs;
|
|
||||||
|
|
||||||
# fetchurl version that is compatible between all the versions of Nix
|
|
||||||
builtins_fetchurl = { url, sha256 }@attrs:
|
|
||||||
let
|
|
||||||
inherit (builtins) lessThan nixVersion fetchurl;
|
|
||||||
in
|
|
||||||
if lessThan nixVersion "1.12" then
|
|
||||||
fetchurl { inherit url; }
|
|
||||||
else
|
|
||||||
fetchurl attrs;
|
|
||||||
|
|
||||||
# Create the final "sources" from the config
|
|
||||||
mkSources = config:
|
|
||||||
mapAttrs (
|
|
||||||
name: spec:
|
|
||||||
if builtins.hasAttr "outPath" spec
|
|
||||||
then abort
|
|
||||||
"The values in sources.json should not have an 'outPath' attribute"
|
|
||||||
else
|
|
||||||
spec // { outPath = fetch config.pkgs name spec; }
|
|
||||||
) config.sources;
|
|
||||||
|
|
||||||
# The "config" used by the fetchers
|
|
||||||
mkConfig =
|
|
||||||
{ sourcesFile ? ./sources.json
|
|
||||||
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
|
|
||||||
, pkgs ? mkPkgs sources
|
|
||||||
}: rec {
|
|
||||||
# The sources, i.e. the attribute set of spec name to spec
|
|
||||||
inherit sources;
|
|
||||||
|
|
||||||
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
|
||||||
inherit pkgs;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
|
74
shell.nix
74
shell.nix
|
@ -1,6 +1,74 @@
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
|
||||||
|
|
||||||
let
|
let
|
||||||
hsPkgs = import ./default.nix;
|
|
||||||
|
inherit (nixpkgs) pkgs;
|
||||||
|
|
||||||
|
affection = with haskellPackages; callPackage(
|
||||||
|
{ mkDerivation, base, bytestring, clock, containers, glib, linear
|
||||||
|
, monad-loops, monad-parallel, mtl, OpenGL, sdl2, stdenv, stm, text
|
||||||
|
, uuid, vector
|
||||||
|
}:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "affection";
|
||||||
|
version = "0.0.0.10";
|
||||||
|
src = ../affection;
|
||||||
|
isLibrary = true;
|
||||||
|
isExecutable = true;
|
||||||
|
libraryHaskellDepends = [
|
||||||
|
base bytestring clock containers glib linear monad-loops
|
||||||
|
monad-parallel mtl OpenGL sdl2 stm text uuid vector
|
||||||
|
];
|
||||||
|
homepage = "https://github.com/nek0/affection#readme";
|
||||||
|
description = "A simple Game Engine using SDL";
|
||||||
|
license = stdenv.lib.licenses.lgpl3;
|
||||||
|
doHaddock = false;
|
||||||
|
}) {};
|
||||||
|
|
||||||
|
GLUtil = with haskellPackages; callPackage(
|
||||||
|
{ mkDerivation, array, base, bytestring, containers, directory
|
||||||
|
, filepath, hpp, JuicyPixels, linear, OpenGL, OpenGLRaw, stdenv
|
||||||
|
, transformers, vector
|
||||||
|
}:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "GLUtil";
|
||||||
|
version = "0.10.3";
|
||||||
|
sha256 = "1933540d309209fb90f0632336ee6c54e160a12da8508dadaf16882a2358ec27";
|
||||||
|
libraryHaskellDepends = [
|
||||||
|
array base bytestring containers directory filepath hpp JuicyPixels
|
||||||
|
linear OpenGL OpenGLRaw transformers vector
|
||||||
|
];
|
||||||
|
libraryToolDepends = [ hpp ];
|
||||||
|
description = "Miscellaneous OpenGL utilities";
|
||||||
|
license = stdenv.lib.licenses.bsd3;
|
||||||
|
}) {};
|
||||||
|
|
||||||
|
f = { mkDerivation, base, bytestring, containers
|
||||||
|
, JuicyPixels, JuicyPixels-extra, linear, OpenGL, OpenGLRaw
|
||||||
|
, random, sdl2, stdenv, stm
|
||||||
|
}:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "canvas";
|
||||||
|
version = "0.0.0.0";
|
||||||
|
src = ./.;
|
||||||
|
isLibrary = false;
|
||||||
|
isExecutable = true;
|
||||||
|
executableHaskellDepends = [
|
||||||
|
affection base bytestring containers GLUtil JuicyPixels
|
||||||
|
JuicyPixels-extra linear OpenGL OpenGLRaw random sdl2 stm
|
||||||
|
];
|
||||||
|
description = "A test implementation for drawing images with SDL2 and OpenGL";
|
||||||
|
license = stdenv.lib.licenses.bsd3;
|
||||||
|
};
|
||||||
|
|
||||||
|
haskellPackages = if compiler == "default"
|
||||||
|
then pkgs.haskellPackages
|
||||||
|
else pkgs.haskell.packages.${compiler};
|
||||||
|
|
||||||
|
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
|
||||||
|
|
||||||
|
drv = variant (haskellPackages.callPackage f {});
|
||||||
|
|
||||||
in
|
in
|
||||||
hsPkgs.canvas.components.all
|
|
||||||
|
if pkgs.lib.inNixShell then drv.env else drv
|
||||||
|
|
Loading…
Reference in a new issue