示例#1
0
        internal void SetSamplers(int startSlot, params ISamplerState[] samplers)
        {
            if (m_tmpSamplers == null)
            {
                m_tmpSamplers = new SamplerState[6];
            }

            for (int i = 0; i < samplers.Length; i++)
            {
                ISamplerState sampler = samplers[i];

                SamplerState dxObject = null;
                if (sampler != null)
                {
                    ISamplerStateInternal samplerInternal = (ISamplerStateInternal)sampler;
                    dxObject = samplerInternal.Resource;
                }

                int slot = startSlot + i;
                if (dxObject == m_samplers[slot])
                {
                    continue;
                }
                m_samplers[slot] = dxObject;
                m_tmpSamplers[i] = dxObject;
            }

            m_shaderStage.SetSamplers(startSlot, samplers.Length, m_tmpSamplers);
            m_statistics.SetSamplers++;
        }
示例#2
0
        internal void SetSampler(int slot, ISamplerState sampler)
        {
            SamplerState dxObject = null;
            if (sampler != null)
            {
                ISamplerStateInternal samplerInternal = (ISamplerStateInternal) sampler;
                dxObject = samplerInternal.Resource;
            }

            if (dxObject == m_samplers[slot])
                return;
            m_samplers[slot] = dxObject;
            m_shaderStage.SetSampler(slot, dxObject);
            m_statistics.SetSamplers++;
        }
示例#3
0
        public static ISamplerState Init(VideoTypes videoType, IDisposableResource parent, ISamplerStateDesc desc)
        {
            ISamplerState api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.SamplerState(parent, desc);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.SamplerState(parent, desc);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.SamplerState(parent, desc);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.SamplerState(parent, desc);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.SamplerState(parent, desc);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("SamplerStateAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
示例#4
0
        internal void SetSampler(int slot, ISamplerState sampler)
        {
            SamplerState dxObject = null;

            if (sampler != null)
            {
                ISamplerStateInternal samplerInternal = (ISamplerStateInternal)sampler;
                dxObject = samplerInternal.Resource;
            }

            if (dxObject == m_samplers[slot])
            {
                return;
            }
            m_samplers[slot] = dxObject;
            m_shaderStage.SetSampler(slot, dxObject);
            m_statistics.SetSamplers++;
        }
示例#5
0
        public RenderToTextureScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var renderTargetFormats = Eye.Adapters[0]
                .GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.RenderTarget | FormatSupport.MipAutogen)
                .Where(fi => fi.ColorBits <= 24);
            if (!renderTargetFormats.Any()) throw new NotSupportedException("Render target textures are not supported.");
            var renderTargetFormatInfo = renderTargetFormats
                .OrderByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var renderTargetTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = TextureHelper.MipLevels(TargetSize, TargetSize, 1),
                ArraySize = 1,
                FormatID = renderTargetFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                MiscFlags = MiscFlags.GenerateMips,
                ExtraFlags = ExtraFlags.None
            });
            targetRtv = renderTargetTexture.ViewAsRenderTarget(renderTargetFormatInfo.ID, 0);
            targetSrv = renderTargetTexture.ViewAsShaderResource(renderTargetFormatInfo.ID, 0, renderTargetTexture.MipLevels);

            var dsFormats = Eye.Adapters[0].GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.DepthStencil);
            var dsFormatInfo = dsFormats
                .OrderBy(fi => (fi.ColorBits == 24 && fi.AlphaBits == 8) ? 0 : 1)
                .ThenByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var depthStencilTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = 1,
                ArraySize = 1,
                FormatID = dsFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.DepthStencil,
                MiscFlags = MiscFlags.None,
                ExtraFlags = ExtraFlags.None
            });
            targetDsv = depthStencilTexture.ViewAsDepthStencil(dsFormatInfo.ID, DepthStencilViewFlags.None, 0);

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Anisotropic);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }
示例#6
0
        internal MySamplerStateManager()
        {
            SamplerStateDescription description = new SamplerStateDescription();

            description.AddressU   = TextureAddressMode.Clamp;
            description.AddressV   = TextureAddressMode.Clamp;
            description.AddressW   = TextureAddressMode.Clamp;
            description.Filter     = Filter.MinMagMipLinear;
            description.MaximumLod = Single.MaxValue;
            Default = CreateResource("Default", ref description);

            description.AddressU    = TextureAddressMode.Border;
            description.AddressV    = TextureAddressMode.Border;
            description.AddressW    = TextureAddressMode.Border;
            description.Filter      = Filter.MinMagMipLinear;
            description.MaximumLod  = Single.MaxValue;
            description.BorderColor = new Color4(0, 0, 0, 0);
            Alphamask = CreateResource("Alphamask", ref description);

            description.AddressU   = TextureAddressMode.Clamp;
            description.AddressV   = TextureAddressMode.Clamp;
            description.AddressW   = TextureAddressMode.Clamp;
            description.Filter     = Filter.MinMagMipPoint;
            description.MaximumLod = Single.MaxValue;
            Point = CreateResource("Point", ref description);

            description.Filter     = Filter.MinMagMipLinear;
            description.MaximumLod = Single.MaxValue;
            Linear = CreateResource("Linear", ref description);

            description.AddressU           = TextureAddressMode.Clamp;
            description.AddressV           = TextureAddressMode.Clamp;
            description.AddressW           = TextureAddressMode.Clamp;
            description.Filter             = Filter.ComparisonMinMagMipLinear;
            description.MaximumLod         = Single.MaxValue;
            description.ComparisonFunction = Comparison.LessEqual;
            Shadowmap = CreateResource("Shadowmap", ref description);

            Texture        = CreateResource("Texture", ref description);
            AlphamaskArray = CreateResource("AlphamaskArray", ref description);

            description.AddressU           = TextureAddressMode.Clamp;
            description.AddressV           = TextureAddressMode.Clamp;
            description.AddressW           = TextureAddressMode.Clamp;
            description.Filter             = Filter.MinMagMipPoint;
            description.MaximumLod         = System.Single.MaxValue;
            description.MaximumAnisotropy  = 1;
            description.ComparisonFunction = Comparison.Never;
            description.BorderColor        = new SharpDX.Mathematics.Interop.RawColor4(-float.MaxValue, -float.MaxValue, -float.MaxValue, -float.MaxValue);
            PointHBAOClamp = CreateResource("PointHBAOClamp", ref description);

            description.AddressU = TextureAddressMode.Border;
            description.AddressV = TextureAddressMode.Border;
            PointHBAOBorder      = CreateResource("PointHBAOBorder", ref description);

            description = new SamplerStateDescription
            {
                AddressU   = TextureAddressMode.Wrap,
                AddressV   = TextureAddressMode.Wrap,
                AddressW   = TextureAddressMode.Wrap,
                Filter     = Filter.MinMagMipLinear,
                MaximumLod = Single.MaxValue
            };
            CloudSampler = CreateResource("CloudSampler", ref description);

            StandardSamplers = new ISamplerState[]
            {
                Default,
                Point,
                Linear,
                Texture,
                Alphamask,
                AlphamaskArray,
            };

            UpdateFiltering();
        }
示例#7
0
        public CubeScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraPixelBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraPixel.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            var specularTexture = textureLoader.Load("../Textures/SpecularTest.png");
            specualrView = specularTexture.ViewAsShaderResource(specularTexture.FormatID, 0, specularTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Default);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }