cleanup/comment

This commit is contained in:
AJ Kelly
2011-03-02 23:57:57 -06:00
parent dc196b38af
commit b36aabeeaa
+105 -129
View File
@@ -34,7 +34,6 @@
#include <math.h> #include <math.h>
#include <list> #include <list>
RString GetErrorString( HRESULT hr ) RString GetErrorString( HRESULT hr )
{ {
char szError[1024] = ""; char szError[1024] = "";
@@ -42,44 +41,40 @@ RString GetErrorString( HRESULT hr )
return szError; return szError;
} }
//
// Globals // Globals
//
#if !defined(XBOX) #if !defined(XBOX)
HMODULE g_D3D8_Module = NULL; HMODULE g_D3D8_Module = NULL;
#endif #endif
LPDIRECT3D8 g_pd3d = NULL; LPDIRECT3D8 g_pd3d = NULL;
LPDIRECT3DDEVICE8 g_pd3dDevice = NULL; LPDIRECT3DDEVICE8 g_pd3dDevice = NULL;
D3DCAPS8 g_DeviceCaps; D3DCAPS8 g_DeviceCaps;
D3DDISPLAYMODE g_DesktopMode; D3DDISPLAYMODE g_DesktopMode;
D3DPRESENT_PARAMETERS g_d3dpp; D3DPRESENT_PARAMETERS g_d3dpp;
int g_ModelMatrixCnt=0; int g_ModelMatrixCnt=0;
static bool g_bSphereMapping[NUM_TextureUnit] = { false, false }; static bool g_bSphereMapping[NUM_TextureUnit] = { false, false };
/* Direct3D doesn't associate a palette with textures. /* Direct3D doesn't associate a palette with textures. Instead, we load a
* Instead, we load a palette into a slot. We need to keep track * palette into a slot. We need to keep track of which texture's palette is
* of which texture's palette is stored in what slot. */ * stored in what slot. */
map<unsigned,int> g_TexResourceToPaletteIndex; map<unsigned,int> g_TexResourceToPaletteIndex;
list<int> g_PaletteIndex; list<int> g_PaletteIndex;
struct TexturePalette { PALETTEENTRY p[256]; }; struct TexturePalette { PALETTEENTRY p[256]; };
map<unsigned,TexturePalette> g_TexResourceToTexturePalette; map<unsigned,TexturePalette> g_TexResourceToTexturePalette;
/* Load the palette, if any, for the given texture into a palette slot, and make // Load the palette, if any, for the given texture into a palette slot, and make it current.
* it current. */
static void SetPalette( unsigned TexResource ) static void SetPalette( unsigned TexResource )
{ {
/* If the texture isn't paletted, we have nothing to do. */ // If the texture isn't paletted, we have nothing to do.
if( g_TexResourceToTexturePalette.find(TexResource) == g_TexResourceToTexturePalette.end() ) if( g_TexResourceToTexturePalette.find(TexResource) == g_TexResourceToTexturePalette.end() )
return; return;
/* Is the palette already loaded? */ // Is the palette already loaded?
if( g_TexResourceToPaletteIndex.find(TexResource) == g_TexResourceToPaletteIndex.end() ) if( g_TexResourceToPaletteIndex.find(TexResource) == g_TexResourceToPaletteIndex.end() )
{ {
/* It's not. Grab the least recently used slot. */ // It's not. Grab the least recently used slot.
int iPalIndex = g_PaletteIndex.front(); int iPalIndex = g_PaletteIndex.front();
/* If any other texture is currently using this slot, mark that palette unloaded. */ // If any other texture is currently using this slot, mark that palette unloaded.
for( map<unsigned,int>::iterator i = g_TexResourceToPaletteIndex.begin(); i != g_TexResourceToPaletteIndex.end(); ++i ) for( map<unsigned,int>::iterator i = g_TexResourceToPaletteIndex.begin(); i != g_TexResourceToPaletteIndex.end(); ++i )
{ {
if( i->second != iPalIndex ) if( i->second != iPalIndex )
@@ -88,7 +83,7 @@ static void SetPalette( unsigned TexResource )
break; break;
} }
/* Load it. */ // Load it.
#if !defined(XBOX) #if !defined(XBOX)
TexturePalette& pal = g_TexResourceToTexturePalette[TexResource]; TexturePalette& pal = g_TexResourceToTexturePalette[TexResource];
g_pd3dDevice->SetPaletteEntries( iPalIndex, pal.p ); g_pd3dDevice->SetPaletteEntries( iPalIndex, pal.p );
@@ -98,10 +93,10 @@ static void SetPalette( unsigned TexResource )
g_TexResourceToPaletteIndex[TexResource] = iPalIndex; g_TexResourceToPaletteIndex[TexResource] = iPalIndex;
} }
const int iPalIndex = g_TexResourceToPaletteIndex[TexResource]; const int iPalIndex = g_TexResourceToPaletteIndex[TexResource];
/* Find this palette index in the least-recently-used queue and move it to the end. */ // Find this palette index in the least-recently-used queue and move it to the end.
for(list<int>::iterator i = g_PaletteIndex.begin(); i != g_PaletteIndex.end(); ++i) for(list<int>::iterator i = g_PaletteIndex.begin(); i != g_PaletteIndex.end(); ++i)
{ {
if( *i != iPalIndex ) if( *i != iPalIndex )
@@ -184,14 +179,14 @@ static D3DFORMAT D3DFORMATS[NUM_PixelFormat] =
D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5,
D3DFMT_X1R5G5B5, D3DFMT_X1R5G5B5,
#if defined(XBOX) #if defined(XBOX)
D3DFMT_UNKNOWN, /* no RGB */ D3DFMT_UNKNOWN, // no RGB
#else #else
D3DFMT_R8G8B8, D3DFMT_R8G8B8,
#endif #endif
D3DFMT_P8, D3DFMT_P8,
D3DFMT_UNKNOWN, /* no BGR */ D3DFMT_UNKNOWN, // no BGR
D3DFMT_UNKNOWN, /* no ABGR */ D3DFMT_UNKNOWN, // no ABGR
D3DFMT_UNKNOWN, /* X1R5G5B5 */ D3DFMT_UNKNOWN, // X1R5G5B5
}; };
const RageDisplay::PixelFormatDesc *RageDisplay_D3D::GetPixelFormatDesc(PixelFormat pf) const const RageDisplay::PixelFormatDesc *RageDisplay_D3D::GetPixelFormatDesc(PixelFormat pf) const
@@ -201,13 +196,11 @@ const RageDisplay::PixelFormatDesc *RageDisplay_D3D::GetPixelFormatDesc(PixelFor
} }
RageDisplay_D3D::RageDisplay_D3D() RageDisplay_D3D::RageDisplay_D3D()
{ {
} }
static LocalizedString D3D_NOT_INSTALLED ( "RageDisplay_D3D", "DirectX 8.1 or greater is not installed. You can download it from:" ); static LocalizedString D3D_NOT_INSTALLED ( "RageDisplay_D3D", "DirectX 8.1 or greater is not installed. You can download it from:" );
const RString D3D_URL = "http://www.microsoft.com/downloads/details.aspx?FamilyID=a19bed22-0b25-4e5d-a584-6389d8a3dad0&displaylang=en"; const RString D3D_URL = "http://www.microsoft.com/downloads/details.aspx?FamilyID=a19bed22-0b25-4e5d-a584-6389d8a3dad0&displaylang=en";
static LocalizedString HARDWARE_ACCELERATION_NOT_AVAILABLE ( "RageDisplay_D3D", static LocalizedString HARDWARE_ACCELERATION_NOT_AVAILABLE ( "RageDisplay_D3D",
@@ -273,10 +266,9 @@ RString RageDisplay_D3D::Init( const VideoModeParams &p, bool bAllowUnaccelerate
// Save the original desktop format. // Save the original desktop format.
g_pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_DesktopMode ); g_pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_DesktopMode );
/* Up until now, all we've done is set up g_pd3d and do some queries. Now, /* 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 * actually initialize the window. Do this after as many error conditions as
* as possible, because if we have to shut it down again we'll flash a window * possible, because if we have to shut it down again we'll flash a window briefly. */
* briefly. */
bool bIgnore = false; bool bIgnore = false;
return SetVideoMode( p, bIgnore ); return SetVideoMode( p, bIgnore );
} }
@@ -299,8 +291,9 @@ RageDisplay_D3D::~RageDisplay_D3D()
g_pd3d = NULL; g_pd3d = NULL;
} }
/* Even after we call Release(), D3D may still affect our window. It seems to subclass /* Even after we call Release(), D3D may still affect our window. It seems
* the window, and never release it. Free the DLL after destroying the window. */ * to subclass the window, and never release it. Free the DLL after
* destroying the window. */
#if !defined(XBOX) #if !defined(XBOX)
if( g_D3D8_Module ) if( g_D3D8_Module )
{ {
@@ -330,9 +323,9 @@ D3DFORMAT FindBackBufferType(bool bWindowed, int iBPP)
HRESULT hr; HRESULT hr;
// If windowed, then bpp is ignored. Use whatever works. // If windowed, then bpp is ignored. Use whatever works.
vector<D3DFORMAT> vBackBufferFormats; // throw all possibilities in here vector<D3DFORMAT> vBackBufferFormats; // throw all possibilities in here
/* When windowed, add all formats; otherwise add only formats that match dwBPP. */ // When windowed, add all formats; otherwise add only formats that match dwBPP.
if( iBPP == 16 || bWindowed ) if( iBPP == 16 || bWindowed )
{ {
vBackBufferFormats.push_back( D3DFMT_R5G6B5 ); vBackBufferFormats.push_back( D3DFMT_R5G6B5 );
@@ -371,7 +364,7 @@ D3DFORMAT FindBackBufferType(bool bWindowed, int iBPP)
fmtDisplay, fmtBackBuffer, bWindowed ); fmtDisplay, fmtBackBuffer, bWindowed );
if( FAILED(hr) ) if( FAILED(hr) )
continue; // skip continue; // skip
// done searching // done searching
LOG->Trace( "This will work." ); LOG->Trace( "This will work." );
@@ -384,7 +377,7 @@ D3DFORMAT FindBackBufferType(bool bWindowed, int iBPP)
RString SetD3DParams( bool &bNewDeviceOut ) RString SetD3DParams( bool &bNewDeviceOut )
{ {
if( g_pd3dDevice == NULL ) // device is not yet created. We need to create it if( g_pd3dDevice == NULL ) // device is not yet created. We need to create it
{ {
bNewDeviceOut = true; bNewDeviceOut = true;
HRESULT hr = g_pd3d->CreateDevice( HRESULT hr = g_pd3d->CreateDevice(
@@ -419,13 +412,13 @@ RString SetD3DParams( bool &bNewDeviceOut )
g_pd3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
/* Palettes were lost by Reset(), so mark them unloaded. */ // Palettes were lost by Reset(), so mark them unloaded.
g_TexResourceToPaletteIndex.clear(); g_TexResourceToPaletteIndex.clear();
return RString(); return RString();
} }
/* If the given parameters have failed, try to lower them. */ // If the given parameters have failed, try to lower them.
static bool D3DReduceParams( D3DPRESENT_PARAMETERS *pp ) static bool D3DReduceParams( D3DPRESENT_PARAMETERS *pp )
{ {
D3DDISPLAYMODE current; D3DDISPLAYMODE current;
@@ -443,41 +436,41 @@ static bool D3DReduceParams( D3DPRESENT_PARAMETERS *pp )
D3DDISPLAYMODE mode; D3DDISPLAYMODE mode;
g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, i, &mode ); g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, i, &mode );
/* Never change the format. */ // Never change the format.
if( mode.Format != current.Format ) if( mode.Format != current.Format )
continue; continue;
/* Never increase the parameters. */ // Never increase the parameters.
if( mode.Height > current.Height || mode.Width > current.Width || mode.RefreshRate > current.RefreshRate ) if( mode.Height > current.Height || mode.Width > current.Width || mode.RefreshRate > current.RefreshRate )
continue; continue;
/* Never go below 640x480 unless we already are. */ // Never go below 640x480 unless we already are.
if( (current.Width >= 640 && current.Height >= 480) && (mode.Width < 640 || mode.Height < 480) ) if( (current.Width >= 640 && current.Height >= 480) && (mode.Width < 640 || mode.Height < 480) )
continue; continue;
/* Never go below 60Hz. */ // Never go below 60Hz.
if( mode.RefreshRate && mode.RefreshRate < 60 ) if( mode.RefreshRate && mode.RefreshRate < 60 )
continue; continue;
/* If mode.RefreshRate is 0, it means "default". We don't know what that means; /* If mode.RefreshRate is 0, it means "default". We don't know what
* assume it's 60Hz. */ * that means; assume it's 60Hz. */
/* Higher scores are better. */ // Higher scores are better.
int iScore = 0; int iScore = 0;
if( current.RefreshRate >= 70 && mode.RefreshRate < 70 ) if( current.RefreshRate >= 70 && mode.RefreshRate < 70 )
{ {
/* Top priority: we really want to avoid dropping to a refresh rate that's /* Top priority: we really want to avoid dropping to a refresh rate
* below 70Hz. */ * that's below 70Hz. */
iScore -= 100000; iScore -= 100000;
} }
else if( mode.RefreshRate < current.RefreshRate ) else if( mode.RefreshRate < current.RefreshRate )
{ {
/* Low priority: We're lowering the refresh rate, but not too far. current.RefreshRate /* Low priority: We're lowering the refresh rate, but not too far.
* might be 0, in which case this simply gives points for higher refresh * current.RefreshRate might be 0, in which case this simply gives
* rates. */ * points for higher refresh rates. */
iScore += (mode.RefreshRate - current.RefreshRate); iScore += (mode.RefreshRate - current.RefreshRate);
} }
/* Medium priority: */ // Medium priority:
int iResolutionDiff = (current.Height - mode.Height) + (current.Width - mode.Width); int iResolutionDiff = (current.Height - mode.Height) + (current.Width - mode.Width);
iScore -= iResolutionDiff * 100; iScore -= iResolutionDiff * 100;
@@ -534,10 +527,10 @@ static void SetPresentParametersFromVideoModeParams( const VideoModeParams &p, D
#else #else
if( XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I ) if( XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I )
{ {
/* Get supported video flags. */ // Get supported video flags.
DWORD VideoFlags = XGetVideoFlags(); DWORD VideoFlags = XGetVideoFlags();
/* Set pal60 if available. */ // Set pal60 if available.
if( VideoFlags & XC_VIDEO_FLAGS_PAL_60Hz ) if( VideoFlags & XC_VIDEO_FLAGS_PAL_60Hz )
pD3Dpp->FullScreen_RefreshRateInHz = 60; pD3Dpp->FullScreen_RefreshRateInHz = 60;
else else
@@ -549,7 +542,6 @@ static void SetPresentParametersFromVideoModeParams( const VideoModeParams &p, D
pD3Dpp->Flags = 0; pD3Dpp->Flags = 0;
LOG->Trace( "Present Parameters: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", LOG->Trace( "Present Parameters: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
pD3Dpp->BackBufferWidth, pD3Dpp->BackBufferHeight, pD3Dpp->BackBufferFormat, pD3Dpp->BackBufferWidth, pD3Dpp->BackBufferHeight, pD3Dpp->BackBufferFormat,
pD3Dpp->BackBufferCount, pD3Dpp->BackBufferCount,
@@ -560,7 +552,7 @@ static void SetPresentParametersFromVideoModeParams( const VideoModeParams &p, D
); );
} }
/* Set the video mode. */ // Set the video mode.
RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDeviceOut ) RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDeviceOut )
{ {
VideoModeParams p = _p; VideoModeParams p = _p;
@@ -572,9 +564,7 @@ RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDevi
if( FindBackBufferType( p.windowed, p.bpp ) == D3DFMT_UNKNOWN ) // no possible back buffer formats if( FindBackBufferType( p.windowed, p.bpp ) == D3DFMT_UNKNOWN ) // no possible back buffer formats
return ssprintf( "FindBackBufferType(%i,%i) failed", p.windowed, p.bpp ); // failed to set mode return ssprintf( "FindBackBufferType(%i,%i) failed", p.windowed, p.bpp ); // failed to set mode
/* Set up and display the window before setting up D3D. If we don't do this,
/* Set up and display the window before setting up D3D. If we don't do this,
* then setting up a fullscreen window (when we're not coming from windowed) * then setting up a fullscreen window (when we're not coming from windowed)
* causes all other windows on the system to be resized to the new resolution. */ * causes all other windows on the system to be resized to the new resolution. */
GraphicsWindow::CreateGraphicsWindow( p ); GraphicsWindow::CreateGraphicsWindow( p );
@@ -586,22 +576,20 @@ RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDevi
g_pd3dDevice = D3D__pDevice; g_pd3dDevice = D3D__pDevice;
#endif #endif
/* Display the window immediately, so we don't display the desktop ... */ // Display the window immediately, so we don't display the desktop ...
while( 1 ) while( 1 )
{ {
/* Try the video mode. */ // Try the video mode.
RString sErr = SetD3DParams( bNewDeviceOut ); RString sErr = SetD3DParams( bNewDeviceOut );
if( sErr.empty() ) if( sErr.empty() )
break; break;
/* It failed. We're probably selecting a video mode that isn't supported. /* It failed. We're probably selecting a video mode that isn't supported.
* If we're fullscreen, search the mode list and find the nearest lower * If we're fullscreen, search the mode list and find the nearest lower mode. */
* mode. */
if( p.windowed || !D3DReduceParams( &g_d3dpp ) ) if( p.windowed || !D3DReduceParams( &g_d3dpp ) )
return sErr; return sErr;
/* Store the new settings we're about to try. */ // Store the new settings we're about to try.
p.height = g_d3dpp.BackBufferHeight; p.height = g_d3dpp.BackBufferHeight;
p.width = g_d3dpp.BackBufferWidth; p.width = g_d3dpp.BackBufferWidth;
if( g_d3dpp.FullScreen_RefreshRateInHz == D3DPRESENT_RATE_DEFAULT ) if( g_d3dpp.FullScreen_RefreshRateInHz == D3DPRESENT_RATE_DEFAULT )
@@ -610,14 +598,14 @@ RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDevi
p.rate = g_d3dpp.FullScreen_RefreshRateInHz; p.rate = g_d3dpp.FullScreen_RefreshRateInHz;
} }
/* Call this again after changing the display mode. If we're going to a window /* Call this again after changing the display mode. If we're going to a window
* from fullscreen, the first call can't set a larger window than the old fullscreen * from fullscreen, the first call can't set a larger window than the old
* resolution or set the window position. */ * fullscreen resolution or set the window position. */
GraphicsWindow::CreateGraphicsWindow( p ); GraphicsWindow::CreateGraphicsWindow( p );
ResolutionChanged(); ResolutionChanged();
return RString(); // mode change successful return RString(); // mode change successful
} }
void RageDisplay_D3D::ResolutionChanged() void RageDisplay_D3D::ResolutionChanged()
@@ -683,12 +671,12 @@ void RageDisplay_D3D::EndFrame()
bool RageDisplay_D3D::SupportsTextureFormat( PixelFormat pixfmt, bool realtime ) bool RageDisplay_D3D::SupportsTextureFormat( PixelFormat pixfmt, bool realtime )
{ {
#if defined(XBOX) #if defined(XBOX)
// Lazy... Xbox handles paletted textures completely differently /* Lazy... Xbox handles paletted textures completely differently than
// than regular D3D. It's not worth writing a bunch of code to handle it. * regular D3D. It's not worth writing a bunch of code to handle it.
// Paletted textures result in worse cache efficiency anyway (see "Xbox * Paletted textures result in worse cache efficiency anyway (see "Xbox
// Palettized Texture Performance" in XDK). * Palettized Texture Performance" in XDK). So, just force 32bit ARGB textures.
// So, just force 32bit ARGB textures. -Chris * -Chris
// This is also needed for XGSwizzleRect(). * This is also needed for XGSwizzleRect(). */
return pixfmt == PixelFormat_RGBA8; return pixfmt == PixelFormat_RGBA8;
#endif #endif
@@ -722,15 +710,15 @@ RageSurface* RageDisplay_D3D::CreateScreenshot()
#if defined(XBOX) #if defined(XBOX)
return NULL; return NULL;
#else #else
/* Get the back buffer. */ // Get the back buffer.
IDirect3DSurface8* pSurface; IDirect3DSurface8* pSurface;
g_pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ); g_pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );
/* Get the back buffer description. */ // Get the back buffer description.
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
pSurface->GetDesc( &desc ); pSurface->GetDesc( &desc );
/* Copy the back buffer into a surface of a type we support. */ // Copy the back buffer into a surface of a type we support.
IDirect3DSurface8* pCopy; IDirect3DSurface8* pCopy;
g_pd3dDevice->CreateImageSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, &pCopy ); g_pd3dDevice->CreateImageSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, &pCopy );
@@ -738,7 +726,7 @@ RageSurface* RageDisplay_D3D::CreateScreenshot()
pSurface->Release(); pSurface->Release();
/* Update desc from the copy. */ // Update desc from the copy.
pCopy->GetDesc( &desc ); pCopy->GetDesc( &desc );
D3DLOCKED_RECT lr; D3DLOCKED_RECT lr;
@@ -755,7 +743,7 @@ RageSurface* RageDisplay_D3D::CreateScreenshot()
RageSurface *surface = CreateSurfaceFromPixfmt( PixelFormat_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch); RageSurface *surface = CreateSurfaceFromPixfmt( PixelFormat_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
ASSERT( surface ); ASSERT( surface );
/* We need to make a copy, since lr.pBits will go away when we call UnlockRect(). */ // We need to make a copy, since lr.pBits will go away when we call UnlockRect().
RageSurface *SurfaceCopy = RageSurface *SurfaceCopy =
CreateSurface( surface->w, surface->h, CreateSurface( surface->w, surface->h,
surface->format->BitsPerPixel, surface->format->BitsPerPixel,
@@ -782,7 +770,7 @@ void RageDisplay_D3D::SendCurrentMatrices()
RageMatrix m; RageMatrix m;
RageMatrixMultiply( &m, GetCentering(), GetProjectionTop() ); RageMatrixMultiply( &m, GetCentering(), GetProjectionTop() );
/* Convert to OpenGL-style "pixel-centered" coords */ // Convert to OpenGL-style "pixel-centered" coords
RageMatrix m2 = GetCenteringMatrix( -0.5f, -0.5f, 0, 0 ); RageMatrix m2 = GetCenteringMatrix( -0.5f, -0.5f, 0, 0 );
RageMatrix projection; RageMatrix projection;
RageMatrixMultiply( &projection, &m2, &m ); RageMatrixMultiply( &projection, &m2, &m );
@@ -795,7 +783,7 @@ void RageDisplay_D3D::SendCurrentMatrices()
{ {
// Optimization opportunity: Turn off texture transform if not using texture coords. // Optimization opportunity: Turn off texture transform if not using texture coords.
g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
// If no texture is set for this texture unit, don't bother setting it up. // If no texture is set for this texture unit, don't bother setting it up.
IDirect3DBaseTexture8* pTexture = NULL; IDirect3DBaseTexture8* pTexture = NULL;
g_pd3dDevice->GetTexture( tu, &pTexture ); g_pd3dDevice->GetTexture( tu, &pTexture );
@@ -803,7 +791,6 @@ void RageDisplay_D3D::SendCurrentMatrices()
continue; continue;
pTexture->Release(); pTexture->Release();
if( g_bSphereMapping[tu] ) if( g_bSphereMapping[tu] )
{ {
static const RageMatrix tex = RageMatrix static const RageMatrix tex = RageMatrix
@@ -821,12 +808,10 @@ void RageDisplay_D3D::SendCurrentMatrices()
} }
else else
{ {
/* /* Direct3D is expecting a 3x3 matrix loaded into the 4x4 in order
* Direct3D is expecting a 3x3 matrix loaded into the 4x4 in order to transform * to transform the 2-component texture coordinates. We currently
* the 2-component texture coordinates. We currently only use translate and scale, * only use translate and scale, and ignore the z component entirely,
* and ignore the z component entirely, so convert the texture matrix from * so convert the texture matrix from 4x4 to 3x3 by dropping z. */
* 4x4 to 3x3 by dropping z.
*/
const RageMatrix &tex1 = *GetTextureTop(); const RageMatrix &tex1 = *GetTextureTop();
const RageMatrix tex2 = RageMatrix const RageMatrix tex2 = RageMatrix
@@ -1067,12 +1052,10 @@ void RageDisplay_D3D::DrawCompiledGeometryInternal( const RageCompiledGeometry *
{ {
SendCurrentMatrices(); SendCurrentMatrices();
/* If lighting is off, then the current material will have no effect. /* If lighting is off, then the current material will have no effect. We
* We want to still be able to color models with lighting off, * want to still be able to color models with lighting off, so shove the
* so shove the material color in texture factor and modify the * material color in texture factor and modify the texture stage to use it
* texture stage to use it instead of the vertex color (our models * instead of the vertex color (our models don't have vertex coloring anyway). */
* don't have vertex coloring anyway).
*/
DWORD bLighting; DWORD bLighting;
g_pd3dDevice->GetRenderState( D3DRS_LIGHTING, &bLighting ); g_pd3dDevice->GetRenderState( D3DRS_LIGHTING, &bLighting );
@@ -1131,17 +1114,19 @@ void RageDisplay_D3D::SetTexture( TextureUnit tu, unsigned iTexture )
{ {
g_pd3dDevice->SetTexture( tu, NULL ); g_pd3dDevice->SetTexture( tu, NULL );
// Intentionally commented out. Don't mess with texture stage state when just setting the texture. /* Intentionally commented out. Don't mess with texture stage state
// Model sets its texture modes before setting the final texture. * when just setting the texture. Model sets its texture modes before
* setting the final texture. */
//g_pd3dDevice->SetTextureStageState( tu, D3DTSS_COLOROP, D3DTOP_DISABLE ); //g_pd3dDevice->SetTextureStageState( tu, D3DTSS_COLOROP, D3DTOP_DISABLE );
} }
else else
{ {
IDirect3DTexture8* pTex = (IDirect3DTexture8*) iTexture; IDirect3DTexture8* pTex = (IDirect3DTexture8*) iTexture;
g_pd3dDevice->SetTexture( tu, pTex ); g_pd3dDevice->SetTexture( tu, pTex );
// Intentionally commented out. Don't mess with texture stage state when just setting the texture. /* Intentionally commented out. Don't mess with texture stage state
// Model sets its texture modes before setting the final texture. * when just setting the texture. Model sets its texture modes before
* setting the final texture. */
//g_pd3dDevice->SetTextureStageState( tu, D3DTSS_COLOROP, D3DTOP_MODULATE ); //g_pd3dDevice->SetTextureStageState( tu, D3DTSS_COLOROP, D3DTOP_MODULATE );
// Set palette (if any) // Set palette (if any)
@@ -1188,7 +1173,7 @@ void RageDisplay_D3D::SetTextureMode( TextureUnit tu, TextureMode tm )
void RageDisplay_D3D::SetTextureFiltering( TextureUnit tu, bool b ) void RageDisplay_D3D::SetTextureFiltering( TextureUnit tu, bool b )
{ {
if( tu >= (int) g_DeviceCaps.MaxSimultaneousTextures ) // not supported if( tu >= (int) g_DeviceCaps.MaxSimultaneousTextures ) // not supported
return; return;
g_pd3dDevice->SetTextureStageState( tu, D3DTSS_MINFILTER, b ? D3DTEXF_LINEAR : D3DTEXF_POINT ); g_pd3dDevice->SetTextureStageState( tu, D3DTSS_MINFILTER, b ? D3DTEXF_LINEAR : D3DTEXF_POINT );
@@ -1222,12 +1207,9 @@ void RageDisplay_D3D::SetBlendMode( BlendMode mode )
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO ); g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
break; break;
/* /* Effects currently missing in D3D: BLEND_ALPHA_MASK, BLEND_ALPHA_KNOCK_OUT
* Effects currently missing in D3D:
* BLEND_ALPHA_MASK, BLEND_ALPHA_KNOCK_OUT
* These two may require DirectX9 since D3DRS_SRCALPHA and D3DRS_DESTALPHA * These two may require DirectX9 since D3DRS_SRCALPHA and D3DRS_DESTALPHA
* don't seem to exist in DX8. -aj * don't seem to exist in DX8. -aj */
*/
case BLEND_ALPHA_MASK: case BLEND_ALPHA_MASK:
// RGB: iSourceRGB = GL_ZERO; iDestRGB = GL_ONE; // RGB: iSourceRGB = GL_ZERO; iDestRGB = GL_ONE;
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO ); g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
@@ -1304,10 +1286,10 @@ void RageDisplay_D3D::SetZTestMode( ZTestMode mode )
DWORD dw; DWORD dw;
switch( mode ) switch( mode )
{ {
case ZTEST_OFF: dw = D3DCMP_ALWAYS; break; case ZTEST_OFF: dw = D3DCMP_ALWAYS; break;
case ZTEST_WRITE_ON_PASS: dw = D3DCMP_LESSEQUAL; break; case ZTEST_WRITE_ON_PASS: dw = D3DCMP_LESSEQUAL; break;
case ZTEST_WRITE_ON_FAIL: dw = D3DCMP_GREATER; break; case ZTEST_WRITE_ON_FAIL: dw = D3DCMP_GREATER; break;
default: ASSERT( 0 ); default: ASSERT( 0 );
} }
g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, dw ); g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, dw );
} }
@@ -1336,11 +1318,9 @@ void RageDisplay_D3D::SetMaterial(
) )
{ {
/* If lighting is off, then the current material will have no effect. /* If lighting is off, then the current material will have no effect.
* We want to still be able to color models with lighting off, * We want to still be able to color models with lighting off, so shove the
* so shove the material color in texture factor and modify the * material color in texture factor and modify the texture stage to use it
* texture stage to use it instead of the vertex color (our models * instead of the vertex color (our models don't have vertex coloring anyway). */
* don't have vertex coloring anyway).
*/
DWORD bLighting; DWORD bLighting;
g_pd3dDevice->GetRenderState( D3DRS_LIGHTING, &bLighting ); g_pd3dDevice->GetRenderState( D3DRS_LIGHTING, &bLighting );
@@ -1389,15 +1369,15 @@ void RageDisplay_D3D::SetLightDirectional(
light.Type = D3DLIGHT_DIRECTIONAL; light.Type = D3DLIGHT_DIRECTIONAL;
/* Z for lighting is flipped for D3D compared to OpenGL. /* Z for lighting is flipped for D3D compared to OpenGL.
* XXX: figure out exactly why this is needed. Our transforms * XXX: figure out exactly why this is needed. Our transforms are probably
* are probably goofed up, but the Z test is the same for both * goofed up, but the Z test is the same for both API's, so I'm not sure
* API's, so I'm not sure why we don't see other weirdness. -Chris */ * why we don't see other weirdness. -Chris */
float position[] = { dir.x, dir.y, -dir.z }; float position[] = { dir.x, dir.y, -dir.z };
memcpy( &light.Direction, position, sizeof(position) ); memcpy( &light.Direction, position, sizeof(position) );
memcpy( &light.Diffuse, diffuse, sizeof(diffuse) ); memcpy( &light.Diffuse, diffuse, sizeof(diffuse) );
memcpy( &light.Ambient, ambient, sizeof(ambient) ); memcpy( &light.Ambient, ambient, sizeof(ambient) );
memcpy( &light.Specular, specular, sizeof(specular) ); memcpy( &light.Specular, specular, sizeof(specular) );
// Same as OpenGL defaults. Not used in directional lights. // Same as OpenGL defaults. Not used in directional lights.
// light.Attenuation0 = 1; // light.Attenuation0 = 1;
// light.Attenuation1 = 0; // light.Attenuation1 = 0;
@@ -1494,7 +1474,7 @@ void RageDisplay_D3D::UpdateTexture(
{ {
IDirect3DTexture8* pTex = (IDirect3DTexture8*)uTexHandle; IDirect3DTexture8* pTex = (IDirect3DTexture8*)uTexHandle;
ASSERT( pTex != NULL ); ASSERT( pTex != NULL );
RECT rect; RECT rect;
rect.left = xoffset; rect.left = xoffset;
rect.top = yoffset; rect.top = yoffset;
@@ -1503,15 +1483,13 @@ void RageDisplay_D3D::UpdateTexture(
D3DLOCKED_RECT lr; D3DLOCKED_RECT lr;
pTex->LockRect( 0, &lr, &rect, 0 ); pTex->LockRect( 0, &lr, &rect, 0 );
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
pTex->GetLevelDesc(0, &desc); pTex->GetLevelDesc(0, &desc);
ASSERT( xoffset+width <= int(desc.Width) ); ASSERT( xoffset+width <= int(desc.Width) );
ASSERT( yoffset+height <= int(desc.Height) ); ASSERT( yoffset+height <= int(desc.Height) );
//
// Copy bits // Copy bits
//
#if defined(XBOX) #if defined(XBOX)
RageSurface *Texture = CreateSurface( width, height, 32, RageSurface *Texture = CreateSurface( width, height, 32,
Swap32BE( 0x0000FF00 ), Swap32BE( 0x0000FF00 ),
@@ -1559,7 +1537,7 @@ RageMatrix RageDisplay_D3D::GetOrthoMatrix( float l, float r, float b, float t,
{ {
RageMatrix m = RageDisplay::GetOrthoMatrix( l, r, b, t, zn, zf ); RageMatrix m = RageDisplay::GetOrthoMatrix( l, r, b, t, zn, zf );
/* Convert from OpenGL's [-1,+1] Z values to D3D's [0,+1]. */ // Convert from OpenGL's [-1,+1] Z values to D3D's [0,+1].
RageMatrix tmp; RageMatrix tmp;
RageMatrixScaling( &tmp, 1, 1, 0.5f ); RageMatrixScaling( &tmp, 1, 1, 0.5f );
RageMatrixMultiply( &m, &tmp, &m ); RageMatrixMultiply( &m, &tmp, &m );
@@ -1577,10 +1555,8 @@ void RageDisplay_D3D::SetSphereEnvironmentMapping( TextureUnit tu, bool b )
void RageDisplay_D3D::SetCelShaded( bool b ) void RageDisplay_D3D::SetCelShaded( bool b )
{ {
/* yo AJ doesn't know what the fuck is going on and he's the only one /* AJ doesn't know how to deal with this and he's the only one of the
* of the sm-ssc team who's touched DirectX in C++ (for all of an hour) * sm-ssc team who's touched DirectX in C++ (for all of an hour). */
* and idkwtf.
*/
} }
/* /*