blob: 3e71e853a82f55952468418e90938609703a344c [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#ifndef _SHHANDLE_INCLUDED_
8#define _SHHANDLE_INCLUDED_
9
10//
11// Machine independent part of the compiler private objects
12// sent as ShHandle to the driver.
13//
14// This should not be included by driver code.
15//
16
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000017#include "GLSLANG/ShaderLang.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
19#include "InfoSink.h"
20
21class TCompiler;
22class TLinker;
23class TUniformMap;
24
25
26//
27// The base class used to back handles returned to the driver.
28//
29class TShHandleBase {
30public:
31 TShHandleBase() { }
32 virtual ~TShHandleBase() { }
33 virtual TCompiler* getAsCompiler() { return 0; }
34 virtual TLinker* getAsLinker() { return 0; }
35 virtual TUniformMap* getAsUniformMap() { return 0; }
36};
37
38//
39// The base class for the machine dependent linker to derive from
40// for managing where uniforms live.
41//
42class TUniformMap : public TShHandleBase {
43public:
44 TUniformMap() { }
45 virtual ~TUniformMap() { }
46 virtual TUniformMap* getAsUniformMap() { return this; }
47 virtual int getLocation(const char* name) = 0;
48 virtual TInfoSink& getInfoSink() { return infoSink; }
49 TInfoSink infoSink;
50};
51class TIntermNode;
52
53//
54// The base class for the machine dependent compiler to derive from
55// for managing object code from the compile.
56//
57class TCompiler : public TShHandleBase {
58public:
59 TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
60 virtual ~TCompiler() { }
61 EShLanguage getLanguage() { return language; }
62 virtual TInfoSink& getInfoSink() { return infoSink; }
63
64 virtual bool compile(TIntermNode* root) = 0;
65
66 virtual TCompiler* getAsCompiler() { return this; }
67 virtual bool linkable() { return haveValidObjectCode; }
68
69 TInfoSink& infoSink;
70protected:
71 EShLanguage language;
72 bool haveValidObjectCode;
73};
74
75//
76// Link operations are base on a list of compile results...
77//
78typedef TVector<TCompiler*> TCompilerList;
79typedef TVector<TShHandleBase*> THandleList;
80
81//
82// The base class for the machine dependent linker to derive from
83// to manage the resulting executable.
84//
85
86class TLinker : public TShHandleBase {
87public:
88 TLinker(EShExecutable e, TInfoSink& iSink) :
89 infoSink(iSink),
90 executable(e),
91 haveReturnableObjectCode(false),
92 appAttributeBindings(0),
93 fixedAttributeBindings(0),
94 excludedAttributes(0),
95 excludedCount(0),
96 uniformBindings(0) { }
97 virtual TLinker* getAsLinker() { return this; }
98 virtual ~TLinker() { }
99 virtual bool link(TCompilerList&, TUniformMap*) = 0;
100 virtual bool link(THandleList&) { return false; }
101 virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
102 virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
103 virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
104 virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
105 virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
106 virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
107 virtual TInfoSink& getInfoSink() { return infoSink; }
108 TInfoSink& infoSink;
109protected:
110 EShExecutable executable;
111 bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
112
113 const ShBindingTable* appAttributeBindings;
114 const ShBindingTable* fixedAttributeBindings;
115 const int* excludedAttributes;
116 int excludedCount;
117 ShBindingTable* uniformBindings; // created by the linker
118};
119
120//
121// This is the interface between the machine independent code
122// and the machine dependent code.
123//
124// The machine dependent code should derive from the classes
125// above. Then Construct*() and Delete*() will create and
126// destroy the machine dependent objects, which contain the
127// above machine independent information.
128//
129TCompiler* ConstructCompiler(EShLanguage, int);
130
131TShHandleBase* ConstructLinker(EShExecutable, int);
132void DeleteLinker(TShHandleBase*);
133
134TUniformMap* ConstructUniformMap();
135void DeleteCompiler(TCompiler*);
136
137void DeleteUniformMap(TUniformMap*);
138
139#endif // _SHHANDLE_INCLUDED_