Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreGLGpuProgram.cpp

Go to the documentation of this file.

    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 "OgreGLGpuProgram.h"
    00027 #include "OgreException.h"
    00028
    00029 using namespace Ogre;
    00030
    00031 GLGpuProgram::GLGpuProgram(const String& name, GpuProgramType gptype, const String& syntaxCode) :
    00032     GpuProgram(name, gptype, syntaxCode)
    00033 {
    00034 }
    00035
    00036 GLArbGpuProgram::GLArbGpuProgram(const String& name, GpuProgramType gptype, const String& syntaxCode) :
    00037     GLGpuProgram(name, gptype, syntaxCode)
    00038 {
    00039     mProgramType = (gptype == GPT_VERTEX_PROGRAM) ? GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
    00040     glGenProgramsARB_ptr(1, &mProgramID);
    00041 }
    00042
    00043 void GLArbGpuProgram::bindProgram(void)
    00044 {
    00045     glEnable(mProgramType);
    00046     glBindProgramARB_ptr(mProgramType, mProgramID);
    00047 }
    00048
    00049 void GLArbGpuProgram::unbindProgram(void)
    00050 {
    00051     glBindProgramARB_ptr(mProgramType, 0);
    00052     glDisable(mProgramType);
    00053 }
    00054
    00055 void GLArbGpuProgram::bindProgramParameters(GpuProgramParametersSharedPtr params)
    00056 {
    00057     GLenum type = (mType == GPT_VERTEX_PROGRAM) ?
    00058         GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
    00059
    00060     if (params->hasRealConstantParams())
    00061     {
    00062         // Iterate over params and set the relevant ones
    00063         GpuProgramParameters::RealConstantIterator realIt =
    00064             params->getRealConstantIterator();
    00065         unsigned int index = 0;
    00066         while (realIt.hasMoreElements())
    00067         {
    00068             const GpuProgramParameters::RealConstantEntry* e = realIt.peekNextPtr();
    00069             if (e->isSet)
    00070             {
    00071                 glProgramLocalParameter4fvARB_ptr(type, index, e->val);
    00072             }
    00073             index++;
    00074             realIt.moveNext();
    00075         }
    00076     }
    00077
    00078 }
    00079
    00080 void GLArbGpuProgram::unload(void)
    00081 {
    00082     glDeleteProgramsARB_ptr(1, &mProgramID);
    00083 }
    00084
    00085 void GLArbGpuProgram::loadFromSource(void)
    00086 {
    00087     glBindProgramARB_ptr(mProgramType, mProgramID);
    00088     glProgramStringARB_ptr(mProgramType, GL_PROGRAM_FORMAT_ASCII_ARB, mSource.length(), mSource.c_str());
    00089     if (GL_INVALID_OPERATION == glGetError())
    00090     {
    00091         int errPos;
    00092         glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
    00093         char errPosStr[16];
    00094         snprintf(errPosStr, 16, "%d", errPos);
    00095         char* errStr = (char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
    00096         // XXX New exception code?
    00097         Except(Exception::ERR_INTERNAL_ERROR,
    00098             "Cannot load GL vertex program " + mName +
    00099             ".  Line " + errPosStr + ":\n" + errStr, mName);
    00100     }
    00101     glBindProgramARB_ptr(mProgramType, 0);
    00102 }
    00103

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:25 2004