source: OGRE/trunk/ogrenew/RenderSystems/GL/src/OgreGLGpuProgram.cpp @ 692

Revision 692, 4.7 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

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 "OgreGLGpuProgram.h"
27#include "OgreException.h"
28
29using namespace Ogre;
30
31GLGpuProgram::GLGpuProgram(ResourceManager* creator, const String& name,
32    ResourceHandle handle, const String& group, bool isManual,
33    ManualResourceLoader* loader)
34    : GpuProgram(creator, name, handle, group, isManual, loader)
35{
36    if (createParamDictionary("GLGpuProgram"))
37    {
38        setupBaseParamDictionary();
39    }
40}
41
42GLGpuProgram::~GLGpuProgram()
43{
44    // have to call this here reather than in Resource destructor
45    // since calling virtual methods in base destructors causes crash
46    unload();
47}
48
49GLArbGpuProgram::GLArbGpuProgram(ResourceManager* creator, const String& name,
50    ResourceHandle handle, const String& group, bool isManual,
51    ManualResourceLoader* loader)
52    : GLGpuProgram(creator, name, handle, group, isManual, loader)
53{
54    glGenProgramsARB(1, &mProgramID);
55}
56
57GLArbGpuProgram::~GLArbGpuProgram()
58{
59    // have to call this here reather than in Resource destructor
60    // since calling virtual methods in base destructors causes crash
61    unload();
62}
63
64void GLArbGpuProgram::setType(GpuProgramType t)
65{
66    GLGpuProgram::setType(t);
67    mProgramType = (mType == GPT_VERTEX_PROGRAM) ? GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
68}
69
70void GLArbGpuProgram::bindProgram(void)
71{
72    glEnable(mProgramType);
73    glBindProgramARB(mProgramType, mProgramID);
74}
75
76void GLArbGpuProgram::unbindProgram(void)
77{
78    glBindProgramARB(mProgramType, 0);
79    glDisable(mProgramType);
80}
81
82void GLArbGpuProgram::bindProgramParameters(GpuProgramParametersSharedPtr params)
83{
84    GLenum type = (mType == GPT_VERTEX_PROGRAM) ?
85        GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
86   
87    if (params->hasRealConstantParams())
88    {
89        // Iterate over params and set the relevant ones
90        GpuProgramParameters::RealConstantIterator realIt =
91            params->getRealConstantIterator();
92        unsigned int index = 0;
93        while (realIt.hasMoreElements())
94        {
95            const GpuProgramParameters::RealConstantEntry* e = realIt.peekNextPtr();
96            if (e->isSet)
97            {
98                glProgramLocalParameter4fvARB(type, index, e->val);
99            }
100            index++;
101            realIt.moveNext();
102        }
103    }
104
105}
106
107void GLArbGpuProgram::bindProgramPassIterationParameters(GpuProgramParametersSharedPtr params)
108{
109    GLenum type = (mType == GPT_VERTEX_PROGRAM) ?
110        GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
111   
112    GpuProgramParameters::RealConstantEntry* realEntry = params->getPassIterationEntry();
113
114    if (realEntry)
115    {
116        glProgramLocalParameter4fvARB(type, (GLuint)params->getPassIterationEntryIndex(), realEntry->val);
117    }
118
119}
120
121void GLArbGpuProgram::unloadImpl(void)
122{
123    glDeleteProgramsARB(1, &mProgramID);
124}
125
126void GLArbGpuProgram::loadFromSource(void)
127{
128    glBindProgramARB(mProgramType, mProgramID);
129    glProgramStringARB(mProgramType, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)mSource.length(), mSource.c_str());
130
131    if (GL_INVALID_OPERATION == glGetError())
132    {
133        GLint errPos;
134        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
135        char errPosStr[16];
136        snprintf(errPosStr, 16, "%d", errPos);
137        char* errStr = (char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
138        // XXX New exception code?
139        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
140            "Cannot load GL vertex program " + mName +
141            ".  Line " + errPosStr + ":\n" + errStr, mName);
142    }
143    glBindProgramARB(mProgramType, 0);
144}
145
Note: See TracBrowser for help on using the repository browser.