예제 #1
0
        //TODO: Data driven -> should refactor so that all GenerateRenderCommandsForModelDescriptor use this structure
        public static void GenerateRenderCommandsForModelDescriptor(CommandList commandList,
                                                                    ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>[] descriptorArray,
                                                                    SceneRuntimeDescriptor sceneRuntimeDescriptor,
                                                                    MeshBVH <VertexPositionNormalTextureTangentBitangent>[] meshBVHArray,
                                                                    RenderDescription renderDescription)
        {
            var meshCount = meshBVHArray.Length;

            for (int j = 0; j < meshCount; j++)
            {
                var meshBVH = meshBVHArray[j];
                if (!meshBVH.AABBIsValid)
                {
                    continue;
                }
                var modelStateIndex    = meshBVH.ModelRuntimeIndex;
                var meshIndex          = meshBVH.MeshRuntimeIndex;
                var modelState         = descriptorArray[modelStateIndex];
                var model              = modelState.Model;
                var modelRenderFlag    = modelState.RenderDescription.RenderModeFlag;
                var currentRenderState = modelRenderFlag & renderDescription.RenderModeFlag;
                if (currentRenderState == RenderFlags.NONE)
                {
                    continue;
                }
                var renderStateArrayIndex = RenderFlags.GetArrayIndexForFlag(currentRenderState);
                commandList.SetPipeline(modelState.Pipelines[renderStateArrayIndex]);
                var effectsInstanceBuffer = modelState.InstanceBuffers[renderStateArrayIndex];
                // We assume one other vertex buffer has been bound or will be bound.
                for (int i = 0; i < effectsInstanceBuffer.Length; i++)
                {
                    commandList.SetVertexBuffer(i.ToUnsigned() + 1, effectsInstanceBuffer[i]);
                }

                var effectSets = modelState.EffectResourceSets[renderStateArrayIndex];

                var mesh     = model.GetMesh(j);
                var material = model.GetMaterial(meshIndex);

                RenderCommandGenerator.GenerateCommandsForPNTTB_Inline(
                    commandList,
                    modelState,
                    meshIndex,
                    sceneRuntimeDescriptor,
                    effectSets,
                    material,
                    mesh,
                    modelState.TotalInstanceCount
                    );
            }
        }
예제 #2
0
        public static void GenerateRenderCommandsForCubeMapModelDescriptor(CommandList commandList,
                                                                           ModelRuntimeDescriptor <VertexPosition> cubeMapRuntimeDescriptor,
                                                                           SceneRuntimeDescriptor sceneRuntimeDescriptor)
        {
            var model = cubeMapRuntimeDescriptor.Model;

            commandList.SetPipeline(cubeMapRuntimeDescriptor.Pipelines[RenderFlags.NORMAL_ARRAY_INDEX]);
            for (int i = 0; i < model.MeshCount; i++)
            {
                var mesh = model.GetMesh(i);
                RenderCommandGenerator.GenerateCommandsForP_Inline(
                    commandList,
                    cubeMapRuntimeDescriptor,
                    i,
                    sceneRuntimeDescriptor,
                    cubeMapRuntimeDescriptor.EffectResourceSets[RenderFlags.NORMAL_ARRAY_INDEX],
                    mesh,
                    cubeMapRuntimeDescriptor.TotalInstanceCount
                    );
            }
        }
예제 #3
0
        public static void GenerateRenderCommandsForModelDescriptor <T>(CommandList commandList,
                                                                        ModelRuntimeDescriptor <T>[] descriptorArray,
                                                                        SceneRuntimeDescriptor sceneRuntimeDescriptor,
                                                                        RenderDescription renderDescription,
                                                                        VertexRuntimeTypes vertexRuntimeType) where T : struct, VertexLocateable
        {
            for (int j = 0; j < descriptorArray.Length; j++)
            {
                var modelState         = descriptorArray[j];
                var modelRenderFlag    = modelState.RenderDescription.RenderModeFlag;
                var currentRenderState = modelRenderFlag & renderDescription.RenderModeFlag;
                if (currentRenderState == RenderFlags.NONE)
                {
                    continue;
                }
                var renderStateArrayIndex = RenderFlags.GetArrayIndexForFlag(currentRenderState);
                commandList.SetPipeline(modelState.Pipelines[renderStateArrayIndex]);
                var effectsInstanceBuffer = modelState.InstanceBuffers[renderStateArrayIndex];
                // We assume one other vertex buffer has been bound or will be bound.
                for (int i = 0; i < effectsInstanceBuffer.Length; i++)
                {
                    commandList.SetVertexBuffer(i.ToUnsigned() + 1, effectsInstanceBuffer[i]);
                }

                var effectSets = modelState.EffectResourceSets[renderStateArrayIndex];

                var model = modelState.Model;

                for (int i = 0; i < model.MeshCount; i++)
                {
                    if (!model.GetMeshBVH(i).AABBIsValid)
                    {
                        continue;
                    }
                    var mesh     = model.GetMesh(i);
                    var material = model.GetMaterial(i);

                    //TODO: @Investiagte this
                    if ((renderDescription.RenderModeFlag & RenderFlags.SHADOW_MAP) == RenderFlags.SHADOW_MAP || (renderDescription.RenderModeFlag & RenderFlags.OMNI_SHADOW_MAPS) == RenderFlags.OMNI_SHADOW_MAPS || vertexRuntimeType == VertexRuntimeTypes.VertexPositionColor)
                    {
                        RenderCommandGenerator.GenerateCommandsForMesh_Inline(
                            commandList,
                            modelState,
                            i,
                            sceneRuntimeDescriptor,
                            effectSets,
                            mesh,
                            modelState.TotalInstanceCount
                            );
                    }


                    else
                    {
                        switch (vertexRuntimeType)
                        {
                        case VertexRuntimeTypes.VertexPosition:
                            RenderCommandGenerator.GenerateCommandsForP_Inline(
                                commandList,
                                modelState as ModelRuntimeDescriptor <VertexPosition>,
                                i,
                                sceneRuntimeDescriptor,
                                effectSets,
                                mesh as Mesh <VertexPosition>,
                                modelState.TotalInstanceCount
                                );
                            break;

                        case VertexRuntimeTypes.VertexPositionTexture:
                            RenderCommandGenerator.GenerateCommandsForPT_Inline(
                                commandList,
                                modelState as ModelRuntimeDescriptor <VertexPositionTexture>,
                                i,
                                sceneRuntimeDescriptor,
                                effectSets,
                                mesh as Mesh <VertexPositionTexture>,
                                modelState.TotalInstanceCount
                                );
                            break;

                        case VertexRuntimeTypes.VertexPositionNormal:
                            RenderCommandGenerator.GenerateCommandsForPN_Inline(
                                commandList,
                                modelState as ModelRuntimeDescriptor <VertexPositionNormal>,
                                i,
                                sceneRuntimeDescriptor,
                                effectSets,
                                material,
                                mesh as Mesh <VertexPositionNormal>,
                                modelState.TotalInstanceCount
                                );
                            break;

                        case VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent:
                            RenderCommandGenerator.GenerateCommandsForPNTTB_Inline(
                                commandList,
                                modelState as ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>,
                                i,
                                sceneRuntimeDescriptor,
                                effectSets,
                                material,
                                mesh as Mesh <VertexPositionNormalTextureTangentBitangent>,
                                modelState.TotalInstanceCount
                                );
                            break;

                        default:
                            var errorStr = "Type: " + typeof(T).Name + " not implemented";
                            throw new System.NotImplementedException(errorStr);
                        }
                    }
                }
            }
        }