OgreShaderExTextureAtlasSampler.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 _ShaderSGXAtlasTexture_
    00028 #define _ShaderSGXAtlasTexture_
    00029
    00030 #include "OgreShaderPrerequisites.h"
    00031 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
    00032 #include "OgreShaderSubRenderState.h"
    00033 #include "OgreShaderParameter.h"
    00034
    00035 #define TAS_MAX_TEXTURES 4
    00036 namespace Ogre {
    00037 namespace RTShader {
    00038
    00045 struct _OgreRTSSExport TextureAtlasRecord
    00046 {
    00047     TextureAtlasRecord(const String & texOriginalName, const String & texAtlasName,
    00048                        const float texPosU, const float texPosV, const float texWidth, const float texHeight,
    00049                        const size_t texIndexInAtlas) :
    00050                   posU(texPosU)
    00051                 , posV(texPosV)
    00052                 , width(texWidth)
    00053                 , height(texHeight)
    00054                 , originalTextureName(texOriginalName)
    00055                 , atlasTextureName(texAtlasName)
    00056                 , indexInAtlas(texIndexInAtlas)
    00057     { }
    00058
    00059     float posU;
    00060     float posV;
    00061     float width;
    00062     float height;
    00063     String originalTextureName;
    00064     String atlasTextureName;
    00065     size_t indexInAtlas;
    00066 };
    00067
    00068 typedef vector<TextureAtlasRecord>::type TextureAtlasTable;
    00069 typedef SharedPtr<TextureAtlasTable> TextureAtlasTablePtr;
    00070 typedef map<String, TextureAtlasTablePtr>::type TextureAtlasMap;
    00071
    00072
    00073
    00130 class _OgreRTSSExport TextureAtlasSampler : public SubRenderState
    00131 {
    00132 public:
    00133
    00134 // Interface.
    00135 public:
    00136
    00138     TextureAtlasSampler();
    00139
    00143     virtual const String& getType() const;
    00144
    00148     virtual int getExecutionOrder() const;
    00149
    00153     virtual void copyFrom(const SubRenderState& rhs);
    00154
    00158     virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass,  const AutoParamDataSource* source,  const LightList* pLightList);
    00159
    00163     virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
    00164
    00165     static String Type;
    00166
    00167 // Protected methods
    00168 protected:
    00169     virtual bool resolveParameters(ProgramSet* programSet);
    00170     virtual bool resolveDependencies(ProgramSet* programSet);
    00171     virtual bool addFunctionInvocations(ProgramSet* programSet);
    00172
    00176     const char* getAdressingFunctionName(TextureUnitState::TextureAddressingMode mode);
    00177
    00178
    00179 // Attributes.
    00180 protected:
    00181     // The index of the information on the texture in the table
    00182     ParameterPtr mVSInpTextureTableIndex;
    00183
    00184     TextureUnitState::UVWAddressingMode mTextureAddressings[TAS_MAX_TEXTURES]; // The addressing mode for each texture
    00185     // The position and size of the texture in the atlas
    00186     ParameterPtr mVSOutTextureDatas[TAS_MAX_TEXTURES];
    00187     // The position and size of the texture in the atlas
    00188     ParameterPtr mPSInpTextureDatas[TAS_MAX_TEXTURES];
    00189     //A parameter carrying the sizes of the atlas textures
    00190     UniformParameterPtr mPSTextureSizes[TAS_MAX_TEXTURES];
    00191     // The table containing information on the textures in the atlas
    00192     UniformParameterPtr mVSTextureTable[TAS_MAX_TEXTURES];
    00193
    00194     //The position of the texture coordinates containing the index information
    00195     ushort mAtlasTexcoordPos;
    00196     //The texture atlas table data
    00197     TextureAtlasTablePtr mAtlasTableDatas[TAS_MAX_TEXTURES];
    00198     //For each texture unit in the pass tells if it uses atlas texture
    00199     bool mIsAtlasTextureUnits[TAS_MAX_TEXTURES];
    00200     //Tells if the data in mAtlasTableData has been uploaded to the corresponding mVSTextureTable parameter
    00201     bool mIsTableDataUpdated;
    00202     //Tells whether border issue handling uses auto adjust polling position.
    00203     bool mAutoAdjustPollPosition;
    00204 };
    00205
    00206
    00207
    00212 class _OgreRTSSExport TextureAtlasSamplerFactory : public SubRenderStateFactory, public Singleton<TextureAtlasSamplerFactory>
    00213 {
    00214 public:
    00215     enum IndexPositionMode
    00216     {
    00217         ipmRelative,
    00218         ipmAbsolute
    00219     };
    00220
    00221     struct TextureAtlasAttib
    00222     {
    00223         TextureAtlasAttib(IndexPositionMode _posMode = ipmRelative, ushort _posOffset = 1,
    00224             bool _autoBorderAdjust = true) : positionMode(_posMode), positionOffset(_posOffset),
    00225              autoBorderAdjust(_autoBorderAdjust) {}
    00226
    00227         IndexPositionMode positionMode;
    00228         ushort positionOffset;
    00229         bool autoBorderAdjust;
    00230     };
    00231
    00232 public:
    00233
    00234     //TextureAtlasSamplerFactory c_tor
    00235     TextureAtlasSamplerFactory();
    00236
    00237     //Singleton implementation
    00238     static TextureAtlasSamplerFactory* getSingletonPtr(void);
    00239     static TextureAtlasSamplerFactory& getSingleton(void);
    00240
    00241
    00242
    00246     virtual const String& getType() const;
    00247
    00251     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
    00252
    00256     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
    00257
    00276     bool addTexutreAtlasDefinition( const Ogre::String& filename, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
    00277     bool addTexutreAtlasDefinition( DataStreamPtr stream, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
    00278
    00287     void setTextureAtlasTable(const String& textureName, const TextureAtlasTablePtr& atlasData, bool autoBorderAdjust = true);
    00288
    00293     void removeTextureAtlasTable(const String& textureName);
    00294
    00298     void removeAllTextureAtlasTables();
    00299
    00304     const TextureAtlasTablePtr& getTextureAtlasTable(const String& textureName) const;
    00305
    00316     void setDefaultAtlasingAttributes(IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
    00317
    00322     const TextureAtlasAttib& getDefaultAtlasingAttributes() const;
    00323
    00335     void setMaterialAtlasingAttributes(Ogre::Material* material,
    00336         IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
    00337
    00338
    00344     bool hasMaterialAtlasingAttributes(Ogre::Material* material, TextureAtlasAttib* attrib = NULL) const;
    00345
    00346 protected:
    00347
    00348
    00349
    00353     virtual SubRenderState* createInstanceImpl();
    00354
    00355 private:
    00356
    00357     //Holds a mapping of texture names and the atlas table information associated with them
    00358     TextureAtlasMap mAtlases;
    00359
    00360     TextureAtlasAttib mDefaultAtlasAttrib;
    00361 };
    00362
    00363 _OgreRTSSExport void operator<<(std::ostream& o, const TextureAtlasSamplerFactory::TextureAtlasAttib& tai);
    00364
    00368 }
    00369 }
    00370
    00371 #endif
    00372 #endif

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:23