void* XdevLWindowWayland::getInternal(const XdevLInternalName& id) { if(id == XdevLString("WAYLAND_DISPLAY")) { return (void*)display; } else if(id == XdevLString("WAYLAND_WINDOW")) { return (void*)m_egl.m_eglWindow; } return nullptr; }
XdevLModule* createModule(const XdevLPluginDescriptor& pluginDescriptor, XdevLModuleDescriptor& moduleDescriptor, const XdevLFileName& pluginPath) { XdevLSharedLibrary* sharedLibrary = new XdevLSharedLibrary(); XdevLFileName pluginName(""); // Did the user specify a plugin folder? if(pluginPath != XdevLFileName()) { pluginName = pluginPath; pluginName += XdevLFileName("/"); } #ifdef XDEVL_PLATFORM_ANDROID pluginName += xdl::XdevLFileName("lib"); #endif pluginName += pluginDescriptor.getName() + STRING("-") + XdevLString(pluginDescriptor.getVersion().toString()); #ifdef XDEVL_DEBUG pluginName += STRING("d"); #endif pluginName += XdevLSharedLibrary::extension; std::string tmp(pluginName.toString()); xdl_int ret; if((ret = checkLocal(tmp, sharedLibrary)) != RET_SUCCESS) { std::cerr << "## Could not find XdevLCore plugin at all." << std::endl; exit(-1); } // // Get the plugins create and delte function pointer. // moduleDescriptor.create = (CREATE_XDEVL_MODULE)(sharedLibrary->getFunctionAddress("_createModule")); if(!moduleDescriptor.create) { return nullptr; } moduleDescriptor.destroy = (DELETE_XDEVL_MODULE)(sharedLibrary->getFunctionAddress("_delete")); if(!moduleDescriptor.destroy) { return nullptr; } moduleDescriptor.setLibrary(sharedLibrary); return moduleDescriptor.create(pluginDescriptor, moduleDescriptor); }
xdl_int XdevLFTDI::readInfoFromXMLFile() { if(getMediator()->getXmlFilename() == nullptr) return RET_FAILED; TiXmlDocument xmlDocument; if(!xmlDocument.LoadFile(getMediator()->getXmlFilename())) { XDEVL_MODULE_ERROR("Could not parse xml file: " << getMediator()->getXmlFilename() << std::endl); return RET_FAILED; } TiXmlHandle docHandle(&xmlDocument); TiXmlElement* root = docHandle.FirstChild(XdevLCorePropertiesName.c_str()).FirstChildElement("XdevLSerial").ToElement(); if(!root) { XDEVL_MODULE_WARNING("<XdevLSerial> section not found. Using default values for the device.\n"); return RET_SUCCESS; } while(root != nullptr) { if(root->Attribute("id")) { XdevLID id(root->Attribute("id")); if(getID() == id) { if(root->Attribute("device")) { m_deviceName = XdevLString(root->Attribute("device")); } if(root->Attribute("usb_in_size")) { std::istringstream ss(root->Attribute("usb_in_size")); ss >> m_usbInSize; } if(root->Attribute("usb_out_size")) { std::istringstream ss(root->Attribute("usb_out_size")); ss >> m_usbOutSize; } if(root->Attribute("latency_timer")) { std::istringstream ss(root->Attribute("latency_timer")); ss >> m_latencyTimer; }
xdl_int XdevLOpenGLContextGLX::initOpenGL(Display* display, Window window) { // // Get all supported extensions. // std::string tmp(glXQueryExtensionsString(display, DefaultScreen(display))); std::vector<std::string> exlist; xstd::tokenize(tmp, exlist, " "); for(auto extension : exlist) { extensionsList.push_back(XdevLString(extension)); } std::vector<int> attribute_list; // --------------------------------------------------------------------------- // Prepare the attribute values for the glXChooseVisual function // attribute_list.push_back(GLX_X_RENDERABLE); attribute_list.push_back(True); // We are going to use the normal RGBA color type, not the color index type. attribute_list.push_back(GLX_RENDER_TYPE); attribute_list.push_back(GLX_RGBA_BIT); // This window is going to use only Window type, that means we can't use PBuffers. // Valid values are GLX WINDOW BIT, GLX PIXMAP BIT, GLX PBUFFER BIT. All can be used at the same time. attribute_list.push_back(GLX_DRAWABLE_TYPE); attribute_list.push_back(GLX_WINDOW_BIT); if(m_attributes.red_size > 0) { attribute_list.push_back(GLX_RED_SIZE); attribute_list.push_back(m_attributes.red_size); } if(m_attributes.green_size > 0) { attribute_list.push_back(GLX_GREEN_SIZE); attribute_list.push_back(m_attributes.green_size); } if(m_attributes.blue_size > 0) { attribute_list.push_back(GLX_BLUE_SIZE); attribute_list.push_back(m_attributes.blue_size); } if(m_attributes.alpha_size > 0) { attribute_list.push_back(GLX_ALPHA_SIZE); attribute_list.push_back(m_attributes.alpha_size); } if((m_attributes.red_size > 0) || (m_attributes.green_size > 0) || (m_attributes.blue_size > 0) || (m_attributes.alpha_size > 0) ) { attribute_list.push_back(GLX_BUFFER_SIZE); attribute_list.push_back(m_attributes.color_buffer_size); } attribute_list.push_back(GLX_DEPTH_SIZE); attribute_list.push_back(m_attributes.depth_size); attribute_list.push_back(GLX_STENCIL_SIZE); attribute_list.push_back(m_attributes.stencil_size); // attribute_list.push_back(GLX_ACCUM_RED_SIZE); // attribute_list.push_back(m_attributes.accum_red_size); // // attribute_list.push_back(GLX_ACCUM_GREEN_SIZE); // attribute_list.push_back(m_attributes.accum_green_size); // // attribute_list.push_back(GLX_ACCUM_BLUE_SIZE); // attribute_list.push_back(m_attributes.accum_blue_size); // // attribute_list.push_back(GLX_ACCUM_ALPHA_SIZE); // attribute_list.push_back(m_attributes.accum_alpha_size); if(m_attributes.stereo > 0) { attribute_list.push_back(GLX_STEREO); attribute_list.push_back(True); } if(m_attributes.multisample_buffers > 0) { attribute_list.push_back(GLX_SAMPLE_BUFFERS); attribute_list.push_back(GL_TRUE); attribute_list.push_back(GLX_SAMPLES); attribute_list.push_back(m_attributes.multisample_samples); } if(m_attributes.double_buffer > 0) { attribute_list.push_back(GLX_DOUBLEBUFFER); attribute_list.push_back(GL_TRUE); } attribute_list.push_back(None); // // Get all supported visual configurations. // xdl_int numberOfConfigs; GLXFBConfig *fbcfg = glXChooseFBConfig(display, DefaultScreen(display), attribute_list.data(), &numberOfConfigs); if(!fbcfg) { XDEVL_MODULE_ERROR("glXChooseFBConfig failed\n"); return RET_FAILED; } // // Retrieve the X Visual associated with a GLXFBConfig // int best_fbc = -1; int worst_fbc = -1; int best_num_samples = -1; int worst_num_samples = 999; for(auto i = 0; i < numberOfConfigs; i++) { XVisualInfo* vi = glXGetVisualFromFBConfig(display, fbcfg[i]); if(nullptr != vi) { int sample_buffer, samples; glXGetFBConfigAttrib(display, fbcfg[i], GLX_SAMPLE_BUFFERS, &sample_buffer); glXGetFBConfigAttrib(display, fbcfg[i], GLX_SAMPLES, &samples); if(best_fbc < 0 || (sample_buffer && samples) > best_num_samples) { best_fbc = i; best_num_samples = samples; } if(worst_fbc < 0 || (!sample_buffer && samples) < worst_num_samples) { worst_fbc = i; worst_num_samples = samples; } } XFree(vi); } /// Now get the GLXFBConfig for the best match. GLXFBConfig bestFbc = fbcfg[best_fbc]; XFree(fbcfg); XDEVL_MODULEX_INFO(XdevLOpenGLContextGLX, "--- GLXFBConfig ---\n"); dumpConfigInfo(bestFbc); XDEVL_MODULEX_INFO(XdevLOpenGLContextGLX, "-------------------\n"); m_visualInfo = glXGetVisualFromFBConfig(display, bestFbc); // Change the windows color map. XSetWindowAttributes swa; swa.colormap = XCreateColormap(display, RootWindow(display, m_visualInfo->screen), m_visualInfo->visual, AllocNone); XChangeWindowAttributes(display, window, CWColormap, &swa); glXWaitGL(); // TODO: This is the easiest way to create a visual for X11. You should do that in a better way cengiz. // m_visualInfo = glXChooseVisual(display, DefaultScreen(display), attribute_list.data()); // if(nullptr == m_visualInfo) { // XDEVL_MODULE_ERROR("glXChooseVisual failed. Please try different framebuffer, depthbuffer, stencilbuffer values.\n"); // return RET_FAILED; // } // // Set OpenGL 3.0 > attributes. // std::vector<int> opengl_profile_attribute_list; opengl_profile_attribute_list.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB); opengl_profile_attribute_list.push_back(m_attributes.context_major_version); opengl_profile_attribute_list.push_back(GLX_CONTEXT_MINOR_VERSION_ARB); opengl_profile_attribute_list.push_back(m_attributes.context_minor_version); if((m_attributes.context_flags & XDEVL_OPENGL_CONTEXT_FLAGS_DEBUG_BIT) || (m_attributes.context_flags & XDEVL_OPENGL_CONTEXT_FLAGS_FORWARD_COMPATIBLE_BIT)) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_FLAGS_ARB); if(m_attributes.context_flags == XDEVL_OPENGL_CONTEXT_FLAGS_DEBUG_BIT) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_DEBUG_BIT_ARB); } else if(m_attributes.context_flags == XDEVL_OPENGL_CONTEXT_FLAGS_FORWARD_COMPATIBLE_BIT) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB); } } if((m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_CORE_PROFILE) || (m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_COMPATIBILITY)) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_PROFILE_MASK_ARB); if(m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_CORE_PROFILE) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_CORE_PROFILE_BIT_ARB); } else if(m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_COMPATIBILITY) { opengl_profile_attribute_list.push_back(GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB); } } opengl_profile_attribute_list.push_back(None); XDEVL_MODULEX_INFO(XdevLOpenGLContextGLX, "OpenGL: " << m_attributes.context_major_version << "." << m_attributes.context_minor_version << std::endl); // // Try to use new ARB_create_context and ARB_create_context_profile // auto sharedContext = m_shareContext ? m_shareContext->getNativeContext() : nullptr; if(nullptr != glXCreateContextAttribs) { // // Create the context. // m_glxContext = glXCreateContextAttribs(display, bestFbc, sharedContext, True, opengl_profile_attribute_list.data()); if(nullptr == m_glxContext) { XDEVL_MODULEX_ERROR(XdevLOpenGLContextGLX, "glXCreateContext failed.\n"); return RET_FAILED; } // // Check for other erros. // glXWaitGL(); if(xdl_true == contextErrorOccured) { // m_glxContext = glXCreateContext(display, m_visualInfo, sharedContext, GL_TRUE); } } else { // // OK, not supported, let's use old function. // m_glxContext = glXCreateContext(display, m_visualInfo, sharedContext, GL_TRUE); if(nullptr == m_glxContext) { XDEVL_MODULEX_ERROR(XdevLOpenGLContextGLX, "glXCreateContext failed.\n"); return RET_FAILED; } } // setEnableFSAA(xdl_true); // // Make it current. // // GLXWindow glxWindow = glXCreateWindow(display, bestFbc, window, nullptr); // GLXDrawable drawable = glxWindow; // glXMakeContextCurrent(display, drawable, drawable, m_glxContext); if(glXMakeCurrent(display, window, m_glxContext) == False) { return RET_FAILED; } return RET_SUCCESS; }