Ejemplo n.º 1
0
AAFRESULT ImplAAFTypeDefExtEnum::LookupValByName(aafUID_t *pVal, const aafCharacter *pName)
{
	aafUInt32 i=0;
	aafUInt32 count=0;
	aafBoolean_t  bFound = kAAFFalse;
	aafCharacter Name_buf[256]; 
	aafUInt32 bufSize = 256;
	
	check_hr ( CountElements(&count) );
	while ( (i<count) && !bFound)
	{
		check_hr ( GetElementName (i, Name_buf, bufSize) );
		if ( wcscmp (Name_buf, pName) == 0 ) //matched
		{
			bFound = kAAFTrue;
			
			check_hr (GetElementValue(i, pVal));
			break;
			
		}//if
		i++;
	}//while

	if (!bFound)
		return AAFRESULT_INVALID_PARAM;

	return AAFRESULT_SUCCESS;
}
Ejemplo n.º 2
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFTypeDefCharacter::GetCharacter (
      ImplAAFPropertyValue * pCharacterValue,
      aafCharacter *  pCharacter)
{
  TRACE("ImplAAFTypeDefCharacter::GetCharacter");
  
	if (! pCharacterValue)
		return AAFRESULT_NULL_PARAM;
	
	if (! pCharacter)
		return AAFRESULT_NULL_PARAM;

	//get a pointer to the Val Data
	ImplAAFPropValDataSP pvd;
	pvd = dynamic_cast<ImplAAFPropValData*>(pCharacterValue);
	if (!pvd) return AAFRESULT_BAD_TYPE;
	
	// get the property value's embedded type
	ImplAAFTypeDefSP pPropType;
	check_hr ( pvd->GetType (&pPropType) );
	//Make sure the TD of the pv passed in, matches that of the ImplAAFTypeDefCharacter
	if ((ImplAAFTypeDef *)pPropType != this) // call operator ImplAAFTypeDef *
		return AAFRESULT_BAD_TYPE;
	
	//check to make sure that the size in the val data matches that of the native size
	aafUInt32 cbChar = 0;
	check_hr (  pvd->GetBitsSize(&cbChar) );

	if (cbChar != NativeSize())
	{
		return AAFRESULT_BAD_SIZE;
	}

	//Now set the character from that contained in the prop val data

	aafMemPtr_t pBits = NULL;
	check_hr ( pvd->GetBits (&pBits) );
	ASSERT("Valid bits", pBits != 0);
	
	memcpy (pCharacter, pBits, cbChar);
	
	return AAFRESULT_SUCCESS;
}
Ejemplo n.º 3
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFTypeDefCharacter::CreateValueFromCharacter (
      aafCharacter  character,
      ImplAAFPropertyValue ** ppCharacterValue)
{
  TRACE("ImplAAFTypeDefCharacter::CreateValueFromCharacter");
  
  if (! ppCharacterValue)
		return AAFRESULT_NULL_PARAM;
	
	aafUInt32 cbChar = NativeSize();
	
	// Create a temporary pointer to copy to the smartptr
	ImplAAFPropValData * tmp = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData);
	if (NULL == tmp)
		return AAFRESULT_NOMEMORY;
	ImplAAFPropValDataSP pv;
	pv = tmp;
	
	tmp->ReleaseReference(); // we don't need this reference anymore.
	tmp = 0;
	
	//Initialize
	check_hr ( pv->Initialize(this) );
	
	//Allocate appropriate bits
	aafMemPtr_t pBits = NULL;
	check_hr ( pv->AllocateBits (cbChar, &pBits) );
	
	//Set the bits to incoming character
	ASSERT("Valid bits", pBits != 0);
	memcpy (pBits, &character, cbChar);
	
	*ppCharacterValue = pv;
	(*ppCharacterValue)->AcquireReference ();
	return AAFRESULT_SUCCESS;
}
Ejemplo n.º 4
0
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefExtEnum::CreateValueFromName (
											/*[in]*/ aafCharacter_constptr  Name,
											/*[out]*/ ImplAAFPropertyValue ** ppPropVal)
{
	if (! ppPropVal )
		return AAFRESULT_NULL_PARAM;
	
	if (! Name )
		return AAFRESULT_NULL_PARAM;
	
	if (!IsRegistered())
		return AAFRESULT_NOT_INITIALIZED;
	
	
	//Now try to do a Name lookup
	aafUID_t the_value = {0};
	AAFRESULT rc;
	rc = LookupValByName(&the_value, Name);
	

	if (rc == AAFRESULT_INVALID_PARAM)
		{
	    // Built-In names changed from v1.0 -> v1.1
	    // to remove kAAF prefix. so we have to deal with both
	    // old and new style names. 
	    // The lookup on the originally provided name failed due to
	    // the name not being found (not some other error).
	    // So here we add kAAF if it isn't there or 
	    // remove kAAF if it is there. Then look up again.
	    aafCharacter *Name_mod;

	    if ( wcsncmp (Name, L"kAAF", 4) == 0 )
	    {
		// Look past kAAF
		Name_mod = new aafCharacter[wcslen(Name) - 3];
		wcscpy(Name_mod, Name + 4);
	    }
	    else
	    {
		// Prepend kAAF
		Name_mod = new aafCharacter[wcslen(Name) + 5];
		if (!Name_mod)
		    return AAFRESULT_NOMEMORY;
		wcscpy(Name_mod, L"kAAF");
		wcscat(Name_mod, Name);
	    }

	    // Look up again - Return checked later.
	    rc = LookupValByName(&the_value, Name_mod);

	    // Cleanup of allocated memory
	    delete[] Name_mod;
	}

	// At this point, we have a successful lookup and the_val is
	// set, the name was not found (even with variation), or
	// some other error occurred. Check the result and return
	// if we are not successful.
	check_hr( rc );
	
	//else FOUND
	
	
	//Now allocate a New PV based on the local INT size ....
	
	ImplAAFTypeDef* ptd;
	ImplAAFTypeDefRecord* ptdAuid;
	
	ptd = NonRefCountedBaseType ();
	ASSERTU (ptd);
	
	ptdAuid = dynamic_cast<ImplAAFTypeDefRecord*> ((ImplAAFTypeDef*) ptd);
	ASSERTU (ptdAuid);
	
	HRESULT hr = ptdAuid->CreateValueFromStruct ((aafMemPtr_t) &the_value, sizeof (aafUID_t),
		ppPropVal);
	
	return hr;
}
Ejemplo n.º 5
0
void Texture::debugSave(const std::wstring& filepathname, Image::EImageFileFormat fileFormat)
{
    if (!mIsInitalized) return;

    ID3D11Texture1D* stagingTex1D = nullptr;
    ID3D11Texture2D* stagingTex2D = nullptr;
    ID3D11Texture3D* stagingTex3D = nullptr;

    // Init Image
    Image dstImage;
    dstImage.createAsEmptyImage(mFormat, mWidth, mHeight, mDepth, mArraySize);

    switch (mDimension)
    {
    case Texture::Texture_1D:
    {
        // Create a 1D staging texture
        D3D11_TEXTURE1D_DESC texDesc;
        texDesc.Width          = mWidth;
        texDesc.MipLevels      = mMipLevels;
        texDesc.ArraySize      = mArraySize;
        texDesc.Format         = mFormat;
        texDesc.Usage          = D3D11_USAGE_STAGING;
        texDesc.BindFlags      = 0;
        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
        texDesc.MiscFlags      = 0;

        check_hr(mDev->CreateTexture1D(&texDesc, 0, &stagingTex1D));
        // Copy this texture to the staging one
        mCtx->CopyResource(stagingTex1D, mTexture1D);

        // Map the Staging texture to copy all its sub resources into dstImage
        std::vector< D3D11_MAPPED_SUBRESOURCE> msr;
        msr.resize(mArraySize);
        for (uint32_t arrayIndex = 0; arrayIndex < mArraySize; ++arrayIndex)
        {
            std::vector<uint8_t>& dstSurface = dstImage.getSurface(arrayIndex);

            // We only want the top level mip map, as Image does not support mip map for now.
            uint32_t topLvlMipId = arrayIndex * mMipLevels;

            mCtx->Map(stagingTex1D, topLvlMipId, D3D11_MAP_READ, 0, &msr[arrayIndex]);

            check(msr[arrayIndex].DepthPitch == dstImage.getSlicePitch());

            memcpy(&dstSurface[0], msr[arrayIndex].pData, msr[arrayIndex].DepthPitch);

            mCtx->Unmap(stagingTex1D, topLvlMipId);
        }
    }
        break;
    case Texture::Texture_2D:
    {
        // Create a 2D staging texture
        D3D11_TEXTURE2D_DESC texDesc;
        texDesc.Width              = mWidth;
        texDesc.Height             = mHeight;
        texDesc.Format             = mFormat;
        texDesc.MipLevels          = mMipLevels;
        texDesc.ArraySize          = mArraySize;
        texDesc.SampleDesc.Count   = mMultiSampleCount;
        texDesc.SampleDesc.Quality = mMultiSampleQuality;
        texDesc.Usage              = D3D11_USAGE_STAGING;
        texDesc.BindFlags          = 0;
        texDesc.CPUAccessFlags     = D3D11_CPU_ACCESS_READ;
        texDesc.MiscFlags          = 0;
        check_hr(mDev->CreateTexture2D(&texDesc, 0, &stagingTex2D));

        // Copy this texture to the staging one
        mCtx->CopyResource(stagingTex2D, mTexture2D);

        // Map the Staging texture to copy all its sub resources into dstImage
        std::vector< D3D11_MAPPED_SUBRESOURCE> msr;
        msr.resize(mArraySize);
        for (uint32_t arrayIndex = 0; arrayIndex < mArraySize; ++arrayIndex)
        {
            std::vector<uint8_t>& dstSurface = dstImage.getSurface(arrayIndex);

            // We only want the top level mip map, as Image does not support mip map for now.
            uint32_t topLvlMipId = arrayIndex * mMipLevels;

            mCtx->Map(stagingTex2D, topLvlMipId, D3D11_MAP_READ, 0, &msr[arrayIndex]);

            check(msr[arrayIndex].DepthPitch == dstImage.getSlicePitch());

            memcpy(&dstSurface[0], msr[arrayIndex].pData, msr[arrayIndex].DepthPitch);

            mCtx->Unmap(stagingTex2D, topLvlMipId);
        }
    }
        break;
    case Texture::Texture_3D:
    {
        // Create a 3D staging texture
        D3D11_TEXTURE3D_DESC texDesc;
        texDesc.Width          =  mWidth;
        texDesc.Height         = mHeight;
        texDesc.Depth          = mDepth;
        texDesc.MipLevels      = mMipLevels;
        texDesc.Format         = mFormat;
        texDesc.Usage          = D3D11_USAGE_STAGING;
        texDesc.BindFlags      = 0;
        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
        texDesc.MiscFlags      = 0;
        check_hr(mDev->CreateTexture3D(&texDesc, 0, &stagingTex3D));

        // Copy this texture to the staging one
        mCtx->CopyResource(stagingTex3D, mTexture3D);

        // Map the Staging texture to copy all its sub resources into dstImage
        std::vector< D3D11_MAPPED_SUBRESOURCE> msr;
        msr.resize(mDepth);
        for (uint32_t depthSlice = 0; depthSlice < mDepth; ++depthSlice)
        {
            std::vector<uint8_t>& dstSurface = dstImage.getSurface(depthSlice);

            mCtx->Map(stagingTex2D, depthSlice, D3D11_MAP_READ, 0, &msr[depthSlice]);

            check(msr[depthSlice].DepthPitch == dstImage.getSlicePitch());

            memcpy(&dstSurface[0], msr[depthSlice].pData, msr[depthSlice].DepthPitch);

            mCtx->Unmap(stagingTex2D, depthSlice);
        }
    }
        break;
    default:
        break;
    }

    // Write image file
    dstImage.saveToFile(filepathname, fileFormat );

    safe_release(stagingTex1D);
    safe_release(stagingTex2D);
    safe_release(stagingTex3D);
}
Ejemplo n.º 6
0
bool Texture::initializeAsImmutableFromImage(const Image& srcImg, uint32_t msCount, uint32_t msQuality)
{
    if (mIsInitalized)
        return false;

    if (!srcImg.isInitialized())
        return false;

    mDev = Renderer::getInstance()->getDevice();
    mCtx = Renderer::getInstance()->getContext();

    mUsage              = EUsage::ImmutableShaderResource;
    mFormat             = srcImg.getDxgiFormat();
    mWidth              = srcImg.getWidth();
    mHeight             = srcImg.getHeight();
    mDepth              = srcImg.getDepth();
    mArraySize          = srcImg.getArraySize();
    mMipLevels          = 1;
    mMultiSampleCount   = msCount;
    mMultiSampleQuality = msQuality;

    determineTextureDimension();

    switch (mDimension)
    {
    case Texture::Texture_1D:
    {
        D3D11_TEXTURE1D_DESC texDesc;
        texDesc.Width          = mWidth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.ArraySize      = mArraySize;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_IMMUTABLE;
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE;
        texDesc.CPUAccessFlags = 0;

        std::vector<D3D11_SUBRESOURCE_DATA> srd;
        srd.resize(mArraySize);
        for (uint32_t i = 0; i < mArraySize; ++i)
        {
            const std::vector<uint8_t>& surface = srcImg.getSurface(i);

            check(!surface.empty());

            srd[i].pSysMem = &surface[0];
            srd[i].SysMemPitch = srcImg.getRowPitch();
            srd[i].SysMemSlicePitch = srcImg.getSlicePitch();
        }

        check_hr(mDev->CreateTexture1D(&texDesc, &srd[0], &mTexture1D));

        check_hr(mDev->CreateShaderResourceView(mTexture1D, nullptr, &mSRV));
    }
        break;
    case Texture::Texture_2D:
    {
        D3D11_TEXTURE2D_DESC texDesc;

        texDesc.Width              = mWidth;
        texDesc.Height             = mHeight;
        texDesc.Format             = mFormat;
        texDesc.MipLevels          = mMipLevels;
        texDesc.ArraySize          = mArraySize;
        texDesc.SampleDesc.Count   = mMultiSampleCount;
        texDesc.SampleDesc.Quality = mMultiSampleQuality;
        texDesc.MiscFlags          = 0;
        texDesc.Usage              = D3D11_USAGE_IMMUTABLE;
        texDesc.BindFlags          = D3D11_BIND_SHADER_RESOURCE;
        texDesc.CPUAccessFlags     = 0;

        //
        // Create resource and related views
        //
        std::vector<D3D11_SUBRESOURCE_DATA> srd;
        srd.resize(mArraySize);
        for (uint32_t i = 0; i < mArraySize; ++i)
        {
            const std::vector<uint8_t>& surface = srcImg.getSurface(i);

            check(!surface.empty());

            srd[i].pSysMem          = &surface[0];
            srd[i].SysMemPitch      = srcImg.getRowPitch();
            srd[i].SysMemSlicePitch = srcImg.getSlicePitch();
        }

        check_hr(mDev->CreateTexture2D(&texDesc, &srd[0], &mTexture2D));

        check_hr(mDev->CreateShaderResourceView(mTexture2D, 0, &mSRV));
    }
        break;

    case Texture::Texture_3D:
    {
        D3D11_TEXTURE3D_DESC texDesc;

        texDesc.Width          = mWidth;
        texDesc.Height         = mHeight;
        texDesc.Depth          = mDepth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_IMMUTABLE;
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE;
        texDesc.CPUAccessFlags = 0;

        //
        // Create resource and related views
        //
        std::vector<D3D11_SUBRESOURCE_DATA> srd;
        srd.resize(mDepth);
        for (uint32_t depthSlice = 0; depthSlice < mDepth; ++depthSlice)
        {
            const std::vector<uint8_t>& surface = srcImg.getSurface(depthSlice);

            check(!surface.empty());

            srd[depthSlice].pSysMem          = &surface[0];
            srd[depthSlice].SysMemPitch      = srcImg.getRowPitch();
            srd[depthSlice].SysMemSlicePitch = srcImg.getSlicePitch();
        }

        check_hr(mDev->CreateTexture3D(&texDesc, &srd[0], &mTexture3D));

        check_hr(mDev->CreateShaderResourceView(mTexture3D, 0, &mSRV));
    }
        break;
    default:
        break;
    }

    mIsInitalized = true;
    return true;
}
Ejemplo n.º 7
0
bool Texture::initializeAsDynamic(DXGI_FORMAT format, uint32_t width, uint32_t height, uint32_t depth /*= 1*/, uint32_t msCount /*= 1*/, uint32_t msQuality /*= 0*/)
{
    if (mIsInitalized) return false;

    mDev = Renderer::getInstance()->getDevice();
    mCtx = Renderer::getInstance()->getContext();

    mUsage              = EUsage::DynamicShaderResource;
    mFormat             = format;
    mWidth              = width;
    mHeight             = height;
    mDepth              = depth;
    mArraySize          = 1;
    mMipLevels          = 1;
    mMultiSampleCount   = msCount;
    mMultiSampleQuality = msQuality;

    determineTextureDimension();

    switch (mDimension)
    {
    case Texture::Texture_1D:
    {
        D3D11_TEXTURE1D_DESC texDesc;

        texDesc.Width          = mWidth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.ArraySize      = mArraySize;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_DYNAMIC;
        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // Only make sense for dynamic and staging textures
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE;

        check_hr(mDev->CreateTexture1D(&texDesc, 0, &mTexture1D));
        check_hr(mDev->CreateShaderResourceView(mTexture1D, 0, &mSRV));

        validateSRV_Texture1D();
    }
        break;

    case Texture::Texture_2D:
    {
        D3D11_TEXTURE2D_DESC texDesc;

        texDesc.Width              = mWidth;
        texDesc.Height             = mHeight;
        texDesc.Format             = mFormat;
        texDesc.MipLevels          = mMipLevels;
        texDesc.ArraySize          = mArraySize;
        texDesc.SampleDesc.Count   = mMultiSampleCount;
        texDesc.SampleDesc.Quality = mMultiSampleQuality;
        texDesc.MiscFlags          = 0;
        texDesc.Usage              = D3D11_USAGE_DYNAMIC;
        texDesc.CPUAccessFlags     = D3D11_CPU_ACCESS_WRITE; // Only make sense for dynamic and staging textures
        texDesc.BindFlags          = D3D11_BIND_SHADER_RESOURCE;

        check_hr(mDev->CreateTexture2D(&texDesc, 0, &mTexture2D));

        check_hr(mDev->CreateShaderResourceView(mTexture2D, 0, &mSRV));

        validateSRV_Texture2D();
    }
        break;
    case Texture::Texture_3D:
    {
        D3D11_TEXTURE3D_DESC texDesc;

        texDesc.Width          = mWidth;
        texDesc.Height         = mHeight;
        texDesc.Depth          = mDepth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_DYNAMIC;
        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // Only make sense for dynamic and staging textures
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE;

        check_hr(mDev->CreateTexture3D(&texDesc, 0, &mTexture3D));

        check_hr(mDev->CreateShaderResourceView(mTexture3D, 0, &mSRV));

        validateSRV_Texture3D();
    }
        break;
    default:
        break;
    }

    intializeImageCache();

    mIsInitalized = true;
    return true;
}
Ejemplo n.º 8
0
bool Texture::initializeAsDepthStencil(DXGI_FORMAT resFormat, DXGI_FORMAT dsvFormat, DXGI_FORMAT srvFormat, uint32_t width, uint32_t height, uint32_t arraySize /*= 1*/, uint32_t mip /*= 1*/, uint32_t msCount /*= 1*/, uint32_t msQuality /*= 0*/)
{
    if (mIsInitalized)
        return false;

    if (msCount > 1) mip = 1;

    // For a depth stencil to be referenced by DSV and SRV at the same time, the depth stencil itself must be created
    // with a typeless format, which allows for DSV and SRV to use their own formats.
    // In d3d11, the formats used by resource views must be cast-able from the typeless format used by the resource.
    // i.e. they are in the same 'typeless family'.

    check(DxgiFormatUtil::isTypeless(resFormat) == true);
    check(DxgiFormatUtil::isDepthStencil(dsvFormat) == true);
    check(DxgiFormatUtil::bitsPerColor(resFormat) == DxgiFormatUtil::bitsPerColor(dsvFormat));
    check(DxgiFormatUtil::bitsPerPixel(dsvFormat) == DxgiFormatUtil::bitsPerPixel(srvFormat));

    mDev = Renderer::getInstance()->getDevice();
    mCtx = Renderer::getInstance()->getContext();

    mUsage              = EUsage::DepthStencilAndShaderResource;
    mFormat             = resFormat;
    mWidth              = width;
    mHeight             = height;
    mDepth              = 1;
    mArraySize          = arraySize;
    mMipLevels          = mip;
    mMultiSampleCount   = msCount;
    mMultiSampleQuality = msQuality;

    determineTextureDimension();

    switch (mDimension)
    {
    case Texture::Texture_1D:
    {
        D3D11_TEXTURE1D_DESC texDesc;

        texDesc.Width          = mWidth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.ArraySize      = mArraySize;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_DEFAULT;
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
        texDesc.CPUAccessFlags = 0;

        //
        // Create the underlying 1D resource
        //
        check_hr(mDev->CreateTexture1D(&texDesc, 0, &mTexture1D));

        //
        // Create a dsv that has full access to the depth stencil resource
        //
        D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
        dsvDesc.Format = dsvFormat;
        dsvDesc.Flags = 0;  // 0 indicates this dsv is not read-only

        if (mArraySize > 1)
        {
            dsvDesc.ViewDimension                  = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
            dsvDesc.Texture1DArray.FirstArraySlice = 0;
            dsvDesc.Texture1DArray.ArraySize       = mArraySize;
            dsvDesc.Texture1DArray.MipSlice        = 0;
        }
        else
        {
            dsvDesc.ViewDimension      = D3D11_DSV_DIMENSION_TEXTURE1D;
            dsvDesc.Texture1D.MipSlice = 0;
        }
        check_hr(mDev->CreateDepthStencilView(mTexture1D, &dsvDesc, &mDSV));

        //
        // Create a srv that has full access to the depth stencil resource
        //
        D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
        srvDesc.Format = srvFormat;
        if (mArraySize > 1)
        {
            srvDesc.ViewDimension                  = D3D_SRV_DIMENSION_TEXTURE1DARRAY;
            srvDesc.Texture1DArray.FirstArraySlice = 0;
            srvDesc.Texture1DArray.ArraySize       = mArraySize;
            srvDesc.Texture1DArray.MostDetailedMip = 0;
            srvDesc.Texture1DArray.MipLevels       = mMipLevels;
        }
        else
        {
            srvDesc.ViewDimension             = D3D_SRV_DIMENSION_TEXTURE1D;
            srvDesc.Texture1D.MipLevels       = mMipLevels;
            srvDesc.Texture1D.MostDetailedMip = 0;
        }
        check_hr(mDev->CreateShaderResourceView(mTexture1D, 0, &mSRV));
    }
        break;

    case Texture::Texture_2D:
    {
        D3D11_TEXTURE2D_DESC texDesc;

        texDesc.Width              = mWidth;
        texDesc.Height             = mHeight;
        texDesc.Format             = mFormat;
        texDesc.MipLevels          = mMipLevels;
        texDesc.ArraySize          = mArraySize;
        texDesc.SampleDesc.Count   = mMultiSampleCount;
        texDesc.SampleDesc.Quality = mMultiSampleQuality;
        texDesc.MiscFlags          = 0;
        texDesc.Usage              = D3D11_USAGE_DEFAULT;
        texDesc.BindFlags          = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
        texDesc.CPUAccessFlags     = 0;

        //
        // Create the underlying 2D resource
        //
        check_hr(mDev->CreateTexture2D(&texDesc, 0, &mTexture2D));

        //
        // Create a dsv that has full access to the depth stencil resource
        //
        D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
        dsvDesc.Format = dsvFormat;
        dsvDesc.Flags = 0;  // 0 indicates this dsv is not read-only
        // Array
        if (mArraySize > 1)
        {
            if (isMultisamplingEnabled())
            {
                dsvDesc.ViewDimension                    = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
                dsvDesc.Texture2DMSArray.ArraySize       = mArraySize;
                dsvDesc.Texture2DMSArray.FirstArraySlice = 0;
            }
            else
            {
                dsvDesc.ViewDimension                  = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
                dsvDesc.Texture2DArray.ArraySize       = mArraySize;
                dsvDesc.Texture2DArray.FirstArraySlice = 0;
                dsvDesc.Texture2DArray.MipSlice        = 0;
            }
        }
        // Single
        else
        {
            if (isMultisamplingEnabled())
            {
                dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
                dsvDesc.Texture2DMS.UnusedField_NothingToDefine;
            }
            else
            {
                dsvDesc.ViewDimension      = D3D11_DSV_DIMENSION_TEXTURE2D;
                dsvDesc.Texture2D.MipSlice = 0;
            }
        }
        check_hr(mDev->CreateDepthStencilView(mTexture2D, &dsvDesc, &mDSV));

        //
        // Create a srv that has full access to the depth stencil resource
        //
        D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
        srvDesc.Format = srvFormat;
        // Array
        if (mArraySize > 1)
        {
            if (isMultisamplingEnabled())
            {
                srvDesc.ViewDimension                    = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
                srvDesc.Texture2DMSArray.ArraySize       = mArraySize;
                srvDesc.Texture2DMSArray.FirstArraySlice = 0;
            }
            else
            {
                srvDesc.ViewDimension                  = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
                srvDesc.Texture2DArray.ArraySize       = mArraySize;
                srvDesc.Texture2DArray.FirstArraySlice = 0;
                srvDesc.Texture2DArray.MipLevels       = mMipLevels;
                srvDesc.Texture2DArray.MostDetailedMip = 0;
            }
        }
        // Single
        else
        {
            if (isMultisamplingEnabled())
            {
                srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
                srvDesc.Texture2DMS.UnusedField_NothingToDefine;
            }
            else
            {
                srvDesc.ViewDimension             = D3D11_SRV_DIMENSION_TEXTURE2D;
                srvDesc.Texture2D.MipLevels       = mMipLevels;
                srvDesc.Texture2D.MostDetailedMip = 0;
            }
        }
        check_hr(mDev->CreateShaderResourceView(mTexture2D, &srvDesc, &mSRV));
    }
        break;

    case Texture::Texture_3D:
    default:
        break;
    }

    mIsInitalized = true;
    return true;
}
Ejemplo n.º 9
0
bool Texture::initializeAsRenderTarget(DXGI_FORMAT format, uint32_t width, uint32_t height, uint32_t arraySize /*= 1*/, uint32_t mip /*= 1*/, uint32_t msCount /*= 1*/, uint32_t msQuality /*= 0 */)
{
    if (mIsInitalized)
        return false;

    if (msCount > 1) mip = 1;

    mDev = Renderer::getInstance()->getDevice();
    mCtx = Renderer::getInstance()->getContext();

    mUsage              = EUsage::RenderTargetAndShaderResource;
    mFormat             = format;
    mWidth              = width;
    mHeight             = height;
    mDepth              = 1;
    mArraySize          = arraySize;
    mMipLevels          = mip;
    mMultiSampleCount   = msCount;
    mMultiSampleQuality = msQuality;

    determineTextureDimension();

    switch (mDimension)
    {
    case Texture::Texture_1D:
    {
        D3D11_TEXTURE1D_DESC texDesc;

        texDesc.Width          = mWidth;
        texDesc.Format         = mFormat;
        texDesc.MipLevels      = mMipLevels;
        texDesc.ArraySize      = mArraySize;
        texDesc.MiscFlags      = 0;
        texDesc.Usage          = D3D11_USAGE_DEFAULT;
        texDesc.BindFlags      = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
        texDesc.CPUAccessFlags = 0;

        check_hr(mDev->CreateTexture1D(&texDesc, 0, &mTexture1D));

        check_hr(mDev->CreateRenderTargetView(mTexture1D, 0, &mRTV));

        check_hr(mDev->CreateShaderResourceView(mTexture1D, 0, &mSRV));

        validateSRV_Texture1D();
    }
        break;

    case Texture::Texture_2D:
    {
        D3D11_TEXTURE2D_DESC texDesc;

        texDesc.Width              = mWidth;
        texDesc.Height             = mHeight;
        texDesc.Format             = mFormat;
        texDesc.MipLevels          = mMipLevels;
        texDesc.ArraySize          = mArraySize;
        texDesc.SampleDesc.Count   = mMultiSampleCount;
        texDesc.SampleDesc.Quality = mMultiSampleQuality;
        texDesc.MiscFlags          = 0;
        texDesc.Usage              = D3D11_USAGE_DEFAULT;
        texDesc.BindFlags          = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
        texDesc.CPUAccessFlags     = 0;

        check_hr(mDev->CreateTexture2D(&texDesc, 0, &mTexture2D));

        check_hr(mDev->CreateRenderTargetView(mTexture2D, 0, &mRTV));

        check_hr(mDev->CreateShaderResourceView(mTexture2D, 0, &mSRV));

        validateSRV_Texture2D();
    }
        break;

    case Texture::Texture_3D:
    default:
        break;
    }

    mIsInitalized = true;
    return true;
}