2 //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
5 //Redistribution and use in source and binary forms, with or without
6 //modification, are permitted provided that the following conditions
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
17 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
21 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _SHHANDLE_INCLUDED_
36 #define _SHHANDLE_INCLUDED_
39 // Machine independent part of the compiler private objects
40 // sent as ShHandle to the driver.
42 // This should not be included by driver code.
47 #include "../Public/ShaderLang.h"
48 #include "../MachineIndependent/Versions.h"
56 // The base class used to back handles returned to the driver.
61 virtual ~TShHandleBase() { }
62 virtual TCompiler* getAsCompiler() { return 0; }
63 virtual TLinker* getAsLinker() { return 0; }
64 virtual TUniformMap* getAsUniformMap() { return 0; }
68 // The base class for the machine dependent linker to derive from
69 // for managing where uniforms live.
71 class TUniformMap : public TShHandleBase {
74 virtual ~TUniformMap() { }
75 virtual TUniformMap* getAsUniformMap() { return this; }
76 virtual int getLocation(const char* name) = 0;
77 virtual TInfoSink& getInfoSink() { return infoSink; }
84 // The base class for the machine dependent compiler to derive from
85 // for managing object code from the compile.
87 class TCompiler : public TShHandleBase {
89 TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
90 virtual ~TCompiler() { }
91 EShLanguage getLanguage() { return language; }
92 virtual TInfoSink& getInfoSink() { return infoSink; }
94 virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
96 virtual TCompiler* getAsCompiler() { return this; }
97 virtual bool linkable() { return haveValidObjectCode; }
101 EShLanguage language;
102 bool haveValidObjectCode;
106 // Link operations are base on a list of compile results...
108 typedef glslang::TVector<TCompiler*> TCompilerList;
109 typedef glslang::TVector<TShHandleBase*> THandleList;
112 // The base class for the machine dependent linker to derive from
113 // to manage the resulting executable.
116 class TLinker : public TShHandleBase {
118 TLinker(EShExecutable e, TInfoSink& iSink) :
121 haveReturnableObjectCode(false),
122 appAttributeBindings(0),
123 fixedAttributeBindings(0),
124 excludedAttributes(0),
126 uniformBindings(0) { }
127 virtual TLinker* getAsLinker() { return this; }
128 virtual ~TLinker() { }
129 virtual bool link(TCompilerList&, TUniformMap*) = 0;
130 virtual bool link(THandleList&) { return false; }
131 virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
132 virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
133 virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
134 virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
135 virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
136 virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
137 virtual TInfoSink& getInfoSink() { return infoSink; }
140 EShExecutable executable;
141 bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
143 const ShBindingTable* appAttributeBindings;
144 const ShBindingTable* fixedAttributeBindings;
145 const int* excludedAttributes;
147 ShBindingTable* uniformBindings; // created by the linker
151 // This is the interface between the machine independent code
152 // and the machine dependent code.
154 // The machine dependent code should derive from the classes
155 // above. Then Construct*() and Delete*() will create and
156 // destroy the machine dependent objects, which contain the
157 // above machine independent information.
159 TCompiler* ConstructCompiler(EShLanguage, int);
161 TShHandleBase* ConstructLinker(EShExecutable, int);
162 void DeleteLinker(TShHandleBase*);
164 TUniformMap* ConstructUniformMap();
165 void DeleteCompiler(TCompiler*);
167 void DeleteUniformMap(TUniformMap*);
169 #endif // _SHHANDLE_INCLUDED_