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