コード例 #1
1
HGLRC CL_GL1CreationHelper::create_opengl3_context(HGLRC share_context, int major_version, int minor_version)
{
	set_active();
	ptr_wglCreateContextAttribsARB wglCreateContextAttribsARB = (ptr_wglCreateContextAttribsARB) wglGetProcAddress("wglCreateContextAttribsARB");
	reset_active();

	HGLRC opengl3_context = 0;
	if (wglCreateContextAttribsARB)
	{
		std::vector<int> int_attributes;

		int_attributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
		int_attributes.push_back(major_version);
		int_attributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
		int_attributes.push_back(minor_version);
		//int_attributes.push_back(WGL_CONTEXT_LAYER_PLANE_ARB);
		//int_attributes.push_back(layer_plane);
		//int_attributes.push_back(WGL_CONTEXT_FLAGS_ARB);
		//int_attributes.push_back(flags);
		//int_attributes.push_back(WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
		//int_attributes.push_back(forward_compatible_bit);
		int_attributes.push_back(0);

		opengl3_context = wglCreateContextAttribsARB(hdc, share_context, &int_attributes[0]);
	}
	return opengl3_context;
}
コード例 #2
0
	HGLRC OpenGLCreationHelper::create_opengl3_context(HGLRC share_context, int major_version, int minor_version, const OpenGLContextDescription &gldesc)
	{
		set_active();
		ptr_wglCreateContextAttribsARB wglCreateContextAttribsARB = (ptr_wglCreateContextAttribsARB)wglGetProcAddress("wglCreateContextAttribsARB");

		HGLRC opengl3_context = 0;
		if (wglCreateContextAttribsARB)
		{
			std::vector<int> int_attributes;

			int_attributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
			int_attributes.push_back(major_version);
			int_attributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
			int_attributes.push_back(minor_version);

			int_attributes.push_back(0x2093);	// WGL_CONTEXT_LAYER_PLANE_ARB
			int_attributes.push_back(gldesc.get_layer_plane());
			int_attributes.push_back(0x2094);	// WGL_CONTEXT_FLAGS_ARB
			int flags = 0;
			if (gldesc.get_debug())
				flags |= 0x1;	// WGL_CONTEXT_DEBUG_BIT_ARB
			if (gldesc.get_forward_compatible())	// WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
				flags |= 0x2;
			int_attributes.push_back(flags);

			int_attributes.push_back(0x9126);	// WGL_CONTEXT_PROFILE_MASK_ARB
			flags = 0;
			if (gldesc.get_core_profile())
				flags |= 0x1;	// WGL_CONTEXT_CORE_PROFILE_BIT_ARB

			if (gldesc.get_compatibility_profile())	// WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
				flags |= 0x2;
			int_attributes.push_back(flags);

			int_attributes.push_back(0);

			opengl3_context = wglCreateContextAttribsARB(hdc, share_context, &int_attributes[0]);
		}

		reset_active();

		return opengl3_context;
	}
コード例 #3
0
void CL_GL1CreationHelper::set_multisampling_pixel_format(const CL_GL1WindowDescription &gldesc)
{
	PIXELFORMATDESCRIPTOR pfd;
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
	pfd.iPixelType = PFD_TYPE_RGBA;
	if (gldesc.get_doublebuffer()) pfd.dwFlags |= PFD_DOUBLEBUFFER;
	if (gldesc.get_stereo()) pfd.dwFlags |= PFD_STEREO;
	pfd.cColorBits = gldesc.get_buffer_size();
	pfd.cRedBits = gldesc.get_red_size();
	pfd.cGreenBits = gldesc.get_green_size();
	pfd.cBlueBits = gldesc.get_blue_size();
	pfd.cAlphaBits = gldesc.get_alpha_size();
	pfd.cDepthBits = gldesc.get_depth_size();
	pfd.cStencilBits = gldesc.get_stencil_size();
	if (gldesc.is_layered())
	{
		pfd.cAlphaBits = 8;
		pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE; // | PFD_DRAW_TO_BITMAP
	}

	if (gldesc.get_multisampling() < 1)
	{
		int pixelformat = ChoosePixelFormat(hdc, &pfd);
		SetPixelFormat(hdc, pixelformat, &pfd);
	}
	else
	{
		int pixelformat = ChoosePixelFormat(hdc, &pfd);

		set_active();
		ptr_wglChoosePixelFormatEXT wglChoosePixelFormatEXT = (ptr_wglChoosePixelFormatEXT) wglGetProcAddress("wglChoosePixelFormatEXT");
		if (wglChoosePixelFormatEXT == 0)
			wglChoosePixelFormatEXT = (ptr_wglChoosePixelFormatEXT) wglGetProcAddress("wglChoosePixelFormatARB");
		reset_active();

		if (wglChoosePixelFormatEXT)
		{
			std::vector<FLOAT> float_attributes;
			std::vector<int> int_attributes;

			int_attributes.push_back(WGL_DRAW_TO_WINDOW);
			int_attributes.push_back(GL_TRUE);
			int_attributes.push_back(WGL_ACCELERATION);
			int_attributes.push_back(WGL_FULL_ACCELERATION);

			if (gldesc.get_doublebuffer())
			{
				int_attributes.push_back(WGL_DOUBLE_BUFFER);
				int_attributes.push_back(GL_TRUE);
			}
			if (gldesc.get_stereo())
			{
				int_attributes.push_back(WGL_STEREO);
				int_attributes.push_back(GL_TRUE);
			}

			int_attributes.push_back(WGL_COLOR_BITS);
			int_attributes.push_back(gldesc.get_red_size() + gldesc.get_green_size() + gldesc.get_blue_size());

			int_attributes.push_back(WGL_ALPHA_BITS);
			int_attributes.push_back(gldesc.get_alpha_size());

			int_attributes.push_back(WGL_DEPTH_BITS);
			int_attributes.push_back(gldesc.get_depth_size());

			int_attributes.push_back(WGL_STENCIL_BITS);
			int_attributes.push_back(gldesc.get_stencil_size());

			int_attributes.push_back(WGL_SAMPLE_BUFFERS);
			int_attributes.push_back(GL_TRUE);
			int_attributes.push_back(WGL_SAMPLES);
			int_attributes.push_back(gldesc.get_multisampling());

			float_attributes.push_back(0.0f);
			float_attributes.push_back(0.0f);
			int_attributes.push_back(0);
			int_attributes.push_back(0);
			int new_pixelformat = pixelformat;
			UINT num_formats = 0;
			BOOL result = wglChoosePixelFormatEXT(hdc, &int_attributes[0], &float_attributes[0], 1, &new_pixelformat, &num_formats);
			if (result == TRUE && num_formats > 0)
				pixelformat = new_pixelformat;
		}

		SetPixelFormat(hdc, pixelformat, &pfd);
	}
}