Example #1
0
  Texture * Create1DR32Texture( int w )
  {
    D3D11_TEXTURE1D_DESC desc;
    ZeroMemory(&desc,sizeof(D3D11_TEXTURE1D_DESC));
    desc.Width = w;
    desc.Format = DXGI_FORMAT_R32_FLOAT;
    desc.MipLevels = 1;
    desc.ArraySize = 1;
    desc.Usage = D3D11_USAGE_DYNAMIC;
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

    ID3D11Texture1D * pTex = NULL;

    if (pDevice->CreateTexture1D( &desc, NULL, &pTex ) != S_OK)
      return NULL;

    DX11Texture * tex = new DX11Texture();
    tex->width = w;
    tex->height = 1;
    tex->pTexture = pTex;
    tex->type = TEXTURETYPE_1D;
    tex->format = desc.Format;
    CreateResourceView(tex);
    return tex;
  }
Example #2
0
bool ds::Texture::CreateFromMem( char* Data, int Length, DWORD Type )
{
	Release( );

	if( !ds::Render::GetDevice( ) )
	{
		dsPushMessage( ErrD3DeviceNotCreated );
		return false;
	}

	D3DX10_IMAGE_LOAD_INFO l_Info = D3DX10_IMAGE_LOAD_INFO( );
	CreateInfo( Type, l_Info);

	ID3D10Resource* l_Resource = nullptr;

	HRESULT l_Result = D3DX10CreateTextureFromMemory( 
		ds::Render::Device,
		Data,
		Length,
		&l_Info,
		nullptr,
		&l_Resource,
		nullptr
		);

	if( FAILED( l_Result ) )
	{
		dsPushError( ErrTextureCreate);
		return false;
	}

	l_Resource->QueryInterface( __uuidof( ID3D10Texture2D ), ( LPVOID* )&Texture2D );
	l_Resource->Release( );

	D3D10_TEXTURE2D_DESC l_Desc;
	Texture2D->GetDesc( &l_Desc );

	Size = ds::Size( l_Desc.Width, l_Desc.Height );

	if( Type & RenderTarget )
	{
		D3D10_RENDER_TARGET_VIEW_DESC l_Target;
		l_Target.Format = l_Info.Format;
		l_Target.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
		l_Target.Texture2D.MipSlice = 0;

		ds::Render::Device->CreateRenderTargetView( Texture2D, &l_Target, &TargetView );
	}

	ShaderView[ 0 ] = CreateResourceView( this );
	return true;
}
Example #3
0
bool ds::Texture::Create( ds::Size Size, DWORD Type )
{
	Release( );

	if( !ds::Render::GetDevice( ) )
	{
		dsPushMessage( ErrD3DeviceNotCreated );
		return false;
	}

	D3D10_TEXTURE2D_DESC l_Info;
	CreateDesc( Type, l_Info );

	l_Info.Width = Size.X;
	l_Info.Height = Size.Y;

	HRESULT l_Result = ds::Render::Device->CreateTexture2D( 
		&l_Info, 
		nullptr,
		&Texture2D );

	if( FAILED( l_Result ) )
	{
		dsPushError( ErrTextureCreate );
		return false;
	}

	this->Size = Size;	

	if( Type & RenderTarget )
	{
		D3D10_RENDER_TARGET_VIEW_DESC l_Target;
		l_Target.Format = l_Info.Format;
		l_Target.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
		l_Target.Texture2D.MipSlice = 0;

		ds::Render::Device->CreateRenderTargetView( Texture2D, &l_Target, &TargetView );
	}

	ShaderView[ 0 ] = CreateResourceView( this );
	return true;
}
Example #4
0
  Texture * CreateRGBA8TextureFromFile( char * szFilename )
  {
    int comp = 0;
    int width = 0;
    int height = 0;
    unsigned char * c = stbi_load( szFilename, (int*)&width, (int*)&height, &comp, STBI_rgb_alpha );
    if (!c) return NULL;

    D3D11_TEXTURE2D_DESC desc;
    ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
    desc.Width = width;
    desc.Height = height;
    desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    desc.MipLevels = 1;
    desc.ArraySize = 1;
    desc.SampleDesc.Count = 1;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    
    D3D11_SUBRESOURCE_DATA subData;
    ZeroMemory(&subData,sizeof(D3D11_SUBRESOURCE_DATA));
    subData.pSysMem = c;
    subData.SysMemPitch = width * sizeof(unsigned char) * 4;

    ID3D11Texture2D * pTex = NULL;

    if (pDevice->CreateTexture2D( &desc, &subData, &pTex ) != S_OK)
      return NULL;

    stbi_image_free(c);

    DX11Texture * tex = new DX11Texture();
    tex->width = width;
    tex->height = height;
    tex->pTexture = pTex;
    tex->type = TEXTURETYPE_2D;
    tex->format = desc.Format;
    CreateResourceView(tex);
    return tex;
  }
Example #5
0
  Texture * CreateA8TextureFromData( int w, int h, unsigned char * data )
  {
    D3D11_TEXTURE2D_DESC desc;
    ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
    desc.Width = w;
    desc.Height = h;
    desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    desc.MipLevels = 1;
    desc.ArraySize = 1;
    desc.SampleDesc.Count = 1;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

    unsigned int * p = new unsigned int[ w * h ];
    for (int i=0; i < w * h; i++)
      p[i] = (data[i] << 24) | 0xFFFFFF;
    D3D11_SUBRESOURCE_DATA subData;
    ZeroMemory(&subData,sizeof(D3D11_SUBRESOURCE_DATA));
    subData.pSysMem = p;
    subData.SysMemPitch = w * sizeof(unsigned int);

    ID3D11Texture2D * pTex = NULL;

    if (pDevice->CreateTexture2D( &desc, &subData, &pTex ) != S_OK)
      return NULL;

    delete[] p;

    DX11Texture * tex = new DX11Texture();
    tex->width = w;
    tex->height = h;
    tex->pTexture = pTex;
    tex->type = TEXTURETYPE_2D;
    tex->format = desc.Format;
    CreateResourceView(tex);
    return tex;
  }