Java Code Examples for org.lwjgl.PointerBuffer#flip()

The following examples show how to use org.lwjgl.PointerBuffer#flip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 6 votes vote down vote up
/**
 * Opens a file open dialog.
 * 
 * @param title window title
 * @param defaultPath default file path
 * @param filterDescription description of the accepted file extension(s)
 * @param acceptedFileExtension the first accepted file extension (example: "txt", use * for all)
 * @param additionalAcceptedFileExtensions any additional accepted file extensions
 * 
 * @return the selected file
 */
public static File showOpenFileDialog(String title, File defaultPath, String filterDescription, String acceptedFileExtension, String... additionalAcceptedFileExtensions){

	MemoryStack stack = MemoryStack.stackPush();

	PointerBuffer filters = stack.mallocPointer(1 + additionalAcceptedFileExtensions.length);

       filters.put(stack.UTF8("*." + acceptedFileExtension));
       for(int i = 0; i < additionalAcceptedFileExtensions.length; i++){
		filters.put(stack.UTF8("*." + additionalAcceptedFileExtensions[i]));
       }

       filters.flip();

       defaultPath = defaultPath.getAbsoluteFile();
       String defaultString = defaultPath.getAbsolutePath();
       if(defaultPath.isDirectory() && !defaultString.endsWith(File.separator)){
       	defaultString += File.separator;
       }
       
       String result = TinyFileDialogs.tinyfd_openFileDialog(title, defaultString, filters, filterDescription, false);

	stack.pop();

	return result != null ? new File(result) : null; 
}
 
Example 2
Source File: VkUtil.java    From oreon-engine with GNU General Public License v3.0 6 votes vote down vote up
public static PointerBuffer createPointerBuffer(Collection<CommandBuffer> commandBuffers){
  	
  	if (commandBuffers.size() == 0){
  		log.info("createPointerBuffer: commandBuffers empty");
  		return null;
  	}
  	
  	PointerBuffer cmdBuffersPointer = memAllocPointer(commandBuffers.size());

for (CommandBuffer cmdBuffer : commandBuffers){
	cmdBuffersPointer.put(cmdBuffer.getHandlePointer());
}

cmdBuffersPointer.flip();

return cmdBuffersPointer;
  }
 
Example 3
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void build(String args, Device... devices) throws KernelCompilationException {
    PointerBuffer deviceList = null;
    if (devices != null) {
        deviceList = PointerBuffer.allocateDirect(devices.length);
        deviceList.rewind();
        for (Device d : devices) {
            deviceList.put(((LwjglDevice) d).device.getPointer());
        }
        deviceList.flip();
    }
    int ret = CL10.clBuildProgram(program, deviceList, args, null);
    if (ret != CL10.CL_SUCCESS) {
        String log = Log();
        LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log);
        if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) {
            throw new KernelCompilationException("Failed to build program", ret, log);
        } else {
            Utils.checkError(ret, "clBuildProgram");
        }
    } else {
        LOG.log(Level.INFO, "Program compiled:\n{0}", Log());
    }
}
 
Example 4
Source File: LwjglProgram.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void build(String args, Device... devices) throws KernelCompilationException {
    PointerBuffer deviceList = null;
    if (devices != null) {
        deviceList = PointerBuffer.allocateDirect(devices.length);
        deviceList.rewind();
        for (Device d : devices) {
            deviceList.put(((LwjglDevice) d).getDevice());
        }
        deviceList.flip();
    }
    int ret = CL10.clBuildProgram(program, deviceList, args, null, 0);
    if (ret != CL10.CL_SUCCESS) {
        String log = Log();
        LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log);
        if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) {
            throw new KernelCompilationException("Failed to build program", ret, log);
        } else {
            Utils.checkError(ret, "clBuildProgram");
        }
    } else {
        LOG.log(Level.INFO, "Program compiled:\n{0}", Log());
    }
}
 
Example 5
Source File: SimpleDemo.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("AWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example 6
Source File: DesktopLauncher.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public File openDialog(String title, String defaultPath,
        String[] filterPatterns, String filterDescription) {
    String result = null;
    
    //fix file path characters
    if (Utils.isWindows()) {
        defaultPath = defaultPath.replace("/", "\\");
    } else {
        defaultPath = defaultPath.replace("\\", "/");
    }
    
    if (filterPatterns != null && filterPatterns.length > 0) {
        try (MemoryStack stack = stackPush()) {
            PointerBuffer pointerBuffer = stack.mallocPointer(filterPatterns.length);

            for (String filterPattern : filterPatterns) {
                pointerBuffer.put(stack.UTF8(filterPattern));
            }
            
            pointerBuffer.flip();
            result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, pointerBuffer, filterDescription, false);
        }
    } else {
        result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, null, filterDescription, false);
    }
    
    if (result != null) {
        return new File(result);
    } else {
        return null;
    }
}
 
Example 7
Source File: DesktopLauncher.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public File saveDialog(String title, String defaultPath,
        String[] filterPatterns, String filterDescription) {
    String result = null;
    
    //fix file path characters
    if (Utils.isWindows()) {
        defaultPath = defaultPath.replace("/", "\\");
    } else {
        defaultPath = defaultPath.replace("\\", "/");
    }
    
    if (filterPatterns != null && filterPatterns.length > 0) {
        try (var stack = stackPush()) {
            PointerBuffer pointerBuffer = null;
            pointerBuffer = stack.mallocPointer(filterPatterns.length);

            for (String filterPattern : filterPatterns) {
                pointerBuffer.put(stack.UTF8(filterPattern));
            }
            
            pointerBuffer.flip();
            result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_saveFileDialog(title, defaultPath, pointerBuffer, filterDescription);
        }
    } else {
        result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_saveFileDialog(title, defaultPath, null, filterDescription);
    }
    
    if (result != null) {
        return new File(result);
    } else {
        return null;
    }
}
 
Example 8
Source File: SimpleDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example 9
Source File: PhysicalDevice.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public void checkDeviceExtensionsSupport(PointerBuffer ppEnabledExtensionNames){
	
	for (int i=0; i<ppEnabledExtensionNames.limit(); i++){
		if (!supportedExtensionNames.contains(ppEnabledExtensionNames.getStringUTF8())){
			throw new AssertionError("Extension " + ppEnabledExtensionNames.getStringUTF8() + " not supported");
		}
	}
	
	ppEnabledExtensionNames.flip();
}
 
Example 10
Source File: DeviceCapabilities.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public static void checkValidationLayerSupport(PointerBuffer ppEnabledLayerNames){
	
	IntBuffer layerCount = memAllocInt(1);
	
	int err = vkEnumerateInstanceLayerProperties(layerCount, null);
	if (err != VK_SUCCESS) {
           throw new AssertionError(VkUtil.translateVulkanResult(err));
       }
	
	VkLayerProperties.Buffer layers = VkLayerProperties.calloc(layerCount.get(0));
	
	err = vkEnumerateInstanceLayerProperties(layerCount, layers);
	if (err != VK_SUCCESS) {
           throw new AssertionError(VkUtil.translateVulkanResult(err));
       }
	
	List<String> availableLayers = new ArrayList<>();
	for (VkLayerProperties layer : layers){
		availableLayers.add(layer.layerNameString());
	}
	
	for (int i=0; i<ppEnabledLayerNames.limit(); i++){
		if (!availableLayers.contains(ppEnabledLayerNames.getStringUTF8())){
			throw new AssertionError("Extension " + ppEnabledLayerNames.getStringUTF8() + " not supported");
		}
	}

	ppEnabledLayerNames.flip();
	
	memFree(layerCount);
	layers.free();
}
 
Example 11
Source File: VkUtil.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public static PointerBuffer getValidationLayerNames(boolean validation, ByteBuffer[] layers){
	
	PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
       for (int i = 0; validation && i < layers.length; i++)
           ppEnabledLayerNames.put(layers[i]);
       ppEnabledLayerNames.flip();
       
       return ppEnabledLayerNames;
}
 
Example 12
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
/**
 * Create a Vulkan {@link VkInstance} using LWJGL 3.
 * <p>
 * The {@link VkInstance} represents a handle to the Vulkan API and we need that instance for about everything we do.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(3)
      .put(VK_KHR_SURFACE_EXTENSION)
      .put(VK_KHR_OS_SURFACE_EXTENSION)
      .put(VK_EXT_DEBUG_REPORT_EXTENSION)
      .flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(NULL)
            .pApplicationInfo(appInfo)
            .ppEnabledExtensionNames(ppEnabledExtensionNames)
            .ppEnabledLayerNames(ppEnabledLayerNames);
    PointerBuffer pInstance = memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    long instance = pInstance.get(0);
    memFree(pInstance);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    pCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example 13
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) {
    IntBuffer pQueueFamilyPropertyCount = memAllocInt(1);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
    int queueCount = pQueueFamilyPropertyCount.get(0);
    VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.calloc(queueCount);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
    memFree(pQueueFamilyPropertyCount);
    int graphicsQueueFamilyIndex;
    for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) {
        if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0)
            break;
    }
    queueProps.free();
    FloatBuffer pQueuePriorities = memAllocFloat(1).put(0.0f);
    pQueuePriorities.flip();
    VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.calloc(1)
            .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
            .queueFamilyIndex(graphicsQueueFamilyIndex)
            .pQueuePriorities(pQueuePriorities);

    PointerBuffer extensions = memAllocPointer(1);
    ByteBuffer VK_KHR_SWAPCHAIN_EXTENSION = memUTF8(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
    extensions.put(VK_KHR_SWAPCHAIN_EXTENSION);
    extensions.flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();

    VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO)
            .pNext(NULL)
            .pQueueCreateInfos(queueCreateInfo)
            .ppEnabledExtensionNames(extensions)
            .ppEnabledLayerNames(ppEnabledLayerNames);

    PointerBuffer pDevice = memAllocPointer(1);
    int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice);
    long device = pDevice.get(0);
    memFree(pDevice);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create device: " + translateVulkanResult(err));
    }

    DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily();
    ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo);
    ret.queueFamilyIndex = graphicsQueueFamilyIndex;

    deviceCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_KHR_SWAPCHAIN_EXTENSION);
    memFree(extensions);
    memFree(pQueuePriorities);
    return ret;
}
 
Example 14
Source File: VulkanInstance.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public VulkanInstance(PointerBuffer ppEnabledLayerNames) {

PointerBuffer requiredExtensions = glfwGetRequiredInstanceExtensions();
      if (requiredExtensions == null) {
          throw new AssertionError("Failed to find list of required Vulkan extensions");
      }

      ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
      
      // +1 due to VK_EXT_DEBUG_REPORT_EXTENSION
      PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
      ppEnabledExtensionNames.put(requiredExtensions);
      ppEnabledExtensionNames.put(VK_EXT_DEBUG_REPORT_EXTENSION);
      ppEnabledExtensionNames.flip();
      
      VkApplicationInfo appInfo = VkApplicationInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
              .pApplicationName(memUTF8("Vulkan Demo"))
              .pEngineName(memUTF8("OREON ENGINE"))
              .apiVersion(VK_MAKE_VERSION(1, 1, 77));
      
      VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
              .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
              .pNext(0)
              .pApplicationInfo(appInfo)
              .ppEnabledExtensionNames(ppEnabledExtensionNames)
              .ppEnabledLayerNames(ppEnabledLayerNames);
      PointerBuffer pInstance = memAllocPointer(1);
      int err = vkCreateInstance(pCreateInfo, null, pInstance);
  
      if (err != VK_SUCCESS) {
          throw new AssertionError("Failed to create VkInstance: " + VkUtil.translateVulkanResult(err));
      }
      
      handle = new VkInstance(pInstance.get(0), pCreateInfo);
      
      pCreateInfo.free();
      memFree(pInstance);
      memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
      memFree(ppEnabledExtensionNames);
      memFree(appInfo.pApplicationName());
      memFree(appInfo.pEngineName());
      appInfo.free();
      
      VkDebugReportCallbackEXT debugCallback = new VkDebugReportCallbackEXT() {
          public int invoke(int flags, int objectType, long object, long location, int messageCode, long pLayerPrefix, long pMessage, long pUserData) {
              System.err.println("ERROR OCCURED: " + VkDebugReportCallbackEXT.getString(pMessage));
              return 0;
          }
      };
      
      debugCallbackHandle = setupDebugging(handle, VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT, debugCallback);
  }
 
Example 15
Source File: VkUtil.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public static PointerBuffer createPointerBuffer(List<CommandBuffer> commandBuffers){
  	
  	if (commandBuffers.size() == 0){
  		log.error("createPointerBuffer: commandBuffers empty");
  	}
  	
  	PointerBuffer cmdBuffersPointer = memAllocPointer(commandBuffers.size());

for (CommandBuffer cmdBuffer : commandBuffers){
	cmdBuffersPointer.put(cmdBuffer.getHandlePointer());
}

cmdBuffersPointer.flip();

return cmdBuffersPointer;
  }
 
Example 16
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private long createContext(final long platform, final long[] devices, long window) {
    try (MemoryStack stack = MemoryStack.stackPush()) {

        final int propertyCount = 2 + 4 + 1;
        final PointerBuffer properties = stack.callocPointer(propertyCount + devices.length);

        // set sharing properties
        // https://github.com/glfw/glfw/issues/104
        // https://github.com/LWJGL/lwjgl3/blob/master/modules/core/src/test/java/org/lwjgl/demo/opencl/Mandelbrot.java
        // TODO: test on Linux and MacOSX
        switch (Platform.get()) {
            case WINDOWS:
                properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeWGL.glfwGetWGLContext(window))
                        .put(KHRGLSharing.CL_WGL_HDC_KHR)
                        .put(org.lwjgl.opengl.WGL.wglGetCurrentDC());
                break;
            case LINUX:
                properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeGLX.glfwGetGLXContext(window))
                        .put(KHRGLSharing.CL_GLX_DISPLAY_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeX11.glfwGetX11Display());
                break;
            case MACOSX:
                properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE)
                        .put(org.lwjgl.opengl.CGL.CGLGetShareGroup(org.lwjgl.opengl.CGL.CGLGetCurrentContext()));
        }

        properties.put(CL_CONTEXT_PLATFORM).put(platform);
        properties.put(0);
        properties.flip();

        final IntBuffer error = stack.callocInt(1);
        final PointerBuffer deviceBuffer = stack.callocPointer(devices.length);
        for (final long deviceId : devices) {
            deviceBuffer.put(deviceId);
        }

        deviceBuffer.flip();

        long context = CL10.clCreateContext(properties, deviceBuffer, null, 0, error);
        Utils.checkError(error, "clCreateContext");

        return context;
    }
}