def test_loadInvalid():
    shader = ShaderProgram()
    with pytest.raises(InvalidShaderProgramError):
        shader.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Shaders", "invalid.shader"))

    with pytest.raises(InvalidShaderProgramError):
        shader.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Shaders", "invalid2.shader"))
def test_load():
    shader = ShaderProgram()

    mocked_shader_program = MagicMock()

    shader._shader_program = mocked_shader_program
    shader.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Shaders", "test.shader"))

    # It should be called 3 times, once for vertex, once for fragment and once for geometry
    call_arg_list = mocked_shader_program.addShaderFromSourceCode.call_args_list
    assert call(QOpenGLShader.Vertex, "vertex_code") in call_arg_list
    assert call(QOpenGLShader.Fragment, "fragment_code") in call_arg_list
    assert call(QOpenGLShader.Geometry, "geometry_code") in call_arg_list
示例#3
0
    def createShaderProgram(self, file_name: str) -> ShaderProgram:
        shader = ShaderProgram()
        # The version_string must match the keys in shader files.
        if OpenGLContext.isLegacyOpenGL():
            version_string = ""  # Nothing is added to "fragment" and "vertex"
        else:
            version_string = "41core"

        try:
            shader.load(file_name, version=version_string)
        except InvalidShaderProgramError:
            # If the loading failed, it could be that there is no specific shader for this version.
            # Try again without a version nr to get the generic one.
            if version_string != "":
                shader.load(file_name, version="")
        return shader
示例#4
0
    def createShaderProgram(self, file_name: str) -> ShaderProgram:
        shader = ShaderProgram()
        # The version_string must match the keys in shader files.
        if OpenGLContext.isLegacyOpenGL():
            version_string = ""  # Nothing is added to "fragment" and "vertex"
        else:
            version_string = "41core"

        try:
            shader.load(file_name, version = version_string)
        except InvalidShaderProgramError:
            # If the loading failed, it could be that there is no specific shader for this version.
            # Try again without a version nr to get the generic one.
            if version_string != "":
                shader.load(file_name, version = "")
        return shader
示例#5
0
    def createShaderProgram(self, file_name: str) -> Optional[ShaderProgram]:
        """Create a ShaderProgram Object.

        This should return an implementation-specifc ShaderProgram subclass.
        """
        shader = ShaderProgram()
        # The version_string must match the keys in shader files.
        if OpenGLContext.isLegacyOpenGL():
            version_string = ""  # Nothing is added to "fragment" and "vertex"
        else:
            version_string = "41core"

        try:
            shader.load(file_name, version=version_string)
        except InvalidShaderProgramError:
            # If the loading failed, it could be that there is no specific shader for this version.
            # Try again without a version nr to get the generic one.
            if version_string != "":
                try:
                    shader.load(file_name, version="")
                except InvalidShaderProgramError as e:
                    Logger.logException("e", str(e))
                    return None
        return shader