//----------------------------------------------------------------------------//
void OpenGLWGLPBTextureTarget::initialisePBuffer()
{
    int creation_attrs[] =
    {
        WGL_PBUFFER_LARGEST_ARB, true,
        0
    };

    releasePBuffer();

    HDC hdc = wglGetCurrentDC();
    d_pbuffer = wglCreatePbufferARB(hdc, d_pixfmt, 
                                    static_cast<int>(d_area.getWidth()),
                                    static_cast<int>(d_area.getHeight()),
                                    creation_attrs);

    if (!d_pbuffer)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglCreatePbufferARB() call failed."));

    d_hdc = wglGetPbufferDCARB(d_pbuffer);

    if (!d_hdc)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglGetPbufferDCARB() call failed."));

    d_context= wglCreateContext(d_hdc);

    if (!d_hdc)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglCreateContext() call failed."));

    if(!wglShareLists(wglGetCurrentContext(), d_context))
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglShareLists() call failed."));

    // extract the actual size of the created bufer
    int actual_width, actual_height;
    wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_WIDTH_ARB, &actual_width);
    wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_HEIGHT_ARB, &actual_height);
    d_area.setSize(Size(static_cast<float>(actual_width),
                        static_cast<float>(actual_height)));

    // ensure CEGUI::Texture is wrapping real GL texture and has correct size
    d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize());
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WGLARBPbuffer_nwglQueryPbufferARB(JNIEnv *__env, jclass clazz, jlong pbufferAddress, jint attribute, jlong valueAddress, jlong __functionAddress) {
	HPBUFFERARB pbuffer = (HPBUFFERARB)(intptr_t)pbufferAddress;
	int *value = (int *)(intptr_t)valueAddress;
	wglQueryPbufferARBPROC wglQueryPbufferARB = (wglQueryPbufferARBPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jint)wglQueryPbufferARB(pbuffer, attribute, value);
}
示例#3
0
void pbf_restore(pbf p)
{
	int lost = 0;
	if (p->isValid) {
		/*
		 * Check to see if pbuffer memory was lost due to a display
		 * mode change.
		 */
		wglQueryPbufferARB(p->pBuffer, WGL_PBUFFER_LOST_ARB, &lost);
		if (lost) {
			wglDeleteContext(p->rc);
			wglReleasePbufferDCARB(p->pBuffer, p->dc);
			wglDestroyPbufferARB(p->pBuffer);
			pbf_init(p, p->width, p->height, p->mode, p->share);
		}
	}
}
示例#4
0
void RenderTexture::BeginRender()
{
	if (m_FBO) {
		glBindTexture(m_texFormat, 0);
		// Bind the frame-buffer object
		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_frameBuffer );
		//glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_texFormat, m_texID, 0);

	} else { // Pixel Buffer
		int flag = 0;
		wglQueryPbufferARB(m_hPBuffer, WGL_PBUFFER_LOST_ARB, &flag );

		if (flag) {
			LOG_ERROR << "The PixelBuffer was lost!";
			return;
		}

		if (!wglMakeCurrent(m_hDC, m_hRC))
			LOG_ERROR << "Could not make the PixelBuffer's context current.";
	}
}
示例#5
0
void RenderTexture::Init(int width, int height, bool fboMode)
{
	GLenum err;
	canvas_hDC = wglGetCurrentDC();
	canvas_hRC = wglGetCurrentContext();

	m_texID = 0;
	m_FBO = fboMode;

	if (width == 0 || height == 0)
	{
		int screenSize[4];
		glGetIntegerv(GL_VIEWPORT, screenSize);

		nWidth = screenSize[2];
		nHeight = screenSize[3];
	}
	else
	{
		nWidth = width;
		nHeight = height;
	}

	// Find the (easiest) format to use
	if (video.supportNPOT && video.supportTexRects && GL_TEXTURE_RECTANGLE_ARB)
	{
		m_texFormat = GL_TEXTURE_RECTANGLE_ARB;
	}
	else
	{
		// If non-power-of-two textures aren't supported, force them to be power-of-two of the max texture size.
		m_texFormat = GL_TEXTURE_2D;

		GLint texSize; 
		glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); 

		bool end=false;
		int curMax=0;

		// Make sure its square and a power-of-two
		for (size_t i=5; !end; i++)
		{
			int iSize = powf(2,(float)i);
			if (iSize < texSize)
				curMax = iSize;
			else
				end = true;
		}

		// Divide by 2 to make sure they're no where near their max texture size
		nWidth = nHeight = (curMax/2);
	}

	// Hmm... why was this here?
	//m_texFormat = GL_TEXTURE_2D;


	if (m_FBO)
	{ // Frame Buffer OBject mode (newer, better, only supported by newer cards and drivers though)
		
		// Reported crash in this section of the code by a user
		// add exception handling to try and capture it for future versions.
		try
		{
			LOG_INFO << "GFX Info: Initialising FrameBufferObject.";

			// Generate our buffers and texture
			glGenFramebuffers(1, &m_frameBuffer );
			glGenRenderbuffers(1, &m_depthRenderBuffer );
			glGenTextures(1, &m_texID);

			// --
			// Bind frame buffer and texture
			glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_frameBuffer);
			glBindTexture(m_texFormat, m_texID);

			// This is our dynamic texture, which will be loaded with new pixel data
			// after we're finshed rendering to the p-buffer.
			glTexImage2D(m_texFormat, 0, GL_RGBA8, nWidth, nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
			glTexParameteri(m_texFormat, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			glTexParameteri(m_texFormat, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

			// And attach it to the FBO so we can render to it
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_texFormat, m_texID, 0);

			// attach a depth buffer to the Frame buffer
			glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthRenderBuffer );
			glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, nWidth, nHeight);
			glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthRenderBuffer);

			CHECK_FRAMEBUFFER_STATUS();

			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);	// Unbind the FBO for now
		}
		catch (...)
		{
			LOG_ERROR << "FrameBuffer Error:" << __FILE__ << ": line #" << __LINE__ << ":" << __FUNCTION__;
		}

	}
	else
	{ // Pixel Buffer Mode
		LOG_INFO << "Attempting to create a PixelBuffer.";

		//-------------------------------------------------------------------------
		// Create a p-buffer for off-screen rendering.
		//-------------------------------------------------------------------------
		
		// Define the minimum pixel format requirements we will need for our 
		// p-buffer. A p-buffer is just like a frame buffer, it can have a depth 
		// buffer associated with it and it can be double buffered.
		int pf_attr[] =
		{
			WGL_SUPPORT_OPENGL_ARB, TRUE,       // P-buffer will be used with OpenGL
			WGL_DRAW_TO_PBUFFER_ARB, TRUE,      // Enable render to p-buffer
			WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // P-buffer will be used as a texture
			WGL_RED_BITS_ARB, 8,                // At least 8 bits for RED channel
			WGL_GREEN_BITS_ARB, 8,              // At least 8 bits for GREEN channel
			WGL_BLUE_BITS_ARB, 8,               // At least 8 bits for BLUE channel
			WGL_ALPHA_BITS_ARB, 8,              // At least 8 bits for ALPHA channel
			WGL_DEPTH_BITS_ARB, 16,             // At least 16 bits for depth buffer
			WGL_DOUBLE_BUFFER_ARB, FALSE,       // We don't require double buffering
			0                                   // Zero terminates the list
		};

		unsigned int iCount = 0;
		int iPixelFormat = 0;
		// g_hdc = wxglcanvas hdc

		wglChoosePixelFormatARB(canvas_hDC, (const int*)pf_attr, NULL, 1, &iPixelFormat, &iCount);

		if (iCount == 0)
		{
			LOG_ERROR << "wglChoosePixelFormatARB() Failed! PixelBuffer could not find an acceptable pixel format!" << glGetError();
			return;
		}

		// Set some p-buffer attributes so that we can use this p-buffer as a
		// 2D RGBA texture target.
		int pb_attr[] =
		{
			WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, // Our p-buffer will have a texture format of RGBA
			WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,   // Of texture target will be GL_TEXTURE_2D
			0                                             // Zero terminates the list
		};

		// Create the p-buffer...
		m_hPBuffer = wglCreatePbufferARB(canvas_hDC, iPixelFormat, nWidth, nHeight, pb_attr );

		// Error check
		err = glGetError();
		if (!m_hPBuffer)
		{
			LOG_ERROR << "Could not create the PixelBuffer." << err;
			return;
		}
		else if (err==GL_NO_ERROR)
		{
			LOG_INFO << "Successfully created the PixelBuffer.";
		}
		else if (err==GL_INVALID_ENUM)
		{
			LOG_ERROR << "Invalid Enum during PixelBuffer creation.";
		}
		else if (err==GL_INVALID_VALUE)
		{
			LOG_ERROR << "Invalid Value during PixelBuffer creation.";
		}
		else if (err==GL_INVALID_OPERATION)
		{
			LOG_ERROR << "Invalid Operation during PixelBuffer creation.";
		}
		else if (err==GL_OUT_OF_MEMORY)
		{
			LOG_ERROR << "Critical error!  Out-of-Memory during PixelBuffer creation. PixelBuffer could not be created.";
			return;
		}
		else
		{
			LOG_ERROR << "PixelBuffer created, but an unknown error occured :" << err;
		}

		m_hDC = wglGetPbufferDCARB( m_hPBuffer );
		m_hRC = wglCreateContext( m_hDC );

		int h=0, w=0;
		wglQueryPbufferARB( m_hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &h );
		wglQueryPbufferARB( m_hPBuffer, WGL_PBUFFER_WIDTH_ARB, &w );

		if (h!=nHeight || w!=nWidth)
		{
			LOG_ERROR << "The width and height of the created PixelBuffer don't match the requirements. Image likely to come out distorted.";
			nHeight = h;
			nWidth = w;
		}

		if (!wglShareLists(canvas_hRC, m_hRC))
		{
			err = glGetError();
			LOG_ERROR << "Call to wglShareLists() failed for our PixelBuffer.";
		}

		// We were successful in creating a p-buffer. We can now make its context 
		// current and set it up just like we would a regular context 
		// attached to a window.
		if (!wglMakeCurrent(m_hDC, m_hRC))
		{
			err = glGetError();
			LOG_ERROR << "wglMakeCurrent() Failed! Could not make the PBuffer's context current!" << err;
		}

		// Setup OpenGL RenderState
		InitGL();

		// This is our dynamic texture, which will be loaded with new pixel data
		// after we're finshed rendering to the p-buffer.
		glGenTextures(1, &m_texID);
		glBindTexture(m_texFormat, m_texID);
		glTexImage2D(m_texFormat, 0, GL_RGBA8, nWidth, nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); //GL_FLOAT
		glTexParameteri(m_texFormat, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri(m_texFormat, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		//glTexParameteri(texFormat, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
		//glTexParameteri(texFormat, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

		// Now set the current context back to original.
		if (!wglMakeCurrent(canvas_hDC, canvas_hRC))
		{
			err = glGetError();
			LOG_ERROR << "wglMakeCurrent() Failed! Could not return the context back to the wxGLCanvas!" << err;
		}
	}
}
示例#6
0
	bool cPBuffer::Init(unsigned int alWidth,unsigned int alHeight, cColor aCol)
	{
		#ifdef WIN32
		unsigned int lFormatNum=0;
		int lFormat=0;

		mlWidth = alWidth;
		mlHeight = alHeight;

		HDC CurrentHdc = wglGetCurrentDC();
		HGLRC CurrentGGlRc = wglGetCurrentContext();

		//Set the pixel format:
		wglChoosePixelFormatARB(CurrentHdc, &mvAttribFormat[0], NULL, 1, &lFormat, &lFormatNum);
		if(lFormatNum==0){
			Error("Couldn't find any pixel format!\n");
			return false;
		}
				
		//Create the buffer
		mPBuffer = wglCreatePbufferARB(CurrentHdc, lFormat, mlWidth, mlHeight, &mvAttribBuffer[0]);
		if (!mPBuffer)
		{
			int err = GetLastError();
			Error("pbuffer creation error!\n");
			return false;
		}

		//Get the Device Context
		mDeviceContext = wglGetPbufferDCARB(mPBuffer);
		if(!mDeviceContext){
			Error("Some DC error!\n");
		}

		//Get the GL Context
		mGLContext = wglCreateContext(mDeviceContext);
		if(!mGLContext){
			Error("Some GLRC error!\n");
		}

		if(mbShareObjects){
			if(!wglShareLists(CurrentGGlRc, mGLContext))
			{
				Error("Error sharing lists.\n");
			}
		}
		
		//Check the real dimensions of the PBuffer
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_WIDTH_ARB, &mlWidth);
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &mlHeight);
			
		//Init some GL stuff with the Buffer.
		#ifdef WIN32
		HDC OldHDC = wglGetCurrentDC();
		HGLRC OldGLRC = wglGetCurrentContext();
		#endif
		MakeCurrentContext();
				
		if(mbShareObjects)
		{
			cLowLevelGraphicsSDL* pSDLGfx = static_cast<cLowLevelGraphicsSDL*>(mpLowLevelGraphics);
			pSDLGfx->SetupGL();
		}
		
		mpLowLevelGraphics->SetClearColor(aCol);
		mpLowLevelGraphics->ClearScreen();

		wglMakeCurrent(OldHDC,OldGLRC);
		#elif defined(__linux__)
		return false;
		#endif
	
		return true;
	}
	void Win32PBuffer::createPBuffer() 
	{

        // Process format
        int bits=0;
        bool isFloat=false;
#if 0
		bool hasAlpha=true;
#endif
        switch(mFormat)
        {
            case PCT_BYTE:
                bits=8; isFloat=false;
                break;
            case PCT_SHORT:
                bits=16; isFloat=false;
                break;
            case PCT_FLOAT16:
                bits=16; isFloat=true;
                break;
            case PCT_FLOAT32:
                bits=32; isFloat=true;
                break;
            default: break;
        };
		LogManager::getSingleton().logMessage(
			" Win32PBuffer::Creating PBuffer of format bits="+
			StringConverter::toString(bits)+
			" float="+StringConverter::toString(isFloat)
	    );


		HDC old_hdc = wglGetCurrentDC();
		HGLRC old_context = wglGetCurrentContext();

		// Bind to RGB or RGBA texture
		int bttype = 0;
#if 0
		if(mUseBind)
		{
			// Only provide bind type when actually binding
			bttype = PixelUtil::hasAlpha(mInternalFormat)?
				WGL_BIND_TO_TEXTURE_RGBA_ARB : WGL_BIND_TO_TEXTURE_RGB_ARB;
		}
		int texformat = hasAlpha?
			WGL_TEXTURE_RGBA_ARB : WGL_TEXTURE_RGB_ARB;
#endif
		// Make a float buffer?
        int pixeltype = isFloat?
			WGL_TYPE_RGBA_FLOAT_ARB: WGL_TYPE_RGBA_ARB;
		
		int attrib[] = {
			WGL_RED_BITS_ARB,bits,
			WGL_GREEN_BITS_ARB,bits,
			WGL_BLUE_BITS_ARB,bits,
			WGL_ALPHA_BITS_ARB,bits,
			WGL_STENCIL_BITS_ARB,1,
			WGL_DEPTH_BITS_ARB,15,
			WGL_DRAW_TO_PBUFFER_ARB,true,
			WGL_SUPPORT_OPENGL_ARB,true,
			WGL_PIXEL_TYPE_ARB,pixeltype,
			//WGL_DOUBLE_BUFFER_ARB,true,
			//WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB, // Make sure it is accelerated
			bttype,true, // must be last, as bttype can be zero
			0
		};
		int pattrib_default[] = { 
			0
		};
#if 0
		int pattrib_bind[] = { 
			WGL_TEXTURE_FORMAT_ARB, texformat, 
			WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
			WGL_PBUFFER_LARGEST_ARB, true,
			0 
		};
#endif
		int format;
		unsigned int count;

		// Choose suitable pixel format
		wglChoosePixelFormatARB(old_hdc,attrib,NULL,1,&format,&count);
		if(count == 0)
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglChoosePixelFormatARB() failed", " Win32PBuffer::createPBuffer");

		// Analyse pixel format
		const int piAttributes[]={
				WGL_RED_BITS_ARB,WGL_GREEN_BITS_ARB,WGL_BLUE_BITS_ARB,WGL_ALPHA_BITS_ARB,
				WGL_DEPTH_BITS_ARB,WGL_STENCIL_BITS_ARB
		};
		int piValues[sizeof(piAttributes)/sizeof(const int)];
		wglGetPixelFormatAttribivARB(old_hdc,format,0,sizeof(piAttributes)/sizeof(const int),piAttributes,piValues);

        LogManager::getSingleton().stream()
			<< " Win32PBuffer::PBuffer -- Chosen pixel format rgba="
            << piValues[0] << ","  
            << piValues[1] << ","  
            << piValues[2] << ","  
            << piValues[3] 
            << " depth=" << piValues[4]
            << " stencil=" << piValues[5];

		mPBuffer = wglCreatePbufferARB(old_hdc,format,mWidth,mHeight,pattrib_default);
		if(!mPBuffer)
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglCreatePbufferARB() failed", " Win32PBuffer::createPBuffer");

		mHDC = wglGetPbufferDCARB(mPBuffer);
		if(!mHDC) {
			wglDestroyPbufferARB(mPBuffer);
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglGetPbufferDCARB() failed", " Win32PBuffer::createPBuffer");
		}
			
		mGlrc = wglCreateContext(mHDC);
		if(!mGlrc) {
			wglReleasePbufferDCARB(mPBuffer,mHDC);
			wglDestroyPbufferARB(mPBuffer);
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglCreateContext() failed", " Win32PBuffer::createPBuffer");
		}

		if(!wglShareLists(old_context,mGlrc)) {
			wglDeleteContext(mGlrc);
			wglReleasePbufferDCARB(mPBuffer,mHDC);
			wglDestroyPbufferARB(mPBuffer);
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglShareLists() failed", " Win32PBuffer::createPBuffer");
		}
				
		// Query real width and height
		int iWidth, iHeight;
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_WIDTH_ARB, &iWidth);
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &iHeight);
		mWidth = iWidth;  
		mHeight = iHeight;
		LogManager::getSingleton().stream()
			<< "Win32RenderTexture::PBuffer created -- Real dimensions "
            << mWidth << "x" << mHeight;
	}
示例#8
0
bool PBUFFER::Init(	int newWidth, int newHeight,
					const int * attribIList, const float * attribFList, const int * flags)
{
	//Check for pbuffer support
	if(	!GLEE_WGL_ARB_extensions_string	||
		!GLEE_WGL_ARB_pixel_format		||
		!GLEE_WGL_ARB_pbuffer)
	{
		LOG::Instance()->OutputError("Extension required for pBuffer unsupported");
		return false;
	}

	//set class's member variables
	width=newWidth;
	height=newHeight;
	
	//Get the current device context
	HDC hCurrentDC=wglGetCurrentDC();
	if(!hCurrentDC)
	{
		LOG::Instance()->OutputError("Unable to get current Device Context");
		return false;
	}
	
	
	//choose pixel format
	GLint pixelFormat;
	unsigned int numFormats;

	if(!wglChoosePixelFormatARB(hCurrentDC, attribIList, attribFList, 1,
								&pixelFormat, &numFormats))
	{
		LOG::Instance()->OutputError("Unable to find a pixel format for the pbuffer");
		return false;
	}

	//Create the pbuffer
	hBuffer=wglCreatePbufferARB(hCurrentDC, pixelFormat, width, height, flags);
	if(!hBuffer)
	{
		LOG::Instance()->OutputError("Unable to create pbuffer");
		return false;
	}

	//Get the pbuffer's device context
	hDC=wglGetPbufferDCARB(hBuffer);
	if(!hDC)
	{
		LOG::Instance()->OutputError("Unable to get pbuffer's device context");
		return false;
	}

	//Create a rendering context for the pbuffer
	hRC=wglCreateContext(hDC);
	if(!hRC)
	{
		LOG::Instance()->OutputError("Unable to create pbuffer's rendering context");
		return false;
	}

	//Set and output the actual pBuffer dimensions
	wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &width);
	wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
	LOG::Instance()->OutputSuccess("Pbuffer Created: (%d x %d)", width, height);
	
	return TRUE;										//success!
}
int ObjMeshGPUDeformer_uUq_pbuffer::InitRTT()
{
  // init WGL extensions

  wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
  char *ext = NULL;

  if( wglGetExtensionsStringARB )
    ext = (char*)wglGetExtensionsStringARB( wglGetCurrentDC() );
  else
  {
    printf("Unable to get address for wglGetExtensionsStringARB!");
    return 1;
  }

  //
  // WGL_ARB_pbuffer
  //

  if( strstr( ext, "WGL_ARB_pbuffer" ) == NULL )
  {
    printf("WGL_ARB_pbuffer extension was not found");
    return 1;
  }
  else
  {
    wglCreatePbufferARB    = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
    wglGetPbufferDCARB     = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
    wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
    wglDestroyPbufferARB   = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
    wglQueryPbufferARB     = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");

    if( !wglCreatePbufferARB || !wglGetPbufferDCARB || !wglReleasePbufferDCARB ||
      !wglDestroyPbufferARB || !wglQueryPbufferARB )
    {
      printf("One or more WGL_ARB_pbuffer functions were not found");
      return 1;
    }
  }

  //
  // WGL_ARB_pixel_format
  //

  if( strstr( ext, "WGL_ARB_pixel_format" ) == NULL )
  {
    printf("Error: WGL_ARB_pixel_format extension was not found");
    return 1;
  }
  else
  {
    wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");

    if( !wglChoosePixelFormatARB )
    {
      printf("Error: One or more WGL_ARB_pixel_format functions were not found");
      return 1;
    }
  }

  //
  // WGL_ARB_render_texture
  //

  if( strstr( ext, "WGL_ARB_render_texture" ) == NULL )
  {
    printf("WGL_ARB_render_texture extension was not found");
    return 1;
  }
  else
  {
    wglBindTexImageARB     = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
    wglReleaseTexImageARB  = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
    wglSetPbufferAttribARB = (PFNWGLSETPBUFFERATTRIBARBPROC)wglGetProcAddress("wglSetPbufferAttribARB");

    if( !wglBindTexImageARB || !wglReleaseTexImageARB || !wglSetPbufferAttribARB )
    {
      printf("One or more WGL_ARB_render_texture functions were not found");
      return 1;
    }
  }

  hDC = wglGetCurrentDC();
  hRC = wglGetCurrentContext();

  //-------------------------------------------------------------------------
  // Create a p-buffer for off-screen rendering.
  //-------------------------------------------------------------------------
  int width = vertexDeformationTextureSize;
  int height = vertexDeformationTextureSize;

  pbuffer.hPBuffer = NULL;
  pbuffer.nWidth   = width;
  pbuffer.nHeight  = height;

  //
  // Define the minimum pixel format requirements we will need for our 
  // p-buffer. A p-buffer is just like a frame buffer, it can have a depth 
  // buffer associated with it and it can be double buffered.
  //

  int pf_attr[] =
  {
    WGL_SUPPORT_OPENGL_ARB, TRUE,       // P-buffer will be used with OpenGL
      WGL_DRAW_TO_PBUFFER_ARB, TRUE,      // Enable render to p-buffer
      WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // P-buffer will be used as a texture
      WGL_RED_BITS_ARB, 32,                // At least 8 bits for RED channel
      WGL_GREEN_BITS_ARB, 32,              // At least 8 bits for GREEN channel
      WGL_BLUE_BITS_ARB, 32,               // At least 8 bits for BLUE channel
      WGL_ALPHA_BITS_ARB, 32,              // At least 8 bits for ALPHA channel
      WGL_DEPTH_BITS_ARB, 0,             // At least 0 bits for depth buffer
      WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_FLOAT_ATI,
      WGL_DOUBLE_BUFFER_ARB, FALSE,       // We don't require double buffering
      0                                   // Zero terminates the list
  };

  unsigned int count = 0;
  int pixelFormat;
  wglChoosePixelFormatARB( hDC, (const int*)pf_attr, NULL, 1, &pixelFormat, &count);

  if( count == 0 )
  {
    printf("Could not find an acceptable pixel format!");
    return 1;
  }

  //
  // Set some p-buffer attributes so that we can use this p-buffer as a
  // 2D RGBA texture target.
  //

  int pb_attr[] =
  {
    WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, // Our p-buffer will have a texture format of RGBA
      WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,   // Of texture target will be GL_TEXTURE_2D
      0                                             // Zero terminates the list
  };

  //
  // Create the p-buffer...
  //

  pbuffer.hPBuffer = wglCreatePbufferARB( hDC, pixelFormat, 
    pbuffer.nWidth, pbuffer.nHeight, pb_attr );
  pbuffer.hDC      = wglGetPbufferDCARB( pbuffer.hPBuffer );
  pbuffer.hRC      = wglCreateContext( pbuffer.hDC );

  if( !pbuffer.hPBuffer )
  {
    printf("Error: could not create the p-buffer");
    return 1;
  }

  int queryHeight;
  int queryWidth;
  wglQueryPbufferARB( pbuffer.hPBuffer, WGL_PBUFFER_WIDTH_ARB, &queryHeight );
  wglQueryPbufferARB( pbuffer.hPBuffer, WGL_PBUFFER_WIDTH_ARB, &queryWidth );

  if( queryHeight != pbuffer.nHeight || queryWidth != pbuffer.nWidth )
  {
    printf("The width and height of the created p-buffer don't match the requirements!");
    return 1;
  }

  return 0;
}
示例#10
0
bool PBuffer::create(int w, int h, int pixel_format, bool bShareContext, bool bShareObjects)
{
	HDC hdc = wglGetCurrentDC();
	HGLRC hglrc = wglGetCurrentContext();
	wglGetLastError();

	m_bShareContext = bShareContext;
	m_bShareObjects = bShareObjects;

	// Query for a suitable pixel format based on the specified mode.
	int     format;
	int     pformat[MAX_PFORMATS];
	unsigned int nformats;
	int     iattributes[2*MAX_ATTRIBS];
	float   fattributes[2*MAX_ATTRIBS];
	int     nfattribs = 0;
	int     niattribs = 0;

/*	const int iattributes[] = { WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
	                           WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
	                           WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_FLOAT_ARB,
	                           WGL_RED_BITS_ARB, 16,
	                           WGL_GREEN_BITS_ARB, 16,
	                           WGL_BLUE_BITS_ARB, 16,
	         //                  WGL_ALPHA_BITS_ARB, 16,
	           //                WGL_DEPTH_BITS_ARB, 24,
	                           WGL_BIND_TO_TEXTURE_RGBA_ARB, GL_TRUE,
	                           0 };
	niattribs = 9;*/

	// Attribute arrays must be "0" terminated - for simplicity, first
	// just zero-out the array entire, then fill from left to right.
	memset(iattributes, 0, sizeof(int)*2*MAX_ATTRIBS);
	memset(fattributes, 0, sizeof(float)*2*MAX_ATTRIBS);

	// Since we are trying to create a pbuffer, the pixel format we
	// request (and subsequently use) must be "p-buffer capable".
	iattributes[niattribs  ] = WGL_DRAW_TO_PBUFFER_ARB;
	iattributes[++niattribs] = GL_TRUE;

	// we are asking for a pbuffer that is meant to be bound
	// as an RGBA texture - therefore we need a color plane
	iattributes[++niattribs] = WGL_BIND_TO_TEXTURE_RGBA_ARB;
	iattributes[++niattribs] = GL_TRUE;

	switch (pixel_format)
	{
	case GL_RGBA8:
		iattributes[++niattribs] = WGL_PIXEL_TYPE_ARB;
		iattributes[++niattribs] = WGL_TYPE_RGBA_ARB;
		
		iattributes[++niattribs] = WGL_RED_BITS_ARB;
		iattributes[++niattribs] = 8;
		iattributes[++niattribs] = WGL_GREEN_BITS_ARB;
		iattributes[++niattribs] = 8;
		iattributes[++niattribs] = WGL_BLUE_BITS_ARB;
		iattributes[++niattribs] = 8;
		break;
	case GL_RGBA16F_ARB:
		iattributes[++niattribs] = WGL_PIXEL_TYPE_ARB;
		iattributes[++niattribs] = WGL_TYPE_RGBA_FLOAT_ARB;
		
		iattributes[++niattribs] = WGL_RED_BITS_ARB;
		iattributes[++niattribs] = 16;
		iattributes[++niattribs] = WGL_GREEN_BITS_ARB;
		iattributes[++niattribs] = 16;
		iattributes[++niattribs] = WGL_BLUE_BITS_ARB;
		iattributes[++niattribs] = 16;
		break;
	case GL_RGBA32F_ARB:
		iattributes[++niattribs] = WGL_PIXEL_TYPE_ARB;
		iattributes[++niattribs] = WGL_TYPE_RGBA_FLOAT_ARB;
		
		iattributes[++niattribs] = WGL_RED_BITS_ARB;
		iattributes[++niattribs] = 32;
		iattributes[++niattribs] = WGL_GREEN_BITS_ARB;
		iattributes[++niattribs] = 32;
		iattributes[++niattribs] = WGL_BLUE_BITS_ARB;
		iattributes[++niattribs] = 32;
		break;
	default: Console::print("PBuffer::create(): Unsupported pixel format\n"); ASSERT(0);
	}

	if (m_bShareContext)
    {
		// Get the pixel format for the on-screen window.
		format = GetPixelFormat(hdc);
		if (format == 0)
		{
			Console::print("pbuffer creation error:  GetPixelFormat() failed\n");
			return false;
		}
    }
    else
    {
		if ( !wglChoosePixelFormatARB( hdc, iattributes, fattributes, MAX_PFORMATS, pformat, &nformats ) )
		{
			Console::print("pbuffer creation error:  wglChoosePixelFormatARB() failed.\n");
			return false;
		}
		wglGetLastError();
		if (nformats <= 0)
		{
			Console::print("pbuffer creation error:  Couldn't find a suitable pixel format.\n");
			return false;
		}
		format = pformat[0];
	}

	// Set up the pbuffer attributes
/*	memset(iattributes, 0, sizeof(int)*2*MAX_ATTRIBS);
	niattribs = 0;
	
	// the render texture format is RGBA
	iattributes[niattribs] = WGL_TEXTURE_FORMAT_ARB;
	iattributes[++niattribs] = texFormat;
	
	// the render texture target is GL_TEXTURE_2D
	iattributes[++niattribs] = WGL_TEXTURE_TARGET_ARB;
	iattributes[++niattribs] = WGL_TEXTURE_2D_ARB;
	
	// ask to allocate room for the mipmaps
//	iattributes[++niattribs] = WGL_MIPMAP_TEXTURE_ARB;
//	iattributes[++niattribs] = TRUE;
	
	// ask to allocate the largest pbuffer it can, if it is
	// unable to allocate for the width and height
	iattributes[++niattribs] = WGL_PBUFFER_LARGEST_ARB;
	iattributes[++niattribs] = FALSE;*/
	
	// Choose a pixel format for the floating-point framebuffer
	const int fbuffer_flags[] = { WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
	                              WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
	                              0 };

	// Create the p-buffer.
	m_hpbuffer = wglCreatePbufferARB( hdc, format, w, h, fbuffer_flags /*iattributes*/ );
	if (m_hpbuffer == 0)
	{
		Console::print("pbuffer creation error:  wglCreatePbufferARB() failed\n");
		wglGetLastError();
		return false;
	}
	wglGetLastError();

	// Get the device context.
	m_hdc = wglGetPbufferDCARB(m_hpbuffer);
	if (m_hdc == 0)
	{
		Console::print("pbuffer creation error:  wglGetPbufferDCARB() failed\n");
		wglGetLastError();
		return false;
	}
	wglGetLastError();

	if (m_bShareContext)
	{
		// share the context
		// Since the device contexts are compatible (i.e. same pixelformat),
        // we should be able to use the same gl rendering context.
		m_hglrc = hglrc;
	}
	else
	{
		// Create a gl context for the p-buffer.
		m_hglrc = wglCreateContext(m_hdc);
		if (m_hglrc == 0)
		{
			Console::print("pbuffer creation error:  wglCreateContext() failed\n");
			wglGetLastError();
			return false;
		}
		wglGetLastError();
	}
	
	if (m_bShareObjects)
	{
		if(!wglShareLists(hglrc, m_hglrc))
		{
			Console::print("pbuffer: wglShareLists() failed\n");
			return false;
		}
	}

	// Determine the actual width and height we were able to create.
	wglQueryPbufferARB( m_hpbuffer, WGL_PBUFFER_WIDTH_ARB, &m_width );
	wglQueryPbufferARB( m_hpbuffer, WGL_PBUFFER_HEIGHT_ARB, &m_height );

	Console::print("Created P-Buffer - width: %d, height: %d\n", m_width, m_height);

	return true;
}
示例#11
0
文件: water.c 项目: mpersano/protozoa
static void
initialize_pbuffer(void)
{
#ifdef WIN32
	static int attribs_render_texture[] = {
		WGL_DRAW_TO_PBUFFER_ARB, 1,
		WGL_SUPPORT_OPENGL_ARB, 1,
		WGL_RED_BITS_ARB, 8,
		WGL_GREEN_BITS_ARB, 8,
		WGL_BLUE_BITS_ARB, 8,
		WGL_ALPHA_BITS_ARB, 8,
		WGL_DEPTH_BITS_ARB, 24,
		WGL_BIND_TO_TEXTURE_RGBA_ARB, 1,
		0
	};
	static int attribs_no_render_texture[] = {
		WGL_DRAW_TO_PBUFFER_ARB, 1,
		WGL_SUPPORT_OPENGL_ARB, 1,
		WGL_RED_BITS_ARB, 8,
		WGL_GREEN_BITS_ARB, 8,
		WGL_BLUE_BITS_ARB, 8,
		WGL_ALPHA_BITS_ARB, 8,
		WGL_DEPTH_BITS_ARB, 24,
		0
	};


	static int pbuffer_attribs_render_texture[] = {
		WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
		WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
		0
	};
	static int pbuffer_attribs_no_render_texture[] = {
		0
	};

	int count, pixel_format;
	int width, height;
	const int rt = settings.static_settings->use_pbuffer_render_texture;

	prev_hdc = wglGetCurrentDC();
	prev_wgl_context = wglGetCurrentContext();

	wglChoosePixelFormatARB(prev_hdc, rt ? attribs_render_texture : attribs_no_render_texture, NULL, 1,
	  &pixel_format, &count);

	pbuffer = wglCreatePbufferARB(prev_hdc, pixel_format,
	  backg_texture_size(), backg_texture_size(),
	  rt ? pbuffer_attribs_render_texture : pbuffer_attribs_no_render_texture);
	if (!pbuffer)
		panic("wglCreatePbufferARB failed");

	if (!(pbuffer_hdc = wglGetPbufferDCARB(pbuffer)))
		panic("wglGetPbufferDCARB failed");

	if (!(pbuffer_wgl_context = wglCreateContext(pbuffer_hdc)))
		panic("wglCreateContext failed");

	fprintf(stderr, "pbuffer wgl context: %p\n", pbuffer_hdc);

	if (!wglShareLists(prev_wgl_context, pbuffer_wgl_context))
		panic("wglShareLists failed");

	wglQueryPbufferARB(pbuffer, WGL_PBUFFER_WIDTH_ARB, &width);
	wglQueryPbufferARB(pbuffer, WGL_PBUFFER_HEIGHT_ARB, &height);

	fprintf(stderr, "pbuffer created: %dx%d\n", width, height);
#else
	assert(0);
#endif
}
示例#12
0
void pbf_init(pbf p, int w, int h, int mode, bool share)
{
	int iattribs[2*MAX_ATTRIBS];
	float fattribs[2*MAX_ATTRIBS];
	int pformat[MAX_PFORMATS];
	int nfattribs = 0;
	int niattribs = 0;
	unsigned int nformats;
	int format;
	HDC dc = wglGetCurrentDC();
	HGLRC rc = wglGetCurrentContext();

	if (p) {
		memset(p, 0, sizeof(struct pbf_str));
		memset(iattribs, 0, sizeof(iattribs));
		memset(fattribs, 0, sizeof(fattribs));

		p->width = w;
		p->height = h;
		p->mode = mode;
		p->share = share;
		p->glutWin = glutGetWindow();
		p->glutWinDc = dc;
		p->glutWinRc = rc;
		p->isValid = false;

		/* pBuffer pixel format must be "p-buffer capable" */
		iattribs[2*niattribs    ] = WGL_DRAW_TO_PBUFFER_ARB;
		iattribs[2*niattribs + 1] = true;
		niattribs++;

		if (mode & GLUT_INDEX) {
			iattribs[2*niattribs    ] = WGL_PIXEL_TYPE_ARB;
			iattribs[2*niattribs + 1] = WGL_TYPE_COLORINDEX_ARB;
			niattribs++;
		}
		else {
			iattribs[2*niattribs    ] = WGL_PIXEL_TYPE_ARB;
			iattribs[2*niattribs + 1] = WGL_TYPE_RGBA_ARB;
			niattribs++;
		}

		if (mode & GLUT_DOUBLE) {
			iattribs[2*niattribs    ] = WGL_DOUBLE_BUFFER_ARB;
			iattribs[2*niattribs + 1] = true;
			niattribs++;
		}

		if (mode & GLUT_DEPTH) {
			iattribs[2*niattribs    ] = WGL_DEPTH_BITS_ARB;
			iattribs[2*niattribs + 1] = true;
			niattribs++;
		}
		if (mode & GLUT_STENCIL) {
			iattribs[2*niattribs    ] = WGL_STENCIL_BITS_ARB;
			iattribs[2*niattribs + 1] = true;
			niattribs++;
		}
		if (mode & GLUT_ACCUM) {
			iattribs[2*niattribs    ] = WGL_ACCUM_BITS_ARB;
			iattribs[2*niattribs + 1] = true;
			niattribs++;
		}

		iattribs[2*niattribs    ] = WGL_SUPPORT_OPENGL_ARB;
		iattribs[2*niattribs + 1] = true;
		niattribs++;

		if (!wglChoosePixelFormatARB(
				dc, iattribs, fattribs, MAX_PFORMATS, pformat, &nformats))
			return;
		format = pformat[0];

		iattribs[0] = 0;
		p->pBuffer = wglCreatePbufferARB(
											dc, format, w, h, iattribs);
		if (!p->pBuffer)
			return;

		p->dc = wglGetPbufferDCARB(p->pBuffer);
		if (!p->dc) {
			wglDestroyPbufferARB(p->pBuffer);
			return;
		}

		p->rc = wglCreateContext(p->dc);
		if (!p->rc) {
			wglReleasePbufferDCARB(p->pBuffer, p->dc);
			wglDestroyPbufferARB(p->pBuffer);
			return;
		}

		if (share) {
			if(!wglShareLists(rc, p->rc))
				p->share = false;
		}

		/* Determine actual width and height */
		wglQueryPbufferARB(p->pBuffer,
								WGL_PBUFFER_WIDTH_ARB, &p->width);
		wglQueryPbufferARB(p->pBuffer,
								WGL_PBUFFER_HEIGHT_ARB, &p->height);

		p->isValid = true;
	}
}
示例#13
0
RenderTarget::RenderTarget(int width, int height, Format format)
{
    this->width = width;
    this->height = height;

    unsigned int count = 0;
    int			 pixelFormat;

    if (!WGL_ARB_pixel_format_initialized) {
        console::print(1, 0, 0, "Error(RenderTarget): WGL_ARB_pixel_format not avilable!");
        return;
    }
    /*if (!WGL_ARB_make_current_read_initialized) {
    	console::print(1, 0, 0, "Error(RenderTarget): WGL_ARB_make_current_read not avilable!");
    	return;
    }*/
    if (!WGL_ARB_pbuffer_initialized) {
        console::print(1, 0, 0, "Error(RenderTarget): WGL_ARB_pbuffer not avilable!");
        return;
    }
    if (!WGL_ARB_render_texture_initialized) {
        console::print(1, 0, 0, "Error(RenderTarget): WGL_ARB_render_texture not avilable!");
        return;
    }

    int pAttrib[] = {
        WGL_TEXTURE_FORMAT_ARB,		WGL_TEXTURE_RGBA_ARB,
        WGL_TEXTURE_TARGET_ARB,		WGL_TEXTURE_2D_ARB,
        0
    };

    if (format == rgba8) {
        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,				TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,			TRUE,
            WGL_BIND_TO_TEXTURE_RGBA_ARB,		TRUE,
            WGL_RED_BITS_ARB,					8,
            WGL_GREEN_BITS_ARB,					8,
            WGL_BLUE_BITS_ARB,					8,
            WGL_ALPHA_BITS_ARB,					8,
            WGL_DEPTH_BITS_ARB,					24,
            WGL_DOUBLE_BUFFER_ARB,				FALSE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1, 0, 0, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }
    }
    else if (format == rgba8rect) {
        if (!WGL_NV_render_texture_rectangle_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): WGL_NV_render_texture_rectangle not avilable!");
            return;
        }

        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,				TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,			TRUE,
            WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV,	TRUE,
            WGL_RED_BITS_ARB,					8,
            WGL_GREEN_BITS_ARB,					8,
            WGL_BLUE_BITS_ARB,					8,
            WGL_ALPHA_BITS_ARB,					8,
            WGL_DEPTH_BITS_ARB,					24,
            WGL_DOUBLE_BUFFER_ARB,				FALSE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1, 0, 0, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }

        pAttrib[3] = WGL_TEXTURE_RECTANGLE_NV;
    }
    else if (format == rgb8) {
        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,				TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,			TRUE,
            WGL_BIND_TO_TEXTURE_RGBA_ARB,		TRUE,
            WGL_RED_BITS_ARB,					8,
            WGL_GREEN_BITS_ARB,					8,
            WGL_BLUE_BITS_ARB,					8,
            WGL_DEPTH_BITS_ARB,					24,
            WGL_DOUBLE_BUFFER_ARB,				FALSE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1, 0, 0, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }

        pAttrib[1] = WGL_TEXTURE_RGB_ARB;
    }
    else if (format == rgba8db) {
        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,				TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,			TRUE,
            WGL_BIND_TO_TEXTURE_RGBA_ARB,		TRUE,
            WGL_RED_BITS_ARB,					8,
            WGL_GREEN_BITS_ARB,					8,
            WGL_BLUE_BITS_ARB,					8,
            WGL_ALPHA_BITS_ARB,					8,
            WGL_DEPTH_BITS_ARB,					24,
            WGL_DOUBLE_BUFFER_ARB,				TRUE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1, 0, 0, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }
    }
    else if (format == rgba8dbrect) {
        if (!WGL_NV_render_texture_rectangle_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): WGL_NV_render_texture_rectangle not avilable!");
            return;
        }

        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,				TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,			TRUE,
            WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV,	TRUE,
            WGL_RED_BITS_ARB,					8,
            WGL_GREEN_BITS_ARB,					8,
            WGL_BLUE_BITS_ARB,					8,
            WGL_ALPHA_BITS_ARB,					8,
            WGL_DEPTH_BITS_ARB,					24,
            WGL_STENCIL_BITS_ARB,				8,
            WGL_DOUBLE_BUFFER_ARB,				TRUE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1, 0, 0, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }

        pAttrib[3] = WGL_TEXTURE_RECTANGLE_NV;
    }
    else if (format == rgb16f) {
        if (!WGL_ATI_pixel_format_float_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): WGL_ATI_pixel_format_float not avilable!");
            return;
        }
        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,			TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,		TRUE,
            WGL_BIND_TO_TEXTURE_RGB_ARB,	TRUE,
            WGL_PIXEL_TYPE_ARB,				WGL_TYPE_RGBA_FLOAT_ATI,
            WGL_RED_BITS_ARB,				32,
            WGL_GREEN_BITS_ARB,				32,
            WGL_BLUE_BITS_ARB,				32,
            WGL_DEPTH_BITS_ARB,				24,
            WGL_DOUBLE_BUFFER_ARB,			FALSE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }

        pAttrib[1] = WGL_TEXTURE_RGB_ARB;
    }
    else if (format == rgb16frect) {
        if (!GL_NV_float_buffer_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): GL_NV_float_buffer not avilable!");
            return;
        }
        if (!WGL_NV_float_buffer_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): WGL_NV_float_buffer not avilable!");
            return;
        }
        if (!WGL_NV_render_texture_rectangle_initialized) {
            console::print(1, 0, 0, "Error(RenderTarget): WGL_NV_render_texture_rectangle not avilable!");
            return;
        }

        int attr[] = {
            WGL_SUPPORT_OPENGL_ARB,			TRUE,
            WGL_DRAW_TO_PBUFFER_ARB,		TRUE,
            WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV, TRUE,
            WGL_FLOAT_COMPONENTS_NV,					TRUE,
            WGL_RED_BITS_ARB,				32,
            WGL_GREEN_BITS_ARB,				32,
            WGL_BLUE_BITS_ARB,				32,
            WGL_DEPTH_BITS_ARB,				24,
            WGL_DOUBLE_BUFFER_ARB,			FALSE,
            0
        };

        if (!wglChoosePixelFormatARB(platform::getDC(), (const int*)attr, NULL, 1, &pixelFormat, &count)) {
            console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
            return;
        }

        pAttrib[1] = WGL_TEXTURE_FLOAT_RGB_NV;
        pAttrib[3] = WGL_TEXTURE_RECTANGLE_NV;
    }
    else {
        console::print(1, 0, 0, "Error(RenderTarget): Unknown format!");
    }

    if (count == 0) {
        console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not find suitable pbuffer pixel format!");
        return;
    }

    pb = wglCreatePbufferARB(platform::getDC(), pixelFormat, width, height, pAttrib);

    if (!pb) {
        console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not create pbuffer handle!");
        return;
    }

    dc = wglGetPbufferDCARB(pb);

    if (!dc) {
        console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not create pbuffer device context!");
        return;
    }

    rc = wglCreateContext(dc);

    if (!rc) {
        console::print(1.0f, 0.0f, 0.0f, "Error(RenderTarget): Could not create pbuffer RC!");
        return;
    }

    wglShareLists(platform::getRC(), rc);

    setActive(this);
    platform::forceResize(width, height);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_CULL_FACE);
    setActive(0);

    int w, h;
    wglQueryPbufferARB(pb, WGL_PBUFFER_WIDTH_ARB, &w);
    wglQueryPbufferARB(pb, WGL_PBUFFER_HEIGHT_ARB, &h);
    console::printf(1,1,0, "Info(RenderTarget): width = %i, height = %i", w, h);
}
示例#14
0
bool PBUFFER::Init(	int newWidth, int newHeight,
					int newColorBits, int newDepthBits, int newStencilBits,
					int numExtraIAttribs, int * extraIAttribList, int * flags)
{
	//Check for pbuffer support
	if(	!WGL_ARB_extensions_string_supported ||
		!WGL_ARB_pixel_format_supported ||
		!WGL_ARB_pbuffer_supported)
	{
		errorLog.OutputError("Extension required for pbuffer unsupported");
		return false;
	}

	//set class's member variables
	width=newWidth;
	height=newHeight;
	colorBits=newColorBits;
	depthBits=newDepthBits;
	stencilBits=newStencilBits;

	//Get the current device context
	HDC hCurrentDC=wglGetCurrentDC();
	if(!hCurrentDC)
	{
		errorLog.OutputError("Unable to get current Device Context");
		return false;
	}
	

	//choose pixel format
	GLint pixelFormat;

	const int standardIAttribList[]={	WGL_DRAW_TO_PBUFFER_ARB, 1,
										WGL_COLOR_BITS_ARB, colorBits,
										WGL_ALPHA_BITS_ARB, colorBits==32 ? 8 : 0,
										WGL_DEPTH_BITS_ARB, depthBits,
										WGL_STENCIL_BITS_ARB, stencilBits};
	const float fAttribList[]={	
										0};

	//add the extraIAttribList to the standardIAttribList
	int * iAttribList=new int[sizeof(standardIAttribList)/sizeof(int)+numExtraIAttribs*2+1];
	if(!iAttribList)
	{
		errorLog.OutputError("Unable to allocate space for iAttribList");
		return false;
	}

	memcpy(	iAttribList, standardIAttribList, sizeof(standardIAttribList));
	memcpy( iAttribList+sizeof(standardIAttribList)/sizeof(int),
			extraIAttribList, numExtraIAttribs*2*sizeof(int)+sizeof(int));

	//Choose pixel format
	unsigned int numFormats;
	if(!wglChoosePixelFormatARB(hCurrentDC, iAttribList, fAttribList, 1,
								&pixelFormat, &numFormats))
	{
		errorLog.OutputError("Unable to find a pixel format for the pbuffer");
		return false;
	}

	//Create the pbuffer
	hBuffer=wglCreatePbufferARB(hCurrentDC, pixelFormat, width, height, flags);
	if(!hBuffer)
	{
		errorLog.OutputError("Unable to create pbuffer");
		return false;
	}

	//Get the pbuffer's device context
	hDC=wglGetPbufferDCARB(hBuffer);
	if(!hDC)
	{
		errorLog.OutputError("Unable to get pbuffer's device context");
		return false;
	}

	//Create a rendering context for the pbuffer
	hRC=wglCreateContext(hDC);
	if(!hRC)
	{
		errorLog.OutputError("Unable to create pbuffer's rendering context");
		return false;
	}

	//Set and output the actual pBuffer dimensions
	wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &width);
	wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
	errorLog.OutputSuccess("Pbuffer Created: (%d x %d)", width, height);
	
	return TRUE;										//success!
}
void OGLRenderTexture2D_ARB::Create( UInt32 pWidth, UInt32 pHeight, Image::Format pFormat )
{
    mWidth  = pWidth;
    mHeight = pHeight;

    mTexture = mTexture2D = Cast<Texture2D>( GraphicSubsystem::Instance()->Create(Texture2D::StaticClass()) );
    mTexture2D->Create( mWidth, mHeight, pFormat );
    mTexture2D->Init();

    mTexture2D->SetMinFilter( Texture::MinFilter_Linear );
    mTexture2D->SetMagFilter( Texture::MagFilter_Linear );
    mTexture2D->SetWrapMode( Texture::Wrap_S, Texture::Wrap_Repeat );
    mTexture2D->SetWrapMode( Texture::Wrap_T, Texture::Wrap_Repeat );

    HDC hdc = wglGetCurrentDC();

    //
	// Define the minimum pixel format requirements we will need for our 
	// p-buffer. A p-buffer is just like a frame buffer, it can have a depth 
	// buffer associated with it and it can be double buffered.
	//
    UInt32  count = 0;
	Int32   pixelFormat;
    
	Int32 pfAttr[] =
	{
		WGL_SUPPORT_OPENGL_ARB,         TRUE,   // P-buffer will be used with OpenGL
		WGL_DRAW_TO_PBUFFER_ARB,        TRUE,   // Enable render to p-buffer
		WGL_BIND_TO_TEXTURE_RGBA_ARB,   TRUE,   // P-buffer will be used as a texture
		WGL_RED_BITS_ARB,               8,      // At least 8 bits for RED channel
		WGL_GREEN_BITS_ARB,             8,      // At least 8 bits for GREEN channel
		WGL_BLUE_BITS_ARB,              8,      // At least 8 bits for BLUE channel
		WGL_ALPHA_BITS_ARB,             8,      // At least 8 bits for ALPHA channel
		WGL_DEPTH_BITS_ARB,             16,     // At least 16 bits for depth buffer
		WGL_DOUBLE_BUFFER_ARB,          FALSE,  // We don't require double buffering
		0                                       // Zero terminates the list
	};
    wglChoosePixelFormatARB( hdc, (const int*)pfAttr, NULL, 1, (int*)&pixelFormat, (UINT*)&count );
    if( count == 0 )
	{
		MessageBox( NULL, "Could not find an acceptable pixel format!", "ERROR", MB_OK|MB_ICONEXCLAMATION );
		exit(-1);
	}

    //
	// Set some p-buffer attributes so that we can use this p-buffer as a
	// 2D RGBA texture target.
	//
	Int32 pb_attr[] =
	{
		WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, // Our p-buffer will have a texture format of RGBA
		WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,   // Of texture target will be GL_TEXTURE_2D
		0                                             // Zero terminates the list
	};

    //
	// Create the p-buffer...
	//
	mPixelBuffer.mPBuffer = wglCreatePbufferARB( (HDC)hdc, pixelFormat, pWidth, pHeight, (int*)pb_attr );
	mPixelBuffer.mDC      = wglGetPbufferDCARB( mPixelBuffer.mPBuffer );
	mPixelBuffer.mRC      = wglCreateContext( mPixelBuffer.mDC );
	if( !mPixelBuffer.mPBuffer )
	{
		MessageBox( NULL, "Could not create the p-buffer", "ERROR", MB_OK|MB_ICONEXCLAMATION );
		exit(-1);
	}

    // 
    // Validate it's size
    //
    Int32 h, w;
    wglQueryPbufferARB( (HPBUFFERARB)mPixelBuffer.mPBuffer, WGL_PBUFFER_HEIGHT_ARB, (int*)&h );
	wglQueryPbufferARB( (HPBUFFERARB)mPixelBuffer.mPBuffer, WGL_PBUFFER_WIDTH_ARB, (int*)&w );
	if( h != (Int32)pWidth || w != (Int32)pHeight )
	{
		MessageBox( NULL, "The width and height of the created p-buffer don't match the requirements!", "ERROR", MB_OK|MB_ICONEXCLAMATION );
		exit(-1);
	}

    //
    // Make sure we share the contexts 
    //
    if( !wglShareLists( wglGetCurrentContext(), mPixelBuffer.mRC ) )
    {
        MessageBox( NULL, "wglShareLists failed !", "ERROR", MB_OK|MB_ICONEXCLAMATION );
		exit(-1);
    }
}