/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   200X/X/X - 2014/01/24
/// 
/// @brief  DirectX  ビューポート拡張クラス。
/// 
/// ****************************************************************************

#pragma once

#include "CPL_DX_RenderFragment.h"


namespace CPL {
namespace DX {

// _____________________________________________________________________________
/// @brief ビュー周り管理
///
// *****************************************************************************
class Viewport
  : public RenderFragment_i_
{
protected:
  DX_VIEWPORT m_viewport;

public:
  Viewport(){}
  Viewport(
    FLOAT in_top_left_x, FLOAT in_top_left_y,
    FLOAT in_width,      FLOAT in_height,
    FLOAT in_min_depth,  FLOAT in_max_depth )
  {
    m_viewport.TopLeftX = in_top_left_x;
    m_viewport.TopLeftY = in_top_left_y;
    m_viewport.Width    = in_width;
    m_viewport.Height   = in_height;
    m_viewport.MinDepth = in_min_depth;
    m_viewport.MaxDepth = in_max_depth;
  }
  Viewport( Viewport const& vp )
  {
    *this = vp;
  }
  
  void  SetXY( float x, float y ){ m_viewport.TopLeftX = x;    m_viewport.TopLeftY = y;           }
  void  SetXY( float2 xy )       { m_viewport.TopLeftX = xy.x; m_viewport.TopLeftY = xy.y;        }
  void  SetWH( float w, float h ){ m_viewport.Width = w;       m_viewport.Height = h;      }
  void  SetWH( float2 wh )       { m_viewport.Width = wh.x;    m_viewport.Height = wh.y;   }
  void  SetClipZ( float in_min, float in_max ){ m_viewport.MinDepth = in_min; m_viewport.MaxDepth = in_max; }

  DX_VIEWPORT*
        GetDxViewport(){ return &m_viewport; }
  DX_VIEWPORT const*
        GetDxViewport() const { return &m_viewport; }
  float GetX()        const { return m_viewport.TopLeftX; }
  float GetY()        const { return m_viewport.TopLeftY; }
  float GetWidth()    const { return m_viewport.Width;  }
  float GetHeight()   const { return m_viewport.Height; }
  float GetMinZ()     const { return m_viewport.MinDepth; }
  float GetMaxZ()     const { return m_viewport.MaxDepth; }

  void SetViewport( DXDeviceContext* in_ptr_d3d_dc )
  {
    in_ptr_d3d_dc->RSSetViewports( 1, &m_viewport );
  }
  HRESULT RenderSetup( DXDeviceContext* in_ptr_d3d_IC )
  {
    SetViewport( in_ptr_d3d_IC );
    return S_OK;
  }
};



} // namespace DX
} // namespace CPL
