diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llrender/llvertexprogramgl.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/linden/indra/llrender/llvertexprogramgl.cpp b/linden/indra/llrender/llvertexprogramgl.cpp new file mode 100644 index 0000000..bc00a64 --- /dev/null +++ b/linden/indra/llrender/llvertexprogramgl.cpp | |||
@@ -0,0 +1,121 @@ | |||
1 | /** | ||
2 | * @file llvertexprogramgl.cpp | ||
3 | * @brief LLVertexProgramGL base class | ||
4 | * | ||
5 | * Copyright (c) 2003-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | // This file contains the definition of LLVertexProgramGL, | ||
29 | // for purposes of running vertex programs on GL hardware. | ||
30 | |||
31 | #include "linden_common.h" | ||
32 | |||
33 | #include "llvertexprogramgl.h" | ||
34 | |||
35 | #include "llglheaders.h" | ||
36 | |||
37 | LLVertexProgramGL::LLVertexProgramGL() | ||
38 | { | ||
39 | mVertexProgramID = 0; | ||
40 | } | ||
41 | |||
42 | LLVertexProgramGL::~LLVertexProgramGL() | ||
43 | { | ||
44 | glDeleteProgramsARB(1, (GLuint*) &mVertexProgramID); | ||
45 | } | ||
46 | |||
47 | BOOL LLVertexProgramGL::load(const char * filename) | ||
48 | { | ||
49 | FILE *fp = fopen(filename, "r"); | ||
50 | if (!fp) | ||
51 | { | ||
52 | llwarns << "Unable to open vertex program " << filename << llendl; | ||
53 | return FALSE; | ||
54 | } | ||
55 | |||
56 | fseek(fp,0,SEEK_END); | ||
57 | S32 file_size = ftell(fp); | ||
58 | fseek(fp,0,SEEK_SET); | ||
59 | |||
60 | char *text_buffer = new char[file_size + 1]; | ||
61 | |||
62 | S32 num_read = (S32)fread(text_buffer, sizeof(char), file_size, fp); | ||
63 | |||
64 | if (ferror(fp) || num_read == 0) | ||
65 | { | ||
66 | llwarns << "Unable to read vertex program " << filename << llendl; | ||
67 | fclose(fp); | ||
68 | delete[] text_buffer; | ||
69 | return FALSE; | ||
70 | } | ||
71 | text_buffer[num_read] = '\0'; | ||
72 | fclose(fp); | ||
73 | |||
74 | //Send program string to OpenGL | ||
75 | glGenProgramsARB(1, (GLuint*) &mVertexProgramID); | ||
76 | glBindProgramARB(GL_VERTEX_PROGRAM_ARB, mVertexProgramID); | ||
77 | glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, num_read, text_buffer); | ||
78 | |||
79 | const GLubyte * program_error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB); | ||
80 | |||
81 | GLint error_pos; | ||
82 | glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); | ||
83 | |||
84 | if(error_pos!=-1) | ||
85 | { | ||
86 | glGetError(); | ||
87 | S32 line_num = 1; | ||
88 | char *next_token = strchr(text_buffer, '\n'); | ||
89 | while(NULL != next_token && next_token < (text_buffer + error_pos)) | ||
90 | { | ||
91 | next_token++; | ||
92 | line_num++; | ||
93 | next_token = strchr(next_token, '\n'); | ||
94 | } | ||
95 | char output[1024]; | ||
96 | char bad_code[11]; | ||
97 | strncpy(bad_code, text_buffer + error_pos, 10); | ||
98 | bad_code[10] = '\0'; | ||
99 | |||
100 | sprintf(output, "%s(%d): Vertex Program Error: %s at (%s)\n", filename, line_num, program_error_string, bad_code); | ||
101 | gErrorStream << output << std::endl; | ||
102 | // clean up buffer | ||
103 | delete[] text_buffer; | ||
104 | return FALSE; | ||
105 | } | ||
106 | |||
107 | // clean up buffer | ||
108 | delete[] text_buffer; | ||
109 | return TRUE; | ||
110 | } | ||
111 | |||
112 | void LLVertexProgramGL::bind() | ||
113 | { | ||
114 | glEnable(GL_VERTEX_PROGRAM_ARB); | ||
115 | glBindProgramARB(GL_VERTEX_PROGRAM_ARB, mVertexProgramID); | ||
116 | } | ||
117 | |||
118 | void LLVertexProgramGL::unbind() | ||
119 | { | ||
120 | glDisable(GL_VERTEX_PROGRAM_ARB); | ||
121 | } | ||