예제 #1
0
        protected override void Load(ResourceDesc resourceDescription)
        {
            ShaderResourceDesc desc = (ShaderResourceDesc)resourceDescription;

            string file = System.IO.File.ReadAllText(resourceDescription.FileName);

            InputElements = Rendering.ShaderPreprocessor.Preprocess(file);

            // Creates a string with specified Defines
            string defines = "";

            if (desc.Defines != null)
            {
                foreach (string str in desc.Defines)
                {
                    defines += String.Format("#define {0}\n", str);
                }
                file = defines + file;
            }

            ShaderInclude  shaderInclude    = new ShaderInclude("data/shaders/");
            ShaderBytecode vsShaderByteCode = ShaderBytecode.Compile(file, "vs_main", "vs_5_0", ShaderFlags.Debug, EffectFlags.None, null, shaderInclude);
            ShaderBytecode psShaderByteCode = ShaderBytecode.Compile(file, "ps_main", "ps_5_0", ShaderFlags.Debug, EffectFlags.None, null, shaderInclude);

            shaderInclude.Dispose();

            InputSignature = ShaderSignature.GetInputSignature(vsShaderByteCode);
            VertexShader   = new D3D11.VertexShader(desc.Device, vsShaderByteCode);
            PixelShader    = new D3D11.PixelShader(desc.Device, psShaderByteCode);

            Shader = new Rendering.Shader(desc.Device, VertexShader, PixelShader, InputSignature, InputElements, resourceDescription.Alias);
        }
예제 #2
0
 protected Guid RemoveResource(ResourceDesc desc)
 {
     _resources = ResourceList ?? new List <ResourceDesc>();
     _resources.Remove(desc);
     Session["Resources"] = _resources;
     return(desc.Id);
 }
예제 #3
0
        protected virtual ID3D12Resource *CreateDepthStencil()
        {
            ID3D12Resource *depthStencil;

            var heapProperties = new HeapProperties(HeapType.HeapTypeDefault);

            var resourceDesc = new ResourceDesc
                               (
                ResourceDimension.ResourceDimensionTexture2D,
                0ul,
                (ulong)Size.X,
                (uint)Size.Y,
                1,
                1,
                DepthBufferFormat,
                new SampleDesc()
            {
                Count = 1, Quality = 0
            },
                TextureLayout.TextureLayoutUnknown,
                ResourceFlags.ResourceFlagAllowDepthStencil
                               );

            var clearValue = new ClearValue(DepthBufferFormat, depthStencil: new DepthStencilValue(1.0f, 0));

            var iid = ID3D12Resource.Guid;

            SilkMarshal.ThrowHResult
            (
                D3DDevice->CreateCommittedResource
                (
                    &heapProperties, HeapFlags.HeapFlagNone, &resourceDesc, ResourceStates.ResourceStateDepthWrite,
                    &clearValue, &iid, (void **)&depthStencil
                )
            );

            var dsvDesc = new DepthStencilViewDesc
            {
                Format        = DepthBufferFormat,
                ViewDimension = DsvDimension.DsvDimensionTexture2D
            };

            D3DDevice->CreateDepthStencilView(depthStencil, &dsvDesc, DSVHeap->GetCPUDescriptorHandleForHeapStart());

            return(depthStencil);
        }
예제 #4
0
        protected override void Load(ResourceDesc resourceDescription)
        {
            Texture2DResourceDesc desc = (Texture2DResourceDesc)resourceDescription;

            var texture2D = CommonDX.TextureLoader.CreateTexture2DFromBitmap(desc.Device, CommonDX.TextureLoader.LoadBitmap(new SharpDX.WIC.ImagingFactory2(), desc.FileName));

            Width  = texture2D.Description.Width;
            Height = texture2D.Description.Height;


            D3D11.ShaderResourceView srvt = null;

            if (desc.CreateSRVT)
            {
                srvt = new D3D11.ShaderResourceView(desc.Device, texture2D);
            }

            Texture = new Rendering.Texture(texture2D, srvt);
        }
예제 #5
0
        protected virtual ID3D12Resource *CreateVertexBuffer(out VertexBufferView vertexBufferView)
        {
            // Define the geometry for a triangle.
            const int TriangleVerticesCount = 3;
            var       triangleVertices      = stackalloc Vertex[TriangleVerticesCount]
            {
                new Vertex
                {
                    Position = new Vector3(0.0f, 0.5f, 0.0f),
                    Color    = new Vector4(1.0f, 0.0f, 0.0f, 1.0f)
                },
                new Vertex
                {
                    Position = new Vector3(0.5f, -0.5f, 0.0f),
                    Color    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f)
                },
                new Vertex
                {
                    Position = new Vector3(-0.5f, -0.5f, 0.0f),
                    Color    = new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
                },
            };

            var vertexBufferSize = (uint)sizeof(Vertex) * TriangleVerticesCount;

            // Note: using upload heaps to transfer static data like vert buffers is not
            // recommended. Every time the GPU needs it, the upload heap will be marshalled
            // over. Please read up on Default Heap usage. An upload heap is used here for
            // code simplicity and because there are very few verts to actually transfer.
            ID3D12Resource *vertexBuffer;

            var heapProperties = new HeapProperties(HeapType.HeapTypeUpload);
            var bufferDesc     = new ResourceDesc
                                 (
                ResourceDimension.ResourceDimensionBuffer, 0, vertexBufferSize, 1, 1, 1, Format.FormatUnknown,
                new SampleDesc(1, 0),
                TextureLayout.TextureLayoutRowMajor, ResourceFlags.ResourceFlagNone
                                 );

            var iid = ID3D12Resource.Guid;

            SilkMarshal.ThrowHResult
            (
                D3DDevice->CreateCommittedResource
                (
                    &heapProperties,
                    HeapFlags.HeapFlagNone,
                    &bufferDesc,
                    ResourceStates.ResourceStateGenericRead,
                    pOptimizedClearValue: null,
                    &iid,
                    (void **)&vertexBuffer
                )
            );

            // Copy the triangle data to the vertex buffer.
            var readRange = new Range();

            byte *pVertexDataBegin;

            SilkMarshal.ThrowHResult(vertexBuffer->Map(Subresource: 0, &readRange, (void **)&pVertexDataBegin));
            Unsafe.CopyBlock(pVertexDataBegin, triangleVertices, vertexBufferSize);
            vertexBuffer->Unmap(0, null);

            // Initialize the vertex buffer view.
            vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
            vertexBufferView.StrideInBytes  = (uint)sizeof(Vertex);
            vertexBufferView.SizeInBytes    = vertexBufferSize;

            return(vertexBuffer);
        }
예제 #6
0
        protected override void Load(ResourceDesc resourceDescription)
        {
            MeshResourceDesc desc = (MeshResourceDesc)resourceDescription;

            Mesh = MeshLoader.LoadMesh(resourceDescription.FileName);
        }