1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_ResUtil.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_ResGraphicsFile.h>
22
23 namespace nw {
24 namespace gfx {
25 namespace res {
26
27 //----------------------------------------
28 Result
SetupReferenceLut(ResReferenceLookupTable resReferenceLut,ResGraphicsFile graphicsFile)29 SetupReferenceLut(ResReferenceLookupTable resReferenceLut, ResGraphicsFile graphicsFile)
30 {
31 Result result = RESOURCE_RESULT_OK;
32
33 if (resReferenceLut.IsValid())
34 {
35 ResImageLookupTable resImageLut = ResDynamicCast<ResImageLookupTable>(resReferenceLut.GetTargetLut());
36 if (!resImageLut.IsValid())
37 {
38 ::std::pair<ResLookupTable, bool> referenceResult;
39 referenceResult = GetReferenceLutTarget(resReferenceLut, graphicsFile);
40
41 if (!referenceResult.second)
42 {
43 result |= Result::MASK_FAIL_BIT;
44 result |= RESOURCE_RESULT_NOT_FOUND_LUT;
45 }
46 }
47 }
48
49 return result;
50 }
51
52 //----------------------------------------
53 ::std::pair<ResLookupTable, bool>
GetReferenceLutTarget(ResReferenceLookupTable referenceLut,ResGraphicsFile graphicsFile)54 GetReferenceLutTarget(ResReferenceLookupTable referenceLut, ResGraphicsFile graphicsFile)
55 {
56 bool isExisted = false;
57 const char* path = referenceLut.GetPath();
58 const char* tableName = referenceLut.GetTableName();
59 int lutSetNum = graphicsFile.GetLutSetsCount();
60
61 ResLookupTableSet resLutSet = graphicsFile.GetLutSets(path);
62
63 if (resLutSet.IsValid())
64 {
65 ResImageLookupTable resLut =
66 ResDynamicCast<ResImageLookupTable>(resLutSet.GetSamplers(tableName));
67
68 if (resLut.IsValid())
69 {
70 referenceLut.ref().toTargetLut.set_ptr(resLut.ptr());
71 isExisted = true;
72 }
73 }
74
75 return ::std::make_pair(referenceLut.GetTargetLut(), isExisted);
76 }
77
78 //----------------------------------------------------------------------------
79 ::std::pair<ResTexture, bool>
GetReferenceTextureTarget(ResReferenceTexture referenceTexture,ResGraphicsFile graphicsFile)80 GetReferenceTextureTarget(ResReferenceTexture referenceTexture, ResGraphicsFile graphicsFile)
81 {
82 bool isExisted = false;
83 const char* path = referenceTexture.GetPath();
84 ResTexture resTexture = graphicsFile.GetTextures(path);
85
86 if (resTexture.IsValid())
87 {
88 ResReferenceTexture refer = ResDynamicCast<ResReferenceTexture>(resTexture);
89
90 // 再帰呼び出しによって参照解決する
91 if (refer.IsValid())
92 {
93 ::std::pair<ResTexture, bool> referenceResult;
94 referenceResult = GetReferenceTextureTarget(refer, graphicsFile);
95 if (referenceResult.second)
96 {
97 referenceTexture.ref().toTargetTexture.set_ptr(referenceResult.first.ptr());
98 isExisted = true;
99 }
100 }
101 else
102 {
103 referenceTexture.ref().toTargetTexture.set_ptr(resTexture.ptr());
104 isExisted = true;
105 }
106 }
107
108 return ::std::make_pair(referenceTexture.GetTargetTexture(), isExisted);
109 }
110
111 //----------------------------------------
112 ::std::pair<ResShader, bool>
GetReferenceShaderTarget(ResReferenceShader referenceShader,ResGraphicsFile graphicsFile)113 GetReferenceShaderTarget(ResReferenceShader referenceShader, ResGraphicsFile graphicsFile)
114 {
115 bool isExisted = false;
116 const char* path = referenceShader.GetPath();
117 ResShader resShader = graphicsFile.GetShaders(path);
118
119 if (resShader.IsValid())
120 {
121 ResReferenceShader refer = ResDynamicCast<ResReferenceShader>(resShader);
122
123 // 再帰呼び出しによって参照解決する
124 if (refer.IsValid())
125 {
126 ::std::pair<ResShader, bool> referenceResult;
127 referenceResult = GetReferenceShaderTarget(refer, graphicsFile);
128 if (referenceResult.second)
129 {
130 referenceShader.ref().toTargetShader.set_ptr(referenceResult.first.ptr());
131 isExisted = true;
132 }
133 }
134 else
135 {
136 referenceShader.ref().toTargetShader.set_ptr(resShader.ptr());
137 isExisted = true;
138 }
139 }
140
141 return ::std::make_pair(referenceShader.GetTargetShader(),isExisted);
142 }
143
144 } /* namespace res */
145 } /* namespace gfx */
146 } /* namespace nw */
147