DOSBox-X
|
00001 /* 00002 Copyright (C) 2003 Ryan A. Nunn 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License 00006 as published by the Free Software Foundation; either version 2 00007 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License along 00015 with this program; if not, write to the Free Software Foundation, Inc., 00016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "dosbox.h" 00020 00021 #if (HAVE_D3D9_H) && (C_D3DSHADERS) && defined(WIN32) 00022 00023 #if defined(_MSC_VER) 00024 # pragma warning(disable:4244) /* const fmath::local::uint64_t to double possible loss of data */ 00025 #endif 00026 00027 #include "ScalingEffect.h" 00028 00029 ScalingEffect::ScalingEffect(LPDIRECT3DDEVICE9 pd3dDevice) : 00030 m_scale(0.0f), m_forceupdate(false), m_pd3dDevice(pd3dDevice), m_pEffect(0) 00031 { 00032 m_iDim[0] = m_iDim[1] = 256.0f; // Some sane default 00033 m_strName = "Unnamed"; 00034 KillThis(); 00035 } 00036 00037 ScalingEffect::~ScalingEffect(void) 00038 { 00039 KillThis(); 00040 } 00041 00042 void ScalingEffect::KillThis() 00043 { 00044 SAFE_RELEASE(m_pEffect); 00045 m_strErrors.clear(); 00046 m_strName = "Unnamed"; 00047 00048 m_MatWorldEffectHandle = 0; 00049 m_MatViewEffectHandle = 0; 00050 m_MatProjEffectHandle = 0; 00051 m_MatWorldViewEffectHandle = 0; 00052 m_MatViewProjEffectHandle = 0; 00053 m_MatWorldViewProjEffectHandle = 0; 00054 00055 // Source Texture Handles 00056 m_SourceDimsEffectHandle = 0; 00057 m_TexelSizeEffectHandle = 0; 00058 m_SourceTextureEffectHandle = 0; 00059 m_WorkingTexture1EffectHandle = 0; 00060 m_WorkingTexture2EffectHandle = 0; 00061 m_Hq2xLookupTextureHandle = 0; 00062 00063 // Technique stuff 00064 m_PreprocessTechnique1EffectHandle = 0; 00065 m_PreprocessTechnique2EffectHandle = 0; 00066 m_CombineTechniqueEffectHandle = 0; 00067 } 00068 00069 HRESULT ScalingEffect::LoadEffect(const TCHAR *filename) 00070 { 00071 KillThis(); 00072 00073 LPD3DXBUFFER lpBufferEffect = 0; 00074 LPD3DXBUFFER lpErrors = 0; 00075 LPD3DXEFFECTCOMPILER lpEffectCompiler = 0; 00076 00077 m_strErrors += filename; 00078 m_strErrors += ":\n"; 00079 00080 // First create an effect compiler 00081 HRESULT hr = D3DXCreateEffectCompilerFromFile(filename, NULL, NULL, 0, 00082 &lpEffectCompiler, &lpErrors); 00083 00084 // Errors... 00085 if(FAILED(hr)) { 00086 if(lpErrors) { 00087 m_strErrors += (char*) lpErrors->GetBufferPointer(); 00088 SAFE_RELEASE(lpErrors); 00089 } 00090 00091 m_strErrors += "Unable to create effect compiler from "; 00092 m_strErrors += filename; 00093 } 00094 00095 if(SUCCEEDED(hr)) { 00096 #ifdef C_D3DSHADERS_COMPILE_WITH_DEBUG 00097 hr = lpEffectCompiler->CompileEffect(D3DXSHADER_DEBUG, &lpBufferEffect, &lpErrors); 00098 #else 00099 hr = lpEffectCompiler->CompileEffect(0, &lpBufferEffect, &lpErrors); 00100 #endif 00101 00102 // Errors... 00103 if(FAILED(hr)) { 00104 if(lpErrors) { 00105 m_strErrors += (char*) lpErrors->GetBufferPointer(); 00106 SAFE_RELEASE(lpErrors); 00107 } 00108 00109 m_strErrors += "Unable to compile effect from "; 00110 m_strErrors += filename; 00111 } 00112 } 00113 00114 if(SUCCEEDED(hr)) { 00115 hr = D3DXCreateEffect(m_pd3dDevice, 00116 lpBufferEffect->GetBufferPointer(), 00117 lpBufferEffect->GetBufferSize(), 00118 NULL, NULL, 00119 0, 00120 NULL, &m_pEffect, &lpErrors); 00121 00122 // Errors... 00123 if(FAILED(hr)) { 00124 if(lpErrors) { 00125 m_strErrors += (char*) lpErrors->GetBufferPointer(); 00126 SAFE_RELEASE(lpErrors); 00127 } 00128 00129 m_strErrors += "Unable to create effect from compiled "; 00130 m_strErrors += filename; 00131 } 00132 } 00133 00134 if(SUCCEEDED(hr)) { 00135 m_pEffect->GetDesc(&m_EffectDesc); 00136 hr = ParseParameters(lpEffectCompiler); 00137 } 00138 00139 SAFE_RELEASE(lpErrors); 00140 SAFE_RELEASE(lpBufferEffect); 00141 SAFE_RELEASE(lpEffectCompiler); 00142 return hr; 00143 } 00144 00145 HRESULT ScalingEffect::ParseParameters(LPD3DXEFFECTCOMPILER lpEffectCompiler) 00146 { 00147 HRESULT hr = S_OK; 00148 00149 if(m_pEffect == NULL) 00150 return E_FAIL; 00151 00152 // Look at parameters for semantics and annotations that we know how to interpret 00153 D3DXPARAMETER_DESC ParamDesc; 00154 D3DXPARAMETER_DESC AnnotDesc; 00155 D3DXHANDLE hParam; 00156 D3DXHANDLE hAnnot; 00157 LPDIRECT3DBASETEXTURE9 pTex = NULL; 00158 00159 for(UINT iParam = 0; iParam < m_EffectDesc.Parameters; iParam++) { 00160 LPCSTR pstrName = NULL; 00161 LPCSTR pstrFunction = NULL; 00162 LPCSTR pstrTarget = NULL; 00163 LPCSTR pstrTextureType = NULL; 00164 INT Width = D3DX_DEFAULT; 00165 INT Height= D3DX_DEFAULT; 00166 INT Depth = D3DX_DEFAULT; 00167 00168 hParam = m_pEffect->GetParameter(NULL, iParam); 00169 m_pEffect->GetParameterDesc(hParam, &ParamDesc); 00170 00171 if(ParamDesc.Semantic != NULL) { 00172 if(ParamDesc.Class == D3DXPC_MATRIX_ROWS || ParamDesc.Class == D3DXPC_MATRIX_COLUMNS) { 00173 if(strcmpi(ParamDesc.Semantic, "world") == 0) 00174 m_MatWorldEffectHandle = hParam; 00175 else if(strcmpi(ParamDesc.Semantic, "view") == 0) 00176 m_MatViewEffectHandle = hParam; 00177 else if(strcmpi(ParamDesc.Semantic, "projection") == 0) 00178 m_MatProjEffectHandle = hParam; 00179 else if(strcmpi(ParamDesc.Semantic, "worldview") == 0) 00180 m_MatWorldViewEffectHandle = hParam; 00181 else if(strcmpi(ParamDesc.Semantic, "viewprojection") == 0) 00182 m_MatViewProjEffectHandle = hParam; 00183 else if(strcmpi(ParamDesc.Semantic, "worldviewprojection") == 0) 00184 m_MatWorldViewProjEffectHandle = hParam; 00185 } 00186 00187 else if(ParamDesc.Class == D3DXPC_VECTOR && ParamDesc.Type == D3DXPT_FLOAT) { 00188 if(strcmpi(ParamDesc.Semantic, "sourcedims") == 0) 00189 m_SourceDimsEffectHandle = hParam; 00190 else if(strcmpi(ParamDesc.Semantic, "texelsize") == 0) 00191 m_TexelSizeEffectHandle = hParam; 00192 else if(strcmpi(ParamDesc.Semantic, "inputdims") == 0) { 00193 if(m_iDim[0] && m_iDim[1] && ((hr = m_pEffect->SetFloatArray(hParam, m_iDim, 2)) != D3D_OK)) { 00194 m_strErrors += "Could not set inputdims parameter!"; 00195 return hr; 00196 } 00197 } 00198 } 00199 00200 else if(ParamDesc.Class == D3DXPC_SCALAR && ParamDesc.Type == D3DXPT_FLOAT) { 00201 if(strcmpi(ParamDesc.Semantic, "SCALING") == 0) 00202 m_pEffect->GetFloat(hParam, &m_scale); 00203 } 00204 00205 else if(ParamDesc.Class == D3DXPC_SCALAR && ParamDesc.Type == D3DXPT_BOOL) { 00206 if(strcmpi(ParamDesc.Semantic, "FORCEUPDATE") == 0) 00207 m_pEffect->GetBool(hParam, &m_forceupdate); 00208 } 00209 00210 else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_TEXTURE) { 00211 if(strcmpi(ParamDesc.Semantic, "SOURCETEXTURE") == 0) 00212 m_SourceTextureEffectHandle = hParam; 00213 if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE") == 0) 00214 m_WorkingTexture1EffectHandle = hParam; 00215 if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE1") == 0) 00216 m_WorkingTexture2EffectHandle = hParam; 00217 if(strcmpi(ParamDesc.Semantic, "HQ2XLOOKUPTEXTURE") == 0) 00218 m_Hq2xLookupTextureHandle = hParam; 00219 } 00220 00221 else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_STRING) { 00222 LPCSTR pstrTechnique = NULL; 00223 00224 if(strcmpi(ParamDesc.Semantic, "COMBINETECHNIQUE") == 0) { 00225 m_pEffect->GetString(hParam, &pstrTechnique); 00226 m_CombineTechniqueEffectHandle = m_pEffect->GetTechniqueByName(pstrTechnique); 00227 } 00228 else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE") == 0) { 00229 m_pEffect->GetString(hParam, &pstrTechnique); 00230 m_PreprocessTechnique1EffectHandle = m_pEffect->GetTechniqueByName(pstrTechnique); 00231 } 00232 else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE1") == 0) { 00233 m_pEffect->GetString(hParam, &pstrTechnique); 00234 m_PreprocessTechnique2EffectHandle = m_pEffect->GetTechniqueByName(pstrTechnique); 00235 } 00236 else if(strcmpi(ParamDesc.Semantic, "NAME") == 0) 00237 m_pEffect->GetString(hParam, &m_strName); 00238 00239 } 00240 00241 00242 } 00243 00244 for(UINT iAnnot = 0; iAnnot < ParamDesc.Annotations; iAnnot++) { 00245 hAnnot = m_pEffect->GetAnnotation (hParam, iAnnot); 00246 m_pEffect->GetParameterDesc(hAnnot, &AnnotDesc); 00247 if(strcmpi(AnnotDesc.Name, "name") == 0) 00248 m_pEffect->GetString(hAnnot, &pstrName); 00249 else if(strcmpi(AnnotDesc.Name, "function") == 0) 00250 m_pEffect->GetString(hAnnot, &pstrFunction); 00251 else if(strcmpi(AnnotDesc.Name, "target") == 0) 00252 m_pEffect->GetString(hAnnot, &pstrTarget); 00253 else if(strcmpi(AnnotDesc.Name, "width") == 0) 00254 m_pEffect->GetInt(hAnnot, &Width); 00255 else if(strcmpi(AnnotDesc.Name, "height") == 0) 00256 m_pEffect->GetInt(hAnnot, &Height); 00257 else if(strcmpi(AnnotDesc.Name, "depth") == 0) 00258 m_pEffect->GetInt(hAnnot, &Depth); 00259 else if(strcmpi(AnnotDesc.Name, "type") == 0) 00260 m_pEffect->GetString(hAnnot, &pstrTextureType); 00261 00262 } 00263 00264 // Not used in DOSBox 00265 /* if(pstrName != NULL) { 00266 pTex = NULL; 00267 DXUtil_ConvertAnsiStringToGenericCch(strPath, pstrName, MAX_PATH); 00268 if(pstrTextureType != NULL) { 00269 if(strcmpi(pstrTextureType, "volume") == 0) { 00270 LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL; 00271 if(SUCCEEDED(hr = D3DXCreateVolumeTextureFromFileEx(m_pd3dDevice, strPath, 00272 Width, Height, Depth, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, 00273 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &pVolumeTex))) { 00274 pTex = pVolumeTex; 00275 } 00276 else { 00277 m_strErrors += "Could not load volume texture "; 00278 m_strErrors += pstrName; 00279 } 00280 } 00281 else if(strcmpi(pstrTextureType, "cube") == 0) { 00282 LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL; 00283 if(SUCCEEDED(hr = D3DXCreateCubeTextureFromFileEx(m_pd3dDevice, strPath, 00284 Width, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, 00285 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &pCubeTex))) { 00286 pTex = pCubeTex; 00287 } 00288 else { 00289 m_strErrors += "Could not load cube texture "; 00290 m_strErrors += pstrName; 00291 } 00292 } 00293 } 00294 else { 00295 LPDIRECT3DTEXTURE9 p2DTex = NULL; 00296 if(SUCCEEDED(hr = D3DXCreateTextureFromFileEx(m_pd3dDevice, strPath, 00297 Width, Height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, 00298 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &p2DTex))) { 00299 pTex = p2DTex; 00300 } 00301 else { 00302 m_strErrors += "Could not load texture "; 00303 m_strErrors += pstrName; 00304 m_strErrors += "\n"; 00305 } 00306 } 00307 00308 // Apply successfully loaded texture to effect 00309 if(SUCCEEDED(hr) && pTex != NULL) { 00310 m_pEffect->SetTexture(m_pEffect->GetParameter(NULL, iParam), pTex); 00311 SAFE_RELEASE(pTex); 00312 } 00313 } 00314 else */ 00315 if(pstrFunction != NULL) { 00316 LPD3DXBUFFER pTextureShader = NULL; 00317 LPD3DXBUFFER lpErrors = 0; 00318 00319 if(pstrTarget == NULL || strcmp(pstrTarget,"tx_1_1")) 00320 pstrTarget = "tx_1_0"; 00321 00322 if(SUCCEEDED(hr = lpEffectCompiler->CompileShader( 00323 pstrFunction, pstrTarget, 00324 0, &pTextureShader, &lpErrors, NULL))) { 00325 SAFE_RELEASE(lpErrors); 00326 00327 if((UINT)Width == D3DX_DEFAULT) 00328 Width = 64; 00329 if((UINT)Height == D3DX_DEFAULT) 00330 Height = 64; 00331 if((UINT)Depth == D3DX_DEFAULT) 00332 Depth = 64; 00333 00334 #if D3DX_SDK_VERSION >= 22 00335 LPD3DXTEXTURESHADER ppTextureShader; 00336 D3DXCreateTextureShader((DWORD *)pTextureShader->GetBufferPointer(), &ppTextureShader); 00337 #endif 00338 00339 if(pstrTextureType != NULL) { 00340 if(strcmpi(pstrTextureType, "volume") == 0) { 00341 LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL; 00342 if(SUCCEEDED(hr = D3DXCreateVolumeTexture(m_pd3dDevice, 00343 Width, Height, Depth, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pVolumeTex))) { 00344 #if D3DX_SDK_VERSION >= 22 00345 if(SUCCEEDED(hr = D3DXFillVolumeTextureTX(pVolumeTex, ppTextureShader))) { 00346 #else 00347 if(SUCCEEDED(hr = D3DXFillVolumeTextureTX(pVolumeTex, 00348 (DWORD *)pTextureShader->GetBufferPointer(), NULL, 0))) { 00349 #endif 00350 pTex = pVolumeTex; 00351 } 00352 } 00353 } else if(strcmpi(pstrTextureType, "cube") == 0) { 00354 LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL; 00355 if(SUCCEEDED(hr = D3DXCreateCubeTexture(m_pd3dDevice, 00356 Width, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pCubeTex))) { 00357 #if D3DX_SDK_VERSION >= 22 00358 if(SUCCEEDED(hr = D3DXFillCubeTextureTX(pCubeTex, ppTextureShader))) { 00359 #else 00360 if(SUCCEEDED(hr = D3DXFillCubeTextureTX(pCubeTex, 00361 (DWORD *)pTextureShader->GetBufferPointer(), NULL, 0))) { 00362 #endif 00363 pTex = pCubeTex; 00364 } 00365 } 00366 } 00367 } else { 00368 LPDIRECT3DTEXTURE9 p2DTex = NULL; 00369 if(SUCCEEDED(hr = D3DXCreateTexture(m_pd3dDevice, Width, Height, 00370 D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &p2DTex))) { 00371 #if D3DX_SDK_VERSION >= 22 00372 if(SUCCEEDED(hr = D3DXFillTextureTX(p2DTex, ppTextureShader))) { 00373 #else 00374 if(SUCCEEDED(hr = D3DXFillTextureTX(p2DTex, 00375 (DWORD *)pTextureShader->GetBufferPointer(), NULL, 0))) { 00376 #endif 00377 pTex = p2DTex; 00378 } 00379 } 00380 } 00381 m_pEffect->SetTexture(m_pEffect->GetParameter(NULL, iParam), pTex); 00382 SAFE_RELEASE(pTex); 00383 SAFE_RELEASE(pTextureShader); 00384 #if D3DX_SDK_VERSION >= 22 00385 SAFE_RELEASE(ppTextureShader); 00386 #endif 00387 } else { 00388 if(lpErrors) { 00389 m_strErrors += (char*) lpErrors->GetBufferPointer(); 00390 } 00391 00392 m_strErrors += "Could not compile texture shader "; 00393 m_strErrors += pstrFunction; 00394 00395 SAFE_RELEASE(lpErrors); 00396 return hr; 00397 } 00398 } 00399 } 00400 00401 return S_OK; 00402 } 00403 00404 // Set Source texture 00405 HRESULT ScalingEffect::SetTextures(LPDIRECT3DTEXTURE9 lpSource, LPDIRECT3DTEXTURE9 lpWorking1, 00406 LPDIRECT3DTEXTURE9 lpWorking2, LPDIRECT3DVOLUMETEXTURE9 lpHq2xLookupTexture) 00407 { 00408 if(!m_SourceTextureEffectHandle) { 00409 m_strErrors += "Texture with SOURCETEXTURE semantic not found"; 00410 return E_FAIL; 00411 } 00412 00413 HRESULT hr = m_pEffect->SetTexture(m_SourceTextureEffectHandle, lpSource); 00414 00415 if(FAILED(hr)) { 00416 m_strErrors += "Unable to set SOURCETEXTURE"; 00417 return hr; 00418 } 00419 00420 if(m_WorkingTexture1EffectHandle) { 00421 hr = m_pEffect->SetTexture(m_WorkingTexture1EffectHandle, lpWorking1); 00422 00423 if(FAILED(hr)) { 00424 m_strErrors += "Unable to set WORKINGTEXTURE"; 00425 return hr; 00426 } 00427 } 00428 00429 if(m_WorkingTexture2EffectHandle) { 00430 hr = m_pEffect->SetTexture(m_WorkingTexture2EffectHandle, lpWorking2); 00431 00432 if(FAILED(hr)) { 00433 m_strErrors += "Unable to set WORKINGTEXTURE1"; 00434 return hr; 00435 } 00436 } 00437 00438 if(m_Hq2xLookupTextureHandle) { 00439 hr = m_pEffect->SetTexture(m_Hq2xLookupTextureHandle, lpHq2xLookupTexture); 00440 00441 if(FAILED(hr)) { 00442 m_strErrors += "Unable to set HQ2XLOOKUPTEXTURE"; 00443 return hr; 00444 } 00445 } 00446 00447 D3DXVECTOR4 fDims(256,256,1,1), fTexelSize(1,1,1,1); 00448 00449 if(lpSource) { 00450 D3DSURFACE_DESC Desc; 00451 lpSource->GetLevelDesc(0, &Desc); 00452 fDims[0] = (FLOAT) Desc.Width; 00453 fDims[1] = (FLOAT) Desc.Height; 00454 } 00455 00456 fTexelSize[0] = (FLOAT)(1.0/fDims[0]); 00457 fTexelSize[1] = (FLOAT)(1.0/fDims[1]); 00458 00459 if(m_SourceDimsEffectHandle) { 00460 hr = m_pEffect->SetVector(m_SourceDimsEffectHandle, &fDims); 00461 00462 if(FAILED(hr)) { 00463 m_strErrors += "Unable to set SOURCEDIMS"; 00464 return hr; 00465 } 00466 } 00467 00468 if(m_TexelSizeEffectHandle) { 00469 hr = m_pEffect->SetVector(m_TexelSizeEffectHandle, &fTexelSize); 00470 00471 if(FAILED(hr)) { 00472 m_strErrors += "Unable to set TEXELSIZE"; 00473 return hr; 00474 } 00475 } 00476 00477 return hr; 00478 } 00479 00480 // Set the Matrices for this frame 00481 HRESULT ScalingEffect::SetMatrices(D3DXMATRIX &matProj, D3DXMATRIX &matView, D3DXMATRIX &matWorld) 00482 { 00483 HRESULT hr = S_OK; 00484 00485 if(m_MatWorldEffectHandle != NULL) { 00486 hr = m_pEffect->SetMatrix(m_MatWorldEffectHandle, &matWorld); 00487 if(FAILED(hr)) { 00488 m_strErrors += "Unable to set WORLD matrix"; 00489 return hr; 00490 } 00491 } 00492 00493 if(m_MatViewEffectHandle != NULL) { 00494 hr = m_pEffect->SetMatrix(m_MatViewEffectHandle, &matView); 00495 if(FAILED(hr)) { 00496 m_strErrors += "Unable to set VIEW matrix"; 00497 return hr; 00498 } 00499 } 00500 00501 if(m_MatProjEffectHandle != NULL) { 00502 hr = m_pEffect->SetMatrix(m_MatProjEffectHandle, &matProj); 00503 if(FAILED(hr)) { 00504 m_strErrors += "Unable to set PROJECTION matrix"; 00505 return hr; 00506 } 00507 } 00508 00509 if(m_MatWorldViewEffectHandle != NULL) { 00510 D3DXMATRIX matWorldView = matWorld * matView; 00511 hr = m_pEffect->SetMatrix(m_MatWorldViewEffectHandle, &matWorldView); 00512 if(FAILED(hr)) { 00513 m_strErrors += "Unable to set WORLDVIEW matrix"; 00514 return hr; 00515 } 00516 } 00517 00518 if(m_MatViewProjEffectHandle != NULL) { 00519 D3DXMATRIX matViewProj = matView * matProj; 00520 hr = m_pEffect->SetMatrix(m_MatViewProjEffectHandle, &matViewProj); 00521 if(FAILED(hr)) { 00522 m_strErrors += "Unable to set VIEWPROJECTION matrix"; 00523 return hr; 00524 } 00525 } 00526 00527 if(m_MatWorldViewProjEffectHandle != NULL) { 00528 D3DXMATRIX matWorldViewProj = matWorld * matView * matProj; 00529 hr = m_pEffect->SetMatrix(m_MatWorldViewProjEffectHandle, &matWorldViewProj); 00530 if(FAILED(hr)) { 00531 m_strErrors += "Unable to set WORLDVIEWPROJECTION matrix"; 00532 return hr; 00533 } 00534 } 00535 00536 return hr; 00537 } 00538 00539 00540 // Returns Number of passes for this technique 00541 HRESULT ScalingEffect::Begin(Pass pass, UINT* pPasses) 00542 { 00543 HRESULT hr = S_OK; 00544 00545 switch (pass) { 00546 case Preprocess1: 00547 hr = m_pEffect->SetTechnique(m_PreprocessTechnique1EffectHandle); 00548 break; 00549 case Preprocess2: 00550 hr = m_pEffect->SetTechnique(m_PreprocessTechnique2EffectHandle); 00551 break; 00552 case Combine: 00553 hr = m_pEffect->SetTechnique(m_CombineTechniqueEffectHandle); 00554 break; 00555 } 00556 00557 if(FAILED(hr)) { 00558 m_strErrors += "SetTechnique failed"; 00559 return E_FAIL; 00560 } 00561 00562 return m_pEffect->Begin(pPasses, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE); 00563 } 00564 00565 // Render Pass in technique 00566 HRESULT ScalingEffect::BeginPass(UINT Pass) 00567 { 00568 #if D3DX_SDK_VERSION >= 22 00569 return m_pEffect->BeginPass(Pass); 00570 #else 00571 return m_pEffect->Pass(Pass); 00572 #endif 00573 } 00574 00575 // End Pass of this technique 00576 HRESULT ScalingEffect::EndPass() 00577 { 00578 #if D3DX_SDK_VERSION >= 22 00579 return m_pEffect->EndPass(); 00580 #else 00581 return S_OK; 00582 #endif 00583 } 00584 00585 // End rendering of this technique 00586 HRESULT ScalingEffect::End() 00587 { 00588 return m_pEffect->End(); 00589 } 00590 00591 // Validates the effect 00592 HRESULT ScalingEffect::Validate() 00593 { 00594 HRESULT hr; 00595 00596 // Now we check to see if they all exist 00597 if(!m_MatWorldEffectHandle || !m_MatWorldViewEffectHandle || 00598 !m_MatWorldViewProjEffectHandle) { 00599 m_strErrors += "Effect doesn't have any world matrix handles"; 00600 return E_FAIL; 00601 } 00602 00603 if(!m_MatViewEffectHandle || !m_MatWorldViewEffectHandle || 00604 !m_MatViewProjEffectHandle || !m_MatWorldViewProjEffectHandle) { 00605 m_strErrors += "Effect doesn't have any view matrix handles"; 00606 return E_FAIL; 00607 } 00608 00609 if(!m_MatProjEffectHandle || !m_MatViewProjEffectHandle || 00610 !m_MatWorldViewProjEffectHandle) { 00611 m_strErrors += "Effect doesn't have any projection matrix handles"; 00612 return E_FAIL; 00613 } 00614 00615 if(!m_SourceTextureEffectHandle) { 00616 m_strErrors += "Effect doesn't have a SOURCETEXTURE handle"; 00617 return E_FAIL; 00618 } 00619 00620 if(!m_CombineTechniqueEffectHandle) { 00621 m_strErrors += "Effect doesn't have a COMBINETECHNIQUE handle"; 00622 return E_FAIL; 00623 } 00624 00625 if(!m_WorkingTexture1EffectHandle && m_PreprocessTechnique1EffectHandle) { 00626 m_strErrors += "Effect doesn't have a WORKINGTEXTURE handle but uses preprocess steps"; 00627 return E_FAIL; 00628 } 00629 00630 if(!m_WorkingTexture2EffectHandle && m_PreprocessTechnique2EffectHandle) { 00631 m_strErrors += "Effect doesn't have a WORKINGTEXTURE1 handle but uses 2 preprocess steps"; 00632 return E_FAIL; 00633 } 00634 00635 // Validate this 00636 if(m_PreprocessTechnique1EffectHandle) { 00637 hr = m_pEffect->ValidateTechnique(m_PreprocessTechnique1EffectHandle); 00638 00639 if(FAILED(hr)) { 00640 m_strErrors += "ValidateTechnique for PREPROCESSTECHNIQUE failed"; 00641 return hr; 00642 } 00643 } 00644 00645 if(m_PreprocessTechnique2EffectHandle) { 00646 hr = m_pEffect->ValidateTechnique(m_PreprocessTechnique2EffectHandle); 00647 00648 if(FAILED(hr)) { 00649 m_strErrors += "ValidateTechnique for PREPROCESSTECHNIQUE1 failed"; 00650 return hr; 00651 } 00652 } 00653 00654 hr = m_pEffect->ValidateTechnique(m_CombineTechniqueEffectHandle); 00655 00656 if(FAILED(hr)) { 00657 m_strErrors += "ValidateTechnique for COMBINETECHNIQUE failed"; 00658 return hr; 00659 } 00660 00661 return S_OK; 00662 } 00663 00664 #endif // C_D3DSHADERS