Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/nvparse/vp1.0_impl.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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