xdl_int XdevLOpenGLWGL::create(XdevLWindow* window) {

		if(window == NULL) {
			XDEVL_MODULE_ERROR("Parameter invalid.\n");
			return ERR_ERROR;
		}

		m_window = window;
		m_wnd = static_cast<HWND>(m_window->getInternal(XdevLInternalName("WIN32_HWND")));
		if ( m_wnd == NULL) {
			XDEVL_MODULE_ERROR("Get WIN32_HWND failed.\n");
			return ERR_ERROR;
		}

		if (initOpenGL() == ERR_ERROR) {
			XDEVL_MODULE_ERROR("Failed to initialize OpenGL.\n");
			return ERR_ERROR;
		}

		// Set vertical syncronisation.
		setVSync(getVSync());

		// TODO: This shouldn't be done maybe because it changes the initial state of the OpenGL context.
		glClearColor(1.0, 0.0, 0.0, 1.0);
		glClear(GL_COLOR_BUFFER_BIT);
		SwapBuffers(m_DC);

		return ERR_OK;
	}
	int XdevLOpenGLContextGLX::create(XdevLWindow* window, XdevLOpenGLContext* shareContext) {
		XDEVL_ASSERT(m_display == nullptr, "XdevLOpenGLContextGLX already created.");

		if(nullptr != shareContext) {
			m_shareContext = static_cast<XdevLOpenGLContextGLX*>(shareContext);
		}

		window->getDescriptor().registerDependency(this);

		m_display = static_cast<Display*>(window->getInternal(XdevLInternalName("X11_DISPLAY")));
		if(nullptr == m_display) {
			XDEVL_MODULE_ERROR("Could not get native X11 display information.\n");
			return RET_FAILED;
		}

		m_window = (Window)(window->getInternal(XdevLInternalName("X11_WINDOW")));
		if(None == m_window) {
			XDEVL_MODULE_ERROR("Could not get native X11 window information.\n");
			return RET_FAILED;
		}

		if(glXQueryVersion(m_display, &m_glxMajorVersion, &m_glxMinorVersion) == False) {
			XDEVL_MODULE_ERROR("glXQueryVersion failed.\n");
			return RET_FAILED;
		}

		if(initOpenGL(m_display, m_window) == RET_FAILED) {
			XDEVL_MODULE_ERROR("Failed to initialize OpenGL.\n");
			return RET_FAILED;
		}

		if(glXIsDirect(m_display, m_glxContext)) {
			XDEVL_MODULE_INFO("Direct Rendering supported.\n");

		} else {
			XDEVL_MODULE_WARNING("Direct Rendering not supported.\n");
		}

		setVSync(getVSync());

		return RET_SUCCESS;
	}
 bool operator() (XF86VidModeModeInfo *mode1, XF86VidModeModeInfo *mode2) {
     return getVSync(mode1) > getVSync(mode2);
 }
Beispiel #4
0
void toggleVSync()
{
	setVSync(!getVSync());
}