1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_ResLookupTable.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_ResLookupTable.h>
21
22 namespace nw {
23 namespace gfx {
24 namespace res {
25
26 typedef void (*ActivateFunc)(ResTexture resTex, RenderContext& context);
27 typedef void (*CleanupFunc)(ResLookupTable resLut);
28 typedef Result (*SetupFunc)(ResLookupTable resLut);
29
30 static void ResImageLut_Cleanup(ResLookupTable resLut);
31 static void ResReferenceLut_Cleanup(ResLookupTable resLut);
32
33 static Result ResImageLut_Setup(ResLookupTable resLut);
34 static Result ResReferenceLut_Setup(ResLookupTable resLut);
35
36 static SetupFunc s_LutSetupTable[] =
37 {
38 ResImageLut_Setup,
39 ResReferenceLut_Setup
40 };
41
42 static CleanupFunc s_LutCleanupTable[] =
43 {
44 ResImageLut_Cleanup,
45 ResReferenceLut_Cleanup
46 };
47
48 //----------------------------------------
49 static Result
ResImageLut_Setup(ResLookupTable resLut)50 ResImageLut_Setup(ResLookupTable resLut)
51 {
52 Result result = RESOURCE_RESULT_OK;
53
54 NW_UNUSED_VARIABLE(resLut);
55
56 return result;
57 }
58
59
60 //----------------------------------------
61 static Result
ResReferenceLut_Setup(ResLookupTable resLut)62 ResReferenceLut_Setup(ResLookupTable resLut)
63 {
64 Result result = RESOURCE_RESULT_OK;
65
66 result |= ResImageLut_Setup(resLut.Dereference());
67
68 return result;
69 }
70
71 //----------------------------------------
72 static void
ResImageLut_Cleanup(ResLookupTable resLut)73 ResImageLut_Cleanup(ResLookupTable resLut)
74 {
75 ResImageLookupTable imageLut = ResStaticCast<ResImageLookupTable>( resLut );
76
77 GraphicsDevice::InvalidateLookupTable(imageLut);
78 }
79
80
81 //----------------------------------------
82 static void
ResReferenceLut_Cleanup(ResLookupTable resLut)83 ResReferenceLut_Cleanup(ResLookupTable resLut)
84 {
85 ResReferenceLookupTable referLut = ResStaticCast<ResReferenceLookupTable>( resLut );
86 NW_ASSERT(resLut.IsValid());
87
88 referLut.ref().toTargetLut.set_ptr(NULL);
89 }
90
91 //----------------------------------------------------------------------------
92 Result
Setup()93 ResLookupTable::Setup()
94 {
95 NW_ASSERT( this->IsValid() );
96
97 Result result = RESOURCE_RESULT_OK;
98
99 switch ( this->ref().typeInfo )
100 {
101 case ResImageLookupTable::TYPE_INFO:
102 {
103 result |= s_LutSetupTable[0]( *this );
104 }
105 break;
106 case ResReferenceLookupTable::TYPE_INFO:
107 {
108 result |= s_LutSetupTable[1]( *this );
109 }
110 break;
111 default:
112 {
113 NW_FATAL_ERROR("Unsupported lut type.");
114 }
115 }
116
117 return result;
118 }
119
120 //----------------------------------------
121 void
Cleanup()122 ResLookupTable::Cleanup()
123 {
124 switch ( this->ref().typeInfo )
125 {
126 case ResImageLookupTable::TYPE_INFO:
127 {
128 s_LutCleanupTable[0]( *this );
129 }
130 break;
131 case ResReferenceLookupTable::TYPE_INFO:
132 {
133 s_LutCleanupTable[1]( *this );
134 }
135 break;
136 default:
137 {
138 NW_FATAL_ERROR("Unsupported lut type.");
139 }
140 }
141 }
142
143 //----------------------------------------
144 void
ForceSetup(ResLookupTable lut)145 ResReferenceLookupTable::ForceSetup(ResLookupTable lut)
146 {
147 NW_ASSERT(lut.IsValid());
148 ref().toTargetLut.set_ptr(lut.ptr());
149
150 ResReferenceLut_Setup(*this);
151 }
152
153 //----------------------------------------
154 void
ForceSetup(const char * targetName,ResLookupTable lut)155 ResReferenceLookupTable::ForceSetup(const char* targetName, ResLookupTable lut)
156 {
157 NW_NULL_ASSERT(targetName);
158 if (std::strcmp(targetName, this->GetPath()) == 0)
159 {
160 this->ForceSetup(lut);
161 }
162 }
163 //----------------------------------------
164 Result
Setup(os::IAllocator * allocator,ResGraphicsFile graphicsFile)165 ResLookupTableSet::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile)
166 {
167 NW_UNUSED_VARIABLE(allocator);
168 NW_UNUSED_VARIABLE(graphicsFile);
169 NW_ASSERT( internal::ResCheckRevision( *this ) );
170
171 Result result = RESOURCE_RESULT_OK;
172
173 s32 samplerNum = this->GetSamplersCount();
174 for ( int i = 0; i < samplerNum; ++i )
175 {
176 result |= this->GetSamplers( i ).Setup();
177 }
178
179 return result;
180 }
181
182 //----------------------------------------
183 void
Cleanup()184 ResLookupTableSet::Cleanup()
185 {
186 ut::SafeCleanupAll(this->GetSamplers());
187 }
188
189 } /* namespace res */
190 } /* namespace gfx */
191 } /* namespace nw */
192
193