CUBI_USE_NAMESPACE
CUBI_USE_NAMESPACE_RESOURCES

QTrackerContactSaveOrUnmergeRequest::QTrackerContactSaveOrUnmergeRequest(QContactAbstractRequest *request,
                                                                         QContactTrackerEngine *engine,
                                                                         QObject *parent)
    : QTrackerBaseRequest<QctUnmergeIMContactsRequest>(engine, parent)
    , m_unmergeOnlineAccounts(staticCast(request)->unmergeOnlineAccounts())
    , m_sourceContact(staticCast(request)->sourceContact())
{
}
Exemplo n.º 2
0
void Shader::bindTextures() const {
	TextureTable::const_iterator it = mTextures.begin();
	for (size_t i = 0; i < mTextures.size(); ++i) {
		GLint index = staticCast(GLsizei, i + 1);
		glCheck(glUniform1iARB(it->first, index));
		glCheck(glActiveTextureARB(GL_TEXTURE0_ARB + index));
		Texture::bind(it->second);
		++it;
	}

	glCheck(glActiveTextureARB(GL_TEXTURE0_ARB));
}
Exemplo n.º 3
0
void GLContextWin32::createContext(GLContextWin32 *shared, uint32 bpp, const ContextSettings &settings) {
	mSettings = settings;

	int bestFormat = 0;
	if (mSettings.aaLevel > 0) {
		PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = reinterpretCast(PFNWGLCHOOSEPIXELFORMATARBPROC, wglGetProcAddress("wglChoosePixelFormatARB"));
		if (wglChoosePixelFormatARB) {
			int intAttributes[] = {
				WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
				WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
				WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
				WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
				WGL_SAMPLE_BUFFERS_ARB, (mSettings.aaLevel ? GL_TRUE : GL_FALSE),
				WGL_SAMPLES_ARB, staticCasti(mSettings.aaLevel),
				0, 0
			};

			int formats[128];
			UINT nbFormats;
			float floatAttributes[] = {0, 0};
			bool isValid = wglChoosePixelFormatARB(mDeviceContext, intAttributes, floatAttributes, sizeof(formats) / sizeof(*formats), formats, &nbFormats) != 0;
			while ((!isValid || (nbFormats == 0)) && mSettings.aaLevel > 0) {
				--mSettings.aaLevel;
				intAttributes[11] = mSettings.aaLevel;
				isValid = wglChoosePixelFormatARB(mDeviceContext, intAttributes, floatAttributes, sizeof(formats) / sizeof(*formats), formats, &nbFormats) != 0;
			}

			if (isValid && nbFormats != 0) {
				int bestScore = 0xFFFF;
				for (UINT i = 0; i < nbFormats; ++i) {
					PIXELFORMATDESCRIPTOR attributes;
					attributes.nSize = sizeof(attributes);
					attributes.nVersion = 1;
					DescribePixelFormat(mDeviceContext, formats[i], sizeof(attributes), &attributes);
					int color = attributes.cRedBits + attributes.cGreenBits + attributes.cBlueBits + attributes.cAlphaBits;
					int score = evaluateFormat(bpp, mSettings, color, attributes.cDepthBits, attributes.cStencilBits, mSettings.aaLevel);

					if (score < bestScore) {
						bestScore = score;
						bestFormat = formats[i];
					}
				}
			}
		} else {
			std::cerr << "Could not set aa.\n";
			mSettings.aaLevel = 0;
		}
	}

	if (bestFormat == 0) {
		PIXELFORMATDESCRIPTOR descriptor;
		ZeroMemory(&descriptor, sizeof(descriptor));
		descriptor.nSize = sizeof(descriptor);
		descriptor.nVersion = 1;
		descriptor.iLayerType = PFD_MAIN_PLANE;
		descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
		descriptor.iPixelType = PFD_TYPE_RGBA;
		descriptor.cColorBits = staticCast(BYTE, bpp);
		descriptor.cDepthBits = staticCast(BYTE, mSettings.depthBits);
		descriptor.cStencilBits = staticCast(BYTE, mSettings.stencilBits);
		descriptor.cAlphaBits = bpp == 32 ? 8 : 0;

		bestFormat = ChoosePixelFormat(mDeviceContext, &descriptor);
		if (bestFormat == 0) {
			std::cerr << "Failed to find a suitable pixel format for device context, cannot create OpenGL context.\n";
			return;
		}
	}

	PIXELFORMATDESCRIPTOR actualFormat;
	actualFormat.nSize = sizeof(actualFormat);
	actualFormat.nVersion = 1;
	DescribePixelFormat(mDeviceContext, bestFormat, sizeof(actualFormat), &actualFormat);
	mSettings.depthBits = actualFormat.cDepthBits;
	mSettings.stencilBits = actualFormat.cStencilBits;

	if (!SetPixelFormat(mDeviceContext, bestFormat, &actualFormat)) {
		std::cerr << "Failed to set pixel format for the devicecontext, cannot create opengl context.\n";
		return;
	}

	HGLRC sharedContext = shared ? shared->mContext : null;

	while (!mContext && (mSettings.majorVersion >= 3)) {
		PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpretCast(PFNWGLCREATECONTEXTATTRIBSARBPROC, wglGetProcAddress("wglCreateContextAttribsARB"));
		if (wglCreateContextAttribsARB) {
			int attributes[] = {
				WGL_CONTEXT_MAJOR_VERSION_ARB, staticCasti(mSettings.majorVersion),
				WGL_CONTEXT_MINOR_VERSION_ARB, staticCasti(mSettings.minorVersion),
				WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
				0, 0
			};

			mContext = wglCreateContextAttribsARB(mDeviceContext, sharedContext, attributes);
		} else {
			std::cerr << "Could not find \"wglCreateContextAttribsARB\".\n";
		}

		if (!mContext) {
			if (mSettings.minorVersion > 0) {
				--mSettings.minorVersion;
			} else {
				--mSettings.majorVersion;
				mSettings.minorVersion = 9;
			}
		}
	}

	//no opengl >= 3
	if (!mContext) {
		mSettings.majorVersion = 2;
		mSettings.minorVersion = 0;

		mContext = wglCreateContext(mDeviceContext);
		if (!mContext) {
			std::cerr << "Failed to create an opengl context for this window.\n";
			return;
		}

		if (sharedContext) {
			static Mutex mutex;
			Lock lock(mutex);

			if (!wglShareLists(sharedContext, mContext)) {
				std::cerr << "Failed to share the opengl context.\n";
			}
		}
	}
}