OGRE: OgreShaderProgramProcessor.h Source File - OGRE Documentation

# OgreShaderProgramProcessor.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 _ShaderProgramProcessor_
    00028 #define _ShaderProgramProcessor_
    00029
    00030 #include "OgreShaderPrerequisites.h"
    00031 #include "OgreShaderParameter.h"
    00032 #include "OgreShaderFunctionAtom.h"
    00033
    00034
    00035 namespace Ogre {
    00036 namespace RTShader {
    00037
    00049 class _OgreRTSSExport ProgramProcessor : public RTShaderSystemAlloc
    00050 {
    00051
    00052 // Interface.
    00053 public:
    00054
    00058     ProgramProcessor            ();
    00059
    00061     virtual ~ProgramProcessor   ();
    00062
    00064     virtual const String&       getTargetLanguage   () const = 0;
    00065
    00071     virtual bool                preCreateGpuPrograms    (ProgramSet* programSet) = 0;
    00072
    00077     virtual bool                postCreateGpuPrograms   (ProgramSet* programSet) = 0;
    00078
    00079 // Protected types.
    00080 protected:
    00081
    00082     //-----------------------------------------------------------------------------
    00083     // Class that holds merge parameter information.
    00084     class _OgreRTSSExport MergeParameter
    00085     {
    00086     // Interface.
    00087     public:
    00089         MergeParameter();
    00090
    00091
    00093         void            clear                       ();
    00094
    00096         void            addSourceParameter          (ParameterPtr srcParam, int mask);
    00097
    00099         size_t          getSourceParameterCount     () const { return mSrcParameterCount; }
    00100
    00102         ParameterPtr    getSourceParameter          (unsigned int index) { return mSrcParameter[index]; }
    00103
    00105         int             getSourceParameterMask      (unsigned int index) const { return mSrcParameterMask[index]; }
    00106
    00108         int             getDestinationParameterMask (unsigned int index) const { return mDstParameterMask[index]; }
    00109
    00111         int             getUsedFloatCount           ();
    00112
    00114         ParameterPtr    getDestinationParameter     (int usage, int index);
    00115
    00116     protected:
    00117
    00119         void            createDestinationParameter  (int usage, int index);
    00120
    00121
    00122     protected:
    00123         ParameterPtr    mDstParameter;          // Destination merged parameter.
    00124         ParameterPtr    mSrcParameter[4];       // Source parameters - 4 source at max 1,1,1,1 -> 4.
    00125         int             mSrcParameterMask[4];   // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
    00126         int             mDstParameterMask[4];   // Destination parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
    00127         size_t          mSrcParameterCount;     // The actual source parameters count.
    00128         size_t          mUsedFloatCount;        // The number of used floats.
    00129     };
    00130     typedef vector<MergeParameter>::type    MergeParameterList;
    00131
    00132
    00133     //-----------------------------------------------------------------------------
    00134     // A struct that defines merge parameters combination.
    00135     struct _OgreRTSSExport MergeCombination
    00136     {
    00137         size_t          srcParamterTypeCount[4];    // The count of each source type. I.E (1 FLOAT1, 0 FLOAT2, 1 FLOAT3, 0 FLOAT4).
    00138         int             srcParameterMask[4];        // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
    00139
    00140         MergeCombination(
    00141             int float1Count, int float1Mask,
    00142             int float2Count, int float2Mask,
    00143             int float3Count, int float3Mask,
    00144             int float4Count, int float4Mask)
    00145         {
    00146             srcParamterTypeCount[0] = float1Count;
    00147             srcParamterTypeCount[1] = float2Count;
    00148             srcParamterTypeCount[2] = float3Count;
    00149             srcParamterTypeCount[3] = float4Count;
    00150             srcParameterMask[0]     = float1Mask;
    00151             srcParameterMask[1]     = float2Mask;
    00152             srcParameterMask[2]     = float3Mask;
    00153             srcParameterMask[3]     = float4Mask;
    00154
    00155         }
    00156     };
    00157     typedef vector<MergeCombination>::type  MergeCombinationList;
    00158
    00159     //-----------------------------------------------------------------------------
    00160     typedef vector<Operand*>::type                      OperandPtrVector;
    00161     typedef map<Parameter*, OperandPtrVector>::type     ParameterOperandMap;
    00162     typedef map<Parameter*, ParameterPtr>::type         LocalParameterMap;
    00163
    00164 protected:
    00165
    00167     void            buildMergeCombinations          ();
    00168
    00174     virtual bool    compactVsOutputs                (Function* vsMain, Function* fsMain);
    00175
    00181     void            countVsTexcoordOutputs          (Function* vsMain, int& outTexCoordSlots, int& outTexCoordFloats);
    00182
    00187     void            buildTexcoordTable              (const ShaderParameterList& paramList, ShaderParameterList outParamsTable[4]);
    00188
    00189
    00194     void            mergeParameters                 (ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
    00195
    00196
    00201     void            mergeParametersByPredefinedCombinations(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams);
    00202
    00208     bool            mergeParametersByCombination            (const MergeCombination& combination, ShaderParameterList paramsTable[4],
    00209                                                                  MergeParameter* mergedParameter);
    00210
    00216     void            mergeParametersReminders                (ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
    00217
    00218
    00220     void            generateLocalSplitParameters                (Function* func, GpuProgramType progType, MergeParameterList& mergedParams, ShaderParameterList& splitParams, LocalParameterMap& localParamsMap);
    00221
    00224     void            rebuildParameterList                (Function* func, int paramsUsage, MergeParameterList& mergedParams);
    00225
    00227     void            rebuildFunctionInvocations          (FunctionAtomInstanceList& funcAtomList, MergeParameterList& mergedParams, LocalParameterMap& localParamsMap);
    00228
    00230     void            buildParameterReferenceMap          (FunctionAtomInstanceList& funcAtomList, ParameterOperandMap& paramsRefMap);
    00231
    00233     void            replaceParametersReferences         (MergeParameterList& mergedParams, ParameterOperandMap& paramsRefMap);
    00234
    00236     void            replaceSplitParametersReferences    (LocalParameterMap& localParamsMap, ParameterOperandMap& paramsRefMap);
    00237
    00239     static int      getParameterFloatCount              (GpuConstantType type);
    00240
    00242     static int      getParameterMaskByType              (GpuConstantType type);
    00243
    00245     static int      getParameterMaskByFloatCount        (int floatCount);
    00246
    00248     void            bindAutoParameters                  (Program* pCpuProgram, GpuProgramPtr pGpuProgram);
    00249
    00250 protected:
    00251     MergeCombinationList    mParamMergeCombinations;        // Merging combinations defs.
    00252     int                     mMaxTexCoordSlots;              // Maximum texcoord slots.
    00253     int                     mMaxTexCoordFloats;             // Maximum texcoord floats count.
    00254
    00255 };
    00256
    00257
    00261 }
    00262 }
    00263
    00264 #endif
    00265

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52