Jump to content
  • Advertisement
Sign in to follow this  
zlatko_bre_1985

Comments on code

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ill be glad to here comments on this code (sarcasm welcome); This code is used for enumerating graphic modes available and creating device with parameters given.It is c++ and DirectX.Also if you think that this needs implementation of some more features, or some changes to design ,.. everything is welcome.
#ifndef Z_D3DGraphics_h
#define Z_D3DGraphics_h

#include "Z_D3D.h"  // here is defined ZpD3D and its destructor 
#include <vector>
#include "d3d9types.h"

class Z_D3DGraphics:public Z_D3D
{

public:
	Z_D3DGraphics(UINT Width,UINT Height,UINT RefreshRate,bool FullScreen,HWND g_hWnd,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat);
	~Z_D3DGraphics(){SafeRelease(pD3DDevice);}
	void SetRenderState(D3DRENDERSTATETYPE RenderStateType,DWORD value);
	LPDIRECT3DDEVICE9			pD3DDevice;
private:
	std::vector<D3DDISPLAYMODE>	ZDisplayModes;
	D3DDISPLAYMODE				ZD3Ddm;
	int							nFoundMode;
	bool						ZbFullscreen;
	D3DCAPS9					ZD3DCaps;
	DWORD						ZdwBehaviorFlags;
	D3DPRESENT_PARAMETERS		ZD3Dpp;
	
};

Z_D3DGraphics::Z_D3DGraphics(UINT Width,UINT Height,UINT RefreshRate,bool Fullscreen,HWND g_hWnd,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat):
ZdwBehaviorFlags(0),ZbFullscreen(Fullscreen),nFoundMode(-1)
{
	D3DDISPLAYMODE D3Ddm;
	int n;

	n = ZpD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8 );
	for( int i = 0; i < n; i++ )
	{
		if( FAILED( ZpD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, i, &D3Ddm ) ) )
		{//EnumAdapterModes FAILED<<<<<<<
		}
		else{
			ZDisplayModes.push_back(D3Ddm); //EnumAdapterModes SUCCEDED	
		}
	};
	n = ZpD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT, D3DFMT_A2R10G10B10 );
	for( int i = 0; i < n; i++ )
	{
		if( FAILED( ZpD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, D3DFMT_A2R10G10B10, i, &D3Ddm ) ) )
		{//EnumAdapterModes FAILED<<<<<<<
		}
		else{
			ZDisplayModes.push_back(D3Ddm); //EnumAdapterModes SUCCEDED	
		}
	};
	n = ZpD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT, D3DFMT_R5G6B5 );
	for( int i = 0; i < n; i++ )
	{
		if( FAILED( ZpD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, D3DFMT_R5G6B5, i, &D3Ddm ) ) )
		{//EnumAdapterModes FAILED<<<<<<<
		}
		else{
			ZDisplayModes.push_back(D3Ddm); //EnumAdapterModes SUCCEDED	
		}
	};
	n = ZpD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT, D3DFMT_X1R5G5B5 );
	for( int i = 0; i < n; i++ )
	{
		if( FAILED( ZpD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, D3DFMT_X1R5G5B5, i, &D3Ddm ) ) )
		{//EnumAdapterModes FAILED<<<<<<<
		}
		else{
			ZDisplayModes.push_back(D3Ddm); //EnumAdapterModes SUCCEDED	
		}
	};

    
	for ( UINT i = 0;i < ZDisplayModes.size();i++)
	{
		if (ZDisplayModes.at(i).Width != Width || ZDisplayModes.at(i).Height != Height)
			continue;
		if (ZDisplayModes.at(i).RefreshRate != RefreshRate)
			continue;
		if (ZDisplayModes.at(i).Format != DisplayFormat)
			continue;
		nFoundMode = i;
		break;
	};

	if( nFoundMode == -1 )
	{
		MessageBox(NULL,"Desired mode not found","Z_D3DGraphics.h" , 1);
	}
	
	


	if( FAILED( ZpD3D->CheckDeviceType( D3DADAPTER_DEFAULT,
										 D3DDEVTYPE_HAL,
										 ZDisplayModes.at(nFoundMode).Format,
										 BackBufferFormat,
										 !Fullscreen ) ) )
	{
		MessageBox(NULL,"Desired back buffer unavailable","Z_D3DGraphics.h", 1);
	}

	if( FAILED( ZpD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT,
                                           D3DDEVTYPE_HAL,
										   ZDisplayModes.at(nFoundMode).Format,
                                           D3DUSAGE_DEPTHSTENCIL,
                                           D3DRTYPE_SURFACE,
                                           D3DFMT_D24S8) ) )
    {
		MessageBox(NULL,"16 bit z-buffer unavailable","ZD3DGraphics Error", 1);
	}
	
	
	///*32 bit-ni buffer ???*/
	if( FAILED( ZpD3D->CheckDeviceType( D3DADAPTER_DEFAULT,
										 D3DDEVTYPE_HAL,
										 ZDisplayModes.at(nFoundMode).Format,
										 BackBufferFormat,
										 !Fullscreen ) ) )
	{
		MessageBox(NULL,"Desired back buffer unavailable","Z_D3DGraphics.h", 1);
	}
	
	


	if( FAILED( ZpD3D->GetDeviceCaps( D3DADAPTER_DEFAULT,
									   D3DDEVTYPE_HAL, &ZD3DCaps ) ) )
	{
		MessageBox(NULL,"Get Device Caps failed!!!","Z_D3DGraphics.h", 1);
	}
	
	//*Hardware or Software processing ???*/
	if( ZD3DCaps.VertexProcessingCaps != 0 )
		ZdwBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
	else
		ZdwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;


	ZeroMemory(&ZD3Dpp,sizeof(ZD3Dpp));
	
	ZD3Dpp.Windowed					= !Fullscreen;
	if (Fullscreen == true)
	{
		ZD3Dpp.BackBufferWidth			= Width;
		ZD3Dpp.BackBufferHeight			= Height;
	}
	else
	{
		ZD3Dpp.BackBufferWidth			= NULL;
		ZD3Dpp.BackBufferHeight			= NULL;
	};
	ZD3Dpp.PresentationInterval		= D3DPRESENT_INTERVAL_IMMEDIATE;
	ZD3Dpp.SwapEffect				= D3DSWAPEFFECT_DISCARD;
	ZD3Dpp.BackBufferCount			= 1;
	ZD3Dpp.BackBufferFormat			= BackBufferFormat;
	if (Fullscreen == false)
		ZD3Dpp.FullScreen_RefreshRateInHz = 0;
	else
		ZD3Dpp.FullScreen_RefreshRateInHz = RefreshRate;
	ZD3Dpp.EnableAutoDepthStencil	= true;
	ZD3Dpp.AutoDepthStencilFormat	= D3DFMT_D24S8;
	
#ifdef PerfHud
	if( FAILED( pD3D->CreateDevice(pD3D->GetAdapterCount()-1,D3DDEVTYPE_REF,g_hWnd,
		dwBehaviorFlags, &D3Dpp,&D3DDevice ) ) )
	{
		/*Create device failed*/
		MessageBox(NULL,"Create device failed","Z_D3DGraphics.h" , 1);
	}
#else
	if( FAILED(ZpD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
									  ZdwBehaviorFlags, &ZD3Dpp,&pD3DDevice ) ) )
	{
		/*Create device failed*/
		MessageBox(NULL,"Create device failed","Z_D3DGraphics.h" , 1);
	}
#endif
};


void Z_D3DGraphics::SetRenderState(D3DRENDERSTATETYPE RenderStateType,DWORD value)
{
	pD3DDevice->SetRenderState(RenderStateType,value);
};

#endif
[\source]

[Edited by - zlatko_bre_1985 on July 24, 2005 1:06:17 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!