📄 r_d3d_old.cpp
字号:
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: R_d3d_old.cpp,v 1.1 2000/10/01 15:14:32 hurdler Exp $
//
// Copyright (C) 1998-2000 by DooM Legacy Team.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// $Log: R_d3d_old.cpp,v $
// Revision 1.1 2000/10/01 15:14:32 hurdler
// Completely rewritten d3d driver... absolutely not finished at all
//
// Revision 1.2 2000/02/27 00:42:11 hurdler
// fix CR+LF problem
//
// Revision 1.1.1.1 2000/02/22 20:32:33 hurdler
// Initial import into CVS (v1.29 pr3)
//
//
// DESCRIPTION:
// Direct 3D Immediate mode driver
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <windowsx.h>
#define D3D_OVERLOADS
#include <d3d.h>
#define _CREATE_DLL_
#include "../hw_drv.h"
#include "../../screen.h"
#include <math.h>
// **************************************************************************
// PROTOS
// **************************************************************************
static void D3D_FormCreate(void);
static void D3D_FormResize(int w, int h);
static void D3D_SetupPixelFormat(void);
static void D3D_Text(unsigned x, unsigned y, unsigned scale, char* format, ...);
static int D3D_SetMode (viddef_t *lvid, vmode_t *pcurrentmode) ;
static void D3D_DownloadCorona(void);
static void D3D_ClearMipmapCache (void);
static void D3D_InitMipmapCache (void);
static void D3D_BufferClear (void);
static BOOL D3D_InitStates (LPDIRECT3DDEVICE3 pd3dDevice,
LPDIRECT3DVIEWPORT3 pvViewport);
static char* DDErr(HRESULT hresult);
// **************************************************************************
// DEFINES
// **************************************************************************
#undef DEBUG_TO_FILE
#define DEBUG_TO_FILE //output debugging msgs to ogllog.txt
#define MAX_VIDEO_MODES 20
#define DYNLIGHT_TEX_NUM 15477
#define SAFE_RELEASE(p) if(p != NULL) { p->Release(); p = NULL; }
#define SAFE_DELETE(p) if(p != NULL) { delete p; p = NULL; }
#define RELEASE(p) {if(p) p->Release();}
// **************************************************************************
// TYPES
// **************************************************************************
typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
} RGBA_t;
typedef struct {
float red;
float green;
float blue;
float alpha;
} RGBA_ft;
typedef struct {
unsigned char alpha;
unsigned char red;
unsigned char green;
unsigned char blue;
} ARGB_t;
// **************************************************************************
// GLOBALS
// **************************************************************************
#ifdef DEBUG_TO_FILE
static HANDLE logstream;
static unsigned long nb_frames=0;
#endif
LPDIRECTDRAW lpDD;
LPDIRECTDRAW4 lpDD4;
LPDIRECTDRAWSURFACE4 lpDDSRender = NULL;
LPDIRECTDRAWSURFACE4 lpDDSPrimary = NULL;
LPDIRECTDRAWSURFACE4 lpDDSBackBuffer = NULL;
LPDIRECT3D3 lpD3D = NULL;
LPDIRECT3DDEVICE3 lpD3DDevice = NULL;
LPDIRECT3DVIEWPORT3 lpD3DViewport = NULL;
RECT rcScreenRect;
RECT rcViewportRect;
//testing
D3DVERTEX pvTriangleVertices[6];
static viddef_t* viddef;
static unsigned long myPaletteData[256]; // 256 ARGB entries
// **************************************************************************
// DLL ENTRY POINT
// **************************************************************************
BOOL APIENTRY DllMain( HANDLE hModule, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
#ifdef DEBUG_TO_FILE
logstream = INVALID_HANDLE_VALUE;
logstream = CreateFile ("r_d3dlog.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH, NULL);
if (logstream == INVALID_HANDLE_VALUE)
return FALSE;
#endif
break;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;
case DLL_PROCESS_DETACH:
// Perform any necessary cleanup.
#ifdef DEBUG_TO_FILE
if ( logstream != INVALID_HANDLE_VALUE ) {
CloseHandle ( logstream );
logstream = INVALID_HANDLE_VALUE;
}
#endif
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
// ----------
// DBG_Printf
// Output error messages to debug log if DEBUG_TO_FILE is defined,
// else do nothing
// ----------
void DBG_Printf (LPCTSTR lpFmt, ...)
{
#ifdef DEBUG_TO_FILE
char str[1024];
va_list arglist;
DWORD bytesWritten;
va_start (arglist, lpFmt);
vsprintf (str, lpFmt, arglist);
va_end (arglist);
if ( logstream != INVALID_HANDLE_VALUE )
WriteFile (logstream, str, lstrlen(str), &bytesWritten, NULL);
#endif
}
// ==========================================================================
// Initialise
// ==========================================================================
EXPORT BOOL HWRAPI( Init ) (void)
{
HRESULT hr;
// create file for development debugging
DBG_Printf ("Init() r_d3d.DLL development mode log file\n");
//-------------------------------------------------------------------------
// Create DirectDraw
//-------------------------------------------------------------------------
hr = DirectDrawCreate (NULL, &lpDD, NULL);
if (FAILED (hr)) {
DBG_Printf (DDErr(hr));
return FALSE;
}
// get the DirectX 6 interface
hr = lpDD->QueryInterface (IID_IDirectDraw4, (VOID**)&lpDD4 );
if (FAILED(hr)) {
DBG_Printf (DDErr(hr));
return FALSE;
}
//-------------------------------------------------------------------------
// Query DirectDraw for access to Direct3D
//-------------------------------------------------------------------------
lpDD4->QueryInterface( IID_IDirect3D3, (VOID**)&lpD3D );
if (FAILED(hr)) {
DBG_Printf (DDErr(hr));
return FALSE;
}
// setup mipmap download cache
//InitMipmapCache ();
return TRUE;
}
// ==========================================================================
//
// ==========================================================================
EXPORT void HWRAPI( Shutdown ) (void)
{
if (viddef->buffer) {
free (viddef->buffer);
viddef->buffer = NULL;
}
// shutdown 3d display here
// release DirectDraw object
// Release the DDraw and D3D objects used by the app
SAFE_RELEASE( lpD3DViewport )
SAFE_RELEASE( lpD3D )
SAFE_RELEASE( lpDDSBackBuffer )
SAFE_RELEASE( lpDDSPrimary )
SAFE_RELEASE( lpDD4 )
// Do a safe check for releasing the D3DDEVICE. RefCount should be zero.
if( lpD3DDevice )
if( 0 < lpD3DDevice->Release() )
DBG_Printf ("RefCount error releasing lpD3DDevice\r\n");
// Do a safe check for releasing DDRAW. RefCount should be zero.
if( lpDD )
if( 0 < lpDD->Release() )
DBG_Printf ("RefCount error releasing lpDD\r\n");
lpD3DDevice = NULL;
lpDD = NULL;
}
// **************************************************************************
// D3D DISPLAY MODES DRIVER
// **************************************************************************
#define NUMD3DVIDMODES 1
vmode_t d3dvidmodes[NUMD3DVIDMODES] = {
{
NULL,
"320x200",
320, 200, //(200.0/320.0)*(320.0/240.0),
320, 1, // rowbytes, bytes per pixel ... NOTE bpp is 1 but we never write to the LFB
0, 2,
NULL,
&D3D_SetMode
}
};
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
#define MAX_DEVICE_NAME 128
#define MAX_DEVICE_DESC 128
DWORD dwDeviceBitDepth = 0;
GUID guidDevice;
char szDeviceName[MAX_DEVICE_NAME+1];
char szDeviceDesc[MAX_DEVICE_DESC+1];
D3DDEVICEDESC d3dHWDeviceDesc;
static HRESULT WINAPI GetModeListCallback( LPGUID lpGUID,
LPSTR lpszDeviceDesc,
LPSTR lpszDeviceName,
LPD3DDEVICEDESC lpd3dHWDeviceDesc,
LPD3DDEVICEDESC lpd3dSWDeviceDesc,
LPVOID lpUserArg )
{
BOOL fIsHardware;
LPD3DDEVICEDESC lpd3dDeviceDesc;
// If there is no hardware support the color model is zero.
fIsHardware = (lpd3dHWDeviceDesc->dcmColorModel != 0);
lpd3dDeviceDesc = (fIsHardware ? lpd3dHWDeviceDesc :
lpd3dSWDeviceDesc);
DBG_Printf ("%s %s depth: %d\r\n", lpszDeviceDesc, lpszDeviceName, lpd3dDeviceDesc->dwDeviceRenderBitDepth);
// Does the device render at the depth we want?
if (!(lpd3dDeviceDesc->dwDeviceRenderBitDepth & dwDeviceBitDepth))
{
// If not, skip this device.
return D3DENUMRET_OK;
}
// The device must support Gouraud-shaded triangles.
if (D3DCOLOR_MONO == lpd3dDeviceDesc->dcmColorModel)
{
if (!(lpd3dDeviceDesc->dpcTriCaps.dwShadeCaps &
D3DPSHADECAPS_COLORGOURAUDMONO))
{
// No Gouraud shading. Skip this device.
return D3DENUMRET_OK;
}
}
else
{
if (!(lpd3dDeviceDesc->dpcTriCaps.dwShadeCaps &
D3DPSHADECAPS_COLORGOURAUDRGB))
{
// No Gouraud shading. Skip this device.
return D3DENUMRET_OK;
}
}
// Reject software devices, and monochromatic
if (!fIsHardware || (lpd3dDeviceDesc->dcmColorModel != D3DCOLOR_RGB))
{
return D3DENUMRET_OK;
}
//
// This is a device we are interested in. Save the details.
//
*((BOOL*)lpUserArg) = TRUE;
CopyMemory(&guidDevice, lpGUID, sizeof(GUID));
strncpy(szDeviceDesc, lpszDeviceDesc, MAX_DEVICE_DESC);
strncpy(szDeviceName, lpszDeviceName, MAX_DEVICE_NAME);
CopyMemory(&d3dHWDeviceDesc, lpd3dHWDeviceDesc, sizeof(D3DDEVICEDESC));
//CopyMemory(&d3dSWDeviceDesc, lpd3dSWDeviceDesc, sizeof(D3DDEVICEDESC));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -