Esempio n. 1
0
RString RageDisplay_D3D::Init( const VideoModeParams &p, bool /* bAllowUnacceleratedRenderer */ )
{
	GraphicsWindow::Initialize( true );

	LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" );
	LOG->MapLog("renderer", "Current renderer: Direct3D");

	g_pd3d = Direct3DCreate9(D3D_SDK_VERSION);
	if(!g_pd3d)
	{
		LOG->Trace( "Direct3DCreate9 failed" );
		return D3D_NOT_INSTALLED.GetValue();
	}

	if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) )
		return HARDWARE_ACCELERATION_NOT_AVAILABLE.GetValue();
			

	D3DADAPTER_IDENTIFIER9	identifier;
	g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier );

	LOG->Trace( 
		"Driver: %s\n"
		"Description: %s\n"
		"Max texture size: %d\n"
		"Alpha in palette: %s\n",
		identifier.Driver, 
		identifier.Description,
		g_DeviceCaps.MaxTextureWidth,
		(g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) ? "yes" : "no" );

	LOG->Trace( "This display adaptor supports the following modes:" );
	D3DDISPLAYMODE mode;

	UINT modeCount = g_pd3d->GetAdapterModeCount(D3DADAPTER_DEFAULT, g_DefaultAdapterFormat);

	for( UINT u=0; u < modeCount; u++ )
		if( SUCCEEDED( g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, g_DefaultAdapterFormat, u, &mode ) ) )
			LOG->Trace( "  %ux%u %uHz, format %d", mode.Width, mode.Height, mode.RefreshRate, mode.Format );

	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 );

	/* 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. */
	bool bIgnore = false;
	return SetVideoMode( p, bIgnore );
}
Esempio n. 2
0
/*********************************************************************
* initDirect3D
* initializes direct3D
*********************************************************************/
bool initDirect3D()
{
	pD3D = NULL;

	// create the directX object
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		return false;
	}

	// this section gets the adapter details
	D3DADAPTER_IDENTIFIER9 ident;
	pD3D->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident);	
	addItemToList("Adapter Details");
	addItemToList(ident.Description);
	addItemToList(ident.DeviceName);
	addItemToList(ident.Driver);
	
	// collects how many modes this adapter has
	UINT numModes = pD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8);
	for (UINT i=0; i<numModes-1; i++)
	{
		D3DDISPLAYMODE mode;
		char modeString[255];
		// get the displaymode structure for this adapter mode
		pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, i, &mode);

		// draw a blank line in the listbox
		addItemToList("");
		// output the width
		sprintf(modeString, "Width=%d",mode.Width);
		addItemToList(modeString);
		// output the height
		sprintf(modeString, "Height=%d",mode.Height);		
		addItemToList(modeString);
		// output the refreshrate
		sprintf(modeString, "RefreshRate=%d",mode.RefreshRate);		
		addItemToList(modeString);		
	}	
	
	return true;
}
Esempio n. 3
0
HRESULT HookIDirect3D9::GetAdapterIdentifier(LPVOID _this, UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier)
{
	LOG_API();
	return pD3D->GetAdapterIdentifier(Adapter, Flags, pIdentifier);
}
Esempio n. 4
0
CString RageDisplay_D3D::Init( VideoModeParams p )
{
	GraphicsWindow::Initialize();

	LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" );
	LOG->MapLog("renderer", "Current renderer: Direct3D");

	typedef IDirect3D9 * (WINAPI * Direct3DCreate9_t) (UINT SDKVersion);
	Direct3DCreate9_t pDirect3DCreate9;
#if defined(XBOX)
	pDirect3DCreate8 = Direct3DCreate8;
#else
	g_D3D9_Module = LoadLibrary("D3D9.dll");
	if(!g_D3D9_Module)
		return D3D_NOT_INSTALLED;

	pDirect3DCreate9 = (Direct3DCreate9_t) GetProcAddress(g_D3D9_Module, "Direct3DCreate9");
	if(!pDirect3DCreate9)
	{
		LOG->Trace( "Direct3DCreate9 not found" );
		return D3D_NOT_INSTALLED;
	}
#endif

	g_pd3d = pDirect3DCreate9( D3D_SDK_VERSION );
	if(!g_pd3d)
	{
		LOG->Trace( "Direct3DCreate9 failed" );
		return D3D_NOT_INSTALLED;
	}

	if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) )
		return
			"Your system is reporting that Direct3D hardware acceleration is not available.  "
			"Please obtain an updated driver from your video card manufacturer.\n\n";

	D3DADAPTER_IDENTIFIER9	identifier;
	g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier );

	LOG->Trace( 
		"Driver: %s\n"
		"Description: %s\n"
		"Max texture size: %d\n"
		"Alpha in palette: %s\n",
		identifier.Driver, 
		identifier.Description,
		g_DeviceCaps.MaxTextureWidth,
		(g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) ? "yes" : "no" );

	LOG->Trace( "This display adaptor supports the following modes:" );
	D3DDISPLAYMODE mode;
	UINT modeCount = g_pd3d->GetAdapterModeCount(D3DADAPTER_DEFAULT, g_DefaultAdapterFormat);
	
	for( UINT u=0; u<modeCount; u++ )
		if( SUCCEEDED( g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, g_DefaultAdapterFormat, u, &mode ) ) )
			LOG->Trace( "  %ux%u %uHz, format %d", mode.Width, mode.Height, mode.RefreshRate, mode.Format );

	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 );

	/* 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. */
	bool bIgnore = false;
	return SetVideoMode( p, bIgnore );
}
Esempio n. 5
0
HRESULT KGraphicsEngine::InitializeWindowed(HWND hBaseWindow, HWND hRenderWindow)
{
	// Create the D3D object.
    if ( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBox(hBaseWindow,"Failed Create the D3D object!.","Failed Create the D3D object!",0);
        return E_FAIL;
	}
    // Get the current desktop display mode, so we can set up a back
    // buffer of the same format
	g_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&g_D3DCaps);

    if ( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &m_DisplayMode ) ) )
	{
		MessageBox(hBaseWindow,"Failed GetAdapterDisplayMode !.","Failed Create the D3D object!",0);
		return E_FAIL;
	}
     
    // Set up the structure used to create the D3DDevice
	D3DFORMAT  DepFormat;
	if (SUCCEEDED(g_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		m_DisplayMode.Format,
		m_DisplayMode.Format,
		D3DFMT_D24S8)))
	{
		DepFormat = D3DFMT_D24S8;
	}
	else
	{
		DepFormat = D3DFMT_D16;
	}

    memset( &m_PresentParam, 0, sizeof(D3DPRESENT_PARAMETERS) );

    memset(&m_RenderWindowRect, 0, sizeof(m_RenderWindowRect));	

	if(hRenderWindow)
		::GetWindowRect(hRenderWindow,&m_RenderWindowRect);
	else
	{
		::GetWindowRect(hBaseWindow,&m_RenderWindowRect);
		hRenderWindow = hBaseWindow;
	}
		
	//m_PresentParam.BackBufferWidth = m_RenderWindowRect.right-m_RenderWindowRect.left ;
    //m_PresentParam.BackBufferHeight= m_RenderWindowRect.bottom - m_RenderWindowRect.top;
	m_PresentParam.BackBufferWidth = m_DisplayMode.Width ;
	m_PresentParam.BackBufferHeight= m_DisplayMode.Height;

    m_PresentParam.Windowed = TRUE ;
    m_PresentParam.SwapEffect = D3DSWAPEFFECT_DISCARD;
    m_PresentParam.BackBufferFormat = m_DisplayMode.Format;
	m_PresentParam.EnableAutoDepthStencil = TRUE;
    m_PresentParam.AutoDepthStencilFormat = DepFormat;
    m_PresentParam.MultiSampleType = D3DMULTISAMPLE_NONE;
    m_PresentParam.hDeviceWindow = hBaseWindow;
    m_PresentParam.Flags = 0;
    m_PresentParam.FullScreen_RefreshRateInHz = 0;
    m_PresentParam.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	//just set camera's aspect
	m_cCamera.Aspect = m_PresentParam.BackBufferWidth*1.0f/m_PresentParam.BackBufferHeight; 

	HRESULT hr;

	// Set default settings
	UINT AdapterToUse=D3DADAPTER_DEFAULT;
	D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL;
//#if SHIPPING_VERSION
	// When building a shipping version, disable NVPerfHUD (opt-out)
//#else
	// Look for 'NVIDIA NVPerfHUD' adapter
	// If it is present, override default settings
	for (UINT Adapter=0;Adapter<g_pD3D->GetAdapterCount();Adapter++)
	{
		D3DADAPTER_IDENTIFIER9 Identifier;
		HRESULT Res=g_pD3D->GetAdapterIdentifier(Adapter,0,&Identifier);
		if (strcmp(Identifier.Description,"NVIDIA NVPerfHUD")==0)
		{
			AdapterToUse=Adapter;
			DeviceType=D3DDEVTYPE_REF;
			break;
		}
	}
//#endif

    // Create the D3DDevice
    /*if ( FAILED(hr = g_pD3D->CreateDevice( AdapterToUse, DeviceType, hBaseWindow,
                                      D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                      &m_PresentParam, &g_pd3dDevice ) ) )
    {*/
		if ( FAILED(hr = g_pD3D->CreateDevice( AdapterToUse, DeviceType, hBaseWindow,
                                      D3DCREATE_MIXED_VERTEXPROCESSING,
                                      &m_PresentParam, &g_pd3dDevice ) ) )
		{
			if ( FAILED(hr = g_pD3D->CreateDevice( AdapterToUse, DeviceType, hBaseWindow,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &m_PresentParam, &g_pd3dDevice ) ) )
			{
				
				if (hr == D3DERR_INVALIDCALL)
					MessageBox(hBaseWindow,"The method call is invalid. For example, a method's parameter may have an invalid value.","Failed Create Device!",0);
				else if (hr == E_OUTOFMEMORY )
					MessageBox(hBaseWindow,"Direct3D could not allocate sufficient memory to complete the call.","Failed Create Device!",0);
				else if (hr == D3DERR_OUTOFVIDEOMEMORY)
					MessageBox(hBaseWindow,"Direct3D does not have enough display memory to perform the operation. ","Failed Create Device!",0);
				return E_FAIL;
			}
		}
	
  /*  }*/
    
//	D3DMULTISAMPLE_TYPE Mul = D3DMULTISAMPLE_4_SAMPLES;
//
//	if( FAILED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//			D3DDEVTYPE_HAL, m_PresentParam.BackBufferFormat, 
//			FALSE, Mul, NULL ) ) &&
//			SUCCEEDED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//			D3DDEVTYPE_HAL, m_PresentParam.AutoDepthStencilFormat, 
//			FALSE, Mul, NULL ) ) )
//	{
//		Mul = D3DMULTISAMPLE_3_SAMPLES; 
//
//		if( FAILED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//			D3DDEVTYPE_HAL, m_PresentParam.BackBufferFormat, 
//			FALSE, Mul, NULL ) ) &&
//			SUCCEEDED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//			D3DDEVTYPE_HAL, m_PresentParam.AutoDepthStencilFormat, 
//			FALSE, Mul, NULL ) ) )
//		{
//			Mul = D3DMULTISAMPLE_2_SAMPLES; 
//
//			if( FAILED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//				D3DDEVTYPE_HAL, m_PresentParam.BackBufferFormat, 
//				FALSE, Mul, NULL ) ) &&
//				SUCCEEDED(g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, 
//				D3DDEVTYPE_HAL, m_PresentParam.AutoDepthStencilFormat, 
//				FALSE, Mul, NULL ) ) )
//			{
//				Mul = D3DMULTISAMPLE_NONE; 
//			}
//		}
//	}
//	if (Mul != D3DMULTISAMPLE_NONE)
//	{
//		m_PresentParam.MultiSampleType = Mul;
//		g_pd3dDevice->Reset( &m_PresentParam );
//	}
    
    // Device state would normally be set here
	// Turn off culling, so we see the front and back of the triangle
     g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW  );

    // Turn off D3D lighting, since we are providing our own vertex colors

    // Turn on the zbuffer
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
    //g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE , TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL  );

	g_cGraphicsTool.SetCurCamera(&m_cCamera);
	
	PreRender(); 
	m_bWindowed = TRUE;
    
	if (m_bUseMotionBlur)
	{
		BackBufferCreate();
		
		g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL,
			0xff666666, 1.0f, 0 );
	}

	return S_OK;
}
Esempio n. 6
0
void initD3D()
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS PresentParams;
	memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));

	PresentParams.Windowed = TRUE;
	PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;

	///////////////////////////////////////////////////////////////////////

	// Set default settings
	UINT AdapterToUse = D3DADAPTER_DEFAULT;
	D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
#ifdef SHIPPING_VERSION
	if(FAILED(d3d->CreateDevice(AdapterToUse, DeviceType, hMainWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&PresentParams, &device)))
	{
		MessageBoxA(hMainWnd, "Unable to initialize PerfectHUD", 0, MB_ICONHAND);
		terminate();
	}
#else
	// Look for 'NVIDIA PerfHUD' adapter
	// If it is present, override default settings
	for (UINT Adapter = 0; Adapter < d3d->GetAdapterCount(); Adapter++)
	{
		D3DADAPTER_IDENTIFIER9  Identifier;
		HRESULT  Res;
		Res = d3d->GetAdapterIdentifier(Adapter, 0, &Identifier);
		if (strstr(Identifier.Description, "PerfHUD") != 0)
		{
			AdapterToUse = Adapter;
			DeviceType = D3DDEVTYPE_REF;
			break;
		}
	}
#endif

	//////////////////////////////////////////////////////////////////////

	device->SetRenderState(D3DRS_POINTSIZE_MAX, *((DWORD*)&pointSize));
	device->SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&pointSize));
	device->SetRenderState(D3DRS_LIGHTING, FALSE);
	device->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
	device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	device->SetRenderState(D3DRS_ZENABLE, FALSE);

	D3DXCreateTextureFromFile(device, L"particle.png", &particleTexture);
	D3DXCreateTextureFromFile(device, L"overlay.png", &overlayTexture);

	D3DXCreateTexture(device, Width, Height, 0, D3DUSAGE_RENDERTARGET, D3DFMT_X8B8G8R8, D3DPOOL_DEFAULT, &renderTexture);
	renderTexture->GetSurfaceLevel(0, &renderTarget);
	device->GetRenderTarget(0, &orig);

	//»нициализаци¤ матриц
	D3DXMATRIX matrixView;
	D3DXMATRIX matrixProjection;

	D3DXMatrixLookAtLH(
		&matrixView,
		&D3DXVECTOR3(0, 0, 0),
		&D3DXVECTOR3(0, 0, 1),
		&D3DXVECTOR3(0, 1, 0));

	D3DXMatrixOrthoOffCenterLH(&matrixProjection, 0, Width, Height, 0, 0, 255);

	device->SetTransform(D3DTS_VIEW, &matrixView);
	device->SetTransform(D3DTS_PROJECTION, &matrixProjection);

	device->SetTexture(0, particleTexture);
}