You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
11 KiB

/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
///////////////////////////////////////////////////////////////////////////////
// //
// hsG3DDeviceSelector Class Header //
// Generic device enumeration (D3D, OpenGL, etc) //
// Cyan, Inc. //
// //
//// Version History //////////////////////////////////////////////////////////
// //
// 5.21.2001 mcn - Cleaned out all the old Glide stuff, since Plasma2 will //
// not support Glide :( //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef hsG3DDeviceSelector_inc
#define hsG3DDeviceSelector_inc
#include "hsWinRef.h"
#include "hsTemplates.h"
#include "hsBitVector.h"
#ifdef HS_BUILD_FOR_WIN32
#define HS_SELECT_DIRECT3D // not supported on the Mac.
#endif // HS_BUILD_FOR_WIN32
#ifdef HS_BUILD_FOR_WIN32
#define __MSC__
#define DYNAHEADER 1
#endif // HS_BUILD_FOR_WIN32
class hsStream;
struct D3DEnum_DeviceInfo;
struct D3DEnum_DriverInfo;
struct D3DEnum_DeviceInfo;
struct D3DEnum_DriverInfo;
class hsG3DDeviceMode
{
enum {
kNone = 0x0,
kDiscarded = 0x1
};
protected:
UInt32 fFlags;
UInt32 fWidth;
UInt32 fHeight;
UInt32 fDepth;
hsTArray<UInt16> fZStencilDepths; // Array of supported depth/stencil buffer formats.
// Each entry is of the form: ( stencil bit count << 8 ) | ( depth bit count )
hsTArray<UInt8> fFSAATypes; // Array of multisample types supported (each one 2-16)
hsBool fCanRenderToCubics;
public:
hsG3DDeviceMode();
~hsG3DDeviceMode();
hsBool operator< (const hsG3DDeviceMode &mode) const;
void Clear();
hsBool GetDiscarded() const { return 0 != (fFlags & kDiscarded); }
UInt32 GetWidth() const { return fWidth; }
UInt32 GetHeight() const { return fHeight; }
UInt32 GetColorDepth() const { return fDepth; }
UInt8 GetNumZStencilDepths( void ) const { return fZStencilDepths.GetCount(); }
UInt16 GetZStencilDepth( UInt8 i ) const { return fZStencilDepths[ i ]; }
UInt8 GetNumFSAATypes( void ) const { return fFSAATypes.GetCount(); }
UInt8 GetFSAAType( UInt8 i ) const { return fFSAATypes[ i ]; }
hsBool GetCanRenderToCubics( void ) const { return fCanRenderToCubics; }
void SetDiscarded(hsBool on=true) { if(on) fFlags |= kDiscarded; else fFlags &= ~kDiscarded; }
void SetWidth(UInt32 w) { fWidth = w; }
void SetHeight(UInt32 h) { fHeight = h; }
void SetColorDepth(UInt32 d) { fDepth = d; }
void ClearZStencilDepths( void ) { fZStencilDepths.Reset(); }
void AddZStencilDepth( UInt16 depth ) { fZStencilDepths.Append( depth ); }
void ClearFSAATypes( void ) { fFSAATypes.Reset(); }
void AddFSAAType( UInt8 type ) { fFSAATypes.Append( type ); }
void SetCanRenderToCubics( hsBool can ) { fCanRenderToCubics = can; }
};
class hsG3DDeviceRecord
{
public:
enum {
kNone = 0x0,
kDiscarded = 0x1,
kInvalid = 0x2
};
enum FogTypes {
kFogExp = 0,
kFogExp2,
kNumFogTypes
};
protected:
UInt32 fFlags;
UInt32 fG3DDeviceType;
UInt32 fG3DHALorHEL;
char* fG3DDriverDesc;
char* fG3DDriverName;
char* fG3DDriverVersion;
char* fG3DDeviceDesc;
hsBitVector fCaps;
UInt32 fLayersAtOnce;
UInt32 fMemoryBytes;
hsTArray<hsG3DDeviceMode> fModes;
float fZBiasRating;
float fLODBiasRating;
float fFogExpApproxStart;
float fFogExp2ApproxStart;
float fFogEndBias; // As a percentage of the max value for fog
// (i.e. for Z fog, it's a percentage of 1 to add on,
// for W fog, it's a percentage of the yon)
float fFogKnees[ kNumFogTypes ];
float fFogKneeVals[ kNumFogTypes ];
UInt8 fAASetting;
UInt8 fMaxAnisotropicSamples; // 1 to disable, up to max allowed in hardware
int fPixelShaderMajorVer;
int fPixelShaderMinorVer;
public:
hsG3DDeviceRecord();
virtual ~hsG3DDeviceRecord();
hsG3DDeviceRecord(const hsG3DDeviceRecord& src);
hsG3DDeviceRecord& operator=(const hsG3DDeviceRecord& src);
UInt32 GetG3DDeviceType() const { return fG3DDeviceType; }
const char* GetG3DDeviceTypeName() const;
UInt32 GetG3DHALorHEL() const { return fG3DHALorHEL; }
UInt32 GetMemoryBytes() const { return fMemoryBytes; }
const char* GetDriverDesc() const { return fG3DDriverDesc; }
const char* GetDriverName() const { return fG3DDriverName; }
const char* GetDriverVersion() const { return fG3DDriverVersion; }
const char* GetDeviceDesc() const { return fG3DDeviceDesc; }
void SetG3DDeviceType(UInt32 t) { fG3DDeviceType = t; }
void SetG3DHALorHEL(UInt32 h) { fG3DHALorHEL = h; }
void SetMemoryBytes(UInt32 b) { fMemoryBytes = b; }
void SetDriverDesc(const char* s);
void SetDriverName(const char* s);
void SetDriverVersion(const char* s);
void SetDeviceDesc(const char* s);
hsBool GetCap(UInt32 cap) const { return fCaps.IsBitSet(cap); }
void SetCap(UInt32 cap, hsBool on=true) { fCaps.SetBit(cap, on); }
float GetZBiasRating( void ) const { return fZBiasRating; }
void SetZBiasRating( float rating ) { fZBiasRating = rating; }
float GetLODBiasRating( void ) const { return fLODBiasRating; }
void SetLODBiasRating( float rating ) { fLODBiasRating = rating; }
void GetFogApproxStarts( float &expApprox, float &exp2Approx ) const { expApprox = fFogExpApproxStart;
exp2Approx = fFogExp2ApproxStart; }
void SetFogApproxStarts( float exp, float exp2 ) { fFogExpApproxStart = exp;
fFogExp2ApproxStart = exp2; }
float GetFogEndBias( void ) const { return fFogEndBias; }
void SetFogEndBias( float rating ) { fFogEndBias = rating; }
void GetFogKneeParams( UInt8 type, float &knee, float &kneeVal ) const { knee = fFogKnees[ type ]; kneeVal = fFogKneeVals[ type ]; }
void SetFogKneeParams( UInt8 type, float knee, float kneeVal ) { fFogKnees[ type ] = knee; fFogKneeVals[ type ] = kneeVal; }
UInt32 GetLayersAtOnce() const { return fLayersAtOnce; }
void SetLayersAtOnce(UInt32 n) { fLayersAtOnce = n; }
UInt8 GetAASetting() const { return fAASetting; }
void SetAASetting( UInt8 s ) { fAASetting = s; }
UInt8 GetMaxAnisotropicSamples( void ) const { return fMaxAnisotropicSamples; }
void SetMaxAnisotropicSamples( UInt8 num ) { fMaxAnisotropicSamples = num; }
void SetDiscarded(hsBool on=true) { if(on)fFlags |= kDiscarded; else fFlags &= ~kDiscarded; }
hsBool GetDiscarded() const { return 0 != (fFlags & kDiscarded); }
void SetInvalid( hsBool on = true ) { if( on ) fFlags |= kInvalid; else fFlags &= ~kInvalid; }
hsBool IsInvalid() const { return 0 != ( fFlags & kInvalid ); }
hsTArray<hsG3DDeviceMode>& GetModes() { return fModes; }
hsG3DDeviceMode* GetMode(int i) const { return &fModes[i]; }
void ClearModes();
void Clear();
void RemoveDiscarded();
void SetPixelShaderVersion(int major, int minor) { fPixelShaderMajorVer = major; fPixelShaderMinorVer = minor; }
void GetPixelShaderVersion(int &major, int &minor) { major = fPixelShaderMajorVer; minor = fPixelShaderMinorVer; }
};
class hsG3DDeviceModeRecord
{
protected:
hsG3DDeviceRecord fDevice;
hsG3DDeviceMode fMode;
public:
hsG3DDeviceModeRecord();
hsG3DDeviceModeRecord(const hsG3DDeviceRecord& devRec, const hsG3DDeviceMode& devMode);
~hsG3DDeviceModeRecord();
hsG3DDeviceModeRecord(const hsG3DDeviceModeRecord& src);
hsG3DDeviceModeRecord& operator=(const hsG3DDeviceModeRecord& src);
const hsG3DDeviceRecord* GetDevice() const { return &fDevice; }
const hsG3DDeviceMode* GetMode() const { return &fMode; }
};
class hsG3DDeviceSelector : public hsRefCnt
{
public:
enum {
kDevTypeUnknown = 0,
kDevTypeDirect3D,
kDevTypeOpenGL,
kNumDevTypes
};
enum {
kHHTypeUnknown = 0,
kHHD3DNullDev,
kHHD3DHALDev,
kHHD3DTnLHalDev,
kHHD3DRefDev,
kNumHHTypes
};
enum {
kCapsNone = 0,
kCapsMipmap,
kCapsPerspective,
kCapsHardware,
kCapsCompressTextures,
kCapsHWTransform,
kCapsFogLinear,
kCapsFogExp,
kCapsFogExp2,
kCapsFogRange,
kCapsDoesSmallTextures,
kCapsPixelFog,
kCapsBadYonStuff,
kCapsCubicTextures,
kCapsCubicMipmap,
kCapsZBias,
kCapsPixelShader,
kCapsNoAA,
kCapsDoubleFlush,
kCapsSingleFlush,
kCapsCantShadow,
kCapsMaxUVWSrc2,
kCapsCantProj,
kCapsShareDepth,
kCapsBadManaged,
kCapsNoAniso,
// etc.
kNumCaps
};
enum
{
kDefaultWidth = 800,
kDefaultHeight = 600,
kDefaultDepth = 32
};
protected:
hsTArray<hsG3DDeviceRecord> fRecords;
char fTempWinClass[ 128 ];
char fErrorString[ 128 ];
Graphics cleanup for old graphics card tunables. c.f. H'uru commits: > commit e4e718e243b721cde94ea39335574360a3a4805e > Author: Adam Johnson <AdamJohnso@gmail.com> > Date: Fri Feb 1 17:19:50 2013 -0500 > > Bypass ATI Generic fudging with Radeon HD cards > commit bbae6a76d7745f3a1e3ea9e00fb5a95d5e76cbfc > Author: Adam Johnson <AdamJohnso@gmail.com> > Date: Sat Nov 30 20:02:08 2013 -0500 > > We don't support 3dfx cards... > > Come on, man... They made some good cards, but they went out of business > in 1999! Ain't nobody got time fo' dat. > commit a30a326d17a7266fe7af799a0771b4147103f495 > Author: Adam Johnson <AdamJohnso@gmail.com> > Date: Sat Nov 30 20:06:19 2013 -0500 > > We only support DirectX 9... > > If you have less than 11MB VRAM or need to use the ref implementation, > then you are using a dinosaur and have no business even attempting to play > this game. > commit 544abef39e1aa5fe27968e927831de7020454440 > Author: Adam Johnson <AdamJohnso@gmail.com> > Date: Sat Nov 30 20:41:56 2013 -0500 > > Wow, those cards are old... > > Remove detection for cards that are don't support at LEAST DirectX 8. > There's no way they would even be able to get past Direct3DCreate9, so we > shouldn't need to worry about them... I hope. > commit 9070d70e504a65145d270ad601b32583f814c991 > Author: Branan Purvine-Riley <branan@gmail.com> > Date: Sat Jul 27 14:50:20 2013 -0700 > > Lots of cleanups to hsG3DeviceDelector > commit ac238353842ab085179957ab2562f9ba5ea3bbcc > Author: Branan Purvine-Riley <branan@gmail.com> > Date: Sat Jul 27 15:09:24 2013 -0700 > > Get rid of obsolete readers/writes for device info > commit fc67738ee80989e79ba65c34521c42e1a30934f4 > Author: Branan Purvine-Riley <branan@gmail.com> > Date: Sat Jul 27 15:50:10 2013 -0700 > > Remove some obviously obsolete caps > commit 60c544e1ff637445cfc0b0a0e56077792239a40a > Author: Adam Johnson <AdamJohnso@gmail.com> > Date: Fri Nov 29 23:42:20 2013 -0500 > > Don't lazy-load D3D9.dll > > We already link against it, so that's just a waste of time. Also, cleanup > some unneeded ddraw includes. Remember that in Direct3D9, all devices can > render in windowed mode.
3 years ago
void IClear();
void IRemoveDiscarded();
void ITryDirect3DTnLDevice(D3DEnum_DeviceInfo* devInfo, hsG3DDeviceRecord& srcDevRec);
void ITryDirect3DTnLDriver(D3DEnum_DriverInfo* drivInfo);
void ITryDirect3DTnL(hsWinRef winRef);
void IFudgeDirectXDevice( hsG3DDeviceRecord &record,
D3DEnum_DriverInfo *driverInfo, D3DEnum_DeviceInfo *deviceInfo );
UInt32 IAdjustDirectXMemory( UInt32 cardMem );
hsBool IGetD3DCardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo,
DWORD *vendorID, DWORD *deviceID, char **driverString, char **descString );
void ISetFudgeFactors( UInt8 chipsetID, hsG3DDeviceRecord &record );
public:
hsG3DDeviceSelector();
virtual ~hsG3DDeviceSelector();
void RemoveUnusableDevModes(hsBool bTough); // Removes modes and devices not allowed supported in release
void Enumerate(hsWinRef winRef);
hsBool GetDefault(hsG3DDeviceModeRecord *dmr);
};
#endif // hsG3DDeviceSelector_inc