1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_LightSet.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: 27868 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17 #include <nw/gfx/gfx_LightSet.h>
18
19 namespace nw
20 {
21 namespace gfx
22 {
23
24 NW_UT_RUNTIME_TYPEINFO_ROOT_DEFINITION(LightSet);
25
26 //----------------------------------------
27 LightSet*
Create(os::IAllocator * allocator)28 LightSet::DynamicBuilder::Create(
29 os::IAllocator* allocator
30 )
31 {
32 NW_NULL_ASSERT(allocator);
33
34 void* memory = allocator->Alloc(sizeof(LightSet));
35 NW_NULL_ASSERT(memory);
36 LightSet* lightSet = new(memory) LightSet(
37 allocator,
38 ResLightSet(NULL),
39 m_Description);
40
41 if (m_Description.isFixedSizeMemory && m_Description.maxVertexLights != 0)
42 {
43 void* memoryArray = allocator->Alloc(sizeof(VertexLight*) * m_Description.maxVertexLights);
44 lightSet->m_VertexLights = VertexLightArray(memoryArray, m_Description.maxVertexLights, allocator);
45 }
46 else
47 {
48 lightSet->m_VertexLights = VertexLightArray(allocator);
49 }
50
51 return lightSet;
52 }
53
54 //----------------------------------------
55 LightSet*
Create(ResLightSet resource,os::IAllocator * allocator)56 LightSet::Create(
57 ResLightSet resource,
58 os::IAllocator* allocator
59 )
60 {
61 NW_NULL_ASSERT(allocator);
62 NW_ASSERT(resource.IsValid());
63
64 void* memory = allocator->Alloc(sizeof(LightSet));
65 NW_NULL_ASSERT(memory);
66
67 LightSet::Description description;
68 description.maxVertexLights = resource.GetLightsCount();
69
70 LightSet* lightSet = new(memory) LightSet(
71 allocator,
72 resource,
73 description);
74
75 if (description.isFixedSizeMemory && description.maxVertexLights != 0)
76 {
77 void* memoryArray = allocator->Alloc(sizeof(VertexLight*) * description.maxVertexLights);
78 lightSet->m_VertexLights = VertexLightArray(memoryArray, description.maxVertexLights, allocator);
79 }
80 else
81 {
82 lightSet->m_VertexLights = VertexLightArray(allocator);
83 }
84
85 return lightSet;
86 }
87
88 } // namespace gfx
89 } // namespace nw
90