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: 33579 $
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     //
38     //
39 
40     //
41                         TextWriterResource();
42 
43     //
44                         ~TextWriterResource();
45 
46     //
47 
48 
49     //
50     //
51 
52     //
53     //
54     //
55     //
56     //
57     void                InitResource(
58                             const void* shaderBinary,
59                             u32         size);
60 
61     //
62     void                Finalize();
63 
64     //
DeleteResource()65     void                DeleteResource()    { Finalize(); }
66 
67     //
68     static void         FinalizeGX();
69 
70     //
71 
72 
73     //
74     //
75 
76     //
77     //
78     //
79     //
80     void                SetProjectionMtx(const nn::math::MTX44& mtx) const;
81 
82     //
83     //
84     //
85     //
86     void                SetViewMtx(const nn::math::MTX34& mtx) const;
87 
88     //
89 
90 
91     //
92     //
93 
94     //
ActiveGlProgram()95     void                ActiveGlProgram() const
96     {
97         glUseProgram(m_ProgramId);
98     }
99 
100     //
101     //
102     //
103     //
GetGlProgram()104     u32                 GetGlProgram() const                { return m_ProgramId; }
105 
106     //
107 
108 private:
109     enum
110     {
111         VBO_ARRAY,
112         VBO_ELEMENT_ARRAY,
113 
114         VBO_NUM
115     };
116 
117     typedef const int   (*TexEnvUniformLocationSquareArray)[internal::TCLOC_MAX];
118 
GetTextureID()119     GLuint              GetTextureID() const                { return m_TextureId; }
120 
121     internal::VertexAttribute*
GetVertexAttributeArray()122                         GetVertexAttributeArray()           { return m_VtxAttrs; }
123 
124     //
125     //
126     //
127     //
GetUniformLocations()128     const int*          GetUniformLocations() const         { return m_UniformLocations; }
129 
130     //
131     //
132     //
133     //
134     TexEnvUniformLocationSquareArray
GetTexEnvUniformLocations()135                         GetTexEnvUniformLocations() const   { return m_TexEnvUniformLocations; }
136 
137     //
ResetLoadingTexture()138     void                ResetLoadingTexture()     { m_LoadingTexture = NULL; }
139 
140     //
141     //
142     //
143     //
SetLoadingTexture(const void * pTexture)144     bool                SetLoadingTexture(const void* pTexture)
145     {
146         const bool isChanged = m_LoadingTexture != pTexture;
147         m_LoadingTexture = pTexture;
148         return isChanged;
149     }
150 
151     void                SetPosZ(f32 posZ);
152 
UpdatePosZ(f32 posZ)153     void                UpdatePosZ(f32 posZ)
154     {
155         if (m_PosZ != posZ)
156         {
157             SetPosZ(posZ);
158         }
159     }
160 
161     u32                 m_ProgramId;            //
162     GLuint              m_TextureId;            //
163     internal::VertexAttribute
164                         m_VtxAttrs[internal::TRIFAN_VTX_MAX];
165     int                 m_UniformLocations[internal::LOC_MAX];
166     int                 m_TexEnvUniformLocations[internal::TEXENV_MAX][internal::TCLOC_MAX];
167     const void*         m_LoadingTexture;       //
168     f32                 m_PosZ;                 //
169 
170     bool                m_IsInitialized;        //
171     NN_PADDING3;
172 };
173 
174 }   // namespace CTR
175 }   // namespace font
176 }   // namespace nn
177 
178 #endif //  NN_FONT_TEXT_WRITER_RESOURCE_H_
179