Пример #1
0
void cl_select_context(cl_platform_id* platform, cl_device_id* device, cl_context* context) {
    cl_int err;
#if defined (__APPLE__)
    CGLContextObj kCGLContext = CGLGetCurrentContext();
    CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
    cl_context_properties props[] =
    {
        CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
        0
    };
    *context = clCreateContext(props, 0,0, NULL, NULL, &err);
#else
    #ifdef UNIX
    cl_context_properties props[] =
    {
        CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
        CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
        CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
        0
    };
    *context = clCreateContext(props, 1, &cdDevices[uiDeviceUsed], NULL, NULL, &err);
    #else // Win32
    cl_context_properties props[] =
    {
        CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
        CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
        CL_CONTEXT_PLATFORM, (cl_context_properties)*platform,
        0
    };
    *context = clCreateContext(props, 1, device, NULL, NULL, &err);
    CHECK_ERR(err);
#endif
#endif
}
Пример #2
0
ocl_constructs * newOclConstructs(cl_uint workerSize, cl_uint groupSize, cl_bool clGlSharing){

  ocl_constructs * occs = (ocl_constructs*) malloc(sizeof(ocl_constructs));
  occs->platformId = NULL;
  occs->deviceId = NULL;
  occs->context = NULL;
  occs->queue = NULL;
  occs->program = NULL;
  occs->buffers = NULL;
  occs->kernel = NULL;
  if(clGlSharing && 0){
    occs->contextProperties = (cl_context_properties*) 
                                malloc(sizeof(cl_context_properties) * 7);
    occs->contextProperties[0] = CL_GL_CONTEXT_KHR;
    occs->contextProperties[1] = (cl_context_properties)glXGetCurrentContext();
    occs->contextProperties[2] = CL_GLX_DISPLAY_KHR;
    occs->contextProperties[3] = (cl_context_properties)glXGetCurrentDisplay();
    occs->contextProperties[4] = CL_CONTEXT_PLATFORM;
    //occs->contextProperties[5] = (cl_context_properties)cpPlatform;
    occs->contextProperties[6] = 0;
  }
  else occs->contextProperties = NULL;
  //occs->refreshCount = 30;

  return occs;
}
Пример #3
0
static int gl_thread_create(void* unused) {
  
  int err = glXMakeCurrent(gl_thread_display, gl_thread_drawable, gl_thread_context);
  if (err == 0) {
    // Could not make context current
    return -1;
  }
  
  int status = gl_thread_func(gl_thread_data);
  
  Display* display = glXGetCurrentDisplay();
  if (display == NULL) {
    // Could not get current display
    return -2;
  }
  
  GLXContext context = glXGetCurrentContext();
  if (context == NULL) {
    // Could not get current context
    return -3;
  }
  
  err = glXMakeCurrent(display, None, NULL);
  if (err == 0) {
    // Could not make context current
    return -4;
  }
  
  glXDestroyContext(display, context);
  
  return status;
}
Пример #4
0
void setSwapInterval(int interval) {
    if (glxewIsSupported("GLX_EXT_swap_control")) {
        Display *dpy = glXGetCurrentDisplay();
        GLXDrawable drawable = glXGetCurrentDrawable();
        glXSwapIntervalEXT(dpy, drawable, interval);
    }
}
Пример #5
0
void glfntInit(void)
{

  Display *dpy;
  
  XFontStruct *fontInfo;
  Font id;
  unsigned int first;

  if (LettersDL!=0) return;
#ifdef SGI_CC
  dpy=glXGetCurrentDisplayEXT();
#else  
  dpy=glXGetCurrentDisplay();
#endif  
   if (dpy==NULL) return;
  fontInfo = XLoadQueryFont(dpy,
        "-adobe-times-medium-r-normal--17-120-100-100-p-88-iso8859-1");    
  if (fontInfo == NULL) return;

  id = fontInfo->fid;
  first = fontInfo->min_char_or_byte2;
  last = fontInfo->max_char_or_byte2;
  if (first<32) first=32;
  if (last>127) last=127;

  LettersDL=glGenLists(last+1);
  if (LettersDL==0) return;
  glXUseXFont(id, first, last-first+1, LettersDL+first);
  
}
Пример #6
0
static int _GetCudaDeviceForCurrentGLContext()
{
#if defined(_WIN32)

    return 0;

#elif defined(__APPLE__)

    return 0;

#else  // X11
    // If we don't have a current GL context, then choose the device which
    // matches the current X11 screen number.
    Display * display = glXGetCurrentDisplay();
    if (!display) {
        display = XOpenDisplay(NULL);
        if (display) {
            int screen = DefaultScreen(display);
            XCloseDisplay(display);
            message("CUDA init using device for default screen: %d\n", screen);
            return screen;
        }
        return 0;
    }

    // We can't use the new interop API, so use the device
    // corresponding to the screen number of the current GL context.
    int screen = DefaultScreen(display);
    message("CUDA init using device for screen: %d\n", screen);
    return screen;
#endif  // X11
}
Пример #7
0
void
GarchGLXContextState::DoneCurrent()
{
    if (Display* display = glXGetCurrentDisplay()) {
        glXMakeCurrent(display, None, NULL);
    }
}
Пример #8
0
void InitCL()
{
	void* glCtx=0;
	void* glDC = 0;

#ifdef _WIN32
	glCtx = wglGetCurrentContext();
	glDC = wglGetCurrentDC();
#elif _APPLE
	glCtx = CGLGetCurrentContext();
#else //!_WIN32
	glCtx = glXGetCurrentContext();
	glDC = glXGetCurrentDisplay();
#endif //!_WIN32

	int ciErrNum = 0;
	cl_device_type deviceType = CL_DEVICE_TYPE_ALL;//GPU;
	g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
	oclCHECKERROR(ciErrNum, CL_SUCCESS);

	int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);

	if (numDev>0)
	{
		g_device= btOpenCLUtils::getDevice(g_cxMainContext,0);
		btOpenCLUtils::printDeviceInfo(g_device);
		// create a command-queue
		g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_device, 0, &ciErrNum);
		oclCHECKERROR(ciErrNum, CL_SUCCESS);
		//normally you would create and execute kernels using this command queue

	}


}
Пример #9
0
static int _GetCudaDeviceForCurrentGLContext()
{
    // Find and use the CUDA device for the current GL context
    unsigned int interopDeviceCount = 0;
    int interopDevices[1];
    cudaError_t status = cudaGLGetDevices(&interopDeviceCount, interopDevices,
                                          1,  cudaGLDeviceListCurrentFrame);
    if (status == cudaErrorNoDevice || interopDeviceCount != 1) {
        message("CUDA no interop devices found.\n");
        return 0;
    }
    int device = interopDevices[0];

#if defined(_WIN32)
    return device;

#elif defined(__APPLE__)
    return device;

#else  // X11
    Display * display = glXGetCurrentDisplay();
    int screen = DefaultScreen(display);
    if (device != screen) {
        error("The CUDA interop device (%d) does not match "
              "the screen used by the current GL context (%d), "
              "which may cause slow performance on systems "
              "with multiple GPU devices.", device, screen);
    }
    message("CUDA init using device for current GL context: %d\n", device);
    return device;
#endif
}
Пример #10
0
static int create(struct gl_hwdec *hw)
{
    GL *gl = hw->gl;
    if (hw->hwctx)
        return -1;
    Display *x11disp = glXGetCurrentDisplay();
    if (!x11disp)
        return -1;
    if (!(gl->mpgl_caps & MPGL_CAP_VDPAU))
        return -1;
    struct priv *p = talloc_zero(hw, struct priv);
    hw->priv = p;
    p->log = hw->log;
    p->ctx = mp_vdpau_create_device_x11(hw->log, x11disp, true);
    if (!p->ctx)
        return -1;
    if (mp_vdpau_handle_preemption(p->ctx, &p->preemption_counter) < 1)
        return -1;
    p->vdp_surface = VDP_INVALID_HANDLE;
    p->mixer = mp_vdpau_mixer_create(p->ctx, hw->log);
    if (hw->probing && mp_vdpau_guess_if_emulated(p->ctx)) {
        destroy(hw);
        return -1;
    }
    hw->hwctx = &p->ctx->hwctx;
    hw->converted_imgfmt = IMGFMT_RGB0;
    return 0;
}
Пример #11
0
GlfQGLPlatformDebugContextPrivate::GlfQGLPlatformDebugContextPrivate(
        int majorVersion, int minorVersion,
        bool coreProfile, bool directRendering)
    : _dpy(NULL)
    , _ctx(NULL)
{
    Display *shareDisplay = glXGetCurrentDisplay();
    GLXContext shareContext = glXGetCurrentContext();

    int fbConfigId = 0;
    glXQueryContext(shareDisplay, shareContext, GLX_FBCONFIG_ID, &fbConfigId);
    int screen = 0;
    glXQueryContext(shareDisplay, shareContext, GLX_SCREEN, &screen);

    int configSpec[] = {
        GLX_FBCONFIG_ID, fbConfigId,
        None, 
    };
    GLXFBConfig *configs = NULL;
    int configCount = 0;
    configs = glXChooseFBConfig(shareDisplay, screen, configSpec, &configCount);
    if (not TF_VERIFY(configCount > 0)) {
        return;
    }

    const int profile =
        coreProfile
            ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB
            : GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;

    int attribs[] = {
        GLX_CONTEXT_MAJOR_VERSION_ARB, majorVersion,
        GLX_CONTEXT_MINOR_VERSION_ARB, minorVersion,
        GLX_CONTEXT_PROFILE_MASK_ARB, profile,
        GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
        0,
    };

    // Extension entry points must be resolved at run-time.
    PFNGLXCREATECONTEXTATTRIBSARBPROC createContextAttribs =
        (PFNGLXCREATECONTEXTATTRIBSARBPROC)
            glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");

    // Create a GL context with the requested capabilities.
    if (createContextAttribs) {
        _ctx = (*createContextAttribs)(shareDisplay, configs[0],
                                       shareContext, directRendering,
                                       attribs);
    } else {
        TF_WARN("Unable to create GL debug context.");
        XVisualInfo *vis = glXGetVisualFromFBConfig(shareDisplay, configs[0]);
        _ctx = glXCreateContext(shareDisplay, vis,
                                shareContext, directRendering);
    }
    if (not TF_VERIFY(_ctx)) {
        return;
    }

    _dpy = shareDisplay;
}
Пример #12
0
void
glx_ctx_push_thread_local(VdpDeviceData *deviceData)
{
    glx_ctx_lock();
    Display *dpy = deviceData->display;
    const Window wnd = deviceData->root;
    thread_id_t thread_id = get_current_thread_id();

    ctx_stack.dpy = glXGetCurrentDisplay();
    if (!ctx_stack.dpy)
        ctx_stack.dpy = dpy;
    ctx_stack.wnd =     glXGetCurrentDrawable();
    ctx_stack.glc =     glXGetCurrentContext();
    ctx_stack.element_count ++;

    struct val_s *val = g_hash_table_lookup(glc_hash_table, GSIZE_TO_POINTER(thread_id));
    if (!val) {
        GLXContext glc = glXCreateContext(dpy, root_vi, root_glc, GL_TRUE);
        assert(glc);
        val = make_val(dpy, glc);
        g_hash_table_insert(glc_hash_table, GSIZE_TO_POINTER(thread_id), val);

        // try cleanup expired entries
        g_hash_table_foreach_remove(glc_hash_table, is_thread_expired, NULL);
    }
    assert(val->dpy == dpy);

    glXMakeCurrent(dpy, wnd, val->glc);
}
    //
    // Constructor
    //
    CRegistry::CRegistry( 
                         bool WindowSystem 
                         ):
        m_VersionStr( NULL ),
        m_ExtensionsStr( NULL )
    {
        if (WindowSystem)
        {
	#ifdef _WIN32
            if (!wglGetExtensionsStringARB)
                throw Sys::CException( this, "::CRegistry() : Failed to obtain wglGetExtensionsStringARB entry point." );
                
            HDC DC = wglGetCurrentDC();
            if (!DC)
                throw Sys::CException( this, "::CRegistry() : Invalid current DC." );
       
            m_ExtensionsStr = wglGetExtensionsStringARB( DC );
	#elif defined (__linux__)
            Display *Dpy = glXGetCurrentDisplay();
            if (!Dpy)
                throw Sys::CException( this, "::CRegistry() : Invalid current Display." );
                
            m_ExtensionsString = glXGetClientString( Dpy, GLX_EXTENSIONS );
	#endif // _WIN32
        }
		else
        {
            m_VersionStr = reinterpret_cast<const char *>( glGetString( GL_VERSION ) );
            m_ExtensionsStr = reinterpret_cast<const char *>( glGetString( GL_EXTENSIONS ) );
        }

        TokenizeString();
    }
Пример #14
0
void OCLContextProperties::AddOpenGLContextProperties() {
#ifdef __linux__
    cl_context_properties props[7] = {
        CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext(),
        CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(),
        0
    };
#elif __APPLE__
    CGLContextObj kGLContext = CGLGetCurrentContext();
    CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kGLContext);

    cl_context_properties props[5] = {
        CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties) kCGLShareGroup,
        NULL
    };
    //foundCtx = clCreateContext(
    //props, 0, 0, NULL, NULL, clerr);
#elif WIN32
    cl_context_properties props[5] = {
        CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
        CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC()
    };
#else
#error "Platform Not avalible for GL intergration"
#endif

    AddProperties(props);
}
Пример #15
0
// XXX: initCL should be removed from libosd
void
OsdClKernelDispatcher::initCL() {

    cl_int ciErrNum;

    cl_platform_id cpPlatform = 0;
    cl_uint num_platforms;
    ciErrNum = clGetPlatformIDs(0, NULL, &num_platforms);
    if (ciErrNum != CL_SUCCESS) {
        OSD_ERROR("Error %i in clGetPlatformIDs call.\n", ciErrNum);
        exit(1);
    }
    if (num_platforms == 0) {
        OSD_ERROR("No OpenCL platform found.\n");
        exit(1);
    }
    cl_platform_id *clPlatformIDs;
    clPlatformIDs = new cl_platform_id[num_platforms];
    ciErrNum = clGetPlatformIDs(num_platforms, clPlatformIDs, NULL);
    char chBuffer[1024];
    for (cl_uint i = 0; i < num_platforms; ++i) {
        ciErrNum = clGetPlatformInfo(clPlatformIDs[i], CL_PLATFORM_NAME, 1024, chBuffer,NULL);
        if (ciErrNum == CL_SUCCESS) {
            cpPlatform = clPlatformIDs[i];
        }
    }
    // -------------
    clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_GPU, 1, &_clDevice, NULL);

#if defined(_WIN32)
    cl_context_properties props[] = {
        CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
        CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
        CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
        0
    };
#elif defined(__APPLE__)
    CGLContextObj kCGLContext = CGLGetCurrentContext();
    CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
    cl_context_properties props[] = {
        CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
        0
    };
#else
    cl_context_properties props[] = {
        CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
        CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
        CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
        0
    };
#endif

    // XXX context creation should be moved to client code
    _clContext = clCreateContext(props, 1, &_clDevice, NULL, NULL, &ciErrNum);
    CL_CHECK_ERROR(ciErrNum, "clCreateContext\n");

    _clQueue = clCreateCommandQueue(_clContext, _clDevice, 0, &ciErrNum);
    CL_CHECK_ERROR(ciErrNum, "clCreateCommandQueue\n");
}
Пример #16
0
GarchGLXContextState::GarchGLXContextState() :
    display(glXGetCurrentDisplay()),
    drawable(glXGetCurrentDrawable()),
    context(glXGetCurrentContext()),
    _defaultCtor(true)
{
    // Do nothing
}
Пример #17
0
		void glx_version(int& major, int& minor)
		{
#ifdef GLLOADER_GLX
			glXQueryVersion(glXGetCurrentDisplay(), &major, &minor);
#else
			major = minor = 0;
#endif		// GLLOADER_GLX
		}
Пример #18
0
Файл: glc.c Проект: cout/mglc
/* Create a new GLC context and return its ID */
GLint glcGenContext() {
	GLCcontext *c;
	int i, j;

	/* If this is the first call, initialize our data */
	if(numGlcContexts==0) {
		memset(glcContextList, 0, sizeof(glcContextList));
		memset(glcContexts, 0, sizeof(glcContexts));
	}
	isFirstCall = FALSE;

	/* Find context that is not in use */
	for(j = 1; j < MAX_GLC_CONTEXTS; j++)
		if(!glcContexts[j].isContext) break;
	if(j == MAX_GLC_CONTEXTS) return 0;

	/* Add this context to the list */
	glcContextList[numGlcContexts++] = j;
	glcContextList[numGlcContexts] = 0;

	/* Initialize this context */
	c = &glcContexts[j];
	c->isContext = TRUE;
	c->display = (Display*)glXGetCurrentDisplay();
	c->bitmap_matrix[0] = 1.0;
	c->bitmap_matrix[1] = 0.0;
	c->bitmap_matrix[2] = 0.0;
	c->bitmap_matrix[3] = 1.0;
	c->bitmap_scale[0] = 1.0;
	c->bitmap_scale[1] = 1.0;
	last_error = GLC_NONE;
	c->data_pointer = 0;
	c->num_fonts = 0;
	c->list_base = glGenLists(256);
	c->reload_font = TRUE;
	c->scale_change = TRUE;
	memcpy(c->bitmap_matrix, identity_matrix_2_by_2, sizeof(c->bitmap_matrix));

	/* Turn on synchronization.  This does not affear to affect performance,
	 * and seems to keep my X server from crashing.  Still, this should
	 * not be necessary, and an alternative solution would probably be
	 * preferable.
	 */
	XSynchronize(c->display, TRUE);

	/* Load a default font */
	memset(c->font_list, 0, sizeof(c->font_list));
	c->fonts[0][GLC_STYLE_NORMAL].xfontinfo = XLoadQueryFont(c->display, "variable");
	c->fonts[0][GLC_STYLE_NORMAL].xfont = c->fonts[0][GLC_STYLE_NORMAL].xfontinfo->fid;
	c->fonts[0][GLC_STYLE_NORMAL].name = strdup("base");
	c->fonts[0][GLC_STYLE_NORMAL].xfontprefix =
	c->fonts[0][GLC_STYLE_NORMAL].xfontsuffix = strdup("");
	c->fonts[0][GLC_STYLE_NORMAL].isFont = TRUE;
	glXUseXFont(c->fonts[0][GLC_STYLE_NORMAL].xfont, 0, 256, c->list_base);
	for(i = 1; i < NUM_GLC_STYLES; i++) c->fonts[0][i].isFont = FALSE;

	return j;
}
Пример #19
0
cl_context QHoneycombWidget::CreateContext()
{
  cl_int errNum;
  cl_uint numPlatforms;
  cl_platform_id firstPlatformId;
  cl_context context = NULL;

  // First, select an OpenCL platform to run on.  For this example, we
  // simply choose the first available platform.  Normally, you would
  // query for all available platforms and select the most appropriate one.
  errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
  if (errNum != CL_SUCCESS || numPlatforms <= 0)
  {
    std::cerr << "Failed to find any OpenCL platforms." << std::endl;
    return NULL;
  }

  // Next, create an OpenCL context on the platform.  Attempt to
  // create a GPU-based context, and if that fails, try to create
  // a CPU-based context.
  cl_context_properties contextProperties[] =
  {
#ifdef _WIN32
    CL_CONTEXT_PLATFORM,
    (cl_context_properties)firstPlatformId,
    CL_GL_CONTEXT_KHR,
    (cl_context_properties)wglGetCurrentContext(),
    CL_WGL_HDC_KHR,
    (cl_context_properties)wglGetCurrentDC(),
#elif defined( __GNUC__)
    CL_CONTEXT_PLATFORM, (cl_context_properties)clSelectedPlatformID,
    CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
    CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
#elif defined(__APPLE__) 
    //todo
#endif
    0



  };
  context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
    NULL, NULL, &errNum);
  if (errNum != CL_SUCCESS)
  {
    std::cout << "Could not create GPU context, trying CPU..." << std::endl;
    context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU,
      NULL, NULL, &errNum);
    if (errNum != CL_SUCCESS)
    {
      std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
      return NULL;
    }
  }

  return context;
}
Пример #20
0
 /** Initialise GPGPU engine.
 */
 void GLEngine::initialise()
 {
     /// Initialize GL extension wrangler
     mDisplay = glXGetCurrentDisplay();
     if(mDisplay == 0)
     {
         /// If there is none, create one
         mDisplay = XOpenDisplay(NULL);
         if(!mDisplay)
             GPGPU_EXCEPT(ERR_RENDERSYSTEM, "Could not open X display");
     }
     mPBuffers.resize(PT_COUNT);
     
     /// Initialize PBuffer for BYTE format
     getPBuffer(PT_BYTE, 256, 256)->makeCurrent();
     
     /// Initialize GL here (load extensions etc)
     glewInit();
     
     /// Get card model
     std::string vendor(reinterpret_cast<const char*>(glGetString(GL_VENDOR)));
     std::string renderer(reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
     mHWInfo.model = vendor + " " + renderer;
     
     /// Get number of texture units
     GLint maxTextureUnits;
     glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits);
     mMaxTextureUnits = (size_t)maxTextureUnits;
     if(mMaxTextureUnits > GPGPU_TEXUNITS)
         mMaxTextureUnits = GPGPU_TEXUNITS;
     mHWInfo.textureUnits = mMaxTextureUnits;
     // Check for NV or ATI float textures
     if(GLEW_ATI_texture_float)
     {
         mFloatTexType = FTT_ATI;
         mHWInfo.mFloatTextures = true;
         mHWInfo.mFullFloatTextures = true;
     }
     else if(GLEW_NV_float_buffer)
     {
         mFloatTexType = FTT_NV;
         mHWInfo.mFloatTextures = true;
         mHWInfo.mFullFloatTextures = false;
     }
     
     /// Register program factories
     mProgramFactories["Cg"] = ProgramFactoryPtr(new CgProgramFactory());
     if(GLEW_ARB_shader_objects)
         mProgramFactories["GLSL"] = ProgramFactoryPtr(new GLSLProgramFactory());
     
     // Initialize program managers
     for(ProgramFactoryMap::iterator i=mProgramFactories.begin(); i!=mProgramFactories.end(); ++i)
     {
         mHWInfo.languages.push_back(i->first);
         i->second->initialise(mHWInfo);
     }
 }
Пример #21
0
bool Context::createContext(bool glInterop)
{
    if(_initialized)
        return false;

    QMutexLocker locker(&_lock);

    _glInterop= glInterop;

    QVector<cl_context_properties> props;
    if(_glInterop) {
        // Add OpenGL properties
        #ifdef __MACOSX
            // Apple (untested)
            props << CL_CGL_SHAREGROUP_KHR;
            props << reinterpret_cast<cl_context_properties>(CGLGetShareGroup(CGLGetCurrentContext()));
            props << CL_CONTEXT_PLATFORM;
            props << reinterpret_cast<cl_context_properties>(devMgr().platform());
        #elif _WIN32
            // Windows (untested)
            props << CL_GL_CONTEXT_KHR
            props << reinterpret_cast<cl_context_properties>(wglGetCurrentContext());
            props << CL_WGL_HDC_KHR
            props << reinterpret_cast<cl_context_properties>(wglGetCurrentDC());
        #else
            // Linux/GLX
            props << CL_GL_CONTEXT_KHR;
            props << (cl_context_properties)glXGetCurrentContext();
            props << CL_GLX_DISPLAY_KHR;
            props << (cl_context_properties)glXGetCurrentDisplay();
            props << (cl_context_properties)(devMgr().platform());
        #endif
        props << 0; // Can't use nullptr here
    }

    // Create OpenCL context
    cl_int err;
    const auto propsPtr= props.count() ? props.data() : nullptr;
    const auto devs= devMgr().devices(); // Get selected devices from the dev manager
    _context= clCreateContext(propsPtr, devs.count(), devs.data(), nullptr, nullptr, &err);
    if(checkCLError(err, "clCreateContext"))
        return false;   

    // Get list of supported formats
    cl_uint formatCount;
    err= clGetSupportedImageFormats(_context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D,
                                    0, nullptr, &formatCount);
    if(checkCLError(err, "clGetSupportedImageFormats") or formatCount<=0)
        return false;
    _imgFormats.resize(formatCount);
    err= clGetSupportedImageFormats(_context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D,
                                    formatCount, _imgFormats.data(), nullptr);
    if(checkCLError(err, "clGetSupportedImageFormats"))
        return false;

    return true;
}
Пример #22
0
int main(int argc, char** argv){
  glutInit(&argc, argv);
  
#if defined(OS_MAC)
  {
    char* p = strrchr(argv[0], '/');
    *p = 0;
    chdir(argv[0]);
    //puts(getcwd(NULL, 0));
  }
#endif
#if defined(OS_WIN)
  OutputDebugString(TEXT("Boot up!\n"));
#endif
  
  glutInitWindowPosition(0, 0);
  glutInitWindowSize(1280, 720);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
#if defined(OS_WIN)
  glutCreateWindow_ATEXIT_HACK("ICG SSAO");
#else
  glutCreateWindow("ICG SSAO");
#endif
  
  glutDisplayFunc(onDisplay);
  glutIdleFunc(onIdle);
  glutReshapeFunc(onReshape);
  glutKeyboardFunc(onKeyDown);
  glutSpecialFunc(onSpecialDown);
  glutMotionFunc(onMouseMotion);
  glutPassiveMotionFunc(onMousePassiveMotion);
  
  glewInit();
  
  /* ENABLE V-SYNC */
  int vsync = 1;
#if defined(OS_MAC)
  CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &vsync);
#elif defined(OS_WIN)
  if(WGLEW_EXT_swap_control)
    wglSwapIntervalEXT(vsync);
#else
  if(GLXEW_EXT_swap_control)
    glXSwapIntervalEXT(glXGetCurrentDisplay(), glXGetCurrentDrawable(), vsync);
#endif
  
  onInitialization();
#if !defined(__MINGW32__)
  atexit(onShutdown);
#endif
  
  /* NO RETURN */
  glutMainLoop();
  
  return 0;
}
Пример #23
0
Bool PUBLIC
glXSet3DfxModeMESA(int mode)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return False;
   return (t->Set3DfxModeMESA)(mode);
}
Пример #24
0
void PUBLIC
glXFreeMemoryNV( GLvoid *pointer )
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return;
   (t->FreeMemoryNV)(pointer);
}
Пример #25
0
GLuint PUBLIC
glXGetAGPOffsetMESA( const GLvoid *pointer )
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return ~0;
   return (t->GetAGPOffsetMESA)(pointer);
}
Пример #26
0
void PUBLIC
glXUseXFont(Font font, int first, int count, int listBase)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return;
   (t->UseXFont)(font, first, count, listBase);
}
Пример #27
0
void PUBLIC
glXWaitX(void)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return;
   (t->WaitX)();
}
Пример #28
0
int PUBLIC
glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t || !glXGetCurrentContext())
      return GLX_BAD_CONTEXT;
   return (t->WaitVideoSyncSGI)(divisor, remainder, count);
}
Пример #29
0
int PUBLIC
glXGetVideoSyncSGI(unsigned int *count)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t || !glXGetCurrentContext())
      return GLX_BAD_CONTEXT;
   return (t->GetVideoSyncSGI)(count);
}
Пример #30
0
int PUBLIC
glXSwapIntervalSGI(int interval)
{
   struct _glxapi_table *t;
   Display *dpy = glXGetCurrentDisplay();
   GET_DISPATCH(dpy, t);
   if (!t)
      return 0;
   return (t->SwapIntervalSGI)(interval);
}