コード例 #1
0
BOOL FindDepthStencilFormat(UINT iAdapter, D3DDEVTYPE DeviceType,
    D3DFORMAT TargetFormat, D3DFORMAT *pDepthStencilFormat)
{
	// prima lo cerco a 32bit, poi a 24 e infine a 16...e se non
	// c'è vaffanculo alla tua scheda grafica.

    if (SUCCEEDED(g_pD3D->CheckDeviceFormat(iAdapter, DeviceType,
                  TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32)))
    {
       if (SUCCEEDED(g_pD3D->CheckDepthStencilMatch(iAdapter, DeviceType,
                TargetFormat, TargetFormat, D3DFMT_D32)))
       {
           *pDepthStencilFormat = D3DFMT_D32;
           return TRUE;
       }
    }

    
	if (SUCCEEDED(g_pD3D->CheckDeviceFormat( iAdapter, DeviceType,
                  TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8)))
    {
       if (SUCCEEDED(g_pD3D->CheckDepthStencilMatch(iAdapter, DeviceType,
                     TargetFormat, TargetFormat, D3DFMT_D24X8 )))
       {
           *pDepthStencilFormat = D3DFMT_D24X8;
           return TRUE;
       }
    }

    
	if(SUCCEEDED(g_pD3D->CheckDeviceFormat(iAdapter, DeviceType,
                 TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8)))
    {
       if(SUCCEEDED(g_pD3D->CheckDepthStencilMatch(iAdapter, DeviceType,
                    TargetFormat, TargetFormat, D3DFMT_D24S8)))
       {
           *pDepthStencilFormat = D3DFMT_D24S8;
           return TRUE;
       }
    }
    
	
	if (SUCCEEDED(g_pD3D->CheckDeviceFormat(iAdapter, DeviceType,
                  TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16)))
    {
       if (SUCCEEDED(g_pD3D->CheckDepthStencilMatch( iAdapter, DeviceType,
                     TargetFormat, TargetFormat, D3DFMT_D16)))
       {
           *pDepthStencilFormat = D3DFMT_D16;
            return TRUE;
       }
    }
    return FALSE;
}
コード例 #2
0
ファイル: RageDisplay_D3D.cpp プロジェクト: augustg/openitg
bool RageDisplay_D3D::SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime )
{
#if defined(XBOX)
	// Lazy...  Xbox handles paletted textures completely differently
	// than D3D and I don't want to add a bunch of code for it.  Also, 
	// paletted textures result in worse cache efficiency (see "Xbox 
	// Palettized Texture Performance" in XDK).  So, we'll force 32bit
	// ARGB textures.  -Chris
	// This is also needed for XGSwizzleRect().
	return pixfmt == FMT_RGBA8;
#endif

	// Some cards (Savage) don't support alpha in palettes.
	// Don't allow paletted textures if this is the case.
	if( pixfmt == FMT_PAL  &&  !(g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) )
		return false;

	if(	D3DFORMATS[pixfmt] == D3DFMT_UNKNOWN )
		return false;

	D3DFORMAT d3dfmt = D3DFORMATS[pixfmt];
	HRESULT hr = g_pd3d->CheckDeviceFormat( 
		D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		g_d3dpp.BackBufferFormat,
		0,
		D3DRTYPE_TEXTURE,
		d3dfmt);

    return SUCCEEDED( hr );
}
コード例 #3
0
ファイル: depth_texture.cpp プロジェクト: 007au/gedosato
//--------------------------------------------------------------------------------------
DepthTexture::DepthTexture(const LPDIRECT3D9 d3d) {
	D3DDISPLAYMODE currentDisplayMode;
	d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &currentDisplayMode);

	// determine if RESZ is supported
	m_isRESZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
		currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, FOURCC_RESZ) == D3D_OK;
	SDLOG(-1, "[DepthTexture] RESZ: %s\n", m_isRESZ?"true":"false");

	// determine if INTZ is supported
	m_isINTZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
		currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, FOURCC_INTZ) == D3D_OK;
	SDLOG(-1, "[DepthTexture] INTZ: %s\n", m_isINTZ ? "true" : "false");

	// determine if RAWZ is supported, used in GeForce 6-7 series.
	m_isRAWZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
		currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, FOURCC_RAWZ) == D3D_OK;
	SDLOG(-1, "[DepthTexture] RAWZ: %s\n", m_isRAWZ ? "true" : "false");

	// determine if RESZ or NVAPI supported
	m_isSupported = (NvAPI_Initialize() == NVAPI_OK || m_isRESZ) && (m_isRAWZ || m_isINTZ);
}
コード例 #4
0
bool RageDisplay_D3D::SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime )
{
	// Some cards (Savage) don't support alpha in palettes.
	// Don't allow paletted textures if this is the case.
	if( pixfmt == RagePixelFormat_PAL  &&  !(g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) )
		return false;

	if( D3DFORMATS[pixfmt] == D3DFMT_UNKNOWN )
		return false;

	D3DFORMAT d3dfmt = D3DFORMATS[pixfmt];
	HRESULT hr = g_pd3d->CheckDeviceFormat( 
		D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		g_d3dpp.BackBufferFormat,
		0,
		D3DRTYPE_TEXTURE,
		d3dfmt);

	return SUCCEEDED( hr );
}
コード例 #5
0
ファイル: D3DWrapper.cpp プロジェクト: zxmarcos/bg4t_monitor
HRESULT HookIDirect3D9::CheckDeviceFormat(LPVOID _this, UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat)
{
	LOG_API();
	return pD3D->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
}
コード例 #6
0
ファイル: dx9rad3d.cpp プロジェクト: F5000/spree
inline u32 is_valid_texture_format(LPDIRECT3D9 direct_3d,
    D3DFORMAT TextureFormat, D3DFORMAT AdapterFormat )
{
    return SUCCEEDED( direct_3d->CheckDeviceFormat( D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL, AdapterFormat, 0, D3DRTYPE_TEXTURE, TextureFormat) );
}
コード例 #7
0
ファイル: Myd3d.cpp プロジェクト: xiaohuaxiong/hello-world
//查询用到的特性,必须支持的,将RESULT置EFAIL,只是提示的就不用置了。
HRESULT DetectDeviceCaps()
{
	HRESULT Result=S_OK;
	//必须支持的特性
	if(d3dcaps.MaxTextureBlendStages<4) {mymessage("支持的纹理混合层太少!"); Result=E_FAIL;}
	if(d3dcaps.MaxSimultaneousTextures<2) {mymessage("支持的纹理流水层太少!");Result=E_FAIL;}
	if(DesktopDisplayMode.Format == D3DFMT_R5G6B5) mymessage("建议将桌面显示模式设置为32位真彩色,否则在切换到窗口模式时可能会出现问题!")

//立方纹理
#ifdef USE_CUBEMAPENVIRONMENT
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, d3ddm.Format)))	{mymessage("不支持RENDERTARGET纹理格式"); Result=E_FAIL;}
	if((d3dcaps.TextureCaps&D3DPTEXTURECAPS_CUBEMAP)==0) {mymessage("不支持立方纹理!"); Result=E_FAIL;}
#endif USE_CUBEMAPENVIRONMENT
#ifdef USE_CUBEMAP
	if((d3dcaps.TextureCaps&D3DPTEXTURECAPS_CUBEMAP)==0) {mymessage("不支持立方纹理!"); Result=E_FAIL;}
#endif USE_CUBEMAP

//渲染到纹理
#ifdef USE_RENDERTOTEXTURE
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, d3ddm.Format)))	{mymessage("不支持RENDERTARGET纹理格式"); Result=E_FAIL;}
#endif USE_RENDERTOTEXTURE

//像素光照
#ifdef USE_DOTPRODUCT3
	if((d3dcaps.TextureOpCaps&D3DTEXOPCAPS_DOTPRODUCT3)==0) {mymessage("不支持DOT3内积纹理混合!"); Result=E_FAIL;}
	if((d3dcaps.SrcBlendCaps&D3DPBLENDCAPS_DESTCOLOR)==0) {mymessage("不支持源COLOR多重纹理混合!"); Result=E_FAIL;}
	if((d3dcaps.DestBlendCaps&D3DPBLENDCAPS_SRCCOLOR)==0) {mymessage("不支持目的COLOR多重纹理混合!"); Result=E_FAIL;}
#endif USE_DOTPRODUCT3

	//非必须支持的特性,尽量不要弹出提示对话框,很可能在XP下有问题

//PixelShader,Vertex Shader的话强制用软件顶点处理就行了
#ifdef USE_PIXELSHADER
	// 一定要预先在这里判断,如果硬件不支持shader,用GetShaderProfile将会返回空指针,造成后面shader版本检测非法操作
	if((d3dcaps.PixelShaderVersion&0xffff) == 0) {mymessage("不支持Pixel Shader!"); Result=E_FAIL;}
#endif USE_PIXELSHADER

//凹凸环境映射
#ifdef USE_EMBM
	if((d3dcaps.TextureOpCaps&(D3DTEXOPCAPS_BUMPENVMAP|D3DTEXOPCAPS_BUMPENVMAPLUMINANCE))==0) {mymessage("注意:显卡不支持凹凸环境映射,必须改用普通环境映射,这样做会降低画面质量!");}
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_0, D3DRTYPE_TEXTURE, D3DFMT_V8U8))) {mymessage("不支持凹凸环境映射V8U8格式"); Result=E_FAIL;}
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_0, D3DRTYPE_TEXTURE, D3DFMT_X8L8V8U8))) {mymessage("不支持凹凸环境映射X8L8V8U8格式"); Result=E_FAIL;}
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_0, D3DRTYPE_TEXTURE, D3DFMT_L6V5U5))) {mymessage("不支持凹凸环境映射L6V6U6格式"); Result=E_FAIL;}
#endif USE_EMBM


// 浮点纹理
#ifdef USE_FP16 
	bool bHDRFP16 = true;
	// 浮点纹理一般都是作为RT使用的,比如MRT或HDR
	// GF6/7不支持R16F,只支持G16R16F,所以这里就不检测R16F了,因为GF6/7都不支持
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_G16R16F)))
		bHDRFP16 = false;
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)))
		bHDRFP16 = false;
	if(!bHDRFP16)
	{
		mymessage("不支持FP16半精度浮点纹理(HDR)!");
		Result = E_FAIL;
	}
#endif
	
#ifdef USE_FP32
	bool bHDRFP32 = true;
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_R32F)))
		bHDRFP32 = false;
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)))
		bHDRFP32 = false;
	if(!bHDRFP32)
	{
		mymessage("不支持FP32全精度浮点纹理(HDR)!");
		Result = E_FAIL;
	}
#endif



// 顶点纹理取样
#ifdef USE_VTF
	bool bVTF = true;
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R32F)))
		bVTF = false;
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)))
		bVTF = false;
	if(!bVTF)
	{
		mymessage("不支持顶点纹理取样(VTF)!");
		Result = E_FAIL;
	}
#endif


	//其他
	if(d3dcaps.NumSimultaneousRTs < USE_MAXMRTNUM)
	{
		char szErrorInfo[50];
		int iNum = USE_MAXMRTNUM;
		sprintf(szErrorInfo, "硬件不支持%d个MRT!", iNum);
		mymessage(szErrorInfo);
		Result = E_FAIL;
	}

#ifdef USE_DYNAMICTEXTURE
	if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, d3ddm.Format)))	{mymessage("不支持动态纹理格式"); Result=E_FAIL;}
#endif USE_DYNAMICTEXTURE

	return Result;
}
コード例 #8
0
ファイル: D3D9Base.cpp プロジェクト: CTimpone/libretro-ppsspp
bool D3D9_Init(HWND wnd, bool windowed, std::string *error_message) {
    hWnd = wnd;

    DIRECT3DCREATE9EX g_pfnCreate9ex;

    hD3D9 = LoadLibrary(TEXT("d3d9.dll"));
    if (!hD3D9) {
        ELOG("Missing d3d9.dll");
        *error_message = "D3D9.dll missing - try reinstalling DirectX.";
        return false;
    }

    int d3dx_version = LoadD3DX9Dynamic();
    if (!d3dx_version) {
        *error_message = "D3DX DLL not found! Try reinstalling DirectX.";
        return false;
    }

    g_pfnCreate9ex = (DIRECT3DCREATE9EX)GetProcAddress(hD3D9, "Direct3DCreate9Ex");
    has9Ex = (g_pfnCreate9ex != NULL) && IsVistaOrHigher();

    if (has9Ex) {
        HRESULT result = g_pfnCreate9ex(D3D_SDK_VERSION, &d3dEx);
        d3d = d3dEx;
        if (FAILED(result)) {
            FreeLibrary(hD3D9);
            *error_message = "D3D9Ex available but context creation failed. Try reinstalling DirectX.";
            return false;
        }
    } else {
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
        if (!d3d) {
            FreeLibrary(hD3D9);
            *error_message = "Failed to create D3D9 context. Try reinstalling DirectX.";
            return false;
        }
    }

    D3DCAPS9 d3dCaps;

    D3DDISPLAYMODE d3ddm;
    if (FAILED(d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) {
        *error_message = "GetAdapterDisplayMode failed";
        d3d->Release();
        return false;
    }

    adapterId = D3DADAPTER_DEFAULT;
    if (FAILED(d3d->GetDeviceCaps(adapterId, D3DDEVTYPE_HAL, &d3dCaps))) {
        *error_message = "GetDeviceCaps failed (???)";
        d3d->Release();
        return false;
    }

    HRESULT hr;
    if (FAILED(hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT,
                                           D3DDEVTYPE_HAL,
                                           d3ddm.Format,
                                           D3DUSAGE_DEPTHSTENCIL,
                                           D3DRTYPE_SURFACE,
                                           D3DFMT_D24S8))) {
        if (hr == D3DERR_NOTAVAILABLE) {
            *error_message = "D24S8 depth/stencil not available";
            d3d->Release();
            return false;
        }
    }

    DWORD dwBehaviorFlags = D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE;
    if (d3dCaps.VertexProcessingCaps != 0)
        dwBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else
        dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    int xres, yres;
    GetRes(xres, yres);

    memset(&pp, 0, sizeof(pp));
    pp.BackBufferWidth = xres;
    pp.BackBufferHeight = yres;
    pp.BackBufferFormat = d3ddm.Format;
    pp.MultiSampleType = D3DMULTISAMPLE_NONE;
    pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    pp.Windowed = windowed;
    pp.hDeviceWindow = wnd;
    pp.EnableAutoDepthStencil = true;
    pp.AutoDepthStencilFormat = D3DFMT_D24S8;
    pp.PresentationInterval = (g_Config.bVSync) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;

    if (has9Ex) {
        if (windowed && IsWin7OrLater()) {
            // This new flip mode gives higher performance.
            // TODO: This makes it slower?
            //pp.BackBufferCount = 2;
            //pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
        }
        hr = d3dEx->CreateDeviceEx(adapterId, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &pp, NULL, &deviceEx);
        device = deviceEx;
    } else {
        hr = d3d->CreateDevice(adapterId, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &pp, &device);
    }

    if (FAILED(hr)) {
        *error_message = "Failed to create D3D device";
        d3d->Release();
        return false;
    }

    device->BeginScene();
    DX9::pD3Ddevice = device;
    DX9::pD3DdeviceEx = deviceEx;

    if (!DX9::CompileShaders(*error_message)) {
        *error_message = "Unable to compile shaders: " + *error_message;
        device->EndScene();
        device->Release();
        d3d->Release();
        DX9::pD3Ddevice = nullptr;
        DX9::pD3DdeviceEx = nullptr;
        device = nullptr;
        UnloadD3DXDynamic();
        return false;
    }

    DX9::fbo_init(d3d);

    if (deviceEx && IsWin7OrLater()) {
        // TODO: This makes it slower?
        //deviceEx->SetMaximumFrameLatency(1);
    }

    return true;
}
コード例 #9
0
ファイル: CD3D9Texture.cpp プロジェクト: Lumirion/pseuwow
//! creates the hardware texture
bool CD3D9Texture::createTexture(u32 flags, IImage * image)
{
	ImageSize = image->getDimension();

	core::dimension2d<u32> optSize = ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);

	D3DFORMAT format = D3DFMT_A1R5G5B5;

	switch(getTextureFormatFromFlags(flags))
	{
	case ETCF_ALWAYS_16_BIT:
		format = D3DFMT_A1R5G5B5; break;
	case ETCF_ALWAYS_32_BIT:
		format = D3DFMT_A8R8G8B8; break;
	case ETCF_OPTIMIZED_FOR_QUALITY:
		{
			switch(image->getColorFormat())
			{
			case ECF_R8G8B8:
			case ECF_A8R8G8B8:
				format = D3DFMT_A8R8G8B8; break;
			case ECF_A1R5G5B5:
			case ECF_R5G6B5:
				format = D3DFMT_A1R5G5B5; break;
			}
		}
		break;
	case ETCF_OPTIMIZED_FOR_SPEED:
		format = D3DFMT_A1R5G5B5;
		break;
	default:
		break;
	}
	if (Driver->getTextureCreationFlag(video::ETCF_NO_ALPHA_CHANNEL))
	{
		if (format == D3DFMT_A8R8G8B8)
			format = D3DFMT_R8G8B8;
		else if (format == D3DFMT_A1R5G5B5)
			format = D3DFMT_R5G6B5;
	}

	const bool mipmaps = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);

	DWORD usage = 0;

	// This enables hardware mip map generation.
	if (mipmaps && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE))
	{
		LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9;
		D3DDISPLAYMODE d3ddm;
		intf->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);

		if (D3D_OK==intf->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,d3ddm.Format,D3DUSAGE_AUTOGENMIPMAP,D3DRTYPE_TEXTURE,format))
		{
			usage = D3DUSAGE_AUTOGENMIPMAP;
			HardwareMipMaps = true;
		}
	}

	HRESULT hr = Device->CreateTexture(optSize.Width, optSize.Height,
		mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
		usage, // usage
		format, D3DPOOL_MANAGED , &Texture, NULL);

	if (FAILED(hr))
	{
		// try brute force 16 bit
		HardwareMipMaps = false;
		if (format == D3DFMT_A8R8G8B8)
			format = D3DFMT_A1R5G5B5;
		else if (format == D3DFMT_R8G8B8)
			format = D3DFMT_R5G6B5;
		else
			return false;

		hr = Device->CreateTexture(optSize.Width, optSize.Height,
			mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
			0, format, D3DPOOL_MANAGED, &Texture, NULL);
	}

	ColorFormat = Driver->getColorFormatFromD3DFormat(format);
	setPitch(format);
	return (SUCCEEDED(hr));
}
コード例 #10
0
ファイル: main.cpp プロジェクト: galek/Asylum_Tutorials
HRESULT InitScene()
{
	HRESULT hr;
	D3DDISPLAYMODE mode;

	if( FAILED(hr = direct3d->GetAdapterDisplayMode(0, &mode)) )
	{
		MYERROR("Could not get adapter mode");
		return hr;
	}
	
	if( FAILED(hr = direct3d->CheckDeviceFormat( 0, D3DDEVTYPE_HAL, mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) )
	{
		MYERROR("No floating point rendertarget support");
		return hr;
	}
	
	// más depth/stencil-el még müködhet
	if( FAILED(hr = direct3d->CheckDepthStencilMatch( 0, D3DDEVTYPE_HAL, mode.Format, D3DFMT_A16B16G16R16F, D3DFMT_D24S8)) )
	{
		MYERROR("D3DFMT_A16B16G16R16F does not support D3DFMT_D24S8");
		return hr;
	}

	D3DVERTEXELEMENT9 elem[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 },
		{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};
	
	SetWindowText(hwnd, TITLE);

	MYVALID(D3DXLoadMeshFromX("../media/meshes/skullocc3.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh1));
	MYVALID(D3DXLoadMeshFromX("../media/meshes//knot.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh2));
	MYVALID(D3DXLoadMeshFromX("../media/meshes//teapot.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh3));
	MYVALID(D3DXLoadMeshFromX("../media/meshes/sky.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &skymesh));

	mesh = mesh1;

	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/altar.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/altar_rough.dds", &roughspecular));
	MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/grace.dds", &skytexture));
	MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/grace_rough.dds", &roughspecular));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/beach.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/beach_rough.dds", &roughspecular));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/stpeters.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/stpeters_rough.dds", &roughspecular));

	MYVALID(D3DXCreateTextureFromFile(device, "../media/textures/gold.jpg", &texture));
	MYVALID(D3DXCreateTextureFromFile(device, "../media/textures/fresnel.png", &fresneltexture));

	// downsample & blur textures
	for( int i = 0; i < 5; ++i )
	{
		MYVALID(device->CreateTexture(screenwidth / (2 << i), screenheight / (2 << i), 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &dstargets[i], NULL));

		MYVALID(device->CreateTexture(screenwidth / (2 << i), screenheight / (2 << i), 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &blurtargets[i], NULL));

		MYVALID(blurtargets[i]->GetSurfaceLevel(0, &blursurfaces[i]));
		MYVALID(dstargets[i]->GetSurfaceLevel(0, &dssurfaces[i]));
	}

	// star textures (8x 1 MB @ 1080p)
	for( int i = 0; i < 4; ++i )
	{
		for( int j = 0; j < 2; ++j )
		{
			MYVALID(device->CreateTexture(screenwidth / 4, screenheight / 4, 1, D3DUSAGE_RENDERTARGET,
				D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &startargets[i][j], NULL));

			MYVALID(startargets[i][j]->GetSurfaceLevel(0, &starsurfaces[i][j]));
		}
	}

	// lens flare textures (2x 4 MB @ 1080p)
	for( int i = 0; i < 2; ++i )
	{
		MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &ghosttargets[i], NULL));

		MYVALID(ghosttargets[i]->GetSurfaceLevel(0, &ghostsurfaces[i]));
	}

	// luminance textures
	for( int i = 0; i < 4; ++i )
	{
		UINT j = 256 / (4 << (2 * i));

		MYVALID(device->CreateTexture(j, j, 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[i], NULL));

		MYVALID(avglumtargets[i]->GetSurfaceLevel(0, &avglumsurfaces[i]));
	}

	// adapted luminance textures
	MYVALID(device->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[4], NULL));
	MYVALID(device->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[5], NULL));

	MYVALID(avglumtargets[4]->GetSurfaceLevel(0, &avglumsurfaces[4]));
	MYVALID(avglumtargets[5]->GetSurfaceLevel(0, &avglumsurfaces[5]));

	// afterimage textures (2x 4 MB @ 1080p)
	MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &afterimages[0], NULL));

	MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &afterimages[1], NULL));

	MYVALID(afterimages[0]->GetSurfaceLevel(0, &aftersurfaces[0]));
	MYVALID(afterimages[1]->GetSurfaceLevel(0, &aftersurfaces[1]));

	// other
	MYVALID(device->CreateTexture(512, 512, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &text, NULL));
	MYVALID(device->CreateTexture(screenwidth, screenheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &scenetarget, NULL));
	MYVALID(device->CreateVertexDeclaration(elem, &vertexdecl));

	// other
	MYVALID(scenetarget->GetSurfaceLevel(0, &scenesurface));

	MYVALID(DXCreateEffect("../media/shaders/hdreffects.fx", device, &hdreffect));
	MYVALID(DXCreateEffect("../media/shaders/hdrfresnel.fx", device, &fresnel));
	MYVALID(DXCreateEffect("../media/shaders/sky.fx", device, &skyeffect));

	device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

	device->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
	device->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

	device->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
	device->SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

	device->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(4, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetSamplerState(5, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	device->SetSamplerState(5, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	device->SetSamplerState(5, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	DXRenderText(HELP_TEXT, text, 512, 512);

	// setup camera
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 3, (float)screenwidth / (float)screenheight, 1, 50);
	D3DXMatrixIdentity(&world);

	cameraangle				= D3DXVECTOR2(0.6f, 0.1f);
	objectangle				= D3DXVECTOR2(0, 0);
	exposurevelocity		= 0;
	destexposurevelocity	= 0;
	exposure				= 0.05f;
	targetluminance			= 0.03f;

	UpdateText();

	return S_OK;
}