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