1 // DerelictCL - a Derelict based dynamic binding for OpenCL 2 // written in the D programming language 3 // 4 // Copyright: MeinMein 2013-2014. 5 // License: Boost License 1.0 6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 // Authors: Gerbrand Kamphuis (meinmein.com), 9 // Marvin Meeng (meinmein.com). 10 module derelict.opencl.cl_gl; 11 12 import derelict.opencl.loader; 13 import derelict.opencl.types; 14 15 extern (System) 16 { 17 // OpenCL 1.0 18 alias nothrow cl_mem function(cl_context, cl_mem_flags, cl_GLuint, int*) da_clCreateFromGLBuffer; 19 alias nothrow cl_mem function(cl_context, cl_mem_flags, cl_GLuint, cl_int*) da_clCreateFromGLRenderbuffer; 20 alias nothrow cl_int function(cl_mem, cl_gl_object_type*, cl_GLuint*) da_clGetGLObjectInfo; 21 alias nothrow cl_int function(cl_mem, cl_gl_texture_info, size_t, void*, size_t*) da_clGetGLTextureInfo; 22 alias nothrow cl_int function(cl_command_queue, cl_uint, const(cl_mem*), cl_uint, const(cl_event*), cl_event*) da_clEnqueueAcquireGLObjects; 23 alias nothrow cl_int function(cl_command_queue, cl_uint, const(cl_mem*), cl_uint, const(cl_event*), cl_event*) da_clEnqueueReleaseGLObjects; 24 alias nothrow cl_int function(const(cl_context_properties*), cl_gl_context_info, size_t, void*, size_t*) da_clGetGLContextInfoKHR; 25 // OpenCL 1.1 Deprecated in 1.2 26 alias nothrow cl_mem function(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*) da_clCreateFromGLTexture2D; 27 alias nothrow cl_mem function(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*) da_clCreateFromGLTexture3D; 28 // OpenCL 1.2 29 alias nothrow cl_mem function(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*) da_clCreateFromGLTexture; 30 } 31 32 __gshared 33 { 34 // OpenCL 1.0 35 da_clCreateFromGLBuffer clCreateFromGLBuffer; 36 da_clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer; 37 da_clGetGLObjectInfo clGetGLObjectInfo; 38 da_clGetGLTextureInfo clGetGLTextureInfo; 39 da_clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects; 40 da_clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects; 41 da_clGetGLContextInfoKHR clGetGLContextInfoKHR; 42 // OpenCL 1.1 Deprecated in 1.2 43 da_clCreateFromGLTexture2D clCreateFromGLTexture2D; 44 da_clCreateFromGLTexture3D clCreateFromGLTexture3D; 45 // OpenCL 1.2 46 da_clCreateFromGLTexture clCreateFromGLTexture; 47 } 48 49 package 50 { 51 void loadSymbols(void delegate(void**, string, bool doThrow) bindFunc) 52 { 53 // OpenCL 1.0 54 bindFunc(cast(void**)&clCreateFromGLBuffer, "clCreateFromGLBuffer", true); 55 bindFunc(cast(void**)&clCreateFromGLRenderbuffer, "clCreateFromGLRenderbuffer", true); 56 bindFunc(cast(void**)&clGetGLObjectInfo, "clGetGLObjectInfo", true); 57 bindFunc(cast(void**)&clGetGLTextureInfo, "clGetGLTextureInfo", true); 58 bindFunc(cast(void**)&clEnqueueAcquireGLObjects, "clEnqueueAcquireGLObjects", true); 59 bindFunc(cast(void**)&clEnqueueReleaseGLObjects, "clEnqueueReleaseGLObjects", true); 60 } 61 62 CLVersion reload(void delegate(void**, string, bool doThrow) bindFunc, CLVersion clVer) 63 { 64 if(clVer <= CLVersion.CL11) 65 { 66 // OpenCL 1.1 Deprecated in 1.2 67 bindFunc(cast(void**)&clCreateFromGLTexture2D, "clCreateFromGLTexture2D", true); 68 bindFunc(cast(void**)&clCreateFromGLTexture3D, "clCreateFromGLTexture3D", true); 69 } 70 71 if(clVer >= CLVersion.CL12) 72 { 73 // OpenCL 1.2 74 bindFunc(cast(void**)&clCreateFromGLTexture, "clCreateFromGLTexture", true); 75 } 76 77 return clVer; 78 } 79 80 private __gshared bool _EXT_cl_khr_gl_sharing; 81 public bool EXT_cl_khr_gl_sharing() @property { return _EXT_cl_khr_gl_sharing; } 82 private void load_cl_khr_gl_sharing(CLVersion clVer, cl_platform_id platform) 83 { 84 try 85 { 86 loadExtensionFunction(cast(void**)&clGetGLContextInfoKHR, "clGetGLContextInfoKHR", clVer, platform); 87 88 _EXT_cl_khr_gl_sharing = clGetGLContextInfoKHR !is null; 89 } 90 catch(Exception e) 91 { 92 _EXT_cl_khr_gl_sharing = false; 93 } 94 } 95 96 void loadEXT(CLVersion clVer, cl_platform_id platform) 97 { 98 if(clVer >= CLVersion.CL10) 99 { 100 // OpenCL 1.0 101 load_cl_khr_gl_sharing(clVer, platform); 102 } 103 } 104 }