def TestMethod(self, method): print 'Starting method', method module = pixel_format hdc = WGL.wglGetCurrentDC() items = [(name, getattr(module, name)) for name in names] failures = [] if method == pixel_format.wglGetPixelFormatAttribivARB: result = WGL.INT32() else: result = WGL.FLOAT() for item in items: try: pf = WGL.GetPixelFormat(hdc) method( hdc, pf, 0, 1, WGL.INT32(item[1]), result, ) except WindowsError, err: failures.append((item, err)) else: print '%20s\t%r' % (item[0], result.value)
def _with_context(self, hdc, proc, flush=False): old_hdc = wgl.wglGetCurrentDC() old_ctx = wgl.wglGetCurrentContext() result = wgl.wglMakeCurrent(hdc, self._win_context) try: self._with_share_group(proc) if flush: if self._win_dblbuf: wgl.SwapBuffers(hdc) else: gl.glFlush() finally: wgl.wglMakeCurrent(old_hdc, old_ctx)
def _win_supported_pixelformat(self, hdc, mode): reqpf = self._as_win_pixelformat(mode) #print "GLConfig._win_supported_pixelformat" ### #print "Requested format:" ### #win_dump_pixelformat(reqpf) ### #print "GLConfig: Choosing pixel format for hdc", hdc ### ipf = wgl.ChoosePixelFormat(hdc, reqpf) #print "... result =", ipf ### actpf = wgl.PIXELFORMATDESCRIPTOR() #print "GLConfig: Describing pixel format", ipf, "for hdc", hdc ### wgl.DescribePixelFormat(hdc, ipf, actpf.nSize, actpf) #print "Actual format:" ### #win_dump_pixelformat(actpf) ### return ipf, actpf
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()
def TestMethod( self, method ): print 'Starting method', method module = pixel_format hdc = WGL.wglGetCurrentDC() items = [(name,getattr( module, name)) for name in names ] failures = [] if method == pixel_format.wglGetPixelFormatAttribivARB: result = WGL.INT32( ) else: result = WGL.FLOAT( ) for item in items: try: pf = WGL.GetPixelFormat(hdc) method( hdc, pf, 0, 1, WGL.INT32(item[1]), result, ) except WindowsError, err: failures.append((item,err)) else: print '%20s\t%r'%( item[0], result.value)
def get_gl_sharing_context_properties(): ctx_props = cl.context_properties from OpenGL import platform as gl_platform props = [] import sys if sys.platform in ["linux", "linux2"]: from OpenGL import GLX props.append( (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext())) props.append((ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": from OpenGL import WGL props.append( (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext())) props.append((ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) elif sys.platform == "darwin": props.append((ctx_props.CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, cl.get_apple_cgl_share_group())) else: raise NotImplementedError("platform '%s' not yet supported" % sys.platform) return props
def get_gl_sharing_context_properties(): ctx_props = cl.context_properties from OpenGL import platform as gl_platform, GLX, WGL props = [] import sys if sys.platform in ["linux", "linux2"]: props.append( (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext())) props.append( (ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": props.append( (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext())) props.append( (ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) elif sys.platform == "darwin": props.append( (ctx_props.CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, cl.get_apple_cgl_share_group())) else: raise NotImplementedError("platform '%s' not yet supported" % sys.platform) return props
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()
def __init__(self): plats = cl.get_platforms() ctx_props = cl.context_properties self.props = [(ctx_props.PLATFORM, plats[0]), (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())] if sys.platform == "linux2": self.props.append((ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": self.props.append((ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) self.ctx = cl.Context(properties=self.props) self.cross4 = ElementwiseKernel( self.ctx, "__global const float4 *u, " "__global const float4 *v, " "__global const float4 *w, " "__global float4 *r", "r[i] = cross4(u[i],v[i],w[i])", "cross4_final", preamble=cross4_preamble) self.distance2 = ElementwiseKernel( self.ctx, "__global const float4 *a, " "__global const float4 *b, " "__global float4 *d", "d[i] = distance2(a[i],b[i])", "distance_final", preamble=distance_preamble) self.place_hyperspheres()
def __init__(self, share_group, config, hdc, mode): print "GLContext: mode =", mode ### GGLContext.__init__(self, share_group) shared_context = self._get_shared_context() if shared_context: share_ctx = shared_context._win_context else: share_ctx = None ipf, actpf = config._win_supported_pixelformat(hdc, mode) config._check_win_pixelformat(actpf, mode) print "GLContext: Setting pixel format", ipf, "for hdc", hdc ### wgl.SetPixelFormat(hdc, ipf, actpf) print "GLContext: Creating context for hdc", hdc ### ctx = wgl.wglCreateContext(hdc) if share_ctx: wgl.wglShareLists(share_ctx, ctx) self._win_context = ctx self._win_dblbuf = actpf.dwFlags & wgl.PFD_DOUBLEBUFFER != 0
def _get_cur_win_context(self, hdc): if threading.current_thread() in self._win_contexts: return self._win_contexts[threading.current_thread()] if hasattr(self, '_win_context'): shared_context = self._win_context else: shared_context = None ipf, actpf = self._config._win_supported_pixelformat(hdc, self._mode) self._config._check_win_pixelformat(actpf, self._mode) #print "GLContext: Setting pixel format", ipf, "for hdc", hdc ### wgl.SetPixelFormat(hdc, ipf, actpf) #print "GLContext: Creating context for hdc", hdc ### ctx = wgl.wglCreateContext(hdc) if shared_context: wgl.wglShareLists(shared_context, ctx) self._win_contexts[threading.current_thread()] = ctx return ctx
def __init__(self, share_group, config, hdc, mode): print("GLContext: mode =", mode) ### GGLContext.__init__(self, share_group) shared_context = self._get_shared_context() if shared_context: share_ctx = shared_context._win_context else: share_ctx = None ipf, act_attrs = config._win_supported_pixelformat(hdc, mode) if ipf is None: raise GLConfigError #config._check_win_pixelattrs(act_attrs, mode) print("GLContext: Setting pixel format", ipf, "for hdc", hdc) ### WGL.SetPixelFormat(hdc, ipfs) ctx = wgl.wglCreateContext(hdc) if share_ctx: wgl.wglShareLists(share_ctx, ctx) self._win_context = ctx self._win_dblbuf = actpf.dwFlags & wgl.PFD_DOUBLEBUFFER != 0
class TestContext(BaseContext): def OnInit(self): self.TestMethod(pixel_format.wglGetPixelFormatAttribivARB) self.TestMethod(pixel_format.wglGetPixelFormatAttribfvARB) def TestMethod(self, method): print 'Starting method', method module = pixel_format hdc = WGL.wglGetCurrentDC() items = [(name, getattr(module, name)) for name in names] failures = [] if method == pixel_format.wglGetPixelFormatAttribivARB: result = WGL.INT32() else: result = WGL.FLOAT() for item in items: try: pf = WGL.GetPixelFormat(hdc) method( hdc, pf, 0, 1, WGL.INT32(item[1]), result, ) except WindowsError, err: failures.append((item, err)) else: print '%20s\t%r' % (item[0], result.value) if failures: print 'FAILURES' for ((name, value), err) in failures: print name, value, '->', err items = [getattr(module, name) for name in names] try: method(hdc, WGL.GetPixelFormat(hdc), 0, 1, WGL.INT32(item[1]), result) except WindowsError, err: print method, 'failed on getting full set'
def BuildFont(self): wgldc = WGL.wglGetCurrentDC() hDC = win32ui.CreateDCFromHandle(wgldc) self.base = glGenLists(32 + 96) # // Storage For 96 Characters, plus 32 at the start... # CreateFont () takes a python dictionary to specify the requested font properties. font_properties = { "name": "Courier New", "width": 0, "height": -24, "weight": 800 } font = win32ui.CreateFont(font_properties) # // Selects The Font We Want oldfont = hDC.SelectObject(font) # // Builds 96 Characters Starting At Character 32 WGL.wglUseFontBitmaps(wgldc, 32, 96, self.base + 32) # // reset the font hDC.SelectObject(oldfont)
def get_context_properties(self, plat): #reference context properties enumeration out = [] #link OpenCL context platform out.append((context_properties.PLATFORM, plat)) #link OpenGL context out.append((context_properties.GL_CONTEXT_KHR, platform.GetCurrentContext())) #link platform specific window contexts if "GLX" in globals(): out.append((context_properties.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) if "WGL" in globals(): out.append((context_properties.WGL_HDC_KHR, WGL.wglGetCurrentDC())) #return context properties return out
def get_context_properties(self, plat): #reference context properties enumeration out = [] #link OpenCL context platform out.append((context_properties.PLATFORM, plat)) #link OpenGL context out.append( (context_properties.GL_CONTEXT_KHR, platform.GetCurrentContext())) #link platform specific window contexts if "GLX" in globals(): out.append((context_properties.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) if "WGL" in globals(): out.append((context_properties.WGL_HDC_KHR, WGL.wglGetCurrentDC())) #return context properties return out
def _as_win_pixelformat(self, mode): #print "GLConfig._as_win_pixelformat: mode =", mode ### pf = wgl.PIXELFORMATDESCRIPTOR() flags = wgl.PFD_SUPPORT_OPENGL if mode == 'screen' or mode == 'both': #print "GLConfig: requesting screen drawing" ### flags |= wgl.PFD_DRAW_TO_WINDOW if self._double_buffer: flags |= wgl.PFD_DOUBLEBUFFER | wgl.PFD_SWAP_EXCHANGE else: flags |= wgl.PFD_DOUBLEBUFFER_DONTCARE if mode == 'pixmap' or mode == 'both': #print "GLConfig: requesting pixmap drawing" ### flags |= wgl.PFD_DRAW_TO_BITMAP | wgl.PFD_SUPPORT_GDI if not self._depth_buffer: flags |= wgl.PFD_DEPTH_DONTCARE if self._stereo: flags |= wgl.PFD_STEREO else: flags |= wgl.PFD_STEREO_DONTCARE pf.dwFlags = flags & 0xffffffff pf.iPixelType = wgl.PFD_TYPE_RGBA #pf.cColorBits = 3 * self._color_size #pf.cColorBits = 32 ### pf.cRedBits = pf.cGreenBits = pf.cBluedBits = self._color_size if self._alpha: pf.cAlphaBits = self._alpha_size pf.cAuxBuffers = self._aux_buffers if self._depth_buffer: pf.cDepthBits = self._depth_size if self._stencil_buffer: pf.cStencilBits = self._stencil_size if self._accum_buffer: pf.cAccumBits = 3 * self._accum_size pf.iLayerType = wgl.PFD_MAIN_PLANE return pf
def destroy(self): wgl.wglDeleteContext(self._win_context)