1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_ResModel.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: 19452 $
14 *---------------------------------------------------------------------------*/
15
16 #include "../precompiled.h"
17
18 #include <nw/ut/ut_ResUtil.h>
19 #include <nw/ut/ut_ResDictionary.h>
20 #include <nw/gfx/gfx_SceneObject.h>
21 #include <nw/gfx/res/gfx_ResShape.h>
22 #include <nw/gfx/res/gfx_ResModel.h>
23 #include <nw/gfx/res/gfx_ResMaterial.h>
24 #include <nw/gfx/res/gfx_ResGraphicsFile.h>
25 #include <nw/gfx/gfx_Common.h>
26 #include <GLES2/gl2.h>
27 #include <GLES2/gl2ext.h>
28
29 namespace nw {
30 namespace gfx {
31 namespace res {
32
33 //----------------------------------------------------------------------------
34 Result
Setup(os::IAllocator * allocator,ResGraphicsFile graphicsFile)35 ResModel::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile)
36 {
37 Result result = RESOURCE_RESULT_OK;
38 NW_ASSERT( this->IsValid() );
39 NW_ASSERT( internal::ResCheckRevision( *this ) );
40 NW_ASSERT( internal::ResCheckRevision( graphicsFile ) );
41
42 s32 shapeNum = this->GetShapesCount();
43 for ( int i = 0; i < shapeNum; ++i )
44 {
45 if (!ut::CheckFlag(this->GetShapes(i).GetFlags(), ResShape::FLAG_HAS_BEEN_SETUP))
46 {
47 result |= this->GetShapes( i ).Setup();
48 }
49 }
50
51 s32 materialNum = this->GetMaterialsCount();
52 for ( int i = 0; i < materialNum; ++i )
53 {
54 result |= this->GetMaterials( i ).Setup(allocator, graphicsFile);
55 }
56
57 #if defined(NW_CALL_DRAW_ELEMENTS_MANUALLY)
58 // シェーダーの参照解決が終わるまでは頂点用のコマンド生成ができない。
59 if ( (result.GetCode() & RESOURCE_RESULT_NOT_FOUND_SHADER) == 0 )
60 {
61 // 各メッシュに対して、頂点アトリビュートの設定コマンドを生成する。
62 s32 meshNum = this->GetMeshesCount();
63 for ( int i = 0; i < meshNum; ++ i )
64 {
65 ResMesh mesh = this->GetMeshes( i );
66 mesh.Setup( *this, allocator, graphicsFile );
67 }
68 }
69 #endif
70
71 return result;
72 }
73
74 //----------------------------------------------------------------------------
75 void
Cleanup()76 ResModel::Cleanup()
77 {
78 s32 shapeNum = this->GetShapesCount();
79 for ( int i = 0; i < shapeNum; ++i )
80 {
81 if (ut::CheckFlag(this->GetShapes(i).GetFlags(), ResShape::FLAG_HAS_BEEN_SETUP))
82 {
83 this->GetShapes( i ).Cleanup();
84 }
85 }
86
87 s32 materialNum = this->GetMaterialsCount();
88 for ( int i = 0; i < materialNum; ++i )
89 {
90 this->GetMaterials( i ).Cleanup();
91 }
92
93 s32 meshNum = this->GetMeshesCount();
94 for ( int i = 0; i < meshNum; ++ i )
95 {
96 this->GetMeshes( i ).Cleanup();
97 }
98 }
99
100 } /* namespace res */
101 } /* namespace gfx */
102 } /* namespace nw */
103
104