1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: font_TextWriterResource.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_FONT_TEXTWRITERRESOURCE_H_ 19 #define NW_FONT_TEXTWRITERRESOURCE_H_ 20 21 #if defined(_MSC_VER) && _MSC_VER >= 1500 22 #pragma once 23 #endif 24 25 #include <nn/types.h> 26 #include <nn/math.h> 27 #include <nw/ut/ut_Preprocessor.h> 28 #include <nw/font/font_Types.h> 29 30 namespace nw { 31 namespace font { 32 33 struct DispStringBuffer; 34 class CharWriter; 35 36 class TextWriterResource : private nn::util::NonCopyable<TextWriterResource> 37 { 38 friend class CharWriter; 39 40 public: 41 42 //! @name コンストラクタ/デストラクタ 43 //@{ 44 45 //! コンストラクタです。 46 TextWriterResource(); 47 48 //! デストラクタです。 49 ~TextWriterResource(); 50 51 //@} 52 53 54 //! @name リソースの初期化/破棄 55 //@{ 56 57 //! @brief DMPGLを使用した描画用のリソースを確保し初期化します。(非推奨) 58 //! 59 //! @param[in] shaderBinary シェーダバイナリ(nwfont_TextWriterShader.shbin) 60 //! @param[in] size シェーダバイナリのサイズ 61 //! 62 void InitResource( 63 const void* shaderBinary, 64 u32 size); 65 66 //! 後処理を行います。 67 void Finalize(); 68 69 //! DMPGLを使用した描画用のリソースを破棄します。(非推奨) DeleteResource()70 void DeleteResource() { Finalize(); } 71 72 //! 描画設定の後処理を行います。 73 static void FinalizeGX(); 74 75 //@} 76 77 78 //! @name 行列の設定 79 //@{ 80 81 //! @brief 射影行列を設定します。 82 //! 83 //! @param[in] mtx 射影行列 84 //! 85 void SetProjectionMtx(const nn::math::MTX44& mtx) const; 86 87 //! @brief ビュー行列を設定します。 88 //! 89 //! @param[in] mtx ビュー行列 90 //! 91 void SetViewMtx(const nn::math::MTX34& mtx) const; 92 93 //@} 94 95 96 //! @name シェーダープログラム関連 97 //@{ 98 99 //! 文字描画用のGLプログラムを有効にします。 ActiveGlProgram()100 void ActiveGlProgram() const 101 { 102 glUseProgram(m_ProgramId); 103 } 104 105 //! @brief プログラムハンドルを取得します。 106 //! 107 //! @return プログラムハンドルを返します。 108 //! GetGlProgram()109 u32 GetGlProgram() const { return m_ProgramId; } 110 111 //@} 112 113 private: 114 enum 115 { 116 VBO_ARRAY, 117 VBO_ELEMENT_ARRAY, 118 119 VBO_NUM 120 }; 121 122 typedef const int (*TexEnvUniformLocationSquareArray)[internal::TCLOC_MAX]; 123 GetTextureID()124 GLuint GetTextureID() const { return m_TextureId; } 125 126 internal::VertexAttribute* GetVertexAttributeArray()127 GetVertexAttributeArray() { return m_VtxAttrs; } 128 129 //! @brief UniformLocation変数配列を取得します。 130 //! 131 //! @return UniformLocation変数配列のポインタを返します。 132 //! GetUniformLocations()133 const int* GetUniformLocations() const { return m_UniformLocations; } 134 135 //! @brief テクスチャコンバイナ用UniformLocation変数配列を取得します。 136 //! 137 //! @return テクスチャコンバイナ用UniformLocation変数配列のポインタを返します。 138 //! 139 TexEnvUniformLocationSquareArray GetTexEnvUniformLocations()140 GetTexEnvUniformLocations() const { return m_TexEnvUniformLocations; } 141 142 //! 読み込み済みテクスチャをリセットします。 ResetLoadingTexture()143 void ResetLoadingTexture() { m_LoadingTexture = NULL; } 144 145 //! @brief 読み込むテクスチャをセットします。 146 //! 147 //! @return テクスチャが変更された場合は真を返します。 148 //! SetLoadingTexture(const void * pTexture)149 bool SetLoadingTexture(const void* pTexture) 150 { 151 const bool isChanged = m_LoadingTexture != pTexture; 152 m_LoadingTexture = pTexture; 153 return isChanged; 154 } 155 156 void SetPosZ(f32 posZ); 157 UpdatePosZ(f32 posZ)158 void UpdatePosZ(f32 posZ) 159 { 160 if (m_PosZ != posZ) 161 { 162 SetPosZ(posZ); 163 } 164 } 165 166 u32 m_ProgramId; //!< プログラムID 167 GLuint m_TextureId; //!< テクスチャオブジェクトのID 168 internal::VertexAttribute 169 m_VtxAttrs[internal::TRIFAN_VTX_MAX]; 170 int m_UniformLocations[internal::LOC_MAX]; 171 int m_TexEnvUniformLocations[internal::TEXENV_MAX][internal::TCLOC_MAX]; 172 const void* m_LoadingTexture; //!< ロード済みテクスチャ 173 f32 m_PosZ; //!< Zの位置 174 175 bool m_IsInitialized; //!< 初期化したかどうか 176 }; 177 178 } // namespace font 179 } // namespace nw 180 181 #endif // NW_FONT_TEXTWRITERRESOURCE_H_ 182