1 | //-----------------------------------------------------------------------------
|
---|
2 | // File: DXUTEffectMap.h
|
---|
3 | //
|
---|
4 | // Desc: Maps the set of standard semantics and annotations to a collection
|
---|
5 | // of ID3DXEffect objects.
|
---|
6 | //
|
---|
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
---|
8 | //-----------------------------------------------------------------------------
|
---|
9 | #pragma once
|
---|
10 | #ifndef DXUT_EFFECTMAP_H
|
---|
11 | #define DXUT_EFFECTMAP_H
|
---|
12 |
|
---|
13 | const int MAX_INDEX = 5;
|
---|
14 |
|
---|
15 | enum DXUT_SEMANTIC
|
---|
16 | {
|
---|
17 | DXUT_UNKNOWN_SEMANTIC,
|
---|
18 |
|
---|
19 | DXUT_Diffuse,
|
---|
20 | DXUT_Specular,
|
---|
21 | DXUT_Ambient,
|
---|
22 | DXUT_SpecularPower,
|
---|
23 | DXUT_Emissive,
|
---|
24 | DXUT_Normal,
|
---|
25 | DXUT_Height,
|
---|
26 | DXUT_Refraction,
|
---|
27 | DXUT_Opacity,
|
---|
28 | DXUT_Environment,
|
---|
29 | DXUT_EnvironmentNormal,
|
---|
30 | DXUT_Fresnel,
|
---|
31 |
|
---|
32 | DXUT_World,
|
---|
33 | DXUT_WorldInverse,
|
---|
34 | DXUT_WorldInverseTranspose,
|
---|
35 | DXUT_WorldView,
|
---|
36 | DXUT_WorldViewInverse,
|
---|
37 | DXUT_WorldViewInverseTranspose,
|
---|
38 | DXUT_WorldViewProjection,
|
---|
39 | DXUT_WorldViewProjectionInverse,
|
---|
40 | DXUT_WorldViewProjectionInverseTranspose,
|
---|
41 | DXUT_View,
|
---|
42 | DXUT_ViewInverse,
|
---|
43 | DXUT_ViewInverseTranspose,
|
---|
44 | DXUT_ViewProjection,
|
---|
45 | DXUT_ViewProjectionInverse,
|
---|
46 | DXUT_ViewProjectionInverseTranspose,
|
---|
47 | DXUT_Projection,
|
---|
48 | DXUT_ProjectionInverse,
|
---|
49 | DXUT_ProjectionInverseTranspose,
|
---|
50 |
|
---|
51 | DXUT_RenderTargetDimensions,
|
---|
52 | DXUT_RenderTargetClipping,
|
---|
53 | DXUT_Time,
|
---|
54 | DXUT_LastTime,
|
---|
55 | DXUT_ElapsedTime,
|
---|
56 | DXUT_Position,
|
---|
57 | DXUT_Direction,
|
---|
58 | DXUT_BoundingCenter,
|
---|
59 | DXUT_BoundingSphereSize,
|
---|
60 | DXUT_BoundingSphereMin,
|
---|
61 | DXUT_BoundingSphereMax,
|
---|
62 | DXUT_BoundingBoxSize,
|
---|
63 | DXUT_BoundingBoxMin,
|
---|
64 | DXUT_BoundingBoxMax,
|
---|
65 | DXUT_Attenuation,
|
---|
66 | DXUT_RenderColorTarget,
|
---|
67 | DXUT_RenderDepthStencilTarget,
|
---|
68 | DXUT_UnitsScale,
|
---|
69 | DXUT_StandardsGlobal,
|
---|
70 |
|
---|
71 | NUM_DXUT_SEMANTICS
|
---|
72 | };
|
---|
73 |
|
---|
74 | enum DXUT_OBJECT
|
---|
75 | {
|
---|
76 | DXUT_UNKNOWN_OBJECT,
|
---|
77 |
|
---|
78 | DXUT_Geometry,
|
---|
79 | DXUT_Light,
|
---|
80 | DXUT_Camera,
|
---|
81 | DXUT_Frame,
|
---|
82 |
|
---|
83 | NUM_DXUT_OBJECTS
|
---|
84 | };
|
---|
85 |
|
---|
86 |
|
---|
87 | struct ParamList
|
---|
88 | {
|
---|
89 | ID3DXEffect* pEffect;
|
---|
90 | CGrowableArray< D3DXHANDLE > ahParameters;
|
---|
91 |
|
---|
92 | void Reset();
|
---|
93 | };
|
---|
94 |
|
---|
95 |
|
---|
96 | class CDXUTEffectMap
|
---|
97 | {
|
---|
98 | public:
|
---|
99 | CDXUTEffectMap() { Reset(); }
|
---|
100 | ~CDXUTEffectMap() { Reset(); }
|
---|
101 |
|
---|
102 | VOID Reset();
|
---|
103 |
|
---|
104 | HRESULT AddEffect( ID3DXEffect* pEffect );
|
---|
105 | HRESULT RemoveEffect( ID3DXEffect* pEffect );
|
---|
106 |
|
---|
107 | HRESULT SetStandardParameter( const WCHAR* strSemantic, const WCHAR* strObject, DWORD dwObjectIndex, float* pData, DWORD dwDataLen, const WCHAR* strType = NULL, const WCHAR* strUnits = NULL, const WCHAR* strSpace = NULL );
|
---|
108 | HRESULT SetStandardParameter( DXUT_SEMANTIC eSemantic, DXUT_OBJECT eObject, DWORD dwObjectIndex, float* pData, DWORD dwDataLen, const WCHAR* strType = NULL, const WCHAR* strUnits = NULL, const WCHAR* strSpace = NULL );
|
---|
109 |
|
---|
110 | HRESULT SetWorldMatrix( D3DXMATRIXA16* pWorldMatrix, const WCHAR* strUnits = NULL );
|
---|
111 | HRESULT SetViewMatrix( D3DXMATRIXA16* pViewMatrix, const WCHAR* strUnits = NULL );
|
---|
112 | HRESULT SetProjectionMatrix( D3DXMATRIXA16* pProjectionMatrix );
|
---|
113 |
|
---|
114 | static DXUT_SEMANTIC StringToSemantic( const char* cstrSemantic );
|
---|
115 | static DXUT_SEMANTIC StringToSemantic( const WCHAR* strSemantic );
|
---|
116 | static DXUT_OBJECT StringToObject( const char* cstrObject );
|
---|
117 | static DXUT_OBJECT StringToObject( const WCHAR* strObject );
|
---|
118 |
|
---|
119 | private:
|
---|
120 | HRESULT UpdateTransforms( DXUT_SEMANTIC eSemantic, const WCHAR* strUnits = L"m" );
|
---|
121 |
|
---|
122 | D3DXMATRIXA16 m_matWorld;
|
---|
123 | D3DXMATRIXA16 m_matView;
|
---|
124 | D3DXMATRIXA16 m_matProjection;
|
---|
125 |
|
---|
126 | // Database of DXUTEffect object parameter handles which are indexed accoring to
|
---|
127 | // Semantic, Object annotation, index, and containing mesh pointer
|
---|
128 | CGrowableArray<ParamList> m_Bindings[ NUM_DXUT_SEMANTICS ][ NUM_DXUT_OBJECTS ][ MAX_INDEX ];
|
---|
129 | };
|
---|
130 |
|
---|
131 |
|
---|
132 | //-------------------------------------------------------------------------------------
|
---|
133 | inline bool StringBegins( const char* strTest, const char* strStartsWith )
|
---|
134 | {
|
---|
135 | return ( 0 == _strnicmp( strTest, strStartsWith, strlen(strStartsWith) ) );
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | //-------------------------------------------------------------------------------------
|
---|
140 | inline bool StringEquals( const char* strTest, const char* strEquals )
|
---|
141 | {
|
---|
142 | return( 0 == _stricmp( strTest, strEquals ) );
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | //-------------------------------------------------------------------------------------
|
---|
147 | inline void RemoveTrailingNumber( char* strWithoutNumber, DWORD dwBufLen, const char* str )
|
---|
148 | {
|
---|
149 | StringCchCopyA( strWithoutNumber, dwBufLen, str );
|
---|
150 |
|
---|
151 | char* strIndex = strWithoutNumber + strlen(strWithoutNumber);
|
---|
152 |
|
---|
153 | // If there is a digit at the end of the semantic discard it
|
---|
154 | while( isdigit( (BYTE) (*(strIndex-1)) ) )
|
---|
155 | {
|
---|
156 | --strIndex;
|
---|
157 | }
|
---|
158 |
|
---|
159 | *strIndex = 0;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | #endif //DXUT_EFFECTMAP_H |
---|