1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_Drawer.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 #include <nw/lyt/lyt_Layout.h>
20 #include <nw/lyt/lyt_Pane.h>
21 #include <nw/lyt/lyt_Drawer.h>
22 #include <nw/lyt/lyt_DrawerCommand.h>
23 #include <nw/lyt/lyt_DrawInfo.h>
24 #include <nw/lyt/lyt_GraphicsResource.h>
25 
26 #ifdef NW_LYT_DRAWER_ENABLE
27 
28 namespace nw { namespace lyt {
29 
30 //----------------------------------------------------------
31 // Drawer
32 
33 void
Draw(const Layout * pLayout,DrawInfo & drawInfo)34 Drawer::Draw( const Layout* pLayout, DrawInfo& drawInfo )
35 {
36     if ( pLayout == NULL )
37     {
38         return;
39     }
40 
41     if ( pLayout->GetRootPane() == NULL ||
42          pLayout->GetRootPane()->IsVisible() == false ) return;
43 
44     pLayout->GetRootPane()->MakeUniformData( &drawInfo, this );
45 }
46 
47 void
Draw(const Pane * pPane,DrawInfo & drawInfo)48 Drawer::Draw( const Pane* pPane, DrawInfo& drawInfo )
49 {
50     if ( pPane == NULL )
51     {
52         return;
53     }
54 
55     if ( pPane->IsVisible() )
56     {
57         pPane->MakeUniformData( &drawInfo, this );
58     }
59 }
60 
61 void
DrawBegin(const DrawInfo & drawInfo)62 Drawer::DrawBegin( const DrawInfo& drawInfo )
63 {
64     u32 flag = 0;
65     DrawBegin(flag);
66 
67     Base::SetProjectionMtx(drawInfo.GetProjectionMtx());
68 }
69 
70 void
DrawBegin(u32 flag)71 Drawer::DrawBegin(u32 flag)
72 {
73     m_ActiveTexureNum = 0;
74     m_TexCoordNum = 0;
75     m_PrevTexObj = 0;
76     m_CurrentTexEnvType = TEX_ENV_TYPE_NUM;
77 
78     m_IsBlendDefault = true;
79 
80     SetUpTextures( NULL, false );
81 
82     Base::DrawBegin(flag);
83 }
84 
85 void
DrawEnd(u32 flag)86 Drawer::DrawEnd(u32 flag)
87 {
88     FlushBuffer();
89 
90     Base::DrawEnd(flag);
91 }
92 
Drawer()93 Drawer::Drawer()
94 :   m_PrevTexObj(0),
95     m_ActiveTexureNum(0),
96     m_TexCoordNum(0),
97     m_IsBlendDefault(true),
98     m_AlphaTestEnable(false),
99     m_CurrentTexEnvType(TEX_ENV_TYPE_NUM)
100 #if ! defined(NW_RELEASE)
101     , m_PreviousTexEnvType(TEX_ENV_TYPE_NUM)
102 #endif
103 {
104 }
105 
Drawer(GraphicsResource & graphicsResource)106 Drawer::Drawer( GraphicsResource& graphicsResource )
107 {
108     this->Initialize( graphicsResource );
109 }
110 
111 void
Initialize(GraphicsResource & graphicsResource,void * vertexBuffer)112 Drawer::Initialize( GraphicsResource& graphicsResource, void* vertexBuffer )
113 {
114     const u32 cmdBufSize = GetCommandBufferSize(
115         graphicsResource.GetRectShaderBinary(),
116         graphicsResource.GetRectShaderBinarySize());
117 
118     const u32 allocSize = cmdBufSize + (vertexBuffer == NULL ? GetVertexBufferSize(): 0);
119 
120     void* commandBuffer = Layout::AllocDeviceMemory(allocSize, 4);
121     NW_NULL_ASSERT(commandBuffer);
122 
123     if (vertexBuffer == NULL)
124     {
125         Base::Initialize(
126             commandBuffer,
127             graphicsResource.GetRectShaderBinary(),
128             graphicsResource.GetRectShaderBinarySize());
129     }
130     else
131     {
132         Base::Initialize(
133             vertexBuffer,
134             commandBuffer,
135             graphicsResource.GetRectShaderBinary(),
136             graphicsResource.GetRectShaderBinarySize());
137     }
138 }
139 
140 void
Finalize()141 Drawer::Finalize()
142 {
143     void *const comamndBuffer = m_CommandBuffer;
144 
145     Base::Finalize();
146     Layout::FreeDeviceMemory(comamndBuffer);
147 }
148 
149 }   // namespace lyt
150 }   // namespace nw
151 #endif
152