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