Пример #1
0
    /*
     * Create default render target and wrap in a RenderTargetRef reference.
     */
    RenderTargetSharedPtr Graphics::SetupDefaultRenderTarget() {
        // get reference to the engine's object manager
        EngineObjectManager * objectManager = Engine::Instance()->GetEngineObjectManager();

        RenderTarget * defaultTarget = CreateDefaultRenderTarget();
        ASSERT(defaultTarget != nullptr, "GraphicsGL::SetupDefaultRenderTarget -> Default target is null.");

        RenderTargetSharedPtr defaultRenderTarget = objectManager->WrapRenderTarget(defaultTarget);
        ASSERT(defaultRenderTarget.IsValid(), "GraphicsGL::SetupDefaultRenderTarget -> Default target is null.");

        return defaultRenderTarget;
    }
Пример #2
0
void D3D9Renderer::PostReset() {
  XTRACE_FUNCTION;

  CreateDefaultRenderTarget();

  FOR_EACH_LIST(TargetIter, m_RenderTargets, IRenderTarget*) {
    (*TargetIter)->Reset();
  }
  FOR_EACH_SET(VertexBufferIter, m_DynamicVertexBuffers, IVertexBuffer*) {
    (*VertexBufferIter)->DeviceReset();
  }

  ResetRenderState();
}
Пример #3
0
void SampleApp::OnResize(const UINT w, const UINT h)
{
    if (swapChain && d3dDeviceContext)
    {
        wndWidth = w;
        wndHeight = h;
        aspectRatio = static_cast<float>(w) / static_cast<float>(h);

        ID3D11RenderTargetView* pNull = nullptr;
        d3dDeviceContext->OMSetRenderTargets(1, &pNull, nullptr);
        ReleaseDefaultRenderTarget();
        ReleaseDefaultDepthStencil();

        HRESULT hr = S_OK;
        hr = swapChain->ResizeBuffers(swapChainCount, 0, 0, swapChainFormat, 0);
        if (FAILED(hr))
        {
            ELOG("Error : IDXGISwapChain::ResizeBuffer() Failed.");
        }

        if (!CreateDefaultRenderTarget())
        {
            ELOG("Error : CreateDefaultRenderTarget() Failed.");
        }
        if (!CreateDefaultDepthStencil())
        {
            ELOG("Error : CreateDefaultDepthStencil() Failed.");
        }
        d3dDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);

        D3D11_VIEWPORT vp;
        vp.Width = static_cast<float>(w);
        vp.Height = static_cast<float>(h);
        vp.MinDepth = 0.0f;
        vp.MaxDepth = 1.0f;
        vp.TopLeftX = 0;
        vp.TopLeftY = 0;
        d3dDeviceContext->RSSetViewports(1, &vp);
    }
    std::for_each(object.begin(), object.end(), [&](Object::SharedPtr o)
    {
        o->OnResize(d3dDevice, d3dDeviceContext, w, h);
    });
}
Пример #4
0
void D3D9Renderer::Initialize() {
  XTRACE_FUNCTION;

  RendererCommon::Initialize();

  STATIC_HASHED_STRING(Render);
  CATPRINTF(sRender, 1, "Creating Direct3D system...\n");

  ASSERT(!m_D3D);
  m_D3D = Direct3DCreate9(D3D_SDK_VERSION);
  ASSERT(m_D3D);

  DEBUGPRINTF("Initializing Direct3D...\n");

  STATICHASH(Renderer);
  STATICHASH(TestCaps);
  const bool TestCaps = ConfigManager::GetBool(sTestCaps, false, sRenderer);
  if (TestCaps) {
    TestCapabilities();
  }

  D3DPRESENT_PARAMETERS D3DParams;
  GetPresentParams(D3DParams);

  CATPRINTF(sRender, 1, "Creating Direct3D device...\n");

  HRESULT Result = 0;
#ifdef USE_NVPERFHUD
  Result = m_D3D->CreateDevice(m_D3D->GetAdapterCount() - 1, D3DDEVTYPE_REF,
                               m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
                               &D3DParams, &m_D3DDevice);
#else
  Result = m_D3D->CreateDevice(
      D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
      D3DCREATE_FPU_PRESERVE | D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DParams,
      &m_D3DDevice);

  if (Result != D3D_OK) {
    CATPRINTF(
        sRender, 1,
        "CreateDevice returned 0x%08X, trying again with software processing\n",
        Result);
    Result = m_D3D->CreateDevice(
        D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
        D3DCREATE_FPU_PRESERVE | D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &D3DParams, &m_D3DDevice);
  }
#endif
  CATPRINTF(sRender, 1, "CreateDevice returned 0x%08X\n", Result);
  ASSERT(Result == D3D_OK);

  CATPRINTF(sRender, 1, "Device created.\n");
  CATPRINTF(sRender, 1, "Creating default render target...\n");

  CreateDefaultRenderTarget();

  CATPRINTF(sRender, 1, "Default render target created.\n");
  CATPRINTF(sRender, 1, "Initializing render state.\n");

  // I never want to use built-in lighting. All other render state should be
  // driven by materials.
  {
    const HRESULT Result = m_D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    DEBUGASSERT(Result == D3D_OK);
    Unused(Result);
  }

  CATPRINTF(sRender, 1, "Render state initialized.\n");
  CATPRINTF(sRender, 1, "Direct3D initialized.\n");
}
Пример #5
0
bool SampleApp::InitializeD3D11()
{
    HRESULT hr = S_OK;

    RECT rc;
    GetClientRect(hMainWnd, &rc);
    UINT w = rc.right - rc.left;
    UINT h = rc.bottom - rc.top;
    wndWidth = w;
    wndHeight = h;

    aspectRatio = static_cast<float>(w) / static_cast<float>(h);

    UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)
    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    D3D_DRIVER_TYPE driverTypes[] = {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
    UINT numDriverTytpes = sizeof(driverTypes) / sizeof(driverTypes[0]);

    D3D_FEATURE_LEVEL featureLevels[] = {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
    };
    UINT numFeatureLevels = sizeof(featureLevels) / sizeof(featureLevels[0]);

    DXGI_SWAP_CHAIN_DESC sd;
    ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC));
    sd.BufferCount = swapChainCount;
    sd.BufferDesc.Width = 0;
    sd.BufferDesc.Height = 0;
    sd.BufferDesc.Format = swapChainFormat;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
    sd.OutputWindow = hMainWnd;
    sd.SampleDesc.Count = multiSampleCount;
    sd.SampleDesc.Quality = multiSampleQuality;
    sd.Windowed = TRUE;

    for (UINT idx = 0; idx < numDriverTytpes; ++idx)
    {
        driverType = driverTypes[idx];
        hr = D3D11CreateDeviceAndSwapChain(
            nullptr,
            driverType,
            NULL,
            createDeviceFlags,
            featureLevels,
            numFeatureLevels,
            D3D11_SDK_VERSION,
            &sd,
            &swapChain,
            &d3dDevice,
            &featureLevel,
            &d3dDeviceContext
            );

        if (SUCCEEDED(hr))
        {
            break;
        }
    }
    if (FAILED(hr))
    {
        ELOG("Error : D3D11CreateDeviceAndSwapChain() Failed.");
        return false;
    }
    hr = d3dDevice->CheckMultisampleQualityLevels(swapChainFormat, multiSampleCount, &multiSampleMaxQuality);
    if (FAILED(hr))
    {
        ELOG("Error : D3D11Device::CheckMultiSampleQualityLevels() Failed.");
        return false;
    }
    if (!CreateDefaultRenderTarget())
    {
        ELOG("Error : CreateDefaultRenderTarget() Failed.");
        return false;
    }
    if (!CreateDefaultDepthStencil())
    {
        ELOG("Error : CreateDefaultDepthStencil() Failed.");
        return false;
    }

    d3dDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);

    D3D11_VIEWPORT vp;
    vp.Width = static_cast<float>(w);
    vp.Height = static_cast<float>(h);
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    d3dDeviceContext->RSSetViewports(1, &vp);
    return OnInit();
}