bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
	hWnd = CreateHiddenWindow();

	if (WINDOW_VISIBLE) {
		ShowWindow(hWnd, TRUE);
		SetFocus(hWnd);
	}

	WindowsGraphicsContext *graphicsContext = nullptr;
	switch (gpuCore_) {
	case GPU_NULL:
	case GPU_GLES:
	case GPU_SOFTWARE:
		graphicsContext = new WindowsGLContext();
		break;

	case GPU_DIRECTX9:
		graphicsContext = new D3D9Context();
		break;

	case GPU_DIRECTX11:
		return false;

	case GPU_VULKAN:
		graphicsContext = new WindowsVulkanContext();
		break;
	}

	if (graphicsContext->Init(NULL, hWnd, error_message)) {
		*ctx = graphicsContext;
		gfx_ = graphicsContext;
	} else {
		delete graphicsContext;
		*ctx = nullptr;
		gfx_ = nullptr;
		return false;
	}

	if (gpuCore_ == GPU_GLES) {
		// TODO: Do we need to do this here?
		CheckGLExtensions();
	}

	LoadNativeAssets();

	return true;
}
bool WindowsHeadlessHostDx9::InitGraphics(std::string *error_message, GraphicsContext **graphicsContext) {
	*graphicsContext = nullptr;
	LoadD3DX9Dynamic();
	hWnd = DxCreateWindow();

	if (WINDOW_VISIBLE) {
		ShowWindow(hWnd, TRUE);
		SetFocus(hWnd);
	}

	DX9::DirectxInit(hWnd);

	LoadNativeAssets();
	
	DX9::pD3Ddevice->BeginScene();   

	return true;
}
示例#3
0
void WindowsHeadlessHost::InitGL()
{
	glOkay = false;
	hWnd = CreateHiddenWindow();

	if (WINDOW_VISIBLE)
	{
		ShowWindow(hWnd, TRUE);
		SetFocus(hWnd);
	}

	int pixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {0};
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;

#define ENFORCE(x, msg) { if (!(x)) { fprintf(stderr, msg); return; } }

	ENFORCE(hDC = GetDC(hWnd), "Unable to create DC.");
	ENFORCE(pixelFormat = ChoosePixelFormat(hDC, &pfd), "Unable to match pixel format.");
	ENFORCE(SetPixelFormat(hDC, pixelFormat, &pfd), "Unable to set pixel format.");
	ENFORCE(hRC = wglCreateContext(hDC), "Unable to create GL context.");
	ENFORCE(wglMakeCurrent(hDC, hRC), "Unable to activate GL context.");

	SetVSync(0);

	glewInit();
	glstate.Initialize();

	LoadNativeAssets();

	if (ResizeGL())
		glOkay = true;
}