Exemplo n.º 1
0
        //TODO: @Investigate: What if multiple delegates are bound to the same event?
        public void InvokeVertexLayoutGeneration()
        {
            // Base vertex geometry
            VertexLayouts[0]           = CallVertexLayoutGeneration.Invoke();
            VertexPreEffectsLayouts[0] = CallVertexLayoutGeneration.Invoke();

            // Instancing data i.e. position, view matrices
            var instancingEventKeys = InstancingEventHandlerKeys.GetKeys();
            var flagIndex           = InstancingDataFlags.GetArrayIndexForFlag(InstancingDataFlag);

            if (flagIndex >= 0)
            {
                var instancingEventKey = instancingEventKeys[flagIndex];
                var instancingVertexInstanceDeletegate = (VertexInstanceLayoutGenerationList[instancingEventKey] as Func <VertexLayoutDescription>);
                VertexLayouts[flagIndex + 1] = instancingVertexInstanceDeletegate.Invoke();
            }

            // Instancing effects data
            var preEffectsEventKeys = PreEffectEventHandlerKeys.GetKeys();
            var preEffectsflagIndex = RenderFlags.GetPreEffectArrayIndexForFlag(PreEffectsInstancingFlag);

            if (preEffectsflagIndex >= 0)
            {
                var preEffectsEventKey       = preEffectsEventKeys[preEffectsflagIndex];
                var vertexInstanceDeletegate = (VertexPreEffectsInstanceLayoutGenerationList[preEffectsEventKey] as Func <VertexLayoutDescription>);
                VertexPreEffectsLayouts[preEffectsflagIndex + 1] = vertexInstanceDeletegate.Invoke();
            }
        }
Exemplo n.º 2
0
        //TODO: Refactor renderFlag preEffectsInstancingFlag and instancingFlag into an class/struct
        public ModelRuntimeDescriptor(Model <T, RealtimeMaterial> modelIn, string vShaderName, string fShaderName, VertexRuntimeTypes vertexRuntimeType, PrimitiveTopology primitiveTopology, RenderDescription renderDescription, InstancingRenderDescription instancingRenderDescription)
        {
            if (!Verifier.VerifyVertexStruct <T>(vertexRuntimeType))
            {
                throw new ArgumentException($"Type Mismatch ModelRuntimeDescriptor");
            }

            Model  = modelIn;
            Length = modelIn.MeshCount;

            TotalInstanceCount = 1;

            _vertexShaderName   = vShaderName;
            _fragmentShaderName = fShaderName;

            VertexRuntimeType = vertexRuntimeType;
            PrimitiveTopology = primitiveTopology;

            RenderDescription        = renderDescription;
            PreEffectsFlag           = RenderFlags.PRE_EFFECTS_MASK & renderDescription.RenderModeFlag;
            PreEffectsInstancingFlag = instancingRenderDescription.PreEffectsFlag;
            InstancingDataFlag       = instancingRenderDescription.RenderModeFlag;

            var preEffectsInstancing = RenderFlags.GetAllPreEffectFor(PreEffectsInstancingFlag);

            VertexBufferList    = new List <DeviceBuffer>();
            IndexBufferList     = new List <DeviceBuffer>();
            Pipelines           = new Pipeline[RenderFlags.EFFCTS_TOTAL_COUNT];
            InstanceBufferLists = new List <DeviceBuffer> [RenderFlags.EFFCTS_TOTAL_COUNT];
            InstanceBufferLists[RenderFlags.NORMAL_ARRAY_INDEX] = new List <DeviceBuffer>();
            foreach (var preEffect in preEffectsInstancing)
            {
                InstanceBufferLists[RenderFlags.GetArrayIndexForFlag(preEffect)] = new List <DeviceBuffer>();
            }
            InstanceBuffers                              = new DeviceBuffer[RenderFlags.EFFCTS_TOTAL_COUNT][];
            TextureResourceSetsList                      = new List <ResourceSet>();
            VertexInstanceLayoutGenerationList           = new EventHandlerList();
            VertexPreEffectsInstanceLayoutGenerationList = new EventHandlerList();

            VertexPreEffectShaders   = new Shader[RenderFlags.PRE_EFFCTS_TOTAL_COUNT];
            GeometryPreEffectShaders = new Shader[RenderFlags.PRE_EFFCTS_TOTAL_COUNT];
            FragmentPreEffectShaders = new Shader[RenderFlags.PRE_EFFCTS_TOTAL_COUNT];

            // Reserve first spot for base vertex geometry
            //TODO: Make on list
            VertexLayouts           = new VertexLayoutDescription[InstancingDataFlags.GetSizeOfPreEffectFlag(InstancingDataFlag) + 1];
            VertexPreEffectsLayouts = new VertexLayoutDescription[RenderFlags.GetSizeOfPreEffectFlag(PreEffectsInstancingFlag) + 1];

            EffectResourceSets = new ResourceSet[RenderFlags.EFFCTS_TOTAL_COUNT][];
            for (int i = 0; i < RenderFlags.EFFCTS_TOTAL_COUNT; i++)
            {
                EffectResourceSets[i] = new ResourceSet[0];
            }
        }
Exemplo n.º 3
0
        public void AddVertexInstanceDelegate(uint instancingFlag, Func <VertexLayoutDescription> vertexLayoutDelegate)
        {
            var flagIndex = InstancingDataFlags.GetArrayIndexForFlag(PreEffectsInstancingFlag);

            VertexInstanceLayoutGenerationList.AddHandler(InstancingEventHandlerKeys.GetKeys()[flagIndex], vertexLayoutDelegate);
        }