protected override void DestroyAssets()
    {
        DestroyBuffers();
        DestroyInputLayout();

        void DestroyInputLayout()
        {
            var inputLayout = _inputLayout;

            if (inputLayout != null)
            {
                _inputLayout = null;
                _            = inputLayout->Release();
            }

            var pixelShader = _pixelShader;

            if (pixelShader != null)
            {
                _pixelShader = null;
                _            = pixelShader->Release();
            }

            var vertexShader = _vertexShader;

            if (vertexShader != null)
            {
                _vertexShader = null;
                _             = vertexShader->Release();
            }
        }
    }
    protected override void CreateAssets()
    {
        _inputLayout = CreateInputLayout();
        CreateBuffers();
        base.CreateAssets();

        ID3D11InputLayout *CreateInputLayout()
        {
            using ComPtr <ID3DBlob> vertexShaderBlob = null;
            using ComPtr <ID3DBlob> pixelShaderBlob  = null;

            fixed(char *fileName = GetAssetFullPath(@"D3D11\Assets\Shaders\HelloTriangle.hlsl"))
            fixed(ID3D11VertexShader **vertexShader = &_vertexShader)
            fixed(ID3D11PixelShader **pixelShader   = &_pixelShader)
            {
                var entryPoint = 0x00006E69614D5356;    // VSMain
                var target     = 0x0000305F345F7376;    // vs_4_0

                ThrowIfFailed(D3DCompileFromFile((ushort *)fileName, null, null, (sbyte *)&entryPoint, (sbyte *)&target, 0, 0, vertexShaderBlob.GetAddressOf(), null));

                ThrowIfFailed(D3DDevice->CreateVertexShader(vertexShaderBlob.Get()->GetBufferPointer(), vertexShaderBlob.Get()->GetBufferSize(), pClassLinkage: null, vertexShader));

                entryPoint = 0x00006E69614D5350;        // PSMain
                target     = 0x0000305F345F7370;        // ps_4_0
                ThrowIfFailed(D3DCompileFromFile((ushort *)fileName, null, null, (sbyte *)&entryPoint, (sbyte *)&target, 0, 0, pixelShaderBlob.GetAddressOf(), null));

                ThrowIfFailed(D3DDevice->CreatePixelShader(pixelShaderBlob.Get()->GetBufferPointer(), pixelShaderBlob.Get()->GetBufferSize(), pClassLinkage: null, pixelShader));
            }

            var inputElementDescs = stackalloc D3D11_INPUT_ELEMENT_DESC[2];
            {
                var semanticName0 = stackalloc sbyte[9];
                {
                    ((ulong *)semanticName0)[0] = 0x4E4F495449534F50;      // POSITION
                }
                inputElementDescs[0] = new D3D11_INPUT_ELEMENT_DESC {
                    SemanticName         = semanticName0,
                    SemanticIndex        = 0,
                    Format               = DXGI_FORMAT_R32G32B32_FLOAT,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11_INPUT_PER_VERTEX_DATA,
                    InstanceDataStepRate = 0
                };

                var semanticName1 = 0x000000524F4C4F43;                     // COLOR
                inputElementDescs[1] = new D3D11_INPUT_ELEMENT_DESC {
                    SemanticName         = (sbyte *)&semanticName1,
                    SemanticIndex        = 0,
                    Format               = DXGI_FORMAT_R32G32B32A32_FLOAT,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11_INPUT_PER_VERTEX_DATA,
                    InstanceDataStepRate = 0
                };
            }

            ID3D11InputLayout *inputLayout;

            ThrowIfFailed(D3DDevice->CreateInputLayout(inputElementDescs, NumElements: 2, vertexShaderBlob.Get()->GetBufferPointer(), vertexShaderBlob.Get()->GetBufferSize(), &inputLayout));
            return(inputLayout);
        }
    }
Beispiel #3
0
 public void IASetInputLayout([NativeTypeName("ID3D11InputLayout *")] ID3D11InputLayout *pInputLayout)
 {
     ((delegate * stdcall <ID3D11DeviceContext *, ID3D11InputLayout *, void>)(lpVtbl[17]))((ID3D11DeviceContext *)Unsafe.AsPointer(ref this), pInputLayout);
 }
Beispiel #4
0
        protected override void Dispose(bool isDisposing)
        {
            var vertexBuffer = _vertexBuffer;

            if (vertexBuffer != null)
            {
                _vertexBuffer = null;
                _             = vertexBuffer->Release();
            }

            var inputLayout = _inputLayout;

            if (inputLayout != null)
            {
                _inputLayout = null;
                _            = inputLayout->Release();
            }

            var pixelShader = _pixelShader;

            if (pixelShader != null)
            {
                _pixelShader = null;
                _            = pixelShader->Release();
            }

            var vertexShader = _vertexShader;

            if (vertexShader != null)
            {
                _vertexShader = null;
                _             = vertexShader->Release();
            }

            var swapChain = _swapChain;

            if (swapChain != null)
            {
                _swapChain = null;
                _          = swapChain->Release();
            }

            var immediateContext = _immediateContext;

            if (immediateContext != null)
            {
                _immediateContext = null;
                _ = immediateContext->Release();
            }

            var device = _device;

            if (device != null)
            {
                _device = null;
                _       = device->Release();
            }

            var renderTarget = _renderTarget;

            if (renderTarget != null)
            {
                _renderTarget = null;
                _             = renderTarget->Release();
            }

            base.Dispose(isDisposing);
        }