예제 #1
0
        public Handle <Sampler> Create(SamplerCreation args)
        {
            var handle = _resourcePool.CreateResource();

            if (!handle.IsValid())
            {
                throw new InvalidOperationException("Failed to Create a Sampler Handle");
            }
            Logger.Trace <SamplerManager>($"Creating sampler with filter {args.Filter} and comparison func {args.ComparisonFunc}");

            var sampler = _resourcePool.GetResourcePointer(handle);

            sampler->Handle         = handle;
            sampler->Filter         = args.Filter;
            sampler->AddressU       = args.AddressU;
            sampler->AddressV       = args.AddressV;
            sampler->AddressW       = args.AddressW;
            sampler->ComparisonFunc = args.ComparisonFunc;

            var desc = new D3D11_SAMPLER_DESC
            {
                Filter         = (D3D11_FILTER)args.Filter,
                AddressU       = (D3D11_TEXTURE_ADDRESS_MODE)args.AddressU,
                AddressV       = (D3D11_TEXTURE_ADDRESS_MODE)args.AddressV,
                AddressW       = (D3D11_TEXTURE_ADDRESS_MODE)args.AddressW,
                ComparisonFunc = (D3D11_COMPARISON_FUNC)args.ComparisonFunc
            };

            Common.CheckAndThrow(_device->CreateSamplerState(&desc, &sampler->SamplerState), nameof(ID3D11Device.CreateSamplerState));

            return(handle);
        }
예제 #2
0
        public Handle <RasterizerState> Create(RasterizerStateCreation args)
        {
            var handle = _resourcePool.CreateResource();

            if (!handle.IsValid())
            {
                throw new InvalidOperationException($"Failed to Create a {nameof(RasterizerState)} Handle");
            }
            Logger.Trace <RasterizerManager>($"Creating {nameof(RasterizerState)} with .....");

            var desc = new D3D11_RASTERIZER_DESC
            {
                CullMode        = (D3D11_CULL_MODE)args.CullMode,
                FillMode        = (D3D11_FILL_MODE)args.FillMode,
                DepthClipEnable = 1,
            };

            var state = _resourcePool.GetResourcePointer(handle);

            state->CullMode = args.CullMode;
            state->FillMode = args.FillMode;

            Common.CheckAndThrow(_device->CreateRasterizerState(&desc, &state->State), nameof(ID3D11Device.CreateRasterizerState));

            return(handle);
        }
예제 #3
0
        public Handle <ResourceBuffer> Create(BufferCreation args)
        {
            Logger.Trace <BufferManager>($"Create {args.Type} with stride {args.Stride} usage {args.Usage}. InitialData: {args.InitialData.HasValue()}");
            var handle = _resourcePool.CreateResource();

            if (!handle.IsValid())
            {
                throw new InvalidOperationException("Failed to Create a Buffer Handle");
            }

            var bindFlag = args.Type switch
            {
                BufferTypes.ConstantBuffer => D3D11_BIND_FLAG.D3D11_BIND_CONSTANT_BUFFER,
                BufferTypes.IndexBuffer => D3D11_BIND_FLAG.D3D11_BIND_INDEX_BUFFER,
                BufferTypes.VertexBuffer => D3D11_BIND_FLAG.D3D11_BIND_VERTEX_BUFFER,
                _ => throw new ArgumentOutOfRangeException()
            };

            var desc = new D3D11_BUFFER_DESC
            {
                BindFlags           = bindFlag,
                Usage               = args.Usage,
                CpuAccessFlags      = args.CpuAccessFlags,
                MiscFlags           = args.MiscFlags,
                ByteWidth           = args.Count * args.Stride,
                StructureByteStride = args.Stride
            };

            var buffer = _resourcePool.GetResourcePointer(handle);

            buffer->Handle        = handle;
            buffer->BindFlag      = bindFlag;
            buffer->Count         = args.Count;
            buffer->CpuAccessFlag = args.CpuAccessFlags;
            buffer->MiscFlag      = args.MiscFlags;
            buffer->Stride        = args.Stride;
            buffer->Usage         = args.Usage;

            if (args.InitialData.HasValue())
            {
                var subResource = new D3D11_SUBRESOURCE_DATA
                {
                    pSysMem = args.InitialData
                };
                Common.CheckAndThrow(_device->CreateBuffer(&desc, &subResource, &buffer->Resource), nameof(ID3D11Device.CreateBuffer));
            }
            else
            {
                Common.CheckAndThrow(_device->CreateBuffer(&desc, null, &buffer->Resource), nameof(ID3D11Device.CreateBuffer));
            }
            return(handle);
        }
예제 #4
0
        public Handle <Material> Create(MaterialCreation args)
        {
            var handle = _resources.CreateResource();

            if (!handle.IsValid())
            {
                throw new InvalidOperationException("Failed to Create Material Handle");
            }

            var material = _resources.GetResourcePointer(handle);

            material->PixelShader  = args.PixelShader;
            material->VertexShader = args.VertexShader;
            ref var properties = ref material->Properties;