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

Revision 657, 4.3 KB checked in by mattausch, 19 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 "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_ptr(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_ptr(mProgramType, mProgramID);
74}
75
76void GLArbGpuProgram::unbindProgram(void)
77{
78    glBindProgramARB_ptr(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_ptr(type, index, e->val);
99            }
100            index++;
101            realIt.moveNext();
102        }
103    }
104
105}
106
107void GLArbGpuProgram::unloadImpl(void)
108{
109    glDeleteProgramsARB_ptr(1, &mProgramID);
110}
111
112void GLArbGpuProgram::loadFromSource(void)
113{
114    glBindProgramARB_ptr(mProgramType, mProgramID);
115    glProgramStringARB_ptr(mProgramType, GL_PROGRAM_FORMAT_ASCII_ARB, mSource.length(), mSource.c_str());
116    if (GL_INVALID_OPERATION == glGetError())
117    {
118        GLint errPos;
119        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
120        char errPosStr[16];
121        snprintf(errPosStr, 16, "%d", errPos);
122        char* errStr = (char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
123        // XXX New exception code?
124        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
125            "Cannot load GL vertex program " + mName +
126            ".  Line " + errPosStr + ":\n" + errStr, mName);
127    }
128    glBindProgramARB_ptr(mProgramType, 0);
129}
130
Note: See TracBrowser for help on using the repository browser.