public bool PreInit(IntPtr WindowHandle)
        {
            D3D = new DirectX11Class();
            if (!D3D.Init(WindowHandle))
            {
                MessageBox.Show("Failed to initialize DirectX11!");
                return(false);
            }

            Timer = new TimerClass();
            FPS   = new FPSClass();

            Timer.Init();
            FPS.Init();

            RenderStorageSingleton.Instance.Prefabs = new RenderPrefabs();
            if (!RenderStorageSingleton.Instance.ShaderManager.Init(D3D.Device))
            {
                MessageBox.Show("Failed to initialize Shader Manager!");
                return(false);
            }
            //this is backup!
            RenderStorageSingleton.Instance.TextureCache.Add(0, TextureLoader.LoadTexture(D3D.Device, D3D.DeviceContext, "texture.dds"));

            var structure = new M2TStructure();
            //import gizmo
            RenderModel model = new RenderModel();

            structure.ReadFromM2T("Resources/GizmoModel.m2t");
            model.ConvertMTKToRenderModel(structure);
            model.InitBuffers(D3D.Device, D3D.DeviceContext);
            model.DoRender = false;

            RenderModel sky = new RenderModel();

            structure = new M2TStructure();
            structure.ReadFromM2T("Resources/sky_backdrop.m2t");
            sky.ConvertMTKToRenderModel(structure);
            sky.InitBuffers(D3D.Device, D3D.DeviceContext);
            sky.DoRender = false;
            Assets.Add(1, sky);

            RenderModel clouds = new RenderModel();

            structure = new M2TStructure();
            structure.ReadFromM2T("Resources/weather_clouds.m2t");
            clouds.ConvertMTKToRenderModel(structure);
            clouds.InitBuffers(D3D.Device, D3D.DeviceContext);
            clouds.DoRender = false;
            Assets.Add(2, clouds);
            return(true);
        }
Exemple #2
0
        public bool Initialise(DirectX11Class D3D)
        {
            if (!ShaderManager.Init(D3D.Device))
            {
                MessageBox.Show("Failed to initialize Shader Manager!");
                return(false);
            }

            // Precache textures and thumbnails which will be reused pretty often.
            Instance.TextureCache.Add(0, TextureLoader.LoadTexture(D3D.Device, D3D.DeviceContext, "texture.dds"));
            Instance.TextureCache.Add(1, TextureLoader.LoadTexture(D3D.Device, D3D.DeviceContext, "default_n.dds"));

            Instance.TextureThumbnails.Add(0, TextureLoader.LoadThumbnail("Resources/Texture.dds"));
            Instance.TextureThumbnails.Add(1, TextureLoader.LoadThumbnail("Resource/MissingMaterial.dds"));

            isInit = true;
            return(true);
        }
Exemple #3
0
        private void GetTextureFromSampler(Device d3d, DeviceContext d3dContext, ModelPart part, string SamplerKey)
        {
            HashName sampler = part.Material.GetTextureByID(SamplerKey);

            if (sampler != null)
            {
                ShaderResourceView texture;

                ulong  SamplerHash = sampler.Hash;
                string SamplerName = sampler.String;

                if (!RenderStorageSingleton.Instance.TextureCache.TryGetValue(SamplerHash, out texture))
                {
                    if (!string.IsNullOrEmpty(SamplerName))
                    {
                        texture = TextureLoader.LoadTexture(d3d, d3dContext, SamplerName);
                        RenderStorageSingleton.Instance.TextureCache.Add(SamplerHash, texture);
                    }
                }
            }
        }
Exemple #4
0
        private void InitTextures(Device d3d, DeviceContext d3dContext)
        {
            if (aoHash != null)
            {
                ShaderResourceView texture;

                if (!RenderStorageSingleton.Instance.TextureCache.TryGetValue(aoHash.Hash, out texture))
                {
                    if (!string.IsNullOrEmpty(aoHash.String))
                    {
                        texture = TextureLoader.LoadTexture(d3d, d3dContext, aoHash.String);
                        RenderStorageSingleton.Instance.TextureCache.Add(aoHash.Hash, texture);
                    }
                }

                AOTexture = texture;
            }
            else
            {
                AOTexture = RenderStorageSingleton.Instance.TextureCache[0];
            }

            for (int i = 0; i < LODs.Length; i++)
            {
                for (int x = 0; x < LODs[i].ModelParts.Length; x++)
                {
                    ModelPart part = LODs[i].ModelParts[x];

                    if (part.Material != null)
                    {
                        GetTextureFromSampler(d3d, d3dContext, part, "S000");
                        GetTextureFromSampler(d3d, d3dContext, part, "S001");
                        GetTextureFromSampler(d3d, d3dContext, part, "S011");
                    }
                }
            }
        }