From: James Turner Date: Fri, 30 Jul 2010 18:15:49 +0000 (+0100) Subject: Remove legacy direct-OpenGL code in simgear/screen (predating switch to OSG). X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=49f418f146003dc092d16417faa1f60970de8b99;p=simgear.git Remove legacy direct-OpenGL code in simgear/screen (predating switch to OSG). --- diff --git a/projects/VC90/SimGear.vcproj b/projects/VC90/SimGear.vcproj index af9ff1aa..8de61f5b 100644 --- a/projects/VC90/SimGear.vcproj +++ b/projects/VC90/SimGear.vcproj @@ -707,14 +707,6 @@ RelativePath="..\..\simgear\screen\extensions.hxx" > - - - - @@ -723,14 +715,6 @@ RelativePath="..\..\simgear\screen\jpgfactory.hxx" > - - - - @@ -739,14 +723,6 @@ RelativePath="..\..\simgear\screen\screen-dump.hxx" > - - - - @@ -755,10 +731,6 @@ RelativePath="..\..\simgear\screen\tr.h" > - - - - - - diff --git a/simgear/scene/sky/Makefile.am b/simgear/scene/sky/Makefile.am index 104ca4e1..440cfb4b 100644 --- a/simgear/scene/sky/Makefile.am +++ b/simgear/scene/sky/Makefile.am @@ -10,7 +10,6 @@ include_HEADERS = \ sky.hxx \ sphere.hxx \ stars.hxx \ - bbcache.hxx \ cloudfield.hxx \ newcloud.hxx \ CloudShaderGeometry.hxx @@ -23,7 +22,6 @@ libsgsky_a_SOURCES = \ sky.cxx \ sphere.cxx \ stars.cxx \ - bbcache.cxx \ cloudfield.cxx \ newcloud.cxx \ CloudShaderGeometry.cxx diff --git a/simgear/scene/sky/bbcache.cxx b/simgear/scene/sky/bbcache.cxx deleted file mode 100644 index 66b27275..00000000 --- a/simgear/scene/sky/bbcache.cxx +++ /dev/null @@ -1,374 +0,0 @@ -// Billboard helper class -// -// Written by Harald JOHNSEN, started April 2005. -// -// Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include -#include -#include -#include - -#include "bbcache.hxx" - - -/* -memory usage : -size 1 tex 8 tex 32 tex 64 tex -64x64x4 16k 128k 512k 1Mo -128x128x4 64k 512k 2Mo 4Mo -256x256x4 256k 2Mo 8Mo 16Mo -*/ - -void SGBbCache::freeTextureMemory(void) { - - if( bbListCount ) { - for(int i = 0 ; i < bbListCount ; i++) { - bbList[i].cldID = 0; - if(bbList[i].texID) - glDeleteTextures(1, & bbList[i].texID); - } - delete [] bbList; - } - bbListCount = 0; - cacheSizeKb = 0; - textureWH = 0; -} - -bool SGBbCache::allocTextureMemory(int cacheCount, int textureDimension) { - textureWH = textureDimension; - bbListCount = cacheCount; - bbList = new bbInfo[bbListCount]; - for(int i = 0 ; i < bbListCount ; i++) { - bbList[i].cldID = 0; - bbList[i].texID = 0; - glGenTextures(1, &bbList[i].texID); - glBindTexture(GL_TEXTURE_2D, bbList[i].texID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, - textureDimension, textureDimension, 0, GL_RGB, GL_FLOAT, NULL); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } - glBindTexture(GL_TEXTURE_2D, 0); - cacheSizeKb = (textureDimension * textureDimension * 4); - cacheSizeKb *= cacheCount; - cacheSizeKb /= 1024; - if(rtAvailable) { - if( rt->BeginCapture() ) { - glViewport(0, 0, textureDimension, textureDimension); - rt->EndCapture(); - } - } - return true; -} - -SGBbCache::SGBbCache(void) : - bbListCount(0), - textureWH(0), - cacheSizeKb(0), - builtBBCount(0), - frameNumber(0), - rt(0), - rtAvailable(false), - maxImpostorRegenFrame(20) -{ -} - -SGBbCache::~SGBbCache(void) { - delete rt; - freeTextureMemory(); -} - - -void SGBbCache::init(int cacheCount) { - GLint colorBits = 0; - glGetIntegerv( GL_BLUE_BITS, &colorBits ); - - rt = new RenderTexture(); - // don't use default rtt on nvidia/win because of poor performance of glCopyTexSubImage2D - // wihtout default pattrib params - see opengl forum - if( colorBits < 8 ) - rt->Reset("rgba=5,5,5,1 ctt"); - else - rt->Reset("rgba ctt"); - -// rt->Reset("rgba tex2D ctt"); -// rt->Reset("rgba tex2D"); - if( rt->Initialize(256, 256, true) ) { - SG_LOG(SG_ALL, SG_INFO, "bbcache:Initialize sucessfull"); - if (rt->BeginCapture()) - { - SG_LOG(SG_ALL, SG_INFO, "bbcache:BeginCapture sucessfull, RTT available"); - rtAvailable = true; - glViewport(0, 0, 256, 256); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60.0, 1, 1, 5.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glDisable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - glDisable(GL_CULL_FACE); - glDisable(GL_FOG); - glDisable(GL_DEPTH_TEST); - glClearColor(0.0, 0.0, 0.0, 0.0); - glEnable(GL_TEXTURE_2D); - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.0f); - glEnable(GL_SMOOTH); - glEnable(GL_BLEND); - glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); - - rt->EndCapture(); - } else - SG_LOG(SG_ALL, SG_WARN, "bbcache:BeginCapture failed, RTT not available for 3D clouds"); - } else - SG_LOG(SG_ALL, SG_WARN, "bbcache:Initialize failed, RTT not available for 3D clouds"); - if( cacheCount ) - allocTextureMemory( cacheCount, 64 ); - -} - - -bool SGBbCache::setCacheSize(int count, int textureDimension) { - if( count < 0 || count > 500) - return false; - freeTextureMemory(); - if( count == 0) - return true; - - // only allow some reasonable dimensions - switch(textureDimension) { - case 0: - // default size - textureDimension = 256; - break; - case 64: - case 128: - case 256: - break; - case 512: - // rt is 256 so higher texture size has no meaning - textureDimension = 256; - break; - default: - textureDimension = 128; - break; - } - return allocTextureMemory( count, textureDimension); -} - - -bool SGBbCache::setCacheSize(int sizeKb) { - if( sizeKb < 0 || sizeKb > 256*1024) - return false; - freeTextureMemory(); - if( sizeKb == 0) - return true; - int count = 1; - int textureDimension = 256; - if( sizeKb >= 8*1024 ) { - // more than 32 256x256 textures - textureDimension = 256; - } else if( sizeKb >= 2*1024 ) { - // more than 32 128x128 textures - textureDimension = 128; - } else { - // don't go under 64x64 textures - textureDimension = 64; - } - count = (sizeKb * 1024) / (textureDimension * textureDimension * 4); - if(count == 0) - count = 1; - return allocTextureMemory( count, textureDimension); -} - -int SGBbCache::queryCacheSize(void) { - return cacheSizeKb; -} - -void SGBbCache::free(int bbId, int cldId) { - if( bbId < 0 || bbId >= bbListCount ) - return; - if( bbList[bbId].cldID != cldId ) - return; - bbList[bbId].cldID = 0; -} - -int SGBbCache::alloc(int cldId) { - // pretend we have no more texture if render to texture is not available - if( ! rtAvailable ) - return -1; - for(int i = 0 ; i < bbListCount ; i++) { - if( (bbList[i].cldID == 0) && (bbList[i].texID != 0) ) { - bbList[i].cldID = cldId; - bbList[i].angleX = -999; - bbList[i].angleY = -999; - bbList[i].frameUsed = 0; - bbList[i].needRedraw = true; - return i; - } - } - return -1; -} - -GLuint SGBbCache::QueryTexID(int cldId, int bbId) { - if( bbId < 0 || bbId >= bbListCount ) - return 0; - if( bbList[bbId].cldID != cldId ) - return 0; - return bbList[bbId].texID; -} - -int SGBbCache::queryImpostorAge(int bbId) { - if( bbId < 0 || bbId >= bbListCount ) - return 0; - return frameNumber - bbList[bbId].frame; -} - -void SGBbCache::beginCapture(void) { - - rt->BeginCapture(); - - glClear(GL_COLOR_BUFFER_BIT); - -} - - - -void SGBbCache::setRadius(float radius, float dist_center) { - float border; - //set viewport to texture resolution - //glViewport(0, 0, 256, 256); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - float near_ = dist_center - radius; - float far_ = dist_center + radius; - if( near_ <= 0 ) { - // we are in trouble - glFrustum(-1, 1, -1, 1, 1, 1 + radius * 2); - } else { - border = (near_ * radius) / sqrt(dist_center * dist_center - radius * radius); - glFrustum(-border, border, -border, border, near_, far_); - } - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} -void SGBbCache::setTextureData(int bbId) { - if( bbId < 0 || bbId >= bbListCount ) - return; - - glBindTexture(GL_TEXTURE_2D, bbList[bbId].texID); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureWH, textureWH); - -// bbList[bbId].angleX = angleX; -// bbList[bbId].angleY = angleY; - bbList[bbId].frame = frameNumber; - bbList[bbId].frameUsed = frameNumber; - bbList[bbId].needRedraw = false; - builtBBCount ++; - builtBBframe ++; -} - -void SGBbCache::endCapture(void) { - - rt->EndCapture(); -// glBindTexture(GL_TEXTURE_2D, rt->GetTextureID() ); - -} - - -bool SGBbCache::isBbValid( int cldId, int bbId, float angleY, float angleX) { - if( bbId < 0 || bbId >= bbListCount ) - return false; - if( bbList[bbId].cldID != cldId ) - return false; - - // it was just allocated - if( bbList[bbId].frameUsed == 0) - return false; - - // we reuse old impostor to speed up things - if( builtBBframe >= maxImpostorRegenFrame ) - return true; - - if( bbList[bbId].needRedraw ) - return false; - -// if( fabs(angleY - bbList[bbId].angleY) >= 4.0 ) -// return false; - -// if( fabs(angleX - bbList[bbId].angleX) >= 4.0 ) -// return false; - - bbList[bbId].frameUsed = frameNumber; - return true; -} - -// TODO:this is not the right way to handle that -void SGBbCache::setReference( int cldId, int bbId, float angleY, float angleX) { - if( bbId < 0 || bbId >= bbListCount ) - return; - if( bbList[bbId].cldID != cldId ) - return; - bbList[bbId].angleX = angleX; - bbList[bbId].angleY = angleY; -} - -void SGBbCache::startNewFrame(void) { - builtBBframe = 0; - // TOTO:find reasonable value - int minFrameNumber = frameNumber - 100; - frameNumber++; - // cleanup of unused enties - for( int bbId = 0 ; bbId < bbListCount ; bbId++) - if( (bbList[bbId].cldID != 0) && (bbList[bbId].frameUsed < minFrameNumber) ) { - // entry is now free - bbList[bbId].cldID = 0; - } -} - -// force all impostors to be rebuilt, this will enventually be done over several frames -void SGBbCache::invalidateCache(void) { - - for( int bbId = 0 ; bbId < bbListCount ; bbId++) -// bbList[bbId].cldID = 0; - bbList[bbId].needRedraw = true; -} - -// flag the impostor for a lazy update -void SGBbCache::invalidate(int cldId, int bbId) { - if( bbId < 0 || bbId >= bbListCount ) - return; - if( bbList[bbId].cldID != cldId ) - return; - bbList[bbId].needRedraw = true; -} - diff --git a/simgear/scene/sky/bbcache.hxx b/simgear/scene/sky/bbcache.hxx deleted file mode 100644 index 021e5487..00000000 --- a/simgear/scene/sky/bbcache.hxx +++ /dev/null @@ -1,205 +0,0 @@ -// Billboard helper class -// -// Written by Harald JOHNSEN, started April 2005. -// -// Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// - -#ifndef _BBCACHE_HXX -#define _BBCACHE_HXX - - -#include -#include -#include - -/** - * Billboard helper class. - */ -class SGBbCache { -private: - - /** - * storage class for impostors state. - */ - class bbInfo { - public: - /// the texture used by this impostor - GLuint texID; - /// the cloud owning this impostor - int cldID; - float angleX, angleY; - // creation frame number for debug only - int frame; - /// last time this entry was used - int frameUsed; - /// dirty flag for lazy rebuild of impostor - bool needRedraw; - }; - - void freeTextureMemory(void); - /** - * Allocate and initialize the texture pool. - * @param count the number of texture to build - * @param textureDimension size in pixel of each texture - */ - bool allocTextureMemory(int count, int textureDimension); - - // a list of impostors - bbInfo *bbList; - int bbListCount; - int textureWH; - int cacheSizeKb; - - // for debug only, stats - int builtBBCount; - // count of generated BB during the current frame - int builtBBframe; - - long frameNumber; - RenderTexture *rt; - bool rtAvailable; - -public: - SGBbCache(void); - ~SGBbCache(void); - - /** - * Call this first to initialize the cache. - * @param cacheCount the number of texture to allocate - */ - void init(int cacheCount); - - /** - * Free one cache slot, usualy when the cached object is destroyed. - * @param bbId the impostor slot - * @param cldId the cloud identifier - */ - void free(int bbId, int cldId); - - /** - * Allocate a new impostor. - * @param cldId the cloud identifier - * @return an impostor slot - */ - int alloc(int cldId); - - /** - * Query the texture name associated with this cloud. - * @param bbId the impostor slot - * @param cldId the cloud identifier - * @return a texture name - */ - GLuint QueryTexID(int cldId, int bbId); - - /** - * Save the rendered texture from the current context to a new texture. - * @param bbId the impostor slot - */ - void setTextureData(int bbId); - - /** - * Start the rendering of a billboard in the RTT context. - */ - void beginCapture(void); - - /** - * Adjust the projection matrix of the RTT context to the size of the object. - * @param radius radius in meters of the object to draw - * @param dist_center distance between viewer and object - */ - void setRadius(float radius, float dist_center); - - /** - * Forget the RTT and go back to the previous rendering context. - */ - void endCapture(void); - - /** - * For debugging only, give the number of frames since the impostor was built. - * @param bbId the impostor slot - */ - int queryImpostorAge(int bbId); - - /** - * Can we still use this impostor ? Check versus view angles and load. - * @param bbId the impostor slot - * @param cloudId the cloud identifier - * @param angleY rotation needed to face the impostor - * @param angleX rotation needed to face the impostor - */ - bool isBbValid( int cloudId, int bbId, float angleY, float angleX); - - /** - * Save view angles of this billboard. - * @param bbId the impostor slot - * @param cloudId the cloud identifier - * @param angleY rotation needed to face the impostor - * @param angleX rotation needed to face the impostor - */ - void setReference( int cloudId, int bbId, float angleY, float angleX); - - /** - * Prepare the cache for the rendering of a new frame. - * Do some garbage collect of unused impostors - */ - void startNewFrame(void); - - /** - * Alloc the impostors texture memory given the size of the memory pool. - * If sizeKb == 0 then the memory pool is freed and impostors are disabled - * @param sizeKb size of the texture pool in K - */ - bool setCacheSize(int sizeKb); - - /** - * Alloc the impostors texture memory given the count and size of texture. - * If count == 0 then the memory pool is freed and impostors are disabled - * @param count number of texture to allocate - * @param textureDimension size of each texture in pixels - */ - bool setCacheSize(int count, int textureDimension); - - bool isRttAvailable(void) { return rtAvailable; } - - /** - * Force all impostors to be rebuilt. - */ - void invalidateCache(void); - - /** - * Flag the impostor for a lazy update. - * @param bbId the impostor slot - * @param cldId the cloud identifier - */ - void invalidate(int cldId, int bbId); - - /** - * Return the size of the memory pool used by texture impostors. - * @return size of the memory pool in Kb - */ - int queryCacheSize(void); - - /** - * Maximum number of impostor to regen each frame. - * If we can't update all of them we will do that in the next frame - */ - int maxImpostorRegenFrame; -}; - -#endif // _BBCACHE_HXX diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index 72462cc7..d7b7e2f3 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include "newcloud.hxx" #include "cloudfield.hxx" diff --git a/simgear/scene/sky/newcloud.hxx b/simgear/scene/sky/newcloud.hxx index 28f8a9c3..f0ac9451 100644 --- a/simgear/scene/sky/newcloud.hxx +++ b/simgear/scene/sky/newcloud.hxx @@ -29,8 +29,6 @@ #include #include -#include "bbcache.hxx" - #include #include diff --git a/simgear/screen/GLBitmaps.cxx b/simgear/screen/GLBitmaps.cxx deleted file mode 100755 index 30b6e12b..00000000 --- a/simgear/screen/GLBitmaps.cxx +++ /dev/null @@ -1,80 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef WIN32 -# include -#endif - -#include -#include -#include -#include // memcpy() - -#include "GLBitmaps.h" - -GlBitmap::GlBitmap( GLenum mode, GLint width, GLint height, GLubyte *bitmap ) -: m_bytesPerPixel(mode==GL_RGB?3:4), m_width(width), m_height(height), m_bitmap(NULL) -{ - m_bitmapSize = m_bytesPerPixel*m_width*m_height; - if ( !m_bitmapSize ) - { - GLint vp[4]; - glGetIntegerv( GL_VIEWPORT, vp ); - m_width = vp[2]; - m_height = vp[3]; - m_bitmapSize = m_bytesPerPixel*m_width*m_height; - } - m_bitmap = (GLubyte *)malloc( m_bitmapSize ); - if ( bitmap ) memcpy( m_bitmap, bitmap, m_bitmapSize ); - else glReadPixels( 0,0, m_width,m_height, mode, GL_UNSIGNED_BYTE, m_bitmap ); -} - -GlBitmap::~GlBitmap( ) -{ - if ( m_bitmap ) free( m_bitmap ); -} - -GLubyte *GlBitmap::getBitmap() -{ - return m_bitmap; -} - -void GlBitmap::copyBitmap( GlBitmap *from, GLint at_x, GLint at_y ) -{ - GLint newWidth = at_x + from->m_width; - GLint newHeight = at_y + from->m_height; - if ( newWidth < m_width ) newWidth = m_width; - if ( newHeight < m_height ) newHeight = m_height; - m_bitmapSize = m_bytesPerPixel*newWidth*newHeight; - GLubyte *newBitmap = (GLubyte *)malloc( m_bitmapSize ); - GLint x,y; - for ( y=0; ym_height; y++ ) - { - GLubyte *s = from->m_bitmap + from->m_bytesPerPixel * (y * from->m_width); - GLubyte *d = m_bitmap + m_bytesPerPixel * ((at_y+y) * m_width + at_x); - for ( x=0; xm_width; x++ ) - { - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - if ( m_bytesPerPixel == 4 ) - { - d[3] = (from->m_bytesPerPixel == 4) ? s[3] : 0; - } - s += from->m_bytesPerPixel; - d += m_bytesPerPixel; - } - } -} - diff --git a/simgear/screen/GLBitmaps.h b/simgear/screen/GLBitmaps.h deleted file mode 100644 index bc92e33d..00000000 --- a/simgear/screen/GLBitmaps.h +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include - -class GlBitmap -{ -public: - GlBitmap( GLenum mode=GL_RGB, GLint width=0, GLint height=0, GLubyte *bitmap=0 ); - ~GlBitmap(); - GLubyte *getBitmap(); - void copyBitmap( GlBitmap *from, GLint at_x, GLint at_y ); -private: - GLint m_bytesPerPixel; - GLint m_width; - GLint m_height; - GLint m_bitmapSize; - GLubyte *m_bitmap; -}; diff --git a/simgear/screen/Makefile.am b/simgear/screen/Makefile.am index 0e5129e7..21bd8ff1 100644 --- a/simgear/screen/Makefile.am +++ b/simgear/screen/Makefile.am @@ -15,34 +15,18 @@ endif noinst_HEADERS = GLBitmaps.h include_HEADERS = \ - colors.hxx \ $(IMAGE_SERVER_INCL) \ screen-dump.hxx \ - extensions.hxx \ - RenderTexture.h \ - shader.h \ - tr.h + colors.hxx \ + tr.h \ + extensions.hxx libsgscreen_a_SOURCES = \ - GLBitmaps.cxx \ $(IMAGE_SERVER_SRCS) \ screen-dump.cxx \ tr.cxx \ - extensions.cxx \ - RenderTexture.cpp \ - shader.cpp \ - win32-printer.h - -if HAVE_GLUT -noinst_PROGRAMS = TestRenderTexture + extensions.cxx + -TestRenderTexture_SOURCES = TestRenderTexture.cpp - -TestRenderTexture_LDADD = \ - libsgscreen.a \ - $(top_builddir)/simgear/debug/libsgdebug.a \ - $(opengl_LIBS) \ - -ldl -endif +INCLUDES = -I$(top_srcdir) -I$(top_builddir) -INCLUDES = -I$(top_srcdir) -I$(top_builddir) -DGLX_GLXEXT_PROTOTYPES diff --git a/simgear/screen/RenderTexture.cpp b/simgear/screen/RenderTexture.cpp deleted file mode 100644 index ad594117..00000000 --- a/simgear/screen/RenderTexture.cpp +++ /dev/null @@ -1,3209 +0,0 @@ -// File : RenderTexture.cpp -//--------------------------------------------------------------------------- -// Copyright (c) 2002-2004 Mark J. Harris -//--------------------------------------------------------------------------- -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any -// damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any -// purpose, including commercial applications, and to alter it and -// redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you -// must not claim that you wrote the original software. If you use -// this software in a product, an acknowledgment in the product -// documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and -// must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -// -------------------------------------------------------------------------- -// Credits: -// Original RenderTexture class: Mark J. Harris -// Original Render to Depth Texture support: Thorsten Scheuermann -// Linux Copy-to-texture: Eric Werness -// OS X: Alexander Powell (someone please help) -// Various Bug Fixes: Daniel (Redge) Sperl -// Bill Baxter -// Ubuntu 8.04 64bit: Geoff McLane - 2009-07-01 -// to work even when version 1.2 is returned. -// -// -------------------------------------------------------------------------- -/** -* @file RenderTexture.cpp -* -* Implementation of class RenderTexture. A multi-format render to -* texture wrapper. -*/ - -/* - * Changelog: - * - * Jan. 2005, Removed GLEW dependencies, Erik Hofman, Fred Bouvier - * Nov. 2005, Use the simgear logging facility, Erik Hofman - * Mar. 2006, Add MAC OS X support, Alexander Powell - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#ifdef _WIN32 -#pragma comment(lib, "gdi32.lib") // required for GetPixelFormat() -#endif - -using namespace std; - -// DEBUG - add a lot of noise -//#ifndef _DEBUG -//#define _DEBUG -//#endif - -#if defined (_DEBUG) -const char * get_attr_name( int val, int * pdef ); -#define dbg_printf printf -#else -#if defined (__GNUC__) -#define dbg_printf(format,args...) ((void)0) -#else // defined (__GNUC__) -#define dbg_printf -#endif // defined (__GNUC__) -#endif // defined (_DEBUG) - -// CHOP/NOT CHOP SOME CODE TO GET SOMETHING WORKING! -#define ADD_QUERY_BUFFER -#define ADD_GET_DRAWABLE -// ======================================= - - -#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( __MACH__ ) -#else /* !_WIN32 */ -static bool glXVersion1_3Present = false; -static glXChooseFBConfigProc glXChooseFBConfigPtr = 0; -static glXCreatePbufferProc glXCreatePbufferPtr = 0; -static glXCreateGLXPbufferProc glXCreateGLXPbufferPtr = 0; -static glXGetVisualFromFBConfigProc glXGetVisualFromFBConfigPtr = 0; -static glXCreateContextProc glXCreateContextPtr = 0; -static glXCreateContextWithConfigProc glXCreateContextWithConfigPtr = 0; -static glXDestroyPbufferProc glXDestroyPbufferPtr = 0; -static glXQueryDrawableProc glXQueryDrawablePtr = 0; -static glXQueryGLXPbufferSGIXProc glXQueryGLXPbufferSGIXPtr = 0; -#endif - -//--------------------------------------------------------------------------- -// Function : RenderTexture::RenderTexture -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::RenderTexture() -* @brief Mode-string-based Constructor. -*/ -RenderTexture::RenderTexture(const char *strMode) -: _iWidth(0), - _iHeight(0), - _bIsTexture(false), - _bIsDepthTexture(false), - _bHasARBDepthTexture(true), // [Redge] -#if defined(_WIN32) || defined(__MACH__) - _eUpdateMode(RT_RENDER_TO_TEXTURE), -#else - _eUpdateMode(RT_COPY_TO_TEXTURE), -#endif - _bInitialized(false), - _iNumAuxBuffers(0), - _bIsBufferBound(false), - _iCurrentBoundBuffer(0), - _iNumDepthBits(0), - _iNumStencilBits(0), - _bFloat(false), - _bDoubleBuffered(false), - _bPowerOf2(true), - _bRectangle(false), - _bMipmap(false), - _bShareObjects(false), - _bCopyContext(false), -#ifdef _WIN32 - _hDC(NULL), - _hGLContext(NULL), - _hPBuffer(NULL), - _hPreviousDC(0), - _hPreviousContext(0), -#elif defined( __MACH__ ) - _hGLContext(NULL), - _hPBuffer(0), - _hPreviousContext(NULL), -#else - _pDisplay(NULL), - _hGLContext(NULL), - _hPBuffer(0), - _hPreviousDrawable(0), - _hPreviousContext(0), -#endif - _iTextureTarget(GL_NONE), - _iTextureID(0), - _iDepthTextureID(0), - _pPoorDepthTexture(0) // [Redge] -{ - dbg_printf("RenderTexture::RenderTexture(%s) BGN instantiation.\n", strMode ); - _iNumColorBits[0] = _iNumColorBits[1] = - _iNumColorBits[2] = _iNumColorBits[3] = 0; - -#ifdef _WIN32 - dbg_printf("RenderTexture::RenderTexture in _WIN32.\n" ); - _pixelFormatAttribs.push_back(WGL_DRAW_TO_PBUFFER_ARB); - _pixelFormatAttribs.push_back(true); - _pixelFormatAttribs.push_back(WGL_SUPPORT_OPENGL_ARB); - _pixelFormatAttribs.push_back(true); - - _pbufferAttribs.push_back(WGL_PBUFFER_LARGEST_ARB); - _pbufferAttribs.push_back(true); -#elif defined( __MACH__ ) - dbg_printf("RenderTexture::RenderTexture in __MACH__.\n" ); - //_pixelFormatAttribs.push_back(kCGLPFANoRecovery); - _pixelFormatAttribs.push_back(kCGLPFAAccelerated); - _pixelFormatAttribs.push_back(kCGLPFAWindow); - _pixelFormatAttribs.push_back(kCGLPFAPBuffer); -#else - dbg_printf("RenderTexture::RenderTexture !_WIN32 and !__MACH__.\n" ); - _pbufferAttribs.push_back(GLX_RENDER_TYPE_SGIX); - _pbufferAttribs.push_back(GLX_RGBA_BIT_SGIX); - _pbufferAttribs.push_back(GLX_DRAWABLE_TYPE_SGIX); - _pbufferAttribs.push_back(GLX_PBUFFER_BIT_SGIX); -#endif - - _ParseModeString(strMode, _pixelFormatAttribs, _pbufferAttribs); - -#ifdef _WIN32 - _pixelFormatAttribs.push_back(0); - _pbufferAttribs.push_back(0); -#elif defined(__MACH__) - _pixelFormatAttribs.push_back((CGLPixelFormatAttribute)0); - _pbufferAttribs.push_back((CGLPixelFormatAttribute)0); -#else - _pixelFormatAttribs.push_back(None); -#endif - - dbg_printf("RenderTexture::RenderTexture(%s) END instantiation. pf=%d pb=%d\n", - strMode, (int)_pixelFormatAttribs.size(), (int)_pbufferAttribs.size() ); - -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::~RenderTexture -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::~RenderTexture() -* @brief Destructor. -*/ -RenderTexture::~RenderTexture() -{ - dbg_printf("RenderTexture::~RenderTexture: destructor.\n" ); - _Invalidate(); -} - - //--------------------------------------------------------------------------- -// Function : _cglcheckError -// Description : -//--------------------------------------------------------------------------- -/** -* @fn _cglCheckError() -* @brief Prints to stderr a description when an OS X error is found. -*/ -#ifdef __MACH__ -static void _cglCheckErrorHelper(CGLError err, char *sourceFile, int sourceLine) -{ -# ifdef _DEBUG - if (err) - { - fprintf(stderr, "RenderTexture CGL Error: %s at (%s,%d)", - CGLErrorString(err), sourceFile, sourceLine); - } -# endif -} - -# define _cglCheckError(err) _cglCheckErrorHelper(err,__FILE__,__LINE__) - -#endif - - -//--------------------------------------------------------------------------- -// Function : _wglGetLastError -// Description : -//--------------------------------------------------------------------------- -/** -* @fn wglGetLastError() -* @brief Returns the last windows error generated. -*/ -#ifdef _WIN32 -void _wglGetLastError() -{ -#ifdef _DEBUG - - DWORD err = GetLastError(); - switch(err) - { - case ERROR_INVALID_PIXEL_FORMAT: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Win32 Error: ERROR_INVALID_PIXEL_FORMAT"); - break; - case ERROR_NO_SYSTEM_RESOURCES: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Win32 Error: ERROR_NO_SYSTEM_RESOURCES"); - break; - case ERROR_INVALID_DATA: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Win32 Error: ERROR_INVALID_DATA"); - break; - case ERROR_INVALID_WINDOW_HANDLE: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Win32 Error: ERROR_INVALID_WINDOW_HANDLE"); - break; - case ERROR_RESOURCE_TYPE_NOT_FOUND: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Win32 Error: ERROR_RESOURCE_TYPE_NOT_FOUND"); - break; - case ERROR_SUCCESS: - // no error - break; - default: - LPVOID lpMsgBuf; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL); - - SG_LOG(SG_GL, SG_ALERT, "RenderTexture Win32 Error " << err << ":" << lpMsgBuf); - LocalFree( lpMsgBuf ); - break; - } - SetLastError(0); - -#endif // _DEBUG -} -#endif - -//--------------------------------------------------------------------------- -// Function : PrintExtensionError -// Description : -//--------------------------------------------------------------------------- -/** -* @fn PrintExtensionError( char* strMsg, ... ) -* @brief Prints an error about missing OpenGL extensions. -*/ -void PrintExtensionError( const char* strMsg, ... ) -{ - SG_LOG(SG_GL, SG_ALERT, - "Error: RenderTexture requires the following unsupported " - "OpenGL extensions: "); - char strBuffer[512]; - va_list args; - va_start(args, strMsg); - vsnprintf( strBuffer, 512, strMsg, args ); - va_end(args); - - SG_LOG(SG_GL, SG_ALERT, strMsg); - dbg_printf("Error: RenderTexture requires the following unsupported OpenGL extensions: \n[%s]\n", strMsg); -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::Initialize -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::Initialize(int width, int height, bool shareObjects, bool copyContext); -* @brief Initializes the RenderTexture, sharing display lists and textures if specified. -* -* This function creates of the p-buffer. It can only be called once a GL -* context has already been created. -*/ -bool RenderTexture::Initialize(int width, int height, - bool shareObjects /* = true */, - bool copyContext /* = false */) -{ - assert(width > 0 && height > 0); - - dbg_printf("RenderTexture::Initialize w=%d h=%d\n", width, height ); - - _iWidth = width; _iHeight = height; - _bPowerOf2 = IsPowerOfTwo(width) && IsPowerOfTwo(height); - - _bShareObjects = shareObjects; - _bCopyContext = copyContext; - - // Check if this is an NVXX GPU and verify necessary extensions. - if (!_VerifyExtensions()) { - dbg_printf("RenderTexture::Initialize: _VerifyExtensions() FAILED - returning false.\n" ); - return false; - } - - if (_bInitialized) - _Invalidate(); - -#ifdef _WIN32 - // Get the current context. - HDC hdc = wglGetCurrentDC(); - if (NULL == hdc) - _wglGetLastError(); - HGLRC hglrc = wglGetCurrentContext(); - if (NULL == hglrc) - _wglGetLastError(); - - int iFormat = 0; - unsigned int iNumFormats; - - if (_bCopyContext) - { - // Get the pixel format for the on-screen window. - iFormat = GetPixelFormat(hdc); - if (iFormat == 0) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: GetPixelFormat() failed."); - return false; - } - } - else - { - if (!wglChoosePixelFormatARBPtr(hdc, &_pixelFormatAttribs[0], NULL, - 1, &iFormat, &iNumFormats)) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: wglChoosePixelFormatARB() failed."); - _wglGetLastError(); - return false; - } - if ( iNumFormats <= 0 ) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: Couldn't find a suitable " - "pixel format."); - _wglGetLastError(); - return false; - } - } - - // Create the p-buffer. - _hPBuffer = wglCreatePbufferARBPtr(hdc, iFormat, _iWidth, _iHeight, - &_pbufferAttribs[0]); - if (!_hPBuffer) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: wglCreatePbufferARB() failed."); - _wglGetLastError(); - return false; - } - - // Get the device context. - _hDC = wglGetPbufferDCARBPtr( _hPBuffer); - if ( !_hDC ) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: wglGetGetPbufferDCARB() failed."); - _wglGetLastError(); - return false; - } - - // Create a gl context for the p-buffer. - if (_bCopyContext) - { - // Let's use the same gl context.. - // Since the device contexts are compatible (i.e. same pixelformat), - // we should be able to use the same gl rendering context. - _hGLContext = hglrc; - } - else - { - _hGLContext = wglCreateContext( _hDC ); - if ( !_hGLContext ) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: wglCreateContext() failed."); - _wglGetLastError(); - return false; - } - } - - // Share lists, texture objects, and program objects. - if( _bShareObjects ) - { - if( !wglShareLists(hglrc, _hGLContext) ) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: wglShareLists() failed."); - _wglGetLastError(); - return false; - } - } - - // Determine the actual width and height we were able to create. - wglQueryPbufferARBPtr( _hPBuffer, WGL_PBUFFER_WIDTH_ARB, &_iWidth ); - wglQueryPbufferARBPtr( _hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &_iHeight ); - - _bInitialized = true; - - // get the actual number of bits allocated: - int attrib = WGL_RED_BITS_ARB; - //int bits[6]; - int value; - _iNumColorBits[0] = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_GREEN_BITS_ARB; - _iNumColorBits[1] = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_BLUE_BITS_ARB; - _iNumColorBits[2] = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_ALPHA_BITS_ARB; - _iNumColorBits[3] = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_DEPTH_BITS_ARB; - _iNumDepthBits = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_STENCIL_BITS_ARB; - _iNumStencilBits = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_DOUBLE_BUFFER_ARB; - _bDoubleBuffered = - (wglGetPixelFormatAttribivARBPtr(_hDC, iFormat, 0, 1, &attrib, &value)) - ? (value?true:false) : false; - -#if defined(_DEBUG) | defined(DEBUG) - SG_LOG(SG_GL, SG_ALERT, "Created a " << _iWidth << "x" << _iHeight << - " RenderTexture with BPP(" << - _iNumColorBits[0] << "," << _iNumColorBits[1] << "," << - _iNumColorBits[2] << "," << _iNumColorBits[3] << ")"); - if (_iNumDepthBits) SG_LOG(SG_GL, SG_ALERT, " depth=" << _iNumDepthBits); - if (_iNumStencilBits) SG_LOG(SG_GL, SG_ALERT, " stencil=" << _iNumStencilBits); - if (_bDoubleBuffered) SG_LOG(SG_GL, SG_ALERT, " double buffered"); -#endif - -#elif defined( __MACH__ ) - // Get the current context. - CGLContextObj hglrc = CGLGetCurrentContext(); - if (NULL == hglrc) - fprintf(stderr, "Couldn't get current context!"); - - CGLPixelFormatObj pixFormat = NULL; - GLint iNumFormats; - CGLError error; - - // Copy the _pixelFormatAttribs into another array to fix - // typecast issues - CGLPixelFormatAttribute *pixFormatAttribs = - (CGLPixelFormatAttribute *)malloc(sizeof(CGLPixelFormatAttribute) - * _pixelFormatAttribs.size()); - - for (unsigned int ii = 0; ii < _pixelFormatAttribs.size(); ii++) - { - pixFormatAttribs[ii] = - (CGLPixelFormatAttribute)_pixelFormatAttribs[ii]; - } - - if (error = - CGLChoosePixelFormat(&pixFormatAttribs[0], &pixFormat, &iNumFormats)) - { - fprintf(stderr, - "RenderTexture Error: CGLChoosePixelFormat() failed.\n"); - _cglCheckError(error); - return false; - } - if ( iNumFormats <= 0 ) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: Couldn't find a suitable " - "pixel format."); - return false; - } - - // Free the copy of the _pixelFormatAttribs array - free(pixFormatAttribs); - - // Create the context. - error = CGLCreateContext(pixFormat, (_bShareObjects) - ? CGLGetCurrentContext() : NULL, &_hGLContext); - if (error) - { - fprintf(stderr, - "RenderTexture Error: CGLCreateContext() failed.\n"); - _cglCheckError(error); - return false; - } - CGLDestroyPixelFormat(pixFormat); - - // Create the p-buffer. - error = CGLCreatePBuffer(_iWidth, _iHeight, (_bRectangle) - ? GL_TEXTURE_RECTANGLE_EXT : GL_TEXTURE_2D, GL_RGBA, 0, &_hPBuffer); - if (error) - { - fprintf(stderr, - "RenderTexture Error: CGLCreatePBuffer() failed.\n"); - _cglCheckError(error); - return false; - } - - GLint screen; - if (error = CGLGetVirtualScreen(CGLGetCurrentContext(), &screen)) - { - _cglCheckError(error); - return false; - } - if (error = CGLSetPBuffer(_hGLContext, _hPBuffer, 0, 0, screen)) - { - _cglCheckError(error); - return false; - } - - // 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 ); - - _bInitialized = true; - - /* - // get the actual number of bits allocated: - int attrib = WGL_RED_BITS_ARB; - //int bits[6]; - int value; - _iNumColorBits[0] = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_GREEN_BITS_ARB; - _iNumColorBits[1] = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_BLUE_BITS_ARB; - _iNumColorBits[2] = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_ALPHA_BITS_ARB; - _iNumColorBits[3] = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_DEPTH_BITS_ARB; - _iNumDepthBits = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_STENCIL_BITS_ARB; - _iNumStencilBits = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? value : 0; - attrib = WGL_DOUBLE_BUFFER_ARB; - _bDoubleBuffered = - (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) - ? (value?true:false) : false; - */ - -#if defined(_DEBUG) | defined(DEBUG) - fprintf(stderr, "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"); -#endif - -#else // !_WIN32, !__MACH_ - - _pDisplay = glXGetCurrentDisplay(); - if ( !_pDisplay ) { - dbg_printf("RenderTexture::Initialize: ERROR: glXGetCurrentDisplay() returned NULL! return false\n"); - return false; - } - dbg_printf("RenderTexture::Initialize: got glXGetCurrentDisplay() _pDisplay=[%p]\n", _pDisplay); - // glXGetCurrentContext returns the current context, as specified by glXMakeCurrent. - // If there is no current context, NULL is returned. - GLXContext context = glXGetCurrentContext(); - if ( !context ) { - dbg_printf("RenderTexture::Initialize: ERROR: glXGetCurrentContext() returned NULL! return false\n"); - return false; - } - dbg_printf("RenderTexture::Initialize: got glXGetCurrentContext() context=[%p]\n", context); - int screen = DefaultScreen(_pDisplay); - dbg_printf("RenderTexture::Initialize: DefaultScreen(_pDisplay) screen=%d\n", screen); - - XVisualInfo *visInfo = NULL; - - GLXFBConfig *fbConfigs; - int nConfigs; -#ifdef _DEBUG - dbg_printf("Using %d pixelFormatAttribs array\n", (int)_pixelFormatAttribs.size()); - size_t max = _pixelFormatAttribs.size() / 2; - int dat = 0; - size_t n; - for (n = 0; n < max; n++) { - const char * cp = get_attr_name(_pixelFormatAttribs[n*2], &dat); - printf( "%s(%d) = %d (def=%d)\n", - cp, _pixelFormatAttribs[n*2], _pixelFormatAttribs[(n*2)+1], dat ); - } - n *= 2; - if ( n < _pixelFormatAttribs.size() ) - printf( "Array ends with %d\n", _pixelFormatAttribs[n] ); - else - printf( "WARNING: Array does not appear ODD! which is ODD\n" ); - -#endif - fbConfigs = glXChooseFBConfigPtr(_pDisplay, screen, - &_pixelFormatAttribs[0], &nConfigs); - // NOTE: ref: http://www.opengl.org/sdk/docs/man/xhtml/glXChooseFBConfig.xml says - // Next, call glXGetFBConfigAttrib to retrieve additional attributes for the frame buffer configurations and then select between them. - - if (nConfigs <= 0 || !fbConfigs) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: Couldn't find a suitable pixel format."); - dbg_printf("RenderTexture Error: Couldn't find a suitable pixel format. return false\n"); - return false; - } - - dbg_printf("RenderTexture::Initialize: glXChooseFBConfigPtr() nConfigs = %d, fbConfigs=[%p]\n", nConfigs, fbConfigs); - - int pbufAttrib[] = { - GLX_PBUFFER_WIDTH, _iWidth, - GLX_PBUFFER_HEIGHT, _iHeight, - GLX_LARGEST_PBUFFER, False, - None - }; - // Pick the first returned format that will return a pbuffer - // if (glXVersion1_3Present) - if (glXCreatePbufferPtr && glXGetVisualFromFBConfigPtr && glXCreateContextPtr) - { - dbg_printf("RenderTexture::Initialize: glXVersion1_3Present = TRUE\n"); - for (int i=0;i_bInitialized) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture::BeginCapture(RenderTexture): 'current' texture is not initialized!"); - return false; - } - - // Sync current pbuffer with its CTT texture if necessary - current->_MaybeCopyBuffer(); - - // pass along the previous context so we can reset it when - // EndCapture() is called. -#ifdef _WIN32 - _hPreviousDC = current->_hPreviousDC; - if (NULL == _hPreviousDC) - _wglGetLastError(); - _hPreviousContext = current->_hPreviousContext; - if (NULL == _hPreviousContext) - _wglGetLastError(); -#elif defined( __MACH__ ) - _hPreviousContext = current->_hPreviousContext; -#else - _hPreviousContext = current->_hPreviousContext; - _hPreviousDrawable = current->_hPreviousDrawable; -#endif - - // Unbind textures before making context current - if (!_ReleaseBoundBuffers()) - return false; - - // Make the pbuffer context current - if (!_MakeCurrent()) - return false; - - // Rebind buffers of initial RenderTexture - current->BindBuffer(_iCurrentBoundBuffer); - current->_BindDepthBuffer(); - - return true; -} - - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::Bind -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::Bind() -* @brief Binds RGB texture. -*/ -void RenderTexture::Bind() const -{ - if (_bInitialized && _bIsTexture) - { - glBindTexture(_iTextureTarget, _iTextureID); - } -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::BindDepth -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::BindDepth() -* @brief Binds depth texture. -*/ -void RenderTexture::BindDepth() const -{ - if (_bInitialized && _bIsDepthTexture) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - } -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::BindBuffer -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::BindBuffer() -* @brief Associate the RTT texture id with 'iBuffer' (e.g. WGL_FRONT_LEFT_ARB) -*/ -bool RenderTexture::BindBuffer( int iBuffer ) -{ - // Must bind the texture too - if (_bInitialized && _bIsTexture) - { - glBindTexture(_iTextureTarget, _iTextureID); - -#ifdef _WIN32 - if (RT_RENDER_TO_TEXTURE == _eUpdateMode && _bIsTexture && - (!_bIsBufferBound || _iCurrentBoundBuffer != 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 - //_wglGetLastError(); - //return false; - SetLastError(0); - } - _bIsBufferBound = true; - _iCurrentBoundBuffer = iBuffer; - } -#elif defined(__MACH__) - if (RT_RENDER_TO_TEXTURE == _eUpdateMode && _bIsTexture && - (!_bIsBufferBound || _iCurrentBoundBuffer != iBuffer)) - { - CGLError err; - if (err=CGLTexImagePBuffer(CGLGetCurrentContext(), _hPBuffer, iBuffer)) - { - _cglCheckError(err); - } - _bIsBufferBound = true; - _iCurrentBoundBuffer = iBuffer; - } -#endif - } - return true; -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::BindDepthBuffer -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_BindDepthBuffer() -* @brief Associate the RTT depth texture id with the depth buffer -*/ -bool RenderTexture::_BindDepthBuffer() const -{ -#ifdef WIN32 - if (_bInitialized && _bIsDepthTexture && - RT_RENDER_TO_TEXTURE == _eUpdateMode) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - if (FALSE == wglBindTexImageARBPtr(_hPBuffer, WGL_DEPTH_COMPONENT_NV)) - { - _wglGetLastError(); - return false; - } - } -#elif defined(__MACH__) - if (_bInitialized && _bIsDepthTexture && - RT_RENDER_TO_TEXTURE == _eUpdateMode) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - //if (FALSE == CGLTexImagePBuffer(<#CGLContextObj ctx#>,<#CGLPBufferObj pbuffer#>,<#unsigned long source#>)(_hPBuffer, WGL_DEPTH_COMPONENT_NV)) - //{ - // _wglGetLastError(); - // return false; - //} - } -#endif - return true; -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_ParseModeString -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_ParseModeString() -* @brief Parses the user-specified mode string for RenderTexture parameters. -*/ -void RenderTexture::_ParseModeString(const char *modeString, - vector &pfAttribs, - vector &pbAttribs) -{ - dbg_printf("RenderTexture::_ParseModeString(%s). BGN vf=%d vp=%d\n", modeString, (int)pfAttribs.size(), (int)pbAttribs.size() ); - if (!modeString || strcmp(modeString, "") == 0) - return; - - _iNumComponents = 0; -#if defined(_WIN32) || defined(__MACH__) - _eUpdateMode = RT_RENDER_TO_TEXTURE; -#else - _eUpdateMode = RT_COPY_TO_TEXTURE; -#endif - - int iDepthBits = 0; - bool bHasStencil = false; - bool bBind2D = false; - bool bBindRECT = false; - bool bBindCUBE = false; - - char *mode = strdup(modeString); - - - vector tokens; - char *buf = strtok(mode, " "); - while (buf != NULL) - { - tokens.push_back(buf); - buf = strtok(NULL, " "); - } - free(mode); - for (unsigned int i = 0; i < tokens.size(); i++) - { - string token = tokens[i]; - - KeyVal kv = _GetKeyValuePair(token); - - - if (kv.first == "rgb" && (_iNumComponents <= 1)) - { - if (kv.second.find("f") != kv.second.npos) - _bFloat = true; - - vector bitVec = _ParseBitVector(kv.second); - - if (bitVec.size() < 3) // expand the scalar to a vector - { - bitVec.push_back(bitVec[0]); - bitVec.push_back(bitVec[0]); - } - -#ifdef _WIN32 - pfAttribs.push_back(WGL_RED_BITS_ARB); - pfAttribs.push_back(bitVec[0]); - pfAttribs.push_back(WGL_GREEN_BITS_ARB); - pfAttribs.push_back(bitVec[1]); - pfAttribs.push_back(WGL_BLUE_BITS_ARB); - pfAttribs.push_back(bitVec[2]); -#elif defined( __MACH__ ) -# if 0 - 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 - pfAttribs.push_back(kCGLPFAColorSize); - pfAttribs.push_back(bitVec[0] + bitVec[1] + bitVec[2]); -# endif -#else - 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 - _iNumComponents += 3; - continue; - } - else if (kv.first == "rgb") - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: mistake in components definition " - "(rgb + " << _iNumComponents << ")."); - dbg_printf("RenderTexture Warning 1: mistake in components definition " - "(rgb + %d).\n", _iNumComponents ); - } - - if (kv.first == "rgba" && (_iNumComponents == 0)) - { - if (kv.second.find("f") != kv.second.npos) - _bFloat = true; - - vector bitVec = _ParseBitVector(kv.second); - - if (bitVec.size() < 4) // expand the scalar to a vector - { - bitVec.push_back(bitVec[0]); - bitVec.push_back(bitVec[0]); - bitVec.push_back(bitVec[0]); - } - -#ifdef _WIN32 - pfAttribs.push_back(WGL_RED_BITS_ARB); - pfAttribs.push_back(bitVec[0]); - pfAttribs.push_back(WGL_GREEN_BITS_ARB); - pfAttribs.push_back(bitVec[1]); - pfAttribs.push_back(WGL_BLUE_BITS_ARB); - pfAttribs.push_back(bitVec[2]); - pfAttribs.push_back(WGL_ALPHA_BITS_ARB); - pfAttribs.push_back(bitVec[3]); -#elif defined( __MACH__ ) -# if 0 - 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 - pfAttribs.push_back(kCGLPFAColorSize); - pfAttribs.push_back(bitVec[0] + bitVec[1] + bitVec[2] + bitVec[3]); - //pfAttribs.push_back(kCGLPFAAlphaSize); - //pfAttribs.push_back(bitVec[3]); - // printf("Color size: %d\n", bitVec[0] + bitVec[1] + bitVec[2] + bitVec[3]); - -# endif -#else - 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]); - pfAttribs.push_back(GLX_ALPHA_SIZE); - pfAttribs.push_back(bitVec[3]); -#endif - _iNumComponents = 4; - continue; - } - else if (kv.first == "rgba") - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: mistake in components definition " - "(rgba + " << _iNumComponents << ")."); - dbg_printf("RenderTexture Warning 2: mistake in components definition " - "(rgb + %d).\n", _iNumComponents ); - } - - if (kv.first == "r" && (_iNumComponents <= 1)) - { - if (kv.second.find("f") != kv.second.npos) - _bFloat = true; - - vector bitVec = _ParseBitVector(kv.second); - -#ifdef _WIN32 - pfAttribs.push_back(WGL_RED_BITS_ARB); - pfAttribs.push_back(bitVec[0]); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_RED_SIZE); - pfAttribs.push_back(bitVec[0]); -# else - pfAttribs.push_back(kCGLPFAColorSize); - pfAttribs.push_back(bitVec[0]); -# endif -#else - pfAttribs.push_back(GLX_RED_SIZE); - pfAttribs.push_back(bitVec[0]); -#endif - _iNumComponents++; - continue; - } - else if (kv.first == "r") - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: mistake in components definition " - "(r + " << _iNumComponents << ")."); - dbg_printf("RenderTexture Warning 3: mistake in components definition " - "(rgb + %d).\n", _iNumComponents ); - } - if (kv.first == "rg" && (_iNumComponents <= 1)) - { - if (kv.second.find("f") != kv.second.npos) - _bFloat = true; - - vector bitVec = _ParseBitVector(kv.second); - - if (bitVec.size() < 2) // expand the scalar to a vector - { - bitVec.push_back(bitVec[0]); - } - -#ifdef _WIN32 - pfAttribs.push_back(WGL_RED_BITS_ARB); - pfAttribs.push_back(bitVec[0]); - pfAttribs.push_back(WGL_GREEN_BITS_ARB); - pfAttribs.push_back(bitVec[1]); -#elif defined( __MACH__ ) -# if 0 - 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(kCGLPFAColorSize); - pfAttribs.push_back(bitVec[0] + bitVec[1]); -# endif -#else - pfAttribs.push_back(GLX_RED_SIZE); - pfAttribs.push_back(bitVec[0]); - pfAttribs.push_back(GLX_GREEN_SIZE); - pfAttribs.push_back(bitVec[1]); -#endif - _iNumComponents += 2; - continue; - } - else if (kv.first == "rg") - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: mistake in components definition " - "(rg + " << _iNumComponents << ")."); - dbg_printf("RenderTexture Warning 4: mistake in components definition " - "(rgb + %d).\n", _iNumComponents ); - } - - if (kv.first == "depth") - { - if (kv.second == "") - iDepthBits = 24; - else - iDepthBits = strtol(kv.second.c_str(), 0, 10); - continue; - } - - if (kv.first == "stencil") - { - bHasStencil = true; -#ifdef _WIN32 - pfAttribs.push_back(WGL_STENCIL_BITS_ARB); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_STENCIL_SIZE); -# else - pfAttribs.push_back(kCGLPFAStencilSize); -# endif -#else - pfAttribs.push_back(GLX_STENCIL_SIZE); -#endif - if (kv.second == "") - pfAttribs.push_back(8); - else - pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10)); - continue; - } - - if (kv.first == "samples") - { -#ifdef _WIN32 - pfAttribs.push_back(WGL_SAMPLE_BUFFERS_ARB); - pfAttribs.push_back(1); - pfAttribs.push_back(WGL_SAMPLES_ARB); - pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10)); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_SAMPLE_BUFFERS_ARB); - pfAttribs.push_back(1); - pfAttribs.push_back(AGL_SAMPLES_ARB); -# else - pfAttribs.push_back(kCGLPFAMultisample); - pfAttribs.push_back(kCGLPFASamples); -# endif - pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10)); -#else - pfAttribs.push_back(GLX_SAMPLE_BUFFERS_ARB); - pfAttribs.push_back(1); - pfAttribs.push_back(GLX_SAMPLES_ARB); - pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10)); -#endif - continue; - - } - - if (kv.first == "doublebuffer" || kv.first == "double") - { -#ifdef _WIN32 - pfAttribs.push_back(WGL_DOUBLE_BUFFER_ARB); - pfAttribs.push_back(true); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_DOUBLEBUFFER); - pfAttribs.push_back(True); -# else - pfAttribs.push_back(kCGLPFADoubleBuffer); -# endif -#else - pfAttribs.push_back(GLX_DOUBLEBUFFER); - pfAttribs.push_back(True); -#endif - continue; - } - - if (kv.first == "aux") - { -#ifdef _WIN32 - pfAttribs.push_back(WGL_AUX_BUFFERS_ARB); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_AUX_BUFFERS); -# else - pfAttribs.push_back(kCGLPFAAuxBuffers); -# endif -#else - pfAttribs.push_back(GLX_AUX_BUFFERS); -#endif - if (kv.second == "") - pfAttribs.push_back(0); - else - pfAttribs.push_back(strtol(kv.second.c_str(), 0, 10)); - continue; - } - - if (token.find("tex") == 0) - { - _bIsTexture = true; - - if ((kv.first == "texRECT") && (GL_NV_texture_rectangle || - GL_EXT_texture_rectangle)) - { - _bRectangle = true; - bBindRECT = true; - } - else if (kv.first == "texCUBE") - { - bBindCUBE = true; - } - else - { - bBind2D = true; - } - - continue; - } - - if (token.find("depthTex") == 0) - { - _bIsDepthTexture = true; - - if ((kv.first == "depthTexRECT") && (GL_NV_texture_rectangle || - GL_EXT_texture_rectangle)) - { - _bRectangle = true; - bBindRECT = true; - } - else if (kv.first == "depthTexCUBE") - { - bBindCUBE = true; - } - else - { - bBind2D = true; - } - - continue; - } - - if (kv.first == "mipmap") - { - _bMipmap = true; - continue; - } - - if (kv.first == "rtt") - { - _eUpdateMode = RT_RENDER_TO_TEXTURE; - continue; - } - - if (kv.first == "ctt") - { - _eUpdateMode = RT_COPY_TO_TEXTURE; - continue; - } - - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: Unknown pbuffer attribute: " << - token.c_str()); - dbg_printf("RenderTexture Error: Uknown pbuffer attribute: %s\n", - token.c_str() ); - } - - // Processing of some options must be last because of interactions. - - // Check for inconsistent texture targets - if (_bIsTexture && _bIsDepthTexture && !(bBind2D ^ bBindRECT ^ bBindCUBE)) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Depth and Color texture targets " - "should match."); - dbg_printf( "RenderTexture Warning: Depth and Color texture targets should match.\n"); - } - - // Apply default bit format if none specified -#ifdef _WIN32 - if (0 == _iNumComponents) - { - pfAttribs.push_back(WGL_RED_BITS_ARB); - pfAttribs.push_back(8); - pfAttribs.push_back(WGL_GREEN_BITS_ARB); - pfAttribs.push_back(8); - pfAttribs.push_back(WGL_BLUE_BITS_ARB); - pfAttribs.push_back(8); - pfAttribs.push_back(WGL_ALPHA_BITS_ARB); - pfAttribs.push_back(8); - _iNumComponents = 4; - } -#endif - - // Depth bits - if (_bIsDepthTexture && !iDepthBits) - iDepthBits = 24; - -#ifdef _WIN32 - pfAttribs.push_back(WGL_DEPTH_BITS_ARB); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_DEPTH_SIZE); -# else - pfAttribs.push_back(kCGLPFADepthSize); -# endif -#else - pfAttribs.push_back(GLX_DEPTH_SIZE); -#endif - pfAttribs.push_back(iDepthBits); // default - - if (!bHasStencil) - { -#ifdef _WIN32 - pfAttribs.push_back(WGL_STENCIL_BITS_ARB); - pfAttribs.push_back(0); -#elif defined( __MACH__ ) -# if 0 - pfAttribs.push_back(AGL_STENCIL_SIZE); -# else - pfAttribs.push_back(kCGLPFAStencilSize); -# endif - pfAttribs.push_back(0); -#else - pfAttribs.push_back(GLX_STENCIL_SIZE); - pfAttribs.push_back(0); -#endif - - } - if (_iNumComponents < 4) - { - // Can't do this right now -- on NVIDIA drivers, currently get - // a non-functioning pbuffer if ALPHA_BITS=0 and - // WGL_BIND_TO_TEXTURE_RGB_ARB=true - - //pfAttribs.push_back(WGL_ALPHA_BITS_ARB); - //pfAttribs.push_back(0); - } - -#ifdef _WIN32 - if (!WGL_NV_render_depth_texture && _bIsDepthTexture && (RT_RENDER_TO_TEXTURE == _eUpdateMode)) - { -#if defined(DEBUG) || defined(_DEBUG) - SG_LOG(SG_GL, SG_ALERT, "RenderTexture Warning: No support found for " - "render to depth texture."); -#endif - dbg_printf("RenderTexture Warning: No support found for render to depth texture.\n"); - _bIsDepthTexture = false; - } -#endif - - if ((_bIsTexture || _bIsDepthTexture) && - (RT_RENDER_TO_TEXTURE == _eUpdateMode)) - { -#ifdef _WIN32 - if (bBindRECT) - { - pbAttribs.push_back(WGL_TEXTURE_TARGET_ARB); - pbAttribs.push_back(WGL_TEXTURE_RECTANGLE_NV); - } - else if (bBindCUBE) - { - pbAttribs.push_back(WGL_TEXTURE_TARGET_ARB); - pbAttribs.push_back(WGL_TEXTURE_CUBE_MAP_ARB); - } - else if (bBind2D) - { - pbAttribs.push_back(WGL_TEXTURE_TARGET_ARB); - pbAttribs.push_back(WGL_TEXTURE_2D_ARB); - } - - if (_bMipmap) - { - pbAttribs.push_back(WGL_MIPMAP_TEXTURE_ARB); - pbAttribs.push_back(true); - } -#elif defined(__MACH__) -#elif defined(DEBUG) || defined(_DEBUG) - SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: Render to Texture not " - "supported in Linux or MacOS"); -#endif - } - - // Set the pixel type - if (_bFloat) - { -#ifdef _WIN32 - if (WGL_NV_float_buffer) - { - pfAttribs.push_back(WGL_PIXEL_TYPE_ARB); - pfAttribs.push_back(WGL_TYPE_RGBA_ARB); - - pfAttribs.push_back(WGL_FLOAT_COMPONENTS_NV); - pfAttribs.push_back(true); - } - else - { - pfAttribs.push_back(WGL_PIXEL_TYPE_ARB); - pfAttribs.push_back(WGL_TYPE_RGBA_FLOAT_ATI); - } -#elif defined( __MACH__ ) - // if (GL_MACH_float_pixels) // FIXME - { - pfAttribs.push_back(kCGLPFAColorFloat); - } -#else - if (GLX_NV_float_buffer) - { - pfAttribs.push_back(GLX_FLOAT_COMPONENTS_NV); - pfAttribs.push_back(1); - } -#endif - } - else - { -#ifdef _WIN32 - pfAttribs.push_back(WGL_PIXEL_TYPE_ARB); - pfAttribs.push_back(WGL_TYPE_RGBA_ARB); -#endif - } - - // Set up texture binding for render to texture - if (_bIsTexture && (RT_RENDER_TO_TEXTURE == _eUpdateMode)) - { - -#ifdef _WIN32 - if (_bFloat) - { - if (WGL_NV_float_buffer) - { - switch(_iNumComponents) - { - case 1: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_R_NV); - break; - case 2: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RG_NV); - break; - case 3: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RGB_NV); - break; - case 4: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RGBA_NV); - break; - default: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Bad number of components " - "(r=1,rg=2,rgb=3,rgba=4): " << - _iNumComponents); - dbg_printf("RenderTexture Warning 1: Bad number of components (r=1,rg=2,rgb=3,rgba=4): %d\n", - _iNumComponents); - break; - } - } - else - { - if (4 == _iNumComponents) - { - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGBA_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGBA_ARB); - } - else - { - // standard ARB_render_texture only supports 3 or 4 channels - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGB_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGB_ARB); - } - } - - } - else - { - switch(_iNumComponents) - { - case 3: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGB_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGB_ARB); - break; - case 4: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGBA_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGBA_ARB); - break; - default: - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Bad number of components " - "(r=1,rg=2,rgb=3,rgba=4): " << _iNumComponents); - dbg_printf("RenderTexture Warning 2: Bad number of components (r=1,rg=2,rgb=3,rgba=4): %d\n", - _iNumComponents); - break; - } - } -#elif defined(__MACH__) - if (_bFloat) - { - /* - //if (WGLEW_NV_float_buffer) // FIXME - { - switch(_iNumComponents) - { - case 1: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_R_NV); - break; - case 2: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RG_NV); - break; - case 3: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RGB_NV); - break; - case 4: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_FLOAT_RGBA_NV); - break; - default: - fprintf(stderr, - "RenderTexture Warning: Bad number of components " - "(r=1,rg=2,rgb=3,rgba=4): %d.\n", - _iNumComponents); - break; - } - } - else - { - if (4 == _iNumComponents) - { - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGBA_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGBA_ARB); - } - else - { - // standard ARB_render_texture only supports 3 or 4 channels - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGB_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGB_ARB); - } - } - */ - } - else - { - /* - switch(_iNumComponents) - { - case 3: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGB_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGB_ARB); - break; - case 4: - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RGBA_ARB); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_TEXTURE_FORMAT_ARB); - pbAttribs.push_back(WGL_TEXTURE_RGBA_ARB); - break; - default: - fprintf(stderr, - "RenderTexture Warning: Bad number of components " - "(r=1,rg=2,rgb=3,rgba=4): %d.\n", _iNumComponents); - break; - } - */ - } -#elif defined(DEBUG) || defined(_DEBUG) - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: Render to Texture not supported in Linux or MacOS"); -#endif - dbg_printf( "RenderTexture Error 1: Render to Texture not supported in Linux or MacOS\n"); - } - - if (_bIsDepthTexture && (RT_RENDER_TO_TEXTURE == _eUpdateMode)) - { -#ifdef _WIN32 - if (_bRectangle) - { - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_DEPTH_TEXTURE_FORMAT_NV); - pbAttribs.push_back(WGL_TEXTURE_DEPTH_COMPONENT_NV); - } - else - { - pfAttribs.push_back(WGL_BIND_TO_TEXTURE_DEPTH_NV); - pfAttribs.push_back(true); - - pbAttribs.push_back(WGL_DEPTH_TEXTURE_FORMAT_NV); - pbAttribs.push_back(WGL_TEXTURE_DEPTH_COMPONENT_NV); - } -#elif defined(__MACH__) -#elif defined(DEBUG) || defined(_DEBUG) - SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: Render to Texture not supported in " - "Linux or MacOS"); -#endif - dbg_printf( "RenderTexture Error 2: Render to Texture not supported in Linux or MacOS\n"); - } - dbg_printf("RenderTexture::_ParseModeString(%s). END vf=%d vp=%d\n", modeString, (int)pfAttribs.size(), (int)pbAttribs.size() ); - -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_GetKeyValuePair -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_GetKeyValuePair() -* @brief Parses expressions of the form "X=Y" into a pair (X,Y). -*/ -RenderTexture::KeyVal RenderTexture::_GetKeyValuePair(string token) -{ - string::size_type pos = 0; - if ((pos = token.find("=")) != token.npos) - { - string key = token.substr(0, pos); - string value = token.substr(pos+1, token.length()-pos+1); - return KeyVal(key, value); - } - else - return KeyVal(token, ""); -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_ParseBitVector -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_ParseBitVector() -* @brief Parses expressions of the form "=r,g,b,a" into a vector: (r,g,b,a) -*/ -vector RenderTexture::_ParseBitVector(string bitVector) -{ - vector pieces; - vector bits; - - if (bitVector == "") - { - bits.push_back(8); // if a depth isn't specified, use default 8 bits - return bits; - } - - string::size_type pos = 0; - string::size_type nextpos = 0; - do - { - nextpos = bitVector.find_first_of(", ", pos); - pieces.push_back(string(bitVector, pos, nextpos - pos)); - pos = nextpos+1; - } while (nextpos != bitVector.npos ); - - for ( vector::iterator it = pieces.begin(); it != pieces.end(); it++) - { - bits.push_back(strtol(it->c_str(), 0, 10)); - } - - return bits; -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_VerifyExtensions -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_VerifyExtensions() -* @brief Checks that the necessary extensions are available based on RT mode. -*/ -bool RenderTexture::_VerifyExtensions() -{ - dbg_printf("RenderTexture::_VerifyExtensions() called...\n"); -#ifdef _WIN32 - // a second call to _VerifyExtensions will allways return true, causing a crash - // if the extension is not supported - if ( true || !fctPtrInited ) - { - 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) - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: " - "OpenGL extension GL_ARB_depth_texture not available." - " Using glReadPixels() to emulate behavior."); -#endif - _bHasARBDepthTexture = false; - //PrintExtensionError("GL_ARB_depth_texture"); - //return false; - // [/Redge] - } - SetLastError(0); - } -#elif defined( __MACH__ ) - // FIXME! Check extensions! -#else - Display* dpy = glXGetCurrentDisplay(); - int minor = 0, major = 0; - if (!dpy) { - dbg_printf("_VerifyExtensions: glXGetCurrentDisplay() returned NULL! returning false\n"); - return false; - } - if (!glXQueryVersion(dpy, &major, &minor)) - { - dbg_printf("_VerifyExtensions: glXQueryVersion(dpy, &major, &minor) FAILED! returning false\n"); - return false; - } - else - { - dbg_printf("_VerifyExtensions: glXQueryVersion(dpy, major=%d, minor=%d)\n", major, minor); - } - - int screen = DefaultScreen(dpy); - const char* extString = glXQueryExtensionsString(dpy, screen); - dbg_printf("_VerifyExtensions: glXQueryExtensionsString(dpy, screen) returned -\n[%s]\n", - (extString ? extString : "") ); - if (!SGSearchExtensionsString(extString, "GLX_SGIX_fbconfig") || - !SGSearchExtensionsString(extString, "GLX_SGIX_pbuffer")) - { - dbg_printf("_VerifyExtensions: glXQueryExtensionsString(dpy,screen) does NOT contain GLX_SGIX_fbconfig or GLX_SGIX_pbuffer!\n" ); - const char * extClient = glXGetClientString( dpy, GLX_EXTENSIONS ); - if (!extClient || - !SGSearchExtensionsString(extClient, "GLX_SGIX_fbconfig") || - !SGSearchExtensionsString(extClient, "GLX_SGIX_pbuffer")) - { - dbg_printf("_VerifyExtensions: AND glXGetClientString(dpy,GLX_EXTENSIONS) also! returning false\n" ); - return false; - } - else - { - dbg_printf("_VerifyExtensions: BUT glXGetClientString(dpy,GLX_EXTENSIONS) returned \n[%s]\n", extClient ); - dbg_printf("Since this DOES contain fbconfig and pbuffer, continuing...\n"); - } - } - // First try the glX version 1.3 functions. - glXChooseFBConfigPtr = (glXChooseFBConfigProc)SGLookupFunction("glXChooseFBConfig"); - glXCreatePbufferPtr = (glXCreatePbufferProc)SGLookupFunction("glXCreatePbuffer"); - glXGetVisualFromFBConfigPtr = (glXGetVisualFromFBConfigProc)SGLookupFunction("glXGetVisualFromFBConfig"); - glXCreateContextPtr = (glXCreateContextProc)SGLookupFunction("glXCreateContext"); - glXDestroyPbufferPtr = (glXDestroyPbufferProc)SGLookupFunction("glXDestroyPbuffer"); - glXQueryDrawablePtr = (glXQueryDrawableProc)SGLookupFunction("glXQueryDrawable"); - - if (((1 <= major && 3 <= minor) || 2 <= major) && - glXChooseFBConfigPtr && - glXCreatePbufferPtr && - glXGetVisualFromFBConfigPtr && - glXCreateContextPtr && - glXDestroyPbufferPtr && - glXQueryDrawablePtr) { - dbg_printf("_VerifyExtensions: setting glXVersion1_3Present TRUE\n" ); - glXVersion1_3Present = true; - } - else - { - dbg_printf("_VerifyExtensions: setting glXVersion1_3Present FALSE\n Reason: " ); - if ( !((1 <= major && 3 <= minor) || 2 <= major) ) { dbg_printf( "Version wrong %d.%d ", major, minor ); } - if ( !glXChooseFBConfigPtr ) { dbg_printf( "missing glXChooseFBConfigPtr " ); } - if ( !glXCreatePbufferPtr ) { dbg_printf( "missing glXCreatePbufferPtr " ); } - if ( !glXGetVisualFromFBConfigPtr ) { dbg_printf( "missing glXGetVisualFromFBConfigPtr " ); } - if ( !glXCreateContextPtr ) { dbg_printf( "missing glXCreateContextPtr " ); } - if ( !glXDestroyPbufferPtr ) { dbg_printf( "missing glXDestroyPbufferPtr " ); } - if ( !glXQueryDrawablePtr ) { dbg_printf( "missing glXQueryDrawablePtr " ); } - dbg_printf("\n"); - - 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) - { - dbg_printf("_VerifyExtensions: some pointer is NULL! return false\n" ); - if ( !glXCreateGLXPbufferPtr ) { - dbg_printf("RenderTexture::Initialize: ERROR glXCreateGLXPbufferPtr = NULL!\n"); - } else if ( !glXCreateContextWithConfigPtr ) { - dbg_printf("RenderTexture::Initialize: ERROR glXCreateContextWithConfigPtr = NULL!\n"); - } else if ( !glXVersion1_3Present && !glXQueryGLXPbufferSGIXPtr ) { - dbg_printf("RenderTexture::Initialize: ERROR glXQueryGLXPbufferSGIXPtr = NULL!\n"); - } - return false; - } else { - dbg_printf("_VerifyExtensions: appear to have all 'procs' glXCreateGLXPbufferPtr=[%p]\n", glXCreateGLXPbufferPtr ); - } - } - - if (_bIsDepthTexture && !GL_ARB_depth_texture) - { - PrintExtensionError("GL_ARB_depth_texture"); - return false; - } - if (_bFloat && _bIsTexture && !GLX_NV_float_buffer) - { - PrintExtensionError("GLX_NV_float_buffer"); - return false; - } - if (_eUpdateMode == RT_RENDER_TO_TEXTURE) - { - PrintExtensionError("Some GLX render texture extension: Please implement me!"); - return false; - } -#endif - - dbg_printf("RenderTexture::_VerifyExtensions: return true.\n"); - return true; -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_InitializeTextures -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_InitializeTextures() -* @brief Initializes the state of textures used by the RenderTexture. -*/ -bool RenderTexture::_InitializeTextures() -{ - dbg_printf( "RenderTexture::_InitializeTextures() called\n" ); - // Determine the appropriate texture formats and filtering modes. - - if (_bIsTexture || _bIsDepthTexture) - { - if (_bRectangle && GL_NV_texture_rectangle) - _iTextureTarget = GL_TEXTURE_RECTANGLE_NV; - else if (_bRectangle && GL_EXT_texture_rectangle) - _iTextureTarget = GL_TEXTURE_RECTANGLE_EXT; - else - _iTextureTarget = GL_TEXTURE_2D; - } - - if (_bIsTexture) - { - glGenTextures(1, (GLuint*)&_iTextureID); - glBindTexture(_iTextureTarget, _iTextureID); - - // Use clamp to edge as the default texture wrap mode for all tex - glTexParameteri(_iTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(_iTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - // Use NEAREST as the default texture filtering mode. - glTexParameteri(_iTextureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(_iTextureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - - if (RT_COPY_TO_TEXTURE == _eUpdateMode) - { - GLuint iInternalFormat; - GLuint iFormat; - - if (_bFloat) - { - if (_bMipmap) - { - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Error: mipmapped float textures not " - "supported."); - dbg_printf( "RenderTexture Error: mipmapped float textures not supported. return false\n"); - return false; - } - - switch(_iNumComponents) - { - case 1: - if (GL_NV_float_buffer) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_FLOAT_R32_NV : GL_FLOAT_R16_NV; - } - else if (GL_ATI_texture_float) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_LUMINANCE_FLOAT32_ATI : - GL_LUMINANCE_FLOAT16_ATI; - } - iFormat = GL_LUMINANCE; - break; - case 2: - if (GL_NV_float_buffer) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_FLOAT_RG32_NV : GL_FLOAT_RG16_NV; - } - else if (GL_ATI_texture_float) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_LUMINANCE_ALPHA_FLOAT32_ATI : - GL_LUMINANCE_ALPHA_FLOAT16_ATI; - } - iFormat = GL_LUMINANCE_ALPHA; - break; - case 3: - if (GL_NV_float_buffer) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_FLOAT_RGB32_NV : GL_FLOAT_RGB16_NV; - } - else if (GL_ATI_texture_float) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_RGB_FLOAT32_ATI : GL_RGB_FLOAT16_ATI; - } - iFormat = GL_RGB; - break; - case 4: - if (GL_NV_float_buffer) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_FLOAT_RGBA32_NV : GL_FLOAT_RGBA16_NV; - } - else if (GL_ATI_texture_float) - { - iInternalFormat = (_iNumColorBits[0] > 16) ? - GL_RGBA_FLOAT32_ATI : GL_RGBA_FLOAT16_ATI; - } - iFormat = GL_RGBA; - break; - default: - SG_LOG(SG_GL, SG_INFO, "RenderTexture Error: " - "Invalid number of components: " << - _iNumComponents); - dbg_printf( "RenderTexture Error: Invalid number of components: %d - return false\n", - _iNumComponents); - return false; - } - } - else // non-float - { - if (4 == _iNumComponents) - { - iInternalFormat = GL_RGBA8; - iFormat = GL_RGBA; - } - else - { - iInternalFormat = GL_RGB8; - iFormat = GL_RGB; - } - } - - // Allocate the texture image (but pass it no data for now). - glTexImage2D(_iTextureTarget, 0, iInternalFormat, - _iWidth, _iHeight, 0, iFormat, GL_FLOAT, NULL); - } - } - - if (_bIsDepthTexture) - { - glGenTextures(1, (GLuint*)&_iDepthTextureID); - glBindTexture(_iTextureTarget, _iDepthTextureID); - - // Use clamp to edge as the default texture wrap mode for all tex - glTexParameteri(_iTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(_iTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - // Use NEAREST as the default texture filtering mode. - glTexParameteri(_iTextureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(_iTextureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - if (RT_COPY_TO_TEXTURE == _eUpdateMode) - { - // [Redge] - if (_bHasARBDepthTexture) - { - // Allocate the texture image (but pass it no data for now). - glTexImage2D(_iTextureTarget, 0, GL_DEPTH_COMPONENT, - _iWidth, _iHeight, 0, GL_DEPTH_COMPONENT, - GL_FLOAT, NULL); - } - else - { - // allocate memory for depth texture - // Since this is slow, we warn the user in debug mode. (above) - _pPoorDepthTexture = new unsigned short[_iWidth * _iHeight]; - glTexImage2D(_iTextureTarget, 0, GL_LUMINANCE16, - _iWidth, _iHeight, 0, GL_LUMINANCE, - GL_UNSIGNED_SHORT, _pPoorDepthTexture); - } - // [/Redge] - } - } - - dbg_printf( "RenderTexture::_InitializeTextures() returning true\n" ); - return true; -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_MaybeCopyBuffer -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_MaybeCopyBuffer() -* @brief Does the actual copying for RenderTextures with RT_COPY_TO_TEXTURE -*/ -void RenderTexture::_MaybeCopyBuffer() -{ -#ifdef _WIN32 - if (RT_COPY_TO_TEXTURE == _eUpdateMode) - { - if (_bIsTexture) - { - glBindTexture(_iTextureTarget, _iTextureID); - glCopyTexSubImage2D(_iTextureTarget, - 0, 0, 0, 0, 0, _iWidth, _iHeight); - } - if (_bIsDepthTexture) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - // HOW TO COPY DEPTH TEXTURE??? Supposedly this just magically works... - // [Redge] - if (_bHasARBDepthTexture) - { - glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, - _iWidth, _iHeight); - } - else - { - // no 'real' depth texture available, so behavior has to be emulated - // using glReadPixels (beware, this is (naturally) slow ...) - glReadPixels(0, 0, _iWidth, _iHeight, GL_DEPTH_COMPONENT, - GL_UNSIGNED_SHORT, _pPoorDepthTexture); - glTexImage2D(_iTextureTarget, 0, GL_LUMINANCE16, - _iWidth, _iHeight, 0, GL_LUMINANCE, - GL_UNSIGNED_SHORT, _pPoorDepthTexture); - } - // [/Redge] - } - } - -#elif defined(__MACH__) - if (RT_COPY_TO_TEXTURE == _eUpdateMode) - { - if (_bIsTexture) - { - glBindTexture(_iTextureTarget, _iTextureID); - glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, _iWidth, _iHeight); - } - if (_bIsDepthTexture) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - assert(_bHasARBDepthTexture); - glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, _iWidth, _iHeight); - } - } -#else - if (_bIsTexture) - { - glBindTexture(_iTextureTarget, _iTextureID); - glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, _iWidth, _iHeight); - } - if (_bIsDepthTexture) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - assert(_bHasARBDepthTexture); - glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, _iWidth, _iHeight); - } -#endif - -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_ReleaseBoundBuffers -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_ReleaseBoundBuffers() -* @brief Releases buffer bindings on RenderTextures with RT_RENDER_TO_TEXTURE -*/ -bool RenderTexture::_ReleaseBoundBuffers() -{ -#ifdef _WIN32 - if (_bIsTexture && RT_RENDER_TO_TEXTURE == _eUpdateMode) - { - glBindTexture(_iTextureTarget, _iTextureID); - - // release the pbuffer from the render texture object - if (0 != _iCurrentBoundBuffer && _bIsBufferBound) - { - if (FALSE == wglReleaseTexImageARBPtr(_hPBuffer, _iCurrentBoundBuffer)) - { - _wglGetLastError(); - return false; - } - _bIsBufferBound = false; - } - } - - if (_bIsDepthTexture && RT_RENDER_TO_TEXTURE == _eUpdateMode) - { - glBindTexture(_iTextureTarget, _iDepthTextureID); - - // release the pbuffer from the render texture object - if (FALSE == wglReleaseTexImageARBPtr(_hPBuffer, WGL_DEPTH_COMPONENT_NV)) - { - _wglGetLastError(); - return false; - } - } - -#else - // textures can't be bound in Linux -#endif - return true; -} - -//--------------------------------------------------------------------------- -// Function : RenderTexture::_MakeCurrent -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::_MakeCurrent() -* @brief Makes the RenderTexture's context current -*/ -bool RenderTexture::_MakeCurrent() -{ -#ifdef _WIN32 - // make the pbuffer's rendering context current. - if (FALSE == wglMakeCurrent( _hDC, _hGLContext)) - { - _wglGetLastError(); - return false; - } -#elif defined( __MACH__ ) - CGLError err; - - if (err = CGLSetCurrentContext(_hGLContext)) - { - _cglCheckError(err); - return false; - } -#else -static GLXContext last_hGLContext = 0; - if (false == glXMakeCurrent(_pDisplay, _hPBuffer, _hGLContext)) - { - dbg_printf( "_MakeCurrent: glXMakeCurrent FAILED! returning false\n"); - return false; - } - - if ( last_hGLContext != _hGLContext ) { - last_hGLContext = _hGLContext; - dbg_printf( "_MakeCurrent: glXMakeCurrent set to [%p] SUCCESS! returning true\n", _hGLContext ); - } -#endif - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// -// Begin Deprecated Interface -// -///////////////////////////////////////////////////////////////////////////// - -//--------------------------------------------------------------------------- -// Function : RenderTexture::RenderTexture -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::RenderTexture() -* @brief Constructor. -*/ -RenderTexture::RenderTexture(int width, int height, - bool bIsTexture /* = true */, - bool bIsDepthTexture /* = false */) -: _iWidth(width), - _iHeight(height), - _bIsTexture(bIsTexture), - _bIsDepthTexture(bIsDepthTexture), - _bHasARBDepthTexture(true), // [Redge] - _eUpdateMode(RT_RENDER_TO_TEXTURE), - _bInitialized(false), - _iNumAuxBuffers(0), - _iCurrentBoundBuffer(0), - _iNumDepthBits(0), - _iNumStencilBits(0), - _bFloat(false), - _bDoubleBuffered(false), - _bPowerOf2(true), - _bRectangle(false), - _bMipmap(false), - _bShareObjects(false), - _bCopyContext(false), -#ifdef _WIN32 - _hDC(NULL), - _hGLContext(NULL), - _hPBuffer(NULL), - _hPreviousDC(0), - _hPreviousContext(0), -#elif defined( __MACH__ ) - _hGLContext(NULL), - _hPBuffer(NULL), - _hPreviousContext(NULL), -#else - _pDisplay(NULL), - _hGLContext(NULL), - _hPBuffer(0), - _hPreviousDrawable(0), - _hPreviousContext(0), -#endif - _iTextureTarget(GL_NONE), - _iTextureID(0), - _iDepthTextureID(0), - _pPoorDepthTexture(0) // [Redge] -{ - assert(width > 0 && height > 0); -#if defined DEBUG || defined _DEBUG - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Deprecated Contructor interface used."); -#endif - dbg_printf("RenderTexture Warning: Deprecated Contructor interface used.\n"); - - _iNumColorBits[0] = _iNumColorBits[1] = - _iNumColorBits[2] = _iNumColorBits[3] = 0; - _bPowerOf2 = IsPowerOfTwo(width) && IsPowerOfTwo(height); -} - -//------------------------------------------------------------------------------ -// Function : RenderTexture::Initialize -// Description : -//------------------------------------------------------------------------------ -/** -* @fn RenderTexture::Initialize(bool bShare, bool bDepth, bool bStencil, bool bMipmap, unsigned int iRBits, unsigned int iGBits, unsigned int iBBits, unsigned int iABits); -* @brief Initializes the RenderTexture, sharing display lists and textures if specified. -* -* This function actually does the creation of the p-buffer. It can only be called -* once a GL context has already been created. Note that if the texture is not -* power of two dimensioned, or has more than 8 bits per channel, enabling mipmapping -* will cause an error. -*/ -bool RenderTexture::Initialize(bool bShare /* = true */, - bool bDepth /* = false */, - bool bStencil /* = false */, - bool bMipmap /* = false */, - bool bAnisoFilter /* = false */, - unsigned int iRBits /* = 8 */, - unsigned int iGBits /* = 8 */, - unsigned int iBBits /* = 8 */, - unsigned int iABits /* = 8 */, - UpdateMode updateMode /* = RT_RENDER_TO_TEXTURE */) -{ - if (0 == _iWidth || 0 == _iHeight) - return false; - -#if defined DEBUG || defined _DEBUG - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Deprecated Initialize() interface used."); -#endif - dbg_printf("RenderTexture Warning: Deprecated Initialize() interface used.\n"); - - // create a mode string. - string mode = ""; - if (bDepth) - mode.append("depth "); - if (bStencil) - mode.append("stencil "); - if (bMipmap) - mode.append("mipmap "); - if (iRBits + iGBits + iBBits + iABits > 0) - { - if (iRBits > 0) - mode.append("r"); - if (iGBits > 0) - mode.append("g"); - if (iBBits > 0) - mode.append("b"); - if (iABits > 0) - mode.append("a"); - mode.append("="); - char bitVector[100]; - snprintf( bitVector, 100, - "%d%s,%d%s,%d%s,%d%s", - iRBits, (iRBits >= 16) ? "f" : "", - iGBits, (iGBits >= 16) ? "f" : "", - iBBits, (iBBits >= 16) ? "f" : "", - iABits, (iABits >= 16) ? "f" : ""); - mode.append(bitVector); - mode.append(" "); - } - if (_bIsTexture) - { - if ((GL_NV_texture_rectangle || GL_EXT_texture_rectangle) && - ((!IsPowerOfTwo(_iWidth) || !IsPowerOfTwo(_iHeight)) - || iRBits >= 16 || iGBits > 16 || iBBits > 16 || iABits >= 16)) - mode.append("texRECT "); - else - mode.append("tex2D "); - } - if (_bIsDepthTexture) - { - if ((GL_NV_texture_rectangle || GL_EXT_texture_rectangle) && - ((!IsPowerOfTwo(_iWidth) || !IsPowerOfTwo(_iHeight)) - || iRBits >= 16 || iGBits > 16 || iBBits > 16 || iABits >= 16)) - mode.append("texRECT "); - else - mode.append("tex2D "); - } - if (RT_COPY_TO_TEXTURE == updateMode) - mode.append("ctt"); - - _pixelFormatAttribs.clear(); - _pbufferAttribs.clear(); - -#ifdef _WIN32 - _pixelFormatAttribs.push_back(WGL_DRAW_TO_PBUFFER_ARB); - _pixelFormatAttribs.push_back(true); - _pixelFormatAttribs.push_back(WGL_SUPPORT_OPENGL_ARB); - _pixelFormatAttribs.push_back(true); - - _pbufferAttribs.push_back(WGL_PBUFFER_LARGEST_ARB); - _pbufferAttribs.push_back(true); -#elif defined( __MACH__ ) - //_pixelFormatAttribs.push_back(kCGLPFANoRecovery); - _pixelFormatAttribs.push_back(kCGLPFAAccelerated); - _pixelFormatAttribs.push_back(kCGLPFAWindow); - _pixelFormatAttribs.push_back(kCGLPFAPBuffer); -#else - _pixelFormatAttribs.push_back(GLX_RENDER_TYPE_SGIX); - _pixelFormatAttribs.push_back(GLX_RGBA_BIT_SGIX); - _pixelFormatAttribs.push_back(GLX_DRAWABLE_TYPE_SGIX); - _pixelFormatAttribs.push_back(GLX_PBUFFER_BIT_SGIX); -#endif - - _ParseModeString(mode.c_str(), _pixelFormatAttribs, _pbufferAttribs); - -#ifdef _WIN32 - _pixelFormatAttribs.push_back(0); - _pbufferAttribs.push_back(0); -#elif defined(__MACH__) - _pixelFormatAttribs.push_back(0); -#else - _pixelFormatAttribs.push_back(None); -#endif - - Initialize(_iWidth, _iHeight, bShare); - - return true; -} - - -//--------------------------------------------------------------------------- -// Function : RenderTexture::Reset -// Description : -//--------------------------------------------------------------------------- -/** -* @fn RenderTexture::Reset(int iWidth, int iHeight, unsigned int iMode, bool bIsTexture, bool bIsDepthTexture) -* @brief Resets the resolution of the offscreen buffer. -* -* Causes the buffer to delete itself. User must call Initialize() again -* before use. -*/ -bool RenderTexture::Reset(int iWidth, int iHeight) -{ - SG_LOG(SG_GL, SG_ALERT, - "RenderTexture Warning: Deprecated Reset() interface used."); - - dbg_printf("RenderTexture Warning: Deprecated Reset(x,y) interface used.\n"); - - if (!_Invalidate()) - { - SG_LOG(SG_GL, SG_ALERT, "RenderTexture::Reset(): failed to invalidate."); - dbg_printf( "RenderTexture::Reset(x,y): failed to invalidate. returning false\n"); - return false; - } - _iWidth = iWidth; - _iHeight = iHeight; - - dbg_printf( "RenderTexture::Reset(x,y): succeeded. returning true\n"); - return true; -} - -#if defined( _DEBUG ) && !defined( _WIN32 ) && !defined( __MACH__ ) -/* just some DEBUG ONLY code, to show the 'attributes' */ - -typedef struct tagPXATTS { - int attr; - const char * name; - const char * desc; - int def; -}PXATTS, * PPXATTS; - -static PXATTS pxAtts[] = { - { GLX_FBCONFIG_ID, "GLX_FBCONFIG_ID", - "followed by a valid XID that indicates the desired GLX frame buffer configuration. " - "When a GLX_FBCONFIG_ID is specified, all attributes are ignored. The default value is GLX_DONT_CARE.", - GLX_DONT_CARE }, - { GLX_BUFFER_SIZE, "GLX_BUFFER_SIZE", - "Must be followed by a nonnegative integer that indicates the desired color index buffer size." - "The smallest index buffer of at least the specified size is preferred. This attribute is ignored if GLX_COLOR_INDEX_BIT is not set " - "in GLX_RENDER_TYPE. The default value is 0.", - 0 }, - { GLX_LEVEL, "GLX_LEVEL", - "Must be followed by an integer buffer-level specification. This specification is honored exactly." - "Buffer level 0 corresponds to the default frame buffer of the display. " - "Buffer level 1 is the first overlay frame buffer, level two the second overlay frame buffer, and so on." - "Negative buffer levels correspond to underlay frame buffers. The default value is 0.", - 0 }, - { GLX_DOUBLEBUFFER, "GLX_DOUBLEBUFFER", - "Must be followed by True or False. If True is specified, then only double-buffered frame buffer configurations are considered;" - "if False is specified, then only single-buffered frame buffer configurations are considered. The default value is GLX_DONT_CARE.", - GLX_DONT_CARE }, - { GLX_STEREO, "GLX_STEREO", - "Must be followed by True or False. If True is specified, then only stereo frame buffer configurations are considered;" - " if False is specified, then only monoscopic frame buffer configurations are considered. The default value is False.", - False }, - { GLX_AUX_BUFFERS, "GLX_AUX_BUFFERS", - "Must be followed by a nonnegative integer that indicates the desired number of auxiliary buffers." - " Configurations with the smallest number of auxiliary buffers that meet or exceed the specified number are preferred." - " The default value is 0.", - 0 }, - { GLX_RED_SIZE, "GLX_RED_SIZE", - "must be followed by a nonnegative minimum size", - 0 }, - { GLX_GREEN_SIZE, "GLX_GREEN_SIZE", - "must be followed by a nonnegative minimum size", - 0 }, - { GLX_BLUE_SIZE, "GLX_BLUE_SIZE", - "must be followed by a nonnegative minimum size", - 0 }, - { GLX_ALPHA_SIZE, "GLX_ALPHA_SIZE", - "Each attribute, if present, must be followed by a nonnegative minimum size specification or GLX_DONT_CARE." - " The largest available total RGBA color buffer size (sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE) " - " of at least the minimum size specified for each color component is preferred. If the requested number of bits for a color " - " component is 0 or GLX_DONT_CARE, it is not considered. The default value for each color component is 0.", - 0 }, - { GLX_DEPTH_SIZE, "GLX_DEPTH_SIZE", - "Must be followed by a nonnegative minimum size specification. If this value is zero, " - "frame buffer configurations with no depth buffer are preferred." - "Otherwise, the largest available depth buffer of at least the minimum size is preferred. The default value is 0.", - 0 }, - { GLX_STENCIL_SIZE, "GLX_STENCIL_SIZE", - "Must be followed by a nonnegative integer that indicates the desired number of stencil bitplanes." - "The smallest stencil buffer of at least the specified size is preferred. If the desired value is zero," - " frame buffer configurations with no stencil buffer are preferred. The default value is 0.", - 0 }, - { GLX_ACCUM_RED_SIZE, "GLX_ACCUM_RED_SIZE", - "Must be followed by a nonnegative minimum size specification. If this value is zero, " - " frame buffer configurations with no red accumulation buffer are preferred." - " Otherwise, the largest possible red accumulation buffer of at least the minimum size is preferred. The default value is 0.", - 0 }, - { GLX_ACCUM_GREEN_SIZE, "GLX_ACCUM_GREEN_SIZE", - "Must be followed by a nonnegative minimum size specification. If this value is zero, " - "frame buffer configurations with no green accumulation buffer are preferred. " - "Otherwise, the largest possible green accumulation buffer of at least the minimum size is preferred. The default value is 0.", - 0 }, - { GLX_ACCUM_BLUE_SIZE, "GLX_ACCUM_BLUE_SIZE", - "Must be followed by a nonnegative minimum size specification. If this value is zero, " - "frame buffer configurations with no blue accumulation buffer are preferred. " - "Otherwise, the largest possible blue accumulation buffer of at least the minimum size is preferred. The default value is 0.", - 0 }, - { GLX_ACCUM_ALPHA_SIZE, "GLX_ACCUM_ALPHA_SIZE", - "Must be followed by a nonnegative minimum size specification. If this value is zero, " - "frame buffer configurations with no alpha accumulation buffer are preferred. " - "Otherwise, the largest possible alpha accumulation buffer of at least the minimum size is preferred. The default value is 0.", - 0 }, - { GLX_RENDER_TYPE, "GLX_RENDER_TYPE", - "Must be followed by a mask indicating which OpenGL rendering modes the frame buffer configuration must support. " - "Valid bits are GLX_RGBA_BIT and GLX_COLOR_INDEX_BIT. If the mask is set to GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT, " - "then only frame buffer configurations that can be bound to both RGBA contexts and color index contexts will be considered. " - "The default value is GLX_RGBA_BIT.", - GLX_RGBA_BIT }, - { GLX_DRAWABLE_TYPE, "GLX_DRAWABLE_TYPE", - "Must be followed by a mask indicating which GLX drawable types the frame buffer configuration must support. " - "Valid bits are GLX_WINDOW_BIT, GLX_PIXMAP_BIT, and GLX_PBUFFER_BIT. For example, if mask is set to " - "GLX_WINDOW_BIT | GLX_PIXMAP_BIT, only frame buffer configurations that support both windows and GLX pixmaps " - "will be considered. The default value is GLX_WINDOW_BIT.", - GLX_WINDOW_BIT }, - { GLX_X_RENDERABLE, "GLX_X_RENDERABLE", - "Must be followed by True or False. If True is specified, then only frame buffer configurations that " - "have associated X visuals (and can be used to render to Windows and/or GLX pixmaps) will be considered. " - "The default value is GLX_DONT_CARE. ", - GLX_DONT_CARE }, - { GLX_X_VISUAL_TYPE, "GLX_X_VISUAL_TYPE", - "Must be followed by one of GLX_TRUE_COLOR, GLX_DIRECT_COLOR, GLX_PSEUDO_COLOR, GLX_STATIC_COLOR, " - "GLX_GRAY_SCALE, or GLX_STATIC_GRAY, indicating the desired X visual type. " - "Not all frame buffer configurations have an associated X visual. If GLX_DRAWABLE_TYPE is specified in attrib_list and the " - "mask that follows does not have GLX_WINDOW_BIT set, then this value is ignored. It is also ignored if " - "GLX_X_RENDERABLE is specified as False. RGBA rendering may be supported for visuals of type " - "GLX_TRUE_COLOR, GLX_DIRECT_COLOR, GLX_PSEUDO_COLOR, or GLX_STATIC_COLOR, " - "but color index rendering is only supported for visuals of type GLX_PSEUDO_COLOR or GLX_STATIC_COLOR " - "(i.e., single-channel visuals). The tokens GLX_GRAY_SCALE and GLX_STATIC_GRAY will " - "not match current OpenGL enabled visuals, but are included for future use." - "The default value for GLX_X_VISUAL_TYPE is GLX_DONT_CARE.", - GLX_DONT_CARE }, - { GLX_CONFIG_CAVEAT, "GLX_CONFIG_CAVEAT", - "Must be followed by one of GLX_NONE, GLX_SLOW_CONFIG, GLX_NON_CONFORMANT_CONFIG. " - "If GLX_NONE is specified, then only frame buffer configurations with " - "no caveats will be considered; if GLX_SLOW_CONFIG is specified, then only slow frame buffer configurations will be considered; if " - "GLX_NON_CONFORMANT_CONFIG is specified, then only nonconformant frame buffer configurations will be considered." - "The default value is GLX_DONT_CARE.", - GLX_DONT_CARE }, - { GLX_TRANSPARENT_TYPE, "GLX_TRANSPARENT_TYPE", - "Must be followed by one of GLX_NONE, GLX_TRANSPARENT_RGB, GLX_TRANSPARENT_INDEX. " - "If GLX_NONE is specified, then only opaque frame buffer configurations will be considered; " - "if GLX_TRANSPARENT_RGB is specified, then only transparent frame buffer configurations that support RGBA rendering will be considered; " - "if GLX_TRANSPARENT_INDEX is specified, then only transparent frame buffer configurations that support color index rendering will be considered." - "The default value is GLX_NONE.", - GLX_NONE }, - { GLX_TRANSPARENT_INDEX_VALUE, "GLX_TRANSPARENT_INDEX_VALUE", - "Must be followed by an integer value indicating the transparent index value; the value must be between 0 and the maximum " - "frame buffer value for indices. Only frame buffer configurations that use the " - "specified transparent index value will be considered. The default value is GLX_DONT_CARE. " - "This attribute is ignored unless GLX_TRANSPARENT_TYPE is included in attrib_list and specified as GLX_TRANSPARENT_INDEX.", - GLX_DONT_CARE }, - { GLX_TRANSPARENT_RED_VALUE, "GLX_TRANSPARENT_RED_VALUE", - "Must be followed by an integer value indicating the transparent red value; the value must be between 0 and the maximum " - "frame buffer value for red. Only frame buffer configurations that use the specified transparent red value will be considered. " - "The default value is GLX_DONT_CARE. This attribute is ignored unless GLX_TRANSPARENT_TYPE is included in " - "attrib_list and specified as GLX_TRANSPARENT_RGB.", - GLX_DONT_CARE }, - { GLX_TRANSPARENT_GREEN_VALUE, "GLX_TRANSPARENT_GREEN_VALUE", - "Must be followed by an integer value indicating the transparent green value; the value must be between 0 and the maximum " - "frame buffer value for green. Only frame buffer configurations that use the specified transparent green value will be considered." - "The default value is GLX_DONT_CARE. This attribute is " - "ignored unless GLX_TRANSPARENT_TYPE is included in attrib_list and specified as GLX_TRANSPARENT_RGB.", - GLX_DONT_CARE }, - { GLX_TRANSPARENT_BLUE_VALUE, "GLX_TRANSPARENT_BLUE_VALUE", - "Must be followed by an integer value indicating the transparent blue value; the value must be between 0 and the maximum " - "frame buffer value for blue. Only frame buffer configurations that use the specified transparent blue value will be considered." - "The default value is GLX_DONT_CARE. This attribute is ignored unless GLX_TRANSPARENT_TYPE is included in " - "attrib_list and specified as GLX_TRANSPARENT_RGB. ", - GLX_DONT_CARE }, - { GLX_TRANSPARENT_ALPHA_VALUE, "GLX_TRANSPARENT_ALPHA_VALUE", - "Must be followed by an integer value indicating the transparent alpha value; the value must be between 0 and the maximum " - "frame buffer value for alpha. Only frame buffer configurations that use the " - "specified transparent alpha value will be considered. The default value is GLX_DONT_CARE.", - GLX_DONT_CARE }, - { 0, NULL, NULL, -1 } -}; - -const char * get_attr_name( int val, int * pdef ) -{ - PPXATTS pat = &pxAtts[0]; - while( pat->name ) - { - if ( pat->attr == val ) { - *pdef = pat->def; - return pat->name; - } - pat++; - } - *pdef = -1; - return "VALUE NOT IN LIST"; -} - -#endif -// eof - RenderTexture.cpp diff --git a/simgear/screen/RenderTexture.h b/simgear/screen/RenderTexture.h deleted file mode 100644 index a1874fbc..00000000 --- a/simgear/screen/RenderTexture.h +++ /dev/null @@ -1,375 +0,0 @@ -//------------------------------------------------------------------------------ -// File : RenderTexture.h -//------------------------------------------------------------------------------ -// Copyright (c) 2002-2004 Mark J. Harris -//--------------------------------------------------------------------------- -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any -// damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any -// purpose, including commercial applications, and to alter it and -// redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you -// must not claim that you wrote the original software. If you use -// this software in a product, an acknowledgment in the product -// documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and -// must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -// ----------------------------------------------------------------------------- -// Credits: -// Original RenderTexture code: Mark J. Harris -// Original Render-to-depth-texture support: Thorsten Scheuermann -// Linux Copy-to-texture: Eric Werness -// OS X: Alexander Powell (someone please help) -// Various Bug Fixes: Daniel (Redge) Sperl -// Bill Baxter -// -// ----------------------------------------------------------------------------- -/** -* @file RenderTexture.h -* -* Interface definition for class RenderTexture. A multi-format render to -* texture wrapper. -*/ -#ifndef __RENDERTEXTURE2_HPP__ -#define __RENDERTEXTURE2_HPP__ - - -/* - * Changelog: - * - * Jan. 2005, Removed GLEW dependencies, Erik Hofman - * Mar. 2006, Added MAC OS X support, Alexander Powell - */ -#include - -#include - -#if defined( __APPLE__) -# include -#endif - -#if !defined( _WIN32 ) && !defined( __APPLE__ ) -# include -# include -#endif - -#include -#include - -/* The pixel format for the pbuffer is controlled by the mode string passed -* into the PBuffer constructor. This string can have the following attributes: -* -* To specify the pixel format, use the following syntax. -* = -* must match one of the following. -* -* r - r pixel format (for float buffer). -* rg - rg pixel format (for float buffer). -* rgb - rgb pixel format. 8 bit or 16/32 bit in float buffer mode -* rgba - same as "rgb alpha" string -* -* can either be a scalar--meaning the same bit depth for each -* channel-- or a 2-, 3-, 4-component vector matching the specified number of -* channels. Vector components should be comma separated. An optional 'f' -* suffix on the bit depth specifies float components. In this case -* must be either "32f" or "16f". If is empty, the default 8 bits per -* channel will be used. -* r=32f -* rg=16f -* rgb=8 -* rgb=5,6,5 -* -* The following other attributes are supported. -* -* depth=n - must have n-bit depth buffer, omit n for default (24 bits) -* stencil=n - must have n-bit stencil buffer, omit n for default (8 bits) -* samples=n - must support n-sample antialiasing (n can be 2 or 4) -* aux=n - must have n AUX buffers -* doublebuffer - must support double buffered rendering -* -* tex2D -* texRECT -* texCUBE - must support binding pbuffer as texture to specified target -* - binding the depth buffer is also supported by specifying -* depthTex2D -* depthTexRECT -* depthTexCUBE -* - Both depth and color texture binding, may be specified, but -* the targets must match! -* For example: "tex2D depthTex2D" or "texRECT depthTexRECT" -* -* rtt -* ctt - These mutually exclusive options specify the update method used -* for render textures that support texture binding. "rtt" -* indicates that render to texture will be used to update the -* texture. "ctt" indicates that copy to texture will be used -* (i.e. glCopyTexSubImage2D()). "rtt" is the default if neither is -* specified, and one of the "tex*" options above is. -* -* -*--------------------------------------------------------------------------- -* -* USAGE NOTES: -* -* * Texture Parameters: -* The default texture wrap mode is GL_CLAMP_TO_EDGE for all textures, and -* the default texture filtering modes (min and mag) are GL_NEAREST. -* To change these parameters, simply bind the RenderTexture (using the -* Bind() method), and set them the way you would for any GL texture object. -* The same goes for depth textures. -* -* * Enabling Mipmapping: -* This is similar to the texture parameters above. When "rtt" is specified -* in the mode string, "mipmap" must also be specified in order to enable -* a mipmapped pbuffer. Then, the mipmaps must be created by enabling the -* GL_SGIS_GENERATE_MIPMAP texture parameter in the same way as above, and -* the min filter mode must be set to a mipmap filter mode, as with any -* mipmapped texture object. -* -* * Enabling Anisotropic Filtering -* As with the texture parameters above, except as in the following code: -* glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max); -* glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, ); -*/ -class RenderTexture -{ -public: // enums - enum UpdateMode - { - RT_RENDER_TO_TEXTURE, - RT_COPY_TO_TEXTURE - }; - -public: // interface - // ctor / dtor - RenderTexture(const char *strMode="rgb tex2D"); - ~RenderTexture(); - - //! Call this once before use. Set bShare to true to share lists, textures, - //! and program objects between the render texture context and the - //! current active GL context. - bool Initialize(int width, int height, - bool shareObjects=true, - bool copyContext=false); - - // !Change the render texture format. - bool Reset(const char* strMode,...); - // !Change the size of the render texture. - bool Resize(int width, int height); - - // !Begin drawing to the texture. (i.e. use as "output" texture) - bool BeginCapture(); - // !Ends drawing to 'current', begins drawing to this RenderTexture - bool BeginCapture(RenderTexture* current); - // !End drawing to the texture. - bool EndCapture(); - - // !Bind the texture to the active texture unit for use as an "input" texture - void Bind() const; - - // !Bind the depth texture to the active texture unit for use as an "input" texture - void BindDepth() const; - - // !Associate the RTT texture with 'iBuffer' (default is WGL_FRONT_LEFT_ARB) - bool BindBuffer( int iBuffer ); - - //! Enables the texture target appropriate for this render texture. - void EnableTextureTarget() const - { if (_bInitialized) glEnable(_iTextureTarget); } - //! Disables the texture target appropriate for this render texture. - void DisableTextureTarget() const - { if (_bInitialized) glDisable(_iTextureTarget); } - - //! Returns the texture ID. Useful in Cg applications. - unsigned int GetTextureID() const { return _iTextureID; } - //! Returns the depth texture ID. Useful in Cg applications. - unsigned int GetDepthTextureID() const { return _iDepthTextureID; } - //! Returns the texture target this texture is bound to. - unsigned int GetTextureTarget() const { return _iTextureTarget; } - //! Conversion operator allows RenderTexture to be passed to GL calls - operator unsigned int()const{return _iTextureID;} - - //! Returns the width of the offscreen buffer. - int GetWidth() const { return _iWidth; } - //! Returns the width of the offscreen buffer. - int GetHeight() const { return _iHeight; } - //! Returns the maximum S texture coordinate. - int GetMaxS() const { return IsRectangleTexture() ? _iWidth : 1; } - //! Returns the maximum T texture coordinate. - int GetMaxT() const { return IsRectangleTexture() ? _iHeight : 1; } - - //! Returns the number of red bits allocated. - int GetRedBits() const { return _iNumColorBits[0]; } - //! Returns the number of green bits allocated. - int GetGreenBits() const { return _iNumColorBits[1]; } - //! Returns the number of blue bits allocated. - int GetBlueBits() const { return _iNumColorBits[2]; } - //! Returns the number of alpha bits allocated. - int GetAlphaBits() const { return _iNumColorBits[3]; } - - //! Returns the number of depth bits allocated. - int GetDepthBits() const { return _iNumDepthBits; } - //! Returns the number of stencil bits allocated. - int GetStencilBits() const { return _iNumStencilBits; } - - //! True if this RenderTexture has been properly initialized. - bool IsInitialized() const { return _bInitialized; } - //! True if this is a texture and not just an offscreen buffer. - bool IsTexture() const { return _bIsTexture; } - //! True if this is a depth texture and not just an offscreen buffer. - bool IsDepthTexture() const { return _bIsDepthTexture; } - //! True if this is a floating point buffer / texture. - bool IsFloatTexture() const { return _bFloat; } - //! True if this is a double-buffered pbuffer - bool IsDoubleBuffered() const { return _bDoubleBuffered; } - //! True if this texture has non-power-of-two dimensions. - bool IsRectangleTexture() const { return _bRectangle; } - //! True if this texture has non-power-of-two dimensions. - //! True if this pbuffer has a depth buffer. - bool HasDepth() const { return (_iNumDepthBits > 0); } - //! True if this pbuffer has a stencil buffer. - bool HasStencil() const { return (_iNumStencilBits > 0); } - //! True if this texture has mipmaps. - bool IsMipmapped() const { return _bMipmap; } - - /** - * @fn IsPowerOfTwo(int n) - * @brief Returns true if /param n is an integer power of 2. - * - * Taken from Steve Baker's Cute Code Collection. - * http://www.sjbaker.org/steve/software/cute_code.html - */ - static bool IsPowerOfTwo(int n) { return ((n&(n-1))==0); } - - - ///////////////////////////////////////////////////////////////////////// - // This is the deprecated (old) interface. It will likely be removed - // in a future version, so it is recommended that you transition to the - // new mode-string-based interface. - RenderTexture(int width, int height, - bool bIsTexture = true, - bool bIsDepthTexture = false); - // - // Call this once before use. Set bShare to true to share lists, - // textures, and program objects between the render texture context - // and the current active GL context. [deprecated] - bool Initialize(bool bShare = true, - bool bDepth = false, - bool bStencil = false, - bool bMipmap = false, - bool bAnisoFilter = false, - unsigned int iRBits = 8, - unsigned int iGBits = 8, - unsigned int iBBits = 8, - unsigned int iABits = 8, -// Only Win32 has RT now, so only make it default there -#ifdef _WIN32 - UpdateMode updateMode = RT_RENDER_TO_TEXTURE -#else - UpdateMode updateMode = RT_COPY_TO_TEXTURE -#endif - ); - // !Change the render texture resolution. [deprecated] - bool Reset(int iWidth, int iHeight); - // - ///////////////////////////////////////////////////////////////////////// - - -protected: // methods - bool _Invalidate(); - - typedef std::pair KeyVal; - - void _ParseModeString(const char *modeString, - std::vector &pixelFormatAttribs, - std::vector &pbufferAttribs); - - std::vector _ParseBitVector(std::string bitVector); - KeyVal _GetKeyValuePair(std::string token); - - - bool _VerifyExtensions(); - bool _InitializeTextures(); - - void _MaybeCopyBuffer(); - bool _ReleaseBoundBuffers(); - bool _MakeCurrent(); - bool _BindDepthBuffer( ) const; - -protected: // data - int _iWidth; // width of the pbuffer - int _iHeight; // height of the pbuffer - - bool _bIsTexture; - bool _bIsDepthTexture; - bool _bHasARBDepthTexture; // [Redge] - - UpdateMode _eUpdateMode; - - bool _bInitialized; - - unsigned int _iNumAuxBuffers; - bool _bIsBufferBound; - int _iCurrentBoundBuffer; - - unsigned int _iNumComponents; - unsigned int _iNumColorBits[4]; - unsigned int _iNumDepthBits; - unsigned int _iNumStencilBits; - - - bool _bFloat; - bool _bDoubleBuffered; - bool _bPowerOf2; - bool _bRectangle; - bool _bMipmap; - - bool _bShareObjects; - bool _bCopyContext; - -#ifdef _WIN32 - HDC _hDC; // Handle to a device context. - HGLRC _hGLContext; // Handle to a GL context. - HPBUFFERARB _hPBuffer; // Handle to a pbuffer. - - HDC _hPreviousDC; - HGLRC _hPreviousContext; -#elif defined( __MACH__ ) - CGLContextObj _hGLContext; - CGLPBufferObj _hPBuffer; - - CGLContextObj _hPreviousContext; -#else - Display *_pDisplay; - GLXContext _hGLContext; - GLXPbuffer _hPBuffer; - - GLXDrawable _hPreviousDrawable; - GLXContext _hPreviousContext; -#endif - - // Texture stuff - GLenum _iTextureTarget; - GLuint _iTextureID; - GLuint _iDepthTextureID; - - unsigned short* _pPoorDepthTexture; // [Redge] - - std::vector _pixelFormatAttribs; - std::vector _pbufferAttribs; - -private: - // Using these could lead to some odd behavior - RenderTexture(const RenderTexture&); - RenderTexture& operator=(const RenderTexture&); -}; - -#endif //__RENDERTEXTURE2_HPP__ diff --git a/simgear/screen/TestRenderTexture.cpp b/simgear/screen/TestRenderTexture.cpp deleted file mode 100644 index 615c2291..00000000 --- a/simgear/screen/TestRenderTexture.cpp +++ /dev/null @@ -1,378 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef HAVE_WINDOWS_H -# include -#endif - -#include - -#include - -#ifdef __APPLE__ -# include -#else -# include -#endif - -#include -#include -#include - -#include -#include -#include - -// DEBUG - add a lot of noise -//#ifndef _DEBUG -//#define _DEBUG -//#endif - -#if defined (_DEBUG) -const char * get_attr_name( int val, int * pdef ); -#define dbg_printf printf -#else -#if defined (__GNUC__) -#define dbg_printf(format,args...) ((void)0) -#else // defined (__GNUC__) -#define dbg_printf -#endif // defined (__GNUC__) -#endif // defined (_DEBUG) - - -void Reshape(int w, int h); - -GLuint iTextureProgram = 0; -GLuint iPassThroughProgram = 0; - -RenderTexture *rt = NULL; - -float rectAngle = 0; -float torusAngle = 0; -bool bTorusMotion = true; -bool bRectMotion = true; -bool bShowDepthTexture = false; - -static const char *g_modeTestStrings[] = -{ - "rgb tex2D", - "rgba tex2D depthTex2D", - "rgba=8 depthTexRECT ctt", - "rgba samples=4 tex2D ctt", - "rgba=8 tex2D mipmap", - "rgb=5,6,5 tex2D", - "rgba=16f texRECT", - "rgba=32f texRECT depthTexRECT", - "rgba=16f texRECT depthTexRECT ctt", - "r=32f texRECT depth ctt", - "rgb double tex2D", - "r=32f texRECT ctt aux=4" -}; - -static int g_numModeTestStrings = sizeof(g_modeTestStrings) / sizeof(char*); -static int g_currentString = 0; - -//--------------------------------------------------------------------------- -// Function : PrintGLerror -// Description : -//--------------------------------------------------------------------------- -void PrintGLerror( const char *msg ) -{ - GLenum errCode; - const GLubyte *errStr; - - if ((errCode = glGetError()) != GL_NO_ERROR) - { - errStr = gluErrorString(errCode); - fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg); - } -} - -//--------------------------------------------------------------------------- -// Function : CreateRenderTexture -// Description : -//--------------------------------------------------------------------------- -RenderTexture* CreateRenderTexture(const char *initstr) -{ - printf("\nCreating with init string: \"%s\"\n", initstr); - - int texWidth = 256, texHeight = 256; - - // Test deprecated interface - //RenderTexture *rt2 = new RenderTexture(texWidth, texHeight); - //if (!rt2->Initialize(true,false,false,false,false,8,8,8,0)) - - RenderTexture *rt2 = new RenderTexture(); - rt2->Reset(initstr); - if (!rt2->Initialize(texWidth, texHeight)) - { - fprintf(stderr, "RenderTexture Initialization failed!\n"); - } - else - { - printf("RenderTexture Initialization done.\n"); - } - - // for shadow mapping we still have to bind it and set the correct - // texture parameters using the SGI_shadow or ARB_shadow extension - // setup the rendering context for the RenderTexture - if (rt2->BeginCapture()) - { - Reshape(texWidth, texHeight); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - glClearColor(0.2, 0.2, 0.2, 1); - rt2->EndCapture(); - } - - // enable linear filtering if available - if (rt2->IsTexture() || rt2->IsDepthTexture()) - { - if (rt2->IsMipmapped()) - { - // Enable trilinear filtering so we can see the mipmapping - if (rt2->IsTexture()) - { - rt2->Bind(); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_GENERATE_MIPMAP_SGIS, GL_TRUE); - } - - if (rt2->IsDepthTexture()) - { - rt2->BindDepth(); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_GENERATE_MIPMAP_SGIS, GL_TRUE); - } - } - else if (!(rt2->IsRectangleTexture() || rt2->IsFloatTexture())) - { - if (rt2->IsTexture()) - { - rt2->Bind(); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } - - if (rt2->IsDepthTexture()) - { - rt2->BindDepth(); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(rt2->GetTextureTarget(), - GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } - } - } - - if (rt2->IsDepthTexture()) - { - fprintf(stderr, - "\nPress the spacebar to toggle color / depth textures.\n"); - if (!rt2->IsTexture()) - bShowDepthTexture = true; - } - else - { - if (rt2->IsTexture()) - bShowDepthTexture = false; - } - - PrintGLerror("Create"); - return rt2; -} - -//--------------------------------------------------------------------------- -// Function : DestroyRenderTexture -// Description : -//--------------------------------------------------------------------------- -void DestroyRenderTexture(RenderTexture *rt2) -{ - delete rt2; -} - -//--------------------------------------------------------------------------- -// Function : Keyboard -// Description : -//--------------------------------------------------------------------------- -void Keyboard(unsigned char key, int x, int y) -{ - switch(key) - { - case 27: - case 'q': - exit(0); - break; - case ' ': - bShowDepthTexture = !bShowDepthTexture; - break; - case 13: - ++g_currentString %= g_numModeTestStrings; - dbg_printf("Changed to #%d = [%s]\n", g_currentString, g_modeTestStrings[g_currentString]); - DestroyRenderTexture(rt); - rt = CreateRenderTexture(g_modeTestStrings[g_currentString]); - break; - case 't': - bTorusMotion = !bTorusMotion; - break; - case 'r': - bRectMotion = !bRectMotion; - break; - default: - return; - } -} - -//--------------------------------------------------------------------------- -// Function : Idle -// Description : -//--------------------------------------------------------------------------- -void Idle() -{ - // make sure we don't try to display nonexistent textures - if (!rt->IsDepthTexture()) - bShowDepthTexture = false; - - if (bRectMotion) rectAngle += 1; - if (bTorusMotion) torusAngle += 1; - glutPostRedisplay(); -} - -//--------------------------------------------------------------------------- -// Function : Reshape -// Description : -//--------------------------------------------------------------------------- -void Reshape(int w, int h) -{ - if (h == 0) h = 1; - - glViewport(0, 0, w, h); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1, 5.0); -} - -//--------------------------------------------------------------------------- -// Function : Display -// Description : -//--------------------------------------------------------------------------- -void _Display() -{ - if (rt->IsInitialized() && rt->BeginCapture()) - { - if (rt->IsDoubleBuffered()) glDrawBuffer(GL_BACK); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - glRotatef(torusAngle, 1, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glColor3f(1,1,0); - - glutSolidTorus(0.25, 1, 32, 64); - - glPopMatrix(); - PrintGLerror("RT Update"); - - rt->EndCapture(); - } - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glColor3f(1, 1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glRotatef(rectAngle / 10, 0, 1, 0); - - if(bShowDepthTexture && rt->IsDepthTexture()) - rt->BindDepth(); - else if (rt->IsTexture()) { - rt->Bind(); - } - - rt->EnableTextureTarget(); - - int maxS = rt->GetMaxS(); - int maxT = rt->GetMaxT(); - - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(-1, -1); - glTexCoord2f(maxS, 0); glVertex2f( 1, -1); - glTexCoord2f(maxS, maxT); glVertex2f( 1, 1); - glTexCoord2f(0, maxT); glVertex2f(-1, 1); - glEnd(); - - rt->DisableTextureTarget(); - - glPopMatrix(); - - PrintGLerror("display"); - glutSwapBuffers(); -} - - - - -//--------------------------------------------------------------------------- -// Function : main -// Description : -//--------------------------------------------------------------------------- -int main(int argc, char *argv[]) -{ - int argn = argc; - glutInit(&argn, argv); - glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); - glutInitWindowPosition(50, 50); - glutInitWindowSize(512, 512); - glutCreateWindow("TestRenderTexture"); - - glutDisplayFunc(_Display); - glutIdleFunc(Idle); - glutReshapeFunc(Reshape); - glutKeyboardFunc(Keyboard); - - Reshape(512, 512); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(0, 0, 2, 0, 0, 0, 0, 1, 0); - glDisable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_DEPTH_TEST); - glClearColor(0.4, 0.6, 0.8, 1); - - - rt = CreateRenderTexture(g_modeTestStrings[g_currentString]); - - if (rt->IsInitialized() && rt->BeginCapture()) { - rt->EndCapture(); - dbg_printf("Torus should also be shown.\n"); - } else { - dbg_printf("No Torus init = %s\n", (rt->IsInitialized() ? "ok" : "NOT INITIALISED")); - } - - printf("Press Enter to change RenderTexture parameters.\n" - "Press 'r' to toggle the rectangle's motion.\n" - "Press 't' to toggle the torus' motion.\n"); - - - glutMainLoop(); - return 0; -} diff --git a/simgear/screen/extensions.cxx b/simgear/screen/extensions.cxx index 130673c5..8ef03a6a 100644 --- a/simgear/screen/extensions.cxx +++ b/simgear/screen/extensions.cxx @@ -22,13 +22,11 @@ * */ -#include #include "extensions.hxx" -#include -#if !defined(WIN32) -# include -#endif + +#include +#include // for glGetString bool SGSearchExtensionsString(const char *extString, const char *extName) { // Returns GL_TRUE if the *extName string appears in the *extString string, @@ -65,89 +63,3 @@ bool SGIsOpenGLExtensionSupported(const char *extName) { return SGSearchExtensionsString((const char *)glGetString(GL_EXTENSIONS),extName); } - -#ifdef __APPLE__ - -#include - -void* macosxGetGLProcAddress(const char *func) { - - /* We may want to cache the bundleRef at some point */ - static CFBundleRef bundle = 0; - - if (!bundle) { - - CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, - CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true); - - bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL); - CFRelease (bundleURL); - } - - if (!bundle) - return 0; - - CFStringRef functionName = CFStringCreateWithCString - (kCFAllocatorDefault, func, kCFStringEncodingASCII); - - void *function; - - function = CFBundleGetFunctionPointerForName (bundle, functionName); - - CFRelease (functionName); - - return function; -} - -#elif !defined( WIN32 ) - -void *SGGetGLProcAddress(const char *func) { - static void *libHandle = NULL; - static void *(*glXGetProcAddressPtr)(const GLubyte*) = 0; - void *fptr = NULL; - - /* - * Clear the error buffer - */ - dlerror(); - - /* - * Since libGL must be linked to the binary we run on, this is the - * right handle. That 'current binary' handle also avoids conflicts which - * arise from linking with a different libGL at link time an than later - * use the standard libGL at runtime ... - */ - if (libHandle == NULL) { - libHandle = dlopen(NULL, RTLD_LAZY); - - if (!libHandle) { - const char *error = dlerror(); - if (error) { - SG_LOG(SG_GENERAL, SG_INFO, error); - return 0; - } - } - - void* symbol = dlsym(libHandle, "glXGetProcAddress"); - if (!symbol) - symbol = dlsym(libHandle, "glXGetProcAddressARB"); - glXGetProcAddressPtr = (void *(*)(const GLubyte*)) symbol; - } - - // First try the glx api function for that - if (glXGetProcAddressPtr) { - fptr = glXGetProcAddressPtr((const GLubyte*)func); - - } else if (libHandle != NULL) { - fptr = dlsym(libHandle, func); - - const char *error = dlerror(); - if (error) - SG_LOG(SG_GENERAL, SG_INFO, error); - } - - return fptr; -} - -#endif - diff --git a/simgear/screen/extensions.hxx b/simgear/screen/extensions.hxx index e1871068..ab5a929f 100644 --- a/simgear/screen/extensions.hxx +++ b/simgear/screen/extensions.hxx @@ -24,945 +24,11 @@ #ifndef __SG_EXTENSIONS_HXX #define __SG_EXTENSIONS_HXX 1 -#ifdef WIN32 -# include -#endif #include -#include - -#if !defined(__APPLE__) && !defined(WIN32) -# include -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif - bool SGSearchExtensionsString(const char *extString, const char *extName); bool SGIsOpenGLExtensionSupported(const char *extName); -#ifdef __APPLE__ - // don't use an inline function for symbol lookup, since it is too big - void* macosxGetGLProcAddress(const char *func); - -#elif !defined( WIN32 ) - - void *SGGetGLProcAddress(const char *func); - -#endif - -inline void (*SGLookupFunction(const char *func))() -{ -#if defined( WIN32 ) - return (void (*)()) wglGetProcAddress(func); - -#elif defined( __APPLE__ ) - return (void (*)()) macosxGetGLProcAddress(func); - -#else // UNIX, default - return (void (*)()) SGGetGLProcAddress(func); -#endif -} - -/* - * OpenGL 1.2 and 1.3 enumerants - */ - -#ifndef GL_VERSION_1_2 -#define GL_CLAMP_TO_EDGE 0x812F -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_BLEND_EQUATION 0x8009 -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_FUNC_ADD 0x8006 -#define GL_FUNC_SUBTRACT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT 0x800B -#define GL_BLEND_COLOR 0x8005 -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#endif - -typedef void (APIENTRY * glBlendEquationProc) (GLenum mode ); -typedef void (APIENTRY * glBlendColorProc) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); - - -/* OpenGL extension declarations */ - -/* - * glPointParameterf and glPointParameterfv - */ -#ifndef GL_EXT_point_parameters -#define GL_EXT_point_parameters 1 -#define GL_POINT_SIZE_MIN_EXT 0x8126 -#define GL_DISTANCE_ATTENUATION_EXT 0x8129 -#endif - -#ifndef GL_ARB_point_parameters -#define GL_ARB_point_parameters 1 -#define GL_POINT_SIZE_MIN_ARB 0x8126 -#define GL_DISTANCE_ATTENUATION_ARB 0x8129 -#endif - -typedef void (APIENTRY * glPointParameterfProc)(GLenum pname, GLfloat param); -typedef void (APIENTRY * glPointParameterfvProc)(GLenum pname, const GLfloat *params); - -/* - * glActiveTextureARB - */ - -#ifndef GL_ARB_multitexture -#define GL_ARB_multitexture 1 -#define GL_TEXTURE0_ARB 0x84C0 -#define GL_TEXTURE1_ARB 0x84C1 -#define GL_TEXTURE2_ARB 0x84C2 -#define GL_TEXTURE3_ARB 0x84C3 -#define GL_TEXTURE4_ARB 0x84C4 -#define GL_TEXTURE5_ARB 0x84C5 -#define GL_TEXTURE6_ARB 0x84C6 -#define GL_TEXTURE7_ARB 0x84C7 -#define GL_TEXTURE8_ARB 0x84C8 -#define GL_TEXTURE9_ARB 0x84C9 -#define GL_TEXTURE10_ARB 0x84CA -#define GL_TEXTURE11_ARB 0x84CB -#define GL_TEXTURE12_ARB 0x84CC -#define GL_TEXTURE13_ARB 0x84CD -#define GL_TEXTURE14_ARB 0x84CE -#define GL_TEXTURE15_ARB 0x84CF -#define GL_TEXTURE16_ARB 0x84D0 -#define GL_TEXTURE17_ARB 0x84D1 -#define GL_TEXTURE18_ARB 0x84D2 -#define GL_TEXTURE19_ARB 0x84D3 -#define GL_TEXTURE20_ARB 0x84D4 -#define GL_TEXTURE21_ARB 0x84D5 -#define GL_TEXTURE22_ARB 0x84D6 -#define GL_TEXTURE23_ARB 0x84D7 -#define GL_TEXTURE24_ARB 0x84D8 -#define GL_TEXTURE25_ARB 0x84D9 -#define GL_TEXTURE26_ARB 0x84DA -#define GL_TEXTURE27_ARB 0x84DB -#define GL_TEXTURE28_ARB 0x84DC -#define GL_TEXTURE29_ARB 0x84DD -#define GL_TEXTURE30_ARB 0x84DE -#define GL_TEXTURE31_ARB 0x84DF -#define GL_ACTIVE_TEXTURE_ARB 0x84E0 -#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 -#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 -#endif - -typedef void (APIENTRY * glActiveTextureProc)(GLenum texture); -typedef void (APIENTRY * glClientActiveTextureProc)(GLenum texture); - -/* - * GL_EXT_separate_specular_color - */ - -#ifndef GL_LIGHT_MODEL_COLOR_CONTROL -#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 -#define GL_SINGLE_COLOR 0x81F9 -#define GL_SEPARATE_SPECULAR_COLOR 0x81FA -#endif - -/* - * GL_ARB_texture_cube_map - */ - -#ifndef GL_ARB_texture_cube_map -#define GL_ARB_texture_cube_map 1 -#define GL_NORMAL_MAP_ARB 0x8511 -#define GL_REFLECTION_MAP_ARB 0x8512 -#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C -#endif - -/* - * GL_ARB_texture_env_combine - */ - -#ifndef GL_ARB_texture_env_combine -#define GL_ARB_texture_env_combine 1 -#define GL_COMBINE_ARB 0x8570 -#define GL_COMBINE_RGB_ARB 0x8571 -#define GL_COMBINE_ALPHA_ARB 0x8572 -#define GL_RGB_SCALE_ARB 0x8573 -#define GL_ADD_SIGNED_ARB 0x8574 -#define GL_INTERPOLATE_ARB 0x8575 -#define GL_SUBTRACT_ARB 0x84E7 -#define GL_CONSTANT_ARB 0x8576 -#define GL_PRIMARY_COLOR_ARB 0x8577 -#define GL_PREVIOUS_ARB 0x8578 -#define GL_SOURCE0_RGB_ARB 0x8580 -#define GL_SOURCE1_RGB_ARB 0x8581 -#define GL_SOURCE2_RGB_ARB 0x8582 -#define GL_SOURCE0_ALPHA_ARB 0x8588 -#define GL_SOURCE1_ALPHA_ARB 0x8589 -#define GL_SOURCE2_ALPHA_ARB 0x858A -#define GL_OPERAND0_RGB_ARB 0x8590 -#define GL_OPERAND1_RGB_ARB 0x8591 -#define GL_OPERAND2_RGB_ARB 0x8592 -#define GL_OPERAND0_ALPHA_ARB 0x8598 -#define GL_OPERAND1_ALPHA_ARB 0x8599 -#define GL_OPERAND2_ALPHA_ARB 0x859A -#endif - -/* - * GL_ARB_texture_env_dot3 - */ - -#ifndef GL_ARB_texture_env_dot3 -#define GL_ARB_texture_env_dot3 1 -#define GL_DOT3_RGB_ARB 0x86AE -#define GL_DOT3_RGBA_ARB 0x86AF -#endif - -/* - * ARB_depth_texture - */ -#ifndef GL_ARB_depth_texture -#define GL_ARB_depth_texture 1 -#define GL_DEPTH_COMPONENT16_ARB 0x81A5 -#define GL_DEPTH_COMPONENT24_ARB 0x81A6 -#define GL_DEPTH_COMPONENT32_ARB 0x81A7 -#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A -#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B -#endif - -/* - * ARB_multisample - */ -#ifndef GL_ARB_multisample -#define GL_ARB_multisample 1 -#define GL_MULTISAMPLE_ARB 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F -#define GL_SAMPLE_COVERAGE_ARB 0x80A0 -#define GL_SAMPLE_BUFFERS_ARB 0x80A8 -#define GL_SAMPLES_ARB 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB -#define GL_MULTISAMPLE_BIT_ARB 0x20000000 -#define GL_DOUBLEBUFFER 0x0C32 -#define GL_AUX_BUFFERS 0x0C00 -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 -#endif - -#ifndef GL_SGIS_generate_mipmap -#define GL_SGIS_generate_mipmap 1 -#define GL_GENERATE_MIPMAP_SGIS 0x8191 -#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 -#endif - -/* WGL spcific OpenGL extenstions */ -#ifdef WIN32 - -/* - * WGL_ARB_extensions_string - */ -#ifndef WGL_ARB_extensions_string -#define WGL_ARB_extensions_string 1 -typedef const char * (APIENTRY * wglGetExtensionsStringARBProc) (HDC hDC); -#endif - -/* - * WGL_ARB_pbuffer - */ -#ifndef WGL_ARB_pbuffer -#define WGL_ARB_pbuffer 1 -#define WGL_DRAW_TO_PBUFFER_ARB 0x202D -#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E -#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F -#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 -#define WGL_PBUFFER_LARGEST_ARB 0x2033 -#define WGL_PBUFFER_WIDTH_ARB 0x2034 -#define WGL_PBUFFER_HEIGHT_ARB 0x2035 -#define WGL_PBUFFER_LOST_ARB 0x2036 -DECLARE_HANDLE(HPBUFFERARB); -typedef HPBUFFERARB (APIENTRY * wglCreatePbufferARBProc) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); -typedef HDC (APIENTRY * wglGetPbufferDCARBProc) (HPBUFFERARB hPbuffer); -typedef int (APIENTRY * wglReleasePbufferDCARBProc) (HPBUFFERARB hPbuffer, HDC hDC); -typedef BOOL (APIENTRY * wglDestroyPbufferARBProc) (HPBUFFERARB hPbuffer); -typedef BOOL (APIENTRY * wglQueryPbufferARBProc) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); -#endif - - -/* - * ARB_pixel_format - */ -#ifndef WGL_ARB_pixel_format -#define WGL_ARB_pixel_format 1 -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B -typedef BOOL (APIENTRY * wglGetPixelFormatAttribivARBProc) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); -typedef BOOL (APIENTRY * wglGetPixelFormatAttribfvARBProc) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); -typedef BOOL (APIENTRY * wglChoosePixelFormatARBProc) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -#endif - -/* - * ARB_render_texture - */ -#ifndef WGL_ARB_render_texture -#define WGL_ARB_render_texture 1 - -#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 -#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 -#define WGL_TEXTURE_FORMAT_ARB 0x2072 -#define WGL_TEXTURE_TARGET_ARB 0x2073 -#define WGL_MIPMAP_TEXTURE_ARB 0x2074 -#define WGL_TEXTURE_RGB_ARB 0x2075 -#define WGL_TEXTURE_RGBA_ARB 0x2076 -#define WGL_NO_TEXTURE_ARB 0x2077 -#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 -#define WGL_TEXTURE_1D_ARB 0x2079 -#define WGL_TEXTURE_2D_ARB 0x207A -#define WGL_NO_TEXTURE_ARB 0x2077 -#define WGL_MIPMAP_LEVEL_ARB 0x207B -#define WGL_CUBE_MAP_FACE_ARB 0x207C -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 -#define WGL_FRONT_LEFT_ARB 0x2083 -#define WGL_FRONT_RIGHT_ARB 0x2084 -#define WGL_BACK_LEFT_ARB 0x2085 -#define WGL_BACK_RIGHT_ARB 0x2086 -#define WGL_AUX0_ARB 0x2087 -#define WGL_AUX1_ARB 0x2088 -#define WGL_AUX2_ARB 0x2089 -#define WGL_AUX3_ARB 0x208A -#define WGL_AUX4_ARB 0x208B -#define WGL_AUX5_ARB 0x208C -#define WGL_AUX6_ARB 0x208D -#define WGL_AUX7_ARB 0x208E -#define WGL_AUX8_ARB 0x208F -#define WGL_AUX9_ARB 0x2090 -typedef BOOL (APIENTRY * wglBindTexImageARBProc) (HPBUFFERARB hPbuffer, int iBuffer); -typedef BOOL (APIENTRY * wglReleaseTexImageARBProc) (HPBUFFERARB hPbuffer, int iBuffer); -typedef BOOL (APIENTRY * wglSetPbufferAttribARBProc) (HPBUFFERARB hPbuffer, const int *piAttribList); -#endif - -#elif !defined(__APPLE__) /* !WIN32 */ - -/* GLX pcific OpenGL extenstions */ -#include - -#ifndef GLX_ARB_multisample -#define GLX_ARB_multisample1 -#define GLX_SAMPLE_BUFFERS_ARB 100001 -#define GLX_SAMPLES_ARB 100000 -#endif - -#ifndef GLX_SGIX_pbuffer -#define GLX_SGIX_pbuffer 1 -#define GLX_DOUBLEBUFFER 5 -#define GLX_AUX_BUFFERS 0x00000010 -#endif - -#ifndef GLXPbuffer -# ifdef GLXPbufferSGIX -# define GLXPbuffer GLXPbufferSGIX -# endif -#endif -#ifndef GLXFBConfig -# ifdef GLXFBConfigSGIX -# define GLXFBConfig GLXFBConfigSGIX -# endif -#endif - -typedef GLXFBConfig *(*glXChooseFBConfigProc) (Display *dpy, int screen, int *attribList, int *nitems); -typedef GLXPbuffer (*glXCreateGLXPbufferProc) (Display *dpy, GLXFBConfig config, unsigned int width, unsigned int height, int *attrib_list); -typedef GLXPbuffer (*glXCreatePbufferProc) (Display *dpy, GLXFBConfig config, int *attrib_list); -typedef XVisualInfo *(*glXGetVisualFromFBConfigProc) (Display *dpy, GLXFBConfig config); -typedef GLXContext (*glXCreateContextWithConfigProc) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); -typedef GLXContext (*glXCreateContextProc) (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); -typedef void (*glXDestroyPbufferProc) (Display *dpy, GLXPbuffer pbuf); -typedef int (*glXQueryGLXPbufferSGIXProc) (Display *, GLXPbuffer, int, unsigned int *); -typedef void (*glXQueryDrawableProc) (Display *, GLXDrawable, int, unsigned int *); -#endif /* WIN32 */ - - -/* NVIDIA specific extension */ - -/* - * NV_texture_rectangle - */ - -#ifndef GL_NV_texture_rectangle -#define GL_NV_texture_rectangle 1 -#define GL_TEXTURE_RECTANGLE_NV 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 -#endif - -/* - * NV_texture_rectangle - */ - -#ifndef GL_EXT_texture_rectangle -#define GL_EXT_texture_rectangle 1 -#define GL_TEXTURE_RECTANGLE_EXT 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE_EXT 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE_EXT 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT 0x84F8 -#endif - -/* - * WGL_NV_texture_rectangle - */ - -#ifndef WGL_NV_texture_rectangle -#define WGL_NV_texture_rectangle 1 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 -#define WGL_TEXTURE_RECTANGLE_NV 0x20A2 -#endif - -/* - * NV_render_depth_texture - */ - -#ifndef WGL_NV_render_depth_texture -#define WGL_NV_render_depth_texture 1 -#define WGL_NO_TEXTURE_ARB 0x2077 -#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 -#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 -#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 -#define WGL_DEPTH_COMPONENT_NV 0x20A7 -#endif - -/* - * NV_float_buffer - */ -#ifndef GL_NV_float_buffer -#define GL_NV_float_buffer 1 -#define GL_FLOAT_R_NV 0x8880 -#define GL_FLOAT_RG_NV 0x8881 -#define GL_FLOAT_RGB_NV 0x8882 -#define GL_FLOAT_RGBA_NV 0x8883 -#define GL_FLOAT_R16_NV 0x8884 -#define GL_FLOAT_R32_NV 0x8885 -#define GL_FLOAT_RG16_NV 0x8886 -#define GL_FLOAT_RG32_NV 0x8887 -#define GL_FLOAT_RGB16_NV 0x8888 -#define GL_FLOAT_RGB32_NV 0x8889 -#define GL_FLOAT_RGBA16_NV 0x888A -#define GL_FLOAT_RGBA32_NV 0x888B -#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C -#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D -#define GL_FLOAT_RGBA_MODE_NV 0x888E -#endif -#ifndef GLX_NV_float_buffer -#define GLX_NV_float_buffer 1 -#define GLX_FLOAT_COMPONENTS_NV 0x20B0 -#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 -#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 -#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 -#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 -#define GLX_TEXTURE_FLOAT_R_NV 0x20B5 -#define GLX_TEXTURE_FLOAT_RG_NV 0x20B6 -#define GLX_TEXTURE_FLOAT_RGB_NV 0x20B7 -#define GLX_TEXTURE_FLOAT_RGBA_NV 0x20B8 -#endif -#ifndef WGL_NV_float_buffer -#define WGL_NV_float_buffer 1 -#define WGL_FLOAT_COMPONENTS_NV 0x20B0 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 -#define WGL_TEXTURE_FLOAT_R_NV 0x20B5 -#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 -#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 -#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 -#endif - - -/* ATI specific extension */ - -/* - * ATI_pixel_format_float - */ -#ifndef WGL_ATI_pixel_format_float -#define WGL_ATI_pixel_format_float 1 -#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 -#define GL_RGBA_FLOAT_MODE_ATI 0x8820 -#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 -#endif - -/* - * ATI_texture_float - */ -#ifndef GL_ATI_texture_float -#define GL_ATI_texture_float 1 -#define GL_RGBA_FLOAT32_ATI 0x8814 -#define GL_RGB_FLOAT32_ATI 0x8815 -#define GL_ALPHA_FLOAT32_ATI 0x8816 -#define GL_INTENSITY_FLOAT32_ATI 0x8817 -#define GL_LUMINANCE_FLOAT32_ATI 0x8818 -#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 -#define GL_RGBA_FLOAT16_ATI 0x881A -#define GL_RGB_FLOAT16_ATI 0x881B -#define GL_ALPHA_FLOAT16_ATI 0x881C -#define GL_INTENSITY_FLOAT16_ATI 0x881D -#define GL_LUMINANCE_FLOAT16_ATI 0x881E -#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F -#endif - -/* - * ARB point sprite - */ -#ifndef GL_ARB_point_sprite -#define GL_ARB_point_sprite 1 -#define GL_POINT_SPRITE_ARB 0x8861 -#define GL_COORD_REPLACE_ARB 0x8862 -#endif - -#ifndef GL_NV_point_sprite -#define GL_NV_point_sprite 1 -#define GL_POINT_SPRITE_NV 0x8861 -#define GL_COORD_REPLACE_NV 0x8862 -#define GL_POINT_SPRITE_R_MODE_NV 0x8863 -#endif - -#ifndef GL_VERSION_2_0 -#define GL_POINT_SPRITE 0x8861 -#define GL_COORD_REPLACE 0x8862 -#endif - -/* - * ARB_vertex_program - */ -#ifndef GL_ARB_vertex_program -#define GL_ARB_vertex_program 1 -#define GL_COLOR_SUM_ARB 0x8458 -#define GL_VERTEX_PROGRAM_ARB 0x8620 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 -#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 -#define GL_PROGRAM_LENGTH_ARB 0x8627 -#define GL_PROGRAM_STRING_ARB 0x8628 -#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E -#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F -#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 -#define GL_CURRENT_MATRIX_ARB 0x8641 -#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 -#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 -#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 -#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B -#define GL_PROGRAM_BINDING_ARB 0x8677 -#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A -#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 -#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 -#define GL_PROGRAM_FORMAT_ARB 0x8876 -#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 -#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 -#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 -#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 -#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 -#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 -#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 -#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 -#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 -#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 -#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA -#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB -#define GL_PROGRAM_ATTRIBS_ARB 0x88AC -#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD -#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE -#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF -#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 -#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 -#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 -#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 -#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 -#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 -#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 -#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 -#define GL_MATRIX0_ARB 0x88C0 -#define GL_MATRIX1_ARB 0x88C1 -#define GL_MATRIX2_ARB 0x88C2 -#define GL_MATRIX3_ARB 0x88C3 -#define GL_MATRIX4_ARB 0x88C4 -#define GL_MATRIX5_ARB 0x88C5 -#define GL_MATRIX6_ARB 0x88C6 -#define GL_MATRIX7_ARB 0x88C7 -#define GL_MATRIX8_ARB 0x88C8 -#define GL_MATRIX9_ARB 0x88C9 -#define GL_MATRIX10_ARB 0x88CA -#define GL_MATRIX11_ARB 0x88CB -#define GL_MATRIX12_ARB 0x88CC -#define GL_MATRIX13_ARB 0x88CD -#define GL_MATRIX14_ARB 0x88CE -#define GL_MATRIX15_ARB 0x88CF -#define GL_MATRIX16_ARB 0x88D0 -#define GL_MATRIX17_ARB 0x88D1 -#define GL_MATRIX18_ARB 0x88D2 -#define GL_MATRIX19_ARB 0x88D3 -#define GL_MATRIX20_ARB 0x88D4 -#define GL_MATRIX21_ARB 0x88D5 -#define GL_MATRIX22_ARB 0x88D6 -#define GL_MATRIX23_ARB 0x88D7 -#define GL_MATRIX24_ARB 0x88D8 -#define GL_MATRIX25_ARB 0x88D9 -#define GL_MATRIX26_ARB 0x88DA -#define GL_MATRIX27_ARB 0x88DB -#define GL_MATRIX28_ARB 0x88DC -#define GL_MATRIX29_ARB 0x88DD -#define GL_MATRIX30_ARB 0x88DE -#define GL_MATRIX31_ARB 0x88DF -#endif - -/* - * ARB_fragment_program - */ -#ifndef GL_ARB_fragment_program -#define GL_ARB_fragment_program 1 -#define GL_FRAGMENT_PROGRAM_ARB 0x8804 -#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 -#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 -#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 -#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 -#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 -#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A -#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B -#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C -#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D -#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E -#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F -#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 -#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 -#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 -#endif - -typedef void (APIENTRY * glVertexAttrib1dProc) (GLuint index, GLdouble x); -typedef void (APIENTRY * glVertexAttrib1dvProc) (GLuint index, const GLdouble *v); -typedef void (APIENTRY * glVertexAttrib1fProc) (GLuint index, GLfloat x); -typedef void (APIENTRY * glVertexAttrib1fvProc) (GLuint index, const GLfloat *v); -typedef void (APIENTRY * glVertexAttrib1sProc) (GLuint index, GLshort x); -typedef void (APIENTRY * glVertexAttrib1svProc) (GLuint index, const GLshort *v); -typedef void (APIENTRY * glVertexAttrib2dProc) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRY * glVertexAttrib2dvProc) (GLuint index, const GLdouble *v); -typedef void (APIENTRY * glVertexAttrib2fProc) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRY * glVertexAttrib2fvProc) (GLuint index, const GLfloat *v); -typedef void (APIENTRY * glVertexAttrib2sProc) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRY * glVertexAttrib2svProc) (GLuint index, const GLshort *v); -typedef void (APIENTRY * glVertexAttrib3dProc) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRY * glVertexAttrib3dvProc) (GLuint index, const GLdouble *v); -typedef void (APIENTRY * glVertexAttrib3fProc) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRY * glVertexAttrib3fvProc) (GLuint index, const GLfloat *v); -typedef void (APIENTRY * glVertexAttrib3sProc) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRY * glVertexAttrib3svProc) (GLuint index, const GLshort *v); -typedef void (APIENTRY * glVertexAttrib4NbvProc) (GLuint index, const GLbyte *v); -typedef void (APIENTRY * glVertexAttrib4NivProc) (GLuint index, const GLint *v); -typedef void (APIENTRY * glVertexAttrib4NsvProc) (GLuint index, const GLshort *v); -typedef void (APIENTRY * glVertexAttrib4NubProc) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRY * glVertexAttrib4NubvProc) (GLuint index, const GLubyte *v); -typedef void (APIENTRY * glVertexAttrib4NuivProc) (GLuint index, const GLuint *v); -typedef void (APIENTRY * glVertexAttrib4NusvProc) (GLuint index, const GLushort *v); -typedef void (APIENTRY * glVertexAttrib4bvProc) (GLuint index, const GLbyte *v); -typedef void (APIENTRY * glVertexAttrib4dProc) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRY * glVertexAttrib4dvProc) (GLuint index, const GLdouble *v); -typedef void (APIENTRY * glVertexAttrib4fProc) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRY * glVertexAttrib4fvProc) (GLuint index, const GLfloat *v); -typedef void (APIENTRY * glVertexAttrib4ivProc) (GLuint index, const GLint *v); -typedef void (APIENTRY * glVertexAttrib4sProc) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRY * glVertexAttrib4svProc) (GLuint index, const GLshort *v); -typedef void (APIENTRY * glVertexAttrib4ubvProc) (GLuint index, const GLubyte *v); -typedef void (APIENTRY * glVertexAttrib4uivProc) (GLuint index, const GLuint *v); -typedef void (APIENTRY * glVertexAttrib4usvProc) (GLuint index, const GLushort *v); -typedef void (APIENTRY * glVertexAttribPointerProc) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRY * glEnableVertexAttribArrayProc) (GLuint index); -typedef void (APIENTRY * glDisableVertexAttribArrayProc) (GLuint index); -typedef void (APIENTRY * glProgramStringProc) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); -typedef void (APIENTRY * glBindProgramProc) (GLenum target, GLuint program); -typedef void (APIENTRY * glDeleteProgramsProc) (GLsizei n, const GLuint *programs); -typedef void (APIENTRY * glGenProgramsProc) (GLsizei n, GLuint *programs); -typedef void (APIENTRY * glProgramEnvParameter4dProc) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRY * glProgramEnvParameter4dvProc) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRY * glProgramEnvParameter4fProc) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRY * glProgramEnvParameter4fvProc) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRY * glProgramLocalParameter4dProc) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRY * glProgramLocalParameter4dvProc) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRY * glProgramLocalParameter4fProc) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRY * glProgramLocalParameter4fvProc) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRY * glGetProgramEnvParameterdvProc) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRY * glGetProgramEnvParameterfvProc) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRY * glGetProgramLocalParameterdvProc) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRY * glGetProgramLocalParameterfvProc) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRY * glGetProgramivProc) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRY * glGetProgramStringProc) (GLenum target, GLenum pname, GLvoid *string); -typedef void (APIENTRY * glGetVertexAttribdvProc) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRY * glGetVertexAttribfvProc) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRY * glGetVertexAttribivProc) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRY * glGetVertexAttribPointervProc) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRY * glIsProgramProc) (GLuint program); - -/* - * EXT_framebuffer_objects - */ -#ifndef GL_EXT_framebuffer_object -#define GL_EXT_framebuffer_object 1 -#define GL_NONE_EXT 0 -#define GL_FRAMEBUFFER_EXT 0x8D40 -#define GL_RENDERBUFFER_EXT 0x8D41 -#define GL_RGBA4_EXT 0x8056 -#define GL_RGB5_A1_EXT 0x8057 -#define GL_RGB565_EXT 0x8D62 -#define GL_DEPTH_COMPONENT16_EXT 0x81A5 -#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 -#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 -#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 -#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 -#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 -#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 -#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA -#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD -#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 -#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 -#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 -#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 -#endif - -typedef GLboolean (APIENTRY * glIsRenderbufferProc) (GLuint renderbuffer); -typedef void (APIENTRY * glBindRenderbufferProc) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRY * glDeleteRenderbuffersProc) (GLsizei n, const GLuint* renderbuffers); -typedef void (APIENTRY * glGenRenderbuffersProc) (GLsizei n, GLuint* renderbuffers); -typedef void (APIENTRY * glRenderbufferStorageProc) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRY * glGetRenderbufferParameterivProc) (GLenum target, GLenum pname, GLint* params); -typedef GLboolean (APIENTRY * glIsFramebufferProc) (GLuint framebuffer); -typedef void (APIENTRY * glBindFramebufferProc) (GLenum target, GLuint framebuffer); -typedef void (APIENTRY * glDeleteFramebuffersProc) (GLsizei n, const GLuint* framebuffers); -typedef void (APIENTRY * glGenFramebuffersProc) (GLsizei n, GLuint* framebuffers); -typedef GLenum (APIENTRY * glCheckFramebufferStatusProc) (GLenum target); -typedef void (APIENTRY * glFramebufferRenderbufferProc) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRY * glFramebufferTexture2DProc) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRY * glGetFramebufferAttachmentParameterivProc) (GLenum target, GLenum attachment, GLenum pname, GLint* params); -typedef void (APIENTRY * glGenerateMipmapProc) (GLenum target); - -/* - * ARB_shader_objects - */ -#ifndef GL_ARB_shader_objects -#define GL_ARB_shader_objects 1 -/* GL types for handling shader object handles and program/shader text */ -typedef char GLcharARB; /* native character */ -typedef unsigned int GLhandleARB; /* shader object handle */ - -#define GL_PROGRAM_OBJECT_ARB 0x8B40 -#define GL_SHADER_OBJECT_ARB 0x8B48 -#define GL_OBJECT_TYPE_ARB 0x8B4E -#define GL_OBJECT_SUBTYPE_ARB 0x8B4F -#define GL_FLOAT_VEC2_ARB 0x8B50 -#define GL_FLOAT_VEC3_ARB 0x8B51 -#define GL_FLOAT_VEC4_ARB 0x8B52 -#define GL_INT_VEC2_ARB 0x8B53 -#define GL_INT_VEC3_ARB 0x8B54 -#define GL_INT_VEC4_ARB 0x8B55 -#define GL_BOOL_ARB 0x8B56 -#define GL_BOOL_VEC2_ARB 0x8B57 -#define GL_BOOL_VEC3_ARB 0x8B58 -#define GL_BOOL_VEC4_ARB 0x8B59 -#define GL_FLOAT_MAT2_ARB 0x8B5A -#define GL_FLOAT_MAT3_ARB 0x8B5B -#define GL_FLOAT_MAT4_ARB 0x8B5C -#define GL_SAMPLER_1D_ARB 0x8B5D -#define GL_SAMPLER_2D_ARB 0x8B5E -#define GL_SAMPLER_3D_ARB 0x8B5F -#define GL_SAMPLER_CUBE_ARB 0x8B60 -#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 -#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 -#define GL_SAMPLER_2D_RECT_ARB 0x8B63 -#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 -#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 -#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 -#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 -#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 -#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 -#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 -#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 -#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 -#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 -#endif - -typedef void (APIENTRY * glDeleteObjectProc) (GLhandleARB obj); -typedef GLhandleARB (APIENTRY * glGetHandleProc) (GLenum pname); -typedef void (APIENTRY * glDetachObjectProc) (GLhandleARB containerObj, GLhandleARB attachedObj); -typedef GLhandleARB (APIENTRY * glCreateShaderObjectProc) (GLenum shaderType); -typedef void (APIENTRY * glShaderSourceProc) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); -typedef void (APIENTRY * glCompileShaderProc) (GLhandleARB shaderObj); -typedef GLhandleARB (APIENTRY * glCreateProgramObjectProc) (void); -typedef void (APIENTRY * glAttachObjectProc) (GLhandleARB containerObj, GLhandleARB obj); -typedef void (APIENTRY * glLinkProgramProc) (GLhandleARB programObj); -typedef void (APIENTRY * glUseProgramObjectProc) (GLhandleARB programObj); -typedef void (APIENTRY * glValidateProgramProc) (GLhandleARB programObj); -typedef void (APIENTRY * glUniform1fProc) (GLint location, GLfloat v0); -typedef void (APIENTRY * glUniform2fProc) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRY * glUniform3fProc) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRY * glUniform4fProc) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRY * glUniform1iProc) (GLint location, GLint v0); -typedef void (APIENTRY * glUniform2iProc) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRY * glUniform3iProc) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRY * glUniform4iProc) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRY * glUniform1fvProc) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRY * glUniform2fvProc) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRY * glUniform3fvProc) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRY * glUniform4fvProc) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRY * glUniform1ivProc) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRY * glUniform2ivProc) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRY * glUniform3ivProc) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRY * glUniform4ivProc) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRY * glUniformMatrix2fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRY * glUniformMatrix3fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRY * glUniformMatrix4fvProc) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRY * glGetObjectParameterfvProc) (GLhandleARB obj, GLenum pname, GLfloat *params); -typedef void (APIENTRY * glGetObjectParameterivProc) (GLhandleARB obj, GLenum pname, GLint *params); -typedef void (APIENTRY * glGetInfoLogProc) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); -typedef void (APIENTRY * glGetAttachedObjectsProc) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); -typedef GLint (APIENTRY * glGetUniformLocationProc) (GLhandleARB programObj, const GLcharARB *name); -typedef void (APIENTRY * glGetActiveUniformProc) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef void (APIENTRY * glGetUniformfvProc) (GLhandleARB programObj, GLint location, GLfloat *params); -typedef void (APIENTRY * glGetUniformivProc) (GLhandleARB programObj, GLint location, GLint *params); -typedef void (APIENTRY * glGetShaderSourceProc) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); - -/* - * ARB_vertex_shader - */ -#ifndef GL_ARB_vertex_shader -#define GL_ARB_vertex_shader 1 -#define GL_VERTEX_SHADER_ARB 0x8B31 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A -#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D -#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 -#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A -#endif - -typedef void (APIENTRY * glBindAttribLocationProc) (GLhandleARB programObj, GLuint index, const GLcharARB *name); -typedef void (APIENTRY * glGetActiveAttribProc) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef GLint (APIENTRY * glGetAttribLocationProc) (GLhandleARB programObj, const GLcharARB *name); - -/* - * ARB_fragment_shader - */ -#ifndef GL_ARB_fragment_shader -#define GL_ARB_fragment_shader1 -#define GL_FRAGMENT_SHADER_ARB 0x8B30 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B -#endif - -/* - * NV_fragment_program - */ -#ifndef GL_NV_fragment_program -#define GL_NV_fragment_program 1 -#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 -#define GL_FRAGMENT_PROGRAM_NV 0x8870 -#define GL_MAX_TEXTURE_COORDS_NV 0x8871 -#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 -#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 -#define GL_PROGRAM_ERROR_STRING_NV 0x8874 -#endif -#ifndef GL_NV_vertex_program -#define GL_NV_vertex_program 1 -#define GL_VERTEX_PROGRAM_NV 0x8620 -#define GL_PROGRAM_ERROR_POSITION_NV 0x864B -#endif - -typedef void (APIENTRY * glBindProgramNVProc) (GLenum target, GLuint id); -typedef void (APIENTRY * glDeleteProgramsNVProc) (GLsizei n, const GLuint *programs); -typedef void (APIENTRY * glGenProgramsNVProc) (GLsizei n, GLuint *programs); -typedef void (APIENTRY * glLoadProgramNVProc) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); -typedef void (APIENTRY * glProgramParameter4fvNVProc) (GLenum target, GLuint index, const GLfloat *v); - -#if defined(__cplusplus) -} -#endif - - #endif // !__SG_EXTENSIONS_HXX diff --git a/simgear/screen/shader.cpp b/simgear/screen/shader.cpp deleted file mode 100644 index c0da0e80..00000000 --- a/simgear/screen/shader.cpp +++ /dev/null @@ -1,709 +0,0 @@ -/* Shader - * - * Copyright (C) 2003-2005, Alexander Zaprjagaev - * Roman Grigoriev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include "shader.h" -#include -#include - -#include -#include - -glVertexAttrib1dProc glVertexAttrib1dPtr = NULL; -glVertexAttrib1dvProc glVertexAttrib1dvPtr = NULL; -glVertexAttrib1fProc glVertexAttrib1fPtr = NULL; -glVertexAttrib1fvProc glVertexAttrib1fvPtr = NULL; -glVertexAttrib1sProc glVertexAttrib1sPtr = NULL; -glVertexAttrib1svProc glVertexAttrib1svPtr = NULL; -glVertexAttrib2dProc glVertexAttrib2dPtr = NULL; -glVertexAttrib2dvProc glVertexAttrib2dvPtr = NULL; -glVertexAttrib2fProc glVertexAttrib2fPtr = NULL; -glVertexAttrib2fvProc glVertexAttrib2fvPtr = NULL; -glVertexAttrib2sProc glVertexAttrib2sPtr = NULL; -glVertexAttrib2svProc glVertexAttrib2svPtr = NULL; -glVertexAttrib3dProc glVertexAttrib3dPtr = NULL; -glVertexAttrib3dvProc glVertexAttrib3dvPtr = NULL; -glVertexAttrib3fProc glVertexAttrib3fPtr = NULL; -glVertexAttrib3fvProc glVertexAttrib3fvPtr = NULL; -glVertexAttrib3sProc glVertexAttrib3sPtr = NULL; -glVertexAttrib3svProc glVertexAttrib3svPtr = NULL; -glVertexAttrib4NbvProc glVertexAttrib4NbvPtr = NULL; -glVertexAttrib4NivProc glVertexAttrib4NivPtr = NULL; -glVertexAttrib4NsvProc glVertexAttrib4NsvPtr = NULL; -glVertexAttrib4NubProc glVertexAttrib4NubPtr = NULL; -glVertexAttrib4NubvProc glVertexAttrib4NubvPtr = NULL; -glVertexAttrib4NuivProc glVertexAttrib4NuivPtr = NULL; -glVertexAttrib4NusvProc glVertexAttrib4NusvPtr = NULL; -glVertexAttrib4bvProc glVertexAttrib4bvPtr = NULL; -glVertexAttrib4dProc glVertexAttrib4dPtr = NULL; -glVertexAttrib4dvProc glVertexAttrib4dvPtr = NULL; -glVertexAttrib4fProc glVertexAttrib4fPtr = NULL; -glVertexAttrib4fvProc glVertexAttrib4fvPtr = NULL; -glVertexAttrib4ivProc glVertexAttrib4ivPtr = NULL; -glVertexAttrib4sProc glVertexAttrib4sPtr = NULL; -glVertexAttrib4svProc glVertexAttrib4svPtr = NULL; -glVertexAttrib4ubvProc glVertexAttrib4ubvPtr = NULL; -glVertexAttrib4uivProc glVertexAttrib4uivPtr = NULL; -glVertexAttrib4usvProc glVertexAttrib4usvPtr = NULL; -glVertexAttribPointerProc glVertexAttribPointerPtr = NULL; -glEnableVertexAttribArrayProc glEnableVertexAttribArrayPtr = NULL; -glDisableVertexAttribArrayProc glDisableVertexAttribArrayPtr = NULL; -glProgramStringProc glProgramStringPtr = NULL; -glBindProgramProc glBindProgramPtr = NULL; -glDeleteProgramsProc glDeleteProgramsPtr = NULL; -glGenProgramsProc glGenProgramsPtr = NULL; -glProgramEnvParameter4dProc glProgramEnvParameter4dPtr = NULL; -glProgramEnvParameter4dvProc glProgramEnvParameter4dvPtr = NULL; -glProgramEnvParameter4fProc glProgramEnvParameter4fPtr = NULL; -glProgramEnvParameter4fvProc glProgramEnvParameter4fvPtr = NULL; -glProgramLocalParameter4dProc glProgramLocalParameter4dPtr = NULL; -glProgramLocalParameter4dvProc glProgramLocalParameter4dvPtr = NULL; -glProgramLocalParameter4fProc glProgramLocalParameter4fPtr = NULL; -glProgramLocalParameter4fvProc glProgramLocalParameter4fvPtr = NULL; -glGetProgramEnvParameterdvProc glGetProgramEnvParameterdvPtr = NULL; -glGetProgramEnvParameterfvProc glGetProgramEnvParameterfvPtr = NULL; -glGetProgramLocalParameterdvProc glGetProgramLocalParameterdvPtr = NULL; -glGetProgramLocalParameterfvProc glGetProgramLocalParameterfvPtr = NULL; -glGetProgramivProc glGetProgramivPtr = NULL; -glGetProgramStringProc glGetProgramStringPtr = NULL; -glGetVertexAttribdvProc glGetVertexAttribdvPtr = NULL; -glGetVertexAttribfvProc glGetVertexAttribfvPtr = NULL; -glGetVertexAttribivProc glGetVertexAttribivPtr = NULL; -glGetVertexAttribPointervProc glGetVertexAttribPointervPtr = NULL; -glIsProgramProc glIsProgramPtr = NULL; - -glDeleteObjectProc glDeleteObjectPtr = NULL; -glGetHandleProc glGetHandlePtr = NULL; -glDetachObjectProc glDetachObjectPtr = NULL; -glCreateShaderObjectProc glCreateShaderObjectPtr = NULL; -glShaderSourceProc glShaderSourcePtr = NULL; -glCompileShaderProc glCompileShaderPtr = NULL; -glCreateProgramObjectProc glCreateProgramObjectPtr = NULL; -glAttachObjectProc glAttachObjectPtr = NULL; -glLinkProgramProc glLinkProgramPtr = NULL; -glUseProgramObjectProc glUseProgramObjectPtr = NULL; -glValidateProgramProc glValidateProgramPtr = NULL; -glUniform1fProc glUniform1fPtr = NULL; -glUniform2fProc glUniform2fPtr = NULL; -glUniform3fProc glUniform3fPtr = NULL; -glUniform4fProc glUniform4fPtr = NULL; -glUniform1iProc glUniform1iPtr = NULL; -glUniform2iProc glUniform2iPtr = NULL; -glUniform3iProc glUniform3iPtr = NULL; -glUniform4iProc glUniform4iPtr = NULL; -glUniform1fvProc glUniform1fvPtr = NULL; -glUniform2fvProc glUniform2fvPtr = NULL; -glUniform3fvProc glUniform3fvPtr = NULL; -glUniform4fvProc glUniform4fvPtr = NULL; -glUniform1ivProc glUniform1ivPtr = NULL; -glUniform2ivProc glUniform2ivPtr = NULL; -glUniform3ivProc glUniform3ivPtr = NULL; -glUniform4ivProc glUniform4ivPtr = NULL; -glUniformMatrix2fvProc glUniformMatrix2fvPtr = NULL; -glUniformMatrix3fvProc glUniformMatrix3fvPtr = NULL; -glUniformMatrix4fvProc glUniformMatrix4fvPtr = NULL; -glGetObjectParameterfvProc glGetObjectParameterfvPtr = NULL; -glGetObjectParameterivProc glGetObjectParameterivPtr = NULL; -glGetInfoLogProc glGetInfoLogPtr = NULL; -glGetAttachedObjectsProc glGetAttachedObjectsPtr = NULL; -glGetUniformLocationProc glGetUniformLocationPtr = NULL; -glGetActiveUniformProc glGetActiveUniformPtr = NULL; -glGetUniformfvProc glGetUniformfvPtr = NULL; -glGetUniformivProc glGetUniformivPtr = NULL; -glGetShaderSourceProc glGetShaderSourcePtr = NULL; - -glBindAttribLocationProc glBindAttribLocationPtr = NULL; -glGetActiveAttribProc glGetActiveAttribPtr = NULL; -glGetAttribLocationProc glGetAttribLocationPtr = NULL; - -glBindProgramNVProc glBindProgramNVPtr = NULL; -glDeleteProgramsNVProc glDeleteProgramsNVPtr = NULL; -glGenProgramsNVProc glGenProgramsNVPtr = NULL; -glLoadProgramNVProc glLoadProgramNVPtr = NULL; -glProgramParameter4fvNVProc glProgramParameter4fvNVPtr = NULL; - -bool Shader::VP_supported = false; -bool Shader::FP_supported = false; -bool Shader::GLSL_supported = false; -bool Shader::NVFP_supported = false; -GLint Shader::nb_texture_unit = 0; - -Shader::Shader(const char *name,const char *vertex,const char *fragment) { - - program = 0; - vertex_target = 0; - vertex_id = 0; - fragment_target = 0; - fragment_id = 0; - - char *data; - FILE *file = fopen(name,"rb"); - if(!file) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): can't open '" << name << "' file\n"); - return; - } - - fseek(file,0,SEEK_END); - int size = ftell(file); - data = new char[size + 1]; - data[size] = '\0'; - fseek(file,0,SEEK_SET); - fread(data,1,size,file); - fclose(file); - - // skip comments - char *s = data; - char *d = data; - while(*s) { - if(*s == '/' && *(s + 1) == '/') { - while(*s && *s != '\n') s++; - while(*s && *s == '\n') s++; - *d++ = '\n'; - } - else if(*s == '/' && *(s + 1) == '*') { - while(*s && (*s != '*' || *(s + 1) != '/')) s++; - s += 2; - while(*s && *s == '\n') s++; - *d++ = '\n'; - } - else *d++ = *s++; - } - *d = '\0'; - - // find shaders - char *vertex_src = NULL; - char *fragment_src = NULL; - s = data; - while(*s) { - if(*s == '<') { - char *name = s; - while(*s) { - if(std::strchr("> \t\n\r",*s)) break; - s++; - } - if(*s == '>') { // it`s shader - *name++ = '\0'; - *s++ = '\0'; - while(*s && std::strchr(" \t\n\r",*s)) s++; - if(vertex == NULL && !std::strcmp(name,"vertex")) vertex_src = s; - if(vertex && !std::strcmp(name,vertex)) vertex_src = s; - if(fragment == NULL && !std::strcmp(name,"fragment")) fragment_src = s; - if(fragment && !std::strcmp(name,fragment)) fragment_src = s; - } - } - s++; - } - - if(vertex_src) { - - // ARB vertex program - if(VP_supported && !std::strncmp(vertex_src,"!!ARBvp1.0",10)) { - vertex_target = GL_VERTEX_PROGRAM_ARB; - glGenProgramsPtr(1,&vertex_id); - glBindProgramPtr(GL_VERTEX_PROGRAM_ARB,vertex_id); - glProgramStringPtr(GL_VERTEX_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)std::strlen(vertex_src),vertex_src); - GLint pos = -1; - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&pos); - if(pos != -1) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): vertex program error in " << name << " file\n" << get_error(vertex_src,pos)); - return; - } - char *var = std::strstr(vertex_src, "#var "); - while( var ) { - char *eol = std::strchr( var + 1, '#'); - char *c2, *c3, *c4; - c2 = strchr( var + 6, ' '); - if( c2 ) { - c3 = strchr( c2 + 1, ':'); - if( c3 ) { - c4 = strchr( c3 + 1, ':'); - if( c4 ) - c4 = strchr( c4 + 1, '['); - if( c4 && c4 < eol) { - char type[10], name[30]; - std::strncpy( type, var + 5, c2-var-5 ); - type[c2-var-5] = 0; - std::strncpy( name, c2 + 1, c3-c2-2 ); - name[c3-c2-2] = 0; - struct Parameter p; - p.location = atoi( c4 + 1); - p.length = 4; - if( ! std::strcmp(type, "float3") ) - p.length = 3; - else if( ! strcmp(type, "float") ) - p.length = 1; - arb_parameters[ name ] = p; - } - } - } - var = strstr(var + 1, "#var "); - } - } - // ARB vertex shader - else { - - program = glCreateProgramObjectPtr(); - - GLint length = (GLint)std::strlen(vertex_src); - GLhandleARB vertex = glCreateShaderObjectPtr(GL_VERTEX_SHADER_ARB); - glShaderSourcePtr(vertex,1,(const GLcharARB**)&vertex_src,&length); - glCompileShaderPtr(vertex); - glAttachObjectPtr(program,vertex); - glDeleteObjectPtr(vertex); - - glBindAttribLocationPtr(program,0,"s_attribute_0"); - glBindAttribLocationPtr(program,1,"s_attribute_1"); - glBindAttribLocationPtr(program,2,"s_attribute_2"); - glBindAttribLocationPtr(program,3,"s_attribute_3"); - glBindAttribLocationPtr(program,4,"s_attribute_4"); - glBindAttribLocationPtr(program,5,"s_attribute_5"); - glBindAttribLocationPtr(program,6,"s_attribute_6"); - - glBindAttribLocationPtr(program,0,"s_xyz"); - glBindAttribLocationPtr(program,1,"s_normal"); - glBindAttribLocationPtr(program,2,"s_tangent"); - glBindAttribLocationPtr(program,3,"s_binormal"); - glBindAttribLocationPtr(program,4,"s_texcoord"); - } - } - - if(fragment_src) { - - // ARB fragment program - if(FP_supported && !std::strncmp(fragment_src,"!!ARBfp1.0",10)) { - fragment_target = GL_FRAGMENT_PROGRAM_ARB; - glGenProgramsPtr(1,&fragment_id); - glBindProgramPtr(GL_FRAGMENT_PROGRAM_ARB,fragment_id); - glProgramStringPtr(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)std::strlen(fragment_src),fragment_src); - GLint pos = -1; - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&pos); - if(pos != -1) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): fragment program error in " << name << " file\n" << get_error(fragment_src,pos)); - return; - } - } - - // NV fragment program - else if(!strncmp(fragment_src,"!!FP1.0",7)) { - fragment_target = GL_FRAGMENT_PROGRAM_NV; - glGenProgramsNVPtr(1,&fragment_id); - glBindProgramNVPtr(GL_FRAGMENT_PROGRAM_NV,fragment_id); - glLoadProgramNVPtr(GL_FRAGMENT_PROGRAM_NV,fragment_id,(GLsizei)std::strlen(fragment_src),(GLubyte*)fragment_src); - GLint pos = -1; - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV,&pos); - if(pos != -1) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): fragment program error in " << name << " file\n" << get_error(fragment_src,pos)); - return; - } - } - - // ARB fragment shader - else { - - if(!program) program = glCreateProgramObjectPtr(); - - GLint length = (GLint)std::strlen(fragment_src); - GLhandleARB fragment = glCreateShaderObjectPtr(GL_FRAGMENT_SHADER_ARB); - glShaderSourcePtr(fragment,1,(const GLcharARB**)&fragment_src,&length); - glCompileShaderPtr(fragment); - glAttachObjectPtr(program,fragment); - glDeleteObjectPtr(fragment); - } - } - - if(program) { - - glLinkProgramPtr(program); - GLint linked; - glGetObjectParameterivPtr(program,GL_OBJECT_LINK_STATUS_ARB,&linked); - if(!linked) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): GLSL error in " << name << " file\n" << get_glsl_error()); - return; - } - - glUseProgramObjectPtr(program); - - for(int i = 0; i < 8; i++) { - char texture[32]; - sprintf(texture,"s_texture_%d",i); - GLint location = glGetUniformLocationPtr(program,texture); - if(location >= 0) glUniform1iPtr(location,i); - } - - glUseProgramObjectPtr(0); - - glValidateProgramPtr(program); - GLint validated; - glGetObjectParameterivPtr(program,GL_OBJECT_VALIDATE_STATUS_ARB,&validated); - if(!validated) { - SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): GLSL error in " << name << " file\n" << get_glsl_error()); - return; - } - } - - delete [] data; -} - -Shader::~Shader() { - if(program) glDeleteObjectPtr(program); - if(vertex_target == GL_VERTEX_PROGRAM_ARB) glDeleteProgramsPtr(1,&vertex_id); - if(fragment_target == GL_FRAGMENT_PROGRAM_ARB) glDeleteProgramsPtr(1,&fragment_id); - else if(fragment_target == GL_FRAGMENT_PROGRAM_NV) glDeleteProgramsNVPtr(1,&fragment_id); - parameters.clear(); -} - -/* - */ -const char *Shader::get_error(char *data,int pos) { - char *s = data; - while(*s && pos--) s++; - while(s >= data && *s != '\n') s--; - char *e = ++s; - while(*e != '\0' && *e != '\n') e++; - *e = '\0'; - return s; -} - -/* - */ - -const char *Shader::get_glsl_error() { - GLint length; - static char error[4096]; - glGetInfoLogPtr(program,sizeof(error),&length,error); - return error; -} - -/* - */ -void Shader::getParameter(const char *name,Parameter *parameter) { - if( program ) { - char buf[1024]; - std::strcpy(buf,name); - char *s = std::strchr(buf,':'); - if(s) { - *s++ = '\0'; - parameter->length = std::atoi(s); - } else { - parameter->length = 4; - } - parameter->location = glGetUniformLocationPtr(program,buf); - } else if( vertex_id ) { - arb_parameter_list::iterator iParam = arb_parameters.find(name); - if( iParam != arb_parameters.end() ) - parameter->location = iParam->second.location; - else - parameter->location = 90; - parameter->length = 4; - } -} - -/* - */ -void Shader::bindNames(const char *name,...) { - Parameter parameter; - getParameter(name,¶meter); - parameters.push_back(parameter); - va_list args; - va_start(args,name); - while(1) { - const char *name = va_arg(args,const char*); - if(name == NULL) break; - getParameter(name,¶meter); - parameters.push_back(parameter); - } - va_end(args); -} - -/*****************************************************************************/ -/* */ -/* enable/disable/bind */ -/* */ -/*****************************************************************************/ - -/* - */ -void Shader::enable() { - if(vertex_id) glEnable(vertex_target); - if(fragment_id) glEnable(fragment_target); -} - -/* - */ -void Shader::disable() { - if(program) glUseProgramObjectPtr(0); - if(vertex_id) glDisable(vertex_target); - if(fragment_id) glDisable(fragment_target); -} - -/* - */ -void Shader::bind() { - if(program) glUseProgramObjectPtr(program); - if(vertex_id) { - if(vertex_target == GL_VERTEX_PROGRAM_ARB) glBindProgramPtr(vertex_target,vertex_id); - } - if(fragment_id) { - if(fragment_target == GL_FRAGMENT_PROGRAM_ARB) glBindProgramPtr(fragment_target,fragment_id); - else if(fragment_target == GL_FRAGMENT_PROGRAM_NV) glBindProgramNVPtr(fragment_target,fragment_id); - } -} - -/* - */ -void Shader::bind(const float *v,...) { - if(fragment_id) { - if(fragment_target == GL_FRAGMENT_PROGRAM_ARB) glBindProgramPtr(fragment_target,fragment_id); - else if(fragment_target == GL_FRAGMENT_PROGRAM_NV) glBindProgramNVPtr(fragment_target,fragment_id); - } else { - if(program == 0) { - SG_LOG(SG_GL, SG_ALERT, "Shader::bind(): error GLSL shader isn't loaded\n"); - return; - } - glUseProgramObjectPtr(program); - } - const float *value = v; - va_list args; - va_start(args,v); - for(int i = 0; i < (int)parameters.size(); i++) { - if( vertex_target ) { - glProgramLocalParameter4fvPtr( vertex_target, parameters[i].location, value); - } else if( program ) { - if(parameters[i].length == 1) glUniform1fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 2) glUniform2fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 3) glUniform3fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 4) glUniform4fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 9) glUniformMatrix3fvPtr(parameters[i].location,1,false,value); - else if(parameters[i].length == 16) glUniformMatrix4fvPtr(parameters[i].location,1,false,value); - } - value = va_arg(args,const float*); - if(!value) break; - } - va_end(args); -} - -/*****************************************************************************/ -/* */ -/* set parameters */ -/* */ -/*****************************************************************************/ - -void Shader::setLocalParameter(int location,const float *value) { - if(vertex_target == 0) { - SG_LOG(SG_GL, SG_ALERT, "Shader::setLocalParameter(): error vertex program isn't loaded\n"); - return; - } - glProgramLocalParameter4fvPtr(vertex_target,location,value); -} - -void Shader::setEnvParameter(int location,const float *value) { - if(vertex_target == 0) { - SG_LOG(SG_GL, SG_ALERT, "Shader::setEnvParameter(): error vertex program isn't loaded\n"); - return; - } - glProgramEnvParameter4fvPtr(vertex_target,location,value); -} - -/* - */ -void Shader::setParameter(const char *name,const float *value) { - Parameter parameter; - getParameter(name,¶meter); - if( vertex_target ) { - glProgramLocalParameter4fvPtr( vertex_target, parameter.location, value); - return; - } - if(program == 0) { - SG_LOG(SG_GL, SG_ALERT, "Shader::setLocalParameter(): error GLSL shader isn't loaded\n"); - return; - } - if(parameter.length == 1) glUniform1fvPtr(parameter.location,1,value); - else if(parameter.length == 2) glUniform2fvPtr(parameter.location,1,value); - else if(parameter.length == 3) glUniform3fvPtr(parameter.location,1,value); - else if(parameter.length == 4) glUniform4fvPtr(parameter.location,1,value); - else if(parameter.length == 9) glUniformMatrix3fvPtr(parameter.location,1,false,value); - else if(parameter.length == 16) glUniformMatrix4fvPtr(parameter.location,1,false,value); -} - -/* - */ -void Shader::setParameters(const float *v,...) { - const float *value = v; - va_list args; - va_start(args,v); - for(int i = 0; i < (int)parameters.size(); i++) { - if( vertex_target ) { - glProgramLocalParameter4fvPtr( vertex_target, parameters[i].location, value); - } else if( program ) { - if(parameters[i].length == 1) glUniform1fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 2) glUniform2fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 3) glUniform3fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 4) glUniform4fvPtr(parameters[i].location,1,value); - else if(parameters[i].length == 9) glUniformMatrix3fvPtr(parameters[i].location,1,false,value); - else if(parameters[i].length == 16) glUniformMatrix4fvPtr(parameters[i].location,1,false,value); - } - value = va_arg(args,const float*); - if(!value) break; - } - va_end(args); -} - -#ifndef CONCAT -#define CONCAT(a,b) a##b -#endif -#define mystringify(a) CONCAT(ST,R)(a) -#define STR(x) #x -#define LOAD_EXT(fn) CONCAT(fn,Ptr) = (CONCAT(fn,Proc)) SGLookupFunction( mystringify(CONCAT(fn,ARB)) ) - -void Shader::Init(void) { - if( SGIsOpenGLExtensionSupported("GL_ARB_multitexture") ) - glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &nb_texture_unit ); - VP_supported = SGIsOpenGLExtensionSupported("GL_ARB_vertex_program"); - FP_supported = SGIsOpenGLExtensionSupported("GL_ARB_fragment_program"); - // check that - GLSL_supported = SGIsOpenGLExtensionSupported("GL_ARB_shading_language_100") && - SGIsOpenGLExtensionSupported("GL_ARB_fragment_shader") && - SGIsOpenGLExtensionSupported("GL_ARB_vertex_shader") && - SGIsOpenGLExtensionSupported("GL_ARB_shader_objects"); - NVFP_supported = SGIsOpenGLExtensionSupported("GL_NV_fragment_program"); - - if( VP_supported || FP_supported ) { - /* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ - LOAD_EXT(glVertexAttrib1d); - LOAD_EXT( glVertexAttrib1dv ); - LOAD_EXT( glVertexAttrib1f ); - LOAD_EXT( glVertexAttrib1fv ); - LOAD_EXT( glVertexAttrib1s ); - LOAD_EXT( glVertexAttrib1sv ); - LOAD_EXT( glVertexAttrib2d ); - LOAD_EXT( glVertexAttrib2dv ); - LOAD_EXT( glVertexAttrib2f ); - LOAD_EXT( glVertexAttrib2fv ); - LOAD_EXT( glVertexAttrib2s ); - LOAD_EXT( glVertexAttrib2sv ); - LOAD_EXT( glVertexAttrib3d ); - LOAD_EXT( glVertexAttrib3dv ); - LOAD_EXT( glVertexAttrib3f ); - LOAD_EXT( glVertexAttrib3fv ); - LOAD_EXT( glVertexAttrib3s ); - LOAD_EXT( glVertexAttrib3sv ); - LOAD_EXT( glVertexAttrib4Nbv ); - LOAD_EXT( glVertexAttrib4Niv ); - LOAD_EXT( glVertexAttrib4Nsv ); - LOAD_EXT( glVertexAttrib4Nub ); - LOAD_EXT( glVertexAttrib4Nubv ); - LOAD_EXT( glVertexAttrib4Nuiv ); - LOAD_EXT( glVertexAttrib4Nusv ); - LOAD_EXT( glVertexAttrib4bv ); - LOAD_EXT( glVertexAttrib4d ); - LOAD_EXT( glVertexAttrib4dv ); - LOAD_EXT( glVertexAttrib4f ); - LOAD_EXT( glVertexAttrib4fv ); - LOAD_EXT( glVertexAttrib4iv ); - LOAD_EXT( glVertexAttrib4s ); - LOAD_EXT( glVertexAttrib4sv ); - LOAD_EXT( glVertexAttrib4ubv ); - LOAD_EXT( glVertexAttrib4uiv ); - LOAD_EXT( glVertexAttrib4usv ); - LOAD_EXT( glVertexAttribPointer ); - LOAD_EXT( glEnableVertexAttribArray ); - LOAD_EXT( glDisableVertexAttribArray ); - LOAD_EXT( glProgramString ); - LOAD_EXT( glBindProgram ); - LOAD_EXT( glDeletePrograms ); - LOAD_EXT( glGenPrograms ); - LOAD_EXT( glProgramEnvParameter4d ); - LOAD_EXT( glProgramEnvParameter4dv ); - LOAD_EXT( glProgramEnvParameter4f ); - LOAD_EXT( glProgramEnvParameter4fv ); - LOAD_EXT( glProgramLocalParameter4d ); - LOAD_EXT( glProgramLocalParameter4dv ); - LOAD_EXT( glProgramLocalParameter4f ); - LOAD_EXT( glProgramLocalParameter4fv ); - LOAD_EXT( glGetProgramEnvParameterdv ); - LOAD_EXT( glGetProgramEnvParameterfv ); - LOAD_EXT( glGetProgramLocalParameterdv ); - LOAD_EXT( glGetProgramLocalParameterfv ); - LOAD_EXT( glGetProgramiv ); - LOAD_EXT( glGetProgramString ); - LOAD_EXT( glGetVertexAttribdv ); - LOAD_EXT( glGetVertexAttribfv ); - LOAD_EXT( glGetVertexAttribiv ); - LOAD_EXT( glGetVertexAttribPointerv ); - LOAD_EXT( glIsProgram ); - } - if( GLSL_supported ) { - LOAD_EXT( glDeleteObject ); - LOAD_EXT( glGetHandle ); - LOAD_EXT( glDetachObject ); - LOAD_EXT( glCreateShaderObject ); - LOAD_EXT( glShaderSource ); - LOAD_EXT( glCompileShader ); - LOAD_EXT( glCreateProgramObject ); - LOAD_EXT( glAttachObject ); - LOAD_EXT( glLinkProgram ); - LOAD_EXT( glUseProgramObject ); - LOAD_EXT( glValidateProgram ); - LOAD_EXT( glUniform1f ); - LOAD_EXT( glUniform2f ); - LOAD_EXT( glUniform3f ); - LOAD_EXT( glUniform4f ); - LOAD_EXT( glUniform1i ); - LOAD_EXT( glUniform2i ); - LOAD_EXT( glUniform3i ); - LOAD_EXT( glUniform4i ); - LOAD_EXT( glUniform1fv ); - LOAD_EXT( glUniform2fv ); - LOAD_EXT( glUniform3fv ); - LOAD_EXT( glUniform4fv ); - LOAD_EXT( glUniform1iv ); - LOAD_EXT( glUniform2iv ); - LOAD_EXT( glUniform3iv ); - LOAD_EXT( glUniform4iv ); - LOAD_EXT( glUniformMatrix2fv ); - LOAD_EXT( glUniformMatrix3fv ); - LOAD_EXT( glUniformMatrix4fv ); - LOAD_EXT( glGetObjectParameterfv ); - LOAD_EXT( glGetObjectParameteriv ); - LOAD_EXT( glGetInfoLog ); - LOAD_EXT( glGetAttachedObjects ); - LOAD_EXT( glGetUniformLocation ); - LOAD_EXT( glGetActiveUniform ); - LOAD_EXT( glGetUniformfv ); - LOAD_EXT( glGetUniformiv ); - LOAD_EXT( glGetShaderSource ); - - LOAD_EXT( glBindAttribLocation ); - LOAD_EXT( glGetActiveAttrib ); - LOAD_EXT( glGetAttribLocation ); - - } - if( NVFP_supported ) { - glBindProgramNVPtr = (glBindProgramNVProc) SGLookupFunction( "glBindProgramNV" ); - glDeleteProgramsNVPtr = (glDeleteProgramsNVProc) SGLookupFunction( "glDeleteProgramsNV" ); - glGenProgramsNVPtr = (glGenProgramsNVProc) SGLookupFunction( "glGenProgramsNV" ); - glLoadProgramNVPtr = (glLoadProgramNVProc) SGLookupFunction( "glLoadProgramNV" ); - glProgramParameter4fvNVPtr = (glProgramParameter4fvNVProc) SGLookupFunction( "glProgramParameter4fvNV" ); - } -} diff --git a/simgear/screen/shader.h b/simgear/screen/shader.h deleted file mode 100644 index 2bd3e8eb..00000000 --- a/simgear/screen/shader.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Shader - * - * Copyright (C) 2003-2005, Alexander Zaprjagaev - * Roman Grigoriev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __SHADER_H__ -#define __SHADER_H__ - -#include -#include - -#include - -#include -#include - -using std::map; -using std::vector; -using std::string; - -class Shader { -public: - - Shader(const char *name,const char *vertex = NULL,const char *fragment = NULL); - ~Shader(); - - void bindNames(const char *name,...); - - void enable(); - void disable(); - void bind(); - void bind(const float *value,...); - - void setLocalParameter(int location,const float *value); - void setEnvParameter(int location,const float *value); - - void setParameter(const char *name,const float *value); - void setParameters(const float *value,...); - - static void Init(void); - inline static bool is_VP_supported(void) {return VP_supported;} - inline static bool is_FP_supported(void) {return FP_supported;} - inline static bool is_GLSL_supported(void) {return GLSL_supported;} - inline static bool is_NVFP_supported(void) {return NVFP_supported;} - inline static int get_nb_texture_units(void) {return nb_texture_unit;} - -protected: - - struct Parameter { - GLuint location; - int length; - }; - - const char *get_error(char *data,int pos); - const char *get_glsl_error(); - - void getParameter(const char *name,Parameter *parameter); - - GLhandleARB program; - - GLuint vertex_target; - GLuint vertex_id; - - GLuint fragment_target; - GLuint fragment_id; - - std::vector parameters; - typedef map arb_parameter_list; - arb_parameter_list arb_parameters; - - static bool VP_supported, FP_supported, GLSL_supported, NVFP_supported; - static GLint nb_texture_unit; -}; - -#endif /* __SHADER_H__ */ diff --git a/simgear/screen/win32-printer.h b/simgear/screen/win32-printer.h deleted file mode 100644 index 6aff3a2c..00000000 --- a/simgear/screen/win32-printer.h +++ /dev/null @@ -1,325 +0,0 @@ - -class CGlPrinter -{ -public: - typedef enum { RENDER_TO_PRINTER, RENDER_TO_BITMAP, READ_BITMAP, PRINT_BITMAP } PRINTMODE; -public: - inline CGlPrinter( PRINTMODE mode = READ_BITMAP ); - inline ~CGlPrinter(); - inline bool Begin( char *title, int w=0, int h=0 ); - inline void End( GLubyte *bm=NULL ); - inline double GetAspect(); - inline int GetHorzRes(); - inline int GetVertRes(); - -private: - PRINTMODE m_printMode; - PRINTDLG m_printDLG; - BITMAPINFO m_bitmapInfo; - void *m_bitmap; - HBITMAP bitmapHandle; - HDC m_bitmapDC; - HGLRC m_printerHGLRC; - HGLRC m_bitmapHGLRC; - int m_pageWidth; // Dimension of printer page (x) - int m_pageHeight; // Dimension of printer page (y) -}; - -inline double CGlPrinter::GetAspect() -{ - return (double)m_pageWidth/(double)m_pageHeight; -} - -inline int CGlPrinter::GetHorzRes() -{ - return m_pageWidth; -} - -inline int CGlPrinter::GetVertRes() -{ - return m_pageHeight; -} - -inline CGlPrinter::CGlPrinter( PRINTMODE mode ) : - m_printerHGLRC( 0 ), m_bitmapHGLRC( 0 ), m_printMode( mode ), m_bitmap( NULL ) -{ -} - -inline CGlPrinter::~CGlPrinter() -{ -} - -inline bool CGlPrinter::Begin( char *title, int w, int h ) -{ - // Pixel format for Printer Device context - static PIXELFORMATDESCRIPTOR pPrintfd = { - sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure - 1, // Version of this structure - PFD_DRAW_TO_WINDOW | // Draw to Window (not to m_bitmap) - PFD_SUPPORT_OPENGL | // Support OpenGL calls - PFD_SUPPORT_GDI | // Allow GDI drawing in window too - PFD_DEPTH_DONTCARE, // Don't care about depth buffering - PFD_TYPE_RGBA, // RGBA Color mode - 24, // Want 24bit color - 0,0,0,0,0,0, // Not used to select mode - 0,0, // Not used to select mode - 0,0,0,0,0, // Not used to select mode - 0, // Size of depth buffer - 0, // Not used to select mode - 0, // Not used to select mode - 0, // Not used to select mode - 0, // Not used to select mode - 0,0,0 }; // Not used to select mode - - DOCINFO docInfo; // Document Info - int nPixelFormat; // Pixel format requested - - // Get printer information - memset(&m_printDLG,0,sizeof(PRINTDLG)); - m_printDLG.lStructSize = sizeof(PRINTDLG); - m_printDLG.hwndOwner = GetForegroundWindow(); - m_printDLG.hDevMode = NULL; - m_printDLG.hDevNames = NULL; - m_printDLG.Flags = PD_RETURNDC | PD_ALLPAGES; - - // Display printer dialog - if(!PrintDlg(&m_printDLG)) - { - printf( "PrintDlg() failed %lx\n", GetLastError() ); - return false; - } - - // Get the dimensions of the page - m_pageWidth = GetDeviceCaps(m_printDLG.hDC, HORZRES); - m_pageHeight = GetDeviceCaps(m_printDLG.hDC, VERTRES); - - // Initialize DocInfo structure - docInfo.cbSize = sizeof(DOCINFO); - docInfo.lpszDocName = title; - docInfo.lpszOutput = NULL; - - - // Choose a pixel format that best matches that described in pfd - nPixelFormat = ChoosePixelFormat(m_printDLG.hDC, &pPrintfd); - // Watch for no pixel format available for this printer - if(nPixelFormat == 0) - { - // Delete the printer context - DeleteDC(m_printDLG.hDC); - - printf( "ChoosePixelFormat() failed %lx\n", GetLastError() ); - return false; - } - - // Start the document and page - StartDoc(m_printDLG.hDC, &docInfo); - StartPage(m_printDLG.hDC); - - // Set the pixel format for the device context, but watch for failure - if(!SetPixelFormat(m_printDLG.hDC, nPixelFormat, &pPrintfd)) - { - // Delete the printer context - DeleteDC(m_printDLG.hDC); - - printf( "SetPixelFormat() failed %lx\n", GetLastError() ); - return false; - } - - // Create the Rendering context and make it current - if ( m_printMode == RENDER_TO_PRINTER ) - { - m_printerHGLRC = wglCreateContext(m_printDLG.hDC); - wglMakeCurrent(m_printDLG.hDC, m_printerHGLRC); - } - else - { - memset( &m_bitmapInfo, 0, sizeof(BITMAPINFO) ); - m_bitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); - if ( m_printMode == READ_BITMAP ) - { - GLint vp[4]; - glGetIntegerv( GL_VIEWPORT, vp ); - m_bitmapInfo.bmiHeader.biWidth = vp[2]; - m_bitmapInfo.bmiHeader.biHeight = (vp[3] + 3) & ~3; - } - else - { - if ( m_printMode == RENDER_TO_BITMAP ) - { - m_bitmapInfo.bmiHeader.biWidth = m_pageWidth; - m_bitmapInfo.bmiHeader.biHeight = m_pageHeight; - } - else - { - // PRINT_BITMAP - m_bitmapInfo.bmiHeader.biWidth = w; - m_bitmapInfo.bmiHeader.biHeight = h; - } - } - m_bitmapInfo.bmiHeader.biPlanes = 1; - m_bitmapInfo.bmiHeader.biBitCount = 24; - m_bitmapInfo.bmiHeader.biCompression = BI_RGB; - m_bitmapInfo.bmiHeader.biSizeImage = m_bitmapInfo.bmiHeader.biWidth*m_bitmapInfo.bmiHeader.biHeight*3; - m_bitmapInfo.bmiHeader.biXPelsPerMeter = 2952; // 75dpi - m_bitmapInfo.bmiHeader.biYPelsPerMeter = 2952; // 75dpi - m_bitmapInfo.bmiHeader.biClrUsed = 0; - m_bitmapInfo.bmiHeader.biClrImportant = 0; - bitmapHandle = CreateDIBSection( NULL, &m_bitmapInfo, DIB_RGB_COLORS, &m_bitmap, NULL, 0); - m_bitmapDC = CreateCompatibleDC( NULL ); - if ( m_bitmapDC == NULL ) - { - DeleteDC(m_printDLG.hDC); - printf( "CreateCompatibleDC() failed %lx\n", GetLastError() ); - return false; - } - if ( SelectObject( m_bitmapDC, bitmapHandle ) == NULL ) - { - DeleteDC(m_printDLG.hDC); - DeleteDC(m_bitmapDC); - printf( "SelectObject() failed %lx\n", GetLastError() ); - return false; - } - PIXELFORMATDESCRIPTOR pfd; - memset( &pfd, 0, sizeof(PIXELFORMATDESCRIPTOR) ); - pfd.nVersion = 1 ; - pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL; - pfd.iPixelType = PFD_TYPE_RGBA ; - pfd.cColorBits = 24; - pfd.iLayerType = PFD_MAIN_PLANE; - int pixelFormat = ::ChoosePixelFormat(m_bitmapDC, &pfd); - SetPixelFormat (m_bitmapDC, pixelFormat, &pfd); - if ( m_printMode == RENDER_TO_BITMAP ) - { - m_bitmapHGLRC = wglCreateContext( m_bitmapDC ); - wglMakeCurrent( m_bitmapDC, m_bitmapHGLRC ); - } - } - - if ( m_printMode == RENDER_TO_PRINTER || m_printMode == RENDER_TO_BITMAP ) - { - // Set viewing volume info - //glViewport(0,0,m_pageWidth/2,m_pageHeight/2); // Put this in to restrict area of page. - - GLfloat nRange = 100.0f; - - // Reset projection matrix stack - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - // Establish clipping volume (left, right, bottom, top, near, far) - // This keeps the perspective square regardless of window or page size - - if (m_pageHeight <= m_pageWidth) - { - glOrtho (-nRange, nRange, -nRange*m_pageHeight/m_pageWidth, nRange*m_pageHeight/m_pageWidth, -nRange, nRange); - } - else - { - glOrtho (-nRange*m_pageWidth/m_pageHeight, nRange*m_pageWidth/m_pageHeight, -nRange, nRange, -nRange, nRange); - } - - // Reset Model view matrix stack - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glRotatef(270.0f, 1.0, 0.0, 0.0); - } - - return true; -} - -inline void CGlPrinter::End( GLubyte *bm ) -{ - if ( m_printDLG.hDC ) - { - glFinish(); - - if ( m_printMode == RENDER_TO_PRINTER ) - { - if ( m_printerHGLRC ) - { - wglDeleteContext( m_printerHGLRC ); - } - } - else - { - if ( m_printMode == RENDER_TO_BITMAP ) - { - BitBlt( m_printDLG.hDC, 0,0, m_pageWidth,m_pageHeight, m_bitmapDC, 0,0, SRCCOPY ); - } - else - { - if ( m_printMode == READ_BITMAP ) - { - glPixelStorei( GL_PACK_ALIGNMENT, 4 ); - glPixelStorei( GL_PACK_ROW_LENGTH, 0 ); - glPixelStorei( GL_PACK_SKIP_ROWS, 0 ); - glPixelStorei( GL_PACK_SKIP_PIXELS, 0 ); - //GLubyte *tempbitmap = (GLubyte *) malloc(m_bitmapInfo.bmiHeader.biWidth*m_bitmapInfo.bmiHeader.biHeight*4); - glReadPixels( 0,0, m_bitmapInfo.bmiHeader.biWidth,m_bitmapInfo.bmiHeader.biHeight, - GL_RGB, GL_UNSIGNED_BYTE, m_bitmap ); - } - else - { - //PRINT_BITMAP - memcpy( m_bitmap, bm, m_bitmapInfo.bmiHeader.biSizeImage ); - } - int i,j; - GLubyte *rgb, temp; - for ( i = 0; i < m_bitmapInfo.bmiHeader.biHeight; i++ ) - { - for ( j = 0, rgb = ((GLubyte *)m_bitmap) + i * m_bitmapInfo.bmiHeader.biWidth * 3; - j < m_bitmapInfo.bmiHeader.biWidth; - j++, rgb +=3 ) - { - temp = rgb[0]; - rgb[0] = rgb[2]; - rgb[2] = temp; - } - } - long width = m_pageWidth; - long height = width * m_bitmapInfo.bmiHeader.biHeight / m_bitmapInfo.bmiHeader.biWidth; - if ( height > m_pageHeight ) - { - height = m_pageHeight; - width = height * m_bitmapInfo.bmiHeader.biWidth / m_bitmapInfo.bmiHeader.biHeight; - } - long xoffset = (m_pageWidth - width) / 2; - long yoffset = (m_pageHeight - height) / 2; - StretchBlt( m_printDLG.hDC, xoffset, yoffset, width, height, m_bitmapDC, 0, 0, - m_bitmapInfo.bmiHeader.biWidth, m_bitmapInfo.bmiHeader.biHeight, SRCCOPY ); - } - if ( m_bitmapDC ) - { - DeleteDC( m_bitmapDC ); - } - if ( bitmapHandle ) - { - DeleteObject( bitmapHandle ); - } - if ( m_bitmapHGLRC ) - { - wglDeleteContext( m_bitmapHGLRC ); - } - } - - /* EndPage... */ - if ( EndPage( m_printDLG.hDC ) <=0 ) - { - printf( "EndPage() failed\n" ); - } - - /* EndDoc... */ - if ( EndDoc( m_printDLG.hDC ) <=0 ) - { - printf( "EndDoc() failed\n" ); - } - - // Delete the printer context when done with it - DeleteDC(m_printDLG.hDC); - - // Restore window rendering context - //wglMakeCurrent(hDC, hRC); - wglMakeCurrent( NULL, NULL ); - - } -}