/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   200X/X/X -2016/12/01
/// 
/// @brief  DXGIFactoryラッパー関連。
/// 
/// ****************************************************************************

#include "CPL_DX_Factory.h"
#include "CPL_DX_Exception.h"


namespace CPL {
namespace DX {


// _____________________________________________________________________________
/// @brief コンストラクタ
/// 
/// IDXGIFactoryの作成
/// 
/// @param[in] in_ptr_dev : DirectXデバイスのポインタを指定します。
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Factory::Factory( DXDevice* in_ptr_dev )
{
  HRESULT hr = S_OK;

  if( in_ptr_dev )
  {
    // create IDXGIDevice
    CpGIDevice cp_GI_dev;
    hr = in_ptr_dev->QueryInterface(
      __uuidof(GIDevice),
      (void**)&cp_GI_dev );
    OutputErrorMessage( hr );
    CPL_THROW_FAILED( hr, "\t - Create GIFactory error!\n" );

    // create IDXGIAdapter
    CpGIAdapter cp_GI_adapter;
    hr = cp_GI_dev->GetParent(
      __uuidof(GIAdapter),
      (void**)&cp_GI_adapter );
    OutputErrorMessage( hr );
    CPL_THROW_FAILED( hr, "\t - Create GIFactory error!\n" );

    // create IDX
    hr = cp_GI_adapter->GetParent(
      __uuidof(GIFactory),
      (void**)&m_ptr_dx_object );
    OutputErrorMessage( hr );
    CPL_THROW_FAILED( hr, "\t - Create GIFactory error!\n" );
  }
  else
  {
    hr = CreateDXGIFactory(
      __uuidof(GIFactory),
      (void**)&m_ptr_dx_object );

    OutputErrorMessage( hr );
    CPL_THROW_FAILED( hr, "\t - Create GIFactory error!\n" );
  }
}


} // namespace DX
} // namespace CPL

