コード例 #1
0
ファイル: C4DrawGL.cpp プロジェクト: chrisweidya/openclonk
CStdGLCtx *CStdGL::CreateContext(HWND hWindow, C4AbstractApp *pApp)
{
	// safety
	if (!hWindow) return NULL;
	// create it
	CStdGLCtx *pCtx = new CStdGLCtx();
	if (!pCtx->Init(NULL, pApp, hWindow))
	{
		delete pCtx; Error("  gl: Error creating secondary context!"); return NULL;
	}
	if (Config.Graphics.DebugOpenGL && glDebugMessageCallbackARB)
	{
		glDebugMessageCallbackARB(&OpenGLDebugProc, nullptr);
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
	}
	if (!pMainCtx)
	{
		pMainCtx = pCtx;
	}
	else
	{
		// creation selected the new context - switch back to previous context
		RenderTarget = NULL;
		pCurrCtx = NULL;
	}
	// done
	return pCtx;
}
コード例 #2
0
CStdGLCtx *CStdGL::CreateContext(C4Window * pWindow, C4AbstractApp *pApp)
{
	// safety
	if (!pWindow) return NULL;

	// create it
	CStdGLCtx *pCtx = new CStdGLCtx();
	bool first_ctx = !pMainCtx;
	if (first_ctx)
	{
		pMainCtx = pCtx;
		LogF("  gl: Create first %scontext...", Config.Graphics.DebugOpenGL ? "debug " : "");
	}
	bool success = pCtx->Init(pWindow, pApp);
	if (Config.Graphics.DebugOpenGL && glDebugMessageCallbackARB)
	{
		if (first_ctx) Log("  gl: Setting OpenGLDebugProc callback");
		glDebugMessageCallbackARB(&OpenGLDebugProc, nullptr);
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
#ifdef GL_KHR_debug
		if (GLEW_KHR_debug)
			glEnable(GL_DEBUG_OUTPUT);
#endif
	}
	// First context: Log some information about hardware/drivers
	// Must log after context creation to get valid results
	if (first_ctx)
	{
		const char *gl_vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
		const char *gl_renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
		const char *gl_version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
		LogF("GL %s on %s (%s)", gl_version ? gl_version : "", gl_renderer ? gl_renderer : "", gl_vendor ? gl_vendor : "");
		
		if (Config.Graphics.DebugOpenGL)
		{
			// Dump extension list
			if (glGetStringi)
			{
				GLint gl_extension_count = 0;
				glGetIntegerv(GL_NUM_EXTENSIONS, &gl_extension_count);
				if (gl_extension_count == 0)
				{
					LogSilentF("No available extensions.");
				}
				else
				{
					LogSilentF("%d available extensions:", gl_extension_count);
					for (GLint i = 0; i < gl_extension_count; ++i)
					{
						const char *gl_extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
						LogSilentF("  %4d: %s", i, gl_extension);
					}
				}
			}
			else
			{
				const char *gl_extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
				LogSilentF("GLExt: %s", gl_extensions ? gl_extensions : "");
			}
		}
	}
	if (!success)
	{
		delete pCtx; Error("  gl: Error creating secondary context!"); return NULL;
	}
	// creation selected the new context - switch back to previous context
	RenderTarget = NULL;
	pCurrCtx = NULL;
	// done
	return pCtx;
}