start of intelligent renderer selection

This commit is contained in:
Glenn Maynard
2003-05-26 23:33:37 +00:00
parent cc6ae9f952
commit 9ee6cfd453
3 changed files with 145 additions and 66 deletions
+28 -25
View File
@@ -177,24 +177,6 @@ RageDisplay_D3D::RageDisplay_D3D( bool windowed, int width, int height, int bpp,
{
LOG->Trace( "RageDisplay_D3D::RageDisplay()" );
if(!SDL_WasInit(SDL_INIT_VIDEO))
SDL_InitSubSystem(SDL_INIT_VIDEO);
/* By default, ignore all SDL events. We'll enable them as we need them.
* We must not enable any events we don't actually want, since we won't
* query for them and they'll fill up the event queue.
*
* This needs to be done after we initialize video, since it's really part
* of the SDL video system--it'll be reinitialized on us if we do this first. */
SDL_EventState(0xFF /*SDL_ALLEVENTS*/, SDL_IGNORE);
SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE);
g_Windowed = false;
for( int i = 0; i < 256; ++i )
g_PaletteIndex.push_back(i);
typedef IDirect3D8 * (WINAPI * Direct3DCreate8_t) (UINT SDKVersion);
Direct3DCreate8_t pDirect3DCreate8;
#if defined(_XBOX)
@@ -202,7 +184,7 @@ RageDisplay_D3D::RageDisplay_D3D( bool windowed, int width, int height, int bpp,
#else
g_D3D8_Module = LoadLibrary("D3D8.dll");
if(!g_D3D8_Module)
RageException::Throw("Couldn't load D3D8.");
throw RageException_D3DNotInstalled();
pDirect3DCreate8 = (Direct3DCreate8_t) GetProcAddress(g_D3D8_Module, "Direct3DCreate8");
#endif
@@ -210,12 +192,11 @@ RageDisplay_D3D::RageDisplay_D3D( bool windowed, int width, int height, int bpp,
g_pd3d = pDirect3DCreate8( D3D_SDK_VERSION );
if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) )
throw RageException(
"There was an error while initializing your video card.\n\n"
"Your system is reporting that Direct3D8 hardware acceleration\n"
"is not available. In most cases, you can download an updated\n"
"driver from your card's manufacturer."
);
{
g_pd3d->Release();
throw RageException_D3DNoAcceleration();
}
D3DADAPTER_IDENTIFIER8 identifier;
g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier );
@@ -235,6 +216,28 @@ RageDisplay_D3D::RageDisplay_D3D( bool windowed, int width, int height, int bpp,
if( SUCCEEDED( g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, u, &mode ) ) )
LOG->Trace( " %ux%u %uHz, format %d", mode.Width, mode.Height, mode.RefreshRate, mode.Format );
/* Up until now, all we've done is set up g_pd3d and do some queries. Now,
* actually initialize the window. Do this after as many error conditions
* as possible, because if we have to shut it down again we'll flash a window
* briefly. */
if(!SDL_WasInit(SDL_INIT_VIDEO))
SDL_InitSubSystem(SDL_INIT_VIDEO);
/* By default, ignore all SDL events. We'll enable them as we need them.
* We must not enable any events we don't actually want, since we won't
* query for them and they'll fill up the event queue.
*
* This needs to be done after we initialize video, since it's really part
* of the SDL video system--it'll be reinitialized on us if we do this first. */
SDL_EventState(0xFF /*SDL_ALLEVENTS*/, SDL_IGNORE);
SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE);
g_Windowed = false;
g_PaletteIndex.clear();
for( int i = 0; i < 256; ++i )
g_PaletteIndex.push_back(i);
// Save the original desktop format.
g_pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_DesktopMode );
+3
View File
@@ -1,6 +1,9 @@
#ifndef RAGEDISPLAY_D3D_H
#define RAGEDISPLAY_D3D_H
class RageException_D3DNotInstalled: public exception { };
class RageException_D3DNoAcceleration: public exception { };
class RageDisplay_D3D: public RageDisplay
{
public:
+114 -41
View File
@@ -23,13 +23,6 @@
#include "RageException.h"
#include "RageMath.h"
#include "RageDisplay.h"
#if defined(WIN32)
#include "RageDisplay_D3D.h"
#endif
#if !defined(_XBOX)
#include "RageDisplay_OGL.h"
#endif
#include "arch/arch.h"
#include "arch/LoadingWindow/LoadingWindow.h"
@@ -212,44 +205,124 @@ static void BoostAppPri()
#endif
}
#if defined(WIN32)
#include "RageDisplay_D3D.h"
#endif
#if !defined(_XBOX)
#include "RageDisplay_OGL.h"
#endif
/* XXX: Passing all of the SetVideoMode arguments to the ctor is cumbersome. */
#if !defined(_XBOX)
static RageDisplay *CreateDisplay_OGL()
{
return new RageDisplay_OGL(
PREFSMAN->m_bWindowed,
PREFSMAN->m_iDisplayWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
THEME->GetMetric("Common","WindowTitle"),
THEME->GetPathToG("Common window icon") );
}
#endif
#if defined(WIN32)
static RageDisplay *CreateDisplay_D3D()
{
return new RageDisplay_D3D(
PREFSMAN->m_bWindowed,
PREFSMAN->m_iDisplayWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
THEME->GetMetric("Common","WindowTitle"),
THEME->GetPathToG("Common window icon") );
}
#endif
#if defined(_XBOX)
RageDisplay *CreateDisplay() { return CreateDisplay_D3D(); }
#elif !defined(WIN32)
RageDisplay *CreateDisplay() { return CreateDisplay_OGL(); }
#else
#include "archutils/Win32/VideoDriverInfo.h"
#include "Regex.h"
RageDisplay *CreateDisplay()
{
/* XXX: Passing all of the SetVideoMode arguments to the ctor is cumbersome. */
#if defined(_XBOX)
RageDisplay *ret = new RageDisplay_D3D(
PREFSMAN->m_bWindowed,
PREFSMAN->m_iDisplayWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
THEME->GetMetric("Common","WindowTitle"),
THEME->GetPathToG("Common window icon") );
#elif !defined(WIN32)
RageDisplay *ret = new RageDisplay_OGL(
PREFSMAN->m_bWindowed,
PREFSMAN->m_iDisplayWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
THEME->GetMetric("Common","WindowTitle"),
THEME->GetPathToG("Common window icon") );
#else
/* Windows; we have both D3D and OGL available. XXX: do something smart. */
RageDisplay *ret = new RageDisplay_OGL(
PREFSMAN->m_bWindowed,
PREFSMAN->m_iDisplayWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
THEME->GetMetric("Common","WindowTitle"),
THEME->GetPathToG("Common window icon") );
return ret;
#endif
/* We never want to bother users with having to decide which API to use.
*
* Some cards simply are too troublesome with OpenGL to ever use it, eg. Voodoos.
* If D3D8 isn't installed on those, complain and refuse to run (by default).
* For others, always use OpenGL. Allow forcing to D3D as an advanced option.
*
* If we're missing acceleration when we load D3D8 due to a card being in the
* D3D list, it means we need drivers and that they do exist.
*
* If we try to load OpenGL and we're missing acceleration, it may mean:
* 1. We're missing drivers, and they just need upgrading.
* 2. The card doesn't have drivers, and it should be using D3D8. In other words,
* it needs an entry in this table.
* 3. The card doesn't have drivers for either. (Sorry, no S3 868s.) Can't play.
*
* In this case, fail to load; don't silently fall back on D3D. We don't want
* people unknowingly using D3D8 with old drivers (and reporting obscure bugs
* due to driver problems). We'll probably get bug reports for all three types.
* #2 is the only case that's actually a bug.
*
* If a system is listed as needing D3D, it's important--don't silently fall
* back on OpenGL if it's missing. (If that would work, we wouldn't use D3D
* on that system to begin with.)
*
* This should probably be exported into an INI.
*/
vector<Regex> Cards;
Cards.push_back(Regex(".*Voodoo.*"));
// Cards.push_back(Regex(".*nVidia.*")); // testing
/* We can't too reliably get driver information before we set up the window. Ask
* VideoDriverInfo; it'll usually give us a name we can match. XXX: If we're on
* an old system with more than one card, we won't know which to match. */
VideoDriverInfo info;
GetPrimaryVideoDriverInfo(info);
const CString &desc = info.sDescription;
bool NeedsD3D = false;
for(unsigned i = 0; i < Cards.size(); ++i)
if(Cards[i].Compare(desc)) NeedsD3D = true;
/* XXX: Handle AllowSoftwareRenderer. Be careful not to fall back from D3D to
* OpenGL because of it, and ending up with an accelerated but broken driver! */
if( NeedsD3D )
{
/* We require D3D. Try to start it. */
CString error = "There was an error while initializing your video card.\n\n"
"Your display adapter, \"" + desc + "\", requires Direct3D 8 (or "
"higher), but ";
try {
return CreateDisplay_D3D();
} catch(RageException_D3DNotInstalled e) {
error +=
"it is not installed. You can download it from: URL";
} catch(RageException_D3DNoAcceleration e) {
error +=
"your system is reporting that hardware acceleration is not available. "
"You can download an updated driver from your card's manufacturer.";
};
RageException::Throw( error );
}
return CreateDisplay_OGL();
}
#endif
static void RestoreAppPri()
{
if(!ChangeAppPri())