1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: font_Font.cpp
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 #include "precompiled.h"
19
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
22 #include <nn/assert.h>
23 #include <nn/gx.h>
24 #ifdef NW_PLATFORM_CTR
25 #include <nn/gx/CTR/gx_CommandAccess.h>
26 #endif
27 #include <nw/font/font_Font.h>
28
29
30 namespace nw {
31 namespace font {
32
33 namespace internal {
34
35 void
LoadTexture(u16 texWidth,u16 texHeight,TexFmt texFormat,const void * pImage,bool isSmallLinearFilter,bool isLargeLinearFilter)36 LoadTexture(
37 u16 texWidth,
38 u16 texHeight,
39 TexFmt texFormat,
40 const void* pImage,
41 bool isSmallLinearFilter,
42 bool isLargeLinearFilter
43 )
44 {
45 GLenum format = GL_ALPHA_NATIVE_DMP;
46 GLenum type = GL_UNSIGNED_BYTE;
47 switch (texFormat)
48 {
49 case FONT_SHEET_FORMAT_A4: format = GL_ALPHA_NATIVE_DMP; type = GL_UNSIGNED_4BITS_DMP; break;
50 case FONT_SHEET_FORMAT_A8: format = GL_ALPHA_NATIVE_DMP; type = GL_UNSIGNED_BYTE; break;
51 case FONT_SHEET_FORMAT_LA4: format = GL_LUMINANCE_ALPHA_NATIVE_DMP; type = GL_UNSIGNED_BYTE_4_4_DMP; break;
52 case FONT_SHEET_FORMAT_LA8: format = GL_LUMINANCE_ALPHA_NATIVE_DMP; type = GL_UNSIGNED_BYTE; break;
53
54 case FONT_SHEET_FORMAT_RGBA4: format = GL_RGBA_NATIVE_DMP; type = GL_UNSIGNED_SHORT_4_4_4_4; break;
55 case FONT_SHEET_FORMAT_RGB5A1: format = GL_RGBA_NATIVE_DMP; type = GL_UNSIGNED_SHORT_5_5_5_1; break;
56 case FONT_SHEET_FORMAT_RGBA8: format = GL_RGBA_NATIVE_DMP; type = GL_UNSIGNED_BYTE; break;
57 case FONT_SHEET_FORMAT_RGB565: format = GL_RGB_NATIVE_DMP; type = GL_UNSIGNED_SHORT_5_6_5; break;
58 case FONT_SHEET_FORMAT_RGB8: format = GL_RGB_NATIVE_DMP; type = GL_UNSIGNED_BYTE; break;
59 default:
60 NN_ASSERTMSG(false,
61 "CharWriter::LoadTexture() : Unknown font sheet format(=%d)",
62 texFormat);
63 }
64 const GLint mipLevel = 0;
65
66 // テクスチャのメモリへの読み込み指定
67 int texLoadFlag =
68 #ifdef NW_PLATFORM_CTR
69 // フォントリソースがメモリに存在していることが前提であるため、
70 // FCRAMのものを直接参照してもらい、コピーしない。
71 NN_GX_MEM_FCRAM | GL_NO_COPY_FCRAM_DMP
72 #else
73 0
74 #endif
75 ;
76
77 glTexImage2D(GL_TEXTURE_2D | texLoadFlag, mipLevel, format, texWidth, texHeight, 0, format, type, pImage);
78
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
81 GLint filter = isSmallLinearFilter ? GL_LINEAR: GL_NEAREST;
82 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
83 filter = isLargeLinearFilter ? GL_LINEAR: GL_NEAREST;
84 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
85 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0.0f);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000);
87 }
88
TextureObject()89 TextureObject::TextureObject()
90 {
91 Reset();
92 }
93
94 void
Set(u32 name,const Font * pFont,const void * pImage,TexFmt format,u16 width,u16 height)95 TextureObject::Set(
96 u32 name,
97 const Font* pFont,
98 const void* pImage,
99 TexFmt format,
100 u16 width,
101 u16 height
102 )
103 {
104 m_Name = name;
105 m_pFont = pFont;
106
107 m_pImage = pImage == NULL ?
108 0:
109 #ifdef NW_PLATFORM_CTR
110 (nngxGetPhysicalAddr(reinterpret_cast<uptr>(pImage)) / 8)
111 #else
112 reinterpret_cast<uptr>(pImage)
113 #endif
114 ;
115
116 m_Format = static_cast<u8>(format);
117 m_Size.width = width;
118 m_Size.height = height;
119 }
120
121 } // namespace internal
122
Glyph()123 Glyph::Glyph()
124 : isSheetUpdated(false)
125 {
126 }
127
~Font()128 Font::~Font()
129 {
130 }
131
132 const CharStrmReader
GetCharStrmReader(char) const133 Font::GetCharStrmReader(char /* dummy */) const
134 {
135 CharStrmReader::ReadNextCharFunc func = NULL;
136
137 switch (GetCharacterCode())
138 {
139 case CHARACTER_CODE_UNICODE: func = &CharStrmReader::ReadNextCharUTF8; break;
140 case CHARACTER_CODE_SJIS: func = &CharStrmReader::ReadNextCharSJIS; break;
141 case CHARACTER_CODE_CP1252: func = &CharStrmReader::ReadNextCharCP1252; break;
142
143 default:
144 NN_ASSERT(false);
145 break;
146 }
147
148 return CharStrmReader(func);
149 }
150
151 const CharStrmReader
GetCharStrmReader(wchar_t) const152 Font::GetCharStrmReader(wchar_t /* dummy */) const
153 {
154 CharStrmReader::ReadNextCharFunc func = NULL;
155
156 switch (GetCharacterCode())
157 {
158 case CHARACTER_CODE_UNICODE: func = &CharStrmReader::ReadNextCharUTF16; break;
159
160 default:
161 NN_ASSERT(false);
162 break;
163 }
164
165 return CharStrmReader(func);
166 }
167
168 } // namespace font
169 } // namespace nw
170