Пример #1
0
bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *inTex, void *raw)
{
   PROFILE_SCOPE(GFXD3D11TextureManager_loadTextureRaw);

   GFXD3D11TextureObject *texture = (GFXD3D11TextureObject *) inTex;
   GFXD3D11Device* dev = static_cast<GFXD3D11Device *>(GFX);
   // currently only for volume textures...
   if(texture->getDepth() < 1) return false;

   U8* Bits = NULL;
  
   if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB)
   {
	   // convert 24 bit to 32 bit
	   Bits = new U8[texture->getWidth() * texture->getHeight() * texture->getDepth() * 4];
	   dMemcpy(Bits, raw, texture->getWidth() * texture->getHeight() * texture->getDepth() * 3);
	   bitmapConvertRGB_to_RGBX(&Bits, texture->getWidth() * texture->getHeight() * texture->getDepth());      
   }

   U32 bytesPerPix = 1;

   switch(texture->mFormat)
   {
      case GFXFormatR8G8B8:
      case GFXFormatR8G8B8_SRGB:
      case GFXFormatR8G8B8A8:
      case GFXFormatR8G8B8X8:
      case GFXFormatR8G8B8A8_SRGB:
         bytesPerPix = 4;
         break;
   }

   D3D11_BOX box;
   box.left    = 0;
   box.right   = texture->getWidth();
   box.front   = 0;
   box.back    = texture->getDepth();
   box.top     = 0;
   box.bottom  = texture->getHeight();

   if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB) // converted format also for volume textures
		dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, Bits, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix);
   else
		dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, raw, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix);

   SAFE_DELETE_ARRAY(Bits);

   return true;
}
Пример #2
0
void GFXD3D11TextureManager::createResourceView(U32 height, U32 width, U32 depth, DXGI_FORMAT format, U32 numMipLevels,U32 usageFlags, GFXTextureObject *inTex)
{
	GFXD3D11TextureObject *tex = static_cast<GFXD3D11TextureObject*>(inTex);
	ID3D11Resource* resource = NULL;
	
	if(tex->get2DTex())
		resource = tex->get2DTex();
	else if(tex->getSurface())
		resource = tex->getSurface();
	else
		resource = tex->get3DTex();

	HRESULT hr;
	//TODO: add MSAA support later.
	if(usageFlags & D3D11_BIND_SHADER_RESOURCE)
	{
      D3D11_SHADER_RESOURCE_VIEW_DESC desc;

      if(usageFlags & D3D11_BIND_DEPTH_STENCIL)
         desc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; // reads the depth
      else
         desc.Format = format;
	
		if(depth > 0)
		{
			desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
			desc.Texture3D.MipLevels = -1;
			desc.Texture3D.MostDetailedMip = 0;
		}
		else
		{
			desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
			desc.Texture2D.MipLevels = -1;
			desc.Texture2D.MostDetailedMip = 0;
		}
		
		hr = D3D11DEVICE->CreateShaderResourceView(resource,&desc, tex->getSRViewPtr());
		AssertFatal(SUCCEEDED(hr), "CreateShaderResourceView:: failed to create view!");
	}

	if(usageFlags & D3D11_BIND_RENDER_TARGET)
	{
		D3D11_RENDER_TARGET_VIEW_DESC desc;
		desc.Format = format;
		desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
		desc.Texture2D.MipSlice = 0;
		hr = D3D11DEVICE->CreateRenderTargetView(resource, &desc, tex->getRTViewPtr());
		AssertFatal(SUCCEEDED(hr), "CreateRenderTargetView:: failed to create view!");
	}

	if(usageFlags & D3D11_BIND_DEPTH_STENCIL)
	{
		D3D11_DEPTH_STENCIL_VIEW_DESC desc;
		desc.Format = format;
		desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
		desc.Texture2D.MipSlice = 0;
		desc.Flags = 0;
		hr = D3D11DEVICE->CreateDepthStencilView(resource,&desc, tex->getDSViewPtr());
		AssertFatal(SUCCEEDED(hr), "CreateDepthStencilView:: failed to create view!");
	}
}