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

Render.cpp File Reference

#include <Windows.h>
#include <stdio.h>
#include "D3DDrv7x.h"
#include "DCommon.h"
#include "Render.h"
#include "Scene.h"
#include "GSpan.h"
#include "D3D_Fx.h"
#include "D3DCache.h"
#include "D3D_Err.h"
#include "THandle.h"
#include "PCache.h"

Go to the source code of this file.

Defines

#define SNAP_VERT(v)   ( ( v ) = ( float )( ( long )( ( v ) * 16 ) ) / 16.0f )

Functions

geBoolean DRIVERCC RenderGouraudPoly (DRV_TLVertex *Pnts, int32 NumPoints, uint32 Flags)
geBoolean DRIVERCC RenderWorldPoly (DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, DRV_TexInfo *TexInfo, DRV_LInfo *LInfo, uint32 Flags)
geBoolean DRIVERCC RenderMiscTexturePoly (DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, uint32 Flags)
geBoolean DRIVERCC DrawDecal (geRDriver_THandle *THandle, RECT *SRect, int32 x, int32 y)


Define Documentation

#define SNAP_VERT v   )     ( ( v ) = ( float )( ( long )( ( v ) * 16 ) ) / 16.0f )
 

Definition at line 46 of file D3D7xDrv/Render.cpp.

Referenced by Render_GouraudPoly(), Render_LinesPoly(), Render_MiscTexturePoly(), and Render_WorldPoly().


Function Documentation

geBoolean DRIVERCC DrawDecal geRDriver_THandle THandle,
RECT SRect,
int32  x,
int32  y
 

Definition at line 248 of file D3D7xDrv/Render.cpp.

00249 {
00250         RECT    SRect2, *pSRect;
00251         int32   Width, Height;
00252         HRESULT ddrval;
00253 
00254         if(!AppInfo.RenderingIsOK)
00255                 return  TRUE;
00256 
00257         if (!SRect)
00258         {
00259                 SRect2.left = 0;
00260                 SRect2.right = THandle->Width;
00261                 SRect2.top = 0;
00262                 SRect2.bottom = THandle->Height;
00263                 pSRect = &SRect2;
00264                 Width = (THandle->Width);
00265                 Height = (THandle->Height);
00266         }
00267         else
00268         {
00269                 pSRect = SRect;
00270                 Width = (pSRect->right - pSRect->left)+1;
00271                 Height = (pSRect->bottom - pSRect->top)+1;
00272         }
00273         
00274         if (x + Width <= 0)
00275                 return TRUE;
00276         if (y + Height <= 0)
00277                 return TRUE;
00278 
00279         if (x >= ClientWindow.Width)
00280                 return TRUE;
00281         
00282         if (y >= ClientWindow.Height)
00283                 return TRUE;
00284         
00285         if (x + Width >= (ClientWindow.Width-1))
00286                 pSRect->right -= ((x + Width) - (ClientWindow.Width-1));
00287         if (y + Height >= (ClientWindow.Height-1))
00288                 pSRect->bottom -= ((y + Height) - (ClientWindow.Height-1));
00289 
00290         if (x < 0)
00291         {
00292                 pSRect->left += -x;
00293                 x=0;
00294         }
00295         if (y < 0)
00296         {
00297                 pSRect->top += -y;
00298                 y=0;
00299         }
00300         
00301 #if 0
00302 
00303 /*      01/24/2002 Wendell Buckner
00304     Change flags for speed...
00305         AppInfo.lpBackBuffer->BltFast(x, y, THandle->MipData[0].Surface, pSRect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);*/
00306     AppInfo.lpBackBuffer->BltFast(x, y, THandle->MipData[0].Surface, pSRect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DONOTWAIT ); 
00307     
00308 #else
00309         RECT    DRect;
00310 
00311         Width = (pSRect->right - pSRect->left);
00312         Height = (pSRect->bottom - pSRect->top);
00313 
00314         DRect.left = x;
00315         DRect.right = x+Width;
00316         DRect.top = y;
00317         DRect.bottom = y+Height;
00318 
00319 /*      01/24/2002 Wendell Buckner
00320     Change flags for speed...
00321     ddrval= AppInfo.lpBackBuffer->Blt(&DRect, THandle->MipData[0].Surface, pSRect, 
00322                              (DDBLT_KEYSRC | DDBLT_WAIT), NULL);*/
00323         ddrval= AppInfo.lpBackBuffer->Blt(&DRect, THandle->MipData[0].Surface, pSRect, 
00324                              (DDBLT_KEYSRC | DDBLT_DONOTWAIT | DDBLT_ASYNC ), NULL);    
00325 
00326         if(ddrval==DDERR_SURFACELOST)
00327         {
00328                 if (!D3DMain_RestoreAllSurfaces())
00329                         return  GE_FALSE;
00330         }
00331         //AppInfo.lpBackBuffer->Blt(&DRect, Decals[Handle].Surface, pSRect, (DDBLT_WAIT), NULL);
00332 #endif
00333 
00334         return GE_TRUE;
00335 }

geBoolean DRIVERCC RenderGouraudPoly DRV_TLVertex Pnts,
int32  NumPoints,
uint32  Flags
 

Definition at line 48 of file D3D7xDrv/Render.cpp.

00049 {
00050         int32                   i;
00051         DRV_TLVertex    *pPnts;
00052         D3DTLVERTEX             D3DPnts[30], *pD3DPnts;
00053         float                   ZRecip;
00054         float                   Alpha;
00055 
00056         if(!AppInfo.RenderingIsOK)
00057                 return  TRUE;
00058 
00059         if (Flags & DRV_RENDER_FLUSH)
00060         {
00061                 if (!PCache_FlushWorldPolys())
00062                         return FALSE;
00063                 if (!PCache_FlushMiscPolys())
00064                         return FALSE;
00065         }
00066 
00067         Alpha = Pnts->a;
00068         
00069         D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
00070 
00071         D3DSetTexture(0, NULL);
00072         
00073         int32 SAlpha = (int32)Alpha<<24;
00074         pPnts = Pnts;
00075         pD3DPnts = D3DPnts;
00076         for (i=0; i< NumPoints; i++)
00077         {
00078                 ZRecip = 1/pPnts->z;
00079 
00080                 pD3DPnts->sx = pPnts->x;
00081                 pD3DPnts->sy = pPnts->y;
00082                 pD3DPnts->sz = (1.0f - ZRecip);         // ZBUFFER
00083                 pD3DPnts->rhw = ZRecip;
00084                 pD3DPnts->color = SAlpha | ((int32)pPnts->r<<16) | ((int32)pPnts->g<<8) | (int32)pPnts->b;
00085 
00086                 if (AppInfo.FogEnable && !(Flags & DRV_RENDER_POLY_NO_FOG)) // poly fog
00087                 {
00088                         DWORD   FogVal;
00089                         float   Val;
00090 
00091                         Val = pPnts->z;
00092 
00093                         if (Val > AppInfo.FogEnd)
00094                                 Val = AppInfo.FogEnd;
00095 
00096                         FogVal = (DWORD)((AppInfo.FogEnd-Val)/(AppInfo.FogEnd-AppInfo.FogStart)*255.0f);
00097                 
00098                         if (FogVal < 0)
00099                                 FogVal = 0;
00100                         else if (FogVal > 255)
00101                                 FogVal = 255;
00102                 
00103                         pD3DPnts->specular = (FogVal<<24);              // Alpha component in specular is the fog value (0...255)
00104                 }
00105                 else
00106                         pD3DPnts->specular = 0;
00107 
00108                 pPnts++;
00109                 pD3DPnts++;
00110         }
00111 
00112         D3DTexturedPolyOld(D3DPnts, NumPoints);
00113 
00114         if (Flags & DRV_RENDER_FLUSH)
00115         {
00116 /* 02/28/2001 Wendell Buckner
00117    These render states are unsupported d3d 7.0 
00118             AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);*/
00119                 AppInfo.lpD3DDevice->EndScene();
00120                 AppInfo.lpD3DDevice->BeginScene();
00121         }
00122 
00123         return TRUE;
00124 }

geBoolean DRIVERCC RenderMiscTexturePoly DRV_TLVertex Pnts,
int32  NumPoints,
geRDriver_THandle THandle,
uint32  Flags
 

Definition at line 227 of file D3D7xDrv/Render.cpp.

00228 {
00229         if(!AppInfo.RenderingIsOK)
00230         {
00231                 return  TRUE;
00232         }
00233         else if (Flags & DRV_RENDER_FLUSH)
00234         {
00235                 PCache_FlushMiscPolys();
00236         }
00237                                 
00238         PCache_InsertMiscPoly(Pnts, NumPoints, THandle, Flags);
00239 
00240         if (Flags & DRV_RENDER_FLUSH)
00241         {
00242                 PCache_FlushMiscPolys();
00243         }
00244 
00245         return TRUE;
00246 }

geBoolean DRIVERCC RenderWorldPoly DRV_TLVertex Pnts,
int32  NumPoints,
geRDriver_THandle THandle,
DRV_TexInfo TexInfo,
DRV_LInfo LInfo,
uint32  Flags
 

Definition at line 126 of file D3D7xDrv/Render.cpp.

00127 {
00128 #ifdef USE_SPANS
00129         int32                   i;
00130         DRV_TLVertex    *CPnt;
00131         int32                   OldPixels;
00132         int32                   Mip = 0;
00133         int32                   MinY, MaxY, MinX, MaxX;
00134         int32                   FirstX, FirstY, x1, y1, x2, y2;
00135         SPAN                    *pSpans;
00136         int32                   WidthHeight;
00137 #endif
00138         
00139         if(!AppInfo.RenderingIsOK)
00140         {
00141                 return  TRUE;
00142         }
00143         else if (Flags & DRV_RENDER_FLUSH)
00144         {
00145                 if (!PCache_FlushWorldPolys())
00146                         return FALSE;
00147         }
00148 
00149 #ifdef USE_SPANS
00150         if (RenderMode != RENDER_WORLD)
00151                 goto NotWorld;
00152         
00153         CPnt = Pnts;                                            // Set to the first points in the array 
00154 
00155         x1 = (int32)CPnt->x;
00156         y1 = (int32)CPnt->y;
00157 
00158         FirstX = MinX = MaxX = x1;
00159         FirstY = MinY = MaxY = y1;
00160 
00161         for (i = 1; i < NumPoints; i++)
00162         {
00163                 CPnt++;
00164 
00165                 x2 = (int32)CPnt->x;
00166                 y2 = (int32)CPnt->y;
00167 
00168                 EdgeOutNoUV (x1, y1, x2, y2);
00169 
00170                 if (x2 > MaxX) 
00171                         MaxX = x2;
00172                 else if (x2 < MinX) 
00173                         MinX = x2;
00174         
00175                 if (y2 > MaxY) 
00176                         MaxY = y2;
00177                 else if (y2 < MinY) 
00178                         MinY = y2;
00179 
00180                 // Swap
00181                 x1 = x2;
00182                 y1 = y2;
00183         }
00184 
00185         // Close the poly
00186         EdgeOutNoUV (x1, y1, FirstX, FirstY);
00187 
00188         OldPixels = NumWorldPixels;
00189         
00190         pSpans = &SpanLines[MinY];
00191 
00192         WidthHeight = ClientWindow.Width*ClientWindow.Height;
00193         for (i = MinY; i <= MaxY; i++, pSpans++)
00194         {
00195                 AddSpanNoUV(pSpans->x1, pSpans->x2, i);
00196 
00197                 if (NumWorldPixels >= WidthHeight)
00198                         break;
00199         }
00200 
00201         if ((MaxY - MinY) < 3)
00202                 goto NotWorld;
00203 
00204         if ((MaxX - MinX) < 3)
00205                 goto NotWorld;
00206 
00207         if (NumWorldPixels == OldPixels)
00208                 return TRUE;
00209 
00210         NotWorld:;
00211 #endif
00212         
00213         D3DDRV.NumRenderedPolys++;
00214         
00215         // Insert the poly into the world cache, for later rendering
00216         PCache_InsertWorldPoly(Pnts, NumPoints, THandle, TexInfo, LInfo, Flags);
00217 
00218         if (Flags & DRV_RENDER_FLUSH)
00219         {
00220                 if (!PCache_FlushWorldPolys())
00221                         return FALSE;
00222         }
00223 
00224         return TRUE;
00225 }


Generated on Tue Sep 30 12:38:01 2003 for GTestAndEngine by doxygen 1.3.2