D3D11_CreateTexture1D

Function

Creates a 1-D texture.

Parameters

Name Type Description
pDevice ID3D11Device* A pointer to the Direct3D 11 device that will create the texture.
pDesc const D3D11_TEXTURE1D_DESC* A pointer to a description of the texture resource (see D3D11_TEXTURE1D_DESC).
pInitialData const D3D11_SUBRESOURCE_DATA* A pointer to the data used to initialize the texture. Pass NULL for no initial data.
ppTexture1D ID3D11Texture1D** A pointer to a variable that receives a pointer to the created texture object (see ID3D11Texture1D).

Return Value

Returns S_OK on success, or one of the following:

  • E_OUTOFMEMORY: If the system cannot allocate enough memory for the texture.
  • E_INVALIDARG: If an invalid parameter is passed.

Remarks

To create a texture, you must set the appropriate flags in the D3D11_TEXTURE1D_DESC structure. For example, to create a shader resource, set the D3D11_BIND_SHADER_RESOURCE flag.

If you do not initialize the texture with data, you must set CPUAccessFlags appropriately to allow the CPU to write to it later. Otherwise, it will be read-only.

The following code example demonstrates how to create a 1-D texture with shader resource view capabilities:


D3D11_TEXTURE1D_DESC texDesc;
ZeroMemory(&texDesc, sizeof(texDesc));

texDesc.Width = 1024;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;

ID3D11Texture1D* pTexture1D = nullptr;
HRESULT hr = pDevice->CreateTexture1D(&texDesc, nullptr, &pTexture1D);

if (SUCCEEDED(hr))
{
    // Texture created successfully
    // ... create shader resource view ...
}
else
{
    // Handle error
}
                

Requirements

Header
d3d11.h
Library
D3d11.lib