From: Markus R. <rol...@us...> - 2005-12-05 21:38:31
|
Update of /cvsroot/simspark/simspark/spark/kerosin/openglserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19774/openglserver Added Files: .cvsignore glbase.h glextensionreg.cpp glextensionreg.h openglserver.cpp openglserver.h openglserver_c.cpp openglsystem.h openglsystem_c.cpp Log Message: --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs glextensionreg.cpp glextensionreg.h --- NEW FILE: openglsystem_c.cpp --- /* -*- 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: openglsystem_c.cpp,v 1.1 2005/12/05 21:38:23 rollmark 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. */ #include "openglsystem.h" using namespace kerosin; void CLASS(OpenGLSystem)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Node); } --- NEW FILE: glextensionreg.h --- #line 2 "utility/glextgen/tocopy/header_begin.txt" #ifndef GLEXTENSIONREG_H__ #define GLEXTENSIONREG_H__ #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) #define WIN32_LEAN_AND_MEAN 1 #include <windows.h> #endif #define GL_GLEXT_PROTOTYPES #include <GL/gl.h> #include <GL/glext.h> #if defined(_WIN32) #include <GL/wglext.h> #else #include <GL/glx.h> #include <GL/glxext.h> [...1043 lines suppressed...] #endif //_WIN32 GLExtensionReg(); ~GLExtensionReg(); void Init(GLExtGenFunctionPointers *funPtr = 0, GLExtGenExtensions *ext = 0); bool QueryGLExtension(const char *name); #if defined(_WIN32) bool QueryWGLExtension(const char *name); HDC GetHDC() const { return mHDC; } void SetHDC(HDC hdc){ mHDC = hdc; } #endif //_WIN32 }; } // end kerosin #line 141 "utility/glextgen/script/glbackend.rb" #if defined(_WIN32) #line 146 "utility/glextgen/script/glbackend.rb" #endif //_WIN32 #line 2 "utility/glextgen/tocopy/header_end.txt" #endif //GLEXTENSIONREG_H__ --- NEW FILE: openglsystem.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: openglsystem.h,v 1.1 2005/12/05 21:38:23 rollmark 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_OPENGLSYSTEM_H #define KEROSIN_OPENGLSYSTEM_H /* \class OpenGLSystem HISTORY: 04.12.05 - Initial version */ #include <zeitgeist/node.h> namespace kerosin { class OpenGLSystem : public zeitgeist::Node { // // functions // public: //! init the opengl subsystem virtual bool Init() = 0; //! called periodically to allow for any event processing virtual void Update() = 0; /** called after each frame in order to swap buffer in OpenGLSystems that support double buffering */ virtual void SwapBuffers() = 0; protected: // // members // protected: }; DECLARE_ABSTRACTCLASS(OpenGLSystem); } // namespace kerosin #endif //KEROSIN_OPENGLSYSTEM_H --- NEW FILE: glbase.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: glbase.h,v 1.1 2005/12/05 21:38:23 rollmark 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_GLBASE_H #define KEROSIN_GLBASE_H namespace kerosin { class RGBA { public: union { float v[4]; struct { float r; float g; float b; float a; } c; } data; public: RGBA() { data.c.r = 1.0f; data.c.g = 1.0f; data.c.b = 1.0f; data.c.a = 1.0f; } RGBA(float rr, float gg, float bb, float aa) { data.c.r = rr; data.c.g = gg; data.c.b = bb; data.c.a = aa; } float& r() { return data.c.r; } float& g() { return data.c.g; } float& b() { return data.c.b; } float& a() { return data.c.a; } const float& r() const { return data.c.r; } const float& g() const { return data.c.g; } const float& b() const { return data.c.b; } const float& a() const { return data.c.a; } float* v() { return data.v; } const float* v() const { return data.v; } operator float* () { return data.v; } operator const float*() const { return data.v; } }; }; #endif // KEROSIN_GLBASE_H --- NEW FILE: openglserver.cpp --- /* -*- 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: openglserver.cpp,v 1.1 2005/12/05 21:38:23 rollmark 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. */ #include "openglserver.h" #include "openglsystem.h" #include <zeitgeist/scriptserver/scriptserver.h> #include <zeitgeist/fileserver/fileserver.h> #include <zeitgeist/logserver/logserver.h> using namespace std; namespace kerosin { class MapHolder { public: //! this structure will be used to map program names to OpenGL IDs #if HAVE_HASH_MAP typedef hash_map<string, unsigned int> TProgramCache; #else typedef map<string, unsigned int> TProgramCache; #endif TProgramCache mPrograms; }; } using namespace boost; using namespace kerosin; using namespace zeitgeist; OpenGLServer::OpenGLServer() : Leaf(), mExtensionReg(new GLExtensionReg()), mWantsToQuit(false), mHolder( new MapHolder() ) { } OpenGLServer::~OpenGLServer() { } boost::shared_ptr<GLExtensionReg> OpenGLServer::GetExtensionReg() const { return mExtensionReg; } void OpenGLServer::Quit() { mWantsToQuit = true; } bool OpenGLServer::WantsToQuit() const { return mWantsToQuit; } void OpenGLServer::Update() { if (mGLSystem.get() == 0) { return; } mGLSystem->Update(); } void OpenGLServer::SwapBuffers() const { if (mGLSystem.get() == 0) { return; } mGLSystem->SwapBuffers(); } 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) { GetLog()->Normal() << "(OpenGLServer) Init " << openGLSysName << "\n"; mGLSystem.reset(); if (! openGLSysName.empty()) { // create the OpenGLSystem mGLSystem = shared_dynamic_cast<OpenGLSystem> (GetCore()->New(openGLSysName)); if(mGLSystem.get() == 0) { // could not create OpenGLSystem GetLog()->Error() << "(OpenGLServer) ERROR: unable to create " << openGLSysName << "\n"; return false; } if (mGLSystem->Init() == false) { GetLog()->Error() << "(InputServer) ERROR: unable to initialize " << openGLSysName << "\n"; return false; } } 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; // prepare the set of available lights for (int i=0;i<GL_MAX_LIGHTS;++i) { mAvailableLights.insert(GL_LIGHT0+i); } return true; } /*! Set up the OpenGL viewport, initialize extension registry */ bool OpenGLServer::ConstructInternal() { return true; } void OpenGLServer::ToggleFancyLighting() { if (mSupportsFancyLighting) mSupportsFancyLighting = false; else mSupportsFancyLighting = true; } int OpenGLServer::AllocLight() { if (mAvailableLights.size() == 0) { return -1; } TLightSet::iterator iter = mAvailableLights.begin(); int l = (*iter); mAvailableLights.erase(iter); return l; } void OpenGLServer::PutLight(int l) { glDisable(l); mAvailableLights.insert(l); } --- NEW FILE: openglserver_c.cpp --- #include "openglserver.h" using namespace std; using namespace boost; using namespace kerosin; using namespace zeitgeist; FUNCTION(OpenGLServer,init) { string openGLSysName; return ( (in.GetSize() == 1) && (in.GetValue(in.begin(), openGLSysName)) && (obj->Init(openGLSysName)) ); } void CLASS(OpenGLServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); DEFINE_FUNCTION(init); } --- NEW FILE: glextensionreg.cpp --- #line 241 "utility/glextgen/script/glbackend.rb" #include "glextensionreg.h" using namespace kerosin; #line 2 "utility/glextgen/tocopy/cpp_begin.txt" #include <string.h> #if !defined(_WIN32) #include <GL/glx.h> #include <GL/glxext.h> #endif #define GET_PROC_ADDRESS(ptr, function) function = (ptr)GetProcedure( #function ); if (function == NULL) return false; void* GetProcedure(const char *name) { #if defined(_WIN32) void *t = wglGetProcAddress(name); [...3385 lines suppressed...] wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) GetProcedure("wglGetExtensionsStringEXT"); mExtensions.mWGL_ARB_extensions_string = wglGetExtensionsStringARB != NULL; mExtensions.mWGL_EXT_extensions_string = wglGetExtensionsStringEXT != NULL; #line 304 "utility/glextgen/script/glbackend.rb" #endif //_WIN32 if (ext) memcpy(ext, &mExtensions, sizeof(GLExtGenExtensions)); if (funPtr) { #line 313 "utility/glextgen/script/glbackend.rb" #if defined(_WIN32) #line 316 "utility/glextgen/script/glbackend.rb" #endif //_WIN32 } } --- NEW FILE: openglserver.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: openglserver.h,v 1.1 2005/12/05 21:38:23 rollmark 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_OPENGLSERVER_H #define KEROSIN_OPENGLSERVER_H #include <string> #include <set> #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> #include "glextensionreg.h" namespace kerosin { #if 0 } #endif class MapHolder; class OpenGLSystem; class OpenGLServer : public zeitgeist::Leaf { // // types // 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; // // functions // public: OpenGLServer(); ~OpenGLServer(); /** Initializes the OpenGLServer and sets up the OpenGLSystem with the given class name. Passing an empty string for openGLSysName is correct. In this case OpenGLServer assumes, that the OpenGL context is already setup */ bool Init(const std::string& openGLSysName); boost::shared_ptr<GLExtensionReg> GetExtensionReg() const; //! if this is called, the application will 'want to quit' void Quit(); //! true if somebody called 'Quit' bool WantsToQuit() const; //! pump event loop of OpenGLSubSystem void Update(); //! swap opengl buffer 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 */ int AllocLight(); /** marks the GL light constant as available */ void PutLight(int l); protected: //! set up opengl viewport virtual bool ConstructInternal(); // // members // 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; //! cache of loaded vertex and fragment programs (assumes that path names to the programs are unique) boost::shared_ptr< MapHolder > mHolder; //! flag whether the OpenGL-driver can do fancy lighting or not bool mSupportsFancyLighting; //! the set of available OpenGL light constants TLightSet mAvailableLights; //! the OpenGL subsystem used boost::shared_ptr<OpenGLSystem> mGLSystem; }; DECLARE_CLASS(OpenGLServer); } //namespace kerosin #endif //KEROSIN_OPENGLSERVER_H |