/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_GraphicsDrawing.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_DEMO_GRAPHICSDRAWING_H_ #define NW_DEMO_GRAPHICSDRAWING_H_ #include #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 InitializeShape( os::IAllocator* allocator, const wchar_t* shaderPath ); //--------------------------------------------------------------------------- //! @brief シェイプ描画用のシェーダの初期化をおこないます。 //! //! @param[in] pShaderBinary シェイプシェーダバイナリのポインタです。 //! @param[in] binarySize シェイプシェーダバイナリのサイズです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeShape( void* pShaderBinary, size_t binarySize ); //--------------------------------------------------------------------------- //! @brief シェイプのリソースの破棄をおこないます。 //--------------------------------------------------------------------------- void DestroyShape(); //--------------------------------------------------------------------------- //! @brief シェイプ描画用のセットアップをおこないます。 //--------------------------------------------------------------------------- void SetupShape(); //--------------------------------------------------------------------------- //! @brief シェイプ描画で描画可能な最大頂点数を設定します。 //! //! @param[in] maxShapeVertexCount 最大頂点数です。 //--------------------------------------------------------------------------- void SetMaxShapeVertexCount( s32 maxShapeVertexCount ) { m_MaxShapeVertexCount = maxShapeVertexCount; } //--------------------------------------------------------------------------- //! @brief ラインサイズを設定します。 //! //! @param[in] width ラインサイズです。 //--------------------------------------------------------------------------- void SetLineWidth( f32 width ) { m_LineWidth = width; } //--------------------------------------------------------------------------- //! @brief シェイプ描画のレンダリングの開始関数です。 //--------------------------------------------------------------------------- void BeginDrawingShape(); //--------------------------------------------------------------------------- //! @brief シェイプ描画のレンダリングの終了関数です。 //--------------------------------------------------------------------------- void EndDrawingShape(); // シェイプ描画 //--------------------------------------------------------------------------- //! @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 フォントの初期化を行います。 //! //! フォントバイナリは DestroyFont で破棄されます。 //! //! @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 フォントの初期化を行います。 //! //! フォントバイナリは Finalize 時に破棄されません。 //! //! @param[in] allocator アロケータです。 //! @param[in] fontShaderPath フォント用シェーダのパスです。 //! @param[in] fontBinary フォントバイナリのポインタです。 //! @param[in] fontSize フォントバイナリのサイズです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 //--------------------------------------------------------------------------- bool InitializeFont( os::IAllocator* allocator, const wchar_t* fontShaderPath, void* fontBinary, size_t fontSize ); //--------------------------------------------------------------------------- //! @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 フォントの描画処理を終了します。 //--------------------------------------------------------------------------- void EndDrawingString(); //@} private: //! @brief シェイプ描画用の GR ライブラリのオブジェクトを初期化します。 void InitializeShapeGraphicsState(); //! @brief シェイプ描画用のマテリアルセットアップをおこないます。 void SetupShapeMaterial(); //! @brief シェイプ描画用のテクスチャコンバイナ設定のセットアップをおこないます。 void SetupShapeTexEnv(); //! @brief シェイプ描画用のプロジェクション、モデルビュー行列を Uniform へ設定します。 void SendShapeMatrix(); //! @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] vertexCount 頂点数です //! @param[in] color 頂点カラーです //! @param[out] *pVecArray 頂点カラーを設定するバッファの先頭アドレスです。 void BuildColor( const s32 vertexCount, const ut::Color8 color, f32* pColorArray ); //! @brief バイナリからフォントの初期化を行います。 //! //! @param[in] shaderBinary シェーダバイナリのポインタです。 //! @param[in] shaderSize シェーダバイナリのサイズです。 //! @param[in] fontBinary フォントバイナリのポインタです。 //! @param[in] fontSize フォントバイナリのサイズです。 //! @param[in] drawBuffer 描画バッファのポインタです。 //! @param[in] stringBuffer 文字列用バッファです。 //! //! @return 初期化に成功した場合は true, 失敗した場合は false を返します。 bool InitializeFontFromBinary( void* shaderBinary, size_t shaderSize, void* fontBinary, size_t fontSize, void* drawBuffer, void* stringBuffer ); //! @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; static const s32 DEFAULT_MAX_SHAPE_VERTEX_COUNT = 128; static const s32 SHAPE_DRAW_LINE_VERTEX_COUNT = 6; static const s32 SHAPE_DRAW_RECTANGLE_VERTEX_COUNT = 4 * SHAPE_DRAW_LINE_VERTEX_COUNT; static const s32 SHAPE_FILL_TRIANGLE_VERTEX_COUNT = 3; static const s32 SHAPE_FILL_RECTANGLE_VERTEX_COUNT = 2 * SHAPE_FILL_TRIANGLE_VERTEX_COUNT; static const f32 FONT_SIZE; static const f32 FONT_FIXED_WIDTH; math::VEC2 m_ScreenSize; // シェイプ描画用のメンバ変数です。 f32 m_LineWidth; s32 m_MaxShapeVertexCount; s32 m_ShapeVertexCount; void* m_pShapeShaderBinary; nn::gr::Shader m_ShapeShader; nn::gr::BindSymbolVSFloat m_ShapeBindSymbolProjectionMatrix; nn::gr::BindSymbolVSFloat m_ShapeBindSymbolModelViewMatrix; nn::gr::CTR::BindSymbolVSInput m_ShapeBindSymbolPos; nn::gr::CTR::BindSymbolVSInput m_ShapeBindSymbolColor; nn::gr::Viewport m_ShapeViewport; nn::gr::RenderState m_ShapeRenderState; nn::gr::Combiner m_ShapeCombiner; nn::gr::Vertex m_ShapeVertex; nn::gr::Vertex::IndexStream m_ShapeIndexStream; math::VEC2* m_ShapePositionStreamArray; f32* m_ShapeColorStreamArray; u16* m_ShapeIndexStreamArray; nw::os::IAllocator* m_ShapeAllocator; // フォント用のメンバです。 nw::font::ResFont m_Font; nw::font::TextWriter m_TextWriter; nw::font::RectDrawer m_Drawer; s32 m_MaxTextCount; void* m_FontCommandBuffer; bool m_IsFontOwner; nw::os::IAllocator* m_FontAllocator; }; } /* namespace demo */ } /* namespace nw */ /* NW_DEMO_GRAPHICSDRAWING_H_ */ #endif