Skip to content

Instantly share code, notes, and snippets.

@acowley
Created March 23, 2012 17:07
Show Gist options
  • Save acowley/2172819 to your computer and use it in GitHub Desktop.
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.
{-# 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