00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.stevestreeting.com/ogre/ 00006 00007 Copyright © 2000-2003 The OGRE Teameeting 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/gpl.html. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include "OgreGLGpuNvparseProgram.h" 00027 #include "OgreException.h" 00028 #include "OgreRoot.h" 00029 #include "OgreRenderSystem.h" 00030 #include "OgreRenderSystemCapabilities.h" 00031 #include "OgreLogManager.h" 00032 #include "nvparse.h" 00033 00034 using namespace Ogre; 00035 00036 GLGpuNvparseProgram::GLGpuNvparseProgram(const String& name, GpuProgramType gptype, const String& syntaxCode) : 00037 GLGpuProgram(name, gptype, syntaxCode) 00038 { 00039 mProgramID = glGenLists(1); 00040 } 00041 00042 void GLGpuNvparseProgram::bindProgram(void) 00043 { 00044 glCallList(mProgramID); 00045 glEnable(GL_TEXTURE_SHADER_NV); 00046 glEnable(GL_REGISTER_COMBINERS_NV); 00047 glEnable(GL_PER_STAGE_CONSTANTS_NV); 00048 } 00049 00050 void GLGpuNvparseProgram::unbindProgram(void) 00051 { 00052 00053 glDisable(GL_TEXTURE_SHADER_NV); 00054 glDisable(GL_REGISTER_COMBINERS_NV); 00055 glDisable(GL_PER_STAGE_CONSTANTS_NV); 00056 } 00057 00058 void GLGpuNvparseProgram::bindProgramParameters(GpuProgramParametersSharedPtr params) 00059 { 00060 // NB, register combiners uses 2 constants per texture stage (0 and 1) 00061 // We have stored these as (stage * 2) + const_index 00062 00063 if (params->hasRealConstantParams()) 00064 { 00065 // Iterate over params and set the relevant ones 00066 GpuProgramParameters::RealConstantIterator realIt = 00067 params->getRealConstantIterator(); 00068 unsigned int index = 0; 00069 while (realIt.hasMoreElements()) 00070 { 00071 GpuProgramParameters::RealConstantEntry* e = realIt.peekNextPtr(); 00072 if (e->isSet) 00073 { 00074 GLenum combinerStage = GL_COMBINER0_NV + (unsigned int)(index / 2); 00075 GLenum pname = GL_CONSTANT_COLOR0_NV + (index % 2); 00076 glCombinerStageParameterfvNV_ptr(combinerStage, pname, e->val); 00077 } 00078 index++; 00079 realIt.moveNext(); 00080 } 00081 } 00082 00083 } 00084 void GLGpuNvparseProgram::unload(void) 00085 { 00086 glDeleteLists(mProgramID,1); 00087 } 00088 00089 void GLGpuNvparseProgram::loadFromSource(void) 00090 { 00091 glNewList(mProgramID, GL_COMPILE); 00092 00093 String::size_type pos = mSource.find("!!"); 00094 00095 while (pos != String::npos) { 00096 String::size_type newPos = mSource.find("!!", pos + 1); 00097 00098 String script = mSource.substr(pos, newPos - pos); 00099 nvparse(script.c_str(), 0); 00100 00101 for (char* const * errors= nvparse_get_errors(); *errors; errors++) 00102 { 00103 LogManager::getSingleton().logMessage("Warning: nvparse reported the following errors:"); 00104 LogManager::getSingleton().logMessage("\t" + String(*errors)); 00105 } 00106 00107 pos = newPos; 00108 } 00109 00110 glEndList(); 00111 } 00112
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:11 2004