Exemplo n.º 1
0
WRAPPER_VISIBILITY BOOL
WRAPPER(epoxy_wglMakeAssociatedContextCurrentAMD)(HGLRC hglrc)
{
    BOOL ret = epoxy_wglMakeAssociatedContextCurrentAMD_unwrapped(hglrc);

    epoxy_handle_external_wglMakeCurrent();

    return ret;
}
Exemplo n.º 2
0
WRAPPER_VISIBILITY BOOL
WRAPPER(epoxy_wglMakeCurrent)(HDC hdc, HGLRC hglrc)
{
    BOOL ret = epoxy_wglMakeCurrent_unwrapped(hdc, hglrc);

    epoxy_handle_external_wglMakeCurrent();

    return ret;
}
Exemplo n.º 3
0
WRAPPER_VISIBILITY BOOL
WRAPPER(epoxy_wglMakeContextCurrentEXT)(HDC hDrawDC,
                                        HDC hReadDC,
                                        HGLRC hglrc)
{
    BOOL ret = epoxy_wglMakeContextCurrentEXT_unwrapped(hDrawDC, hReadDC,
                                                        hglrc);

    epoxy_handle_external_wglMakeCurrent();

    return ret;
}
Exemplo n.º 4
0
bool SDLWindow::createContext() {
	//Init SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
		fprintf(stderr, "SDL Error: %s", SDL_GetError());
		return false;
	}

	// Check to see if we are forcing the legacy profile.
	bool forceLegacy = false;
	for (auto cmd : GameState::gState->mCmdArgs) {
		if (strcasecmp(cmd.c_str(), "-legacygl") == 0) {
			forceLegacy = true;
			break;
		}
	}

	SDL_GLContext context;

	// First try the core profile, unless we specified the legacy profile
	// as a command line argument.
	bool success = false;
	GLContext profileChosen = GLContext::INVALID;
	if (!forceLegacy) {
		IO::printf("Attempting to create a core OpenGL context.");
		success = createGLContextAndWindow(GLContext::CORE, window, context);
		if (success)
			profileChosen = GLContext::CORE;
	}

	if (forceLegacy || !success) {
		if (!success)
			IO::printf("Failed to create a core OpenGL context. Attempting to create a legacy context.\n");
		if (forceLegacy)
			IO::printf("Forcing the legacy OpenGL context. Attempting to create a legacy context.\n");

		success = createGLContextAndWindow(GLContext::LEGACY, window, context);
		if (success)
			profileChosen = GLContext::LEGACY;
	}

	// If we still didn't have success, bail.
	if (!success) {
		IO::printf("Failed to create an OpenGL context. Make sure that you have at least OpenGL 2.1.\n");
		return false;
	}

	SDL_GL_MakeCurrent(window, context);
#ifdef _WIN32
	epoxy_handle_external_wglMakeCurrent();
#endif

	// Initialize the GL library
	if (profileChosen == GLContext::CORE)
		GL::createGL<GL33>();
	else
		GL::createGL<GL21>();

	// for the love of god please not software rendering.
#if defined(_WIN32) || defined(__APPLE__)
	{
		std::string renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
	#ifdef _WIN32
		if (renderer.find("Microsoft") != std::string::npos) {
	#else
		if (renderer.find("APPLE") != std::string::npos) {
	#endif
			IO::printf("Unable to create a hardware accelerated OpenGL driver. Please make sure that you have OpenGL drivers downloaded and they are up to date.\n");
			return false;
		}
	}
#endif
	
	// Let the GL library store this context.
	glBindContextEXT(context);

	IO::printf("System Memory: %dMB\n", PlatformEx::getPhysicalSystemRam());
	IO::printf("OpenGL Core Profile Info\n");
	IO::printf("   Version:  %s\n", glGetString(GL_VERSION));
	IO::printf("   Vendor:   %s\n", glGetString(GL_VENDOR));
	IO::printf("   Renderer: %s\n", glGetString(GL_RENDERER));
	IO::printf("   Shading:  %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
	IO::printf("   VRAM:     %uMB\n", glGetVideoRamEXT());

	//Use Vsync
	setVerticalSync(true);
	
	//Lock cursor
	lockCursor(true);

	// we bind a blank VAO, as it's required for core profile
	glGenVertexArrays(1, &mVAO);
	glBindVertexArray(mVAO);

	return true;
}

void SDLWindow::destroyContext() {
	// clean up VAO
	if (mVAO)
		glDeleteVertexArrays(1, &mVAO);
	SDL_GL_DeleteContext(context);
	glBindContextEXT(nullptr);
	SDL_Quit();
}

void SDLWindow::swapBuffers() {
	SDL_GL_SwapWindow(window);
}