1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_Window.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 <nw/lyt/lyt_Common.h>
21 #include <nw/lyt/lyt_DrawInfo.h>
22 #include <nw/lyt/lyt_GraphicsResource.h>
23 #include <nw/lyt/lyt_Layout.h>
24 #include <nw/lyt/lyt_Window.h>
25 #include <nw/lyt/lyt_Material.h>
26 #include <nw/lyt/lyt_Animation.h>
27 #include <nw/lyt/lyt_ResourceAccessor.h>
28 #include <nw/lyt/lyt_Stopwatch.h>
29 
30 namespace nw
31 {
32 namespace lyt
33 {
34 namespace local
35 {
36 namespace
37 {
38 
39 struct Rect
40 {
41     f32 x, y, w, h;
42 
Positionnw::lyt::local::__anondbc6db900111::Rect43     const math::VEC2& Position() const
44     {
45         return *(const math::VEC2 *)&this->x;
46     }
47 
Sizenw::lyt::local::__anondbc6db900111::Rect48     const nw::lyt::Size& Size() const
49     {
50         return *(const nw::lyt::Size *)&this->w;
51     }
52 };
53 
54 struct TextureFlipInfo
55 {
56     u8      coords[VERTEX_MAX][2];
57     u8      idx[2];
58 
59 };
60 
61 const TextureFlipInfo&
GetTexutreFlipInfo(u8 textureFlip)62 GetTexutreFlipInfo(u8 textureFlip)
63 {
64     NW_ASSERT(textureFlip < TEXTUREFLIP_MAX);
65 
66     static TextureFlipInfo flipInfos[] =
67     {
68         { { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }, { 0, 1 } },   // TEXTUREFLIP_NONE
69         { { { 1, 0 }, { 0, 0 }, { 1, 1 }, { 0, 1 } }, { 0, 1 } },   // TEXTUREFLIP_FLIPH
70         { { { 0, 1 }, { 1, 1 }, { 0, 0 }, { 1, 0 } }, { 0, 1 } },   // TEXTUREFLIP_FLIPV
71         { { { 0, 1 }, { 0, 0 }, { 1, 1 }, { 1, 0 } }, { 1, 0 } },   // TEXTUREFLIP_ROTATE90
72         { { { 1, 1 }, { 0, 1 }, { 1, 0 }, { 0, 0 } }, { 0, 1 } },   // TEXTUREFLIP_ROTATE180
73         { { { 1, 0 }, { 1, 1 }, { 0, 0 }, { 0, 1 } }, { 1, 0 } },   // TEXTUREFLIP_ROTATE270
74     };
75 
76     return flipInfos[textureFlip];
77 }
78 
79 void
GetLTFrameSize(math::VEC2 * pPt,Size * pSize,const math::VEC2 & basePt,const Size & winSize,const WindowFrameSize & frameSize)80 GetLTFrameSize(
81     math::VEC2*             pPt,
82     Size*                   pSize,
83     const math::VEC2&       basePt,
84     const Size&             winSize,
85     const WindowFrameSize&  frameSize
86 )
87 {
88     *pPt = basePt;
89 
90     pSize->width = winSize.width - frameSize.r;
91     pSize->height = frameSize.t;
92 }
93 
94 void
GetLTTexCoord(math::VEC2 texCds[],const Size & polSize,const TexSize & texSize,u8 textureFlip)95 GetLTTexCoord(
96     math::VEC2 texCds[],
97     const Size& polSize,
98     const TexSize& texSize,
99     u8 textureFlip
100 )
101 {
102     const TextureFlipInfo& flipInfo = GetTexutreFlipInfo(textureFlip);
103     const int ix = flipInfo.idx[0];
104     const int iy = flipInfo.idx[1];
105     const math::VEC2 tSz(texSize.width, texSize.height);
106 
107     texCds[VERTEX_LT][ix] = texCds[VERTEX_LB][ix] = flipInfo.coords[VERTEX_LT][ix];
108     texCds[VERTEX_LT][iy] = texCds[VERTEX_RT][iy] = flipInfo.coords[VERTEX_LT][iy];
109 
110     texCds[VERTEX_RB][ix] = texCds[VERTEX_RT][ix] = polSize.width  / ((flipInfo.coords[VERTEX_RT][ix] - flipInfo.coords[VERTEX_LT][ix]) * tSz[ix]) + flipInfo.coords[VERTEX_LT][ix];
111     texCds[VERTEX_RB][iy] = texCds[VERTEX_LB][iy] = polSize.height / ((flipInfo.coords[VERTEX_LB][iy] - flipInfo.coords[VERTEX_LT][iy]) * tSz[iy]) + flipInfo.coords[VERTEX_LT][iy];
112 }
113 
114 void
GetRTFrameSize(math::VEC2 * pPt,Size * pSize,const math::VEC2 & basePt,const Size & winSize,const WindowFrameSize & frameSize)115 GetRTFrameSize(
116     math::VEC2*             pPt,
117     Size*                   pSize,
118     const math::VEC2&       basePt,
119     const Size&             winSize,
120     const WindowFrameSize&  frameSize
121 )
122 {
123     using namespace nw::math;
124 
125     *pPt = VEC2(basePt.x + winSize.width - frameSize.r, basePt.y);
126 
127     pSize->width  = frameSize.r;
128     pSize->height = winSize.height - frameSize.b;
129 }
130 
131 void
GetRTTexCoord(math::VEC2 texCds[],const Size & polSize,const TexSize & texSize,u8 textureFlip)132 GetRTTexCoord(
133     math::VEC2 texCds[],
134     const Size& polSize,
135     const TexSize& texSize,
136     u8 textureFlip
137 )
138 {
139     const TextureFlipInfo& flipInfo = GetTexutreFlipInfo(textureFlip);
140     const int ix = flipInfo.idx[0];
141     const int iy = flipInfo.idx[1];
142     const math::VEC2 tSz(texSize.width, texSize.height);
143 
144     texCds[VERTEX_RT][ix] = texCds[VERTEX_RB][ix] = flipInfo.coords[VERTEX_RT][ix];
145     texCds[VERTEX_RT][iy] = texCds[VERTEX_LT][iy] = flipInfo.coords[VERTEX_RT][iy];
146 
147     texCds[VERTEX_LB][ix] = texCds[VERTEX_LT][ix] = polSize.width  / ((flipInfo.coords[VERTEX_LT][ix] - flipInfo.coords[VERTEX_RT][ix]) * tSz[ix]) + flipInfo.coords[VERTEX_RT][ix];
148     texCds[VERTEX_LB][iy] = texCds[VERTEX_RB][iy] = polSize.height / ((flipInfo.coords[VERTEX_RB][iy] - flipInfo.coords[VERTEX_RT][iy]) * tSz[iy]) + flipInfo.coords[VERTEX_RT][iy];
149 }
150 
151 void
GetLBFrameSize(math::VEC2 * pPt,Size * pSize,const math::VEC2 & basePt,const Size & winSize,const WindowFrameSize & frameSize)152 GetLBFrameSize(
153     math::VEC2*             pPt,
154     Size*                   pSize,
155     const math::VEC2&       basePt,
156     const Size&             winSize,
157     const WindowFrameSize&  frameSize
158 )
159 {
160     *pPt = math::VEC2(basePt.x, basePt.y - frameSize.t);
161 
162     pSize->width  = frameSize.l;
163     pSize->height = winSize.height - frameSize.t;
164 }
165 
166 void
GetLBTexCoord(math::VEC2 texCds[],const Size & polSize,const TexSize & texSize,u8 textureFlip)167 GetLBTexCoord(
168     math::VEC2  texCds[],
169     const Size& polSize,
170     const TexSize& texSize,
171     u8 textureFlip
172 )
173 {
174     const TextureFlipInfo& flipInfo = GetTexutreFlipInfo(textureFlip);
175     const int ix = flipInfo.idx[0];
176     const int iy = flipInfo.idx[1];
177     const math::VEC2 tSz(texSize.width, texSize.height);
178 
179     texCds[VERTEX_LB][ix] = texCds[VERTEX_LT][ix] = flipInfo.coords[VERTEX_LB][ix];
180     texCds[VERTEX_LB][iy] = texCds[VERTEX_RB][iy] = flipInfo.coords[VERTEX_LB][iy];
181 
182     texCds[VERTEX_RT][ix] = texCds[VERTEX_RB][ix] = polSize.width  / ((flipInfo.coords[VERTEX_RB][ix] - flipInfo.coords[VERTEX_LB][ix]) * tSz[ix]) + flipInfo.coords[VERTEX_LB][ix];
183     texCds[VERTEX_RT][iy] = texCds[VERTEX_LT][iy] = polSize.height / ((flipInfo.coords[VERTEX_LT][iy] - flipInfo.coords[VERTEX_LB][iy]) * tSz[iy]) + flipInfo.coords[VERTEX_LB][iy];
184 }
185 
186 void
GetRBFrameSize(math::VEC2 * pPt,Size * pSize,const math::VEC2 & basePt,const Size & winSize,const WindowFrameSize & frameSize)187 GetRBFrameSize(
188     math::VEC2*             pPt,
189     Size*                   pSize,
190     const math::VEC2&       basePt,
191     const Size&             winSize,
192     const WindowFrameSize&  frameSize
193 )
194 {
195     *pPt = math::VEC2(basePt.x + frameSize.l, basePt.y - winSize.height + frameSize.b);
196 
197     pSize->width  = winSize.width - frameSize.l;
198     pSize->height = frameSize.b;
199 }
200 
201 void
GetRBTexCoord(math::VEC2 texCds[],const Size & polSize,const TexSize & texSize,u8 textureFlip)202 GetRBTexCoord(
203     math::VEC2  texCds[],
204     const Size& polSize,
205     const TexSize& texSize,
206     u8 textureFlip
207 )
208 {
209     const TextureFlipInfo& flipInfo = GetTexutreFlipInfo(textureFlip);
210     const int ix = flipInfo.idx[0];
211     const int iy = flipInfo.idx[1];
212     const math::VEC2 tSz(texSize.width, texSize.height);
213 
214     texCds[VERTEX_RB][ix] = texCds[VERTEX_RT][ix] = flipInfo.coords[VERTEX_RB][ix];
215     texCds[VERTEX_RB][iy] = texCds[VERTEX_LB][iy] = flipInfo.coords[VERTEX_RB][iy];
216 
217     texCds[VERTEX_LT][ix] = texCds[VERTEX_LB][ix] = polSize.width  / ((flipInfo.coords[VERTEX_LB][ix] - flipInfo.coords[VERTEX_RB][ix]) * tSz[ix]) + flipInfo.coords[VERTEX_RB][ix];
218     texCds[VERTEX_LT][iy] = texCds[VERTEX_RT][iy] = polSize.height / ((flipInfo.coords[VERTEX_RT][iy] - flipInfo.coords[VERTEX_RB][iy]) * tSz[iy]) + flipInfo.coords[VERTEX_RB][iy];
219 }
220 
221 #ifdef NW_LYT_DMPGL_ENABLED
222 
223 // @brief フレームのテクスチャ座標変換を設定します。
224 //
225 // @param gres グラフィックスリソースです。
226 // @param frame フレーム番号です。
227 // @param flip テクスチャフリップ番号です。
228 void
SetupFrameTransform(const GraphicsResource & gres,WindowFrame frame,TextureFlip flip)229 SetupFrameTransform(
230     const GraphicsResource& gres,
231     WindowFrame frame,
232     TextureFlip flip)
233 {
234     static const u32 frameFlag[WINDOWFRAME_MAX] =
235     {
236         internal::FRAMESPECFLAG_FRAME_LT, // WINDOWFRAME_LT
237         internal::FRAMESPECFLAG_FRAME_RT, // WINDOWFRAME_RT
238         internal::FRAMESPECFLAG_FRAME_LB, // WINDOWFRAME_LG
239         internal::FRAMESPECFLAG_FRAME_RB, // WINDOWFRAME_RB
240         internal::FRAMESPECFLAG_FRAME_LB, // WINDOWFRAME_L
241         internal::FRAMESPECFLAG_FRAME_RT, // WINDOWFRAME_R
242         internal::FRAMESPECFLAG_FRAME_LT, // WINDOWFRAME_T
243         internal::FRAMESPECFLAG_FRAME_RB  // WINDOWFRAME_B
244     };
245 
246     static const u32 flipFlag[TEXTUREFLIP_MAX] =
247     {
248         internal::FRAMESPECFLAG_NORMAL,       // TEXTUREFLIP_NONE
249         internal::FRAMESPECFLAG_FLIP_HFLIP,   // TEXTUREFLIP_FLIPH
250         internal::FRAMESPECFLAG_FLIP_VFLIP,   // TEXTUREFLIP_FLIPV
251         internal::FRAMESPECFLAG_FLIP_R90,     // TEXTUREFLIP_ROTATE90
252         internal::FRAMESPECFLAG_FLIP_R180,    // TEXTUREFLIP_ROTATE180
253         internal::FRAMESPECFLAG_FLIP_R270     // TEXTUREFLIP_ROTATE270
254     };
255 
256     GLint loc = gres.GetUniformLocation(gres.UNIFORM_uFrameSpec);
257     u32 flag =frameFlag[frame] | flipFlag[flip];
258 
259     glUniform4f(loc, (f32)flag, 0, 0, 0);
260     NW_GL_ASSERT();
261 }
262 
263 #endif // NW_LYT_DMPGL_ENABLED
264 
265 } // nw::lyt::local::{anonymous}
266 } // nw::lyt::local
267 
268 NW_UT_RUNTIME_TYPEINFO_DEFINITION(Window, Window::Base);      // 実行時型情報の実体を定義
269 
~Frame()270 Window::Frame::~Frame()
271 {
272     if (pMaterial && !pMaterial->IsUserAllocated())
273     {
274         Layout::DeleteObj(pMaterial);
275     }
276     pMaterial = 0;
277 }
278 
Window(u8 contentTexNum,u8 frameTexNum)279 Window::Window(
280     u8  contentTexNum,
281     u8  frameTexNum
282 )
283 {
284     NW_ASSERT(contentTexNum <= TexMapMax);
285     NW_ASSERT(frameTexNum <= TexMapMax);
286 
287     const u8 frameNum = 1;
288     u8 frameTexNums[frameNum];
289     frameTexNums[WINDOWFRAME_LT] = frameTexNum;
290 
291     InitTexNum(contentTexNum, frameTexNums, frameNum);
292 }
293 
Window(u8 contentTexNum,u8 frameLTTexNum,u8 frameRTTexNum,u8 frameRBTexNum,u8 frameLBTexNum)294 Window::Window(
295     u8  contentTexNum,
296     u8  frameLTTexNum,
297     u8  frameRTTexNum,
298     u8  frameRBTexNum,
299     u8  frameLBTexNum
300 )
301 {
302     NW_ASSERT(contentTexNum <= TexMapMax);
303     NW_ASSERT(frameLTTexNum <= TexMapMax);
304     NW_ASSERT(frameRTTexNum <= TexMapMax);
305     NW_ASSERT(frameRBTexNum <= TexMapMax);
306     NW_ASSERT(frameLBTexNum <= TexMapMax);
307 
308     const u8 frameNum = 4;
309     u8 frameTexNums[frameNum];
310     frameTexNums[WINDOWFRAME_LT] = frameLTTexNum;
311     frameTexNums[WINDOWFRAME_RT] = frameRTTexNum;
312     frameTexNums[WINDOWFRAME_RB] = frameRBTexNum;
313     frameTexNums[WINDOWFRAME_LB] = frameLBTexNum;
314 
315     InitTexNum(contentTexNum, frameTexNums, frameNum);
316 }
317 
Window(u8 contentTexNum,u8 cornerLTTexNum,u8 cornerRTTexNum,u8 cornerRBTexNum,u8 cornerLBTexNum,u8 frameLTexNum,u8 frameTTexNum,u8 frameRTexNum,u8 frameBTexNum)318 Window::Window(
319     u8  contentTexNum,
320     u8  cornerLTTexNum,
321     u8  cornerRTTexNum,
322     u8  cornerRBTexNum,
323     u8  cornerLBTexNum,
324     u8  frameLTexNum,
325     u8  frameTTexNum,
326     u8  frameRTexNum,
327     u8  frameBTexNum
328 )
329 {
330     NW_ASSERT(contentTexNum <= TexMapMax);
331     NW_ASSERT(cornerLTTexNum <= TexMapMax);
332     NW_ASSERT(cornerRTTexNum <= TexMapMax);
333     NW_ASSERT(cornerRBTexNum <= TexMapMax);
334     NW_ASSERT(cornerLBTexNum <= TexMapMax);
335     NW_ASSERT(frameLTexNum <= TexMapMax);
336     NW_ASSERT(frameTTexNum <= TexMapMax);
337     NW_ASSERT(frameRTexNum <= TexMapMax);
338     NW_ASSERT(frameBTexNum <= TexMapMax);
339 
340     const u8 frameNum = 8;
341     u8 frameTexNums[frameNum];
342     frameTexNums[WINDOWFRAME_LT] = cornerLTTexNum;
343     frameTexNums[WINDOWFRAME_RT] = cornerRTTexNum;
344     frameTexNums[WINDOWFRAME_RB] = cornerRBTexNum;
345     frameTexNums[WINDOWFRAME_LB] = cornerLBTexNum;
346     frameTexNums[WINDOWFRAME_L ] = frameLTexNum;
347     frameTexNums[WINDOWFRAME_T ] = frameTTexNum;
348     frameTexNums[WINDOWFRAME_R ] = frameRTexNum;
349     frameTexNums[WINDOWFRAME_B ] = frameBTexNum;
350 
351     InitTexNum(contentTexNum, frameTexNums, frameNum);
352 
353 }
354 
Window(const res::Window * pBlock,const ResBlockSet & resBlockSet)355 Window::Window(
356     const res::Window*  pBlock,
357     const ResBlockSet&  resBlockSet
358 )
359 :   Base(pBlock)
360 {
361     const res::WindowContent *const pResContent = internal::ConvertOffsToPtr<res::WindowContent>(pBlock, pBlock->contentOffset);
362     const u8 texCoordNum = ut::Min(pResContent->texCoordNum, u8(TexMapMax));
363 
364     InitContent(texCoordNum);
365 
366     m_ContentInflation = pBlock->inflation;
367 
368     NW_NULL_ASSERT(resBlockSet.pMaterialList);
369     const u32 *const matOffsTbl = internal::ConvertOffsToPtr<u32>(resBlockSet.pMaterialList, sizeof(*resBlockSet.pMaterialList));
370 
371     // content
372     // 頂点カラー
373     for (int i = 0; i < VERTEXCOLOR_MAX; ++i)
374     {
375         m_Content.vtxColors[i] = pResContent->vtxCols[i];
376     }
377 
378     // テクスチャ座標
379     if (texCoordNum > 0)
380     {
381         if (! m_Content.texCoordAry.IsEmpty())
382         {
383             m_Content.texCoordAry.Copy(
384                 reinterpret_cast<const char*>(pResContent) + sizeof(*pResContent),
385                 texCoordNum);
386         }
387     }
388 
389     // マテリアルの作成
390     {
391         const res::Material *const pResMaterial = internal::ConvertOffsToPtr<res::Material>(resBlockSet.pMaterialList, matOffsTbl[pResContent->materialIdx]);
392         m_pMaterial = Layout::NewObj<Material>(pResMaterial, resBlockSet);
393     }
394 
395     // Frame
396     m_FrameNum = 0;
397     m_Frames = 0;
398     if (pBlock->frameNum > 0)
399     {
400         InitFrame(pBlock->frameNum);
401 
402         const u32 *const frameOffsetTable = internal::ConvertOffsToPtr<u32>(pBlock, pBlock->frameOffsetTableOffset);
403         for (int i = 0; i < m_FrameNum; ++i)
404         {
405             const res::WindowFrame *const pResWindowFrame = internal::ConvertOffsToPtr<res::WindowFrame>(pBlock, frameOffsetTable[i]);
406             m_Frames[i].textureFlip = pResWindowFrame->textureFlip;
407 
408             // マテリアルの初期化
409             const res::Material *const pResMaterial = internal::ConvertOffsToPtr<res::Material>(resBlockSet.pMaterialList, matOffsTbl[pResWindowFrame->materialIdx]);
410             m_Frames[i].pMaterial = Layout::NewObj<Material>(pResMaterial, resBlockSet);
411         }
412     }
413 }
414 
415 void
InitTexNum(u8 contentTexNum,u8 frameTexNums[],u8 frameNum)416 Window::InitTexNum(
417     u8  contentTexNum,
418     u8  frameTexNums[],
419     u8  frameNum
420 )
421 {
422     InitContent(contentTexNum);
423 
424     m_ContentInflation.l = 0;
425     m_ContentInflation.r = 0;
426     m_ContentInflation.t = 0;
427     m_ContentInflation.b = 0;
428 
429     // マテリアルの作成
430     m_pMaterial = Layout::NewObj<Material>();
431     if (m_pMaterial)
432     {
433         m_pMaterial->ReserveMem(contentTexNum, contentTexNum, contentTexNum);
434     }
435 
436     // Frame
437     InitFrame(frameNum);
438 
439     for (int i = 0; i < m_FrameNum; ++i)
440     {
441         // マテリアルの作成
442         m_Frames[i].pMaterial = Layout::NewObj<Material>();
443         if (m_Frames[i].pMaterial)
444         {
445             m_Frames[i].pMaterial->ReserveMem(frameTexNums[i], frameTexNums[i], frameTexNums[i]);
446         }
447     }
448 }
449 
450 void
InitContent(u8 texNum)451 Window::InitContent(u8 texNum)
452 {
453     if (texNum > 0)
454     {
455         ReserveTexCoord(texNum);
456     }
457 
458 #ifdef NW_LYT_DRAWER_ENABLE
459     m_IsTexCoordInited = false;
460 #endif
461 }
462 
463 void
InitFrame(u8 frameNum)464 Window::InitFrame(u8 frameNum)
465 {
466     m_FrameNum = 0;
467     m_Frames = Layout::NewArray<Frame>(frameNum);
468     if (m_Frames)
469     {
470         m_FrameNum = frameNum;
471     }
472 }
473 
~Window()474 Window::~Window()
475 {
476     // OSReport("Window::~Window()\n");
477 
478     Layout::DeleteArray(m_Frames, m_FrameNum);
479 
480     if (m_pMaterial && ! m_pMaterial->IsUserAllocated())
481     {
482         Layout::DeleteObj(m_pMaterial);
483         m_pMaterial = 0;
484     }
485 
486     m_Content.texCoordAry.Free();
487 }
488 
489 void
ReserveTexCoord(u8 num)490 Window::ReserveTexCoord(u8 num)
491 {
492     m_Content.texCoordAry.Reserve(num);
493 }
494 
495 u8
GetTexCoordNum() const496 Window::GetTexCoordNum() const
497 {
498     return m_Content.texCoordAry.GetSize();
499 }
500 
501 void
SetTexCoordNum(u8 num)502 Window::SetTexCoordNum(u8 num)
503 {
504     m_Content.texCoordAry.SetSize(num);
505 }
506 
507 void
GetTexCoord(u32 idx,TexCoordQuad coords) const508 Window::GetTexCoord(
509     u32 idx,
510     TexCoordQuad coords
511 ) const
512 {
513     m_Content.texCoordAry.GetCoord(idx, coords);
514 }
515 
516 void
SetTexCoord(u32 idx,const TexCoordQuad coords)517 Window::SetTexCoord(
518     u32 idx,
519     const TexCoordQuad coords
520 )
521 {
522     m_Content.texCoordAry.SetCoord(idx, coords);
523 
524     Material* pMaterial = this->GetContentMaterial();
525     if (pMaterial != NULL)
526     {
527         pMaterial->SetTextureDirty();
528     }
529 }
530 
531 Material*
FindMaterialByName(const char * findName,bool bRecursive)532 Window::FindMaterialByName(
533     const char* findName,
534     bool        bRecursive
535 )
536 {
537     if (m_pMaterial)
538     {
539         if (internal::EqualsMaterialName(m_pMaterial->GetName(), findName))
540         {
541             return m_pMaterial;
542         }
543     }
544     for (int i = 0; i < m_FrameNum; ++i)
545     {
546         if (internal::EqualsMaterialName(m_Frames[i].pMaterial->GetName(), findName))
547         {
548             return m_Frames[i].pMaterial;
549         }
550     }
551 
552     if (bRecursive)
553     {
554         // 子供に一致するものが無いか検索
555         for (PaneList::Iterator it = GetChildList().GetBeginIter(); it != GetChildList().GetEndIter(); ++it)
556         {
557             if (Material* pMat = it->FindMaterialByName(findName, bRecursive))
558             {
559                 return pMat;
560             }
561         }
562     }
563 
564     return 0;
565 }
566 
567 const ut::Color8
GetVtxColor(u32 idx) const568 Window::GetVtxColor(u32 idx) const
569 {
570     NW_ASSERT(idx < VERTEXCOLOR_MAX);
571 
572     return m_Content.vtxColors[idx];
573 }
574 
575 void
SetVtxColor(u32 idx,ut::Color8 value)576 Window::SetVtxColor(
577     u32         idx,
578     ut::Color8 value
579 )
580 {
581     NW_ASSERT(idx < VERTEXCOLOR_MAX);
582 
583     m_Content.vtxColors[idx] = value;
584 }
585 
586 u8
GetVtxColorElement(u32 idx) const587 Window::GetVtxColorElement(u32 idx) const
588 {
589     return internal::GetVtxColorElement(m_Content.vtxColors, idx);
590 }
591 
592 void
SetVtxColorElement(u32 idx,u8 value)593 Window::SetVtxColorElement(u32 idx, u8 value)
594 {
595     internal::SetVtxColorElement(m_Content.vtxColors, idx, value);
596 }
597 
598 #ifdef NW_LYT_DMPGL_ENABLED
599 
600 void
DrawSelf(const DrawInfo & drawInfo)601 Window::DrawSelf(const DrawInfo& drawInfo)
602 {
603     NW_LYT_STOPWATCH_MEASURE(-500, "nw::lyt::Window::DrawSelf");
604 
605     // 行列
606     LoadMtx(drawInfo);
607 
608     const WindowFrameSize frameSize = GetFrameSize(m_FrameNum, m_Frames);
609     const math::VEC2 basePt = GetVtxPos();
610 
611     // contentの描画
612     DrawContent(drawInfo, basePt, frameSize, GetGlobalAlpha());
613 
614     // frameの描画
615     switch (m_FrameNum)
616     {
617     case 1:
618         DrawFrame(drawInfo, basePt, m_Frames[WINDOWFRAME_LT], frameSize, GetGlobalAlpha());
619         break;
620     case 4:
621         DrawFrame4(drawInfo, basePt, m_Frames, frameSize, GetGlobalAlpha());
622         break;
623     case 8:
624         DrawFrame8(drawInfo, basePt, m_Frames, frameSize, GetGlobalAlpha());
625         break;
626     }
627 }
628 
629 void
DrawContent(const DrawInfo & drawInfo,const math::VEC2 & basePt,const WindowFrameSize & frameSize,u8 alpha)630 Window::DrawContent(
631     const DrawInfo&         drawInfo,
632     const math::VEC2&       basePt,
633     const WindowFrameSize&  frameSize,
634     u8                      alpha
635 )
636 {
637     m_pMaterial->SetupGraphics(drawInfo, alpha);
638 
639     internal::DrawQuad(
640         drawInfo,
641         math::VEC2(basePt.x + frameSize.l - m_ContentInflation.l, basePt.y - frameSize.t + m_ContentInflation.t),
642         Size(GetSize().width - frameSize.l + m_ContentInflation.l - frameSize.r + m_ContentInflation.r, GetSize().height - frameSize.t + m_ContentInflation.t - frameSize.b + m_ContentInflation.b),
643         m_Content.texCoordAry.GetSize(),
644         m_Content.texCoordAry.GetArray(),
645         m_Content.vtxColors);
646 }
647 
648 void
DrawFrame(const DrawInfo & drawInfo,const math::VEC2 & basePt,const Frame & frame,const WindowFrameSize & frameSize,u8 alpha)649 Window::DrawFrame(
650     const DrawInfo&         drawInfo,
651     const math::VEC2&       basePt,
652     const Frame&            frame,
653     const WindowFrameSize&  frameSize,
654     u8                      alpha
655 )
656 {
657     NW_LYT_STOPWATCH_MEASURE(-501, "nw::lyt::Window::DrawFrame");
658 
659     // フレームのテクスチャがない場合は何もしない
660     if (frame.pMaterial->GetTexMapNum() == 0)
661     {
662         return;
663     }
664 
665     frame.pMaterial->SetupGraphics(drawInfo, alpha, false);
666 
667     math::VEC2 polPt;
668     Size polSize;
669 
670     GraphicsResource& gres = *drawInfo.GetGraphicsResource();
671 
672     local::GetLTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
673     local::SetupFrameTransform(gres, WINDOWFRAME_LT, TEXTUREFLIP_NONE);
674     internal::DrawQuad(drawInfo, polPt, polSize);
675 
676     local::GetRTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
677     local::SetupFrameTransform(gres, WINDOWFRAME_RT, TEXTUREFLIP_FLIPH);
678     internal::DrawQuad(drawInfo, polPt, polSize);
679 
680     local::GetRBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
681     local::SetupFrameTransform(gres, WINDOWFRAME_RB, TEXTUREFLIP_ROTATE180);
682     internal::DrawQuad(drawInfo, polPt, polSize);
683 
684     local::GetLBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
685     local::SetupFrameTransform(gres, WINDOWFRAME_LB, TEXTUREFLIP_FLIPV);
686     internal::DrawQuad(drawInfo, polPt, polSize);
687 }
688 
689 void
DrawFrame4(const DrawInfo & drawInfo,const math::VEC2 & basePt,const Frame * frames,const WindowFrameSize & frameSize,u8 alpha)690 Window::DrawFrame4(
691     const DrawInfo&         drawInfo,
692     const math::VEC2&       basePt,
693     const Frame*            frames,
694     const WindowFrameSize&  frameSize,
695     u8                      alpha
696 )
697 {
698     NW_LYT_STOPWATCH_MEASURE(-502, "nw::lyt::Window::DrawFrame4");
699 
700     math::VEC2 polPt[WINDOWFRAME_RB + 1];
701     Size polSize[WINDOWFRAME_RB + 1];
702     bool bRepeat = false;
703     GraphicsResource& gres = *drawInfo.GetGraphicsResource();
704 
705     local::GetLTFrameSize(&polPt[WINDOWFRAME_LT], &polSize[WINDOWFRAME_LT], basePt, GetSize(), frameSize);
706     local::GetRTFrameSize(&polPt[WINDOWFRAME_RT], &polSize[WINDOWFRAME_RT], basePt, GetSize(), frameSize);
707     local::GetLBFrameSize(&polPt[WINDOWFRAME_LB], &polSize[WINDOWFRAME_LB], basePt, GetSize(), frameSize);
708     local::GetRBFrameSize(&polPt[WINDOWFRAME_RB], &polSize[WINDOWFRAME_RB], basePt, GetSize(), frameSize);
709 
710     for (int i = WINDOWFRAME_LT; i <= WINDOWFRAME_RB; ++i)
711     {
712         const Frame& frame = frames[i];
713 
714         if (frame.pMaterial && frame.pMaterial->GetTexMapNum() > 0)
715         {
716             frame.pMaterial->SetupGraphics(drawInfo, alpha, false);
717             local::SetupFrameTransform(gres, WindowFrame(i), frame.GetTextureFlip());
718             if (!bRepeat)
719             {
720                 internal::DrawQuad(drawInfo, polPt[i], polSize[i]);
721                 bRepeat = true;
722             }
723             else
724             {
725                 internal::DrawQuad_Repeat(drawInfo, polPt[i], polSize[i]);
726             }
727         }
728     }
729 }
730 
731 void
DrawFrame8(const DrawInfo & drawInfo,const math::VEC2 & basePt,const Frame * frames,const WindowFrameSize & frameSize,u8 alpha)732 Window::DrawFrame8(
733     const DrawInfo&         drawInfo,
734     const math::VEC2&       basePt,
735     const Frame*            frames,
736     const WindowFrameSize&  frameSize,
737     u8                      alpha
738 )
739 {
740     NW_LYT_STOPWATCH_MEASURE(-503, "nw::lyt::Window::DrawFrame8");
741 
742     const f32 x0 = basePt.x;
743     const f32 x1 = basePt.x + frameSize.l;
744     const f32 x2 = basePt.x + this->GetSize().width - frameSize.r;
745 
746     const f32 y0 = basePt.y;
747     const f32 y1 = basePt.y - frameSize.t;
748     const f32 y2 = basePt.y - this->GetSize().height + frameSize.b;
749 
750     const f32 w0 = frameSize.l;
751     const f32 w1 = this->GetSize().width - frameSize.l - frameSize.r;
752     const f32 w2 = frameSize.r;
753 
754     const f32 h0 = frameSize.t;
755     const f32 h1 = this->GetSize().height - frameSize.t - frameSize.b;
756     const f32 h2 = frameSize.b;
757 
758     const local::Rect frameRect[WINDOWFRAME_MAX] =
759     {
760         { x0, y0, w0, h0 }, // LT
761         { x2, y0, w2, h0 }, // RT
762         { x0, y2, w0, h2 }, // LB
763         { x2, y2, w2, h2 }, // RB
764         { x0, y1, w0, h1 }, // L
765         { x2, y1, w2, h1 }, // R
766         { x1, y0, w1, h0 }, // T
767         { x1, y2, w1, h2 }, // B
768     };
769 
770     GraphicsResource& gres = *drawInfo.GetGraphicsResource();
771     bool bRepeat = false;
772 
773     for (int i = 0; i < WINDOWFRAME_MAX; ++i)
774     {
775         const Frame& frame = frames[i];
776 
777         if (frame.pMaterial->GetTexMapNum() > 0)  // Corner LT
778         {
779             frame.pMaterial->SetupGraphics(drawInfo, alpha, false);
780             local::SetupFrameTransform(gres, WindowFrame(i), frame.GetTextureFlip());
781             if (!bRepeat)
782             {
783                 internal::DrawQuad(drawInfo, frameRect[i].Position(), frameRect[i].Size());
784                 bRepeat = true;
785             }
786             else
787             {
788                 internal::DrawQuad_Repeat(drawInfo, frameRect[i].Position(), frameRect[i].Size());
789             }
790         }
791     }
792 }
793 
794 #endif // NW_LYT_DMPGL_ENABLED
795 
796 const WindowFrameSize
GetFrameSize(u8 frameNum,const Window::Frame * frames) const797 Window::GetFrameSize(
798     u8                      frameNum,
799     const Window::Frame*    frames
800 ) const
801 {
802     WindowFrameSize ret = { 0, 0, 0, 0 };
803 
804     switch (frameNum)
805     {
806     case 1:
807         {
808             Material* pMaterial = frames[WINDOWFRAME_LT].pMaterial;
809             if (pMaterial != NULL && pMaterial->GetTexMapNum() > 0)
810             {
811                 TexSize texSize = pMaterial->GetTexMap(0).GetSize();
812                 ret.l = texSize.width;
813                 ret.t = texSize.height;
814                 ret.r = texSize.width;
815                 ret.b = texSize.height;
816             }
817         }
818         break;
819     case 4:
820     case 8:
821         {
822             Material* pMaterialLT = frames[WINDOWFRAME_LT].pMaterial;
823             if (pMaterialLT != NULL && pMaterialLT->GetTexMapNum() > 0)
824             {
825                 ret.t = pMaterialLT->GetTexMap(0).GetHeight();
826             }
827 
828             Material *pMaterialRT = frames[WINDOWFRAME_RT].pMaterial;
829             if (pMaterialRT != NULL && pMaterialRT->GetTexMapNum() > 0)
830             {
831                 ret.r = pMaterialRT->GetTexMap(0).GetWidth();
832             }
833 
834             Material *pMaterialRB = frames[WINDOWFRAME_RB].pMaterial;
835             if (pMaterialRB != NULL && pMaterialRB->GetTexMapNum() > 0)
836             {
837                 ret.b = pMaterialRB->GetTexMap(0).GetHeight();
838             }
839 
840             Material *pMaterialLB = frames[WINDOWFRAME_LB].pMaterial;
841             if (pMaterialLB != NULL && pMaterialLB->GetTexMapNum() > 0)
842             {
843                 ret.l = pMaterialLB->GetTexMap(0).GetWidth();
844             }
845         }
846         break;
847     }
848 
849     return ret;
850 }
851 
852 u8
GetMaterialNum() const853 Window::GetMaterialNum() const
854 {
855     return u8(1 + m_FrameNum);
856 }
857 
858 Material*
GetMaterial(u32 idx) const859 Window::GetMaterial(u32 idx) const
860 {
861     NW_WARNING(idx < GetMaterialNum(), "idx >= GetMaterialNum() : %d >= %d", idx, GetMaterialNum());
862 
863     return idx == 0 ? GetContentMaterial(): GetFrameMaterial(WindowFrame(idx - 1));
864 }
865 
866 Material*
GetFrameMaterial(WindowFrame frameIdx) const867 Window::GetFrameMaterial(WindowFrame frameIdx) const
868 {
869     NW_ASSERT(frameIdx < WINDOWFRAME_MAX);
870 
871     if (frameIdx >= m_FrameNum)
872     {
873         return NULL;
874     }
875 
876     return m_Frames[frameIdx].pMaterial;
877 }
878 
SetFrameMaterial(WindowFrame frameIdx,Material * pMaterial)879 void Window::SetFrameMaterial(WindowFrame frameIdx, Material* pMaterial)
880 {
881     NW_ASSERT(frameIdx < WINDOWFRAME_MAX);
882 
883     if (m_Frames[frameIdx].pMaterial == pMaterial)
884     {
885         return;
886     }
887 
888     if (m_Frames[frameIdx].pMaterial != NULL &&
889         !m_Frames[frameIdx].pMaterial->IsUserAllocated())
890     {
891         Layout::DeleteObj(m_Frames[frameIdx].pMaterial);
892     }
893 
894     m_Frames[frameIdx].pMaterial = pMaterial;
895     if (pMaterial != NULL)
896     {
897         pMaterial->SetTextureDirty();
898     }
899 }
900 
901 Material*
GetContentMaterial() const902 Window::GetContentMaterial() const
903 {
904     return m_pMaterial;
905 }
906 
SetContentMaterial(Material * pMaterial)907 void Window::SetContentMaterial(Material* pMaterial)
908 {
909     if (m_pMaterial == pMaterial)
910     {
911         return;
912     }
913 
914     if (m_pMaterial != NULL && !m_pMaterial->IsUserAllocated())
915     {
916         Layout::DeleteObj(m_pMaterial);
917     }
918 
919     m_pMaterial = pMaterial;
920     if (m_pMaterial != NULL)
921     {
922         m_pMaterial->SetTextureDirty();
923     }
924 }
925 
926 
927 #ifdef NW_LYT_DRAWER_ENABLE
928 //----------------------------------------------------------
929 // Window
930 void
MakeUniformDataSelf(DrawInfo * pDrawInfo,Drawer * pDrawer) const931 Window::MakeUniformDataSelf( DrawInfo* pDrawInfo, Drawer* pDrawer ) const
932 {
933 #ifdef NW_LYT_DRAWER_DISABLE_DRAW_WINOOW
934     return;
935 #endif
936 
937     // 使わないぽい
938     NW_UNUSED_VARIABLE( pDrawInfo );
939 
940     const WindowFrameSize frameSize( GetFrameSize(m_FrameNum, m_Frames) );
941     const math::VEC2 basePt( GetVtxPos() );
942 
943     { // Contentについての設定
944 
945         { // TexEnv設定
946             pDrawer->SetUpTexEnv( m_pMaterial );
947         }
948 
949         { // テクスチャの設定
950             pDrawer->SetUpTextures( m_pMaterial );
951         }
952 
953         { // テクスチャ座標の設定
954 
955             if ( !m_IsTexCoordInited || m_pMaterial->IsTextureDirty() )
956             {
957                 m_UniformTexCoordNum = pDrawer->CalcTextureCoords( m_pMaterial,
958                                                                         m_Content.texCoordAry.GetArray(),
959                                                                         m_UniformTexCoords );
960                 m_IsTexCoordInited = true;
961                 m_pMaterial->SetTextureDirty( false );
962             }
963             pDrawer->SetUpTextureCoords( m_UniformTexCoords, m_UniformTexCoordNum );
964         }
965 
966         { // 頂点座標の計算に必要な情報の設定
967             pDrawer->SetUpMtx( GetGlobalMtx() );
968 
969             // TODO: lyt_Windowにキャッシュすることを検討
970             Size size( GetSize().width  - frameSize.l + m_ContentInflation.l - frameSize.r + m_ContentInflation.r,
971                        GetSize().height - frameSize.t + m_ContentInflation.t - frameSize.b + m_ContentInflation.b );
972 
973             nw::math::VEC2 pos(  basePt.x + frameSize.l - m_ContentInflation.l,
974                                  basePt.y - frameSize.t + m_ContentInflation.t );
975 
976             pDrawer->SetUpQuad( size, pos );
977         }
978 
979         { // 頂点カラーの設定
980             pDrawer->SetUpVtxColors( m_Content.vtxColors, GetGlobalAlpha() );
981         }
982 
983         { // UniformDataの設定終了
984             pDrawer->SetUniformDataEnd();
985         }
986     }
987 
988 
989     { // 頂点カラーの設定
990         ut::Color8 white[ 4 ] = { 0xffffffff,0xffffffff,0xffffffff,0xffffffff };
991         pDrawer->SetUpVtxColors( white, GetGlobalAlpha() );
992     }
993 
994     const u8 texCoordNum = 1;
995     int uniformTexCoordNum;
996     nw::math::VEC4 uniformTexCoords[ TexMapMax * 2 ];
997     Size polSize;
998     math::VEC2 polPt;
999     math::VEC2 texCds[ texCoordNum ][ VERTEX_MAX ];
1000 
1001     // Frameについての設定
1002     switch ( m_FrameNum )
1003     {
1004       case 1 :
1005         {
1006             const Frame& frame = m_Frames[ WINDOWFRAME_LT ];
1007 
1008             // フレームのテクスチャがない場合は何もしない
1009             if ( frame.pMaterial->GetTexMapNum() == 0 ) return;
1010 
1011             // TexEnv設定
1012             pDrawer->SetUpTexEnv( frame.pMaterial );
1013 
1014             // テクスチャの設定
1015             pDrawer->SetUpTextures( frame.pMaterial );
1016             const TexSize texSize = frame.pMaterial->GetTexMap(0).GetSize();
1017 
1018             local::GetLTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1019             local::GetLTTexCoord( texCds[0], polSize, texSize, TEXTUREFLIP_NONE );
1020 
1021             uniformTexCoordNum = pDrawer->CalcTextureCoords( frame.pMaterial, texCds,  uniformTexCoords );
1022             pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1023             pDrawer->SetUpQuad( polSize, polPt );
1024             pDrawer->SetUniformDataEnd();
1025 
1026             local::GetRTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1027             local::GetRTTexCoord(texCds[0], polSize, texSize, TEXTUREFLIP_FLIPH);
1028 
1029             uniformTexCoordNum = pDrawer->CalcTextureCoords( frame.pMaterial, texCds,  uniformTexCoords );
1030             pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1031             pDrawer->SetUpQuad( polSize, polPt );
1032             pDrawer->SetUniformDataEnd();
1033 
1034             local::GetRBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1035             local::GetRBTexCoord(texCds[0], polSize, texSize, TEXTUREFLIP_ROTATE180);
1036 
1037             uniformTexCoordNum = pDrawer->CalcTextureCoords( frame.pMaterial, texCds,  uniformTexCoords );
1038             pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1039             pDrawer->SetUpQuad( polSize, polPt );
1040             pDrawer->SetUniformDataEnd();
1041 
1042             local::GetLBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1043             local::GetLBTexCoord(texCds[0], polSize, texSize, TEXTUREFLIP_FLIPV);
1044 
1045             // TODO: uniformTexCoordsをキャッシュしたい
1046             uniformTexCoordNum = pDrawer->CalcTextureCoords( frame.pMaterial, texCds,  uniformTexCoords );
1047             pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1048             pDrawer->SetUpQuad( polSize, polPt );
1049             pDrawer->SetUniformDataEnd();
1050         }
1051         break;
1052       case 4 :
1053         {
1054             const Frame* pFrame = &m_Frames[ WINDOWFRAME_LT ];
1055             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1056             {
1057                 // TexEnv設定
1058                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1059 
1060                 // テクスチャの設定
1061                 pDrawer->SetUpTextures( pFrame->pMaterial );
1062 
1063                 local::GetLTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1064                 local::GetLTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1065 
1066                 // TODO: uniformTexCoordsをキャッシュしたい
1067                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1068                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1069                 pDrawer->SetUpQuad( polSize, polPt );
1070                 pDrawer->SetUniformDataEnd();
1071             }
1072 
1073             pFrame = &m_Frames[ WINDOWFRAME_RT ];
1074             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1075             {
1076                 // TexEnv設定
1077                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1078 
1079                 // テクスチャの設定
1080                 pDrawer->SetUpTextures( pFrame->pMaterial );
1081 
1082                 local::GetRTFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1083                 local::GetRTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1084 
1085                 // TODO: uniformTexCoordsをキャッシュしたい
1086                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1087                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1088                 pDrawer->SetUpQuad( polSize, polPt );
1089                 pDrawer->SetUniformDataEnd();
1090 
1091             }
1092 
1093             pFrame = &m_Frames[ WINDOWFRAME_RB ];
1094             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1095             {
1096                 // TexEnv設定
1097                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1098 
1099                 // テクスチャの設定
1100                 pDrawer->SetUpTextures( pFrame->pMaterial );
1101 
1102                 local::GetRBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1103                 local::GetRBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1104 
1105                 // TODO: uniformTexCoordsをキャッシュしたい
1106                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1107                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1108                 pDrawer->SetUpQuad( polSize, polPt );
1109                 pDrawer->SetUniformDataEnd();
1110 
1111             }
1112 
1113             pFrame = &m_Frames[ WINDOWFRAME_LB ];
1114             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1115             {
1116                 // TexEnv設定
1117                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1118 
1119                 // テクスチャの設定
1120                 pDrawer->SetUpTextures( pFrame->pMaterial );
1121 
1122                 local::GetLBFrameSize(&polPt, &polSize, basePt, GetSize(), frameSize);
1123                 local::GetLBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1124 
1125                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1126                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1127                 pDrawer->SetUpQuad( polSize, polPt );
1128                 pDrawer->SetUniformDataEnd();
1129             }
1130         }
1131         break;
1132       case 8 :
1133         {
1134             const Frame* pFrame = &m_Frames[ WINDOWFRAME_LT ];
1135             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1136             {
1137                 // TexEnv設定
1138                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1139 
1140                 // テクスチャの設定
1141                 pDrawer->SetUpTextures( pFrame->pMaterial );
1142 
1143                 polSize = Size(frameSize.l, frameSize.t);
1144                 polPt    = basePt;
1145 
1146                 local::GetLTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1147 
1148                 // TODO: uniformTexCoordsをキャッシュしたい
1149                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1150                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1151                 pDrawer->SetUpQuad( polSize, polPt );
1152                 pDrawer->SetUniformDataEnd();
1153             }
1154 
1155             pFrame = &m_Frames[ WINDOWFRAME_T ];
1156             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1157             {
1158                 // TexEnv設定
1159                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1160 
1161                 // テクスチャの設定
1162                 pDrawer->SetUpTextures( pFrame->pMaterial );
1163 
1164                 polSize = Size(GetSize().width - frameSize.l - frameSize.r, frameSize.t);
1165                 polPt   = math::VEC2(basePt.x + frameSize.l, basePt.y);
1166 
1167                 local::GetLTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1168 
1169                 // TODO: uniformTexCoordsをキャッシュしたい
1170                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1171                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1172                 pDrawer->SetUpQuad( polSize, polPt );
1173                 pDrawer->SetUniformDataEnd();
1174             }
1175 
1176             pFrame = &m_Frames[ WINDOWFRAME_RT ];
1177             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1178             {
1179                 // TexEnv設定
1180                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1181 
1182                 // テクスチャの設定
1183                 pDrawer->SetUpTextures( pFrame->pMaterial );
1184 
1185                 polSize = Size(frameSize.r, frameSize.t);
1186                 polPt   = math::VEC2(basePt.x + GetSize().width - frameSize.r, basePt.y);
1187 
1188                 local::GetRTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1189 
1190                 // TODO: uniformTexCoordsをキャッシュしたい
1191                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1192                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1193                 pDrawer->SetUpQuad( polSize, polPt );
1194                 pDrawer->SetUniformDataEnd();
1195 
1196             }
1197 
1198             pFrame = &m_Frames[ WINDOWFRAME_R ];
1199             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1200             {
1201                 // TexEnv設定
1202                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1203 
1204                 // テクスチャの設定
1205                 pDrawer->SetUpTextures( pFrame->pMaterial );
1206 
1207                 polSize = Size(frameSize.r, GetSize().height - frameSize.t - frameSize.b);
1208                 polPt   = math::VEC2(basePt.x + GetSize().width - frameSize.r, basePt.y - frameSize.t);
1209 
1210                 local::GetRTTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1211 
1212                 // TODO: uniformTexCoordsをキャッシュしたい
1213                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1214                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1215                 pDrawer->SetUpQuad( polSize, polPt );
1216                 pDrawer->SetUniformDataEnd();
1217             }
1218 
1219             pFrame = &m_Frames[ WINDOWFRAME_RB ];
1220             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1221             {
1222                 // TexEnv設定
1223                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1224 
1225                 // テクスチャの設定
1226                 pDrawer->SetUpTextures( pFrame->pMaterial );
1227 
1228                 polSize =  Size(frameSize.r, frameSize.b);
1229                 polPt   = math::VEC2(basePt.x + GetSize().width - frameSize.r, basePt.y - GetSize().height + frameSize.b);
1230 
1231                 local::GetRBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1232 
1233                 // TODO: uniformTexCoordsをキャッシュしたい
1234                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1235                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1236                 pDrawer->SetUpQuad( polSize, polPt );
1237                 pDrawer->SetUniformDataEnd();
1238             }
1239 
1240             pFrame = &m_Frames[ WINDOWFRAME_B ];
1241             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1242             {
1243                 // TexEnv設定
1244                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1245 
1246                 // テクスチャの設定
1247                 pDrawer->SetUpTextures( pFrame->pMaterial );
1248 
1249                 polSize =  Size(GetSize().width - frameSize.l - frameSize.r, frameSize.b);
1250                 polPt   =  math::VEC2(basePt.x + frameSize.l, basePt.y - GetSize().height + frameSize.b);
1251 
1252                 local::GetRBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1253 
1254                 // TODO: uniformTexCoordsをキャッシュしたい
1255                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1256                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1257                 pDrawer->SetUpQuad( polSize, polPt );
1258                 pDrawer->SetUniformDataEnd();
1259             }
1260 
1261             pFrame = &m_Frames[ WINDOWFRAME_LB ];
1262             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1263             {
1264                 // TexEnv設定
1265                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1266 
1267                 // テクスチャの設定
1268                 pDrawer->SetUpTextures( pFrame->pMaterial );
1269 
1270                 polSize =  Size(frameSize.l, frameSize.b);
1271                 polPt   =  math::VEC2(basePt.x, basePt.y - GetSize().height + frameSize.b);
1272 
1273                 local::GetLBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1274 
1275                 // TODO: uniformTexCoordsをキャッシュしたい
1276                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1277                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1278                 pDrawer->SetUpQuad( polSize, polPt );
1279                 pDrawer->SetUniformDataEnd();
1280             }
1281 
1282             pFrame = &m_Frames[ WINDOWFRAME_L ];
1283             if ( pFrame->pMaterial->GetTexMapNum() != 0 )
1284             {
1285                 // TexEnv設定
1286                 pDrawer->SetUpTexEnv( pFrame->pMaterial );
1287 
1288                 // テクスチャの設定
1289                 pDrawer->SetUpTextures( pFrame->pMaterial );
1290 
1291                 polSize =  Size(frameSize.l, GetSize().height - frameSize.t - frameSize.b);
1292                 polPt   =  math::VEC2(basePt.x, basePt.y - frameSize.t);
1293 
1294                 local::GetLBTexCoord(texCds[0], polSize, pFrame->pMaterial->GetTexMap(0).GetSize(), pFrame->textureFlip);
1295 
1296                 // TODO: uniformTexCoordsをキャッシュしたい
1297                 uniformTexCoordNum = pDrawer->CalcTextureCoords( pFrame->pMaterial, texCds,  uniformTexCoords );
1298                 pDrawer->SetUpTextureCoords( uniformTexCoords, uniformTexCoordNum );
1299                 pDrawer->SetUpQuad( polSize, polPt );
1300                 pDrawer->SetUniformDataEnd();
1301             }
1302         }
1303         break;
1304     }
1305 
1306     // 同じテクスチャを使用するWindowとPictureの描画で、フレームの
1307     // 描画位置がおかしくなる不具合への対処 <BTS:536>
1308     pDrawer->FlushBuffer();
1309 }
1310 #endif
1311 
1312 } // namespace nw::lyt
1313 } // namespace nw
1314