For openGL i use lwjgl and for openCL i use jocl.
my video card rx550.
os win10pro.
This my GL Init method, i run it first.
static long window;
static void initGL(){
if(glfwInit()!=true){
System.err.println("INIT_GLFW_FAILED");
System.exit(1);
}
window=glfwCreateWindow( w, h, "test", 0, 0);
glfwShowWindow(window);
glfwMakeContextCurrent(window);
GL.createCapabilities();
glViewport(0, 0, w, h);
glOrtho(0, w, h, 0, -1, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_3D);
}
This my CL init method, i run it second.
static void initCL(){
CL.setExceptionsEnabled(true);
int numPlatformsArray[] = new int[1];
clGetPlatformIDs(0, null, numPlatformsArray);
numPlatforms=numPlatformsArray[0];
cl_platform_id platforms[] = new cl_platform_id[numPlatforms];
clGetPlatformIDs(platforms.length, platforms, null);
cl_platform_id platform = platforms[platformIndex];
int numDevicesArray[] = new int[1];
clGetDeviceIDs(platform, deviceType, 0, null, numDevicesArray);
numDevices = numDevicesArray[0];
cl_device_id devices[] = new cl_device_id[numDevices];
clGetDeviceIDs(platform, deviceType, numDevices, devices, null);
device = devices[deviceIndex];
cl_context_properties contextProperties = new cl_context_properties();
contextProperties.addProperty(CL_GL_CONTEXT_KHR,
glfwGetCurrentContext());//wglGetCurrentContext()
contextProperties.addProperty(CL_WGL_HDC_KHR, wglGetCurrentDC());
contextProperties.addProperty(CL_CONTEXT_PLATFORM, platform);
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
null, null, null);
commandQueue = clCreateCommandQueue(context, device, 0, null);
mprogram = clCreateProgramWithSource(context,1, new String[]{ program }, null, null);
clBuildProgram(mprogram, numDevices, devices, null, null, null);
mkernel = clCreateKernel(mprogram, "sampleKernel", null);
System.out.println("CLinit done");
}
And in this part he say CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR.
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, null, null, null);
I try change glfwGetCurrentContext() to wglGetCurrentContext() and to window but he say it again.
But if i remove this line
contextProperties.addProperty(CL_WGL_HDC_KHR, wglGetCurrentDC());
he run perfectly, but if i try to put texture3d
clCreateFromGLTexture3D(context, CL_MEM_READ_ONLY, GL_TEXTURE_3D, 0, GL_TEXTURE_3D, null);
he say CL_INVALID_CONTEXT.