MCPcopy Create free account
hub / github.com/carbonengine/trinity / EffectInfo

Class EffectInfo

shadercompiler/python/shadercompiler/effectinfo.py:582–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580
581
582class EffectInfo(object):
583 def __init__(self, path, platform=Platform.DX11, shader_model=ShaderModel.DEPTH):
584 self._stream = None
585 self._version = None
586 self._compilerVersion = None
587 self._sourceHash = None
588 self.permutations = []
589
590 if path.lower().endswith('.fx'):
591 self._load(paths.get_compiled_path(path, shader_model, platform))
592 else:
593 self._load(path)
594
595 def _load(self, path):
596 with open(path, 'rb') as f:
597 data = f.read()
598 self._stream = _StructStream(data)
599 stream = self._stream
600 version = stream.read_uint32()
601 self._version = version
602 if version < 2 or version > 15:
603 raise RuntimeError('unsupported effect file version')
604 if version >= 15:
605 self._compilerVersion = stream.read_uint32()
606 self._sourceHash = stream.read_raw(32)
607 if version < 5:
608 header_size = stream.read_uint32()
609 if header_size == 0:
610 raise RuntimeError('effect file contains no compiled effects')
611 if header_size * 3 * 4 + 4 > stream.remaining():
612 raise RuntimeError('invalid header size')
613 self._offsets = {}
614 for i in range(header_size):
615 key = stream.read_uint32()
616 self._offsets[key] = (stream.read_uint32(), stream.read_uint32())
617 self._string_table = _StringTable(stream)
618 else:
619 self._string_table = _StringTable(stream)
620 permutation_count = stream.read_uint8()
621 self.permutations = []
622 for i in range(permutation_count):
623 self.permutations.append(Permutation(stream, self._string_table, version))
624 header_size = stream.read_uint32()
625 if header_size == 0:
626 raise RuntimeError('effect file contains no compiled effects')
627 if header_size * 3 * 4 + 4 > stream.remaining():
628 raise RuntimeError('invalid header size')
629 self._offsets = {}
630 for i in range(header_size):
631 key = stream.read_uint32()
632 self._offsets[key] = (stream.read_uint32(), stream.read_uint32())
633
634 def get_shader(self, permutation=0):
635 """
636 Return particular permutation information
637 :param permutation: Either a permutation number (Incarna shaders) or a dict of permutation options
638 :type permutation: int|dict
639 :rtype: ShaderInfo

Callers 4

_compile_and_parseMethod · 0.90
apply_to_shadersFunction · 0.85
get_merged_parametersFunction · 0.85

Calls

no outgoing calls

Tested by 1

_compile_and_parseMethod · 0.72