예제 #1
0
 def __init__(self):
     self.display_draw = None
     self.meshes = {}
     self.pipeline = MaltPipeline.get_pipeline().__class__()
     self.view_matrix = None
     self.request_new_frame = False
     self.profiling_data = io.StringIO()
예제 #2
0
 def get_parameters(self):
     if '_RNA_UI' not in self.keys():
         return {}
     rna = self.get_rna()
     parameters = {}
     for key in rna.keys():
         if rna[key]['active'] == False:
             continue
         if rna[key]['type'] in (Type.INT, Type.FLOAT):
             parameters[key] = self[key]
         elif rna[key]['type'] == Type.BOOL:
             parameters[key] = self.bools[key].boolean
         elif rna[key]['type'] == Type.TEXTURE:
             texture = self.textures[key].texture
             if texture:
                 texture.gl_load()
                 parameters[key] = texture.bindcode
             else:
                 parameters[key] = None
         elif rna[key]['type'] == Type.GRADIENT:
             #TODO: Only works for materials
             parameters[key] = get_color_ramp_texture(self.id_data, key)
         elif rna[key]['type'] == Type.MATERIAL:
             material = self.materials[key].material
             extension = self.materials[key].extension
             if material:
                 shader = material.malt.get_shader(extension)
                 if shader:
                     parameters[key] = shader[
                         MaltPipeline.get_pipeline().__class__.__name__]
                     continue
             parameters[key] = None
     return parameters
예제 #3
0
    def update_source(self, context):
        #TODO: Store source locally (for linked data and deleted files)
        global SHADERS
        self.compiler_error = ''
        uniforms = {}

        if self.shader_source != '':
            path = bpy.path.abspath(self.shader_source)
            if os.path.exists(path):
                pipeline_material = {}
                SHADERS[self.shader_source] = pipeline_material

                pipelines = [MaltPipeline.get_pipeline()
                             ]  #TODO: get all active pipelines
                for pipeline in pipelines:
                    pipeline_name = pipeline.__class__.__name__
                    pipeline_material[
                        pipeline_name] = pipeline.compile_material(path)

                    for pass_name, shader in pipeline_material[
                            pipeline_name].items():
                        for uniform_name, uniform in shader.uniforms.items():
                            uniforms[uniform_name] = uniform
                        if shader.error:
                            self.compiler_error += pipeline_name + " : " + pass_name + " : " + shader.error
                        if shader.validator:
                            self.compiler_error += pipeline_name + " : " + pass_name + " : " + shader.validator
            else:
                self.compiler_error = 'Invalid file path'

        self.parameters.setup(uniforms)
예제 #4
0
    def update_source(self, context):
        #TODO: Store source locally (for linked data and deleted files)
        global SHADERS
        self.compiler_error = ''
        parameters = {}

        if self.shader_source != '':
            path = find_shader_path(self.shader_source)
            if path:
                compiled_material = MaltPipeline.get_pipeline(
                ).compile_material(path)
                if compiled_material is None:
                    self.compiler_error = 'Invalid file'
                elif isinstance(compiled_material, str):
                    self.compiler_error = compiled_material
                else:
                    pipeline_material = {}
                    SHADERS[self.shader_source] = pipeline_material

                    pipelines = [MaltPipeline.get_pipeline()
                                 ]  #TODO: get all active pipelines
                    for pipeline in pipelines:
                        pipeline_name = pipeline.__class__.__name__
                        pipeline_material[pipeline_name] = compiled_material

                        for pass_name, shader in pipeline_material[
                                pipeline_name].items():
                            for uniform_name, uniform in shader.uniforms.items(
                            ):
                                parameters[
                                    uniform_name] = Parameter.from_uniform(
                                        uniform)
                            if shader.error:
                                self.compiler_error += pipeline_name + " : " + pass_name + " : " + shader.error
                            if shader.validator:
                                self.compiler_error += pipeline_name + " : " + pass_name + " : " + shader.validator
            else:
                self.compiler_error = 'Invalid file path'

        if self.compiler_error != '':
            SHADERS[self.shader_source] = None
            self.parameters.setup({})
        else:
            self.parameters.setup(parameters)
예제 #5
0
 def get_parameters(self):
     if '_RNA_UI' not in self.keys():
         return {}
     rna = self.get_rna()
     parameters = {}
     for key in rna.keys():
         if rna[key]['active'] == False:
             continue
         if rna[key]['type'] == 'SHADER':
             shader = self.shaders[key].get_shader()
             if shader:
                 shader = shader[MaltPipeline.get_pipeline().__class__.
                                 __name__]['SHADER']
             parameters[key] = shader
         elif rna[key]['type'] == GL.GL_BOOL:
             parameters[key] = self.bools[key].boolean
         else:
             parameters[key] = self[key]
     return parameters
예제 #6
0
 def get_pipeline(self):
     if self.pipeline is None or self.pipeline.__class__ != MaltPipeline.get_pipeline(
     ).__class__:
         self.pipeline = MaltPipeline.get_pipeline().__class__()
     return self.pipeline