Created
March 23, 2012 17:07
-
-
Save acowley/2172819 to your computer and use it in GitHub Desktop.
Example of setting up OpenCL to use an OpenGL context. Uses the CLUtil library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface #-} | |
module Renderer.CLGLInterop (initFromGL) where | |
import Control.Parallel.CLUtil | |
import Foreign.Ptr (nullPtr, Ptr) | |
foreign import ccall "CGLGetCurrentContext" | |
cGLGetCurrentContext :: IO (Ptr ()) | |
foreign import ccall "CGLGetShareGroup" | |
cGLGetShareGroup :: Ptr () -> IO (Ptr ()) | |
initFromGL :: CLDeviceType -> IO OpenCLState | |
initFromGL devType = | |
do (dev:_) <- clGetDeviceIDs nullPtr devType | |
shareGroup <- cGLGetCurrentContext >>= cGLGetShareGroup | |
context <- clCreateContext [CL_CGL_SHAREGROUP_KHR shareGroup] | |
[dev] | |
putStrLn | |
q <- clCreateCommandQueue context dev [] | |
return $ OpenCLState dev context q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment