示例#1
0
//*************************************************************************************************
// Constructor
//*************************************************************************************************
RenderContext::RenderContext(HWND clientWindow, SUINT clientWidth, SUINT clientHeight)
	:	_d3dDevice(0),
		_swapChain(0),
		_d3dImmediateContext(0),
		_d3dDriverType(D3D_DRIVER_TYPE_UNKNOWN),
		_4xMsaaEnabled(false)
{
	// Initialize the render context
	SBOOL success = false;

	// Create the Direct3D device
	success = createDevice();

	// Check for multisampling
	if(success == true)
	{
		success = checkMultisampling();
	}

	// Create the swap chain for the device
	if(success == true)
	{
		success = createSwapChain(clientWindow, clientWidth, clientHeight);
	}
}
egl::Error DXGISwapChainWindowSurfaceWGL::initialize()
{
    if (mOrientation != EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE)
    {
        // TODO(geofflang): Support the orientation extensions fully.  Currently only inverting Y is
        // supported.  To support all orientations, an intermediate framebuffer will be needed with
        // a blit before swap.
        return egl::Error(EGL_BAD_ATTRIBUTE,
                          "DXGISwapChainWindowSurfaceWGL requires an orientation of "
                          "EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE.");
    }

    RECT rect;
    if (!GetClientRect(mWindow, &rect))
    {
        return egl::Error(EGL_BAD_NATIVE_WINDOW, "Failed to query the window size.");
    }
    mWidth  = rect.right - rect.left;
    mHeight = rect.bottom - rect.top;

    mSwapChainFormat   = DXGI_FORMAT_R8G8B8A8_UNORM;
    mSwapChainFlags    = 0;
    mDepthBufferFormat = GL_DEPTH24_STENCIL8;

    mFunctionsGL->genFramebuffers(1, &mFramebufferID);
    mFunctionsGL->genRenderbuffers(1, &mColorRenderbufferID);
    mFunctionsGL->genRenderbuffers(1, &mDepthRenderbufferID);

    return createSwapChain();
}
egl::Error DXGISwapChainWindowSurfaceWGL::checkForResize()
{
    RECT rect;
    if (!GetClientRect(mWindow, &rect))
    {
        return egl::Error(EGL_BAD_NATIVE_WINDOW, "Failed to query the window size.");
    }

    size_t newWidth  = rect.right - rect.left;
    size_t newHeight = rect.bottom - rect.top;
    if (newWidth != mWidth || newHeight != mHeight)
    {
        mWidth  = newWidth;
        mHeight = newHeight;

        // TODO(geofflang): Handle resize by resizing the swap chain instead of re-creating it.
        egl::Error error = createSwapChain();
        if (error.isError())
        {
            return error;
        }
    }

    return egl::Error(EGL_SUCCESS);
}
egl::Error DXGISwapChainWindowSurfaceWGL::initialize(const egl::Display *display)
{
    if (mOrientation != EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE)
    {
        // TODO(geofflang): Support the orientation extensions fully.  Currently only inverting Y is
        // supported.  To support all orientations, an intermediate framebuffer will be needed with
        // a blit before swap.
        return egl::EglBadAttribute() << "DXGISwapChainWindowSurfaceWGL requires an orientation of "
                                         "EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE.";
    }

    RECT rect;
    if (!GetClientRect(mWindow, &rect))
    {
        return egl::EglBadNativeWindow() << "Failed to query the window size.";
    }
    mWidth  = rect.right - rect.left;
    mHeight = rect.bottom - rect.top;

    mSwapChainFormat   = DXGI_FORMAT_R8G8B8A8_UNORM;
    mSwapChainFlags    = 0;
    mDepthBufferFormat = GL_DEPTH24_STENCIL8;

    mFunctionsGL->genRenderbuffers(1, &mColorRenderbufferID);
    mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mColorRenderbufferID);

    mFunctionsGL->genRenderbuffers(1, &mDepthRenderbufferID);
    mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mDepthRenderbufferID);

    return createSwapChain();
}
 void initVulkan() {
     createInstance();
     setupDebugCallback();
     createSurface();
     pickPhysicalDevice();
     createLogicalDevice();
     createSwapChain();
 }
 void initVulkan() {
     createInstance();
     setupDebugCallback();
     createSurface();
     pickPhysicalDevice();
     createLogicalDevice();
     createSwapChain();
     createImageViews();
     createRenderPass();
     createGraphicsPipeline();
 }