# 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-2009 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     (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     mutable SubRenderStateAccessorPtr   mThisAccessor;          // The accessor of this instance.
    00156     SubRenderStateAccessorPtr           mOtherAccessor;         // The accessor of the source instance which used as base to create this instance.
    00157
    00158 };
    00159
    00160 typedef vector<SubRenderState*>::type               SubRenderStateList;
    00161 typedef SubRenderStateList::iterator                SubRenderStateListIterator;
    00162 typedef SubRenderStateList::const_iterator          SubRenderStateListConstIterator;
    00163
    00164 typedef set<SubRenderState*>::type                  SubRenderStateSet;
    00165 typedef SubRenderStateSet::iterator                 SubRenderStateSetIterator;
    00166 typedef SubRenderStateSet::const_iterator           SubRenderStateSetConstIterator;
    00167
    00168
    00175 class _OgreRTSSExport SubRenderStateAccessor
    00176 {
    00177 public:
    00180     void addSubRenderStateInstance(SubRenderState* subRenderState) const
    00181     {
    00182         mSubRenderStateInstancesSet.insert(subRenderState);
    00183     }
    00184
    00187     void removeSubRenderStateInstance(SubRenderState* subRenderState) const
    00188     {
    00189         SubRenderStateSetIterator itFind = mSubRenderStateInstancesSet.find(subRenderState);
    00190
    00191         if (itFind != mSubRenderStateInstancesSet.end())
    00192         {
    00193             mSubRenderStateInstancesSet.erase(itFind);
    00194         }
    00195     }
    00196
    00198     SubRenderStateSet&  getSubRenderStateInstanceSet() { return mSubRenderStateInstancesSet; }
    00199
    00201     const SubRenderStateSet&    getSubRenderStateInstanceSet() const { return mSubRenderStateInstancesSet; }
    00202
    00203 protected:
    00206     SubRenderStateAccessor(const SubRenderState* templateSubRenderState) : mTemplateSubRenderState(templateSubRenderState) {}
    00207
    00208
    00209 protected:
    00210     const SubRenderState*       mTemplateSubRenderState;
    00211     mutable SubRenderStateSet   mSubRenderStateInstancesSet;
    00212
    00213 private:
    00214     friend class SubRenderState;
    00215
    00216 };
    00217
    00218
    00230 class _OgreRTSSExport SubRenderStateFactory : public RTShaderSystemAlloc
    00231 {
    00232
    00233 public:
    00234     SubRenderStateFactory           () {}
    00235     virtual ~SubRenderStateFactory  ();
    00236
    00242     virtual const String&   getType             () const = 0;
    00243
    00246     virtual SubRenderState* createInstance      ();
    00247
    00255     virtual SubRenderState* createInstance      (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass) { return NULL; }
    00256
    00260     virtual void            destroyInstance     (SubRenderState* subRenderState);
    00261
    00264     virtual void            destroyAllInstances ();
    00265
    00275     virtual void            writeInstance       (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass) {}
    00276
    00277 protected:
    00282     virtual SubRenderState* createInstanceImpl  () = 0;
    00283
    00284 // Attributes.
    00285 protected:
    00286     SubRenderStateSet       mSubRenderStateList;        // List of all sub render states instances this factory created.
    00287 };
    00288
    00292 }
    00293 }
    00294
    00295 #endif
    00296

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:09