source: OGRE/trunk/ogrenew/RenderSystems/GL/src/nvparse/vsp1.0_impl.cpp @ 657

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

added ogre dependencies and patched ogre sources

Line 
1#include "nvparse_errors.h"
2#include "nvparse_externs.h"
3#include <string.h>
4#include <string>
5#include <ctype.h>
6
7#include <OgreGLPrerequisites.h>
8#include <GL/glu.h>
9
10using namespace std;
11
12
13namespace
14{
15        void LoadProgram( GLenum target, GLuint id, char *instring );
16        void StrToUpper(char * string);
17}
18
19
20bool is_vsp10(const char * s)
21{
22        return ! strncmp(s, "!!VSP1.0", 8);
23}
24
25bool vsp10_init(char * s)
26{
27        static bool vpinit = false;
28        if (vpinit == false )
29        {
30      /*
31                if(! glh_init_extensions("GL_NV_vertex_program"))
32                {
33                        errors.set("unable to initialize GL_NV_vertex_program");
34                        return false;
35                }
36                else
37                {
38        */
39                        vpinit = true;
40            /*
41                }
42        */
43        }
44       
45        errors.reset();
46        line_number = 1;
47        myin = s;
48       
49        return true;   
50}
51
52int vsp10_parse(int vpsid)
53{
54    LoadProgram( GL_VERTEX_STATE_PROGRAM_NV, vpsid, myin );
55        return 0;
56}
57
58namespace
59{
60        //.----------------------------------------------------------------------------.
61        //|   Function   : LoadProgram                                                 |
62        //|   Description: Load a program into GL, and report any errors encountered.  |
63        //.----------------------------------------------------------------------------.
64        void LoadProgram( GLenum target, GLuint id, char *instring )
65        {
66                GLint  errPos;
67                GLenum errCode;
68                const GLubyte *errString;
69               
70                int len = strlen(instring);
71                glLoadProgramNV_ptr( target, id, len, (const GLubyte *) instring );
72                if ( (errCode = glGetError()) != GL_NO_ERROR )
73                {
74                        errString = gluErrorString( errCode );
75                       
76                        glGetIntegerv( GL_PROGRAM_ERROR_POSITION_NV, &errPos );
77                       
78                        int nlines = 1;
79                        int nchar  = 1;
80                        int i;
81                        for ( i = 0; i < errPos; i++ )
82                        {
83                                if ( instring[i] == '\n' )
84                                {
85                                        nlines++;
86                                        nchar = 1;
87                                }
88                                else
89                                {
90                                        nchar++;
91                                }
92                        }
93                        int start;
94                        int end;
95                        int flag = ((instring[errPos]==';') | (instring[errPos-1]==';')) ? 1 : 0;
96                        for ( i = errPos; i >= 0; i-- )
97                        {
98                                start = i;
99                                if ( flag && (start >= errPos-1)  )
100                                        continue;
101                                if ( instring[i] == ';' )
102                                {
103                                        if ( !flag )
104                                        {
105                                                start = i+1;
106                                                if ( instring[start] == '\n' )
107                                                        start++;
108                                        }
109                                        break;
110                                }
111                        }
112                        for ( i = errPos; i < len; i++ )
113                        {
114                                end = i;
115                                if ( instring[i] == ';' && end > start)
116                                {
117                                        break;
118                                }
119                        }
120                        if ( errPos - start > 30 )
121                        {
122                                start = errPos - 30;
123                        }
124                        if ( end - errPos > 30 )
125                        {
126                                end = errPos + 30;
127                        }
128                       
129                        char substring[96];
130                        memset( substring, 0, 96 );
131                        strncpy( substring, &(instring[start]), end-start+1 );
132                        char str[256];
133                        //sprintf( str, "error at line %d character %d\n    \"%s\"\n", nlines, nchar, substring );
134                        sprintf( str, "error at line %d character %d\n\"%s\"\n", nlines, nchar, substring );
135                        int width = errPos-start;
136                        for ( i = 0; i < width; i++ )
137                        {
138                                strcat( str, " " );
139                        }
140                        strcat( str, "|\n" );
141                        for ( i = 0; i < width; i++ )
142                        {
143                                strcat( str, " " );
144                        }
145                        strcat( str, "^\n" );
146                       
147                        errors.set( str );
148                }
149        }
150       
151       
152        //.----------------------------------------------------------------------------.
153        //|   Function   : StrToUpper                                                  |
154        //|   Description: Converts all lowercase chars in a string to uppercase.      |
155        //.----------------------------------------------------------------------------.
156        void StrToUpper(char *string)
157        {
158                for (unsigned int i = 0; i < strlen(string); i++)
159                        string[i] = toupper(string[i]);
160        }
161       
162}
163/*
164else if(!strncmp(instring, "!!VSP1.0", 8))
165{
166if (vpinit == 0 )
167{
168if(! glh_init_extensions("GL_NV_vertex_program"))
169{
170errors.set("unable to initialize GL_NV_vertex_program");
171free(instring);
172return;
173}
174else
175{
176vpinit = 1;
177}
178}
179
180  errors.reset();
181  line_number = 1;
182 
183        va_list ap;
184        va_start(ap, input_string);
185        int vpsid = va_arg(ap,int);
186        va_end(ap);
187       
188          if ( glGetError() != GL_NO_ERROR )
189          {
190          errors.set( "Previous GL_ERROR prior to vertex state program parsing." );
191          }
192         
193        LoadProgram( GL_VERTEX_STATE_PROGRAM_NV, vpsid, instring );
194                }
195                */
Note: See TracBrowser for help on using the repository browser.