* Changelog:
*
* Jan. 2005, Removed GLEW dependencies, Erik Hofman, Fred Bouvier
+ * Nov. 2005, Use the simgear logging facility, Erik Hofman
*/
#ifdef HAVE_CONFIG_H
#endif
#include <simgear/compiler.h>
+#include <simgear/debug/logstream.hxx>
#include <simgear/screen/extensions.hxx>
#include <simgear/screen/RenderTexture.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <assert.h>
+#include <stdarg.h>
#ifdef _WIN32
#pragma comment(lib, "gdi32.lib") // required for GetPixelFormat()
#else /* !_WIN32 */
static bool glXVersion1_3Present = false;
static glXChooseFBConfigProc glXChooseFBConfigPtr = 0;
+static glXCreatePbufferProc glXCreatePbufferPtr = 0;
static glXCreateGLXPbufferProc glXCreateGLXPbufferPtr = 0;
static glXGetVisualFromFBConfigProc glXGetVisualFromFBConfigPtr = 0;
-static glXCreateContextWithConfigProc glXCreateContextWithConfigPtr = 0;
static glXCreateContextProc glXCreateContextPtr = 0;
+static glXCreateContextWithConfigProc glXCreateContextWithConfigPtr = 0;
static glXDestroyPbufferProc glXDestroyPbufferPtr = 0;
static glXQueryDrawableProc glXQueryDrawablePtr = 0;
static glXQueryGLXPbufferSGIXProc glXQueryGLXPbufferSGIXPtr = 0;
switch(err)
{
case ERROR_INVALID_PIXEL_FORMAT:
- fprintf(stderr,
- "RenderTexture Win32 Error: ERROR_INVALID_PIXEL_FORMAT\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Win32 Error: ERROR_INVALID_PIXEL_FORMAT");
break;
case ERROR_NO_SYSTEM_RESOURCES:
- fprintf(stderr,
- "RenderTexture Win32 Error: ERROR_NO_SYSTEM_RESOURCES\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Win32 Error: ERROR_NO_SYSTEM_RESOURCES");
break;
case ERROR_INVALID_DATA:
- fprintf(stderr,
- "RenderTexture Win32 Error: ERROR_INVALID_DATA\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Win32 Error: ERROR_INVALID_DATA");
break;
case ERROR_INVALID_WINDOW_HANDLE:
- fprintf(stderr,
- "RenderTexture Win32 Error: ERROR_INVALID_WINDOW_HANDLE\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Win32 Error: ERROR_INVALID_WINDOW_HANDLE");
break;
case ERROR_RESOURCE_TYPE_NOT_FOUND:
- fprintf(stderr,
- "RenderTexture Win32 Error: ERROR_RESOURCE_TYPE_NOT_FOUND\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Win32 Error: ERROR_RESOURCE_TYPE_NOT_FOUND");
break;
case ERROR_SUCCESS:
// no error
0,
NULL);
- fprintf(stderr, "RenderTexture Win32 Error %d: %s\n", err, lpMsgBuf);
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture Win32 Error %d: %s", err, lpMsgBuf);
LocalFree( lpMsgBuf );
break;
}
*/
void PrintExtensionError( char* strMsg, ... )
{
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"Error: RenderTexture requires the following unsupported "
- "OpenGL extensions: \n");
+ "OpenGL extensions: ");
char strBuffer[512];
va_list args;
va_start(args, strMsg);
#endif
va_end(args);
- fprintf(stderr, strMsg);
+ SG_LOG(SG_GL, SG_ALERT, strMsg);
}
iFormat = GetPixelFormat(hdc);
if (iFormat == 0)
{
- fprintf(stderr,
- "RenderTexture Error: GetPixelFormat() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: GetPixelFormat() failed.");
return false;
}
}
if (!wglChoosePixelFormatARBPtr(hdc, &_pixelFormatAttribs[0], NULL,
1, &iFormat, &iNumFormats))
{
- fprintf(stderr,
- "RenderTexture Error: wglChoosePixelFormatARB() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: wglChoosePixelFormatARB() failed.");
_wglGetLastError();
return false;
}
if ( iNumFormats <= 0 )
{
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Error: Couldn't find a suitable "
- "pixel format.\n");
+ "pixel format.");
_wglGetLastError();
return false;
}
&_pbufferAttribs[0]);
if (!_hPBuffer)
{
- fprintf(stderr,
- "RenderTexture Error: wglCreatePbufferARB() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: wglCreatePbufferARB() failed.");
_wglGetLastError();
return false;
}
_hDC = wglGetPbufferDCARBPtr( _hPBuffer);
if ( !_hDC )
{
- fprintf(stderr,
- "RenderTexture Error: wglGetGetPbufferDCARB() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: wglGetGetPbufferDCARB() failed.");
_wglGetLastError();
return false;
}
_hGLContext = wglCreateContext( _hDC );
if ( !_hGLContext )
{
- fprintf(stderr,
- "RenderTexture Error: wglCreateContext() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: wglCreateContext() failed.");
_wglGetLastError();
return false;
}
{
if( !wglShareLists(hglrc, _hGLContext) )
{
- fprintf(stderr,
- "RenderTexture Error: wglShareLists() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: wglShareLists() failed.");
_wglGetLastError();
return false;
}
? (value?true:false) : false;
#if defined(_DEBUG) | defined(DEBUG)
- fprintf(stderr, "Created a %dx%d RenderTexture with BPP(%d, %d, %d, %d)",
+ SG_LOG(SG_GL, SG_ALERT, "Created a %dx%d RenderTexture with BPP(%d, %d, %d, %d)",
_iWidth, _iHeight,
_iNumColorBits[0], _iNumColorBits[1],
_iNumColorBits[2], _iNumColorBits[3]);
- if (_iNumDepthBits) fprintf(stderr, " depth=%d", _iNumDepthBits);
- if (_iNumStencilBits) fprintf(stderr, " stencil=%d", _iNumStencilBits);
- if (_bDoubleBuffered) fprintf(stderr, " double buffered");
- fprintf(stderr, "\n");
+ if (_iNumDepthBits) SG_LOG(SG_GL, SG_ALERT, " depth=%d", _iNumDepthBits);
+ if (_iNumStencilBits) SG_LOG(SG_GL, SG_ALERT, " stencil=%d", _iNumStencilBits);
+ if (_bDoubleBuffered) SG_LOG(SG_GL, SG_ALERT, " double buffered");
+ SG_LOG(SG_GL, SG_ALERT, "");
#endif
#elif defined( __APPLE__ )
if (nConfigs == 0 || !fbConfigs)
{
- fprintf(stderr,
- "RenderTexture Error: Couldn't find a suitable pixel format.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: Couldn't find a suitable pixel format.");
return false;
}
};
for (int i=0;i<nConfigs;i++)
{
- _hPBuffer = glXCreatePbuffer(_pDisplay, fbConfigs[i], pbufAttrib);
+ _hPBuffer = glXCreatePbufferPtr(_pDisplay, fbConfigs[i], pbufAttrib);
if (_hPBuffer)
{
- XVisualInfo *visInfo = glXGetVisualFromFBConfig(_pDisplay, fbConfigs[i]);
+ XVisualInfo *visInfo = glXGetVisualFromFBConfigPtr(_pDisplay, fbConfigs[i]);
- _hGLContext = glXCreateContext(_pDisplay, visInfo,
+ _hGLContext = glXCreateContextPtr(_pDisplay, visInfo,
_bShareObjects ? context : NULL,
- True);
+ GL_TRUE);
+ if (!_hGLContext)
+ {
+ return false;
+ }
XFree( visInfo );
break;
}
if (!_hPBuffer)
{
- fprintf(stderr,
- "RenderTexture Error: glXCreateGLXPbufferPtr() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: glXCreateGLXPbufferPtr() failed.");
return false;
}
_bShareObjects ? context : NULL, False);
if ( !_hGLContext )
{
- fprintf(stderr,
- "RenderTexture Error: glXCreateContext() failed.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: glXCreateContext() failed.");
return false;
}
}
if (IsInitialized() && !_Invalidate())
{
- fprintf(stderr, "RenderTexture::Reset(): failed to invalidate.\n");
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture::Reset(): failed to invalidate.");
return false;
}
char strBuffer[256];
va_start(args,strMode);
#if defined _WIN32 && !defined __CYGWIN__
- _vsnprintf( strBuffer, 256, strMode, args );
+ _vsnSG_LOG(SG_GL, SG_INFO, strBuffer, 256, strMode, args );
#else
vsnprintf( strBuffer, 256, strMode, args );
#endif
bool RenderTexture::Resize(int iWidth, int iHeight)
{
if (!_bInitialized) {
- fprintf(stderr, "RenderTexture::Resize(): must Initialize() first.\n");
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture::Resize(): must Initialize() first.");
return false;
}
if (iWidth == _iWidth && iHeight == _iHeight) {
}
#endif
else {
- fprintf(stderr, "RenderTexture::Resize(): failed to resize.\n");
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture::Resize(): failed to resize.");
return false;
}
_bInitialized = false;
{
if (!_bInitialized)
{
- fprintf(stderr,
- "RenderTexture::BeginCapture(): Texture is not initialized!\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture::BeginCapture(): Texture is not initialized!");
return false;
}
#ifdef _WIN32
{
if (!_bInitialized)
{
- fprintf(stderr,
- "RenderTexture::EndCapture() : Texture is not initialized!\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture::EndCapture() : Texture is not initialized!");
return false;
}
}
if (!_bInitialized)
{
- fprintf(stderr,
- "RenderTexture::BeginCapture(RenderTexture*): Texture is not initialized!\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture::BeginCapture(RenderTexture*): Texture is not initialized!");
return false;
}
if (!current->_bInitialized)
{
- fprintf(stderr,
- "RenderTexture::BeginCapture(RenderTexture): 'current' texture is not initialized!\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture::BeginCapture(RenderTexture): 'current' texture is not initialized!");
return false;
}
continue;
}
else if (kv.first == "rgb")
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: mistake in components definition "
- "(rgb + %d).\n",
- _iNumComponents);
-
+ "(rgb + " << _iNumComponents << ").");
if (kv.first == "rgba" && (_iNumComponents == 0))
{
continue;
}
else if (kv.first == "rgba")
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: mistake in components definition "
- "(rgba + %d).\n",
- _iNumComponents);
+ "(rgba + " << _iNumComponents << ").");
if (kv.first == "r" && (_iNumComponents <= 1))
{
continue;
}
else if (kv.first == "r")
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: mistake in components definition "
- "(r + %d).\n",
- _iNumComponents);
+ "(r + " << _iNumComponents << ").");
if (kv.first == "rg" && (_iNumComponents <= 1))
{
continue;
}
else if (kv.first == "rg")
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: mistake in components definition "
- "(rg + %d).\n",
- _iNumComponents);
+ "(rg + " << _iNumComponents << ").");
if (kv.first == "depth")
{
continue;
}
- fprintf(stderr,
- "RenderTexture Error: Unknown pbuffer attribute: %s\n",
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Error: Unknown pbuffer attribute: " <<
token.c_str());
}
// Check for inconsistent texture targets
if (_bIsTexture && _bIsDepthTexture && !(bBind2D ^ bBindRECT ^ bBindCUBE))
{
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: Depth and Color texture targets "
- "should match.\n");
+ "should match.");
}
// Apply default bit format if none specified
if (!WGL_NV_render_depth_texture && _bIsDepthTexture && (RT_RENDER_TO_TEXTURE == _eUpdateMode))
{
#if defined(DEBUG) || defined(_DEBUG)
- fprintf(stderr, "RenderTexture Warning: No support found for "
- "render to depth texture.\n");
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture Warning: No support found for "
+ "render to depth texture.");
#endif
_bIsDepthTexture = false;
}
}
#elif defined(DEBUG) || defined(_DEBUG)
- printf("RenderTexture Error: Render to Texture not "
- "supported in Linux or MacOS\n");
+ SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: Render to Texture not "
+ "supported in Linux or MacOS");
#endif
}
pbAttribs.push_back(WGL_TEXTURE_FLOAT_RGBA_NV);
break;
default:
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: Bad number of components "
- "(r=1,rg=2,rgb=3,rgba=4): %d.\n",
+ "(r=1,rg=2,rgb=3,rgba=4): %d.",
_iNumComponents);
break;
}
pbAttribs.push_back(WGL_TEXTURE_RGBA_ARB);
break;
default:
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: Bad number of components "
- "(r=1,rg=2,rgb=3,rgba=4): %d.\n", _iNumComponents);
+ "(r=1,rg=2,rgb=3,rgba=4): %d.", _iNumComponents);
break;
}
}
#elif defined(DEBUG) || defined(_DEBUG)
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Error: Render to Texture not supported in "
"Linux or MacOS\ n");
#endif
pbAttribs.push_back(WGL_TEXTURE_DEPTH_COMPONENT_NV);
}
#elif defined(DEBUG) || defined(_DEBUG)
- printf("RenderTexture Error: Render to Texture not supported in "
- "Linux or MacOS\n");
+ SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: Render to Texture not supported in "
+ "Linux or MacOS");
#endif
}
}
string::size_type nextpos = 0;
do
{
- nextpos = bitVector.find_first_of(", \n", pos);
+ nextpos = bitVector.find_first_of(", ", pos);
pieces.push_back(string(bitVector, pos, nextpos - pos));
pos = nextpos+1;
} while (nextpos != bitVector.npos );
{
// [Redge]
#if defined(_DEBUG) | defined(DEBUG)
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Warning: "
- "OpenGL extension GL_ARB_depth_texture not available.\n"
- " Using glReadPixels() to emulate behavior.\n");
+ "OpenGL extension GL_ARB_depth_texture not available."
+ " Using glReadPixels() to emulate behavior.");
#endif
_bHasARBDepthTexture = false;
//PrintExtensionError("GL_ARB_depth_texture");
// First try the glX version 1.3 functions.
glXChooseFBConfigPtr = (glXChooseFBConfigProc)SGLookupFunction("glXChooseFBConfig");
- glXCreateGLXPbufferPtr = (glXCreateGLXPbufferProc)SGLookupFunction("glXCreatePbuffer");
+ glXCreatePbufferPtr = (glXCreatePbufferProc)SGLookupFunction("glXCreatePbuffer");
glXGetVisualFromFBConfigPtr = (glXGetVisualFromFBConfigProc)SGLookupFunction("glXGetVisualFromFBConfig");
glXCreateContextPtr = (glXCreateContextProc)SGLookupFunction("glXCreateContext");
glXDestroyPbufferPtr = (glXDestroyPbufferProc)SGLookupFunction("glXDestroyPbuffer");
glXQueryDrawablePtr = (glXQueryDrawableProc)SGLookupFunction("glXQueryDrawable");
if (glXChooseFBConfigPtr &&
- glXCreateGLXPbufferPtr &&
+ glXCreatePbufferPtr &&
glXGetVisualFromFBConfigPtr &&
glXCreateContextPtr &&
glXDestroyPbufferPtr &&
{
if (_bMipmap)
{
- fprintf(stderr,
+ SG_LOG(SG_GL, SG_ALERT,
"RenderTexture Error: mipmapped float textures not "
- "supported.\n");
+ "supported.");
return false;
}
iFormat = GL_RGBA;
break;
default:
- printf("RenderTexture Error: "
- "Invalid number of components: %d\n",
+ SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: "
+ "Invalid number of components: " <<
_iNumComponents);
return false;
}
{
assert(width > 0 && height > 0);
#if defined DEBUG || defined _DEBUG
- fprintf(stderr,
- "RenderTexture Warning: Deprecated Contructor interface used.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Warning: Deprecated Contructor interface used.");
#endif
_iNumColorBits[0] = _iNumColorBits[1] =
return false;
#if defined DEBUG || defined _DEBUG
- fprintf(stderr,
- "RenderTexture Warning: Deprecated Initialize() interface used.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Warning: Deprecated Initialize() interface used.");
#endif
// create a mode string.
mode.append("a");
mode.append("=");
char bitVector[100];
- sprintf(bitVector,
+ snprintf( bitVector, 100,
"%d%s,%d%s,%d%s,%d%s",
iRBits, (iRBits >= 16) ? "f" : "",
iGBits, (iGBits >= 16) ? "f" : "",
*/
bool RenderTexture::Reset(int iWidth, int iHeight)
{
- fprintf(stderr,
- "RenderTexture Warning: Deprecated Reset() interface used.\n");
+ SG_LOG(SG_GL, SG_ALERT,
+ "RenderTexture Warning: Deprecated Reset() interface used.");
if (!_Invalidate())
{
- fprintf(stderr, "RenderTexture::Reset(): failed to invalidate.\n");
+ SG_LOG(SG_GL, SG_ALERT, "RenderTexture::Reset(): failed to invalidate.");
return false;
}
_iWidth = iWidth;