6 Replies Latest reply on Nov 28, 2012 2:08 AM by zoomzoom

    Re-create OpenCL-OpenGL interop

    10n02
      Problem when create, release and re-create OpenCL-OpenGL context.

      Hi everyone,

      I have a problem when I create, release and re-create OpenCL-OpenGL context. I have isolated this issue in the program folowing:

      The first iteration will succeed, and the second (or the 3rd sometime...) will fail at clCreateFromGLBuffer(), with the CL_INVALID_GL_OBJECT error.

      I don't undurstand why because I delete ALL, even the window

      Here is the output of the program:

       

      ===================START ITERATION 0

      ===================START ITERATION 1

      !!! ERROR -60 !!!!!!!!

       

       

      If you have any idea, Thx in advance

       

      Edit: Here, I do not use GLUT, in order to isolate the problem to the maximum. But Even with GLUT, I have the same problem.

      /* additional libraries used: OpenCL.lib Opengl32.lib glew32.lib */ #include <iostream> //std::cout... #include <Windows.h> // wglGetCurrentContext, wglGetCurrentDC... #include <CL/cl.h> #include <CL/cl_gl.h> #include <GL\glew.h>//include GLEW //manage OpenCL errors #define ECL_CHECK(a) { cl_int errorCode = a;\ if ( errorCode != CL_SUCCESS )\ { std::cout<<"ERROR OpenCL, error = "<<\ errorCode<<std::endl; return 0; } } //manage OpenGL errors #define EGL_CHECK() { GLenum glError = glGetError();\ if ( glError != GL_NO_ERROR ) {\ std::cout<<"ERROR OpenGL, error = "<<\ glError<<std::endl; return 0; } } //the simplest window procedure long __stdcall WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp ) { return DefWindowProc( window, msg, wp, lp ) ; } //entry point int main(int nbArg, char** args) { //the first iteration will succeed, //the second will fail with the "!!! ERROR -60 !!!!!!!!" message for(int i=0; i<10; i++) { std::cout<<"===================START ITERATION "<<i<<std::endl; ////// CREATE WINDOW ////////////////////////////// const wchar_t* const myclassName = L"myclass" ; WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, WindowProcedure, 0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION), LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1), 0, myclassName, LoadIcon(0,IDI_APPLICATION) } ; if( !RegisterClassEx(&wndclass) ) { std::cout<<"erreur RegisterClassEx"<<std::endl;return 0; } HWND hWnd = CreateWindowEx( 0, myclassName, L"test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 ) ; if ( hWnd == NULL ) { std::cout<<"erreur window"<<std::endl;return 0; } ////// CREATE WINDOW OPENGL CONTEXT ////////////////////////////// HDC windowDC = GetWindowDC(hWnd); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; // get the best available match of pixel format for the device context int iPixelFormat = ChoosePixelFormat(windowDC, &pfd); // make that the pixel format of the device context if ( !SetPixelFormat(windowDC, iPixelFormat, &pfd) ) { std::cout<<"error SetPixelFormat"<<std::endl; return 0; } HGLRC windowGLcontext = wglCreateContext(windowDC); // make it the calling thread's current rendering context if ( !wglMakeCurrent (windowDC, windowGLcontext) ) { std::cout<<"error wglMakeCurrent"<<std::endl; return 0; } //init the GLEW if ( glewInit() != GLEW_OK ) { std::cout<<"error glewInit"<<std::endl;return 0; } ////// INIT OPENCL ////////////////////////////// //get the 1st platform cl_platform_id platform; cl_uint platforms; ECL_CHECK(clGetPlatformIDs(1, &platform, &platforms)); //get the CPU device cl_device_id device[1]; cl_uint nbDevicesCPU; ECL_CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &(device[0]), &nbDevicesCPU)); if ( nbDevicesCPU != 1 ) {std::cout<<"number of device CPU != 1"<<std::endl;return 0;} ////// CREATE OPENCL interop context ////////////////////////////// //context properties cl_context_properties properties[]= { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, CL_GL_CONTEXT_KHR,(cl_context_properties) windowGLcontext, CL_WGL_HDC_KHR, (cl_context_properties) windowDC, 0 }; cl_device_id deviceUsedForContext[] = { device[0] }; cl_int errorCreateContext; cl_context openCLcontext = clCreateContext(properties, 1, deviceUsedForContext, NULL, NULL, &errorCreateContext); ECL_CHECK(errorCreateContext); ////////// create the interop buffer ////////////////////////////// GLuint bufferOpenGL; glGenBuffers(1,&bufferOpenGL); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,bufferOpenGL); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,0); EGL_CHECK(); if ( !glIsBuffer(bufferOpenGL) ) { std::cout<<"error: is NOT buffer"<<std::endl; } cl_int err; cl_mem clMemory = clCreateFromGLBuffer(openCLcontext, CL_MEM_READ_WRITE, bufferOpenGL, &err); // // ----> HERE IS THE ERROR (triggered at the second iteration (or the 3rd sometime...)) <---- // if ( err == CL_INVALID_GL_OBJECT ) { std::cout<<"!!! ERROR -60 !!!!!!!!"<<std::endl; return 0; } ECL_CHECK(err); ////////// RELEASE ALL ////////////////////////////// ECL_CHECK(clReleaseMemObject(clMemory)); glDeleteBuffers(1, &bufferOpenGL); EGL_CHECK(); ECL_CHECK(clReleaseContext(openCLcontext)); if ( 1 != ReleaseDC(hWnd,windowDC)) { std::cout<<"error ReleaseDC"<<std::endl; } if ( !wglMakeCurrent (NULL, NULL) ) { std::cout<<"error make current NULL"<<std::endl; } if ( !wglDeleteContext (windowGLcontext) ) { std::cout<<"error delete context"<<std::endl; } if ( !DestroyWindow(hWnd) ) { std::cout<<"error DestroyWindow"<<std::endl; } if ( !UnregisterClass(myclassName,NULL) ) { std::cout<<"error UnregisterClass"<<std::endl; } } std::cout<<"--- END OF PROGRAM ---"<<std::endl; return 0; }

        • Re-create OpenCL-OpenGL interop
          antzrhere

          I don't have much experience with gl buffers, but don't you have to actually allocate the buffer data with glBufferData() before you create a cl_mem object from it? Otherwise there is nothing for OpenCL to reference to? (I may be wrong)

            • Re-create OpenCL-OpenGL interop
              10n02

              Thx for your answer,

              allocate the buffer with something like:

               

               

              char randomData[] = {15,18,3};

              glBufferData(GL_ARRAY_BUFFER,

                     sizeof(randomData),randomData,GL_DYNAMIC_DRAW);



               

              doesn't solve the issue: The first iteration will succeed and the 2nd (or the 3rd sometime..) will fail

                • Re-create OpenCL-OpenGL interop
                  laobrasuca

                  EDIT:DELETE

                  EDIT 2:

                  if you use the code attached, it will work. So it has something to do with the creation/deletion of the windows, although I can't see why. So it's not necessarily related to the creation/deletion of the GL or CL context and/or buffers.

                  /* additional libraries used: OpenCL.lib Opengl32.lib glew32.lib */ #include <iostream> //std::cout... #include <Windows.h> // wglGetCurrentContext, wglGetCurrentDC... #include <CL/cl.h> #include <CL/cl_gl.h> #include <GL\glew.h>//include GLEW //manage OpenCL errors #define ECL_CHECK(a) { cl_int errorCode = a;\ if ( errorCode != CL_SUCCESS )\ { std::cout<<"ERROR OpenCL, error = "<<\ errorCode<<std::endl; return 0; } } //manage OpenGL errors #define EGL_CHECK() { GLenum glError = glGetError();\ if ( glError != GL_NO_ERROR ) {\ std::cout<<"ERROR OpenGL, error = "<<\ glError<<std::endl; return 0; } } //the simplest window procedure long __stdcall WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp ) { return DefWindowProc( window, msg, wp, lp ) ; } //entry point int main(int nbArg, char** args) { ////// CREATE WINDOW ////////////////////////////// const wchar_t* const myclassName = L"myclass" ; WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, WindowProcedure, 0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION), LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1), 0, myclassName, LoadIcon(0,IDI_APPLICATION) } ; if( !RegisterClassEx(&wndclass) ) { std::cout<<"erreur RegisterClassEx"<<std::endl;return 0; } HWND hWnd = CreateWindowEx( 0, myclassName, L"test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 ) ; if ( hWnd == NULL ) { std::cout<<"erreur window"<<std::endl;return 0; } ////// CREATE WINDOW OPENGL CONTEXT ////////////////////////////// HDC windowDC = GetWindowDC(hWnd); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; // get the best available match of pixel format for the device context int iPixelFormat = ChoosePixelFormat(windowDC, &pfd); // make that the pixel format of the device context if ( !SetPixelFormat(windowDC, iPixelFormat, &pfd) ) { std::cout<<"error SetPixelFormat"<<std::endl; return 0; } //the first iteration will succeed, //the second will fail with the "!!! ERROR -60 !!!!!!!!" message for(int i=0; i<10; i++) { std::cout<<"===================START ITERATION "<<i<<std::endl; HGLRC windowGLcontext = wglCreateContext(windowDC); // make it the calling thread's current rendering context if ( !wglMakeCurrent (windowDC, windowGLcontext) ) { std::cout<<"error wglMakeCurrent"<<std::endl; return 0; } //init the GLEW if ( glewInit() != GLEW_OK ) { std::cout<<"error glewInit"<<std::endl;return 0; } ////// INIT OPENCL ////////////////////////////// //get the 1st platform cl_platform_id platform; cl_uint platforms; ECL_CHECK(clGetPlatformIDs(1, &platform, &platforms)); //get the CPU device cl_device_id device[1]; cl_uint nbDevicesCPU; ECL_CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &(device[0]), &nbDevicesCPU)); if ( nbDevicesCPU != 1 ) {std::cout<<"number of device CPU != 1"<<std::endl;return 0;} ////// CREATE OPENCL interop context ////////////////////////////// //context properties cl_context_properties properties[]= { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, CL_GL_CONTEXT_KHR,(cl_context_properties) windowGLcontext, CL_WGL_HDC_KHR, (cl_context_properties) windowDC, 0 }; cl_device_id deviceUsedForContext[] = { device[0] }; cl_int errorCreateContext; cl_context openCLcontext = clCreateContext(properties, 1, deviceUsedForContext, NULL, NULL, &errorCreateContext); ECL_CHECK(errorCreateContext); ////////// create the interop buffer ////////////////////////////// GLuint bufferOpenGL; glGenBuffers(1,&bufferOpenGL); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,bufferOpenGL); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,0); EGL_CHECK(); if ( !glIsBuffer(bufferOpenGL) ) { std::cout<<"error: is NOT buffer"<<std::endl; } cl_int err; cl_mem clMemory = clCreateFromGLBuffer(openCLcontext, CL_MEM_READ_WRITE, bufferOpenGL, &err); // // ----> HERE IS THE ERROR (triggered at the second iteration (or the 3rd sometime...)) <---- // if ( err == CL_INVALID_GL_OBJECT ) { std::cout<<"!!! ERROR -60 !!!!!!!!"<<std::endl; return 0; } ECL_CHECK(err); ////////// RELEASE ALL ////////////////////////////// ECL_CHECK(clReleaseMemObject(clMemory)); glDeleteBuffers(1, &bufferOpenGL); EGL_CHECK(); ECL_CHECK(clReleaseContext(openCLcontext)); if ( !wglMakeCurrent (NULL, NULL) ) { std::cout<<"error make current NULL"<<std::endl; } if ( !wglDeleteContext (windowGLcontext) ) { std::cout<<"error delete context"<<std::endl; } } if ( 1 != ReleaseDC(hWnd,windowDC)) { std::cout<<"error ReleaseDC"<<std::endl; } if ( !DestroyWindow(hWnd) ) { std::cout<<"error DestroyWindow"<<std::endl; } if ( !UnregisterClass(myclassName,NULL) ) { std::cout<<"error UnregisterClass"<<std::endl; } std::cout<<"--- END OF PROGRAM ---"<<std::endl; return 0; }

                    • Re-create OpenCL-OpenGL interop
                      10n02

                      Thank you very much! Yes that works if the window creation/desctruction is done one time outside the loop... Don't know why but that solved my problem, thx!

                        • Re-create OpenCL-OpenGL interop
                          10n02

                          hi again, I have discovered another strange thing that I have isolated in the program following:

                          to run this program, you need a CPU & GPU devices.

                          The program will do the following:

                          ----------------------------------

                          Loop

                          {

                          do that:

                          1)create CPU-only context and run a Buffer Setting on CPU, destroy the context

                          or that:

                          2)create CPU-GPU context and run a Buffer Setting on GPU, destroy the context

                          }

                          -------------------------------

                           

                          The problem is : if I do 1) 2) 1) 2) 1) 2).... all 2) will fail.  But if I do 2) 1) 2) 1) 2) 1).... all succeed

                           

                          the variable "bool g_beguinWithCPU" controls if you want to beguin with the 1)CPU-only or 2)CPU-GPU.

                          If you have any idea..... thx

                           

                           

                          /* additional libraries used: OpenCL.lib Opengl32.lib glew32.lib */ #include <iostream> //std::cout... #include <Windows.h> // wglGetCurrentContext, wglGetCurrentDC... #include <CL/cl.h> #include <CL/cl_gl.h> #include "GL\glew.h"//include GLEW //manage OpenCL error #define ECL_CHECK(a) { cl_int errorCode = a;\ if ( errorCode != CL_SUCCESS )\ { std::cout<<"ERROR OpenCL, error = "<<\ errorCode<<std::endl; return 0; } } //manage OpenGL error #define EGL_CHECK() { GLenum glError = glGetError();\ if ( glError != GL_NO_ERROR ) {\ std::cout<<"ERROR OpenGL, error = "<<\ glError<<std::endl; return 0; } } //the simplest window procedure long __stdcall WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp ) { return DefWindowProc( window, msg, wp, lp ) ; } ///////////////////////////////// // if = true -> all run on GPU will fail // if = false -> all will succeed ////////////////////////////// bool g_beguinWithCPU = true; //entry point int main(int nbArg, char** args) { ////// CREATE WINDOW ////////////////////////////// const wchar_t* const myclassName = L"myclass" ; WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, WindowProcedure, 0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION), LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1), 0, myclassName, LoadIcon(0,IDI_APPLICATION) } ; if( !RegisterClassEx(&wndclass) ) { std::cout<<"erreur RegisterClassEx"<<std::endl;return 0; } HWND hWnd = CreateWindowEx( 0, myclassName, L"test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 ) ; if ( hWnd == NULL ) { std::cout<<"erreur window"<<std::endl;return 0; } ////// CREATE WINDOW OPENGL CONTEXT ////////////////////////////// HDC windowDC = GetWindowDC(hWnd); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; // get the best available match of pixel format for the device context int iPixelFormat = ChoosePixelFormat(windowDC, &pfd); // make that the pixel format of the device context if ( !SetPixelFormat(windowDC, iPixelFormat, &pfd) ) { std::cout<<"error SetPixelFormat"<<std::endl; return 0; } HGLRC windowGLcontext = wglCreateContext(windowDC); bool configCL_runOnGPU = !g_beguinWithCPU; for(int i=0; i<10; i++) { std::cout<<"=======START ITERATION "<<i; if ( configCL_runOnGPU ) { std::cout<<"(run on GPU)"<<std::endl; } else { std::cout<<"(run on CPU)"<<std::endl; } // make it the calling thread's current rendering context if ( !wglMakeCurrent (windowDC, windowGLcontext) ) { std::cout<<"error wglMakeCurrent"<<std::endl; return 0; } //init the GLEW if ( glewInit() != GLEW_OK ) { std::cout<<"error glewInit"<<std::endl;return 0; } ////// INIT OPENCL ////////////////////////////// //get the 1st platform cl_platform_id platform; cl_uint platforms; ECL_CHECK(clGetPlatformIDs(1, &platform, &platforms)); //get the CPU device cl_device_id device[2]; cl_uint nbDevicesCPU; ECL_CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &(device[0]), &nbDevicesCPU)); if ( nbDevicesCPU != 1 ) {std::cout<<"number of device CPU != 1"<<std::endl;return 0;} //get the GPU device if ( configCL_runOnGPU ) { cl_uint nbDevicesGPU; ECL_CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &(device[1]), &nbDevicesGPU)); if ( nbDevicesGPU != 1 ) {std::cout<<"number of device GPU != 1"<<std::endl;return 0;} } ////// CREATE OPENCL interop context ////////////////////////////// //context properties cl_context_properties properties[]= { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, CL_GL_CONTEXT_KHR,(cl_context_properties) windowGLcontext, CL_WGL_HDC_KHR, (cl_context_properties) windowDC, 0 }; cl_int nbDevicesUsed; cl_device_id deviceUsedForContext[2]; cl_device_id deviceRun; if ( configCL_runOnGPU ) { nbDevicesUsed = 2; deviceUsedForContext[0] = device[0] ; deviceUsedForContext[1] = device[1] ; deviceRun = device[1] ; } else { nbDevicesUsed = 1; deviceUsedForContext[0] = device[0] ; deviceRun = device[0] ; } cl_int errorCreateContext; cl_context openCLcontext = clCreateContext(properties, nbDevicesUsed, deviceUsedForContext, NULL, NULL, &errorCreateContext); ECL_CHECK(errorCreateContext); cl_int errorCreateCommandQueue; cl_command_queue commandQueueCL = clCreateCommandQueue( openCLcontext, deviceRun, 0, &errorCreateCommandQueue); ECL_CHECK(errorCreateCommandQueue); ////////// CREATE THE INTEROP BUFFER ////////////////////////////// GLuint bufferOpenGL; glGenBuffers(1,&bufferOpenGL); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,bufferOpenGL); EGL_CHECK(); char randomData[] = {15,18,3,8}; //fill it with random data glBufferData(GL_ARRAY_BUFFER,sizeof(randomData),randomData,GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER,0); EGL_CHECK(); if ( !glIsBuffer(bufferOpenGL) ) { std::cout<<"error: is NOT buffer"<<std::endl; } cl_int errCreateFromGL; cl_mem clMemory = clCreateFromGLBuffer(openCLcontext, CL_MEM_READ_WRITE, bufferOpenGL, &errCreateFromGL); //error triggered if we create de window inside the loop if ( errCreateFromGL == CL_INVALID_GL_OBJECT ) { std::cout<<"!!! ERROR -60 !!!!!!!!"<<std::endl; return 0; } ECL_CHECK(errCreateFromGL); //get and check the size of the CL buffer size_t sizeCLbuffer; size_t sizeValueReturned; ECL_CHECK(clGetMemObjectInfo(clMemory,CL_MEM_SIZE,sizeof(size_t),&sizeCLbuffer,&sizeValueReturned)); if ( sizeValueReturned != sizeof(size_t) ) {std::cout<<"error clGetMemObjectInfo"<<std::endl; return 0;} //error triggered if wglCreateContext is called inside the loop if ( sizeCLbuffer != sizeof(randomData) ) { std::cout<<"error size CL buffer != size GL buffer"<<std::endl; } ////////// OPENCL CHECKS AND MODIFY THE OPENGL BUFFER ////////////////////////////// glFinish(); EGL_CHECK(); cl_event clevent; ECL_CHECK(clEnqueueAcquireGLObjects(commandQueueCL,1, &clMemory, 0, 0, &clevent)); ECL_CHECK(clWaitForEvents(1,&clevent)); cl_int errClEnqueueMapBuffer; char* dataMapped = (char*)clEnqueueMapBuffer ( commandQueueCL,clMemory, CL_TRUE,CL_MAP_WRITE | CL_MAP_READ,0,sizeof(randomData), 0, 0, &clevent, &errClEnqueueMapBuffer); ECL_CHECK(errClEnqueueMapBuffer); ECL_CHECK(clWaitForEvents(1,&clevent)); if ( dataMapped[0] != randomData[0] || dataMapped[1] != randomData[1] || dataMapped[2] != randomData[2] || dataMapped[3] != randomData[3] ) { std::cout<<"error not corresponding for openCL"<<std::endl; } //increment by random values (here: 1,2,3,4) dataMapped[0] += 1; dataMapped[1] += 2; dataMapped[2] += 3; dataMapped[3] += 4; ECL_CHECK(clEnqueueUnmapMemObject( commandQueueCL,clMemory,dataMapped, 0, 0, &clevent)); ECL_CHECK(clWaitForEvents(1,&clevent)); ECL_CHECK(clEnqueueReleaseGLObjects(commandQueueCL,1, &clMemory, 0, 0, &clevent)); ECL_CHECK(clWaitForEvents(1,&clevent)); clFinish(commandQueueCL); ////////// OPENGL CHECKS THAT THE MODIFICATION HAS BEEN DONE ////////////////////////////// glBindBuffer(GL_ARRAY_BUFFER,bufferOpenGL); EGL_CHECK(); char* dataMappedGL = (char*)glMapBuffer(GL_ARRAY_BUFFER,GL_READ_WRITE); EGL_CHECK(); //check that the increment by random values has been done if ( dataMapped[0] != randomData[0]+1 || dataMapped[1] != randomData[1]+2 || dataMapped[2] != randomData[2]+3 || dataMapped[3] != randomData[3]+4 ) { std::cout<<"error not corresponding for OpenGL"<<std::endl; } glUnmapBuffer(GL_ARRAY_BUFFER); EGL_CHECK(); glBindBuffer(GL_ARRAY_BUFFER,0); EGL_CHECK(); ////////// RELEASE ALL ////////////////////////////// ECL_CHECK(clReleaseCommandQueue(commandQueueCL)); ECL_CHECK(clReleaseMemObject(clMemory)); ECL_CHECK(clReleaseContext(openCLcontext)); glDeleteBuffers(1, &bufferOpenGL); EGL_CHECK(); if ( !wglMakeCurrent (NULL, NULL) ) { std::cout<<"error make current NULL"<<std::endl; } configCL_runOnGPU = !configCL_runOnGPU; Sleep(30); //useless, but I prefere } if ( !wglDeleteContext (windowGLcontext) ) { std::cout<<"error delete context"<<std::endl; } if ( 1 != ReleaseDC(hWnd,windowDC)) { std::cout<<"error ReleaseDC"<<std::endl; } if ( !DestroyWindow(hWnd) ) { std::cout<<"error DestroyWindow"<<std::endl; } if ( !UnregisterClass(myclassName,NULL) ) { std::cout<<"error UnregisterClass"<<std::endl; } std::cout<<"--- END OF PROGRAM ---"<<std::endl; return 0; }