Skip to content

Commit

Permalink
get_gl_object_info
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Sep 14, 2014
1 parent f1003b4 commit d3b4d00
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions TODOs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- generic_info
- Incorporate fixes in C++ stuff from after the fork
- compare and tests
- MemoryPool
- enqueue_nd_range_kernel size/offset mess

- CommandQueue.set_property
Expand Down
10 changes: 5 additions & 5 deletions pyopencl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,12 @@ def error_what(self):

# }}}

# if _cl.have_gl():
# def gl_object_get_gl_object(self):
# return self.get_gl_object_info()[1]
if _cl.have_gl():
def gl_object_get_gl_object(self):
return self.get_gl_object_info()[1]

# GLBuffer.gl_object = property(gl_object_get_gl_object)
# GLTexture.gl_object = property(gl_object_get_gl_object)
GLBuffer.gl_object = property(gl_object_get_gl_object)
GLTexture.gl_object = property(gl_object_get_gl_object)

_add_functionality()

Expand Down
6 changes: 6 additions & 0 deletions pyopencl/_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
typedef cl_bitfield cl_mem_migration_flags_ext;
/* cl_gl.h */
typedef cl_uint cl_gl_object_type;
typedef cl_uint cl_gl_texture_info;
typedef cl_uint cl_gl_platform_info;
typedef struct __GLsync *cl_GLsync;
/* c++ class pointer */
typedef struct clbase *clobj_t;
"""
Expand Down
2 changes: 2 additions & 0 deletions pyopencl/c_wrapper/wrap_cl_gl_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ error *enqueue_release_gl_objects(
clobj_t *event, clobj_t queue, const clobj_t *mem_objects,
uint32_t num_mem_objects, const clobj_t *wait_for, uint32_t num_wait_for);
cl_context_properties get_apple_cgl_share_group();
error *get_gl_object_info(clobj_t mem, cl_gl_object_type *otype,
GLuint *gl_name);
1 change: 1 addition & 0 deletions pyopencl/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def create_built_program_from_source_cached(ctx, src, options=[], devices=None,
already_built = False

except Exception, e:
raise
from pyopencl import Error
if (isinstance(e, Error)
and e.code == _cl.status_code.BUILD_PROGRAM_FAILURE):
Expand Down
14 changes: 11 additions & 3 deletions pyopencl/cffi_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,15 @@ def have_gl():
return bool(_lib.have_gl())


class GLBuffer(MemoryObject):
class _GLObject(object):
def get_gl_object_info(self):
otype = _ffi.new('cl_gl_object_type*')
gl_name = _ffi.new('GLuint*')
_handle_error(_lib.get_gl_object_info(self.ptr, otype, gl_name))
return otype[0], gl_name[0]


class GLBuffer(MemoryObject, _GLObject):
_id = 'gl_buffer'

def __init__(self, context, flags, bufobj):
Expand All @@ -1457,7 +1465,7 @@ def __init__(self, context, flags, bufobj):
self.ptr = ptr[0]


class GLRenderBuffer(MemoryObject):
class GLRenderBuffer(MemoryObject, _GLObject):
_id = 'gl_renderbuffer'

def __init__(self, context, flags, bufobj):
Expand Down Expand Up @@ -1750,7 +1758,7 @@ def __init__(self, context, normalized_coords, addressing_mode, filter_mode):

# {{{ GLTexture

class GLTexture(Image):
class GLTexture(Image, _GLObject):
_id = 'gl_texture'

def __init__(self, context, flags, texture_target, miplevel, texture, dims):
Expand Down
20 changes: 10 additions & 10 deletions src/c_wrapper/gl_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ create_from_gl_texture(const context *ctx, cl_mem_flags flags,
}
#endif

// TODO:
// PYOPENCL_INLINE
// py::tuple get_gl_object_info(memory_object_holder const &mem)
// {
// cl_gl_object_type otype;
// GLuint gl_name;
// PYOPENCL_CALL_GUARDED(clGetGLObjectInfo, (mem, &otype, &gl_name));
// return py::make_tuple(otype, gl_name);
// }

typedef cl_int (*clEnqueueGLObjectFunc)(cl_command_queue, cl_uint,
const cl_mem*, cl_uint,
const cl_event*, cl_event*);
Expand Down Expand Up @@ -155,3 +145,13 @@ get_apple_cgl_share_group()
return (cl_context_properties)kCGLShareGroup;
}
#endif /* __APPLE__ */

error*
get_gl_object_info(clobj_t mem, cl_gl_object_type *otype, GLuint *gl_name)
{
auto globj = static_cast<memory_object*>(mem);
return c_handle_error([&] {
pyopencl_call_guarded(clGetGLObjectInfo, globj, buf_arg(*otype),
buf_arg(*gl_name));
});
}

0 comments on commit d3b4d00

Please sign in to comment.