/*
* Changelog:
*
- * Jan. 2005, Removed GLEW dependencies, Erik Hofman
+ * Jan. 2005, Removed GLEW dependencies, Erik Hofman, Fred Bouvier
*/
+#ifdef HAVE_CONFIG_H
+# include <simgear_config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
#include <simgear/compiler.h>
-#include <simgear/screen/RenderTexture.h>
#include <simgear/screen/extensions.hxx>
+#include <simgear/screen/RenderTexture.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
+#ifdef _WIN32
+static bool fctPtrInited = false;
+/* WGL_ARB_pixel_format */
+static wglChoosePixelFormatARBProc wglChoosePixelFormatARBPtr = 0;
+static wglGetPixelFormatAttribivARBProc wglGetPixelFormatAttribivARBPtr = 0;
+/* WGL_ARB_pbuffer */
+static wglCreatePbufferARBProc wglCreatePbufferARBPtr = 0;
+static wglGetPbufferDCARBProc wglGetPbufferDCARBPtr = 0;
+static wglQueryPbufferARBProc wglQueryPbufferARBPtr = 0;
+static wglReleasePbufferDCARBProc wglReleasePbufferDCARBPtr = 0;
+static wglDestroyPbufferARBProc wglDestroyPbufferARBPtr = 0;
+/* WGL_ARB_render_texture */
+static wglBindTexImageARBProc wglBindTexImageARBPtr = 0;
+static wglReleaseTexImageARBProc wglReleaseTexImageARBPtr = 0;
+
+#elif defined( __APPLE__ )
+#else /* !_WIN32 */
+static bool glXVersion1_3Present = false;
+static glXChooseFBConfigProc glXChooseFBConfigPtr = 0;
+static glXCreateGLXPbufferProc glXCreateGLXPbufferPtr = 0;
+static glXGetVisualFromFBConfigProc glXGetVisualFromFBConfigPtr = 0;
+static glXCreateContextWithConfigProc glXCreateContextWithConfigPtr = 0;
+static glXCreateContextProc glXCreateContextPtr = 0;
+static glXDestroyPbufferProc glXDestroyPbufferPtr = 0;
+static glXQueryDrawableProc glXQueryDrawablePtr = 0;
+static glXQueryGLXPbufferSGIXProc glXQueryGLXPbufferSGIXPtr = 0;
+#endif
+
//---------------------------------------------------------------------------
// Function : RenderTexture::RenderTexture
// Description :
_hPBuffer(NULL),
_hPreviousDC(0),
_hPreviousContext(0),
+#elif defined( __APPLE__ )
#else
_pDisplay(NULL),
_hGLContext(NULL),
_pbufferAttribs.push_back(WGL_PBUFFER_LARGEST_ARB);
_pbufferAttribs.push_back(true);
+#elif defined( __APPLE__ )
#else
_pbufferAttribs.push_back(GLX_RENDER_TYPE_SGIX);
_pbufferAttribs.push_back(GLX_RGBA_BIT_SGIX);
char strBuffer[512];
va_list args;
va_start(args, strMsg);
-#ifdef _WIN32
+#if defined _WIN32 && !defined __CYGWIN__
_vsnprintf( strBuffer, 512, strMsg, args );
#else
vsnprintf( strBuffer, 512, strMsg, args );
fprintf(stderr, strMsg);
}
+
//---------------------------------------------------------------------------
// Function : RenderTexture::Initialize
// Description :
if (_bInitialized)
_Invalidate();
-#if _WIN32
+#ifdef _WIN32
// Get the current context.
HDC hdc = wglGetCurrentDC();
if (NULL == hdc)
}
else
{
- if (!wglChoosePixelFormatARB(hdc, &_pixelFormatAttribs[0], NULL,
+ if (!wglChoosePixelFormatARBPtr(hdc, &_pixelFormatAttribs[0], NULL,
1, &iFormat, &iNumFormats))
{
fprintf(stderr,
}
// Create the p-buffer.
- _hPBuffer = wglCreatePbufferARB(hdc, iFormat, _iWidth, _iHeight,
+ _hPBuffer = wglCreatePbufferARBPtr(hdc, iFormat, _iWidth, _iHeight,
&_pbufferAttribs[0]);
if (!_hPBuffer)
{
}
// Get the device context.
- _hDC = wglGetPbufferDCARB( _hPBuffer);
+ _hDC = wglGetPbufferDCARBPtr( _hPBuffer);
if ( !_hDC )
{
fprintf(stderr,
}
// Determine the actual width and height we were able to create.
- wglQueryPbufferARB( _hPBuffer, WGL_PBUFFER_WIDTH_ARB, &_iWidth );
- wglQueryPbufferARB( _hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &_iHeight );
+ wglQueryPbufferARBPtr( _hPBuffer, WGL_PBUFFER_WIDTH_ARB, &_iWidth );
+ wglQueryPbufferARBPtr( _hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &_iHeight );
_bInitialized = true;
//int bits[6];
int value;
_iNumColorBits[0] =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_GREEN_BITS_ARB;
_iNumColorBits[1] =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_BLUE_BITS_ARB;
_iNumColorBits[2] =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_ALPHA_BITS_ARB;
_iNumColorBits[3] =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_DEPTH_BITS_ARB;
_iNumDepthBits =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_STENCIL_BITS_ARB;
_iNumStencilBits =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? value : 0;
attrib = WGL_DOUBLE_BUFFER_ARB;
_bDoubleBuffered =
- (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value))
? (value?true:false) : false;
#if defined(_DEBUG) | defined(DEBUG)
fprintf(stderr, "\n");
#endif
+#elif defined( __APPLE__ )
#else // !_WIN32
_pDisplay = glXGetCurrentDisplay();
GLXContext context = glXGetCurrentContext();
int screen = DefaultScreen(_pDisplay);
XVisualInfo *visInfo;
- int iFormat = 0;
- int iNumFormats;
- int attrib = 0;
-
- GLXFBConfigSGIX *fbConfigs;
+ GLXFBConfig *fbConfigs;
int nConfigs;
- fbConfigs = glXChooseFBConfigSGIX(_pDisplay, screen,
+ fbConfigs = glXChooseFBConfigPtr(_pDisplay, screen,
&_pixelFormatAttribs[0], &nConfigs);
if (nConfigs == 0 || !fbConfigs)
}
// Pick the first returned format that will return a pbuffer
- for (int i=0;i<nConfigs;i++)
+ if (glXVersion1_3Present)
+ {
+ int pbufAttrib[] = {
+ GLX_PBUFFER_WIDTH, _iWidth,
+ GLX_PBUFFER_HEIGHT, _iHeight,
+ GLX_LARGEST_PBUFFER, False,
+ None
+ };
+ for (int i=0;i<nConfigs;i++)
+ {
+ _hPBuffer = glXCreatePbuffer(_pDisplay, fbConfigs[i], pbufAttrib);
+ if (_hPBuffer)
+ {
+ XVisualInfo *visInfo = glXGetVisualFromFBConfig(_pDisplay, fbConfigs[i]);
+
+ _hGLContext = glXCreateContext(_pDisplay, visInfo,
+ _bShareObjects ? context : NULL,
+ True);
+ XFree( visInfo );
+ break;
+ }
+ }
+ }
+ else
{
- _hPBuffer = glXCreateGLXPbufferSGIX(_pDisplay, fbConfigs[i],
- _iWidth, _iHeight, NULL);
- if (_hPBuffer)
+ int iFormat = 0;
+ int iNumFormats;
+ int attrib = 0;
+ for (int i=0;i<nConfigs;i++)
{
- _hGLContext = glXCreateContextWithConfigSGIX(_pDisplay,
- fbConfigs[i],
- GLX_RGBA_TYPE,
- _bShareObjects ? context : NULL,
- True);
- break;
+ _hPBuffer = glXCreateGLXPbufferPtr(_pDisplay, fbConfigs[i],
+ _iWidth, _iHeight, NULL);
+ if (_hPBuffer)
+ {
+ _hGLContext = glXCreateContextWithConfigPtr(_pDisplay,
+ fbConfigs[i],
+ GLX_RGBA_TYPE,
+ _bShareObjects ? context : NULL,
+ True);
+ break;
+ }
}
}
+ XFree( fbConfigs );
if (!_hPBuffer)
{
fprintf(stderr,
- "RenderTexture Error: glXCreateGLXPbufferSGIX() failed.\n");
+ "RenderTexture Error: glXCreateGLXPbufferPtr() failed.\n");
return false;
}
}
}
- glXQueryGLXPbufferSGIX(_pDisplay, _hPBuffer, GLX_WIDTH_SGIX,
- (GLuint*)&_iWidth);
- glXQueryGLXPbufferSGIX(_pDisplay, _hPBuffer, GLX_HEIGHT_SGIX,
- (GLuint*)&_iHeight);
+ if (!glXVersion1_3Present)
+ {
+ glXQueryGLXPbufferSGIXPtr(_pDisplay, _hPBuffer, GLX_WIDTH_SGIX,
+ (GLuint*)&_iWidth);
+ glXQueryGLXPbufferSGIXPtr(_pDisplay, _hPBuffer, GLX_HEIGHT_SGIX,
+ (GLuint*)&_iHeight);
+ }
_bInitialized = true;
_wglGetLastError();
return false;
}
+#elif defined( __APPLE__ )
#else
_hPreviousContext = glXGetCurrentContext();
_hPreviousDrawable = glXGetCurrentDrawable();
_wglGetLastError();
return false;
}
+#elif defined( __APPLE__ )
#else
if (False == glXMakeCurrent(_pDisplay,
_hPreviousDrawable, _hPreviousContext))
{
return false;
}
+ if (glXVersion1_3Present)
+ {
+ GLXDrawable draw = glXGetCurrentDrawable();
+ glXQueryDrawablePtr(_pDisplay, draw, GLX_WIDTH, (unsigned int*)&_iWidth);
+ glXQueryDrawablePtr(_pDisplay, draw, GLX_HEIGHT, (unsigned int*)&_iHeight);
+ }
#endif
return result;
glDeleteTextures(1, &_iDepthTextureID);
}
-#if _WIN32
+#ifdef _WIN32
if ( _hPBuffer )
{
// Check if we are currently rendering in the pbuffer
wglMakeCurrent(0,0);
if (!_bCopyContext)
wglDeleteContext( _hGLContext);
- wglReleasePbufferDCARB( _hPBuffer, _hDC);
- wglDestroyPbufferARB( _hPBuffer );
+ wglReleasePbufferDCARBPtr( _hPBuffer, _hDC);
+ wglDestroyPbufferARBPtr( _hPBuffer );
_hPBuffer = 0;
return true;
}
+#elif defined( __APPLE__ )
#else
if ( _hPBuffer )
{
if(glXGetCurrentContext() == _hGLContext)
// XXX I don't know if this is right at all
glXMakeCurrent(_pDisplay, _hPBuffer, 0);
- glXDestroyGLXPbufferSGIX(_pDisplay, _hPBuffer);
+ glXDestroyPbufferPtr(_pDisplay, _hPBuffer);
_hPBuffer = 0;
return true;
}
_pbufferAttribs.push_back(WGL_PBUFFER_LARGEST_ARB);
_pbufferAttribs.push_back(true);
+#elif defined( __APPLE__ )
#else
_pbufferAttribs.push_back(GLX_RENDER_TYPE_SGIX);
_pbufferAttribs.push_back(GLX_RGBA_BIT_SGIX);
va_list args;
char strBuffer[256];
va_start(args,strMode);
-#ifdef _WIN32
+#if defined _WIN32 && !defined __CYGWIN__
_vsnprintf( strBuffer, 256, strMode, args );
#else
vsnprintf( strBuffer, 256, strMode, args );
wglMakeCurrent(0,0);
if (!_bCopyContext)
wglDeleteContext( _hGLContext);
- wglReleasePbufferDCARB( _hPBuffer, _hDC);
- wglDestroyPbufferARB( _hPBuffer );
+ wglReleasePbufferDCARBPtr( _hPBuffer, _hDC);
+ wglDestroyPbufferARBPtr( _hPBuffer );
_hPBuffer = 0;
return true;
}
+#elif defined( __APPLE__ )
#else
if ( _hPBuffer )
{
if(glXGetCurrentContext() == _hGLContext)
// XXX I don't know if this is right at all
glXMakeCurrent(_pDisplay, _hPBuffer, 0);
- glXDestroyGLXPbufferSGIX(_pDisplay, _hPBuffer);
+ glXDestroyPbufferPtr(_pDisplay, _hPBuffer);
_hPBuffer = 0;
}
#endif
_hPreviousContext = wglGetCurrentContext();
if (NULL == _hPreviousContext)
_wglGetLastError();
+#elif defined( __APPLE__ )
#else
_hPreviousContext = glXGetCurrentContext();
_hPreviousDrawable = glXGetCurrentDrawable();
_wglGetLastError();
return false;
}
+#elif defined( __APPLE__ )
#else
if (False == glXMakeCurrent(_pDisplay, _hPreviousDrawable,
_hPreviousContext))
_hPreviousContext = current->_hPreviousContext;
if (NULL == _hPreviousContext)
_wglGetLastError();
+#elif defined( __APPLE__ )
#else
_hPreviousContext = current->_hPreviousContext;
_hPreviousDrawable = current->_hPreviousDrawable;
{
glBindTexture(_iTextureTarget, _iTextureID);
-#if _WIN32
+#ifdef _WIN32
if (RT_RENDER_TO_TEXTURE == _eUpdateMode && _bIsTexture &&
(!_bIsBufferBound || _iCurrentBoundBuffer != iBuffer))
{
- if (FALSE == wglBindTexImageARB(_hPBuffer, iBuffer))
+ if (FALSE == wglBindTexImageARBPtr(_hPBuffer, iBuffer))
{
// WVB: WGL API considers binding twice to the same buffer
// to be an error. But we don't want to
RT_RENDER_TO_TEXTURE == _eUpdateMode)
{
glBindTexture(_iTextureTarget, _iDepthTextureID);
- if (FALSE == wglBindTexImageARB(_hPBuffer, WGL_DEPTH_COMPONENT_NV))
+ if (FALSE == wglBindTexImageARBPtr(_hPBuffer, WGL_DEPTH_COMPONENT_NV))
{
_wglGetLastError();
return false;
pfAttribs.push_back(bitVec[1]);
pfAttribs.push_back(WGL_BLUE_BITS_ARB);
pfAttribs.push_back(bitVec[2]);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_RED_SIZE);
+ pfAttribs.push_back(bitVec[0]);
+ pfAttribs.push_back(AGL_GREEN_SIZE);
+ pfAttribs.push_back(bitVec[1]);
+ pfAttribs.push_back(AGL_BLUE_SIZE);
+ pfAttribs.push_back(bitVec[2]);
#else
-# ifndef sgi
pfAttribs.push_back(GLX_RED_SIZE);
pfAttribs.push_back(bitVec[0]);
pfAttribs.push_back(GLX_GREEN_SIZE);
pfAttribs.push_back(bitVec[1]);
pfAttribs.push_back(GLX_BLUE_SIZE);
pfAttribs.push_back(bitVec[2]);
-# endif
#endif
- _iNumComponents += 3;
+ _iNumComponents += 3;
continue;
}
else if (kv.first == "rgb")
pfAttribs.push_back(bitVec[2]);
pfAttribs.push_back(WGL_ALPHA_BITS_ARB);
pfAttribs.push_back(bitVec[3]);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_RED_SIZE);
+ pfAttribs.push_back(bitVec[0]);
+ pfAttribs.push_back(AGL_GREEN_SIZE);
+ pfAttribs.push_back(bitVec[1]);
+ pfAttribs.push_back(AGL_BLUE_SIZE);
+ pfAttribs.push_back(bitVec[2]);
+ pfAttribs.push_back(AGL_ALPHA_SIZE);
+ pfAttribs.push_back(bitVec[3]);
#else
-# ifndef sgi
pfAttribs.push_back(GLX_RED_SIZE);
pfAttribs.push_back(bitVec[0]);
pfAttribs.push_back(GLX_GREEN_SIZE);
pfAttribs.push_back(bitVec[2]);
pfAttribs.push_back(GLX_ALPHA_SIZE);
pfAttribs.push_back(bitVec[3]);
-# endif
#endif
- _iNumComponents = 4;
+ _iNumComponents = 4;
continue;
}
else if (kv.first == "rgba")
#ifdef _WIN32
pfAttribs.push_back(WGL_RED_BITS_ARB);
pfAttribs.push_back(bitVec[0]);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_RED_SIZE);
+ pfAttribs.push_back(bitVec[0]);
#else
pfAttribs.push_back(GLX_RED_SIZE);
pfAttribs.push_back(bitVec[0]);
pfAttribs.push_back(bitVec[0]);
pfAttribs.push_back(WGL_GREEN_BITS_ARB);
pfAttribs.push_back(bitVec[1]);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_RED_SIZE);
+ pfAttribs.push_back(bitVec[0]);
+ pfAttribs.push_back(AGL_GREEN_SIZE);
+ pfAttribs.push_back(bitVec[1]);
#else
pfAttribs.push_back(GLX_RED_SIZE);
pfAttribs.push_back(bitVec[0]);
bHasStencil = true;
#ifdef _WIN32
pfAttribs.push_back(WGL_STENCIL_BITS_ARB);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_STENCIL_SIZE);
#else
pfAttribs.push_back(GLX_STENCIL_SIZE);
#endif
pfAttribs.push_back(1);
pfAttribs.push_back(WGL_SAMPLES_ARB);
pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10));
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_SAMPLE_BUFFERS_ARB);
+ pfAttribs.push_back(1);
+ pfAttribs.push_back(AGL_SAMPLES_ARB);
+ pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10));
#else
- pfAttribs.push_back(GL_SAMPLE_BUFFERS_ARB);
+ pfAttribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
pfAttribs.push_back(1);
- pfAttribs.push_back(GL_SAMPLES_ARB);
+ pfAttribs.push_back(GLX_SAMPLES_ARB);
pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10));
#endif
continue;
#ifdef _WIN32
pfAttribs.push_back(WGL_DOUBLE_BUFFER_ARB);
pfAttribs.push_back(true);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_DOUBLEBUFFER);
+ pfAttribs.push_back(True);
#else
- pfAttribs.push_back(GL_DOUBLEBUFFER);
+ pfAttribs.push_back(GLX_DOUBLEBUFFER);
pfAttribs.push_back(True);
#endif
continue;
{
#ifdef _WIN32
pfAttribs.push_back(WGL_AUX_BUFFERS_ARB);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_AUX_BUFFERS);
#else
- pfAttribs.push_back(GL_AUX_BUFFERS);
+ pfAttribs.push_back(GLX_AUX_BUFFERS);
#endif
if (kv.second == "")
pfAttribs.push_back(0);
#ifdef _WIN32
pfAttribs.push_back(WGL_DEPTH_BITS_ARB);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_DEPTH_SIZE);
#else
pfAttribs.push_back(GLX_DEPTH_SIZE);
#endif
#ifdef _WIN32
pfAttribs.push_back(WGL_STENCIL_BITS_ARB);
pfAttribs.push_back(0);
+#elif defined( __APPLE__ )
+ pfAttribs.push_back(AGL_STENCIL_SIZE);
+ pfAttribs.push_back(0);
#else
pfAttribs.push_back(GLX_STENCIL_SIZE);
pfAttribs.push_back(0);
#elif defined(DEBUG) || defined(_DEBUG)
printf("RenderTexture Error: Render to Texture not "
- "supported in Linux\n");
+ "supported in Linux or MacOS\n");
#endif
}
pfAttribs.push_back(WGL_PIXEL_TYPE_ARB);
pfAttribs.push_back(WGL_TYPE_RGBA_FLOAT_ATI);
}
+#elif defined( __APPLE__ )
#else
- if (GL_NV_float_buffer)
+ if (GLX_NV_float_buffer)
{
- pfAttribs.push_back(GL_FLOAT_COMPONENTS_NV);
+ pfAttribs.push_back(GLX_FLOAT_COMPONENTS_NV);
pfAttribs.push_back(1);
}
#endif
#elif defined(DEBUG) || defined(_DEBUG)
fprintf(stderr,
"RenderTexture Error: Render to Texture not supported in "
- "Linux\n");
+ "Linux or MacOS\ n");
#endif
}
}
#elif defined(DEBUG) || defined(_DEBUG)
printf("RenderTexture Error: Render to Texture not supported in "
- "Linux\n");
+ "Linux or MacOS\n");
#endif
}
}
bool RenderTexture::_VerifyExtensions()
{
#ifdef _WIN32
- if (!WGL_ARB_pbuffer)
- {
- PrintExtensionError("WGL_ARB_pbuffer");
- return false;
- }
- if (!WGL_ARB_pixel_format)
- {
- PrintExtensionError("WGL_ARB_pixel_format");
- return false;
- }
- if (_bIsTexture && !WGL_ARB_render_texture)
- {
- PrintExtensionError("WGL_ARB_render_texture");
- return false;
- }
- if (_bRectangle && !GL_NV_texture_rectangle)
- {
- PrintExtensionError("GL_NV_texture_rectangle");
- return false;
- }
- if (_bFloat && !(GL_NV_float_buffer || WGL_ATI_pixel_format_float))
- {
- PrintExtensionError("GL_NV_float_buffer or GL_ATI_pixel_format_float");
- return false;
-
- }
- if (_bFloat && _bIsTexture && !(GL_NV_float_buffer || GL_ATI_texture_float))
- {
- PrintExtensionError("NV_float_buffer or ATI_texture_float");
- }
- if (_bIsDepthTexture && !GL_ARB_depth_texture)
+ // a second call to _VerifyExtensions will allways return true, causing a crash
+ // if the extension is not supported
+ if ( true || !fctPtrInited )
{
- // [Redge]
+ fctPtrInited = true;
+ wglGetExtensionsStringARBProc wglGetExtensionsStringARBPtr = (wglGetExtensionsStringARBProc)wglGetProcAddress( "wglGetExtensionsStringARB" );
+ if ( wglGetExtensionsStringARBPtr == 0 )
+ {
+ PrintExtensionError("WGL_ARB_extensions_string");
+ return false;
+ }
+ string wglExtensionsString = wglGetExtensionsStringARBPtr( wglGetCurrentDC() );
+ if ( SGSearchExtensionsString( wglExtensionsString.c_str(), "WGL_ARB_pixel_format" ) )
+ {
+ wglChoosePixelFormatARBPtr = (wglChoosePixelFormatARBProc)SGLookupFunction("wglChoosePixelFormatARB");
+ wglGetPixelFormatAttribivARBPtr = (wglGetPixelFormatAttribivARBProc)SGLookupFunction("wglGetPixelFormatAttribivARB");
+ }
+ else
+ {
+ PrintExtensionError("WGL_ARB_pixel_format");
+ return false;
+ }
+ if ( SGSearchExtensionsString( wglExtensionsString.c_str(), "WGL_ARB_pbuffer" ) )
+ {
+ wglCreatePbufferARBPtr = (wglCreatePbufferARBProc)SGLookupFunction("wglCreatePbufferARB");
+ wglGetPbufferDCARBPtr = (wglGetPbufferDCARBProc)SGLookupFunction("wglGetPbufferDCARB");
+ wglQueryPbufferARBPtr = (wglQueryPbufferARBProc)SGLookupFunction("wglQueryPbufferARB");
+ wglReleasePbufferDCARBPtr = (wglReleasePbufferDCARBProc)SGLookupFunction("wglReleasePbufferDCARB");
+ wglDestroyPbufferARBPtr = (wglDestroyPbufferARBProc)SGLookupFunction("wglDestroyPbufferARB");
+ }
+ else
+ {
+ PrintExtensionError("WGL_ARB_pbuffer");
+ return false;
+ }
+ if ( SGSearchExtensionsString( wglExtensionsString.c_str(), "WGL_ARB_render_texture" ) )
+ {
+ wglBindTexImageARBPtr = (wglBindTexImageARBProc)SGLookupFunction("wglBindTexImageARB");
+ wglReleaseTexImageARBPtr = (wglReleaseTexImageARBProc)SGLookupFunction("wglReleaseTexImageARB");
+ }
+ else if ( _bIsTexture )
+ {
+ PrintExtensionError("WGL_ARB_render_texture");
+ return false;
+ }
+ if (_bRectangle && !SGIsOpenGLExtensionSupported( "GL_NV_texture_rectangle" ))
+ {
+ PrintExtensionError("GL_NV_texture_rectangle");
+ return false;
+ }
+ if (_bFloat && !(SGIsOpenGLExtensionSupported( "GL_NV_float_buffer" ) || SGSearchExtensionsString( wglExtensionsString.c_str(), "WGL_ATI_pixel_format_float" )))
+ {
+ PrintExtensionError("GL_NV_float_buffer or GL_ATI_pixel_format_float");
+ return false;
+
+ }
+ if (_bFloat && _bIsTexture && !(SGIsOpenGLExtensionSupported( "GL_NV_float_buffer" ) || SGIsOpenGLExtensionSupported( "GL_ATI_texture_float" )))
+ {
+ PrintExtensionError("NV_float_buffer or ATI_texture_float");
+ }
+ if (_bIsDepthTexture && !SGIsOpenGLExtensionSupported( "GL_ARB_depth_texture" ))
+ {
+ // [Redge]
#if defined(_DEBUG) | defined(DEBUG)
- fprintf(stderr,
- "RenderTexture Warning: "
- "OpenGL extension GL_ARB_depth_texture not available.\n"
- " Using glReadPixels() to emulate behavior.\n");
+ fprintf(stderr,
+ "RenderTexture Warning: "
+ "OpenGL extension GL_ARB_depth_texture not available.\n"
+ " Using glReadPixels() to emulate behavior.\n");
#endif
- _bHasARBDepthTexture = false;
- //PrintExtensionError("GL_ARB_depth_texture");
- //return false;
- // [/Redge]
+ _bHasARBDepthTexture = false;
+ //PrintExtensionError("GL_ARB_depth_texture");
+ //return false;
+ // [/Redge]
+ }
+ SetLastError(0);
}
- SetLastError(0);
+#elif defined( __APPLE__ )
#else
- if (!GLX_SGIX_pbuffer)
- {
- PrintExtensionError("GL_SGIX_pbuffer");
- return false;
- }
- if (!GLX_SGIX_fbconfig)
+
+ // First try the glX version 1.3 functions.
+ glXChooseFBConfigPtr = (glXChooseFBConfigProc)SGLookupFunction("glXChooseFBConfig");
+ glXCreateGLXPbufferPtr = (glXCreateGLXPbufferProc)SGLookupFunction("glXCreatePbuffer");
+ glXGetVisualFromFBConfigPtr = (glXGetVisualFromFBConfigProc)SGLookupFunction("glXGetVisualFromFBConfig");
+ glXCreateContextPtr = (glXCreateContextProc)SGLookupFunction("glXCreateContext");
+ glXDestroyPbufferPtr = (glXDestroyPbufferProc)SGLookupFunction("glXDestroyPbuffer");
+ glXQueryDrawablePtr = (glXQueryDrawableProc)SGLookupFunction("glXQueryDrawable");
+
+ if (glXChooseFBConfigPtr &&
+ glXCreateGLXPbufferPtr &&
+ glXGetVisualFromFBConfigPtr &&
+ glXCreateContextPtr &&
+ glXDestroyPbufferPtr &&
+ glXQueryDrawablePtr)
+ glXVersion1_3Present = true;
+ else
{
- PrintExtensionError("GL_SGIX_fbconfig");
- return false;
+ glXChooseFBConfigPtr = (glXChooseFBConfigProc)SGLookupFunction("glXChooseFBConfigSGIX");
+ glXCreateGLXPbufferPtr = (glXCreateGLXPbufferProc)SGLookupFunction("glXCreateGLXPbufferSGIX");
+ glXGetVisualFromFBConfigPtr = (glXGetVisualFromFBConfigProc)SGLookupFunction("glXGetVisualFromFBConfigSGIX");
+ glXCreateContextWithConfigPtr = (glXCreateContextWithConfigProc)SGLookupFunction("glXCreateContextWithConfigSGIX");
+ glXDestroyPbufferPtr = (glXDestroyPbufferProc)SGLookupFunction("glXDestroyGLXPbufferSGIX");
+ glXQueryGLXPbufferSGIXPtr = (glXQueryGLXPbufferSGIXProc)SGLookupFunction("glXQueryGLXPbufferSGIX");
+
+
+ if (!glXChooseFBConfigPtr ||
+ !glXCreateGLXPbufferPtr ||
+ !glXGetVisualFromFBConfigPtr ||
+ !glXCreateContextWithConfigPtr ||
+ !glXDestroyPbufferPtr ||
+ !glXQueryGLXPbufferSGIXPtr)
+ return false;
}
+
if (_bIsDepthTexture && !GL_ARB_depth_texture)
{
PrintExtensionError("GL_ARB_depth_texture");
return false;
}
- if (_bFloat && _bIsTexture && !GL_NV_float_buffer)
+ if (_bFloat && _bIsTexture && !GLX_NV_float_buffer)
{
- PrintExtensionError("GL_NV_float_buffer");
+ PrintExtensionError("GLX_NV_float_buffer");
return false;
}
if (_eUpdateMode == RT_RENDER_TO_TEXTURE)
{
- PrintExtensionError("Some GLX render texture extension: FIXME!");
+ PrintExtensionError("Some GLX render texture extension: Please implement me!");
return false;
}
#endif
if (_bIsTexture)
{
- glGenTextures(1, &_iTextureID);
+ glGenTextures(1, (GLuint*)&_iTextureID);
glBindTexture(_iTextureTarget, _iTextureID);
// Use clamp to edge as the default texture wrap mode for all tex
if (_bIsDepthTexture)
{
- glGenTextures(1, &_iDepthTextureID);
+ glGenTextures(1, (GLuint*)&_iDepthTextureID);
glBindTexture(_iTextureTarget, _iDepthTextureID);
// Use clamp to edge as the default texture wrap mode for all tex
// release the pbuffer from the render texture object
if (0 != _iCurrentBoundBuffer && _bIsBufferBound)
{
- if (FALSE == wglReleaseTexImageARB(_hPBuffer, _iCurrentBoundBuffer))
+ if (FALSE == wglReleaseTexImageARBPtr(_hPBuffer, _iCurrentBoundBuffer))
{
_wglGetLastError();
return false;
glBindTexture(_iTextureTarget, _iDepthTextureID);
// release the pbuffer from the render texture object
- if (FALSE == wglReleaseTexImageARB(_hPBuffer, WGL_DEPTH_COMPONENT_NV))
+ if (FALSE == wglReleaseTexImageARBPtr(_hPBuffer, WGL_DEPTH_COMPONENT_NV))
{
_wglGetLastError();
return false;
_wglGetLastError();
return false;
}
+#elif defined( __APPLE__ )
#else
if (false == glXMakeCurrent(_pDisplay, _hPBuffer, _hGLContext))
{
_hPBuffer(NULL),
_hPreviousDC(0),
_hPreviousContext(0),
+#elif defined( __APPLE__ )
#else
_pDisplay(NULL),
_hGLContext(NULL),
_pbufferAttribs.push_back(WGL_PBUFFER_LARGEST_ARB);
_pbufferAttribs.push_back(true);
+#elif defined( __APPLE__ )
#else
_pixelFormatAttribs.push_back(GLX_RENDER_TYPE_SGIX);
_pixelFormatAttribs.push_back(GLX_RGBA_BIT_SGIX);