Examples of NativeSizeBuffer


Examples of com.jogamp.common.nio.NativeSizeBuffer

            return Collections.emptyMap();
        }
       
        CLDevice[] devices = getCLDevices();

        NativeSizeBuffer sizes = NativeSizeBuffer.allocateDirect(devices.length);
        int ret = binding.clGetProgramInfo(ID, CL_PROGRAM_BINARY_SIZES, sizes.capacity()*NativeSizeBuffer.elementSize(), sizes.getBuffer(), null);
        if(ret != CL_SUCCESS) {
            throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARY_SIZES) of "+this);
        }

        int binariesSize = 0;
        while(sizes.remaining() != 0) {
            int size = (int) sizes.get();
            binariesSize += size;
        }
        ByteBuffer binaries = newDirectByteBuffer(binariesSize);

       
        long address = InternalBufferUtil.getDirectBufferAddress(binaries);
        NativeSizeBuffer addresses = NativeSizeBuffer.allocateDirect(sizes.capacity());
        sizes.rewind();
        while(sizes.remaining() != 0) {
            addresses.put(address);
            address += sizes.get();
        }
        addresses.rewind();
       
        ret = binding.clGetProgramInfo(ID, CL_PROGRAM_BINARIES, addresses.capacity()*NativeSizeBuffer.elementSize(), addresses.getBuffer(), null);
        if(ret != CL_SUCCESS) {
            throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARIES) of "+this);
        }

        Map<CLDevice, byte[]> map = new LinkedHashMap<CLDevice, byte[]>();
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

        IntBuffer ib = Buffers.newDirectIntBuffer(1);
        int ret = cl.clCreateSubDevicesEXT(ID, props, 0, null, ib);
        CLException.checkForError(ret, "create sub devices failed");

        int count = ib.get(0);
        NativeSizeBuffer ids = NativeSizeBuffer.allocateDirect(count);
        ret = cl.clCreateSubDevicesEXT(ID, props, count, ids, null);
        CLException.checkForError(ret, "create sub devices failed");

        CLSubDevice[] devices = new CLSubDevice[count];
        for (int i = 0; i < devices.length; i++) {
            devices[i] = CLSubDevice.createSubDevice(this, ids.get());
        }
        return devices;
    }
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

    private LongBuffer getInfoLongs(int flag) {

        CL cl = CLPlatform.getLowLevelCLInterface();

        NativeSizeBuffer nsb = NativeSizeBuffer.allocateDirect(1);
        int ret = cl.clGetDeviceInfo(ID, flag, 0, null, nsb);
        CLException.checkForError(ret, "clGetDeviceInfo failed");

        LongBuffer types = Buffers.newDirectByteBuffer((int)nsb.get(0)).asLongBuffer();
        ret = cl.clGetDeviceInfo(ID, flag, types.capacity()*Buffers.SIZEOF_LONG, types, null);
        CLException.checkForError(ret, "clGetDeviceInfo failed");

        return types;
    }
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

    private synchronized void initDevices(CLContextBinding cl) {
       
        if (devices == null) {

            NativeSizeBuffer deviceCount = NativeSizeBuffer.allocateDirect(1);

            int ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, 0, null, deviceCount);
            checkForError(ret, "can not enumerate devices");

            ByteBuffer deviceIDs = Buffers.newDirectByteBuffer((int)deviceCount.get());
            ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null);
            checkForError(ret, "can not enumerate devices");

            devices = new CLDevice[deviceIDs.capacity() / (is32Bit() ? 4 : 8)];
            for (int i = 0; i < devices.length; i++) {
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

            platform = CLPlatform.getDefault();
        }

        long type = toDeviceBitmap(deviceTypes);

        NativeSizeBuffer properties = setupContextProperties(platform);
        ErrorDispatcher dispatcher = new ErrorDispatcher();
        return new CLContext(platform, createContextFromType(platform, dispatcher, properties, type), dispatcher);
    }
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

            throw new IllegalArgumentException("first device was null");
        }

        CLPlatform platform = devices[0].getPlatform();

        NativeSizeBuffer properties = setupContextProperties(platform);
        ErrorDispatcher dispatcher = new ErrorDispatcher();
        CLContext context = new CLContext(platform, createContext(platform, dispatcher, properties, devices), dispatcher);
        if(devices != null) {
            for (int i = 0; i < devices.length; i++) {
                devices[i].setContext(context);
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

    }

    protected static long createContext(CLPlatform platform, CLErrorHandler handler, NativeSizeBuffer properties, CLDevice... devices) {

        IntBuffer status = newDirectIntBuffer(1);
        NativeSizeBuffer pb = null;
        if(devices != null && devices.length != 0) {
            pb = NativeSizeBuffer.allocateDirect(devices.length);
            for (int i = 0; i < devices.length; i++) {
                CLDevice device = devices[i];
                if(device == null) {
                    throw new IllegalArgumentException("device at index "+i+" was null.");
                }
                pb.put(i, device.ID);
            }
        }
        CLContextBinding cl = platform.getContextBinding();
        long context = cl.clCreateContext(properties, pb, handler, status);
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

        if(platform == null) {
            platform = CLPlatform.getDefault();
        }

        long[] glID = new long[1];
        NativeSizeBuffer properties = setupContextProperties(platform, glContext, glID);
        ErrorDispatcher dispatcher = createErrorHandler();
        long clID = createContextFromType(platform, dispatcher, properties, toDeviceBitmap(deviceTypes));

        return new CLGLContext(platform, glContext, clID, glID[0], dispatcher);
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

        }

        CLPlatform platform = devices[0].getPlatform();

        long[] glID = new long[1];
        NativeSizeBuffer properties = setupContextProperties(platform, glContext, glID);
        ErrorDispatcher dispatcher = createErrorHandler();
        long clID = createContext(platform, dispatcher, properties, devices);

        CLGLContext context = new CLGLContext(platform, glContext, clID, glID[0], dispatcher);
        if(devices != null) {
View Full Code Here

Examples of com.jogamp.common.nio.NativeSizeBuffer

        }

        GLContextImpl ctxImpl = (GLContextImpl)glContext;
        glID[0] = glContext.getHandle();

        NativeSizeBuffer properties;
        if(glContext instanceof X11GLXContext) {
//          spec: "When the GLX binding API is supported, the attribute
//          CL_GL_CONTEXT_KHR should be set to a GLXContext handle to an
//          OpenGL context, and the attribute CL_GLX_DISPLAY_KHR should be
//          set to the Display handle of the X Window System display used to
//          create the OpenGL context."
            properties = NativeSizeBuffer.allocateDirect(7);
            long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
            properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
                      .put(CL_GLX_DISPLAY_KHR).put(displayHandle)
                      .put(CL_CONTEXT_PLATFORM).put(platform.ID);
        }else if(glContext instanceof WindowsWGLContext) {
//          spec: "When the WGL binding API is supported, the attribute
//          CL_GL_CONTEXT_KHR should be set to an HGLRC handle to an OpenGL
//          context, and the attribute CL_WGL_HDC_KHR should be set to the
//          HDC handle of the display used to create the OpenGL context."
            properties = NativeSizeBuffer.allocateDirect(7);
            long surfaceHandle = ctxImpl.getDrawableImpl().getNativeSurface().getSurfaceHandle();
            properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
                      .put(CL_WGL_HDC_KHR).put(surfaceHandle)
                      .put(CL_CONTEXT_PLATFORM).put(platform.ID);
        }else if(glContext instanceof MacOSXCGLContext) {
//          spec: "When the CGL binding API is supported, the attribute
//          CL_CGL_SHAREGROUP_KHR should be set to a CGLShareGroup handle to
//          a CGL share group object."
            long cgl = CGL.getCGLContext(glID[0]);
            long group = CGL.CGLGetShareGroup(cgl);
            properties = NativeSizeBuffer.allocateDirect(5);
            properties.put(CL_CGL_SHAREGROUP_KHR).put(group)
                      .put(CL_CONTEXT_PLATFORM).put(platform.ID);
        }else if(glContext instanceof EGLContext) {
//            TODO test EGL
//          spec: "When the EGL binding API is supported, the attribute
//          CL_GL_CONTEXT_KHR should be set to an EGLContext handle to an
//          OpenGL ES or OpenGL context, and the attribute
//          CL_EGL_DISPLAY_KHR should be set to the EGLDisplay handle of the
//          display used to create the OpenGL ES or OpenGL context."
            properties = NativeSizeBuffer.allocateDirect(7);
            long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
            properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
                      .put(CL_EGL_DISPLAY_KHR).put(displayHandle)
                      .put(CL_CONTEXT_PLATFORM).put(platform.ID);
        }else{
            throw new RuntimeException("unsupported GLContext: "+glContext);
        }

        return properties.put(0).rewind(); // 0 terminated array
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.