当前位置: 首页>>代码示例>>Java>>正文


Java CLGLContext.create方法代码示例

本文整理汇总了Java中com.jogamp.opencl.gl.CLGLContext.create方法的典型用法代码示例。如果您正苦于以下问题:Java CLGLContext.create方法的具体用法?Java CLGLContext.create怎么用?Java CLGLContext.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jogamp.opencl.gl.CLGLContext的用法示例。


在下文中一共展示了CLGLContext.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JavaCVCL

import com.jogamp.opencl.gl.CLGLContext; //导入方法依赖的package包/类
public JavaCVCL(GLCapabilitiesImmutable caps, GLContext shareWith, CLDevice device) {
        GLPbuffer pbuffer = null;
        if (caps != null) {
            GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
            if (factory.canCreateGLPbuffer(null)) {
                try {
                    // makes a new buffer
                    pbuffer = factory.createGLPbuffer(null, caps, null, 32, 32, shareWith);
                    // required for drawing to the buffer
                    pbuffer.createContext(shareWith).makeCurrent();
                } catch (GLException e) {
                    logger.warning("Could not create PBuffer: " + e);
                }
            } else {
                logger.warning("OpenGL implementation does not support PBuffers.");
            }
        }
        this.pbuffer = pbuffer;

        GLContext glContext = GLContext.getCurrent();
        if (device == null && glContext != null) {
            // woohoo! we have a GLContext

            // find gl compatible device
            CLDevice[] devices = CLPlatform.getDefault().listCLDevices();
            for (CLDevice d : devices) {
                if(d.isGLMemorySharingSupported()) {
                    device = d;
                    break;
                }
            }
//            if(null==device) {
//                throw new RuntimeException("couldn't find any CL/GL memory sharing devices ..");
//            }
        }
        if (glContext != null && device != null) {
            // create OpenCL context before creating any OpenGL objects
            // you want to share with OpenCL (AMD driver requirement)
            context = CLGLContext.create(glContext, device);
            glu = GLU.createGLU();
        } else if (device != null) {
            context = CLContext.create(device);
            glu = null;
        } else {
            // find a CL implementation
            //CLPlatform platform = CLPlatform.getDefault(/*type(CPU)*/);
            context = CLContext.create(/*platform.getMaxFlopsDevice()*/);
            device = context.getDevices()[0];
            glu = null;
        }

        // creade a command queue with benchmarking flag set
        commandQueue = device.createCommandQueue(/*Mode.PROFILING_MODE*/);

        CLKernel[] kernels = buildKernels(fastCompilerOptions, "JavaCV.cl", "pyrDown", "remap", "remapBayer");
        this.pyrDownKernel    = kernels[0];
        this.remapKernel      = kernels[1];
        this.remapBayerKernel = kernels[2];
    }
 
开发者ID:wordin0,项目名称:javacv,代码行数:60,代码来源:JavaCVCL.java

示例2: init

import com.jogamp.opencl.gl.CLGLContext; //导入方法依赖的package包/类
/**
 * Implementation of GLEventListener: Called to initialize the
 * GLAutoDrawable. This method will initialize the JCudaDriver
 * and cause the initialization of CUDA and the OpenGL PBO.
 */
public void init(GLAutoDrawable drawable)
{
	// Perform the default GL initialization
	GL gl = drawable.getGL();
	gl.setSwapInterval(0);
	gl.glEnable(GL.GL_DEPTH_TEST);
	gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	setupView(drawable);

	// Initialize the GL_ARB_pixel_buffer_object extension
	if (!gl.isExtensionAvailable("GL_ARB_pixel_buffer_object"))
	{
		new Thread(new Runnable()
		{
			public void run()
			{
				JOptionPane.showMessageDialog(null,
						"GL_ARB_pixel_buffer_object extension not available",
						"Unavailable extension", JOptionPane.ERROR_MESSAGE);
				runExit();
			}
		}).start();
	}

	// Create a TextRenderer for the status messages
	renderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 12));

	if (initialized)
	{
		return;
	}

	try {
		// find gl compatible device
        device = OpenCLUtil.getStaticContext().getMaxFlopsDevice();
        // create OpenCL context before creating any OpenGL objects
        // you want to share with OpenCL (AMD driver requirement)
        glCtx = CLGLContext.create(drawable.getContext(), device);

        // create the program
        program = glCtx.createProgram(getClass().getResourceAsStream("volumeRender.cl")).build();
        System.out.println(program.getBuildStatus());
        System.out.println(program.isExecutable());
        System.out.println(program.getBuildLog());
        
        commandQueue = device.createCommandQueue();
        
        kernelFunction = program.createCLKernel("d_render");
        
	} catch (Exception e) {
		e.printStackTrace();
		unload();
	}

	// Initialize CUDA with the current volume data
	initCL();

	// Initialize the OpenGL pixel buffer object
	initPBO(gl);
	
	initialized = true;
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:68,代码来源:OpenCLTextureRendering.java

示例3: init

import com.jogamp.opencl.gl.CLGLContext; //导入方法依赖的package包/类
@Override
public void init(GLAutoDrawable drawable) {

    if(clContext == null) {

        // find gl compatible device
        CLDevice[] devices = CLPlatform.getDefault().listCLDevices();
        CLDevice device = null;
        for (CLDevice d : devices) {
            if(d.isGLMemorySharingSupported()) {
                device = d;
                break;
            }
        }
        if(null==device) {
            throw new RuntimeException("couldn't find any CL/GL memory sharing devices ..");
        }
        // create OpenCL context before creating any OpenGL objects
        // you want to share with OpenCL (AMD driver requirement)
        clContext = CLGLContext.create(drawable.getContext(), device);

        // enable GL error checking using the composable pipeline
        drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));

        // OpenGL initialization
        GL2 gl = drawable.getGL().getGL2();

        gl.setSwapInterval(1);

        gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);

        gl.glGenBuffers(glObjects.length, glObjects, 0);

//        gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, glObjects[INDICES]);
//        gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, ib.capacity() * SIZEOF_INT, ib, GL2.GL_STATIC_DRAW);
//        gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);

        final int bsz = MESH_SIZE * MESH_SIZE * 4 * SIZEOF_FLOAT;
        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
            gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, glObjects[VERTICES]);
            gl.glBufferData(GL2.GL_ARRAY_BUFFER, bsz, null, GL2.GL_DYNAMIC_DRAW);
            gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);                       

        pushPerspectiveView(gl);
        gl.glFinish();

        // init OpenCL
        initCL(gl, bsz);

        // start rendering thread
        Animator animator = new Animator(drawable);
        animator.start();

    }
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:57,代码来源:GLCLInteroperabilityDemo.java


注:本文中的com.jogamp.opencl.gl.CLGLContext.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。