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

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