Esempio n. 1
0
        void CreateFontsTexture()
        {
            var   io = ImGui.GetIO();
            byte *pixels;
            int   width, height;

            io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height);

            var texDesc = new Texture2DDescription
            {
                Width             = width,
                Height            = height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription {
                    Count = 1
                },
                Usage          = Vortice.Direct3D11.Usage.Default,
                BindFlags      = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None
            };

            var subResource = new SubresourceData
            {
                DataPointer = (IntPtr)pixels,
                Pitch       = texDesc.Width * 4,
                SlicePitch  = 0
            };

            var texture = device.CreateTexture2D(texDesc, new[] { subResource });

            var resViewDesc = new ShaderResourceViewDescription
            {
                Format        = Format.R8G8B8A8_UNorm,
                ViewDimension = ShaderResourceViewDimension.Texture2D,
                Texture2D     = new Texture2DShaderResourceView {
                    MipLevels = texDesc.MipLevels, MostDetailedMip = 0
                }
            };

            fontTextureView = device.CreateShaderResourceView(texture, resViewDesc);
            texture.Release();

            io.Fonts.TexID = RegisterTexture(fontTextureView);

            var samplerDesc = new SamplerDescription
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                MipLODBias         = 0f,
                ComparisonFunction = ComparisonFunction.Always,
                MinLOD             = 0f,
                MaxLOD             = 0f
            };

            fontSampler = device.CreateSamplerState(samplerDesc);
        }
Esempio n. 2
0
        IntPtr RegisterTexture(ID3D11ShaderResourceView texture)
        {
            var imguiID = texture.NativePointer;

            textureResources.Add(imguiID, texture);

            return(imguiID);
        }
Esempio n. 3
0
        public override void SetShaderParameters(ID3D11Device device, ID3D11DeviceContext deviceContext, MaterialParameters matParams)
        {
            base.SetShaderParameters(device, deviceContext, matParams);

            Shader_50760736Params parameters = new Shader_50760736Params();
            var material = matParams.MaterialData;

            var param = material.GetParameterByKey("C005");

            if (param != null)
            {
                parameters.C005_EmissiveFacadeColorAndIntensity = new Vector4(param.Paramaters[0], param.Paramaters[1], param.Paramaters[2], param.Paramaters[3]);
            }

            if (material == null)
            {
                ID3D11ShaderResourceView texture = RenderStorageSingleton.Instance.TextureCache[0];
                deviceContext.PSSetShaderResource(0, texture);
                ShaderParams = parameters;
            }
            else
            {
                ID3D11ShaderResourceView[] textures = new ID3D11ShaderResourceView[2];

                HashName TextureFile = material.GetTextureByID("S000");
                if (TextureFile != null)
                {
                    textures[0] = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash];
                }
                else
                {
                    textures[0] = RenderStorageSingleton.Instance.TextureCache[0];
                }

                TextureFile = material.GetTextureByID("S011");
                if (TextureFile != null)
                {
                    textures[1] = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash];
                }
                else
                {
                    textures[1] = RenderStorageSingleton.Instance.TextureCache[0];
                }

                deviceContext.PSSetShaderResources(0, textures);
            }

            ShaderParams = parameters;
        }
        private void StartDesktopDuplicator(int adapterId, int outputId)
        {
            var adapter = factory.GetAdapter1(adapterId);

            D3D11.D3D11CreateDevice(adapter, DriverType.Unknown, DeviceCreationFlags.None, s_featureLevels, out device);

            var output  = adapter.GetOutput(outputId);
            var output1 = output.QueryInterface <IDXGIOutput1>();

            var bounds = output1.Description.DesktopCoordinates;
            var width  = bounds.Right - bounds.Left;
            var height = bounds.Bottom - bounds.Top;

            var textureDesc = new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.Read,
                BindFlags         = BindFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = width / 2,
                Height            = height / 2,
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = Usage.Staging
            };

            stagingTexture = device.CreateTexture2D(textureDesc);

            var smallerTextureDesc = new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.None,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = width,
                Height            = height,
                OptionFlags       = ResourceOptionFlags.GenerateMips,
                MipLevels         = 4,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = Usage.Default
            };

            smallerTexture     = device.CreateTexture2D(smallerTextureDesc);
            smallerTextureView = device.CreateShaderResourceView(smallerTexture);

            duplication = output1.DuplicateOutput(device);
        }
Esempio n. 5
0
        public override void SetShaderParameters(ID3D11Device device, ID3D11DeviceContext context, MaterialParameters matParams)
        {
            base.SetShaderParameters(device, context, matParams);

            int previousHasTangentSpace = extraParams.hasTangentSpace;

            var material = matParams.MaterialData;

            if (material == null)
            {
                ID3D11ShaderResourceView texture = RenderStorageSingleton.Instance.TextureCache[0];
                context.PSSetShaderResource(0, texture);
            }
            else
            {
                HashName TextureFile = material.GetTextureByID("S000");
                ID3D11ShaderResourceView[] ShaderTextures = new ID3D11ShaderResourceView[2];
                if (TextureFile != null)
                {
                    ShaderTextures[0] = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash];
                }
                else
                {
                    ShaderTextures[0] = RenderStorageSingleton.Instance.TextureCache[0];
                }

                TextureFile = material.GetTextureByID("S001");
                if (TextureFile != null)
                {
                    ShaderTextures[1]           = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash];
                    extraParams.hasTangentSpace = 1;
                }
                else
                {
                    ShaderTextures[1]           = RenderStorageSingleton.Instance.TextureCache[1];
                    extraParams.hasTangentSpace = 0;
                }

                context.PSSetShaderResources(0, ShaderTextures);
            }

            if (previousRenderType != extraParams.hasTangentSpace)
            {
                ConstantBufferFactory.UpdatePixelBuffer(context, ConstantExtraParameterBuffer, 2, extraParams);
            }
        }
 internal D3D11ShaderResourceView(ID3D11ShaderResourceView shaderResourceView)
 {
     this.shaderResourceView = shaderResourceView;
 }
        public unsafe void CSSetShaderResource(int startSlot, ID3D11ShaderResourceView shaderResourceView)
        {
            var viewPtr = shaderResourceView.NativePointer;

            CSSetShaderResources(startSlot, 1, new IntPtr(&viewPtr));
        }
Esempio n. 8
0
 public Texture2D(ID3D11Texture2D texture, ID3D11ShaderResourceView textureView, uint width, in uint height)
 internal D3D11ShaderResourceView(ID3D11ShaderResourceView shaderResourceView)
 {
     this.shaderResourceView = shaderResourceView;
 }