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