MCPcopy Create free account
hub / github.com/carbonengine/trinity / ChangeDevice

Method ChangeDevice

trinity/TriDevice.cpp:341–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341bool TriDevice::ChangeDevice(
342 uint32_t adapter,
343 Tr2WindowHandle hWnd,
344 const Tr2PresentParametersAL* pp )
345{
346 bool resetOnly = true;
347 bool adaptersChanged = Tr2VideoAdapterInfo::AreAdaptersDifferent( adapter, mAdapter );
348 if( !DeviceExists() || hWnd != mHwnd || adaptersChanged )
349 {
350 resetOnly = false; // reset is not enough, we need to recreate the device.
351 }
352
353 if( !pp )
354 {
355 pp = &mPresentParam;
356 }
357
358 if( resetOnly && ResetDevice( adapter, pp ) )
359 {
360 return true; // reset was enough.
361 }
362
363 // Okay, we are creating a new device.
364 // release all resources etc.
365 // We can handle video memory exhaustion gracefully by releasing the device first.
366 if( DeviceExists() )
367 {
368 ReleaseDeviceResources( TRISTORAGE_ALL );
369 Tr2RenderContext::DestroyMainThreadRenderContext();
370 }
371
372 Tr2SyncToGpu::GetInstance().Flush();
373
374 CreateUpscalingTechnique( adapter );
375
376 if( FAILED( CreateDeviceInt( adapter, hWnd, *pp ) ) )
377 {
378 return false;
379 }
380
381 Tr2Renderer::SetResourceCreationAllowed( true );
382
383 mAdapter = adapter;
384 mHwnd = hWnd;
385 mWidth = pp->mode.width;
386 mHeight = pp->mode.height;
387 mPresentParam = *pp;
388 // find out the mode we are in now
389 if( ( mPresentParam.outputWindow || !mPresentParam.software ) &&
390 FAILED( Tr2VideoAdapterInfo::GetAdapterDisplayMode( mAdapter, mDisplayMode ) ) )
391 {
392 return false;
393 }
394
395 if( !SetPresentParameters( mAdapter, mPresentParam ) )
396 {
397 return false;
398 }

Callers 1

SetStateMethod · 0.80

Calls 4

CreateDeviceIntFunction · 0.85
emptyMethod · 0.80
CreateUpscalingTechniqueFunction · 0.50
FlushMethod · 0.45

Tested by

no test coverage detected