示例#1
0
void App::ToggleFullScreen(bool fullScreen)
{
    if(fullScreen != deviceManager.FullScreen())
    {
        BeforeReset();

        deviceManager.SetFullScreen(fullScreen);
        deviceManager.Reset();

        AfterReset();
    }
}
void SwapChain::Reset()
{
    Assert_(swapChain);
    if(output == nullptr)
        fullScreen = false;

    // Release all references
    for(uint64 i = 0; i < NumBackBuffers; ++i)
    {
        DX12::Release(backBuffers[i].Texture.Resource);
        DX12::RTVDescriptorHeap.FreePersistent(backBuffers[i].RTV);
    }

    if(format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
        noSRGBFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
    else if(format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
        noSRGBFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
    else
        noSRGBFormat = format;

    if(fullScreen)
        PrepareFullScreenSettings();
    else
    {
        refreshRate.Numerator = 60;
        refreshRate.Denominator = 1;
    }

    DXCall(swapChain->SetFullscreenState(fullScreen, NULL));

    DXCall(swapChain->ResizeBuffers(NumBackBuffers, width, height, noSRGBFormat,
                                    DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH |
                                    DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING |
                                    DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT));

    if(fullScreen)
    {
        DXGI_MODE_DESC mode;
        mode.Format = noSRGBFormat;
        mode.Width = width;
        mode.Height = height;
        mode.RefreshRate.Numerator = 0;
        mode.RefreshRate.Denominator = 0;
        mode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
        mode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
        DXCall(swapChain->ResizeTarget(&mode));
    }

    AfterReset();
}
示例#3
0
//===============================================================================================================================
void D3D::ResizeDevice()
{
	assert(m_swapChain);

    // Release all references
    //SAFE_RELEASE(m_depthStencilBackBuffer);
    //SAFE_RELEASE(m_renderTargetViewBackbuffer);

    m_deviceContext->ClearState();

    if(!m_isFullscreen)
    {
		refreshRate.Numerator = 0;
		refreshRate.Denominator = 1;
    }

    m_swapChain->SetFullscreenState(m_isFullscreen, NULL);

    m_swapChain->ResizeBuffers(1, m_screenWidth, m_screenHeight, m_backBufferFormat, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);

    if(m_isFullscreen)
    {
        DXGI_MODE_DESC mode;
        mode.Format = m_backBufferFormat;
        mode.Width = m_screenWidth;
        mode.Height = m_screenHeight;
        mode.RefreshRate.Numerator = 0;
        mode.RefreshRate.Denominator = 0;
        mode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
        mode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
        m_swapChain->ResizeTarget(&mode);
    }
	else
	{
		int crap = 0;
		crap = 23;
	}

    AfterReset(m_screenWidth, m_screenHeight);
}
void SwapChain::Initialize(HWND outputWindow)
{
    Shutdown();

    // We'll just use the first output for fullscreen
    DX12::Adapter->EnumOutputs(0, &output);

    if(format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
        noSRGBFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
    else if(format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
        noSRGBFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
    else
        noSRGBFormat = format;

    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
    swapChainDesc.BufferCount = uint32(NumBackBuffers);
    swapChainDesc.BufferDesc.Width = width;
    swapChainDesc.BufferDesc.Height = height;
    swapChainDesc.BufferDesc.Format = noSRGBFormat;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
    swapChainDesc.OutputWindow = outputWindow;
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.Windowed = TRUE;
    swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH |
                          DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING |
                          DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;

    IDXGISwapChain* tempSwapChain = nullptr;
    DXCall(DX12::Factory->CreateSwapChain(DX12::GfxQueue, &swapChainDesc, &tempSwapChain));
    DXCall(tempSwapChain->QueryInterface(IID_PPV_ARGS(&swapChain)));
    DX12::Release(tempSwapChain);

    backBufferIdx = swapChain->GetCurrentBackBufferIndex();
    waitableObject = swapChain->GetFrameLatencyWaitableObject();

    AfterReset();
}
示例#5
0
int32 App::Run()
{
    try
    {
        if(createConsole)
        {
            Win32Call(AllocConsole());
            Win32Call(SetConsoleTitle(applicationName.c_str()));
            FILE* consoleFile = nullptr;
            freopen_s(&consoleFile, "CONOUT$", "wb", stdout);
        }

        window.SetClientArea(deviceManager.BackBufferWidth(), deviceManager.BackBufferHeight());
        deviceManager.Initialize(window);

        if(showWindow)
            window.ShowWindow();

        blendStates.Initialize(deviceManager.Device());
        rasterizerStates.Initialize(deviceManager.Device());
        depthStencilStates.Initialize(deviceManager.Device());
        samplerStates.Initialize(deviceManager.Device());

        // Create a font + SpriteRenderer
        font.Initialize(L"Arial", 18, SpriteFont::Regular, true, deviceManager.Device());
        spriteRenderer.Initialize(deviceManager.Device());

        Profiler::GlobalProfiler.Initialize(deviceManager.Device(), deviceManager.ImmediateContext());

        window.RegisterMessageCallback(WM_SIZE, OnWindowResized, this);

        // Initialize AntTweakBar
        TwCall(TwInit(TW_DIRECT3D11, deviceManager.Device()));

        // Create a tweak bar
        tweakBar = TwNewBar("Settings");
        std::string helpTextDefinition = MakeAnsiString(" GLOBAL help='%s' ", globalHelpText.c_str());
        TwCall(TwDefine(helpTextDefinition.c_str()));
        TwCall(TwDefine(" GLOBAL fontsize=3 "));

        Settings.Initialize(tweakBar);

        TwHelper::SetValuesWidth(Settings.TweakBar(), 120, false);

        AppSettings::Initialize(deviceManager.Device());

        Initialize();

        AfterReset();

        while(window.IsAlive())
        {
            if(!window.IsMinimized())
            {
                timer.Update();
                Settings.Update();

                CalculateFPS();

                AppSettings::Update();

                Update(timer);

                UpdateShaders(deviceManager.Device());

                AppSettings::UpdateCBuffer(deviceManager.ImmediateContext());

                Render(timer);

                // Render the profiler text
                spriteRenderer.Begin(deviceManager.ImmediateContext(), SpriteRenderer::Point);
                Profiler::GlobalProfiler.EndFrame(spriteRenderer, font);
                spriteRenderer.End();

                {
                    PIXEvent pixEvent(L"Ant Tweak Bar");

                    // Render the TweakBar UI
                    TwCall(TwDraw());
                }

                deviceManager.Present();
            }

            window.MessageLoop();
        }
    }
    catch(SampleFramework11::Exception exception)
    {
        exception.ShowErrorMessage();
        return -1;
    }

    ShutdownShaders();

    TwCall(TwTerminate());

    if(createConsole)
    {
        fclose(stdout);
        FreeConsole();
    }

    return returnCode;
}
示例#6
0
void App::AfterReset_Internal()
{
    AfterReset();
}