source: OGRE/trunk/ogrenew/RenderSystems/GL/src/OgreGLGpuNvparseProgram.cpp @ 657

Revision 657, 3.9 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.stevestreeting.com/ogre/
6
7Copyright (c) 2000-2005 The OGRE Teameeting
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
34using namespace Ogre;
35
36GLGpuNvparseProgram::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
44GLGpuNvparseProgram::~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
51void 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
59void 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
67void 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_ptr(combinerStage, pname, e->val);
86            }
87            index++;
88            realIt.moveNext();
89        }
90    }
91
92}
93void GLGpuNvparseProgram::unloadImpl(void)
94{
95    glDeleteLists(mProgramID,1);
96}
97
98void 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
Note: See TracBrowser for help on using the repository browser.