Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstracting the library over monad transformers #1

Closed
abbradar opened this issue Nov 30, 2014 · 17 comments
Closed

Abstracting the library over monad transformers #1

abbradar opened this issue Nov 30, 2014 · 17 comments

Comments

@abbradar
Copy link
Collaborator

What do you think of abstracting most of the library over MonadIO? This would make life easier for people using monad transformers (like me), but it can introduce overhead (it can be mitigated for plain IO users with SPECIALIZE, though, to have no regressions). Exceptions shouldn't be an issue internally because you don't use transformers in the library (no MonadBaseControl stuff). I can try to make necessary changes if there is an interest, but I'd like to hear opinions first.
Another thing of interest may be to convert Draw into a monad transformer.

@abbradar
Copy link
Collaborator Author

Related thing would be haskell-game/sdl2@5991a6b , though I use my own SDL bindings (incomplete and not on Hackage).

@Noeda
Copy link
Owner

Noeda commented Nov 30, 2014

I have no objection to abstracting everything to MonadIO. It's just something I wasn't thinking when I started with the library. If you do the work, I'll merge it. And I probably would do it myself at some point. I'm not really worried about performance with MonadIO in particular; there is already quite a bit of overhead in many places in caramia. I want to encourage the user to make GPU do a lot of the heavy lifting so that I wouldn't have to do micro-optimization.

I think the Draw monad might need some rethinking anyway. It's probably the place where most applications spend their time and could use being fast. Before going into any serious optimization efforts, I would want to have some benchmarks to measure with.

@abbradar
Copy link
Collaborator Author

Okay, then one little thing -- what codestyle do you prefer:

foo :: MonadIO m => a
    -> b
    -> m c

or

foo :: MonadIO m
    => a
    -> b
    -> m c

I can't figure this out from existing code.

@Noeda
Copy link
Owner

Noeda commented Nov 30, 2014

I think I prefer

foo :: MonadIO m
    => a
    -> b
    -> c

Although I don't usually concern myself with such trifling matters =)
Caramia has existed long enough that my preferred style has had changes so things may be inconsistent in places.

@abbradar
Copy link
Collaborator Author

Another question! Particularly, withMapping2 uses mask -- I'd still have to use MonadBaseControl 1 and lifted-base 2. I have several options:

  1. Abstract the whole library over MonadBase and MonadBaseControl. I've chosen this approach for my library.
  2. Abstract it over MonadIO, and use MonadBaseControl only when needed -- less consistency but MonadIO is more popular.
  3. Just skip it for now.
  4. Maybe there is other library which provides monad-control-like functionality and I've been overlooking it?

@Noeda
Copy link
Owner

Noeda commented Nov 30, 2014

Right now I'm not comfortable with MonadBaseControl and friends. If it's just for exceptions, I think you could check the exceptions package. Otherwise I'd like the option 3) for the moment.

@abbradar
Copy link
Collaborator Author

Aha! That would be option 4) really -- I've been ignorant of this package all this time! Great, I'll use it.

@abbradar
Copy link
Collaborator Author

https://github.com/Noeda/caramia/blob/master/src/Graphics/Caramia/Context.hs#L132
When can this be expected? Also, does glGetString gl_VERSION work on Mac OS X? I wanted to unify this with my version checking in FlextGL.

@Noeda
Copy link
Owner

Noeda commented Dec 1, 2014

I don't think I've tried glGetString gl_VERSION on OS X (but I'd assume it works). I know the method in that piece of code does not work on OS X which is why it's #ifdefd away. OpenGL on OS X is different from other implementations in that core profile really cannot use any legacy functionality which may be related to why it doesn't work.

The comment refers to a situation where a completely broken OpenGL is being used and functions may be no-ops or something. I'm not sure if it actually happens anywhere.

@abbradar
Copy link
Collaborator Author

abbradar commented Dec 1, 2014

Things become more and more cryptic for me. I've added small executables to show GL version using both my SDL library and sdl2 (1 and 2) . Here's what I'm getting:

[nix-shell:~/sdlcube/cube]$ cabal run glinfo
Preprocessing executable 'glinfo' for cube-0.1.0.0...
glGetIntegerv gl_*_VERSION: 3.3
glGetString gl_VERSION: 3.3 (Core Profile) Mesa 10.2.6

[nix-shell:~/sdlcube/cube]$ cd ../caramia/

[nix-shell:~/sdlcube/caramia]$ cabal run gl-info
Preprocessing executable 'gl-info' for caramia-0.4.0.0...
glGetIntegerv gl_*_VERSION: 3.3
glGetString gl_VERSION: 3.0 Mesa 10.2.6

[nix-shell:~/sdlcube/caramia]$ glxinfo | grep "OpenGL version"
OpenGL version string: 3.0 Mesa 10.2.6

Any ideas what's going on? I'm using llvmpipe on Linux (export LIBGL_ALWAYS_SOFTWARE=1).

Upd: These don't use caramia at all, but I was getting same strings while adding parseVersion to flextGL earlier -- I've tested it with my library.

@Noeda
Copy link
Owner

Noeda commented Dec 1, 2014

Something I did notice that the second program (and my toys) don't initialize the SDL2 library. Try fixing them and trying again?

@abbradar
Copy link
Collaborator Author

abbradar commented Dec 1, 2014

Yes, that works now. I'll ask someone with a Mac to run this tool to find a consistent version detecting way. Also, I've found how can I get zeros from MINOR/MAJOR:

[nix-shell:~/sdlcube/caramia]$ cabal run gl-info
Preprocessing executable 'gl-info' for caramia-0.4.0.0...
glGetIntegerv gl_*_VERSION: 0.0
glGetString gl_VERSION: 2.1 Mesa 10.2.6

This is on an old integrated Intel card (I'm using llvmpipe for a reason :3) and sdl2 -- it fails on glSetAttribute actually, but I haven't bothered to check them.

@Noeda
Copy link
Owner

Noeda commented Dec 1, 2014

I have access to an OS X and can do some testing later today if you don't have immediate access. I also have an intel and nVidia drivers to test with but I don't have immediate access to any AMD cards.

@abbradar
Copy link
Collaborator Author

abbradar commented Dec 1, 2014

Oh, good then -- I wanted to make One Right getGLVersion, please do. Sadly, no AMD either.

@abbradar
Copy link
Collaborator Author

abbradar commented Dec 1, 2014

A more error-aware version: abbradar@3c2dcb0 (I can make a PR if you want)

@Noeda
Copy link
Owner

Noeda commented Dec 1, 2014

Linux, NVIDIA 343.22:
glGetIntegerv gl_*_VERSION: 3.3
glGetString gl_VERSION: 3.3.0 NVIDIA 343.22

Linux, Mesa (using intel driver):
glGetIntegerv gl_*_VERSION: 3.3
glGetString gl_VERSION: 3.3 (Core Profile) Mesa 10.3.4

OS X (NVIDIA, Mavericks)
glGetIntegerv gl_*_VERSION: 4.4
glGetString gl_VERSION: 4.1 NVIDIA-8.26.28 310.40.55b01

OS X (intel, Mavericks)
glGetIntegerv gl_*_VERSION: 4.4
glGetString gl_VERSION: 4.1 INTEL-8.28.32

It seems that glGetIntegerv actually does work on OS X (maybe my faulty toys that didn't initialize sdl2 led me astray). OS X doesn't have OpenGL 4.4 (it has 4.1). gl-info has a bug that it calls glGetIntegerv on gl_MAJOR only (I only noticed this just now that I'm writing this, it originates from my code). I think we can go with glGetIntegerv approach.

@Noeda
Copy link
Owner

Noeda commented Dec 1, 2014

Closing this issue since we went for the MonadIO abstraction, let's keep issues organized.

@Noeda Noeda closed this as completed Dec 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants