/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_GraphicsDrawing.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 24575 $ *---------------------------------------------------------------------------*/ #ifndef NW_DEMO_GRAPHICSDRAWING_H_ #define NW_DEMO_GRAPHICSDRAWING_H_ #include #include #include #include #include #include #include namespace nw { namespace os { class IAllocator; } namespace font { class Font; } namespace demo { //--------------------------------------------------------------------------- //! @brief デモ用の文字やプリミティブを描画するためのクラスです。 //--------------------------------------------------------------------------- class GraphicsDrawing { public: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //--------------------------------------------------------------------------- //! @brief スクリーンサイズを設定します。 //! //! @param[in] width スクリーンの横幅です。 //! @param[in] height スクリーンの縦幅です。 //--------------------------------------------------------------------------- void SetScreenSize( s32 width, s32 height ) { m_ScreenSize = math::VEC2( static_cast(width), static_cast(height) ); } //--------------------------------------------------------------------------- //! @brief コンストラクタです。 //--------------------------------------------------------------------------- GraphicsDrawing(); //--------------------------------------------------------------------------- //! @brief デストラクタです。 //--------------------------------------------------------------------------- ~GraphicsDrawing(); //@} //--------------------------------------------------------------------------- //! @brief リソースの破棄をおこないます。 //--------------------------------------------------------------------------- void Finalize(); //======================================================================================== //! @name シェイプ描画 //@{ //--------------------------------------------------------------------------- //! @brief シェーダの初期化をおこないます。 //! //! @param[in] allocator アロケータです。 //! @param[in] shaderPath シェーダバイナリのファイルパスです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeShader( os::IAllocator* allocator, const wchar_t* shaderPath ); //--------------------------------------------------------------------------- //! @brief シェーダや描画用のセットアップをおこないます。 //--------------------------------------------------------------------------- void Setup(); //--------------------------------------------------------------------------- //! @brief ラインサイズを設定します。 //! //! @param[in] width ラインサイズです。 //--------------------------------------------------------------------------- void SetLineWidth(f32 width) { m_LineWidth = width; } //--------------------------------------------------------------------------- //! @brief demo::GraphicsDrawing のレンダリングの開始関数です。 //--------------------------------------------------------------------------- void BeginDrawingShape(); // 図形描画 //--------------------------------------------------------------------------- //! @brief ラインを描画します。 ラインシェーダは使用せず、CPUで頂点を生成します。 //! //! @param[in] x1 ライン開始点の x 座標です。 //! @param[in] y1 ライン開始点の y 座標です。 //! @param[in] x2 ライン終了点の x 座標です。 //! @param[in] y2 ライン終了点の y 座標です。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void DrawLine( s32 x1, s32 y1, s32 x2, s32 y2, ut::Color8 color ) { this->DrawLine( math::VEC2(static_cast(x1), static_cast(y1)), math::VEC2(static_cast(x2), static_cast(y2)), color ); } //--------------------------------------------------------------------------- //! @brief ラインを描画します。 ラインシェーダは使用せず、CPUで頂点を生成します。 //! //! @param[in] p1 ラインの開始点です。 //! @param[in] p2 ラインの終了点です。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void DrawLine( const math::VEC2& p1, const math::VEC2& p2, ut::Color8 color ); //--------------------------------------------------------------------------- //! @brief 四角形の線を描画します。 ラインシェーダは使用せず、CPUで頂点を生成します。 //! //! @param[in] posh 左上端のx座標です。 //! @param[in] posv 左上端のy座標です。 //! @param[in] sizeh 四角形のx方向サイズです。 //! @param[in] sizev 四角形のy方向サイズです。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void DrawRectangle( s32 posh, s32 posv, s32 sizeh, s32 sizev, ut::Color8 color ) { this->DrawRectangle( math::VEC2(static_cast(posh), static_cast(posv)), math::VEC2(static_cast(sizeh), static_cast(sizev)), color ); } //--------------------------------------------------------------------------- //! @brief 四角形の線を描画します。 ラインシェーダは使用せず、CPUで頂点を生成します。 //! //! @param[in] pos 左上端の座標です。 //! @param[in] size 四角形のサイズです。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void DrawRectangle( const math::VEC2& pos, const math::VEC2& size, ut::Color8 color ); //--------------------------------------------------------------------------- //! @brief 四角形を描画します。 //! //! @param[in] posh 左上端のx座標です。 //! @param[in] posv 左上端のy座標です。 //! @param[in] sizeh 四角形のx方向サイズです。 //! @param[in] sizev 四角形のy方向サイズです。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void FillRectangle( s32 posh, s32 posv, s32 sizeh, s32 sizev, ut::Color8 color ) { this->FillRectangle( math::VEC2(static_cast(posh), static_cast(posv)), math::VEC2(static_cast(sizeh), static_cast(sizev)), color ); } //--------------------------------------------------------------------------- //! @brief 四角形を描画します。 //! //! @param[in] pos 左上端の座標です。 //! @param[in] size 四角形のサイズです。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void FillRectangle( const math::VEC2& pos, const math::VEC2& size, ut::Color8 color ); //--------------------------------------------------------------------------- //! @brief 三角形を描画します。 //! //! @param[in] pt1 頂点1です。 //! @param[in] pt2 頂点2です。 //! @param[in] pt3 頂点3です。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void FillTriangle( const math::VEC2& pt1, const math::VEC2& pt2, const math::VEC2& pt3, ut::Color8 color ); //--------------------------------------------------------------------------- //! @brief 三角形を描画します。 //! //! @param[in] pPointArray 頂点配列へのポインタです。 //! @param[in] pointCount 頂点数です。 //! @param[in] color カラーです。 //--------------------------------------------------------------------------- void FillTriangles( const math::VEC2* pPointArray, s32 pointCount, ut::Color8 color ); //@} //======================================================================================== //! @name フォント描画 //@{ //--------------------------------------------------------------------------- //! @brief 描画可能な最大文字数を設定します。 //! //! @param[in] maxTextCount 最大文字数です。 //--------------------------------------------------------------------------- void SetMaxTextCount( s32 maxTextCount ) { m_MaxTextCount = maxTextCount; } //--------------------------------------------------------------------------- //! @brief フォントの初期化をおこないます。 //! //! @param[in] allocator アロケータです。 //! @param[in] fontShaderPath フォント用シェーダのパスです。 //! @param[in] fontPath フォントファイルのパスです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeFont( os::IAllocator* allocator, const wchar_t* fontShaderPath, const wchar_t* fontPath ); //--------------------------------------------------------------------------- //! @brief フォントの破棄をおこないます。 //--------------------------------------------------------------------------- void DestroyFont(); //--------------------------------------------------------------------------- //! @brief demo::GraphicsDrawing のフォントレンダリングの開始関数です。 //--------------------------------------------------------------------------- void BeginDrawingString(); //--------------------------------------------------------------------------- //! @brief 文字列を描画します。 //! //! @param[in] format フォーマット文字列です。 //! @param[in] ... 出力パラメータです。 //! //! @return 出力文字幅を返します。 //--------------------------------------------------------------------------- f32 DrawString( const char* format, ... ); //--------------------------------------------------------------------------- //! @brief 位置指定付きで、文字列を描画します。 //! //! @param[in] posh 出力開始位置の x 座標です。 //! @param[in] posv 出力開始位置の y 座標です。 //! @param[in] format フォーマット文字列です。 //! @param[in] ... 出力パラメータです。 //! //! @return 出力文字幅を返します。 //--------------------------------------------------------------------------- f32 DrawString( s32 posh, s32 posv, const char* format, ... ); //--------------------------------------------------------------------------- //! @brief 位置指定付きで、文字列を描画します。 //! //! @param[in] posh 出力開始位置の x 座標です。 //! @param[in] posv 出力開始位置の y 座標です。 //! @param[in] format フォーマット文字列です。 //! @param[in] args 出力パラメータです。 //! //! @return 出力文字幅を返します。 //--------------------------------------------------------------------------- f32 DrawStringArgs( s32 posh, s32 posv, const char* format, std::va_list args ); //! @brief デモ用のテキストライターを取得します。 font::TextWriter& GetWriter() { return m_TextWriter; } const font::TextWriter& GetWriter() const { return m_TextWriter; } //@} //--------------------------------------------------------------------------- //! @brief demo::GraphicsDrawing の描画を Flush します。 //--------------------------------------------------------------------------- void FlushDrawing(); //--------------------------------------------------------------------------- //! @brief シェーダの初期化をおこないます。 //! //! @param[in] pShaderBinary シェーダバイナリのポインタです。 //! @param[in] binarySize シェーダバイナリのサイズです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeShader( void* pShaderBinary, size_t binarySize ); //--------------------------------------------------------------------------- //! @brief フォントの初期化をおこないます。 //! //! @param[in] shaderBinary シェーダバイナリのポインタです。 //! @param[in] shaderSize シェーダバイナリのサイズです。 //! @param[in] fontBinary フォントバイナリのポインタです。 //! @param[in] fontSize フォントバイナリのサイズです。 //! @param[in] drawBuffer 描画バッファのポインタです。 //! @param[in] stringBuffer 文字列用バッファです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeFont( void* shaderBinary, size_t shaderSize, void* fontBinary, size_t fontSize, void* drawBuffer, void* stringBuffer ); private: //! @brief デモ描画用のマテリアルセットアップをおこないます。 void SetupMaterial(); //! @brief デモ描画用のテクスチャコンバイナ設定のセットアップをおこないます。 void SetupTexEnv(); //! @brief プロジェクション、モデルビュー行列を Uniform へ設定します。 void SendMatrix(); //! @brief 四角形描画用の頂点列を生成します。 //! //! @param[in] pt1 頂点座標1です。 //! @param[in] pt2 頂点座標2です。 //! @param[in] pt3 頂点座標3です。 //! @param[out] *pVecArray 頂点列を生成するバッファの先頭アドレスです。 //! //! @return 頂点数を返します。 s32 BuildTriangle( const math::VEC2& pt1, const math::VEC2& pt2, const math::VEC2& pt3, math::VEC2 *pVecArray ); //! @brief xy軸に平行な四角形描画用の頂点列を生成します。 //! //! @param[in] pos 左上座標です。 //! @param[in] size 四角形のサイズです。 //! @param[out] *pVecArray 頂点列を生成するバッファの先頭アドレスです。 //! //! @return 頂点数を返します。 s32 BuildRectangle( const math::VEC2& pos, const math::VEC2& size, math::VEC2 *pVecArray ); //! @brief 四角形描画用の頂点列を生成します。 //! //! 頂点は、pt1, pt2, pt3, pt4 の順に、時計回り または 反時計回りに //! 指定する必要があります。 //! //! @param[in] pt1 頂点座標1です。 //! @param[in] pt2 頂点座標2です。 //! @param[in] pt3 頂点座標3です。 //! @param[in] pt4 頂点座標4です。 //! @param[out] *pVecArray 頂点列を生成するバッファの先頭アドレスです。 //! //! @return 頂点数を返します。 s32 BuildRectangle( const math::VEC2& pt1, const math::VEC2& pt2, const math::VEC2& pt3, const math::VEC2& pt4, math::VEC2 *pVecArray ); //! @brief ライン描画用の頂点列を生成します。 //! //! @param[in] pt1 ラインの開始座標です。 //! @param[in] pt2 ラインの終端座標です。 //! @param[in] lineWidth ライン幅の指定です。 //! @param[out] *pVecArray 頂点列を生成するバッファの先頭アドレスです。 //! //! @return 頂点数を返します。 s32 BuildLine( const math::VEC2& pt1, const math::VEC2& pt2, f32 lineWidth, math::VEC2 *pVecArray ); //! @brief フォントデータを設定します。 //! //! @param[in] fontData フォントバイナリへのポインタです。 //! @param[in] fontSize フォントバイナリサイズです。 //! //! @return 設定に成功した場合は true そうでなければ false を返します。 bool InitializeFontResource( void* fontData, size_t fontSize ); //! @brief フォント用のシェーダを設定します。 //! //! @param[in] shaderData シェーダバイナリへのポインタです。 //! @param[in] shaderSize シェーダバイナリサイズです。 //! //! @return 設定に成功した場合は true そうでなければ false を返します。 bool InitializeFontShader( void* shaderData, size_t shaderSize ); //! @brief 文字列表示用にモデルビュー行列と射影行列を設定します。 void SendFontMatrix(); static const s32 DEFAULT_SCREEN_WIDTH = 320; static const s32 DEFAULT_SCREEN_HEIGHT = 240; static const s32 DEFAULT_MAX_TEXT_COUNT = 512; enum { VERTEX_STREAM_SIZE = 24 }; math::VEC2 m_ScreenSize; f32 m_LineWidth; GLuint m_ProgramID; GLuint m_ShaderID; void* m_pShaderBinary; math::VEC2 m_PositionStream[ VERTEX_STREAM_SIZE ]; math::VEC4 m_ColorStream[ VERTEX_STREAM_SIZE ]; math::VEC2 m_TexCoordStream[ VERTEX_STREAM_SIZE ]; nw::font::ResFont m_Font; nw::font::TextWriter m_TextWriter; nw::font::RectDrawer m_Drawer; s32 m_MaxTextCount; void* m_FontCommandBuffer; nw::os::IAllocator* m_FontAllocator; nw::os::IAllocator* m_ShapeAllocator; }; } /* namespace demo */ } /* namespace nw */ /* NW_DEMO_GRAPHICSDRAWING_H_ */ #endif