Example #1
0
    def _setupGL(self):

        #setup screen color
        if self.colorSpace in ['rgb','dkl','lms','hsv']: #these spaces are 0-centred
            desiredRGB = (self.rgb+1)/2.0#RGB in range 0:1 and scaled for contrast
        else:
            desiredRGB = self.rgb/255.0
        GL.glClearColor(desiredRGB[0],desiredRGB[1],desiredRGB[2], 1.0)
        GL.glClearDepth(1.0)

        GL.glViewport(0, 0, int(self.size[0]), int(self.size[1]))

        GL.glMatrixMode(GL.GL_PROJECTION) # Reset The Projection Matrix
        GL.glLoadIdentity()
        GL.gluOrtho2D(-1,1,-1,1)

        GL.glMatrixMode(GL.GL_MODELVIEW)# Reset The Projection Matrix
        GL.glLoadIdentity()

        GL.glDisable(GL.GL_DEPTH_TEST)
        #GL.glEnable(GL.GL_DEPTH_TEST)                   # Enables Depth Testing
        #GL.glDepthFunc(GL.GL_LESS)                      # The Type Of Depth Test To Do
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        GL.glShadeModel(GL.GL_SMOOTH)                   # Color Shading (FLAT or SMOOTH)
        GL.glEnable(GL.GL_POINT_SMOOTH)

        #check for GL_ARB_texture_float (which is needed for shaders to be useful)
        #this needs to be done AFTER the context has been created
        if not GL.gl_info.have_extension('GL_ARB_texture_float'):
            self._haveShaders=False

        if self.winType=='pyglet' and self._haveShaders:
            #we should be able to compile shaders (don't just 'try')
            self._progSignedTexMask = _shaders.compileProgram(_shaders.vertSimple, _shaders.fragSignedColorTexMask)#fragSignedColorTexMask
            self._progSignedTex = _shaders.compileProgram(_shaders.vertSimple, _shaders.fragSignedColorTex)
            self._progSignedTexMask1D = _shaders.compileProgram(_shaders.vertSimple, _shaders.fragSignedColorTexMask1D)
            self._progSignedTexFont = _shaders.compileProgram(_shaders.vertSimple, _shaders.fragSignedColorTexFont)

        GL.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT)

        #identify gfx card vendor
        self.glVendor=GL.gl_info.get_vendor().lower()

        if sys.platform=='darwin':
            platform_specific.syncSwapBuffers(1)

        if haveFB:
            self._setupFrameBuffer()
Example #2
0
def setUpShaderAndWindow(device, window):
    """Sets up the appropriate shader and functions for the window to work
    
    Args:
        device (pypixxlib object): The current object handle for your device
        window (PsychoPy.Window object): A PsychoPy Window object
        
    Returns:
        int: The OpenGL program number for the generated shader.
    """
    shader_dict = {
        'L48': no_mode_Shader,
        'C24': no_mode_Shader,
        'M16': M16_mode_Shader,
        'M16O': M16O_mode_Shader,
        'C48': C48_mode_Shader,
        'L48D': L48D_mode_Shader,
        'M16D': M16D_mode_Shader,
        'C36D': C36D_mode_Shader,
    }

    vid_mode = device.getVideoMode()
    shader = shader_dict[vid_mode]
    if not hasattr(window, '_prepareFBOrender'):
        raise "Window does not have FBO."
    # Compile the shader
    from psychopy._shadersPyglet import compileProgram, vertSimple
    from OpenGL.GL import glUseProgram

    compiled_shader = compileProgram(vertSimple, shader)

    def _prepareFBOrender():
        glUseProgram(compiled_shader)

    def _finishFBOrender():
        glUseProgram(0)

    def _afterFBOrender():
        pass

    window._prepareFBOrender = _prepareFBOrender
    window._finishFBOrender = _finishFBOrender
    window._afterFBOrender = _afterFBOrender
    window._DPShaderProg = compiled_shader
    return compiled_shader
    def __init__(self,  win, tex="sin",
                 mask="none", units="", pos=(0.0, 0.0), size=None,
                 sf=None, ori=0.0, phase=(0.0, 0.0),
                 texRes=128, rgb=None, dkl=None,
                 lms=None, color=(1.0, 1.0, 1.0), colorSpace='rgb',
                 contrast=1.0, opacity=1.0, depth=0,
                 rgbPedestal=(0.0, 0.0, 0.0), interpolate=False, name=None,
                 autoLog=None, autoDraw=False, maskParams=None, pedestal=0.0):

        #initialise parent class
        super(PedestalGratingStim, self).__init__(win, units=units, name=name,
                autoLog=autoLog, tex=tex, mask=mask, pos=pos, size=size, sf=sf,
                ori=ori, phase=phase, texRes=texRes, rgb=rgb, dkl=dkl, lms=lms,
                color=color, colorSpace=colorSpace, contrast=contrast,
                opacity=opacity, depth=depth, rgbPedestal=rgbPedestal,
                interpolate=interpolate, autoDraw=autoDraw, maskParams=maskParams)
        self.pedestal = pedestal
        self._progSignedTexMask = _shaders.compileProgram(_shaders.vertSimple, fragSignedColorTexMask)
Example #4
0
    def __init__(self,
                 win,
                 carrier="noise",
                 mask="none",
                 envelope="sin",
                 units="",
                 pos=(0.0, 0.0),
                 size=None,
                 sf=None,
                 envsf=None,
                 ori=0.0,
                 envori=0.0,
                 phase=(0.0, 0.0),
                 envphase=(0.0, 0.0),
                 beat=False,
                 texRes=128,
                 rgb=None,
                 dkl=None,
                 lms=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 contrast=0.5,  # contrast of carrier default this to 0.5 to avoid overmodulation - contrast and moddepth must work together, for moddepth=1 the max carrier contrast is 0.5. If moddepth < 1 higher contrasts can be accomodated
                 moddepth=1.0, # modulation depth for envelope
                 opacity=1.0, # not sure what this will do with an envelope stimulus.
                 depth=0,
                 rgbPedestal=(0.0, 0.0, 0.0),
                 interpolate=False,
                 name=None,
                 autoLog=None,
                 autoDraw=False,
                 maskParams=None):
        """ """  # Empty docstring. All doc is in attributes
        #what local vars are defined (these are the init params) for use by __repr__
        assert(win._haveShaders==True),"Currently EnvelopeGratings need your graphics card to have shaders and yours does not seem to comply - sorry"
        self._initParams = dir()
        for unecess in ['self', 'rgb', 'dkl', 'lms']:
            self._initParams.remove(unecess)
        #initialise parent class
        GratingStim.__init__(self, win,
                 units=units, pos=pos, size=size, sf=sf, ori=ori, phase=phase,
                 color=color, colorSpace=colorSpace,
                 contrast=contrast, opacity=opacity,
                 depth=depth, interpolate=interpolate,
                 name=name, autoLog=autoLog, autoDraw=autoDraw,
                 maskParams=None)
        self.__dict__['useShaders'] = win._haveShaders  #use shaders if available by default, this is a good thing
        # UGLY HACK: Some parameters depend on each other for processing.
        # They are set "superficially" here.
        # TO DO: postpone calls to _createTexture, setColor and _calcCyclesPerStim whin initiating stimulus
        self.__dict__['carrier'] = carrier
        self.__dict__['envelope'] = envelope
        self.__dict__['maskParams'] = maskParams

        #initialise textures and masks for stimulus
        self._carrierID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._carrierID))
        self._envelopeID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._envelopeID))
        self.interpolate = interpolate
        del self._texID #created by GratingStim.__init__

        self.mask = mask
        self.envelope = envelope
        self.carrier = carrier
        self.envsf=val2array(envsf)
        self.envphase=val2array(envphase, False)
        self.envori=float(envori)
        self.moddepth=float(moddepth)
        self.beat=bool(beat)
        #print(self.CMphase)
        self._shaderProg = _shaders.compileProgram(_shaders.vertSimple, carrierEnvelopeMaskFrag)
        
        self.local=numpy.ones((texRes,texRes),dtype=numpy.ubyte)
        self.local_p=self.local.ctypes
        #self.local=GL.GL_UNSIGNED_BYTE(self.local)
        #fix scaling to window coords
        #self._calcCyclesPerStim()
        self._calcEnvCyclesPerStim()
        del self.__dict__['tex']