Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

vertexprog.cpp File Reference

#include <iostream>
#include <fstream>
#include <string>
#include <celutil/util.h>
#include "gl.h"
#include "glext.h"
#include "vertexprog.h"

Include dependency graph for vertexprog.cpp:

Go to the source code of this file.

Functions

static int findLineNumber (const string &s, int index)
static bool LoadARBVertexProgram (const string &filename, unsigned int &id)
static bool LoadNvVertexProgram (const string &filename, unsigned int &id)
static stringReadTextFromFile (const string &filename)

Variables

static unsigned int parameterMappings []


Function Documentation

static int findLineNumber const string s,
int  index
[static]
 

Definition at line 138 of file vertexprog.cpp.

00139 {
00140     if (index >= (int)s.length())
00141         return -1;
00142 
00143     int lineno = 1;
00144     for (int i = 0; i < index; i++)
00145     {
00146         if (s[i] == '\n')
00147             lineno++;
00148     }
00149 
00150     return lineno;
00151 }

static bool LoadARBVertexProgram const string filename,
unsigned int &  id
[static]
 

Definition at line 154 of file vertexprog.cpp.

References _, findLineNumber(), GL_PROGRAM_ERROR_POSITION_ARB, GL_PROGRAM_ERROR_STRING_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, GL_VERTEX_PROGRAM_ARB, glx::glBindProgramARB, glx::glGenProgramsARB, glx::glProgramStringARB, and ReadTextFromFile().

Referenced by vp::initARB().

00155 {
00156     cout << _("Loading ARB vertex program: ") << filename << '\n';
00157 
00158     string* source = ReadTextFromFile(filename);
00159     if (source == NULL)
00160     {
00161         cout << _("Error loading ARB vertex program: ") << filename << '\n';
00162         return false;
00163     }
00164 
00165     glx::glGenProgramsARB(1, (GLuint*) &id);
00166     if (glGetError() != GL_NO_ERROR)
00167     {
00168         delete source;
00169         return false;
00170     }
00171 
00172     glx::glBindProgramARB(GL_VERTEX_PROGRAM_ARB, id);
00173     glx::glProgramStringARB(GL_VERTEX_PROGRAM_ARB,
00174                             GL_PROGRAM_FORMAT_ASCII_ARB,
00175                             source->length(),
00176                             reinterpret_cast<const GLubyte*>(source->c_str()));
00177 
00178     GLenum err = glGetError();
00179     if (err != GL_NO_ERROR)
00180     {
00181         GLint errPos = 0;
00182         glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
00183 
00184         const char* errMsg = (const char*) glGetString(GL_PROGRAM_ERROR_STRING_ARB);
00185         if (errMsg == NULL)
00186             errMsg = "Unknown error";
00187         
00188         cout << _("Error in vertex program ") << filename <<
00189             _(", line ") << findLineNumber(*source, errPos) << ": " << errMsg << '\n';
00190     }
00191 
00192     delete source;
00193 
00194     return err == GL_NO_ERROR;
00195 }

static bool LoadNvVertexProgram const string filename,
unsigned int &  id
[static]
 

Definition at line 105 of file vertexprog.cpp.

References _, GL_PROGRAM_ERROR_POSITION_NV, GL_VERTEX_PROGRAM_NV, glx::glGenProgramsNV, glx::glLoadProgramNV, and ReadTextFromFile().

Referenced by vp::initNV().

00106 {
00107     cout << _("Loading NV vertex program: ") << filename << '\n';
00108 
00109     string* source = ReadTextFromFile(filename);
00110     if (source == NULL)
00111     {
00112         cout << _("Error loading NV vertex program: ") << filename << '\n';
00113         return false;
00114     }
00115 
00116     glx::glGenProgramsNV(1, (GLuint*) &id);
00117     glx::glLoadProgramNV(GL_VERTEX_PROGRAM_NV,
00118                          id,
00119                          source->length(),
00120                          reinterpret_cast<const GLubyte*>(source->c_str()));
00121 
00122     delete source;
00123 
00124     GLenum err = glGetError();
00125     if (err != GL_NO_ERROR)
00126     {
00127         GLint errPos = 0;
00128         glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errPos);
00129         cout << _("Error in vertex program ") << filename <<
00130             " @ " << errPos << '\n';
00131         return false;
00132     }
00133 
00134     return true;
00135 }

static string* ReadTextFromFile const string filename  )  [static]
 

Definition at line 89 of file vertexprog.cpp.

00090 {
00091     ifstream textFile(filename.c_str(), ios::in);
00092     if (!textFile.good())
00093         return NULL;
00094 
00095     string* s = new string();
00096 
00097     char c;
00098     while (textFile.get(c))
00099         *s += c;
00100 
00101     return s;
00102 }


Variable Documentation

unsigned int parameterMappings[] [static]
 

Initial value:

 
{
    16, 
    15, 
    20, 
    34, 
    40, 
    32, 
    33, 
    41, 
    90, 
     0, 
    41, 
    42, 
     0, 
     0, 
     0, 
     0, 
     0, 
     0, 
    50, 
    51, 
    52, 
}

Definition at line 398 of file vertexprog.cpp.

Referenced by VertexProcessorNV::parameter().


Generated on Sat Jan 14 22:31:30 2006 for Celestia by  doxygen 1.4.1