1 | /******************************************************************************** |
---|
2 | * Volatile - Volume Visualization Software for SAGE |
---|
3 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about Volatile to www.evl.uic.edu/cavern/forum |
---|
33 | *********************************************************************************/ |
---|
34 | |
---|
35 | //vARB.cpp |
---|
36 | //has the CG related code from Luc Renambot |
---|
37 | |
---|
38 | #if defined(ADDARBGL) |
---|
39 | |
---|
40 | #include "vARB.h" |
---|
41 | #include "global.h" |
---|
42 | #include <stdio.h> |
---|
43 | #include <stdlib.h> |
---|
44 | #include <GL/glext.h> |
---|
45 | |
---|
46 | |
---|
47 | const char *shader_code1 = |
---|
48 | "!!ARBfp1.0\n" |
---|
49 | "# cgc version 1.3.0001, build date Jul 16 2004 12:35:04\n" |
---|
50 | "# command line args: -profile arbfp1 -entry C2E2f_passthrough\n" |
---|
51 | "# source file: fragment20.cg\n" |
---|
52 | "#vendor NVIDIA Corporation\n" |
---|
53 | "#version 1.0.02\n" |
---|
54 | "#profile arbfp1\n" |
---|
55 | "#program C2E2f_passthrough\n" |
---|
56 | "#semantic C2E2f_passthrough.texture0\n" |
---|
57 | "#semantic C2E2f_passthrough.texture1\n" |
---|
58 | "#var float3 texCoord0 : $vin.TEX0 : TEX0 : 0 : 1\n" |
---|
59 | "#var sampler3D texture0 : : texunit 0 : 1 : 1\n" |
---|
60 | "#var sampler2D texture1 : : texunit 1 : 2 : 1\n" |
---|
61 | "#var float4 C2E2f_passthrough : $vout.COL : COL : -1 : 1\n" |
---|
62 | "PARAM c[1] = { program.local[0] };\n" |
---|
63 | "TEMP R0;\n" |
---|
64 | "TEX R0.xw, fragment.texcoord[0], texture[0], 3D;\n" |
---|
65 | "TEX result.color, R0.wxzw, texture[1], 2D;\n" |
---|
66 | "END\n" |
---|
67 | "# 2 instructions, 1 R-regs\n"; |
---|
68 | |
---|
69 | const char *shader_code = |
---|
70 | "!!ARBfp1.0\n" |
---|
71 | "#var float3 texCoord0 : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1\n" |
---|
72 | "#var sampler3D texture0 : : texunit 0 : 1 : 1\n" |
---|
73 | "#var sampler2D texture1 : : texunit 1 : 2 : 1\n" |
---|
74 | "#var float4 C2E2f_passthrough : $vout.COLOR : COLOR : -1 : 1\n" |
---|
75 | "TEMP R0;\n" |
---|
76 | "TEX R0.xw, fragment.texcoord[0], texture[0], 3D;\n" |
---|
77 | "TEX result.color, R0.wxww, texture[1], 2D;\n" |
---|
78 | "END\n"; |
---|
79 | |
---|
80 | // WORKS |
---|
81 | const char *shader_code3 = |
---|
82 | "!!ARBfp1.0\n" |
---|
83 | "OUTPUT out = result.color;\n" |
---|
84 | "TEMP temp;\n" |
---|
85 | "PARAM pink = { 1.0, 0.4, 0.4, 0.0}; \n" |
---|
86 | "TEX temp, fragment.texcoord[0], texture[0], 3D;\n" |
---|
87 | "ADD out, temp, pink;\n" |
---|
88 | "END\n"; |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | GLuint vertexProgram, fragmentProgram; |
---|
93 | int curTexId ; |
---|
94 | |
---|
95 | void handleARBError() |
---|
96 | { |
---|
97 | fprintf(stderr, "ARB> error \n"); |
---|
98 | exit(1); |
---|
99 | } |
---|
100 | |
---|
101 | int initARB() |
---|
102 | { |
---|
103 | int notgood; |
---|
104 | const char *extensions = (const char*)glGetString(GL_EXTENSIONS); |
---|
105 | size_t sysExtsLen = strlen(extensions); |
---|
106 | |
---|
107 | notgood = 0; |
---|
108 | |
---|
109 | if(strstr(extensions,"GL_ARB_vertex_program")) |
---|
110 | fprintf(stderr, "GL_ARB_vertex_program supported\n"); |
---|
111 | else |
---|
112 | { |
---|
113 | fprintf(stderr, "GL_ARB_vertex_program NOT supported\n"); |
---|
114 | notgood = 1; |
---|
115 | } |
---|
116 | if(strstr(extensions,"GL_ARB_fragment_program")) |
---|
117 | fprintf(stderr, "GL_ARB_fragment_program supported\n"); |
---|
118 | else |
---|
119 | { |
---|
120 | fprintf(stderr, "GL_ARB_fragment_program NOT supported\n"); |
---|
121 | notgood = 1; |
---|
122 | } |
---|
123 | |
---|
124 | if (notgood) |
---|
125 | { |
---|
126 | fprintf(stderr, "ARB> error : fragment and vertex program required (GL_ARB_fragment_program, GL_ARB_vertex_program).\n"); |
---|
127 | fprintf(stderr, "---------------------------------------------------------\n"); |
---|
128 | exit(1); |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | GLint maxInsts, maxTemps, maxParams; |
---|
133 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_INSTRUCTIONS_ARB, &maxInsts ); |
---|
134 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_TEMPORARIES_ARB, &maxTemps ); |
---|
135 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_PARAMETERS_ARB, &maxParams ); |
---|
136 | fprintf(stderr, "ARB> GL_ARB_fragment_program, GL_ARB_vertex_program present\n"); |
---|
137 | fprintf(stderr, "ARB> \t %d max instructions, %d max temp varriables, %d max variables\n", |
---|
138 | maxInsts, maxTemps, maxParams); |
---|
139 | fprintf(stderr, "---------------------------------------------------------\n"); |
---|
140 | } |
---|
141 | |
---|
142 | glGenProgramsARB(1, &fragmentProgram); |
---|
143 | glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragmentProgram); |
---|
144 | glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei) strlen(shader_code), (GLubyte *) shader_code); |
---|
145 | |
---|
146 | GLint error_pos; |
---|
147 | glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); |
---|
148 | if (error_pos != -1) |
---|
149 | { |
---|
150 | const GLubyte *error_string; |
---|
151 | error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB); |
---|
152 | fprintf(stderr, "Program error at position: %d\n%s\n", error_pos, error_string); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | GLint maxInsts, maxTemps, maxParams; |
---|
157 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_INSTRUCTIONS_ARB, &maxInsts ); |
---|
158 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_TEMPORARIES_ARB, &maxTemps ); |
---|
159 | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_PARAMETERS_ARB, &maxParams ); |
---|
160 | fprintf(stderr, "ARB> GL_ARB_fragment_program, GL_ARB_vertex_program present\n"); |
---|
161 | fprintf(stderr, "ARB> \t %d current instructions, %d current varriables, %d current variables\n", |
---|
162 | maxInsts, maxTemps, maxParams); |
---|
163 | fprintf(stderr, "---------------------------------------------------------\n"); |
---|
164 | } |
---|
165 | |
---|
166 | //hTexture0 = cgGetNamedParameter(fragmentProgram, "texture0"); |
---|
167 | //hTexture1 = cgGetNamedParameter(fragmentProgram, "texture1"); |
---|
168 | |
---|
169 | return 1; |
---|
170 | } |
---|
171 | |
---|
172 | void enableARB(unsigned int volTex) |
---|
173 | { |
---|
174 | glEnable(GL_FRAGMENT_PROGRAM_ARB); |
---|
175 | glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragmentProgram); |
---|
176 | |
---|
177 | glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, global.volume->texName, curTexId, 0, 0); |
---|
178 | |
---|
179 | glActiveTextureARB(GL_TEXTURE0_ARB); |
---|
180 | glBindTexture(GL_TEXTURE_3D, global.volume->texName); |
---|
181 | |
---|
182 | glActiveTextureARB(GL_TEXTURE1_ARB); |
---|
183 | glBindTexture(GL_TEXTURE_2D, curTexId); |
---|
184 | |
---|
185 | glActiveTextureARB(GL_TEXTURE0_ARB); |
---|
186 | |
---|
187 | //cgGLSetTextureParameter(hTexture0, global.volume->texName); |
---|
188 | //cgGLSetTextureParameter(hTexture1, curTexId); |
---|
189 | |
---|
190 | //cgGLEnableTextureParameter(hTexture0); |
---|
191 | //cgGLEnableTextureParameter(hTexture1); |
---|
192 | |
---|
193 | |
---|
194 | //glActiveTextureARB( GL_TEXTURE0_ARB ); |
---|
195 | //glBindTexture(GL_TEXTURE_3D, global.volume->texName); |
---|
196 | //glActiveTextureARB( GL_TEXTURE1_ARB ); |
---|
197 | //glBindTexture(GL_TEXTURE_3D, curTexId); |
---|
198 | |
---|
199 | } |
---|
200 | |
---|
201 | void setCurTextureARB(int texName) |
---|
202 | { |
---|
203 | curTexId = texName; |
---|
204 | } |
---|
205 | |
---|
206 | void disableARB() |
---|
207 | { |
---|
208 | glDisable(GL_FRAGMENT_PROGRAM_ARB); |
---|
209 | |
---|
210 | //cgGLDisableTextureParameter(hTexture0); |
---|
211 | //cgGLDisableTextureParameter(hTexture1); |
---|
212 | } |
---|
213 | |
---|
214 | void exitARB() |
---|
215 | { |
---|
216 | glDeleteProgramsARB(1, &fragmentProgram); |
---|
217 | } |
---|
218 | |
---|
219 | #endif |
---|