Ejemplo n.º 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;
}