1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResProceduralTexture.h
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 #ifndef NW_GFX_RESPROCEDURALTEXTURE_H_
19 #define NW_GFX_RESPROCEDURALTEXTURE_H_
20 
21 #include <GLES2/gl2.h>
22 #include <GLES2/gl2ext.h>
23 
24 #include <nw/ut/ut_Color.h>
25 #include <nw/ut/ut_ResUtil.h>
26 #include <nw/ut/ut_ResDictionary.h>
27 #include <nw/gfx/res/gfx_ResTexture.h>
28 #include <nw/gfx/res/gfx_ResLookupTable.h>
29 #include <nw/gfx/res/gfx_ResTypeInfo.h>
30 
31 namespace nw {
32 namespace gfx {
33 namespace res {
34 
35 //! @details :private
36 struct ResProceduralNoiseData
37 {
38     nw::ut::ResBool m_IsNoiseEnabled;
39     u8 _padding_0[3];
40     nw::ut::ResVec3 m_NoiseU;
41     nw::ut::ResVec3 m_NoiseV;
42     nw::ut::Offset toNoiseTable;
43 };
44 
45 //! @details :private
46 struct ResProceduralClampShiftData
47 {
48     nw::ut::ResU32 m_ClampU;
49     nw::ut::ResU32 m_ClampV;
50     nw::ut::ResU32 m_ShiftU;
51     nw::ut::ResU32 m_ShiftV;
52 };
53 
54 //! @details :private
55 struct ResProceduralMappingData
56 {
57     nw::ut::ResBool m_IsAlphaSeparate;
58     u8 _padding_0[3];
59     nw::ut::ResU32 m_MappingFunction;
60     nw::ut::ResU32 m_AlphaMappingFunction;
61     nw::ut::Offset toMappingTable;
62     nw::ut::Offset toAlphaMappingTable;
63 };
64 
65 //! @details :private
66 struct ResProceduralColorData
67 {
68     nw::ut::ResS32 m_TextureWidth;
69     nw::ut::ResS32 m_TextureOffset;
70     nw::ut::ResF32 m_TextureLodBias;
71     nw::ut::ResU32 m_MinFilter;
72     nw::ut::Offset toColorTables[4];
73 };
74 
75 //! @details :private
76 struct ResProceduralTextureData : public ResTextureData
77 {
78     ResProceduralNoiseData m_Noise;
79     ResProceduralClampShiftData m_ClampShift;
80     ResProceduralMappingData m_Mapping;
81     ResProceduralColorData m_Color;
82 };
83 
84 
85 //--------------------------------------------------------------------------
86 //! @brief  プロシージャルテクスチャのノイズを表すバイナリリソースクラスです。
87 //! @details :private
88 //---------------------------------------------------------------------------
89 class ResProceduralNoise : public nw::ut::ResCommon<ResProceduralNoiseData>
90 {
91 public:
92     NW_RES_CTOR( ResProceduralNoise )
93 
94     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( NoiseEnabled )        // IsNoiseEnabled(), SetNoiseEnabled()
95     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, NoiseU )     // GetNoiseU()
96     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, NoiseV )     // GetNoiseV()
97     NW_RES_FIELD_CLASS_DECL( ResImageLookupTable, NoiseTable ) // GetNoiseTable()
98 };
99 
100 
101 //--------------------------------------------------------------------------
102 //! @brief  プロシージャルテクスチャのクランプを表すバイナリリソースクラスです。
103 //! @details :private
104 //---------------------------------------------------------------------------
105 class ResProceduralClampShift : public nw::ut::ResCommon<ResProceduralClampShiftData>
106 {
107 public:
108     enum Clamp
109     {
110         CLAMP_REPEAT    = GL_SYMMETRICAL_REPEAT_DMP,
111         CLAMP_MIRRORED  = GL_MIRRORED_REPEAT,
112         CLAMP_PULSE     = GL_PULSE_DMP,
113         CLAMP_EDGE      = GL_CLAMP_TO_EDGE,
114         CLAMP_ZERO      = GL_CLAMP_TO_ZERO_DMP
115     };
116 
117     enum Shift
118     {
119         SHIFT_EVEN = GL_EVEN_DMP,
120         SHIFT_ODD  = GL_ODD_DMP,
121         SHIFT_NONE = GL_NONE_DMP
122     };
123 
124     NW_RES_CTOR( ResProceduralClampShift )
125 
126     NW_RES_FIELD_PRIMITIVE_DECL( Clamp, ClampU ) // GetClampU(), SetClampU()
127     NW_RES_FIELD_PRIMITIVE_DECL( Clamp, ClampV ) // GetClampV(), SetClampV()
128     NW_RES_FIELD_PRIMITIVE_DECL( Shift, ShiftU ) // GetShiftU(), SetShiftU()
129     NW_RES_FIELD_PRIMITIVE_DECL( Shift, ShiftV ) // GetShiftV(), SetShiftV()
130 };
131 
132 //--------------------------------------------------------------------------
133 //! @brief  プロシージャルテクスチャのマッピングを表すバイナリリソースクラスです。
134 //! @details :private
135 //---------------------------------------------------------------------------
136 class ResProceduralMapping : public nw::ut::ResCommon<ResProceduralMappingData>
137 {
138 public:
139     enum Function
140     {
141         FUNCTION_U        = GL_PROCTEX_U_DMP,
142         FUNCTION_V        = GL_PROCTEX_V_DMP,
143         FUNCTION_U2       = GL_PROCTEX_U2_DMP,
144         FUNCTION_V2       = GL_PROCTEX_V2_DMP,
145         FUNCTION_ADD      = GL_PROCTEX_ADD_DMP,
146         FUNCTION_ADD2     = GL_PROCTEX_ADD2_DMP,
147         FUNCTION_ADDSQRT2 = GL_PROCTEX_ADDSQRT2_DMP,
148         FUNCTION_MIN      = GL_PROCTEX_MIN_DMP,
149         FUNCTION_MAX      = GL_PROCTEX_MAX_DMP,
150         FUNCTION_RMAX     = GL_PROCTEX_RMAX_DMP
151     };
152 
153     NW_RES_CTOR( ResProceduralMapping )
154 
155     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( AlphaSeparate )             // IsAlphaSeparate(), SetAlphaSeparate()
156     NW_RES_FIELD_PRIMITIVE_DECL( Function, MappingFunction )      // GetMappingFunction(), SetMappingFunction()
157     NW_RES_FIELD_PRIMITIVE_DECL( Function, AlphaMappingFunction ) // GetAlphaMappingFunction(), SetAlphaMappingFunction()
158     NW_RES_FIELD_CLASS_DECL( ResImageLookupTable, MappingTable )      // GetMappingTable()
159     NW_RES_FIELD_CLASS_DECL( ResImageLookupTable, AlphaMappingTable ) // GetAlphaMappingTable()
160 };
161 
162 //--------------------------------------------------------------------------
163 //! @brief  プロシージャルテクスチャのカラーを表すバイナリリソースクラスです。
164 //! @details :private
165 //---------------------------------------------------------------------------
166 class ResProceduralColor : public nw::ut::ResCommon<ResProceduralColorData>
167 {
168 public:
169     enum MinFilter
170     {
171         MINFILTER_NEAREST                = GL_NEAREST,
172         MINFILTER_LINEAR                 = GL_LINEAR,
173         MINFILTER_NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
174         MINFILTER_NEAREST_MIPMAP_LINEAR  = GL_NEAREST_MIPMAP_LINEAR,
175         MINFILTER_LINEAR_MIPMAP_NEAREST  = GL_LINEAR_MIPMAP_NEAREST,
176         MINFILTER_LINEAR_MIPMAP_LINEAR   = GL_LINEAR_MIPMAP_LINEAR
177     };
178 
179     NW_RES_CTOR( ResProceduralColor )
180 
181     NW_RES_FIELD_PRIMITIVE_DECL( s32, TextureWidth )    // GetTextureWidth(), SetTextureWidth()
182     NW_RES_FIELD_PRIMITIVE_DECL( s32, TextureOffset )   // GetTextureOffset(), SetTextureOffset()
183     NW_RES_FIELD_PRIMITIVE_DECL( f32, TextureLodBias )  // GetTextureLodBias(), SetTextureLodBias()
184     NW_RES_FIELD_PRIMITIVE_DECL( MinFilter, MinFilter ) // GetMinFilter(), SetMinFilter()
185     NW_RES_FIELD_CLASS_FIXED_LIST_DECL( ResImageLookupTable, ColorTables ) // GetColorTables(int idx), GetColorTablesCount()
186 };
187 
188 
189 //--------------------------------------------------------------------------
190 //! @brief  プロシージャルテクスチャを表すバイナリリソースクラスです。
191 //! @details :private
192 //---------------------------------------------------------------------------
193 class ResProceduralTexture : public ResTexture
194 {
195 public:
196     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResProceduralTexture) };
197     enum { SIGNATURE = NW_RES_SIGNATURE32('TXPR') };
198 
199     NW_RES_CTOR_INHERIT( ResProceduralTexture, ResTexture )
200 
201     NW_RES_FIELD_RESSTRUCT_DECL( ResProceduralNoise, Noise )     // GetNoise(), GetNoiseData()
202     NW_RES_FIELD_RESSTRUCT_DECL( ResProceduralClampShift, ClampShift ) // GetClampShift(), GetClampShiftData()
203     NW_RES_FIELD_RESSTRUCT_DECL( ResProceduralMapping, Mapping ) // GetMapping(), GetMappingData()
204     NW_RES_FIELD_RESSTRUCT_DECL( ResProceduralColor, Color )    // GetColor(), GetColorData()
205 };
206 
207 } // namespace res
208 } // namespace gfx
209 } // namespace nw
210 
211 #endif // NW_GFX_RESPROCEDURALTEXTURE_H_
212