Example #1
0
/**
 * Create an OpenGL context.
 */
FPlatformOpenGLContext* PlatformCreateOpenGLContext(FPlatformOpenGLDevice* Device, void* InWindowHandle)
{
	check(InWindowHandle);

	Device->TargetDirty = true;

	FPlatformOpenGLContext* Context = new FPlatformOpenGLContext;
	Context->WindowHandle = (HWND)InWindowHandle;
	Context->bReleaseWindowOnDestroy = false;
	Context->DeviceContext = GetDC(Context->WindowHandle);
	check(Context->DeviceContext);
	PlatformInitPixelFormatForDevice(Context->DeviceContext, false);

	int MajorVersion = 0;
	int MinorVersion = 0;
	PlatformOpenGLVersionFromCommandLine(MajorVersion, MinorVersion);

	PlatformCreateOpenGLContextCore(Context, MajorVersion, MinorVersion, Device->SharedContext.OpenGLContext);	
	check(Context->OpenGLContext);
	{
		FScopeContext Scope(Context);
		InitDefaultGLContextState();
		glGenFramebuffers(1, &Context->ViewportFramebuffer);
	}

	Device->ViewportContexts.Add(Context);
	return Context;
}
/**
 * Create a dummy window used to construct OpenGL contexts.
 */
static void PlatformCreateDummyGLWindow(FPlatformOpenGLContext* OutContext)
{
	const TCHAR* WindowClassName = TEXT("DummyGLWindow");

	// Register a dummy window class.
	static bool bInitializedWindowClass = false;
	if (!bInitializedWindowClass)
	{
		WNDCLASS wc;

		bInitializedWindowClass = true;
		FMemory::MemZero(wc);
		wc.style = CS_OWNDC;
		wc.lpfnWndProc = PlatformDummyGLWndproc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = 0;
		wc.hInstance = NULL;
		wc.hIcon = NULL;
		wc.hCursor = NULL;
		wc.hbrBackground = (HBRUSH)(COLOR_MENUTEXT);
		wc.lpszMenuName = NULL;
		wc.lpszClassName = WindowClassName;
		ATOM ClassAtom = ::RegisterClass(&wc);
		check(ClassAtom);
	}

	// Create a dummy window.
	OutContext->WindowHandle = CreateWindowEx(
		WS_EX_WINDOWEDGE,
		WindowClassName,
		NULL,
		WS_POPUP,
		0, 0, 1, 1,
		NULL, NULL, NULL, NULL);
	check(OutContext->WindowHandle);
	OutContext->bReleaseWindowOnDestroy = true;

	// Get the device context.
	OutContext->DeviceContext = GetDC(OutContext->WindowHandle);
	check(OutContext->DeviceContext);
	PlatformInitPixelFormatForDevice(OutContext->DeviceContext);
}
/**
 * Create an OpenGL context.
 */
FPlatformOpenGLContext* PlatformCreateOpenGLContext(FPlatformOpenGLDevice* Device, void* InWindowHandle)
{
	check(InWindowHandle);

	FPlatformOpenGLContext* Context = new FPlatformOpenGLContext;
	Context->WindowHandle = (HWND)InWindowHandle;
	Context->bReleaseWindowOnDestroy = false;
	Context->DeviceContext = GetDC(Context->WindowHandle);
	check(Context->DeviceContext);
	PlatformInitPixelFormatForDevice(Context->DeviceContext);

	int MajorVersion = 0;
	int MinorVersion = 0;
	PlatformOpenGLVersionFromCommandLine(MajorVersion, MinorVersion);

	PlatformCreateOpenGLContextCore(Context, MajorVersion, MinorVersion, Device->SharedContext.OpenGLContext);	
	check(Context->OpenGLContext);
	{
		FScopeContext Scope(Context);
		InitDefaultGLContextState();
	}
	return Context;
}