Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreScriptTranslator.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 11.7 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __SCRIPTTRANSLATOR_H_
30#define __SCRIPTTRANSLATOR_H_
31
32#include "OgrePrerequisites.h"
33#include "OgreScriptCompiler.h"
34#include "OgreHeaderPrefix.h"
35
36namespace Ogre{
37        /** \addtogroup Core
38        *  @{
39        */
40        /** \addtogroup General
41        *  @{
42        */
43        /** This class translates script AST (abstract syntax tree) into
44         *  Ogre resources. It defines a common interface for subclasses
45         *  which perform the actual translation.
46         */
47
48        class _OgreExport ScriptTranslator : public ScriptTranslatorAlloc
49        {
50        public:
51                /**
52                 * This function translates the given node into Ogre resource(s).
53                 * @param compiler The compiler invoking this translator
54                 * @param node The current AST node to be translated
55                 */
56                virtual void translate(ScriptCompiler *compiler, const AbstractNodePtr &node) = 0;
57        protected:
58                // needs virtual destructor
59                virtual ~ScriptTranslator() {}
60                /// Retrieves a new translator from the factories and uses it to process the give node
61                void processNode(ScriptCompiler *compiler, const AbstractNodePtr &node);
62
63                /// Retrieves the node iterator at the given index
64                static AbstractNodeList::const_iterator getNodeAt(const AbstractNodeList &nodes, int index);
65                /// Converts the node to a boolean and returns true if successful
66                static bool getBoolean(const AbstractNodePtr &node, bool *result);
67                /// Converts the node to a string and returns true if successful
68                static bool getString(const AbstractNodePtr &node, String *result);
69                /// Converts the node to a Real and returns true if successful
70                static bool getReal(const AbstractNodePtr &node, Real *result);
71                /// Converts the node to a float and returns true if successful
72                static bool getFloat(const AbstractNodePtr &node, float *result);
73                /// Converts the node to an integer and returns true if successful
74                static bool getInt(const AbstractNodePtr &node, int *result); 
75                /// Converts the node to an unsigned integer and returns true if successful
76                static bool getUInt(const AbstractNodePtr &node, uint32 *result); 
77                /// Converts the range of nodes to a ColourValue and returns true if successful
78                static bool getColour(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, ColourValue *result, int maxEntries = 4);
79                /// Converts the node to a SceneBlendFactor enum and returns true if successful
80                static bool getSceneBlendFactor(const AbstractNodePtr &node, SceneBlendFactor *sbf);
81                /// Converts the node to a CompareFunction enum and returns true if successful
82                static bool getCompareFunction(const AbstractNodePtr &node, CompareFunction *func);
83                /// Converts the range of nodes to a Matrix4 and returns true if successful
84                static bool getMatrix4(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, Matrix4 *m);
85                /// Converts the range of nodes to an array of ints and returns true if successful
86                static bool getInts(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, int *vals, int count);
87                /// Converts the range of nodes to an array of floats and returns true if successful
88                static bool getFloats(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, float *vals, int count);
89                /// Converts the node to a StencilOperation enum and returns true if successful
90                static bool getStencilOp(const AbstractNodePtr &node, StencilOperation *op); 
91                /// Converts the node to a GpuConstantType enum and returns true if successful
92                static bool getConstantType(AbstractNodeList::const_iterator i, GpuConstantType *op); 
93
94        };
95
96        /** The ScriptTranslatorManager manages the lifetime and access to
97         *  script translators. You register these managers with the
98         *  ScriptCompilerManager tied to specific object types.
99         *  Each manager may manage multiple types.
100         */
101        class ScriptTranslatorManager : public ScriptTranslatorAlloc
102        {
103        public:
104                // required - virtual destructor
105                virtual ~ScriptTranslatorManager() {}
106
107                /// Returns the number of translators being managed
108                virtual size_t getNumTranslators() const = 0;
109                /// Returns a manager for the given object abstract node, or null if it is not supported
110                virtual ScriptTranslator *getTranslator(const AbstractNodePtr&) = 0;
111        };
112
113        /**************************************************************************
114         * Material compilation section
115         *************************************************************************/
116        class _OgreExport MaterialTranslator : public ScriptTranslator
117        {
118        protected:
119                Material *mMaterial;
120                Ogre::AliasTextureNamePairList mTextureAliases;
121        public:
122                MaterialTranslator();
123                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
124        };
125               
126        class _OgreExport TechniqueTranslator : public ScriptTranslator
127        {
128        protected:
129                Technique *mTechnique;
130        public:
131                TechniqueTranslator();
132                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
133        };
134       
135        class _OgreExport PassTranslator : public ScriptTranslator
136        {
137        protected:
138                Pass *mPass;
139        public:
140                PassTranslator();
141                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
142        protected:
143                void translateVertexProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
144                void translateGeometryProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
145                void translateFragmentProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
146                void translateTesselationHullProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
147                void translateTesselationDomainProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
148                void translateComputeProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
149                void translateShadowCasterVertexProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
150                void translateShadowCasterFragmentProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
151                void translateShadowReceiverVertexProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
152                void translateShadowReceiverFragmentProgramRef(ScriptCompiler *compiler, ObjectAbstractNode *node);
153        };
154
155        class _OgreExport TextureUnitTranslator : public ScriptTranslator
156        {
157        protected:
158                TextureUnitState *mUnit;
159        public:
160                TextureUnitTranslator();
161                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
162        };
163
164        class _OgreExport TextureSourceTranslator : public ScriptTranslator
165        {
166        public:
167                TextureSourceTranslator();
168                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
169        };
170
171        class _OgreExport GpuProgramTranslator : public ScriptTranslator
172        {       
173        public:
174                GpuProgramTranslator();
175                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
176        protected:
177                void translateGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj);
178                void translateHighLevelGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj);
179                void translateUnifiedGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj);
180        public:
181                static void translateProgramParameters(ScriptCompiler *compiler, GpuProgramParametersSharedPtr params, ObjectAbstractNode *obj);
182        };
183
184        class _OgreExport SharedParamsTranslator : public ScriptTranslator
185        {       
186        public:
187                SharedParamsTranslator();
188                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
189        protected:
190        };
191
192        /**************************************************************************
193         * Particle System section
194         *************************************************************************/
195        class _OgreExport ParticleSystemTranslator : public ScriptTranslator
196        {
197        protected:
198                Ogre::ParticleSystem *mSystem;
199        public:
200                ParticleSystemTranslator();
201                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
202        };
203        class _OgreExport ParticleEmitterTranslator : public ScriptTranslator
204        {
205        protected:
206                Ogre::ParticleEmitter *mEmitter;
207        public:
208                ParticleEmitterTranslator();
209                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
210        };
211        class _OgreExport ParticleAffectorTranslator : public ScriptTranslator
212        {
213        protected:
214                Ogre::ParticleAffector *mAffector;
215        public:
216                ParticleAffectorTranslator();
217                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
218        };
219
220        /**************************************************************************
221         * Compositor section
222         *************************************************************************/
223        class _OgreExport CompositorTranslator : public ScriptTranslator
224        {
225        protected:
226                Compositor *mCompositor;
227        public:
228                CompositorTranslator();
229                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
230        };
231        class _OgreExport CompositionTechniqueTranslator : public ScriptTranslator
232        {
233        protected:
234                CompositionTechnique *mTechnique;
235        public:
236                CompositionTechniqueTranslator();
237                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
238        };
239        class _OgreExport CompositionTargetPassTranslator : public ScriptTranslator
240        {
241        protected:
242                CompositionTargetPass *mTarget;
243        public:
244                CompositionTargetPassTranslator();
245                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
246        };
247        class _OgreExport CompositionPassTranslator : public ScriptTranslator
248        {
249        protected:
250                CompositionPass *mPass;
251        public:
252                CompositionPassTranslator();
253                void translate(ScriptCompiler *compiler, const AbstractNodePtr &node);
254        };
255
256        /**************************************************************************
257         * BuiltinScriptTranslatorManager
258         *************************************************************************/
259        /// This class manages the builtin translators
260        class _OgreExport BuiltinScriptTranslatorManager : public ScriptTranslatorManager
261        {
262        private:
263                MaterialTranslator mMaterialTranslator;
264                TechniqueTranslator mTechniqueTranslator;
265                PassTranslator mPassTranslator;
266                TextureUnitTranslator mTextureUnitTranslator;
267                TextureSourceTranslator mTextureSourceTranslator;
268                GpuProgramTranslator mGpuProgramTranslator;
269                SharedParamsTranslator mSharedParamsTranslator;
270                ParticleSystemTranslator mParticleSystemTranslator;
271                ParticleEmitterTranslator mParticleEmitterTranslator;
272                ParticleAffectorTranslator mParticleAffectorTranslator;
273                CompositorTranslator mCompositorTranslator;
274                CompositionTechniqueTranslator mCompositionTechniqueTranslator;
275                CompositionTargetPassTranslator mCompositionTargetPassTranslator;
276                CompositionPassTranslator mCompositionPassTranslator;
277        public:
278                BuiltinScriptTranslatorManager();
279                /// Returns the number of translators being managed
280                virtual size_t getNumTranslators() const;
281                /// Returns a manager for the given object abstract node, or null if it is not supported
282                virtual ScriptTranslator *getTranslator(const AbstractNodePtr &node);
283        };
284        /** @} */
285        /** @} */
286}
287
288#include "OgreHeaderSuffix.h"
289
290#endif
291
Note: See TracBrowser for help on using the repository browser.