[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.stevestreeting.com/ogre/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Teameeting
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/gpl.html.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #include "OgreGLGpuNvparseProgram.h"
|
---|
| 27 | #include "OgreException.h"
|
---|
| 28 | #include "OgreRoot.h"
|
---|
| 29 | #include "OgreRenderSystem.h"
|
---|
| 30 | #include "OgreRenderSystemCapabilities.h"
|
---|
| 31 | #include "OgreLogManager.h"
|
---|
| 32 | #include "nvparse.h"
|
---|
| 33 |
|
---|
| 34 | using namespace Ogre;
|
---|
| 35 |
|
---|
| 36 | GLGpuNvparseProgram::GLGpuNvparseProgram(ResourceManager* creator,
|
---|
| 37 | const String& name, ResourceHandle handle,
|
---|
| 38 | const String& group, bool isManual, ManualResourceLoader* loader)
|
---|
| 39 | : GLGpuProgram(creator, name, handle, group, isManual, loader)
|
---|
| 40 | {
|
---|
| 41 | mProgramID = glGenLists(1);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | GLGpuNvparseProgram::~GLGpuNvparseProgram()
|
---|
| 45 | {
|
---|
| 46 | // have to call this here reather than in Resource destructor
|
---|
| 47 | // since calling virtual methods in base destructors causes crash
|
---|
| 48 | unload();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void GLGpuNvparseProgram::bindProgram(void)
|
---|
| 52 | {
|
---|
| 53 | glCallList(mProgramID);
|
---|
| 54 | glEnable(GL_TEXTURE_SHADER_NV);
|
---|
| 55 | glEnable(GL_REGISTER_COMBINERS_NV);
|
---|
| 56 | glEnable(GL_PER_STAGE_CONSTANTS_NV);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void GLGpuNvparseProgram::unbindProgram(void)
|
---|
| 60 | {
|
---|
| 61 |
|
---|
| 62 | glDisable(GL_TEXTURE_SHADER_NV);
|
---|
| 63 | glDisable(GL_REGISTER_COMBINERS_NV);
|
---|
| 64 | glDisable(GL_PER_STAGE_CONSTANTS_NV);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | void GLGpuNvparseProgram::bindProgramParameters(GpuProgramParametersSharedPtr params)
|
---|
| 68 | {
|
---|
| 69 | // NB, register combiners uses 2 constants per texture stage (0 and 1)
|
---|
| 70 | // We have stored these as (stage * 2) + const_index
|
---|
| 71 |
|
---|
| 72 | if (params->hasRealConstantParams())
|
---|
| 73 | {
|
---|
| 74 | // Iterate over params and set the relevant ones
|
---|
| 75 | GpuProgramParameters::RealConstantIterator realIt =
|
---|
| 76 | params->getRealConstantIterator();
|
---|
| 77 | unsigned int index = 0;
|
---|
| 78 | while (realIt.hasMoreElements())
|
---|
| 79 | {
|
---|
| 80 | const GpuProgramParameters::RealConstantEntry* e = realIt.peekNextPtr();
|
---|
| 81 | if (e->isSet)
|
---|
| 82 | {
|
---|
| 83 | GLenum combinerStage = GL_COMBINER0_NV + (unsigned int)(index / 2);
|
---|
| 84 | GLenum pname = GL_CONSTANT_COLOR0_NV + (index % 2);
|
---|
| 85 | glCombinerStageParameterfvNV(combinerStage, pname, e->val);
|
---|
| 86 | }
|
---|
| 87 | index++;
|
---|
| 88 | realIt.moveNext();
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | }
|
---|
| 93 | void GLGpuNvparseProgram::unloadImpl(void)
|
---|
| 94 | {
|
---|
| 95 | glDeleteLists(mProgramID,1);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void GLGpuNvparseProgram::loadFromSource(void)
|
---|
| 99 | {
|
---|
| 100 | glNewList(mProgramID, GL_COMPILE);
|
---|
| 101 |
|
---|
| 102 | String::size_type pos = mSource.find("!!");
|
---|
| 103 |
|
---|
| 104 | while (pos != String::npos) {
|
---|
| 105 | String::size_type newPos = mSource.find("!!", pos + 1);
|
---|
| 106 |
|
---|
| 107 | String script = mSource.substr(pos, newPos - pos);
|
---|
| 108 | nvparse(script.c_str(), 0);
|
---|
| 109 |
|
---|
| 110 | for (char* const * errors= nvparse_get_errors(); *errors; errors++)
|
---|
| 111 | {
|
---|
| 112 | LogManager::getSingleton().logMessage("Warning: nvparse reported the following errors:");
|
---|
| 113 | LogManager::getSingleton().logMessage("\t" + String(*errors));
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | pos = newPos;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | glEndList();
|
---|
| 120 | }
|
---|
| 121 |
|
---|