Hello,

since two days I am trying to get the sharing of a texture between
OpenGL and OpenCL working, but there must be something I am missing
here.

For now I am trying to get an OpenCL-program to fill a texture and I now
have code that does not generate any exceptions, the textures are valid
in the OpenGl world since I can fill and display them and the textures
seem valid in the OpenCL world too, since I can query their imageformat
etc. The only thing is that the program doesn't seem to have any effect.

I use this OpenCl code:

src = """
__kernel void fill_texture(write_only image2d_t out)
{
    int id0 = get_global_id(0);
    int id1 = get_global_id(1);
    write_imageui(out, (int2)( id0, id1 ), (uint4)(255, 54, 254, 255));
}

"""


this is where I initialize things:

    def initializeGL(self):
        init_all()
        self.initializeCL()
        self.yellow = np.zeros((tex_width, tex_height, 4),
dtype=np.uint8)
        self.yellow[:] = [255,255,0,0]
        self.texture2 = Texture.from_array(tex_width, tex_height,
self.yellow, dtype="uint8", planes=4)
        glFlush()
        self.prog = cl.Program(self.ctx, src).build()
        self.queue = cl.CommandQueue(self.ctx)
        mf = cl.mem_flags
        self.texture2_cl = cl.GLTexture(self.ctx, mf.READ_WRITE,
GL_TEXTURE_RECTANGLE_ARB, 0, int(self.texture2.id), 2)
        self.queue.finish()

    def initializeCL(self):
        platform = cl.get_platforms()[0]
        if sys.platform == "darwin":
            self.ctx =
cl.Context(properties=get_gl_sharing_context_properties(),
                                  devices=[])
        else:
            # Some OSs prefer clCreateContextFromType, some prefer
            # clCreateContext. Try both.
            try:
                self.ctx = cl.Context(properties=[

(cl.context_properties.PLATFORM, platform)]
                                                  +
get_gl_sharing_context_properties())
            except:
                self.ctx = cl.Context(properties=[

(cl.context_properties.PLATFORM, platform)]
                                      +
get_gl_sharing_context_properties(),
                                      devices =
[platform.get_devices()[0]])


and this is my drawing function:

    def paintGL(self):
        try:
            glFinish()
            cl.enqueue_acquire_gl_objects(self.queue,
[self.texture2_cl])
            self.prog.fill_texture(self.queue, (800,800), (32,32),
self.texture2_cl)
            cl.enqueue_release_gl_objects(self.queue,
[self.texture2_cl])
        except cl.RuntimeError: 
            raise SystemExit
        self.queue.finish()
        self.texture2.draw()

I am using a texture class I defined myself, but that works.

What am I missing ?
When looking around I was quite suprised that so few people seem to be
interested in this: there are no code examples (a few in C++) and only
some questions of people who seem to have been stuck at about the same
point as I have ? Or is this so obvious ?

If someone can illuminate me in this, I would be very grateful indeed !

kind regards,

Joost.





_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to