Beispiel #1
0
bool MultiSample::InitMultiSample(HWND hwnd){
  multisampleSupportted = WGLisExtensionSupported("WGL_ARB_multisample");

  if(!multisampleSupportted)
  {
    multisampleSupportted =multisampleSupportted;
    //  return false;
  }

  PFNWGLCHOOSEPIXELFORMATARBPROC wglewChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");

  HDC hdc = ::GetDC(hwnd);

  float	fAttributes[] = {0,0};
  int iAtributes[] = 
#if 1
  {
    WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
      WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
      WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
      WGL_COLOR_BITS_ARB, 24,
      WGL_ALPHA_BITS_ARB, 8,
      WGL_DEPTH_BITS_ARB, 16,
      WGL_STENCIL_BITS_ARB, 0,
      WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
      WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
      WGL_SAMPLES_ARB, Multisample,   //1< <=2  - 16F(20-64),// 2< <=4  - 12F, // 4< <=8  - 8F, 8< <=16 -4F, 
      0,0
  };
#else
  {  
    WGL_SUPPORT_OPENGL_ARB, 1, // Must support OGL rendering  
      WGL_DRAW_TO_WINDOW_ARB, 1, // pf that can run a window  
      WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB, // must be HW accelerated  
      WGL_COLOR_BITS_ARB,     32, // 8 bits of each R, G and B  
      WGL_DEPTH_BITS_ARB,     24, // 24 bits of depth precision for window, 典型情况下深度缓冲区都是24位的,试了几台机器都不支持32位深度缓冲区  
      WGL_DOUBLE_BUFFER_ARB,GL_TRUE, // Double buffered context  
      WGL_PIXEL_TYPE_ARB,      WGL_TYPE_RGBA_ARB, // pf should be RGBA type  
      WGL_STENCIL_BITS_ARB, 8,//开启模板缓冲区,模板缓冲区位数=8  
      WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, // MSAA on,开启多重采样  
      WGL_SAMPLES_ARB,        Multisample, // 4x MSAA ,多重采样样本数量为4  
      0, 0
  }; // NULL termination  
#endif

  if(!wglewChoosePixelFormatARB(hdc, iAtributes, fAttributes, 20*2 , pixelformat, &numofFormats)) {
    multisampleSupportted = false;
    return false;
  }
  if(numofFormats <= 0)
    return false;

  MultiSampleFormat = pixelformat[0];
  return true;
}
Beispiel #2
0
// InitMultisample: Used To Query The Multisample Frequencies
static int InitMultisample(HDC hDC, PIXELFORMATDESCRIPTOR *pfd)
{
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
	int pixelFormat;
	int valid, i;
	UINT numFormats;
	float fAttributes[] = {0,0};
	// These Attributes Are The Bits We Want To Test For In Our Sample
	// Everything Is Pretty Standard, The Only One We Want To
	// Really Focus On Is The SAMPLE BUFFERS ARB And WGL SAMPLES
	// These Two Are Going To Do The Main Testing For Whether Or Not
	// We Support Multisampling On This Hardware.
	int iAttributes[] = {
		WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		WGL_COLOR_BITS_ARB, pfd->cDepthBits,
		WGL_ALPHA_BITS_ARB,0,
		WGL_DEPTH_BITS_ARB,0,
		WGL_STENCIL_BITS_ARB,0,
		WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
		WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
		WGL_SAMPLES_ARB,0,
		0,0
	};

	 // See If The String Exists In WGL!
	if (!WGLisExtensionSupported("WGL_ARB_multisample"))
		return 0;

	// Get Our Pixel Format
	wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	if (!wglChoosePixelFormatARB)
		return 0;

	for (i = 8; i >= 2; i -= 2) {
	    iAttributes[19] = i;
	    valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
	    // If We Returned True, And Our Format Count Is Greater Than 1
	    if (valid && numFormats >= 1) {
		arbMultisampleSupported = i;
		arbMultisampleFormat = pixelFormat;
		write_log (_T("OPENGL: max FSAA = %d\n"), i);
		return arbMultisampleSupported;
	    }
	}
	// Return The Valid Format
	write_log (_T("OPENGL: no FSAA support detected\n"));
	return  arbMultisampleSupported;
}
// 初始化多重渲染
bool InitMultisample(HINSTANCE hInstance,HWND hWnd,PIXELFORMATDESCRIPTOR pfd)
{  
	 // 检测是否支持多重渲染
	if (!WGLisExtensionSupported("WGL_ARB_multisample"))
	{
		arbMultisampleSupported=false;
		return false;
	}

	// 返回wglChoosePixelFormatARB函数的入口
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");	
	if (!wglChoosePixelFormatARB) 
	{
		arbMultisampleSupported=false;
		return false;
	}

	HDC hDC = GetDC(hWnd);

	int		pixelFormat;
	int		valid;
	UINT	numFormats;
	float	fAttributes[] = {0,0};

	//下面的代码设置多重采样的像素格式
	int iAttributes[] =
	{
		WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		WGL_COLOR_BITS_ARB,24,
		WGL_ALPHA_BITS_ARB,8,
		WGL_DEPTH_BITS_ARB,16,
		WGL_STENCIL_BITS_ARB,0,
		WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
		WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
		WGL_SAMPLES_ARB,4,
		0,0
	};

	// 首先我们测试是否支持4个采样点的多重采样
	valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
	// 如果返回true并且numformats大于1,则表示成功,那么起用多重采样
	if (valid && numFormats >= 1)
	{
		arbMultisampleSupported = true;
		arbMultisampleFormat = pixelFormat;	
		return arbMultisampleSupported;
	}

	// 接着我们测试是否支持2个采样点的多重采样
	iAttributes[19] = 2;
	// 如果返回true并且numformats大于1,则表示成功,那么起用多重采样
	valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
	if (valid && numFormats >= 1)
	{
		arbMultisampleSupported = true;
		arbMultisampleFormat = pixelFormat;	 
		return arbMultisampleSupported;
	}
	  
	// 返回支持多重采样
	return  arbMultisampleSupported;
}
Beispiel #4
0
// InitMultisample: Used To Query The Multisample Frequencies
bool InitMultisample(HINSTANCE hInstance,HWND hWnd,PIXELFORMATDESCRIPTOR pfd)
{  
	 // See If The String Exists In WGL!
	int UserSetMultisample=GetPrivateProfileInt("Resolution","AA",0,".\\set.ini");
	if(UserSetMultisample>8)
		UserSetMultisample=8;
	if((UserSetMultisample>4)&&(UserSetMultisample<8))
		UserSetMultisample=4;
	if((UserSetMultisample>2)&&(UserSetMultisample<4))
		UserSetMultisample=2;
	if ((!WGLisExtensionSupported("WGL_ARB_multisample"))||(UserSetMultisample<2))
	{
		arbMultisampleSupported=false;
		return false;
	}

	// Get Our Pixel Format
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");	
	if (!wglChoosePixelFormatARB) 
	{
		arbMultisampleSupported=false;
		return false;
	}

	// Get Our Current Device Context
	HDC hDC = GetDC(hWnd);

	int		pixelFormat;
	int		valid;
	UINT	numFormats;
	float	fAttributes[] = {0,0};

	// These Attributes Are The Bits We Want To Test For In Our Sample
	// Everything Is Pretty Standard, The Only One We Want To 
	// Really Focus On Is The SAMPLE BUFFERS ARB And WGL SAMPLES
	// These Two Are Going To Do The Main Testing For Whether Or Not
	// We Support Multisampling On This Hardware.
	int iAttributes[] =
	{
		WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		WGL_COLOR_BITS_ARB,24,
		WGL_ALPHA_BITS_ARB,8,
		WGL_DEPTH_BITS_ARB,16,
		WGL_STENCIL_BITS_ARB,0,
		WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
		WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
		WGL_SAMPLES_ARB,4,
		0,0
	};

	// First We Check To See If We Can Get A Pixel Format For 4 Samples
	iAttributes[19] = UserSetMultisample;
	valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);

	// If We Returned True, And Our Format Count Is Greater Than 1
	if (valid && numFormats >= 1)
	{

		arbMultisampleSupported = true;
		arbMultisampleFormat = pixelFormat;	
		return arbMultisampleSupported;

	}

	// Our Pixel Format With 4 Samples Failed, Test For 2 Samples
	iAttributes[19] = 2;
	valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
	if (valid && numFormats >= 1)
	{
		arbMultisampleSupported = true;
		arbMultisampleFormat = pixelFormat;	 
		return arbMultisampleSupported;
	}
	  
	// Return The Valid Format
	return  arbMultisampleSupported;
}