本文整理汇总了Python中pyopencl.enqueue_release_gl_objects函数的典型用法代码示例。如果您正苦于以下问题:Python enqueue_release_gl_objects函数的具体用法?Python enqueue_release_gl_objects怎么用?Python enqueue_release_gl_objects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enqueue_release_gl_objects函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, sub_intervals):
cl.enqueue_acquire_gl_objects(self.queue, self.gl_objects)
global_size = (self.num,)
local_size = None
# set up the Kernel argument list
w = numpy.int32(640)
h = numpy.int32(480)
kernelargs = (self.pos_cl,
self.col_cl,
self.depth_cl,
self.rgb_cl,
self.pt_cl,
self.ipt_cl,
w,
h)
for i in xrange(0, sub_intervals):
self.program.project(self.queue, global_size, local_size, *(kernelargs))
#pos = numpy.ndarray((self.imsize*4, 1), dtype=numpy.float32)
#cl.enqueue_read_buffer(self.queue, self.pos_cl, pos).wait()
#for i in xrange(0, 100, 4):
# print pos[i], pos[i+1], pos[i+2], pos[i+3]
cl.enqueue_release_gl_objects(self.queue, self.gl_objects)
self.queue.finish()
示例2: initialize
def initialize():
plats = cl.get_platforms()
ctx_props = cl.context_properties
props = [(ctx_props.PLATFORM, plats[0]),
(ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())]
import sys
if sys.platform == "linux2":
props.append(
(ctx_props.GLX_DISPLAY_KHR,
GLX.glXGetCurrentDisplay()))
elif sys.platform == "win32":
props.append(
(ctx_props.WGL_HDC_KHR,
WGL.wglGetCurrentDC()))
ctx = cl.Context(properties=props)
glClearColor(1, 1, 1, 1)
glColor(0, 0, 1)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
rawGlBufferData(GL_ARRAY_BUFFER, n_vertices * 2 * 4, None, GL_STATIC_DRAW)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(2, GL_FLOAT, 0, None)
coords_dev = cl.GLBuffer(ctx, cl.mem_flags.READ_WRITE, int(vbo))
prog = cl.Program(ctx, src).build()
queue = cl.CommandQueue(ctx)
cl.enqueue_acquire_gl_objects(queue, [coords_dev])
prog.generate_sin(queue, (n_vertices,), None, coords_dev)
cl.enqueue_release_gl_objects(queue, [coords_dev])
queue.finish()
glFlush()
示例3: step
def step(self, step_size):
if len(self.network_data.gl_objects) > 0:
cl.enqueue_acquire_gl_objects(self.queue, self.network_data.gl_objects)
global_size = (len(self.units),)
kernel_args = [
self.network_data.unit_state_index_buf,
self.network_data.unit_param_index_buf,
self.network_data.state_buf,
self.network_data.params_buf,
self.network_data.unit_weight_index_buf,
self.network_data.conn_index_buf,
self.network_data.num_connections_buf,
self.network_data.weights_buf,
self.network_data.next_state_buf,
np.float32(step_size),
self.network_data.color_buf,
]
self.program.unit_step(self.queue, global_size, None, *kernel_args)
self.time += step_size
self.network_data.update_state(self.cl_context, self.queue, self.time)
if len(self.network_data.gl_objects) > 0:
cl.enqueue_release_gl_objects(self.queue, self.network_data.gl_objects)
return self.network_data.state
示例4: execute
def execute(self, subintervals):
dt = numpy.float32(self.dt)
dx = numpy.float32(self.dx)
ntracers = numpy.int32(self.ntracers)
num = numpy.int32(self.num)
choice = numpy.int32(self.params[0]) # choice)
k = numpy.float32(self.params[1]) # k)
ymin = numpy.float32(self.params[2]) # ymin)
ymax = numpy.float32(self.params[3]) # ymax)
"""
print "in execute, num", self.num
print "tracers", self.ntracers
print "choice", choice
print "k", k
print "ymin", ymin
print "ymax", ymax
print "dt", dt
print "dx", dx
"""
cl.enqueue_acquire_gl_objects(self.queue, self.gl_objects)
global_size = (self.num,)
local_size = None
kernelargs = (self.pos_cl, self.col_cl, self.pos_gen_cl, ntracers, choice, num, k, ymin, ymax, dt, dx)
for i in xrange(0, subintervals):
self.program.wave(self.queue, global_size, local_size, *(kernelargs))
cl.enqueue_release_gl_objects(self.queue, self.gl_objects)
self.queue.finish()
示例5: run
def run(self):
for ii in range(0,10):
for jj in range(0,10):
r = np.random.random([self.nsample,3])
r[:,0]=(r[:,0]+ii)*0.1
r[:,1]=(r[:,1]+jj)*0.1
self.X = np.zeros((self.nsample,4), dtype = np.float32)
self.X[:,0:3] = r
self.X[:,3] = 1.
self.I = np.zeros((self.nsample,4), dtype = np.float32)
self.I[:,0:3] = 1.
#self.I[:,3] = 0.
cl.enqueue_acquire_gl_objects(self.queue, [self.X_cl,self.I_cl])
cl.enqueue_copy(self.queue, self.X_cl, self.X)
cl.enqueue_copy(self.queue, self.I_cl, self.I)
self.program.Solve(self.queue, (self.nsample, self.na), None, self.A_cl, self.X_cl, self.I_cl, self.alpha)
cl.enqueue_release_gl_objects(self.queue, [self.X_cl,self.I_cl])
self.queue.finish()
self.draw()
self.scrnData = np.zeros((self.width,self.height), dtype = np.float32)
glReadPixels(0, 0, self.width, self.height, GL_ALPHA, GL_FLOAT, self.scrnData)
print np.max(self.scrnData)
scipy.misc.imsave('render.png', np.flipud(self.scrnData))
示例6: buildCopImageDataTexture
def buildCopImageDataTexture(self):
if not cl.have_gl():
raise BaseException("No OpenGL interop !!!")
if self.node:
# bind texture from current compy node
cl_image_buffer = self.node.getCookedData()
glBindTexture(GL_TEXTURE_2D, self.node_gl_tex_id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, self.node.xRes(), self.node.yRes(), 0, GL_RGB, GL_FLOAT, None)
logger.debug("Node size to display: %s %s" % (self.node.xRes(), self.node.yRes()))
node_gl_texture = cl.GLTexture(hou.openclContext(), cl.mem_flags.WRITE_ONLY, GL_TEXTURE_2D, 0, self.node_gl_tex_id, 2)
# Aquire OpenGL texture object
cl.enqueue_acquire_gl_objects(hou.openclQueue(), [node_gl_texture])
# copy OpenCL buffer to OpenGl texture
cl.enqueue_copy_image(hou.openclQueue(), cl_image_buffer, node_gl_texture, (0,0), (0,0), (self.node.xRes(), self.node.yRes()), wait_for=None)
# Release OpenGL texturte object
cl.enqueue_release_gl_objects(hou.openclQueue(), [node_gl_texture])
hou.openclQueue().finish()
glGenerateMipmap(GL_TEXTURE_2D) #Generate mipmaps now!!!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
glBindTexture(GL_TEXTURE_2D, 0)
示例7: execute
def execute(self, newp, t):
self.count += 1
if self.count >= self.ntracers-1:
self.count = 0
cl.enqueue_acquire_gl_objects(self.queue, self.gl_objects)
global_size = (self.ntracers,)
local_size = None
ca_kernelargs = (self.pos_cl,
self.col_cl,
self.time_cl,
self.props_cl,
np.int32(self.count),
np.float32(t),
newp,
self.params_cl
)
#print len(self.params)
self.prgs["cartist"].cartist(self.queue, global_size, local_size, *(ca_kernelargs))
cl.enqueue_release_gl_objects(self.queue, self.gl_objects)
self.queue.finish()
示例8: render_advanced
def render_advanced(self):
"""
Render particles as a fluid surface (Simon Green's screen space rendering).
"""
self._create_thickness_map()
# render depth to depth target
with self.depth_target:
self.render_point_sprites(self.depth_shader)
# smooth depth texture
if self.smooth_depth:
cl.enqueue_acquire_gl_objects(self.queue, self.cl_gl_objects)
local_size = self.cl_local_size
for i in range(self.smoothing_iterations):
# alternate between writing to depth2_target and depth1_target
# (can't read from and write to the same texture at the same time).
args = (np.float32(self.smoothing_dt),
np.float32(self.smoothing_z_contrib),)
self.prg.curvatureFlow(self.queue, self.window_size, local_size, self.depth_cl, self.depth2_cl, *args).wait()
self.prg.curvatureFlow(self.queue, self.window_size, local_size, self.depth2_cl, self.depth_cl, *args).wait()
cl.enqueue_release_gl_objects(self.queue, self.cl_gl_objects)
if self.render_mean_curvature:
cl.enqueue_acquire_gl_objects(self.queue, self.cl_gl_objects)
self.prg.test(self.queue, self.window_size, self.cl_local_size, self.depth_cl, self.test_cl).wait()
cl.enqueue_release_gl_objects(self.queue, self.cl_gl_objects)
with self.tex_shader:
self.render_texture(self.test_target.texture)
return
# # testing
# cl.enqueue_acquire_gl_objects(self.queue, [self.depth_cl, self.test_cl])
# self.prg.test(self.queue, self.depth_target.size, self.cl_local_size, self.depth_cl, self.test_cl).wait()
# with self.tex_shader:
# self.render_texture(self.test_target.texture)
# #self.render_texture(self.depth_target.texture)
# cl.enqueue_release_gl_objects(self.queue, [self.depth_cl, self.test_cl])
# return
# use alpha blending
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
# bind thickness texture
glActiveTexture(GL_TEXTURE0+1)
glBindTexture(GL_TEXTURE_2D, self.thickness_target.texture)
with self.final_shader:
self.render_texture(self.depth_target.texture)
glActiveTexture(GL_TEXTURE0)
glDisable(GL_BLEND)
示例9: step
def step(self):
"""
Advance simulation.
"""
prg = self.prg
queue = self.queue
if self.gl_interop:
cl.enqueue_acquire_gl_objects(queue, self.cl_gl_objects)
## one simulation step consists of four steps:
## step 1) assign particles to cells in the uniform grid
## step 2) compute densities
## step 3) compute accelerations from forces
## step 4) move particles according to accelerations.
## for now, simple collision detection is done in the last step.
# step 1)
if self.use_grid:
self.assign_cells()
global_size = self.global_size
local_size = self.local_size
# if we use a grid based neighbour search, we need to pass
# some additional arguments.
grid_args = [self.grid_index_cl,
self.cell_start_cl,
self.cell_end_cl] if self.use_grid else []
# step 2)
prg.stepDensity(queue, global_size, local_size,
self.position_sorted_cl if self.use_grid and self.reorder else self.position_cl,
self.density_cl,
self.pressure_cl,
self.params_cl, *grid_args).wait()
# step 3)
prg.stepForces(queue, global_size, local_size,
self.position_sorted_cl if self.use_grid and self.reorder else self.position_cl,
self.velocity_sorted_cl if self.use_grid and self.reorder else self.velocity_cl,
self.acceleration_cl,
self.density_cl,
self.pressure_cl,
self.params_cl, *grid_args).wait()
# step 4)
prg.stepMove(queue, global_size, local_size,
self.position_cl,
self.velocity_cl,
self.acceleration_cl,
self.params_cl).wait()
if self.gl_interop:
cl.enqueue_release_gl_objects(queue, self.cl_gl_objects)
示例10: execute
def execute(self, a=1.0):
if self.use_gl_texture_as_tmp:
cl.enqueue_acquire_gl_objects(self.queue, [self.cl_image, self.cl_lapl_mask, self.cl_tmp])
else:
cl.enqueue_acquire_gl_objects(self.queue, [self.cl_image, self.cl_lapl_mask])
self.program.laplace(self.queue, self.shape, None, self.cl_tmp, self.cl_image, self.cl_lapl_mask, float32(a))
self.program.laplace(self.queue, self.shape, None, self.cl_image, self.cl_tmp, self.cl_lapl_mask, float32(a))
if self.use_gl_texture_as_tmp:
cl.enqueue_release_gl_objects(self.queue, [self.cl_image, self.cl_lapl_mask, self.cl_tmp])
else:
cl.enqueue_release_gl_objects(self.queue, [self.cl_image, self.cl_lapl_mask])
示例11: execute
def execute(self):
"""Execute the OpenCL kernel.
"""
# get secure access to GL-CL interop objects
cl.enqueue_acquire_gl_objects(self.queue, [self.glclbuf])
# arguments to the OpenCL kernel
kernelargs = (self.clbuf, self.glclbuf)
# execute the kernel
self.program.clkernel(self.queue, (self.count,), None, *kernelargs)
# release access to the GL-CL interop objects
cl.enqueue_release_gl_objects(self.queue, [self.glclbuf])
self.queue.finish()
示例12: execute
def execute(self, sub_intervals):
cl.enqueue_acquire_gl_objects(self.queue, self.gl_objects)
global_size = (self.num,)
local_size = None
kernelargs = (self.pos_cl, self.col_cl, self.vel_cl, self.pos_gen_cl, self.vel_gen_cl, self.dt)
for i in xrange(0, sub_intervals):
self.program.part2(self.queue, global_size, local_size, *(kernelargs))
cl.enqueue_release_gl_objects(self.queue, self.gl_objects)
self.queue.finish()
示例13: change_display
def change_display(image) :
image_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=image)
mem = cl.GLBuffer(ctx, mf.WRITE_ONLY, numpy.float32(buf))
cl.enqueue_acquire_gl_objects(queue, [mem])
add_knl = prog.add
add_knl.set_args(image_buf, mem)
cl.enqueue_nd_range_kernel(queue, add_knl, image.shape, None)
cl.enqueue_release_gl_objects(queue, [mem])
queue.finish()
glFlush()
示例14: render
def render(self):
self.sample += 1
front_buf = self.buf[self.front]
back_buf = self.buf[1 - self.front]
self.front = 1 - self.front
prog = self.cache.get('kernels/test.cl')
cl.enqueue_acquire_gl_objects(self.queue, self.buf)
global_size = (self.width, self.height)
args = (self.cam_xform, np.int32(self.sample), self.env, back_buf, front_buf)
prog.test(self.queue, global_size, None, *args)
cl.enqueue_release_gl_objects(self.queue, self.buf)
self.queue.finish()
return front_buf.gl_object