Exemplo n.º 1
0
        public Graphics.CGfxShadingEnv[] InitEditorMobileShadingEnv(CRenderContext RHICtx)
        {
            InitSystemStates(RHICtx);

            var result = new Graphics.CGfxShadingEnv[(int)PrebuildPassIndex.PPI_Num];

            result[(int)EngineNS.PrebuildPassIndex.PPI_OpaquePbr]            = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxMobileOpaqueSE>();
            result[(int)EngineNS.PrebuildPassIndex.PPI_TransparentPbr]       = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxMobileTranslucentSE>();
            result[(int)EngineNS.PrebuildPassIndex.PPI_CustomTranslucentPbr] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxMobileCustomTranslucentSE>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_OpaquePbrEditor]            = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxMobileOpaqueEditorSE>();
            result[(int)EngineNS.PrebuildPassIndex.PPI_CustomTranslucentPbrEditor] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxMobileCustomTranslucentEditorSE>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_HitProxy] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxHitProxySE>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_PickedEditor] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxPickedSetUpSE>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_Gizmos]   = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxGizmosSE>();
            result[(int)EngineNS.PrebuildPassIndex.PPI_Snapshot] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxSnapshotSE>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_SSM] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxSE_SSM>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_Sky] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxSE_MobileSky>();

            result[(int)EngineNS.PrebuildPassIndex.PPI_SceneCapture] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxSceneCaptureSE>();

            return(result);
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task <bool> InitPassForViewportView(CRenderContext RHICtx, Graphics.CGfxShadingEnv shadingEnv, Graphics.CGfxMaterialInstance MtlInst,
                                                                                Graphics.Mesh.CGfxMesh ViewportMesh)
        {
            var effect = GetEffect(RHICtx, shadingEnv.EnvCode, MtlInst, ViewportMesh);

            if (effect == null)
            {
                return(false);
            }
            await effect.AwaitLoad();

            if (effect.ShaderProgram == null)
            {
                return(false);
            }

            this.ShadingEnv = shadingEnv;
            this.Effect     = effect;
            this.mMtlInst   = MtlInst;
            this.MtlMesh    = ViewportMesh.MtlMeshArray[0];
            if (mRenderPipeline == null)
            {
                var RplDesc = new CRenderPipelineDesc();
                RenderPipeline = RHICtx.CreateRenderPipeline(RplDesc);
            }

            BindCBuffer(effect.ShaderProgram, effect.CacheData.PerInstanceId, ViewportMesh.MtlMeshArray[0].CBuffer);
            BindCBuffer(effect.ShaderProgram, effect.CacheData.PerFrameId, CEngine.Instance.PerFrameCBuffer);

            this.BindGeometry(ViewportMesh.MeshPrimitives, 0, 0);

            PreUse();

            return(true);
        }
Exemplo n.º 3
0
        public void InitPass(CRenderContext RHICtx, Graphics.CGfxEffect effect, Graphics.CGfxShadingEnv shadingEnv, Graphics.Mesh.CGfxMtlMesh mesh, UInt32 index)
        {
            if (IsEffectValid == 2)
            {
                if (Effect != effect)
                {
                    Effect = effect;
                    if (Effect.CacheData.PerFrameId != UInt32.MaxValue)
                    {
                        BindCBuffer(Effect.ShaderProgram, Effect.CacheData.PerFrameId, CEngine.Instance.PerFrameCBuffer);
                    }
                }
            }
            ShadingEnv = shadingEnv;
            Effect     = effect;
            MtlMesh    = mesh;
            MeshIndex  = index;

            if (mRenderPipeline == null)
            {
                var RplDesc = new CRenderPipelineDesc();
                RenderPipeline = RHICtx.CreateRenderPipeline(RplDesc);
            }

            this.BindGeometry(MtlMesh.mRootSceneMesh.MeshPrimitives, index, 0);
        }
Exemplo n.º 4
0
        private Graphics.CGfxEffect GetEffect(CRenderContext RHICtx,
                                              Graphics.GfxEnvShaderCode ShaderEnv,
                                              Graphics.CGfxMaterialInstance mtl,
                                              Graphics.Mesh.CGfxMesh mesh)
        {
            var desc = Graphics.CGfxEffectDesc.CreateDesc(mtl.Material, mesh.MdfQueue, ShaderEnv);

            return(CEngine.Instance.EffectManager.GetEffect(RHICtx, desc));
        }
Exemplo n.º 5
0
        public virtual void TickStreaming(CRenderContext rc)
        {
            if (PauseStreaming)
            {
                return;
            }
            UInt64 resSize         = 0;
            var    now             = CEngine.Instance.EngineTime;
            var    scaleForgetTime = (long)((float)ForgetTime * CEngine.Instance.EngineTimeScale);

            using (var iter = Resources.GetEnumerator())
            {
                while (true)
                {
                    try
                    {
                        bool go = iter.MoveNext();
                        if (go == false)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        break;
                    }
                    var cur = iter.Current;
                    var res = cur.Value;
                    if (CanRemove(res))
                    {//外部无引用
                        Resources.Remove(cur.Key);
                        OnRemove(res);
                        break;
                    }

                    if (res.ResourceState.KeepValid == false && now - res.ResourceState.AccessTime > scaleForgetTime)
                    {
                        InvalidateResource(res);
                    }
                    else
                    {
                        if (res.ResourceState.StreamState == EStreamingState.SS_Invalid)
                        {
                            RestoreResource(res);
                            res.ResourceState.StreamState = EStreamingState.SS_Streaming;
                        }

                        OnStreamingTick(res);
                    }

                    resSize += cur.Value.ResourceState.ResourceSize;
                }
            }
            TotalSize = resSize;
        }
Exemplo n.º 6
0
        public bool Save2File(CRenderContext rc, string fileName, EIMAGE_FILE_FORMAT Type)
        {
            unsafe
            {
                Support.CBlobObject data = new Support.CBlobObject();
                Save2Memory(rc, data, EIMAGE_FILE_FORMAT.BMP);

                return(Save2File(fileName, data, Type));
            }
            //return (bool)SDK_IShaderResourceView_Save2File(CoreObject, rc.CoreObject, fileName, Type);
        }
Exemplo n.º 7
0
        public void Commit(CRenderContext RenderContext)
        {
            ScopeExecute.Begin();

            lock (this)
            {
                SDK_ICommandList_Commit(CoreObject, RenderContext.CoreObject);
            }

            ScopeExecute.End();
        }
Exemplo n.º 8
0
        public CBlendState GetBlendState(CRenderContext rc, CBlendStateDesc desc)
        {
            Hash64 hash = new Hash64();

            unsafe
            {
                Hash64.CalcHash64(&hash, (byte *)&desc, sizeof(CBlendStateDesc));
            }
            CBlendState state;

            if (States.TryGetValue(hash, out state) == false)
            {
                state = rc.CreateBlendState(desc);
                States.Add(hash, state);
            }
            return(state);
        }
Exemplo n.º 9
0
        public static Graphics.Mesh.CGfxMeshPrimitives MergeGeomsAsMeshSimple(CRenderContext rc, List <Graphics.Mesh.CGfxMeshPrimitives> meshArray, List <Matrix> transforms)
        {
            var aabb   = new BoundingBox();
            var geom   = MergeGeoms(rc, meshArray, transforms, ref aabb);
            var result = new Graphics.Mesh.CGfxMeshPrimitives();

            result.InitFromGeomtryMesh(rc, geom, 1, ref aabb);

            var desc = new CDrawPrimitiveDesc();

            desc.SetDefault();
            foreach (var i in meshArray)
            {
                var td = new CDrawPrimitiveDesc();
                i.GetAtom(0, 0, ref td);
                desc.NumPrimitives += td.NumPrimitives;
            }
            result.PushAtomLOD(0, ref desc);
            return(result);
        }
Exemplo n.º 10
0
        public static CGeometryMesh MergeGeoms(CRenderContext rc, List <Graphics.Mesh.CGfxMeshPrimitives> meshArray, List <Matrix> transforms, ref BoundingBox aabb)
        {
            CGeometryMesh.NativePointer[] usedArray = new CGeometryMesh.NativePointer[meshArray.Count];
            Matrix[] usedMatrix = transforms.ToArray();
            for (int i = 0; i < meshArray.Count; i++)
            {
                meshArray[i].PreUse(true);
                usedArray[i] = meshArray[i].GeometryMesh.CoreObject;
            }
            unsafe
            {
                fixed(CGeometryMesh.NativePointer *p = &usedArray[0])
                fixed(Matrix * pMatrix    = &usedMatrix[0])
                fixed(BoundingBox * pAABB = &aabb)
                {
                    var ptr    = SDK_IGeometryMesh_MergeGeoms(rc.CoreObject, p, pMatrix, meshArray.Count, pAABB);
                    var result = new CGeometryMesh(ptr);

                    result.Core_Release();
                    return(result);
                }
            }
        }
Exemplo n.º 11
0
 //public bool LoadAllMips(CRenderContext rc, CShaderResourceView srv)
 //{
 //    return SDK_GfxTextureStreaming_LoadAllMips(CoreObject, rc.CoreObject, srv.CoreObject);
 //}
 public bool LoadNextMip(CRenderContext rc, CShaderResourceView srv)
 {
     return(SDK_GfxTextureStreaming_LoadNextMip(CoreObject, rc.CoreObject, srv.CoreObject));
 }
Exemplo n.º 12
0
 public bool LinkShaders(CRenderContext rc)
 {
     return(SDK_IShaderProgram_LinkShaders(CoreObject, rc.CoreObject));
 }
Exemplo n.º 13
0
        public async virtual System.Threading.Tasks.Task <T> AwaitResource(CRenderContext rc, RName name)
        {
            await Thread.AsyncDummyClass.DummyFunc();

            return(default(T));
        }
Exemplo n.º 14
0
 public virtual T GetResource(CRenderContext rc, RName name, bool firstLoad = false)
 {
     return(default(T));
 }
Exemplo n.º 15
0
 //这个函数要从显卡取数据,根据目前的渲染器结构,要求在Render线程执行,调用的时候要注意Post
 public void GetBufferData(CRenderContext rc, Support.CBlobObject blob)
 {
     SDK_IVertexBuffer_GetBufferData(CoreObject, rc.CoreObject, blob.CoreObject);
 }
Exemplo n.º 16
0
        public void InitSystemStates(CRenderContext RHICtx)
        {
            //raster stat;
            CRasterizerStateDesc RSDescOpaque = new CRasterizerStateDesc();

            RSDescOpaque.InitForOpaque();
            mOpaqueRasterStat = CEngine.Instance.RasterizerStateManager.GetRasterizerState(RHICtx, RSDescOpaque);

            CRasterizerStateDesc RSDescTranslucent = new CRasterizerStateDesc();

            RSDescTranslucent.InitForTranslucent();
            mTranslucentRasterStat = CEngine.Instance.RasterizerStateManager.GetRasterizerState(RHICtx, RSDescTranslucent);

            {
                CRasterizerStateDesc rsDesc = new CRasterizerStateDesc();
                rsDesc.InitForTranslucent();
                rsDesc.CullMode      = ECullMode.CMD_NONE;
                mNoCullingRasterStat = CEngine.Instance.RasterizerStateManager.GetRasterizerState(RHICtx, rsDesc);
            }

            //depth stencil stat;
            CDepthStencilStateDesc OpaqueDSSDesc = new CDepthStencilStateDesc();

            OpaqueDSSDesc.InitForOpacity();
            mOpaqueDSStat = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, OpaqueDSSDesc);

            CDepthStencilStateDesc TranslucentDSSDesc = new CDepthStencilStateDesc();

            TranslucentDSSDesc.InitForTranslucency();
            mTranslucentDSStat = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, TranslucentDSSDesc);

            CDepthStencilStateDesc dsDesc = new CDepthStencilStateDesc();

            dsDesc.InitForTranslucency();
            dsDesc.DepthEnable       = 0;
            mDisableDepthStencilStat = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, dsDesc);

            CDepthStencilStateDesc DSDescEqual = new CDepthStencilStateDesc();

            DSDescEqual.DepthEnable                  = 1;
            DSDescEqual.DepthWriteMask               = EDepthWriteMask.DSWM_ALL;
            DSDescEqual.DepthFunc                    = EComparisionMode.CMP_EQUAL;
            DSDescEqual.StencilEnable                = 0;
            DSDescEqual.StencilReadMask              = 0xFF;
            DSDescEqual.StencilWriteMask             = 0xFF;
            DSDescEqual.FrontFace.StencilDepthFailOp = EStencilOp.STOP_KEEP;
            DSDescEqual.FrontFace.StencilFailOp      = EStencilOp.STOP_KEEP;
            DSDescEqual.FrontFace.StencilFunc        = EComparisionMode.CMP_NEVER;
            DSDescEqual.BackFace.StencilDepthFailOp  = EStencilOp.STOP_KEEP;
            DSDescEqual.BackFace.StencilFailOp       = EStencilOp.STOP_KEEP;
            DSDescEqual.BackFace.StencilFunc         = EComparisionMode.CMP_NEVER;
            DSDescEqual.StencilRef                   = 0;
            mDSEqual = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, DSDescEqual);

            //blend state
            CBlendStateDesc ShadowBlendDesc = new CBlendStateDesc();

            ShadowBlendDesc.InitForShadow();
            mShadowBlendStat = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, ShadowBlendDesc);

            CBlendStateDesc OpaqueBlendDesc = new CBlendStateDesc();

            OpaqueBlendDesc.InitForOpacity();
            mOpaqueBlendStat = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, OpaqueBlendDesc);

            CBlendStateDesc TranslucentBlendDesc = new CBlendStateDesc();

            TranslucentBlendDesc.InitForTranslucency();
            mTranslucentBlendStat = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, TranslucentBlendDesc);

            {
                CBlendStateDesc bldDesc = new CBlendStateDesc();
                bldDesc.InitForTranslucency();
                bldDesc.RenderTarget0.SrcBlend  = EBlend.BLD_ONE;
                bldDesc.RenderTarget0.DestBlend = EBlend.BLD_ONE;
                mAddColorBlendStat = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, bldDesc);
            }

            CBlendStateDesc SnapshotBlendDesc = new CBlendStateDesc();

            SnapshotBlendDesc.InitForSnapshot();
            mSnapshotBlendStat = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, SnapshotBlendDesc);


            Image2DShadingEnvs[(int)PrebuildPassIndex.PPI_Default] = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.Mesh.CImage2DShadingEnv>();
            mOtherShadingEnvs.Add(Image2DShadingEnvs[(int)PrebuildPassIndex.PPI_Default]);

            Font2DShadingEnvs[(int)PrebuildPassIndex.PPI_Default] = Bricks.FreeTypeFont.CFTShadingEnv.GetFTShadingEnv();
            mOtherShadingEnvs.Add(Font2DShadingEnvs[(int)PrebuildPassIndex.PPI_Default]);

            Graphics.CGfxShadingEnv temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EngineNS.Graphics.EnvShader.CGfxDefaultSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileBloomUSSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileBloomDSSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileBloomSetUpSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileBloomBlurHSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileBloomBlurVSE>();
            mOtherShadingEnvs.Add(temp);

            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileCopySE>();
            mOtherShadingEnvs.Add(temp);

            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxHitProxyAxisSE>();
            mOtherShadingEnvs.Add(temp);

            //picked editor;
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxPickedBlurHSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxPickedBlurVSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxPickedHollowSE>();
            mOtherShadingEnvs.Add(temp);

            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileCopyEditorSE>();
            mOtherShadingEnvs.Add(temp);

            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileSunShaftMaskSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileSunShaftBlurSE>();
            mOtherShadingEnvs.Add(temp);

            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileAoMaskSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileAoBlurHSE>();
            mOtherShadingEnvs.Add(temp);
            temp = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Graphics.EnvShader.CGfxMobileAoBlurVSE>();
            mOtherShadingEnvs.Add(temp);
        }
Exemplo n.º 17
0
 public bool GetBufferData(CRenderContext rc, Support.CBlobObject blob)
 {
     return(SDK_IGpuBuffer_GetBufferData(CoreObject, rc.CoreObject, blob.CoreObject));
 }