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

Render.cpp File Reference

#include <Windows.h>
#include <stdio.h>
#include "D3DDrv.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 ) = ( geFloat )( ( 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 ) = ( geFloat )( ( long )( ( v ) * 16 ) ) / 16.0f )
 

Definition at line 37 of file D3DDrv/Render.cpp.


Function Documentation

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

Definition at line 237 of file D3DDrv/Render.cpp.

References AppInfo, tagRECT::bottom, ClientWindow, D3DMain_RestoreAllSurfaces(), DRIVERCC, GE_FALSE, GE_TRUE, geBoolean, DRV_Window::Height, geRDriver_THandle::Height, int32, tagRECT::left, App_Info::lpBackBuffer, geRDriver_THandle::MipData, NULL, App_Info::RenderingIsOK, tagRECT::right, THandle_MipData::Surface, tagRECT::top, TRUE, DRV_Window::Width, geRDriver_THandle::Width, and y.

00238 {
00239         RECT    SRect2, *pSRect;
00240         int32   Width, Height;
00241         HRESULT ddrval;
00242 
00243         if(!AppInfo.RenderingIsOK)
00244                 return  TRUE;
00245 
00246         if (!SRect)
00247         {
00248                 SRect2.left = 0;
00249                 SRect2.right = THandle->Width;
00250                 SRect2.top = 0;
00251                 SRect2.bottom = THandle->Height;
00252                 pSRect = &SRect2;
00253                 Width = (THandle->Width);
00254                 Height = (THandle->Height);
00255         }
00256         else
00257         {
00258                 pSRect = SRect;
00259                 Width = (pSRect->right - pSRect->left)+1;
00260                 Height = (pSRect->bottom - pSRect->top)+1;
00261         }
00262         
00263         if (x + Width <= 0)
00264                 return TRUE;
00265         if (y + Height <= 0)
00266                 return TRUE;
00267 
00268         if (x >= ClientWindow.Width)
00269                 return TRUE;
00270         
00271         if (y >= ClientWindow.Height)
00272                 return TRUE;
00273         
00274         if (x + Width >= (ClientWindow.Width-1))
00275                 pSRect->right -= ((x + Width) - (ClientWindow.Width-1));
00276         if (y + Height >= (ClientWindow.Height-1))
00277                 pSRect->bottom -= ((y + Height) - (ClientWindow.Height-1));
00278 
00279         if (x < 0)
00280         {
00281                 pSRect->left += -x;
00282                 x=0;
00283         }
00284         if (y < 0)
00285         {
00286                 pSRect->top += -y;
00287                 y=0;
00288         }
00289         
00290 #if 0
00291         AppInfo.lpBackBuffer->BltFast(x, y, THandle->MipData[0].Surface, pSRect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
00292 #else
00293         RECT    DRect;
00294 
00295         Width = (pSRect->right - pSRect->left);
00296         Height = (pSRect->bottom - pSRect->top);
00297 
00298         DRect.left = x;
00299         DRect.right = x+Width;
00300         DRect.top = y;
00301         DRect.bottom = y+Height;
00302         
00303         ddrval= AppInfo.lpBackBuffer->Blt(&DRect, THandle->MipData[0].Surface, pSRect, 
00304                              (DDBLT_KEYSRC | DDBLT_WAIT), NULL);
00305 
00306         if(ddrval==DDERR_SURFACELOST)
00307         {
00308                 if (!D3DMain_RestoreAllSurfaces())
00309                         return  GE_FALSE;
00310         }
00311         //AppInfo.lpBackBuffer->Blt(&DRect, Decals[Handle].Surface, pSRect, (DDBLT_WAIT), NULL);
00312 #endif
00313 
00314         return GE_TRUE;
00315 }

geBoolean DRIVERCC RenderGouraudPoly DRV_TLVertex Pnts,
int32  NumPoints,
uint32  Flags
 

Definition at line 39 of file D3DDrv/Render.cpp.

References DRV_TLVertex::a, AppInfo, DRV_TLVertex::b, D3DBlendFunc(), D3DSetTexture(), D3DTexturedPolyOld(), DRIVERCC, DRV_RENDER_FLUSH, DRV_RENDER_POLY_NO_FOG, DWORD, FALSE, App_Info::FogEnable, App_Info::FogEnd, App_Info::FogStart, DRV_TLVertex::g, geBoolean, geFloat, int32, App_Info::lpD3DDevice, NULL, PCache_FlushMiscPolys(), PCache_FlushWorldPolys(), DRV_TLVertex::r, App_Info::RenderingIsOK, TRUE, DRV_TLVertex::x, DRV_TLVertex::y, and DRV_TLVertex::z.

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

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

Definition at line 216 of file D3DDrv/Render.cpp.

References AppInfo, DRIVERCC, DRV_RENDER_FLUSH, geBoolean, PCache_FlushMiscPolys(), PCache_InsertMiscPoly(), App_Info::RenderingIsOK, and TRUE.

00217 {
00218         if(!AppInfo.RenderingIsOK)
00219         {
00220                 return  TRUE;
00221         }
00222         else if (Flags & DRV_RENDER_FLUSH)
00223         {
00224                 PCache_FlushMiscPolys();
00225         }
00226                                 
00227         PCache_InsertMiscPoly(Pnts, NumPoints, THandle, Flags);
00228 
00229         if (Flags & DRV_RENDER_FLUSH)
00230         {
00231                 PCache_FlushMiscPolys();
00232         }
00233 
00234         return TRUE;
00235 }

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

Definition at line 115 of file D3DDrv/Render.cpp.

References AddSpanNoUV(), AppInfo, ClientWindow, D3DDRV, DRIVERCC, DRV_RENDER_FLUSH, EdgeOutNoUV(), FALSE, geBoolean, DRV_Window::Height, int32, DRV_Driver::NumRenderedPolys, NumWorldPixels, PCache_FlushWorldPolys(), PCache_InsertWorldPoly(), RENDER_WORLD, App_Info::RenderingIsOK, RenderMode, SpanLines, TRUE, DRV_Window::Width, DRV_TLVertex::x, SPAN::x1, SPAN::x2, and DRV_TLVertex::y.

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


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