1 | /*
|
---|
2 | *
|
---|
3 | * Copyright (c) 2002, NVIDIA Corporation.
|
---|
4 | *
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
|
---|
8 | * of your agreement to the following terms, and your use, installation,
|
---|
9 | * modification or redistribution of this NVIDIA software constitutes
|
---|
10 | * acceptance of these terms. If you do not agree with these terms, please do
|
---|
11 | * not use, install, modify or redistribute this NVIDIA software.
|
---|
12 | *
|
---|
13 | *
|
---|
14 | *
|
---|
15 | * In consideration of your agreement to abide by the following terms, and
|
---|
16 | * subject to these terms, NVIDIA grants you a personal, non-exclusive license,
|
---|
17 | * under NVIDIAs copyrights in this original NVIDIA software (the "NVIDIA
|
---|
18 | * Software"), to use, reproduce, modify and redistribute the NVIDIA
|
---|
19 | * Software, with or without modifications, in source and/or binary forms;
|
---|
20 | * provided that if you redistribute the NVIDIA Software, you must retain the
|
---|
21 | * copyright notice of NVIDIA, this notice and the following text and
|
---|
22 | * disclaimers in all such redistributions of the NVIDIA Software. Neither the
|
---|
23 | * name, trademarks, service marks nor logos of NVIDIA Corporation may be used
|
---|
24 | * to endorse or promote products derived from the NVIDIA Software without
|
---|
25 | * specific prior written permission from NVIDIA. Except as expressly stated
|
---|
26 | * in this notice, no other rights or licenses express or implied, are granted
|
---|
27 | * by NVIDIA herein, including but not limited to any patent rights that may be
|
---|
28 | * infringed by your derivative works or by other works in which the NVIDIA
|
---|
29 | * Software may be incorporated. No hardware is licensed hereunder.
|
---|
30 | *
|
---|
31 | *
|
---|
32 | *
|
---|
33 | * THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
|
---|
34 | * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
---|
35 | * WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
|
---|
36 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
|
---|
37 | * EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
|
---|
38 | *
|
---|
39 | *
|
---|
40 | *
|
---|
41 | * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
|
---|
42 | * EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
|
---|
43 | * PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
44 | * PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
|
---|
45 | * REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
|
---|
46 | * HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
|
---|
47 | * NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
|
---|
48 | * OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
49 | *
|
---|
50 | */
|
---|
51 |
|
---|
52 | /*********************************************************************NVMH2****
|
---|
53 | File: cgContextManager.h
|
---|
54 |
|
---|
55 | Copyright (C) 1999, 2000 NVIDIA Corporation
|
---|
56 | This file is provided without support, instruction, or implied warranty of any
|
---|
57 | kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
|
---|
58 | not liable under any circumstances for any damages or loss whatsoever arising
|
---|
59 | from the use or inability to use this file or items derived from it.
|
---|
60 |
|
---|
61 | Comments:
|
---|
62 |
|
---|
63 | cgContextManager - a class for loading various cg programs,
|
---|
64 |
|
---|
65 |
|
---|
66 | ******************************************************************************/
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | #ifndef __NV_CG_MANAGER_H
|
---|
71 | #define __NV_CG_MANAGER_H
|
---|
72 |
|
---|
73 | #if WIN32
|
---|
74 |
|
---|
75 | #pragma warning (disable:4786) // identifier was truncated to '255' characters in the browser information
|
---|
76 |
|
---|
77 | #include <windows.h>
|
---|
78 | #include <d3d8.h>
|
---|
79 | #include <d3dx8.h>
|
---|
80 |
|
---|
81 | #include <Cg/cgTemplates.h>
|
---|
82 | #include <Cg/cg.h>
|
---|
83 | #include <Cg/cgProgramManager.h>
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | class cgContextManager;
|
---|
91 |
|
---|
92 |
|
---|
93 | class cgContextContainer
|
---|
94 | {
|
---|
95 | public:
|
---|
96 |
|
---|
97 |
|
---|
98 | // retrieve the listing file for the last compile
|
---|
99 | const char *GetLastListing();
|
---|
100 |
|
---|
101 |
|
---|
102 | // loads and compiles the cg program
|
---|
103 | cgProgramContainer * LoadCGProgramFromFile(
|
---|
104 | const char * filename, // filename of the Cg program
|
---|
105 | const char * title, // title of the program
|
---|
106 | cgProfileType type, // profile of the program
|
---|
107 | cgVertexDefinition * va = 0, // optionally, set streams or allow different vetex definitions
|
---|
108 | DWORD * outIndex = 0,
|
---|
109 | const char * entry = 0);
|
---|
110 |
|
---|
111 | cgProgramContainer * LoadCGProgramFromMemory(
|
---|
112 | const char * memory, // memory location that contain the cg program
|
---|
113 | const char * title, // name of the program
|
---|
114 | cgProfileType type, // profile of the program
|
---|
115 | cgVertexDefinition * va = 0, // optionally, set the streams for each vertex entry
|
---|
116 | DWORD * outIndex = 0,
|
---|
117 | const char * entry = 0);
|
---|
118 |
|
---|
119 |
|
---|
120 | // use outIndex returned from LoadCGProgramFrom to retriece the program iterator
|
---|
121 | cgProgramContainer * GetProgramIterator(DWORD index);
|
---|
122 |
|
---|
123 |
|
---|
124 | // program operators (for multiple programs(vertex, pixel) in one cg
|
---|
125 | // pass NULL to get first program
|
---|
126 | cgProgramIter *GetNextProgram(cgProgramIter *iter);
|
---|
127 |
|
---|
128 | // get a specific program
|
---|
129 | cgProgramIter *ProgramByName(const char *name);
|
---|
130 |
|
---|
131 |
|
---|
132 | // get the vertexshader or pixel shader handle that is passed to
|
---|
133 | // SetVertexShader and SetPixelShader
|
---|
134 | DWORD GetShaderHandle(cgProfileType type)
|
---|
135 | {
|
---|
136 | return pm.GetShaderHandle( type);
|
---|
137 | }
|
---|
138 |
|
---|
139 | ~cgContextContainer( );
|
---|
140 |
|
---|
141 | friend class cgContextManager;
|
---|
142 | protected:
|
---|
143 |
|
---|
144 | cgContextContainer( LPDIRECT3DDEVICE8 pd3dDevice, cgContext * context);
|
---|
145 |
|
---|
146 |
|
---|
147 | private:
|
---|
148 |
|
---|
149 |
|
---|
150 | cgProgramContainer * CreateProgramContainer(DWORD * outIndex = 0);
|
---|
151 |
|
---|
152 | cgProgramContainer * CreateProgramContainer(
|
---|
153 | cgProgramIter *ProgramIter,
|
---|
154 | LPDIRECT3DDEVICE8 pd3dDevice,
|
---|
155 | DWORD * outIndex = 0); // index of this
|
---|
156 |
|
---|
157 | // loads and compiles the cg program
|
---|
158 | HRESULT AddProgramFromFile(const char * filename, const char * name, cgProfileType type, const char * entry = 0);
|
---|
159 | HRESULT AddProgramFromMemory(const char * memory, const char * name, cgProfileType type, const char * entry = 0);
|
---|
160 |
|
---|
161 |
|
---|
162 | void Free();
|
---|
163 | cgProgramManager pm; // manage the vertex or pixel shader that is derived from this
|
---|
164 | cgContext * m_Context;
|
---|
165 | cg_string m_ContextDefinition;
|
---|
166 | LPDIRECT3DDEVICE8 m_pd3dDevice;
|
---|
167 |
|
---|
168 | };
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 | class cgContextManager
|
---|
173 | {
|
---|
174 | private:
|
---|
175 |
|
---|
176 | cg_vector < cgContextContainer *> m_ContextContainers;
|
---|
177 | cg_vector < DWORD > m_ContextIndices; // indirection to m_Shaders
|
---|
178 | // Programs hold an index to this array for
|
---|
179 | // their shaders. The array int at that index
|
---|
180 | // holds the index into the m_Shaders array.
|
---|
181 |
|
---|
182 | // each context has a list of programs (up to one for each profile)
|
---|
183 |
|
---|
184 |
|
---|
185 | public:
|
---|
186 | cgContextManager();
|
---|
187 | ~cgContextManager();
|
---|
188 |
|
---|
189 | cgError Free();
|
---|
190 |
|
---|
191 | cgContextContainer *CreateContextContainer(LPDIRECT3DDEVICE8 pd3dDevice, DWORD * outIndex);
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | };
|
---|
196 |
|
---|
197 |
|
---|
198 | #endif // WIN32
|
---|
199 |
|
---|
200 | #endif
|
---|