source: trunk/src/testing/app/volvis/vCG.cpp @ 4

Revision 4, 6.7 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
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//vCG.cpp
36//has the CG related code from Luc Renambot
37#if defined(ADDCGGL)
38
39#include "vCG.h"
40#include "global.h"
41#include <stdio.h>
42#include <stdlib.h>
43CGcontext context;
44CGprogram vertexProgram, fragmentProgram;
45CGprofile fprofile, vprofile;
46CGparameter ModelViewProj;
47CGparameter hTexture0, hTexture1;
48CGparameter param;
49int curTexId ;
50void handleCgError()
51{
52    fprintf(stderr, "Cg> error: %s\n", cgGetErrorString(cgGetError()));
53    exit(1);
54}
55
56int initCG()
57{
58        // Basic Cg setup; register a callback function for any errors
59        // and create an initial context
60        cgSetErrorCallback(handleCgError);
61
62        /* cgContext creation */
63        context = cgCreateContext();
64        assert(cgIsContext(context));
65
66        fprintf(stderr, "---------------------------------------------------------\n");
67
68        if (cgGLIsProfileSupported(CG_PROFILE_FP30))
69    {
70                fprintf(stderr, "CG> success : FP30 fragment profile supported on this system.\n");
71                fprofile = CG_PROFILE_FP30;
72    }
73        else
74    {
75                fprintf(stderr, "CG> warning : FP30 fragment profile NOT supported on this system.\n");
76                if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1))
77                {
78                        fprintf(stderr, "CG> success : ARBFP1 fragment profile supported on this system.\n");
79                        fprofile = CG_PROFILE_ARBFP1;
80                }
81                else
82                {
83                        fprintf(stderr, "CG> warning : ARBFP1 fragment profile NOT supported on this system.\n");
84                        if (cgGLIsProfileSupported(CG_PROFILE_FP20))
85                        {
86                                fprintf(stderr, "CG> success : FP20 fragment profile supported on this system.\n");
87                                fprofile = CG_PROFILE_FP20;
88                        }
89                        else
90                        {
91                                fprintf(stderr, "CG> warning : FP20 fragment profile NOT supported on this system.\n");
92                                fprintf(stderr, "CG> error : NO fragment profile supported on this system.\n");
93                                fprintf(stderr, "---------------------------------------------------------\n");
94                                exit(1);
95                        }
96                }
97    }
98
99        fprintf(stderr, "---------------------------------------------------------\n");
100
101        if (cgGLIsProfileSupported(CG_PROFILE_VP30))
102    {
103                fprintf(stderr, "CG> success : VP30 vertex profile supported on this system.\n");
104                vprofile = CG_PROFILE_VP30;
105    }
106        else
107    {
108                fprintf(stderr, "CG> warning : VP30 vertex profile NOT supported on this system.\n");
109                if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1))
110                {
111                        fprintf(stderr, "CG> success : ARBVP1 vertex profile supported on this system.\n");
112                        vprofile = CG_PROFILE_ARBVP1;
113                }
114                else
115                {
116                        fprintf(stderr, "CG> warning : ARBVP1 vertex profile NOT supported on this system.\n");
117                        if (cgGLIsProfileSupported(CG_PROFILE_VP20))
118                        {
119                                fprintf(stderr, "CG> success : VP20 vertex profile supported on this system.\n");
120                                vprofile = CG_PROFILE_VP20;
121                        }
122                        else
123                        {
124                                fprintf(stderr, "CG> warning : VP20 vertex profile NOT supported on this system.\n");
125                                fprintf(stderr, "CG> error : NO vertex profile supported on this system.\n");
126                                fprintf(stderr, "---------------------------------------------------------\n");
127                                exit(1);
128                        }
129                }
130    }
131
132        fprintf(stderr, "---------------------------------------------------------\n");
133
134        // adding source text to context
135        //shalini commenting out for cutplane
136/*      vertexProgram = cgCreateProgramFromFile(
137                context, CG_SOURCE, "shaders/vertex.cg", vprofile, "C4E1v_transform", NULL);
138        fprintf(stderr, "CG> Compiling Vertex [shaders/vertex.cg]....\n");
139        if (!cgIsProgramCompiled(vertexProgram))
140                cgCompileProgram(vertexProgram);
141        fprintf(stderr, "CG> \t done\n");
142        cgGLLoadProgram(vertexProgram);
143
144        ModelViewProj = cgGetNamedParameter(vertexProgram, "modelViewProj");
145*/
146        if (fprofile == CG_PROFILE_FP20)
147    {
148                fragmentProgram = cgCreateProgramFromFile(
149                        context, CG_SOURCE, "shaders/fragment20.cg", fprofile, "C2E2f_passthrough", NULL);
150                fprintf(stderr, "CG> Compiling Fragment [shaders/fragment20.cg] ....\n");
151    }
152        else
153                if (fprofile == CG_PROFILE_FP30)
154                {
155                        fragmentProgram = cgCreateProgramFromFile(
156                                context, CG_SOURCE, "shaders/fragment30.cg", fprofile, "C2E2f_passthrough", NULL);
157                        fprintf(stderr, "CG> Compiling Fragment [shaders/fragment30.cg] ....\n");
158                }
159
160                if (!cgIsProgramCompiled(fragmentProgram))
161                        cgCompileProgram(fragmentProgram);
162                fprintf(stderr, "CG> \t done\n");
163                cgGLLoadProgram(fragmentProgram);
164
165                hTexture0 = cgGetNamedParameter(fragmentProgram, "texture0");
166                hTexture1 = cgGetNamedParameter(fragmentProgram, "texture1");
167
168                return 1;
169
170}
171
172void enableCG(unsigned int volTex) {
173        cgGLBindProgram(fragmentProgram);
174        cgGLEnableProfile(fprofile);
175
176        cgGLSetTextureParameter(hTexture0, global.volume->texName);
177        cgGLSetTextureParameter(hTexture1, curTexId);
178
179        cgGLEnableTextureParameter(hTexture0);
180        cgGLEnableTextureParameter(hTexture1);
181}
182
183void setCurTextureCG(int texName) {
184        curTexId = texName;
185}
186
187void disableCG() {
188        cgGLDisableProfile(vprofile);
189        cgGLDisableProfile(fprofile);
190        cgGLDisableTextureParameter(hTexture0);
191        cgGLDisableTextureParameter(hTexture1);
192}
193
194void exitCG() {
195//      cgDestroyProgram(vertexProgram);
196        cgDestroyProgram(fragmentProgram);
197        cgDestroyContext(context);
198}
199
200#endif
Note: See TracBrowser for help on using the repository browser.