From: Oliver O. <fr...@us...> - 2007-03-15 07:27:06
|
Update of /cvsroot/simspark/simspark/spark/kerosin/openglserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7790/spark/kerosin/openglserver Modified Files: openglserver.cpp openglserver.h openglsystem.h Added Files: openglwrapper.h Log Message: Merged WIN32 branch back to main trunk (access previous version with tag pre_merge_WIN32) Index: openglserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/openglserver/openglserver.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** openglserver.cpp 5 Dec 2005 21:38:23 -0000 1.1 --- openglserver.cpp 15 Mar 2007 07:26:26 -0000 1.2 *************** *** 20,25 **** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - #include "openglserver.h" #include "openglsystem.h" #include <zeitgeist/scriptserver/scriptserver.h> --- 20,25 ---- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "openglserver.h" + #include "openglwrapper.h" #include "openglsystem.h" #include <zeitgeist/scriptserver/scriptserver.h> *************** *** 29,32 **** --- 29,51 ---- using namespace std; + #ifdef __APPLE__ + // code below from http://developer.apple.com/qa/qa2001/qa1188.html + #import <mach-o/dyld.h> + void *NSGLGetProcAddress(const char *name) + { + NSSymbol symbol; + char *symbolName; + // Prepend a '_' for the Unix C symbol mangling convention + symbolName = (char*) malloc (strlen (name) + 2); + strcpy(symbolName + 1, name); + symbolName[0] = '_'; + symbol = NULL; + if (NSIsSymbolNameDefined (symbolName)) + symbol = NSLookupAndBindSymbol (symbolName); + free (symbolName); + return symbol ? NSAddressOfSymbol (symbol) : NULL; + } + #endif + namespace kerosin { *************** *** 48,53 **** using namespace zeitgeist; ! OpenGLServer::OpenGLServer() : Leaf(), mExtensionReg(new GLExtensionReg()), ! mWantsToQuit(false), mHolder( new MapHolder() ) { } --- 67,71 ---- using namespace zeitgeist; ! OpenGLServer::OpenGLServer() : Leaf(), mWantsToQuit(false), mHolder( new MapHolder() ) { } *************** *** 57,65 **** } - boost::shared_ptr<GLExtensionReg> OpenGLServer::GetExtensionReg() const - { - return mExtensionReg; - } - void OpenGLServer::Quit() { --- 75,78 ---- *************** *** 92,179 **** } - unsigned int OpenGLServer::LoadARBProgram(GLenum /*target*/, const char* /*fileName*/) - { - #if 0 - // only try to load stuff if the extension is supported - if (!mExtensionReg->Has_GL_ARB_vertex_program()) - { - return 0; - } - - // before actually loading, try the cache - MapHolder::TProgramCache::iterator entry = mHolder->mPrograms.find(fileName); - - if (entry != mHolder->mPrograms.end()) - { - // we already have a match - return (*entry).second; - } - - unsigned int id = 0; - - // open file - shared_ptr<FileServer> fileServer = shared_static_cast<FileServer>(GetCore()->Get("/sys/server/file")); - salt::RFile *file = fileServer->Open(fileName); - - if (!file) return 0; - - unsigned char *buffer = new unsigned char[file->Size()+1]; - file->Read(buffer, file->Size()); - - glGenProgramsARB(1, &id); - glBindProgramARB(target, id); - - // try to load the actual program - glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, file->Size(), buffer); - - // free memory - delete file; - delete []buffer; - - const unsigned char* error = glGetString(GL_PROGRAM_ERROR_STRING_ARB); - - // if an error occured, display error message - if (error[0] != 0) - { - int i; - glDeleteProgramsARB(1, &id); - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &i); - GetCore()->GetLogServer()->Error() << "ERROR: Loading ARB program (Pos: " << i << ")..." << endl; - GetCore()->GetLogServer()->Error() << " => " << error << endl; - return 0; - } - - // enter program into the cache - mHolder->mPrograms[fileName] = id; - - return id; - #else - return 0; - #endif - } - - unsigned int OpenGLServer::LoadARBVertexProgram(const char* fileName) - { - // only try to load stuff if the extension is supported - if (!mExtensionReg->Has_GL_ARB_vertex_program()) - { - return 0; - } - - return LoadARBProgram(GL_VERTEX_PROGRAM_ARB, fileName); - } - - unsigned int OpenGLServer::LoadARBFragmentProgram(const char* /*fileName*/) - { - // only try to load stuff if the extension is supported - // if (!mExtensionReg->Has_GL_ARB_fragment_program()) - // { - // return 0; - // } - - // return LoadARBProgram(GL_FRAGMENT_PROGRAM_ARB, fileName); - return 0; - } - bool OpenGLServer::Init(const string& openGLSysName) { --- 105,108 ---- *************** *** 203,212 **** } - mExtensionReg->Init(); - - // if (!mExtensionReg->Has_GL_ARB_vertex_program() || !mExtensionReg->Has_GL_ARB_fragment_program()) - // { - // GetLog()->Normal() << "WARNING: GL_ARB_vertex_program not supported. " - // << "disabling fancy lighting\n" << endl; mSupportsFancyLighting = false; --- 132,135 ---- *************** *** 228,239 **** } - void OpenGLServer::ToggleFancyLighting() - { - if (mSupportsFancyLighting) - mSupportsFancyLighting = false; - else - mSupportsFancyLighting = true; - } - int OpenGLServer::AllocLight() --- 151,154 ---- *************** *** 258,260 **** --- 173,207 ---- } + // Maybe see also http://rainwarrior.thenoos.net/dragon/sdl_glsl.html + // and http://www.evl.uic.edu/arao/cs594/sdlglsl.html to rework the stuff here more platform independently + // The code below uses stuff from the apple developer website (hidden in openglwrapper.h) + void* OpenGLServer::GetExtension(const char* name) + { + #ifdef WIN32 + return wglGetProcAddress(name); + #elif defined(__APPLE__) + return NSGLGetProcAddress(name); + #else + return glXGetProcAddressARB((unsigned char*)name); + #endif + } + #define PROC_ADDRESS(_ptr, _function)\ + static _ptr proc = (_ptr) GetExtension(#_function); + + void OpenGLServer::glActiveTextureARB(unsigned int texture) + { + #ifdef __APPLE__ + // this is ugly, but I don't know where are the function prototypes in mac os X? + return ::glActiveTextureARB(texture); + #else + PROC_ADDRESS(PFNGLACTIVETEXTUREARBPROC, "glActiveTextureARB"); + + if (! proc) + { + return; + } + + (proc)(static_cast<GLenum>(texture)); + #endif + } Index: openglsystem.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/openglserver/openglsystem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** openglsystem.h 5 Dec 2005 21:38:23 -0000 1.1 --- openglsystem.h 15 Mar 2007 07:26:26 -0000 1.2 *************** *** 51,55 **** protected: - // // members --- 51,54 ---- --- NEW FILE: openglwrapper.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: openglwrapper.h,v 1.2 2007/03/15 07:26:26 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_OPENGLWRAPPER_H #define KEROSIN_OPENGLWRAPPER_H #define GL_GLEXT_PROTOTYPES #ifdef WIN32 #define WIN32_LEAN_AND_MEAN 1 #include <windows.h> #endif #ifdef __APPLE__ #include <OpenGL/gl.h> #include <OpenGL/glext.h> #else #include <GL/gl.h> #include <GL/glext.h> #endif #if defined(WIN32) #include <GL/wglext.h> #elif defined(__APPLE__) /* nothing here */ #else #include <GL/glx.h> #include <GL/glxext.h> #endif #endif // KEROSIN_OPENGLWRAPPER_H Index: openglserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/openglserver/openglserver.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** openglserver.h 5 Dec 2005 21:38:23 -0000 1.1 --- openglserver.h 15 Mar 2007 07:26:26 -0000 1.2 *************** *** 27,31 **** #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> - #include "glextensionreg.h" namespace kerosin --- 27,30 ---- *************** *** 44,54 **** // protected: - //! this structure will be used to map program names to OpenGL IDs - // #if HAVE_HASH_MAP - // typedef std::hash_map<std::string, unsigned int> TProgramCache; - // #else - // typedef std::map<std::string, unsigned int> TProgramCache; - // #endif - //! set of OpenGL light constants typedef std::set<int> TLightSet; --- 43,46 ---- *************** *** 68,73 **** bool Init(const std::string& openGLSysName); - boost::shared_ptr<GLExtensionReg> GetExtensionReg() const; - //! if this is called, the application will 'want to quit' void Quit(); --- 60,63 ---- *************** *** 82,97 **** void SwapBuffers() const; - //! vertex and fragment program loading - unsigned int LoadARBProgram(GLenum target, const char* fileName); - - //! vertex and fragment program loading - unsigned int LoadARBVertexProgram(const char* fileName); - - //! vertex and fragment program loading - unsigned int LoadARBFragmentProgram(const char* fileName); - - bool SupportsFancyLighting() const { return mSupportsFancyLighting; } - void ToggleFancyLighting(); - /** returns the next availble GL light constant or -1 if no more lights are available --- 72,75 ---- *************** *** 102,105 **** --- 80,89 ---- void PutLight(int l); + /** returns the address of an OpenGL extension by name */ + static void* GetExtension(const char* name); + + /** looksup and calls glActiveTextureARB extension if available */ + static void glActiveTextureARB(unsigned int texture); + protected: //! set up opengl viewport *************** *** 110,116 **** // protected: - //! this contains information on all available extensions - boost::shared_ptr<GLExtensionReg> mExtensionReg; - //! a flag, which can be used to control the shutdown of the display window and the application bool mWantsToQuit; --- 94,97 ---- |