OgreShaderSubRenderState.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008 Permission is hereby granted, free of charge, to any person obtaining a copy
    00009 of this software and associated documentation files (the "Software"), to deal
    00010 in the Software without restriction, including without limitation the rights
    00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00012 copies of the Software, and to permit persons to whom the Software is
    00013 furnished to do so, subject to the following conditions:
    00014
    00015 The above copyright notice and this permission notice shall be included in
    00016 all copies or substantial portions of the Software.
    00017
    00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00024 THE SOFTWARE.
    00025 -----------------------------------------------------------------------------
    00026 */
    00027 #ifndef _ShaderSubRenderState_
    00028 #define _ShaderSubRenderState_
    00029
    00030 #include "OgreShaderPrerequisites.h"
    00031 #include "OgreGpuProgram.h"
    00032 #include "OgreSceneManager.h"
    00033 #include "OgreMaterialSerializer.h"
    00034 #include "OgreScriptCompiler.h"
    00035 #include "OgreShaderScriptTranslator.h"
    00036
    00037
    00038 namespace Ogre {
    00039 namespace RTShader {
    00040
    00048 typedef SharedPtr<SubRenderStateAccessor>   SubRenderStateAccessorPtr;
    00049
    00050
    00056 class _OgreRTSSExport SubRenderState : public RTShaderSystemAlloc
    00057 {
    00058
    00059 // Interface.
    00060 public:
    00061
    00063     SubRenderState();
    00064
    00066     virtual ~SubRenderState();
    00067
    00068
    00073     virtual const String& getType() const = 0;
    00074
    00075
    00081     virtual int getExecutionOrder() const = 0;
    00082
    00083
    00087     virtual void copyFrom(const SubRenderState& rhs) = 0;
    00088
    00092     SubRenderState& operator=   (const SubRenderState& rhs);
    00093
    00100     virtual bool createCpuSubPrograms(ProgramSet* programSet);
    00101
    00111     virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass,  const AutoParamDataSource* source,  const LightList* pLightList) { }
    00112
    00120     virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass) { return true; }
    00121
    00125     SubRenderStateAccessorPtr getAccessor();
    00126
    00130     SubRenderStateAccessorPtr getAccessor() const;
    00131
    00132 // Protected methods
    00133 protected:
    00134
    00139     virtual bool resolveParameters(ProgramSet* programSet);
    00140
    00145     virtual bool resolveDependencies(ProgramSet* programSet);
    00146
    00151     virtual bool addFunctionInvocations(ProgramSet* programSet);
    00152
    00153 // Attributes.
    00154 private:
    00155     // The accessor of this instance.
    00156     mutable SubRenderStateAccessorPtr mThisAccessor;
    00157     // The accessor of the source instance which used as base to create this instance.
    00158     SubRenderStateAccessorPtr mOtherAccessor;
    00159
    00160 };
    00161
    00162 typedef vector<SubRenderState*>::type               SubRenderStateList;
    00163 typedef SubRenderStateList::iterator                SubRenderStateListIterator;
    00164 typedef SubRenderStateList::const_iterator          SubRenderStateListConstIterator;
    00165
    00166 typedef set<SubRenderState*>::type                  SubRenderStateSet;
    00167 typedef SubRenderStateSet::iterator                 SubRenderStateSetIterator;
    00168 typedef SubRenderStateSet::const_iterator           SubRenderStateSetConstIterator;
    00169
    00170
    00177 class _OgreRTSSExport SubRenderStateAccessor
    00178 {
    00179 public:
    00182     void addSubRenderStateInstance(SubRenderState* subRenderState) const
    00183     {
    00184         mSubRenderStateInstancesSet.insert(subRenderState);
    00185     }
    00186
    00189     void removeSubRenderStateInstance(SubRenderState* subRenderState) const
    00190     {
    00191         SubRenderStateSetIterator itFind = mSubRenderStateInstancesSet.find(subRenderState);
    00192
    00193         if (itFind != mSubRenderStateInstancesSet.end())
    00194         {
    00195             mSubRenderStateInstancesSet.erase(itFind);
    00196         }
    00197     }
    00198
    00200     SubRenderStateSet& getSubRenderStateInstanceSet() { return mSubRenderStateInstancesSet; }
    00201
    00203     const SubRenderStateSet& getSubRenderStateInstanceSet() const { return mSubRenderStateInstancesSet; }
    00204
    00205 protected:
    00208     SubRenderStateAccessor(const SubRenderState* templateSubRenderState) : mTemplateSubRenderState(templateSubRenderState) {}
    00209
    00210
    00211 protected:
    00212     const SubRenderState* mTemplateSubRenderState;
    00213     mutable SubRenderStateSet mSubRenderStateInstancesSet;
    00214
    00215 private:
    00216     friend class SubRenderState;
    00217
    00218 };
    00219
    00220
    00232 class _OgreRTSSExport SubRenderStateFactory : public RTShaderSystemAlloc
    00233 {
    00234
    00235 public:
    00236     SubRenderStateFactory() {}
    00237     virtual ~SubRenderStateFactory();
    00238
    00244     virtual const String& getType() const = 0;
    00245
    00248     virtual SubRenderState* createInstance();
    00249
    00257     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator) { return NULL; }
    00258
    00266     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, TextureUnitState* texState, SGScriptTranslator* translator) { return NULL; }
    00267
    00272     virtual SubRenderState* createOrRetrieveInstance(SGScriptTranslator* translator);
    00273
    00277     virtual void destroyInstance(SubRenderState* subRenderState);
    00278
    00281     virtual void destroyAllInstances();
    00282
    00292     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass) {}
    00293
    00303     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, const TextureUnitState* srcTextureUnit, const TextureUnitState* dstTextureUnit) {}
    00304 protected:
    00309     virtual SubRenderState* createInstanceImpl() = 0;
    00310
    00311 // Attributes.
    00312 protected:
    00313     // List of all sub render states instances this factory created.
    00314     SubRenderStateSet mSubRenderStateList;
    00315 };
    00316
    00320 }
    00321 }
    00322
    00323 #endif
    00324

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24