2015-01-28 4 views
0

openCL 및 openGL interop을 수행하는 간단한 프로그램을 만들려고합니다. 현재 opengl 또는 opencl 코드가 없지만 컨텍스트를 만들기 전에 프로그램이 실패합니다. 여기에 내가 실행하려고하는 코드 (컴파일 가능한 코드)가 있는데, 그렇게 비참하게 실패합니다. 코드의OpenCL OpenGL interop 컨텍스트 생성이 실패 함

#include <GL/glew.h> 
#include <GLFW/glfw3.h> 

#include <CL/cl.hpp> 

#include <iostream> 
#include <fstream> 

cl::Platform getBestPlatform() 
{ 

    std::vector<cl::Platform> platforms; 
    std::vector<cl::Device> devices; 

    cl::Platform ret; 

    cl::Platform::get(&platforms); 



    cl_int fastestNum = 0; 

    for (auto& p : platforms) 
    { 
     p.getDevices(CL_DEVICE_TYPE_ALL, &devices); 

     for (auto& d : devices) 
     { 
      cl_int speed; 
      d.getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &speed); 

      if (speed > fastestNum) 
      { 
       fastestNum = speed; 
       ret = p; 
      } 
     } 
    } 
    return ret; 
} 

int main() 
{ 
    if (!glfwInit()) 
    { 
     std::cout << "Failed to init GLFW" << std::endl; 

     return -1; 
    } 



    // set AA 
    glfwWindowHint(GLFW_SAMPLES, 1); 

    // set GL version 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 

    // set profile to core profile 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 

    // set the window to non-resizable 
    glfwWindowHint(GLFW_RESIZABLE, false); 

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenCL OpenGL", NULL, NULL); 


    // exit if the window wasn't initialized correctly 
    if (!window) 
    { 
     fprintf(stderr, "Window failed to create"); 
     glfwTerminate(); 
     return -1; 
    } 


    // make context current 
    glfwMakeContextCurrent(window); 

    // use newer GL 
    glewExperimental = GL_TRUE; 

    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); 




    if (glewInit() != GLEW_OK) 
    { 
     std::cout << "Failed to init GLEW. err code: " << glewInit() << std::endl; 
     glfwTerminate(); 
     return -1; 
    } 

    // init cl 
    cl::Platform platform = getBestPlatform(); 

    std::cout << "Using Platform: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl; 

    std::vector<cl::Device> devices; 
    platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); 

    std::cout << "Using Device: " << devices[0].getInfo<CL_DEVICE_NAME>() << std::endl; 


    cl_context_properties context_properties[] = 
    { 
     CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), 
     CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), 
     CL_CONTEXT_PLATFORM, (cl_context_properties)platform() 
    }; 

    cl_int err = CL_SUCCESS; 
    cl::Context context(devices, context_properties, NULL, NULL, &err); 

    if (err != CL_SUCCESS){ 
     std::cout << "Error creating context" << "\t" << err << "\n"; 
     exit(-1); 
    } 

    do 
    { 



     glfwPollEvents(); 
     glfwSwapBuffers(window); 

    } while (!glfwWindowShouldClose(window)); 

} 

첫 번째 비트 그냥 OpenGL을 컨텍스트 생성 물건이지만, 두 번째 부분에 관심을 지불 할 것입니다 :

는 여기있다.

죄송합니다 나는이 포함 잊었지만 컨텍스트 생성이 호출 된 후 상황에 맞는 생성에서 에러 코드이기 때문이다 출구 -30은

+0

어디에서 추락합니까? – Dan

답변

1

(CL_INVALID_VALUE는) 나는 당신의 오류로 인해 마무리하지 않도록 것 같아요 속성 목록에 NULL이 있어야합니다. 그렇지 않으면 완전히 알려지지 않은 값인 다음 매개 변수를 가져 오려고 시도하므로 CL_INVALID_VALUE 오류가 발생합니다.

cl_context_properties context_properties[] = 
{ 
    CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), 
    CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), 
    CL_CONTEXT_PLATFORM, (cl_context_properties)platform(), 
    NULL 
}; 
관련 문제