Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

D3d_fx.cpp

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  D3D_Fx.cpp                                                                          */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: D3D renderstate wrapper                                                */
00006 /*                                                                                      */
00007 /*  02/28/2001 Wendell Buckner                                                          */
00008 /*   The flags at the end of DrawPrimitive are no longer supported in  d3d 7.0, use the */
00009 /*   combination of flags in the renderstate call                                       */
00010 /*   Optimization from GeForce_Optimization2.doc                                        */
00011 /*    9. Do not duplicate render state commands.  Worse is useless renderstates.        */ 
00012 /*       Do not set a renderstate unless it is needed.                                  */ 
00013 /*   These render states are unsupported d3d 7.0                                        */
00014 /*  07/16/2000 Wendell Buckner                                                          */
00015 /*    Convert to Directx7...                                                            */
00016 /*                                                                                      */
00017 /*  The contents of this file are subject to the Genesis3D Public License               */
00018 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00019 /*  compliance with the License. You may obtain a copy of the License at                */
00020 /*  http://www.genesis3d.com                                                            */
00021 /*                                                                                      */
00022 /*  Software distributed under the License is distributed on an "AS IS"                 */
00023 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00024 /*  the License for the specific language governing rights and limitations              */
00025 /*  under the License.                                                                  */
00026 /*                                                                                      */
00027 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00028 /*Genesis3D Version 1.1 released November 15, 1999                            */
00029 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00030 /*                                                                                      */
00031 /****************************************************************************************/
00032 #include <Windows.h>
00033 #include <stdio.h>
00034 #include <DDraw.h>
00035 #include <D3D.h>
00036 
00037 /*  07/16/2000 Wendell Buckner       
00038 /*    Convert to Directx7...         
00039 #include "D3DDrv.h"                */
00040 #include "D3DDrv7x.h"
00041 
00042 #include "DCommon.h"
00043 #include "Render.h"
00044 #include "Scene.h"
00045 #include "D3D_FX.h"
00046 #include "D3D_Main.h"
00047 #include "D3D_Err.h"
00048 
00049 static D3DTEXTUREHANDLE OldTexHandle = NULL;
00050 
00051 //======================================================================================================
00052 //======================================================================================================
00053 void D3DSetTexHandle(D3DTEXTUREHANDLE TexHandle)
00054 {
00055         if (TexHandle == OldTexHandle)
00056                 return;
00057 
00058         OldTexHandle = TexHandle;
00059 
00060 /* 02/28/2001 Wendell Buckner
00061    These render states are unsupported d3d 7.0
00062         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, TexHandle);*/
00063 }
00064 
00065 /*   07/16/2000 Wendell Buckner
00066 /*    Convert to Directx7...    
00067 static LPDIRECT3DTEXTURE2    OldTexture[8];*/
00068 static LPDIRECTDRAWSURFACE7  OldTexture[8];     
00069 
00070 
00071 //======================================================================================================
00072 //======================================================================================================
00073 
00074 /*   07/16/2000 Wendell Buckner
00075 /*    Convert to Directx7...    
00076 void D3DSetTexture(int32 Stage, LPDIRECT3DTEXTURE2   Texture)  */
00077 void D3DSetTexture(int32 Stage, LPDIRECTDRAWSURFACE7 Texture)
00078 
00079 {
00080         if (Texture == OldTexture[Stage])
00081                 return;
00082 
00083         OldTexture[Stage] = Texture;
00084 
00085         AppInfo.lpD3DDevice->SetTexture(Stage, Texture);
00086 }
00087                 
00088 //======================================================================================================
00089 //======================================================================================================
00090 void D3DBilinearFilter(D3DTEXTUREFILTER Min, D3DTEXTUREFILTER Mag)
00091 {
00092         AppInfo.lpD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR);
00093         AppInfo.lpD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
00094 
00095         if (AppInfo.CanDoMultiTexture)
00096         {
00097                 AppInfo.lpD3DDevice->SetTextureStageState(1, D3DTSS_MINFILTER, D3DTFN_LINEAR);
00098                 AppInfo.lpD3DDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
00099         }
00100 }
00101 
00102 //======================================================================================================
00103 // Old one uses D3DTLVERTEX vertex format
00104 //======================================================================================================
00105 void D3DTexturedPolyOld(void *Pnts, int32 NumPoints)
00106 {
00107 /* 02/28/2001 Wendell Buckner
00108    The flags at the end of DrawPrimitive are no longer supported in  d3d 7.0, use the combination of flags in 
00109    the renderstate call */
00110         HRESULT Hr;
00111 
00112 /*      02/08/2002 Wendell Buckner
00113     Optimization from GeForce_Optimization2.doc
00114     9.  Do not duplicate render state commands.  Worse is useless renderstates.  Do not set a renderstate unless it is needed. 
00115         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,FALSE);
00116         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
00117         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_EXTENTS,FALSE);                                                        
00118         AppInfo.lpD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX, Pnts, NumPoints, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP);*/
00119         Hr = AppInfo.lpD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX, Pnts, NumPoints, NULL);
00120         if( Hr != DD_OK ) D3DMain_Log("D3DTExturedPolOld failed...\n\n");
00121 }       
00122 
00123 //======================================================================================================
00124 //      D3DTexturedPoly
00125 //======================================================================================================
00126 void D3DTexturedPoly(void *Pnts, int32 NumPoints)
00127 {
00128 /* 02/28/2001 Wendell Buckner
00129    The flags at the end of DrawPrimitive are no longer supported in  d3d 7.0, use the combination of flags in 
00130    the renderstate call */
00131         HRESULT Hr;
00132 
00133 /*      02/08/2002 Wendell Buckner
00134     Optimization from GeForce_Optimization2.doc
00135     9.  Do not duplicate render state commands.  Worse is useless renderstates.  Do not set a renderstate unless it is needed. 
00136         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,FALSE);
00137         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
00138         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_EXTENTS,FALSE);
00139         AppInfo.lpD3DDevice->DrawPrimitive(     D3DPT_TRIANGLEFAN, 
00140                                                                                 //D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2, 
00141                                                                                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2, 
00142                                                                                 Pnts, 
00143                                                                                 NumPoints, 
00144                                                                                 D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP);
00145                                                                                 //D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTCLIP);*/
00146         Hr = AppInfo.lpD3DDevice->DrawPrimitive(        D3DPT_TRIANGLEFAN, 
00147                                                                                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2, 
00148                                                                                 Pnts, 
00149                                                                                 NumPoints, 
00150                                                                                 NULL);
00151 
00152         if( Hr != DD_OK ) D3DMain_Log("D3DTexturedPoly failed...\n\n");
00153 }       
00154 
00155 //======================================================================================================
00156 //      D3DViewport
00157 //======================================================================================================
00158 void D3DViewport (int32 x, int32 y, int32 width, int32 height)
00159 {
00160 /*   07/16/2000 Wendell Buckner
00161 /*    Convert to Directx7...    
00162         D3DVIEWPORT2 vport;         */ 
00163         D3DVIEWPORT7 vport;
00164 
00165 //03/01/2002 Wendell Buckner    
00166 //This wasn't commented in the original code but it was in my genesis 1.0 converted code...
00167 //not sure I should do this.
00168 //      return;
00169 //
00170 //  vport.dwSize = sizeof(D3DVIEWPORT2);
00171 
00172 /*   07/16/2000 Wendell Buckner
00173 /*    Convert to Directx7...    
00174     AppInfo.lpD3DViewport->GetViewport2(&vport); */
00175     AppInfo.lpD3DDevice->GetViewport(&vport);
00176 
00177     vport.dwX = x;
00178     vport.dwY = AppInfo.OldHeight - (y + height);
00179     vport.dwWidth = width;
00180     vport.dwHeight = height;
00181 
00182 /*  07/16/2000 Wendell Buckner
00183     Convert to Directx7...    
00184     vport.dvClipX = -1.0f;
00185     vport.dvClipY = 1.0f;
00186     vport.dvClipWidth = (float)width /2.0f;
00187     vport.dvClipHeight = (float)height/2.0f;*/
00188 
00189 /*   07/16/2000 Wendell Buckner
00190 /*    Convert to Directx7...        
00191     AppInfo.lpD3DViewport->SetViewport2(&vport); */
00192         AppInfo.lpD3DDevice->SetViewport(&vport);
00193 }
00194 
00195 //======================================================================================================
00196 //======================================================================================================
00197 void D3DDepthRange (float zNear, float zFar)
00198 {
00199 /*   07/16/2000 Wendell Buckner
00200 /*    Convert to Directx7...         
00201     D3DVIEWPORT2 vport;*/
00202         D3DVIEWPORT7 vport;
00203 
00204 //03/01/2002 Wendell Buckner    
00205 //This wasn't commented in the original code but it was in my genesis 1.0 converted code...
00206 //not sure I should do this.
00207 //  vport.dwSize = sizeof(D3DVIEWPORT2);
00208 
00209 /*   07/16/2000 Wendell Buckner
00210 /*    Convert to Directx7...     
00211     AppInfo.lpD3DViewport->GetViewport2(&vport);*/
00212         AppInfo.lpD3DDevice->GetViewport(&vport);
00213 
00214 //03/01/2002 Wendell Buckner    
00215 //This wasn't commented in the original code but it was in my genesis 1.0 converted code...
00216 //not sure I should do this.
00217 //  vport.dvMinZ = (D3DVALUE)(((-1.0) * (zFar + zNear)) / (zFar - zNear));
00218 //  vport.dvMaxZ = (D3DVALUE)(((-1.0) * (zFar + zNear - 2.0)) / (zFar - zNear));
00219     vport.dvMinZ = zNear; 
00220     vport.dvMaxZ = zFar;  
00221 
00222 
00223 /*   07/16/2000 Wendell Buckner
00224 /*    Convert to Directx7...     
00225         AppInfo.lpD3DViewport->SetViewport2(&vport);*/
00226     AppInfo.lpD3DDevice->SetViewport(&vport);
00227     
00228 }
00229 
00230 static D3DBLEND OldSFunc = D3DBLEND_ONE;
00231 static D3DBLEND OldDFunc = D3DBLEND_ONE;
00232 
00233 //======================================================================================================
00234 //======================================================================================================
00235 void D3DBlendFunc (D3DBLEND SFunc, D3DBLEND DFunc)
00236 {
00237         if (SFunc != OldSFunc)
00238         {
00239                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, SFunc);
00240                 OldSFunc = SFunc;
00241         }
00242         if (DFunc != OldDFunc)
00243         {
00244                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, DFunc);
00245                 OldDFunc = DFunc;
00246         }
00247 
00248 }
00249 
00250 static BOOL OldBlend = FALSE;
00251 
00252 //======================================================================================================
00253 //======================================================================================================
00254 void D3DBlendEnable(BOOL Enable)
00255 {
00256         if (OldBlend == Enable)
00257                 return;
00258 
00259         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, Enable);
00260 
00261         OldBlend = Enable;
00262 }
00263 
00264 static BOOL OldWrap = FALSE;
00265 
00266 void D3DTexWrap(DWORD Stage, BOOL Wrap)
00267 {
00268         if (OldWrap == Wrap)
00269                 return;
00270 
00271         OldWrap = Wrap;
00272 
00273         if (Wrap)
00274         {
00275                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
00276                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
00277                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
00278         }
00279         else
00280         {
00281                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);
00282                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
00283                 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
00284         }
00285 }
00286 
00287 void D3DZWriteEnable (BOOL Enable)
00288 {
00289         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, Enable);
00290 }
00291 
00292 void D3DZFunc (D3DCMPFUNC Func)
00293 {
00294         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, Func);
00295 }
00296 
00297 void D3DZEnable(BOOL Enable)
00298 {
00299         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, Enable);
00300 }
00301 
00302 void D3DPolygonMode (D3DFILLMODE Mode)
00303 {
00304         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);
00305 }
00306 
00307 
00308 

Generated on Tue Sep 30 12:35:29 2003 for GTestAndEngine by doxygen 1.3.2