1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResLight.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: $
16  *---------------------------------------------------------------------------*/
17 
18 #include "../precompiled.h"
19 
20 #include <nw/gfx/res/gfx_ResUtil.h>
21 #include <nw/gfx/res/gfx_ResLight.h>
22 #include <nw/gfx/res/gfx_ResGraphicsFile.h>
23 
24 namespace nw {
25 namespace gfx {
26 namespace res {
27 
28 //----------------------------------------
29 Result
Setup(os::IAllocator * allocator,ResGraphicsFile graphicsFile)30 ResLight::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile)
31 {
32     NW_UNUSED_VARIABLE(allocator);
33 
34     Result result = RESOURCE_RESULT_OK;
35 
36     ResFragmentLight fragment = ResDynamicCast<ResFragmentLight>(*this);
37 
38     if (fragment.IsValid())
39     {
40         ResReferenceLookupTable referenceDistanceSampler =
41             ResDynamicCast<ResReferenceLookupTable>(fragment.GetDistanceSampler());
42 
43         Result distanceResult = SetupReferenceLut(referenceDistanceSampler, graphicsFile);
44 
45         if ( fragment.GetDistanceSampler().IsValid() )
46         {
47             if (distanceResult.IsSuccess())
48             {
49                 result |= fragment.GetDistanceSampler().Setup();
50             }
51         }
52 
53         result |= distanceResult;
54 
55         if (fragment.GetAngleSampler().IsValid())
56         {
57             ResLookupTable resLut = fragment.GetAngleSampler().GetSampler();
58 
59             if (resLut.IsValid())
60             {
61                 ResReferenceLookupTable referenceAngleSampler =
62                     ResDynamicCast<ResReferenceLookupTable>(resLut);
63 
64                 Result angleResult = SetupReferenceLut(referenceAngleSampler, graphicsFile);
65 
66                 if (angleResult.IsSuccess())
67                 {
68                     result |= resLut.Setup();
69                 }
70 
71                 result |= angleResult;
72             }
73             else
74             {
75                 result |= RESOURCE_RESULT_IRRELEVANT_LOCATION_LUT;
76             }
77         }
78     }
79 
80     return result;
81 }
82 
83 //----------------------------------------
84 void
Cleanup()85 ResLight::Cleanup()
86 {
87     ResFragmentLight fragment = ResDynamicCast<ResFragmentLight>(*this);
88 
89     if (fragment.IsValid())
90     {
91         ut::SafeCleanup(fragment.GetDistanceSampler());
92         ut::SafeCleanup(fragment.GetAngleSampler());
93     }
94 }
95 
96 } /* namespace res */
97 } /* namespace gfx */
98 } /* namespace nw */
99 
100