00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Windows.h>
00023 #include <stdio.h>
00024 #include <assert.h>
00025
00026 #include "SoftDrv.h"
00027 #include "DCommon.h"
00028 #include "Render.h"
00029 #include "Scene.h"
00030 #include "Span.h"
00031 #include "System.h"
00032 #include "Sal.h"
00033 #include "dmodes.h"
00034
00035 S32 RenderMode = RENDER_NONE;
00036
00037 VidModeList *cmode=NULL;
00038
00039
00040 RECT WorldRect;
00041 RECT FrontRect;
00042 U16 FPUCW, OldFPUCW;
00043
00044 extern CPUInfo ProcessorInfo;
00045
00046 void SetFPU24(void)
00047 {
00048 _asm
00049 {
00050 fstcw [OldFPUCW] ; store copy of CW
00051 mov ax, OldFPUCW ; get it in ax
00052 and eax,0xFFFFFCFF
00053
00054 mov [FPUCW],ax ; store it
00055 fldcw [FPUCW] ; load the FPU
00056 }
00057 }
00058
00059 void RestoreFPU(void)
00060 {
00061 _asm fldcw [OldFPUCW] ; restore the FPU
00062 }
00063
00064 BOOL DRIVERCC BeginScene(BOOL Clear, BOOL ClearZ, RECT *pWorldRect)
00065 {
00066 if(ProcessorInfo.Has3DNow)
00067 {
00068 SetFPU24();
00069 }
00070
00071 if (RenderMode != RENDER_NONE)
00072 {
00073 SetLastDrvError(DRV_ERROR_GENERIC, "Still in some other render mode.");
00074 return FALSE;
00075 }
00076
00077 if(0 && pWorldRect)
00078 {
00079 WorldRect =*pWorldRect;
00080 WorldRect.right;
00081 WorldRect.bottom;
00082 }
00083 else
00084 {
00085 WorldRect.left =WorldRect.top =0;
00086 WorldRect.right =ClientWindow.Width - 1;
00087 WorldRect.bottom=ClientWindow.Height - 1;
00088 }
00089
00090 if(!bWindowed)
00091 {
00092 if(cmode->flags & STRETCHMODE)
00093 {
00094 geFloat xstrch, ystrch;
00095
00096 xstrch =640.0f / ((geFloat)ClientWindow.Width);
00097 ystrch =480.0f / ((geFloat)ClientWindow.Height);
00098 FrontRect.left =(int)(xstrch * (geFloat)WorldRect.left);
00099 FrontRect.right =(int)(xstrch * (geFloat)WorldRect.right);
00100 FrontRect.bottom=(int)(ystrch * (geFloat)WorldRect.bottom);
00101 FrontRect.top =(int)(ystrch * (geFloat)WorldRect.top);
00102 }
00103 }
00104
00105 NumPixels = 0;
00106
00107 if(ClearZ)
00108 {
00109 ClearZBuffer(&ClientWindow);
00110 }
00111 if(Clear)
00112 {
00113 if(bWindowed)
00114 {
00115 SAL_wipe_surface(SAL_BACK_SURFACE, 0);
00116 }
00117 else
00118 {
00119 ClearBackBuffer(&ClientWindow);
00120 }
00121 }
00122
00123 if(bWindowed)
00124 {
00125 SAL_lock_surface(SAL_BACK_SURFACE, &ClientWindow.Buffer, &ClientWindow.PixelPitch);
00126 }
00127 else
00128 {
00129 if(!LockDDrawBackBuffer(&ClientWindow, &WorldRect))
00130 {
00131 SetLastDrvError(DRV_ERROR_INVALID_PARMS, "World rect invalid.");
00132 DumpErrorLogToFile("softdrv.log");
00133 return FALSE;
00134 }
00135 }
00136 assert(ClientWindow.Buffer);
00137
00138 return TRUE;
00139 }
00140
00141 BOOL DRIVERCC EndScene(void)
00142 {
00143 if (RenderMode != RENDER_NONE)
00144 {
00145 SetLastDrvError(DRV_ERROR_GENERIC, "Still in some other render mode.");
00146 return FALSE;
00147 }
00148 if(bWindowed)
00149 {
00150 SAL_release_surface(SAL_BACK_SURFACE, FALSE);
00151
00152 SAL_blit_surface();
00153 SAL_serve_message_queue();
00154 }
00155 else
00156 {
00157 UnlockDDrawBackBuffer(&ClientWindow, &WorldRect);
00158 RefreshDDraw(&ClientWindow, cmode, &WorldRect, &FrontRect);
00159 }
00160
00161
00162
00163
00164 if(ProcessorInfo.Has3DNow)
00165 {
00166 RestoreFPU();
00167 }
00168
00169 return TRUE;
00170 }
00171
00172 static U32 OldFlags =0;
00173
00174 BOOL DRIVERCC BeginWorld(void)
00175 {
00176 if (RenderMode != RENDER_NONE && RenderMode != RENDER_WORLD)
00177 {
00178 SetLastDrvError(DRV_ERROR_GENERIC, "Still in some other render mode.");
00179 return FALSE;
00180 }
00181
00182 ResetSpans(ClientWindow.Height);
00183
00184 RenderMode = RENDER_WORLD;
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 return TRUE;
00195 }
00196
00197 BOOL DRIVERCC EndWorld(void)
00198 {
00199 RenderMode = RENDER_NONE;
00200
00201
00202
00203
00204
00205
00206
00207 return TRUE;
00208 }
00209
00210 BOOL DRIVERCC BeginMeshes(void)
00211 {
00212 if (RenderMode != RENDER_NONE)
00213 {
00214 SetLastDrvError(DRV_ERROR_GENERIC, "Still in some other render mode.");
00215 return FALSE;
00216 }
00217
00218 ResetSpans(ClientWindow.Height);
00219 NumPixels = 0;
00220 RenderMode = RENDER_MESHES;
00221
00222 return TRUE;
00223 }
00224
00225 BOOL DRIVERCC EndMeshes(void)
00226 {
00227 RenderMode = RENDER_NONE;
00228
00229 return TRUE;
00230 }
00231
00232 BOOL DRIVERCC BeginModels(void)
00233 {
00234 if (RenderMode != RENDER_NONE)
00235 {
00236 SetLastDrvError(DRV_ERROR_GENERIC, "Still in some other render mode.");
00237 return FALSE;
00238 }
00239 ResetSpans(ClientWindow.Height);
00240 NumPixels = 0;
00241
00242 RenderMode = RENDER_MODELS;
00243
00244 return TRUE;
00245 }
00246
00247 BOOL DRIVERCC EndModels(void)
00248 {
00249 RenderMode = RENDER_NONE;
00250 return TRUE;
00251 }