Ejemplo n.º 1
0
bool CGSH_Direct3D9::TestDevice()
{
	HRESULT coopLevelResult = m_device->TestCooperativeLevel();
	if(FAILED(coopLevelResult))
	{
		if(coopLevelResult == D3DERR_DEVICELOST)
		{
			return false;
		}
		else if(coopLevelResult == D3DERR_DEVICENOTRESET)
		{
			OnDeviceResetting();
			auto presentParams = CreatePresentParams();
			HRESULT result = m_device->Reset(&presentParams);
			if(FAILED(result))
			{
				assert(0);
				return false;
			}
			OnDeviceReset();
		}
		else
		{
			assert(0);
		}
	}

	return true;
}
Ejemplo n.º 2
0
	void RenderingDevice::ResetDevice() {
		

		CreatePresentParams();
		auto result = mDevice->Reset(&mPresentParams);
		if (result != D3D_OK) {
			logger->warn("Device reset failed.");
		}

	}
Ejemplo n.º 3
0
void CGSH_Direct3D9::CreateDevice()
{
	auto presentParams = CreatePresentParams();
	HRESULT result = S_OK;
	result = m_d3d->CreateDevice(D3DADAPTER_DEFAULT,
						D3DDEVTYPE_HAL,
						m_outputWnd->m_hWnd,
						D3DCREATE_SOFTWARE_VERTEXPROCESSING,
						&presentParams,
						&m_device);
	assert(SUCCEEDED(result));

	OnDeviceReset();

	m_sceneBegun = false;
	BeginScene();
}
Ejemplo n.º 4
0
	RenderingDevice::RenderingDevice(HWND windowHandle, int renderWidth, int renderHeight, bool antiAliasing) 
		  : mWindowHandle(windowHandle), 
			mRenderWidth(renderWidth),
			mRenderHeight(renderHeight),
			mShaders(*this),
			mTextures(*this, 128 * 1024 * 1024),
			mAntiAliasing(antiAliasing) {
		Expects(!renderingDevice);
		renderingDevice = this;
		
		HRESULT status;

		status = D3DLOG(Direct3DCreate9Ex(D3D_SDK_VERSION, &mDirect3d9));
		if (status != D3D_OK) {
			throw TempleException("Unable to create Direct3D9Ex interface.");
		}

		// At this point we only do a GetDisplayMode to check the resolution. We could also do this elsewhere
		D3DDISPLAYMODE displayMode;
		status = D3DLOG(mDirect3d9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
		if (status != D3D_OK) {
			throw TempleException("Unable to query display mode for primary adapter.");
		}

		D3DMULTISAMPLE_TYPE aaTypes[] = {
			D3DMULTISAMPLE_2_SAMPLES,
			D3DMULTISAMPLE_3_SAMPLES,
			D3DMULTISAMPLE_4_SAMPLES,
			D3DMULTISAMPLE_5_SAMPLES,
			D3DMULTISAMPLE_6_SAMPLES,
			D3DMULTISAMPLE_7_SAMPLES,
			D3DMULTISAMPLE_8_SAMPLES,
			D3DMULTISAMPLE_9_SAMPLES,
			D3DMULTISAMPLE_10_SAMPLES,
			D3DMULTISAMPLE_11_SAMPLES,
			D3DMULTISAMPLE_12_SAMPLES,
			D3DMULTISAMPLE_13_SAMPLES,
			D3DMULTISAMPLE_14_SAMPLES,
			D3DMULTISAMPLE_15_SAMPLES,
			D3DMULTISAMPLE_16_SAMPLES
		};

		for (auto type : aaTypes) {
			status = mDirect3d9->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, type, nullptr);
			if (status == D3D_OK) {
				logger->trace("AA method {} is available", type);
				mSupportedAaSamples.push_back(type);
			}
		}

		// We need at least 1024x768
		if (displayMode.Width < 1024 || displayMode.Height < 768) {
			throw TempleException("You need at least a display resolution of 1024x768.");
		}

		CreatePresentParams();

		status = D3DLOG(mDirect3d9->CreateDeviceEx(
			D3DADAPTER_DEFAULT,
			D3DDEVTYPE_HAL,
			mWindowHandle,
			D3DCREATE_HARDWARE_VERTEXPROCESSING,
			&mPresentParams,
			nullptr,
			&mDevice));

		if (status != D3D_OK) {
			throw TempleException("Unable to create Direct3D9 device!");
		}

		// TODO: color bullshit is not yet done (tig_d3d_init_handleformat et al)

		// Get the device caps for real this time.
		ReadCaps();
		
		// Get the currently attached backbuffer
		if (D3DLOG(mDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &mBackBuffer)) != D3D_OK) {
			throw TempleException("Unable to retrieve the back buffer");
		}
		if (D3DLOG(mDevice->GetDepthStencilSurface(&mBackBufferDepth)) != D3D_OK) {
			throw TempleException("Unable to retrieve depth/stencil surface from device");
		}

		memset(&mBackBufferDesc, 0, sizeof(mBackBufferDesc));
		if (D3DLOG(mBackBuffer->GetDesc(&mBackBufferDesc)) != D3D_OK) {
			throw TempleException("Unable to retrieve back buffer description");
		}

		SetRenderSize(renderWidth, renderHeight);
		
		for (auto &listener : mResourcesListeners) {
			listener->CreateResources(*this);
		}
		mResourcesCreated = true;
	}
Ejemplo n.º 5
0
void Graphics::InitializeDirect3d() {

    HRESULT d3dresult;

    /*
    Set some global flags.
    */

    if (config.useDirect3d9Ex) {
        logger->info("Using Direct3D9Ex mode");
        d3dresult = D3DLOG(Direct3DCreate9Ex(D3D_SDK_VERSION, &mDirect3d9));
        if (d3dresult != D3D_OK) {
            throw TempleException("Unable to create Direct3D9 interface.");
        }
    } else {
        logger->info("Using standard Direct3D9 mode");
        mDirect3d9 = static_cast<IDirect3D9Ex*>(Direct3DCreate9(D3D_SDK_VERSION));
        if (!mDirect3d9) {
            throw TempleException("Unable to create Direct3D9 interface.");
        }
    }

    /** START OF OLD WINDOWED INIT */
    // At this point we only do a GetDisplayMode to check the resolution. We could also do this elsewhere
    D3DDISPLAYMODE displayMode;
    d3dresult = D3DLOG(mDirect3d9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
    if (d3dresult != D3D_OK) {
        throw TempleException("Unable to query display mode for primary adapter.");
    }

    // We need at least 1024x768
    if (displayMode.Width < 1024 || displayMode.Height < 768) {
        throw TempleException("You need at least a display resolution of 1024x768.");
    }

    auto presentParams = CreatePresentParams();

    // presentParams.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
    // presentParams.MultiSampleQuality = 0;

    // Nvidia drivers seriously barf on D3d9ex if we use software vertex processing here, as ToEE specifies.
    // I think we are safe with hardware vertex processing, since HW T&L has been standard for more than 10 years.
    if (config.useDirect3d9Ex) {
        logger->info("Creating Direct3D9Ex device.");
        d3dresult = D3DLOG(mDirect3d9->CreateDeviceEx(
                               D3DADAPTER_DEFAULT,
                               D3DDEVTYPE_HAL,
                               mMainWindow.GetHwnd(),
                               D3DCREATE_HARDWARE_VERTEXPROCESSING,
                               &presentParams,
                               nullptr,
                               &mDevice));
    } else {
        logger->info("Creating Direct3D9 device.");
        d3dresult = D3DLOG(mDirect3d9->CreateDevice(
                               D3DADAPTER_DEFAULT,
                               D3DDEVTYPE_HAL,
                               mMainWindow.GetHwnd(),
                               D3DCREATE_HARDWARE_VERTEXPROCESSING,
                               &presentParams,
                               reinterpret_cast<IDirect3DDevice9**>(&mDevice)));
    }

    if (d3dresult != D3D_OK) {
        throw TempleException("Unable to create Direct3D9 device!");
    }

    // TODO: color bullshit is not yet done (tig_d3d_init_handleformat et al)

    // Get the device caps for real this time.
    ReadCaps();

    SetDefaultRenderStates();

    CreateResources();
}