def _get_arb_pixel_format_matching_configs(self, canvas): '''Get configs using the WGL_ARB_pixel_format extension. This method assumes a (dummy) GL context is already created.''' # Check for required extensions if self.sample_buffers or self.samples: if not gl_info.have_extension('GL_ARB_multisample'): return [] # Construct array of attributes attrs = [] for name, value in self.get_gl_attributes(): attr = Win32CanvasConfigARB.attribute_ids.get(name, None) if attr and value is not None: attrs.extend([attr, int(value)]) attrs.append(0) attrs = (c_int * len(attrs))(*attrs) pformats = (c_int * 16)() nformats = c_uint(16) wglext_arb.wglChoosePixelFormatARB(canvas.hdc, attrs, None, nformats, pformats, nformats) formats = [Win32CanvasConfigARB(canvas, pf, self) \ for pf in pformats[:nformats.value]] return formats
def load_image(self): if not gl_info.have_extension('GL_ARB_imaging'): print 'GL_ARB_imaging is not present, skipping test.' self.has_exit = True else: # Load image as usual then rearrange components super(TEST_MATRIX_RGBA, self).load_image() pixels = self.image.get_data('GBAR', self.image.width * 4)
def require_gl_extension(extension): """ Skip the test if the given GL extension is not available. :param str extension: Name of the extension required. """ return pytest.mark.skipif(not gl_info.have_extension(extension), reason='Tests requires GL extension {0}'.format(extension))
def load_image(self): if not gl_info.have_extension('GL_ARB_imaging'): print('GL_ARB_imaging is not present, skipping test.') self.has_exit = True else: # Load image as usual then rearrange components super(TEST_MATRIX_RGBA, self).load_image() pixels = self.image.get_data('GBAR', self.image.width * 4)
def load_image(self): if not gl_info.have_extension('GL_ARB_imaging'): print('GL_ARB_imaging is not present, skipping test.') self.has_exit = True else: # Load image as usual then rearrange components super(TEST_MATRIX_RGB, self).load_image() self.image.format = 'GRB' pixels = self.image.data # forces conversion
def load_image(self): if not gl_info.have_extension('GL_ARB_imaging'): print 'GL_ARB_imaging is not present, skipping test.' self.has_exit = True else: # Load image as usual then rearrange components super(TEST_MATRIX_RGB, self).load_image() self.image.format = 'GRB' pixels = self.image.data # forces conversion
def _setOpenGLInfo(self): # OpenGL info: self['openGLVendor'] = gl_info.get_vendor() self['openGLRenderingEngine'] = gl_info.get_renderer() self['openGLVersion'] = gl_info.get_version() GLextensionsOfInterest=['GL_ARB_multitexture', 'GL_EXT_framebuffer_object','GL_ARB_fragment_program', 'GL_ARB_shader_objects','GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two','GL_ARB_texture_float'] for ext in GLextensionsOfInterest: self['openGLext.'+ext] = bool(gl_info.have_extension(ext))
def _setOpenGLInfo(self): # OpenGL info: self['openGLVendor'] = gl_info.get_vendor() self['openGLRenderingEngine'] = gl_info.get_renderer() self['openGLVersion'] = gl_info.get_version() GLextensionsOfInterest = [ 'GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float' ] for ext in GLextensionsOfInterest: self['openGLext.' + ext] = bool(gl_info.have_extension(ext))
def _setOpenGLInfo(self): # OpenGL info: self['openGLVendor'] = gl_info.get_vendor() self['openGLRenderingEngine'] = gl_info.get_renderer() self['openGLVersion'] = gl_info.get_version() GLextensionsOfInterest = ['GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float', 'GL_STEREO'] for ext in GLextensionsOfInterest: self['openGLext.'+ext] = bool(gl_info.have_extension(ext)) maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) self['openGLmaxVerticesInVertexArray'] = maxVerts.value
def _get_gl_format_and_type(self, format): if format == 'I': return GL_LUMINANCE, GL_UNSIGNED_BYTE elif format == 'L': return GL_LUMINANCE, GL_UNSIGNED_BYTE elif format == 'LA': return GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE elif format == 'R': return GL_RED, GL_UNSIGNED_BYTE elif format == 'G': return GL_GREEN, GL_UNSIGNED_BYTE elif format == 'B': return GL_BLUE, GL_UNSIGNED_BYTE elif format == 'A': return GL_ALPHA, GL_UNSIGNED_BYTE elif format == 'RGB': return GL_RGB, GL_UNSIGNED_BYTE elif format == 'RGBA': return GL_RGBA, GL_UNSIGNED_BYTE elif (format == 'ARGB' and gl_info.have_extension('GL_EXT_bgra') and gl_info.have_extension('GL_APPLE_packed_pixels')): return GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV elif (format == 'ABGR' and gl_info.have_extension('GL_EXT_abgr')): return GL_ABGR_EXT, GL_UNSIGNED_BYTE elif (format == 'BGR' and gl_info.have_extension('GL_EXT_bgra')): return GL_BGR, GL_UNSIGNED_BYTE elif (format == 'BGRA' and gl_info.have_extension('GL_EXT_bgra')): return GL_BGRA, GL_UNSIGNED_BYTE elif (format == 'ABGR1555'): return GL_BGRA,GL_UNSIGNED_SHORT_1_5_5_5_REV return None, None
def __init__(self, wrap = GL_REPEAT, filter = GL_LINEAR, min_filter = None): if self.max_anisotropy == 0.0 and \ gl_info.have_extension('GL_EXT_texture_filter_anisotropic'): v = c_float() glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, byref(v)) self.max_anisotropy = v.value if min_filter is None: min_filter = filter self.min_filter = min_filter self.mag_filter = filter self.min_lod = -1000 self.max_lod = 1000 self.min_mipmap = 0 self.max_mipmap = 1000 self.wrap_s = wrap self.wrap_t = wrap self.wrap_r = wrap self.priority = 0 self.anisotropy = 1.0 self.border_colour = c_float4(0.0, 0.0, 0.0, 0.0)
def _init_texture(self, player): if not self.video_format: return width = self.video_format.width height = self.video_format.height if gl_info.have_extension('GL_ARB_texture_rectangle'): texture = image.Texture.create_for_size( gl.GL_TEXTURE_RECTANGLE_ARB, width, height, internalformat=gl.GL_RGB) else: texture = image.Texture.create_for_size( gl.GL_TEXTURE_2D, width, height, internalformat=gl.GL_RGB) if texture.width != width or texture.height != height: texture = texture.get_region(0, 0, width, height) player._texture = texture # Flip texture coords (good enough for simple apps). bl, br, tr, tl = player._texture.tex_coords player._texture.tex_coords = tl, tr, br, bl
def _init_texture(self, player): if not self.video_format: return width = self.video_format.width height = self.video_format.height if gl_info.have_extension('GL_ARB_texture_rectangle'): texture = image.Texture.create_for_size( gl.GL_TEXTURE_RECTANGLE_ARB, width, height, internalformat=gl.GL_RGB) else: texture = image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height, internalformat=gl.GL_RGB) if texture.width != width or texture.height != height: texture = texture.get_region(0, 0, width, height) player._texture = texture # Flip texture coords (good enough for simple apps). t = list(player._texture.tex_coords) player._texture.tex_coords = t[9:12] + t[6:9] + t[3:6] + t[:3]
import pyglet print("pyglet", pyglet.version) # pyo is a new dependency, for sound: try: import pyo print("pyo", '%i.%i.%i' % pyo.getVersion()) except Exception: print('pyo [not installed]') from psychopy import __version__ print("\nPsychoPy", __version__) win = visual.Window([100, 100]) # some drivers want a window open first print("have shaders:", win._haveShaders) print("\nOpenGL info:") # get info about the graphics card and drivers print("vendor:", gl_info.get_vendor()) print("rendering engine:", gl_info.get_renderer()) print("OpenGL version:", gl_info.get_version()) print("(Selected) Extensions:") extensionsOfInterest = ['GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float', 'GL_STEREO'] for ext in extensionsOfInterest: print("\t", bool(gl_info.have_extension(ext)), ext) # also determine nVertices that can be used in vertex arrays maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) print('\tmax vertices in vertex array:', maxVerts.value)
from pyglet.gl import gl_info assert gl_info.have_extension("GL_ARB_point_sprite"), "ARB_point_sprite not available" from pyglet.gl import * import random # see: # http://www.opengl.org/registry/specs/ARB/point_sprite.txt # http://www.opengl.org/registry/specs/ARB/point_parameters.txt g_slowdown = 2.0 # Query for the max point size supported by the hardware g_maxSize = c_float(0.0) glGetFloatv(GL_POINT_SIZE_MAX_ARB, pointer(g_maxSize)) # Clamp size to 100.0f or the sprites could get a little too big on some of the # newer graphic cards. My ATI card at home supports a max point size of 1024.0! if (g_maxSize.value > 100.0): g_maxSize.value = 100.0 def draw_task(texture_id): particles = [{ 'life': 1.0, 'fade': random.uniform(0.1, 0.004), #'r': 1.0, 'g': 1.0, 'b': 1.0, 'r': 0.32, 'g': 0.32, 'b': 0.32, 'x': 0.0, 'y': 0.0, 'z': 0.0, 'xi': float(random.randint(-250, 250)), 'yi': float(random.randint(-250, 250)), 'zi': float(random.randint(-250, 250)), 'xg': 0.0, 'yg': -0.8, 'zg': 0.0, } for i in xrange(1000)]
def getInfoText(self): """Get system information text.""" outputText = "" # text to return # show the PsychoPy version from psychopy import __version__ outputText += self.getLine("PsychoPy", __version__) # get system paths outputText += self.getLine("\nPaths to files on the system:") for key in ['userPrefsFile', 'appDataFile', 'demos', 'appFile']: outputText += self.getLine( " %s: %s" % (key, preferences.prefs.paths[key])) # system information such as OS, CPU and memory outputText += self.getLine("\nSystem Info:") outputText += self.getLine( ' '*4, 'Operating System: {}'.format(platform.platform())) outputText += self.getLine( ' ' * 4, 'Processor: {}'.format(platform.processor())) # requires psutil try: import psutil outputText += self.getLine( ' ' * 4, 'CPU freq (MHz): {}'.format(psutil.cpu_freq().max)) outputText += self.getLine( ' ' * 4, 'CPU cores: {} (physical), {} (logical)'.format( psutil.cpu_count(False), psutil.cpu_count())) outputText += self.getLine( ' ' * 4, 'Installed memory: {} (Total), {} (Available)'.format( *psutil.virtual_memory())) except ImportError: outputText += self.getLine(' ' * 4, 'CPU freq (MHz): N/A') outputText += self.getLine( ' ' * 4, 'CPU cores: {} (logical)'.format(os.cpu_count())) outputText += self.getLine(' ' * 4, 'Installed memory: N/A') # if on MacOS if sys.platform == 'darwin': OSXver, junk, architecture = platform.mac_ver() outputText += self.getLine( ' ' * 4, "macOS %s running on %s" % (OSXver, architecture)) # Python information outputText += self.getLine("\nPython info:") outputText += self.getLine(' '*4, 'Executable path:', sys.executable) outputText += self.getLine(' '*4, 'Version:', sys.version) outputText += self.getLine(' ' * 4, '(Selected) Installed Packages:') import numpy outputText += self.getLine(' '*8, "numpy ({})".format( numpy.__version__)) import scipy outputText += self.getLine(' '*8, "scipy ({})".format( scipy.__version__)) import matplotlib outputText += self.getLine(' '*8, "matplotlib ({})".format( matplotlib.__version__)) import pyglet outputText += self.getLine(' '*8, "pyglet ({})".format(pyglet.version)) try: import glfw outputText += self.getLine(' '*8, "PyGLFW ({})".format( glfw.__version__)) except Exception: outputText += self.getLine(' '*8, 'PyGLFW [not installed]') # sound related try: import pyo outputText += self.getLine( ' '*8, "pyo", ('%i.%i.%i' % pyo.getVersion())) except Exception: outputText += self.getLine(' '*8, 'pyo [not installed]') try: import psychtoolbox outputText += self.getLine(' '*8, "psychtoolbox ({})".format( psychtoolbox._version.__version__)) except Exception: outputText += self.getLine(' '*8, 'psychtoolbox [not installed]') # wxpython version try: import wx outputText += self.getLine(' '*8, "wxPython ({})".format( wx.__version__)) except Exception: outputText += self.getLine(' '*8, 'wxPython [not installed]') # get OpenGL details win = visual.Window([100, 100]) # some drivers want a window open first outputText += self.getLine("\nOpenGL Info:") # # get info about the graphics card and drivers outputText += self.getLine( ' '*4, "Vendor:", gl_info.get_vendor()) outputText += self.getLine( ' '*4, "Rendering engine:", gl_info.get_renderer()) outputText += self.getLine( ' '*4, "OpenGL version:", gl_info.get_version()) outputText += self.getLine( ' '*4, "Shaders supported: ", win._haveShaders) # get opengl extensions outputText += self.getLine(' '*4, "(Selected) Extensions:") extensionsOfInterest = [ 'GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float', 'GL_STEREO'] for ext in extensionsOfInterest: outputText += self.getLine( ' '*8, ext + ':', bool(gl_info.have_extension(ext))) # also determine nVertices that can be used in vertex arrays maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) outputText += self.getLine( ' '*4, 'max vertices in vertex array:', maxVerts.value) win.close() return outputText
def getSysInfo(win): from collections import OrderedDict # based on sysInfo.py from pyglet.gl import gl_info, GLint, glGetIntegerv, GL_MAX_ELEMENTS_VERTICES import sys, platform sys_info = OrderedDict() sys_info['OS'] = OrderedDict() sys_info['OS']['Name'] = platform.platform() if sys.platform == 'darwin': OSXver, _, architecture = platform.mac_ver() sys_info['OS']['OSX Version'] = OSXver sys_info['OS']['OSX Architecture'] = architecture sys_info['Computer Hardware'] = OrderedDict() try: import psutil def getMemoryInfo(): rdict = dict() nt = psutil.virtual_memory() for name in nt._fields: value = getattr(nt, name) if name != 'percent': value = bytes2human(value) rdict[name.capitalize()] = value # '%s%s%-10s : %7s\n'%(rstr, '\t' * indent, name.capitalize(), value) return rdict core_count = psutil.cpu_count(logical=False) logical_psu_count = psutil.cpu_count() memory_info = getMemoryInfo() sys_info['Computer Hardware']['CPUs (cores / logical)'] = (core_count, logical_psu_count) sys_info['Computer Hardware']['System Memory'] = memory_info except Exception: sys_info['Computer Hardware']['Failed'] = 'psutil 2.x + is required.' sys_info['Python'] = OrderedDict() sys_info['Python']['exe'] = sys.executable sys_info['Python']['version'] = sys.version sys_info['Packages'] = OrderedDict() try: import numpy sys_info['Packages']['numpy'] = numpy.__version__ except ImportError: sys_info['Packages']['numpy'] = "Not Installed" try: import pyglet sys_info['Packages']['pyglet'] = pyglet.version except ImportError: sys_info['Packages']['pyglet'] = "Not Installed" try: import cv2 sys_info['Packages']['cv2'] = cv2.__version__ except ImportError: sys_info['Packages']['cv2'] = "Not Installed" try: import psychopy sys_info['Packages']['PsychoPy'] = psychopy.__version__ except ImportError: sys_info['Packages']['PsychoPy'] = "Not Installed" sys_info['Graphics'] = OrderedDict() sys_info['Graphics']['shaders'] = win._haveShaders sys_info['Graphics']['opengl'] = OrderedDict() sys_info['Graphics']['opengl']['version'] = gl_info.get_version() sys_info['Graphics']['opengl']['vendor'] = gl_info.get_vendor() sys_info['Graphics']['opengl']['engine'] = gl_info.get_renderer() maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) sys_info['Graphics']['opengl']['Max vert in VA'] = maxVerts.value sys_info['Graphics']['opengl']['extensions'] = OrderedDict() extensionsOfInterest = ['GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float', 'GL_STEREO'] for ext in extensionsOfInterest: sys_info['Graphics']['opengl']['extensions'][ext] = bool(gl_info.have_extension(ext)) sys_info['Processes'] = OrderedDict() if sys.platform == 'darwin': sys_info['Processes']['Failed'] = 'Not Supported on OSX.' elif SAVE_PER_PROCESS_DATA: try: import psutil for proc in psutil.process_iter(): pkey = proc.pid vattrs = ['name', 'exe', 'ppid', 'num_threads', 'memory_percent', 'cpu_percent', 'cpu_affinity', 'nice', 'num_ctx_switches'] procinfo = proc.as_dict(attrs=vattrs, ad_value=u"Access Denied") if procinfo['exe'] is not u"Access Denied" and (SAVE_PER_PROCESS_DATA is True or SAVE_PER_PROCESS_DATA == procinfo['name']): sys_info['Processes'][pkey] = procinfo except ImportError: sys_info['Processes']['Failed'] = 'psutil 2.x + is required.' else: sys_info['Processes']['Disabled'] = 'Per Process details disabled by user.' return sys_info
def supported(): " Requires OpenGL >= 3.2 && GLSL >= 1.50 " return check_requirements(target_gl=(3,2), target_glsl=(1,50)) and gl_info.have_extension('GL_ARB_gpu_shader_fp64')
# -- own -- # -- code -- class ShaderError(Exception): pass def _get_infolog(oid): buffer = create_string_buffer(3000) i = GLsizei(0) glGetInfoLogARB(oid, 3000, byref(i), cast(byref(buffer), POINTER(c_char))) return buffer.value HAVE_SHADER = gl_info.have_extension('GL_ARB_shader_objects') class _Shader(object): def __new__(cls, *a): if HAVE_SHADER: return object.__new__(cls, *a) else: return None def __init__(self, src): sid = False try: sid = glCreateShaderObjectARB(self.shader_type) except GLException: pass
# http://www.opengl.org/registry/specs/ARB/point_parameters.txt from pyglet.gl import gl_info assert gl_info.have_extension("GL_ARB_point_parameters"), "ARB_point_parameters not available" from pyglet.gl import * import random import math g_slowdown = 2.0 # Query for the max point size supported by the hardware maxSize = c_float(0.0) maxSize = GLfloat(0.0) glGetFloatv(GL_POINT_SIZE_MAX_ARB, maxSize) print "GL_POINT_SIZE_MAX_ARB", maxSize.value # 256.0 def draw_task(texture_id, size, pos): particles = [{ 'life': 1.0, 'fade': random.uniform(0.1, 0.004), 'r': 1.0, 'g': 1.0, 'b': 1.0, 'x': 0.0, 'y': 0.0, 'z': 0.0, 'xi': float(random.randint(-250, 250)), 'yi': 0.0,#float(random.randint(-250, 250)), 'zi': float(random.randint(-250, 250)), 'xg': 0.0, 'yg': -0.8, 'zg': 0.0, } for i in xrange(50)] mat = (GLfloat*16)() viewport = (GLint*4)()
pass def _get_infolog(oid): buffer = create_string_buffer(3000) i = GLsizei(0) glGetInfoLogARB( oid, 3000, byref(i), cast( byref(buffer), POINTER(c_char) ) ) return buffer.value HAVE_SHADER = gl_info.have_extension('GL_ARB_shader_objects') class _Shader(object): def __new__(cls, *a): if HAVE_SHADER: return object.__new__(cls, *a) else: return None def __init__(self, src): sid = False try: sid = glCreateShaderObjectARB(self.shader_type) except GLException: pass
def renderToTexture(w, h, function): import ctypes from pyglet import gl from pyglet import image from pyglet.gl import gl_info global has_fbo if has_fbo is None: has_fbo = gl_info.have_extension('GL_EXT_framebuffer_object') # enforce dimensions are ints w, h = int(w), int(h) # set up viewport gl.glPushAttrib(gl.GL_VIEWPORT_BIT | gl.GL_TRANSFORM_BIT) gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.glOrtho(0, w, 0, h, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) if has_fbo: # render directly to texture # create our frame buffer fbo = gl.GLuint() gl.glGenFramebuffersEXT(1, ctypes.byref(fbo)) gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo) # allocate a texture and add to the frame buffer tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h, gl.GL_RGBA) gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id) gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, tex.id, 0) status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT) assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT # now render gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo) function() gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0) # clean up gl.glDeleteFramebuffersEXT(1, ctypes.byref(fbo)) else: # render and copy to texture # render function() # grab the buffer and copy contents to the texture buffer = image.get_buffer_manager().get_color_buffer() tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h, gl.GL_RGBA) tex.blit_into(buffer.get_region(0, 0, w, h), 0, 0, 0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPopMatrix() gl.glPopAttrib() # return the region (the whole texture will most likely be larger) return tex.get_region(0, 0, w, h)
def getSysInfo(win): try: from collections import OrderedDict except Exception: from psychopy.iohub import OrderedDict # based on sysInfo.py from pyglet.gl import gl_info, GLint, glGetIntegerv, GL_MAX_ELEMENTS_VERTICES import sys, platform sys_info = OrderedDict() sys_info['OS'] = OrderedDict() sys_info['OS']['Name'] = platform.platform() if sys.platform == 'darwin': OSXver, _, architecture = platform.mac_ver() sys_info['OS']['OSX Version'] = OSXver sys_info['OS']['OSX Architecture'] = architecture sys_info['Computer Hardware'] = OrderedDict() try: import psutil def getMemoryInfo(): rdict = dict() nt = psutil.virtual_memory() for name in nt._fields: value = getattr(nt, name) if name != 'percent': value = bytes2human(value) rdict[name.capitalize( )] = value # '%s%s%-10s : %7s\n'%(rstr, '\t' * indent, name.capitalize(), value) return rdict core_count = psutil.cpu_count(logical=False) logical_psu_count = psutil.cpu_count() memory_info = getMemoryInfo() sys_info['Computer Hardware']['CPUs (cores / logical)'] = ( core_count, logical_psu_count) sys_info['Computer Hardware']['System Memory'] = memory_info except Exception: sys_info['Computer Hardware']['Failed'] = 'psutil 2.x + is required.' sys_info['Python'] = OrderedDict() sys_info['Python']['exe'] = sys.executable sys_info['Python']['version'] = sys.version sys_info['Packages'] = OrderedDict() try: import numpy sys_info['Packages']['numpy'] = numpy.__version__ except ImportError: sys_info['Packages']['numpy'] = "Not Installed" try: import pyglet sys_info['Packages']['pyglet'] = pyglet.version except ImportError: sys_info['Packages']['pyglet'] = "Not Installed" try: import cv2 sys_info['Packages']['cv2'] = cv2.__version__ except ImportError: sys_info['Packages']['cv2'] = "Not Installed" try: import psychopy sys_info['Packages']['PsychoPy'] = psychopy.__version__ except ImportError: sys_info['Packages']['PsychoPy'] = "Not Installed" sys_info['Graphics'] = OrderedDict() sys_info['Graphics']['shaders'] = win._haveShaders sys_info['Graphics']['opengl'] = OrderedDict() sys_info['Graphics']['opengl']['version'] = gl_info.get_version() sys_info['Graphics']['opengl']['vendor'] = gl_info.get_vendor() sys_info['Graphics']['opengl']['engine'] = gl_info.get_renderer() maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) sys_info['Graphics']['opengl']['Max vert in VA'] = maxVerts.value sys_info['Graphics']['opengl']['extensions'] = OrderedDict() extensionsOfInterest = [ 'GL_ARB_multitexture', 'GL_EXT_framebuffer_object', 'GL_ARB_fragment_program', 'GL_ARB_shader_objects', 'GL_ARB_vertex_shader', 'GL_ARB_texture_non_power_of_two', 'GL_ARB_texture_float', 'GL_STEREO' ] for ext in extensionsOfInterest: sys_info['Graphics']['opengl']['extensions'][ext] = bool( gl_info.have_extension(ext)) sys_info['Processes'] = OrderedDict() if sys.platform == 'darwin': sys_info['Processes']['Failed'] = 'Not Supported on OSX.' elif SAVE_PER_PROCESS_DATA: try: import psutil for proc in psutil.process_iter(): pkey = proc.pid vattrs = [ 'name', 'exe', 'ppid', 'num_threads', 'memory_percent', 'cpu_percent', 'cpu_affinity', 'nice', 'num_ctx_switches' ] procinfo = proc.as_dict(attrs=vattrs, ad_value=u"Access Denied") if procinfo['exe'] is not u"Access Denied" and ( SAVE_PER_PROCESS_DATA is True or SAVE_PER_PROCESS_DATA == procinfo['name']): sys_info['Processes'][pkey] = procinfo except ImportError: sys_info['Processes']['Failed'] = 'psutil 2.x + is required.' else: sys_info['Processes'][ 'Disabled'] = 'Per Process details disabled by user.' return sys_info
def normal_sphere(r, divide, tex, normal, lighting=True, fv4=GLfloat * 4): if (not have_extension('GL_ARB_multitexture') or not have_extension('GL_ARB_texture_env_combine') or not have_extension('GL_EXT_texture_env_dot3')): print 'No hardware normal mapping support. No bumping for you.' return sphere(r, divide, divide, tex, lighting) from texture import load_texture normal = load_texture(normal) with glRestore(GL_ENABLE_BIT | GL_TEXTURE_BIT): glEnable(GL_CULL_FACE) glCullFace(GL_BACK) glActiveTextureARB(GL_TEXTURE0_ARB) glBindTexture(GL_TEXTURE_2D, normal) glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB) glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB) glActiveTextureARB(GL_TEXTURE1_ARB) glBindTexture(GL_TEXTURE_2D, tex) glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB) glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE) if lighting: glDisable(GL_BLEND) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, fv4(1, 1, 1, 0)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, fv4(1, 1, 1, 0)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 125) else: glDisable(GL_LIGHTING) glBindTexture(GL_TEXTURE_2D, tex) twopi_divide = TWOPI / divide pi_divide = pi / divide with glSection(GL_TRIANGLE_STRIP): for j in xrange(divide + 1): phi1 = j * twopi_divide phi2 = (j + 1) * twopi_divide for i in xrange(divide + 1): theta = i * pi_divide s = phi2 / TWOPI t = theta / pi dx, dy, dz = sin(theta) * cos(phi2), sin(theta) * sin(phi2), cos(theta) glNormal3f(dx, dy, dz) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, s, 1 - t) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, s, 1 - t) glVertex3f(r * dx, r * dy, r * dz) s = phi1 / TWOPI # x dx, dy = sin(theta) * cos(phi1), sin(theta) * sin(phi1) glNormal3f(dx, dy, dz) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, s, 1 - t) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, s, 1 - t) glVertex3f(r * dx, r * dy, r * dz)
def renderToTexture(w, h, function): import ctypes from pyglet import gl from pyglet import image from pyglet.gl import gl_info global has_fbo if has_fbo is None: has_fbo = gl_info.have_extension("GL_EXT_framebuffer_object") # enforce dimensions are ints w, h = int(w), int(h) # set up viewport gl.glPushAttrib(gl.GL_VIEWPORT_BIT | gl.GL_TRANSFORM_BIT) gl.glViewport(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.glOrtho(0, w, 0, h, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) if has_fbo: # render directly to texture # create our frame buffer fbo = gl.GLuint() gl.glGenFramebuffersEXT(1, ctypes.byref(fbo)) gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo) # allocate a texture and add to the frame buffer tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h, gl.GL_RGBA) gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id) gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, tex.id, 0) status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT) assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT # now render gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo) function() gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0) # clean up gl.glDeleteFramebuffersEXT(1, ctypes.byref(fbo)) else: # render and copy to texture # render function() # grab the buffer and copy contents to the texture buffer = image.get_buffer_manager().get_color_buffer() tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h, gl.GL_RGBA) tex.blit_into(buffer.get_region(0, 0, w, h), 0, 0, 0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPopMatrix() gl.glPopAttrib() # return the region (the whole texture will most likely be larger) return tex.get_region(0, 0, w, h)
def getSysInfo(win): try: from collections import OrderedDict except: from psychopy.iohub import OrderedDict # based on sysInfo.py from pyglet.gl import gl_info, GLint, glGetIntegerv, GL_MAX_ELEMENTS_VERTICES import sys, platform sys_info = OrderedDict() sys_info["OS"] = OrderedDict() sys_info["OS"]["Name"] = platform.platform() if sys.platform == "darwin": OSXver, _, architecture = platform.mac_ver() sys_info["OS"]["OSX Version"] = OSXver sys_info["OS"]["OSX Architecture"] = architecture sys_info["Computer Hardware"] = OrderedDict() try: import psutil def getMemoryInfo(): rdict = dict() nt = psutil.virtual_memory() for name in nt._fields: value = getattr(nt, name) if name != "percent": value = bytes2human(value) rdict[name.capitalize()] = value #'%s%s%-10s : %7s\n'%(rstr,'\t'*indent,name.capitalize(), value) return rdict core_count = psutil.cpu_count(logical=False) logical_psu_count = psutil.cpu_count() memory_info = getMemoryInfo() sys_info["Computer Hardware"]["CPUs (cores / logical)"] = (core_count, logical_psu_count) sys_info["Computer Hardware"]["System Memory"] = memory_info except: sys_info["Computer Hardware"]["Failed"] = "psutil 2.x + is required." sys_info["Python"] = OrderedDict() sys_info["Python"]["exe"] = sys.executable sys_info["Python"]["version"] = sys.version sys_info["Packages"] = OrderedDict() try: import numpy sys_info["Packages"]["numpy"] = numpy.__version__ except: sys_info["Packages"]["numpy"] = "Not Installed" try: import pyglet sys_info["Packages"]["pyglet"] = pyglet.version except: sys_info["Packages"]["pyglet"] = "Not Installed" try: import cv2 sys_info["Packages"]["cv2"] = cv2.__version__ except: sys_info["Packages"]["cv2"] = "Not Installed" try: import psychopy sys_info["Packages"]["PsychoPy"] = psychopy.__version__ except: sys_info["Packages"]["PsychoPy"] = "Not Installed" sys_info["Graphics"] = OrderedDict() sys_info["Graphics"]["shaders"] = win._haveShaders sys_info["Graphics"]["opengl"] = OrderedDict() sys_info["Graphics"]["opengl"]["version"] = gl_info.get_version() sys_info["Graphics"]["opengl"]["vendor"] = gl_info.get_vendor() sys_info["Graphics"]["opengl"]["engine"] = gl_info.get_renderer() maxVerts = GLint() glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, maxVerts) sys_info["Graphics"]["opengl"]["Max vert in VA"] = maxVerts.value sys_info["Graphics"]["opengl"]["extensions"] = OrderedDict() extensionsOfInterest = [ "GL_ARB_multitexture", "GL_EXT_framebuffer_object", "GL_ARB_fragment_program", "GL_ARB_shader_objects", "GL_ARB_vertex_shader", "GL_ARB_texture_non_power_of_two", "GL_ARB_texture_float", "GL_STEREO", ] for ext in extensionsOfInterest: sys_info["Graphics"]["opengl"]["extensions"][ext] = bool(gl_info.have_extension(ext)) sys_info["Processes"] = OrderedDict() if sys.platform == "darwin": sys_info["Processes"]["Failed"] = "Not Supported on OSX." elif SAVE_PER_PROCESS_DATA: try: import psutil for proc in psutil.process_iter(): pkey = proc.pid vattrs = [ "name", "exe", "ppid", "num_threads", "memory_percent", "cpu_percent", "cpu_affinity", "nice", "num_ctx_switches", ] procinfo = proc.as_dict(attrs=vattrs, ad_value=u"Access Denied") if procinfo["exe"] is not u"Access Denied" and ( SAVE_PER_PROCESS_DATA is True or SAVE_PER_PROCESS_DATA == procinfo["name"] ): sys_info["Processes"][pkey] = procinfo except: sys_info["Processes"]["Failed"] = "psutil 2.x + is required." else: sys_info["Processes"]["Disabled"] = "Per Process details disabled by user." return sys_info