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