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-2013 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:
00182     ParameterPtr mVSInpTextureTableIndex;
00183     
00185     TextureUnitState::UVWAddressingMode mTextureAddressings[TAS_MAX_TEXTURES];
00187     ParameterPtr mVSOutTextureDatas[TAS_MAX_TEXTURES];
00189     ParameterPtr mPSInpTextureDatas[TAS_MAX_TEXTURES];
00191     UniformParameterPtr mPSTextureSizes[TAS_MAX_TEXTURES];
00193     UniformParameterPtr mVSTextureTable[TAS_MAX_TEXTURES];
00194 
00196     ushort mAtlasTexcoordPos; 
00198     TextureAtlasTablePtr mAtlasTableDatas[TAS_MAX_TEXTURES];
00200     bool mIsAtlasTextureUnits[TAS_MAX_TEXTURES];
00202     bool mIsTableDataUpdated;
00204     bool mAutoAdjustPollPosition;
00205 };
00206 
00207 
00208 
00213 class _OgreRTSSExport TextureAtlasSamplerFactory : public SubRenderStateFactory, public Singleton<TextureAtlasSamplerFactory>
00214 {
00215 public:
00216     enum IndexPositionMode
00217     {
00218         ipmRelative,
00219         ipmAbsolute
00220     };
00221 
00222     struct TextureAtlasAttib
00223     {
00224         TextureAtlasAttib(IndexPositionMode _posMode = ipmRelative, ushort _posOffset = 1,
00225             bool _autoBorderAdjust = true) : positionMode(_posMode), positionOffset(_posOffset),
00226              autoBorderAdjust(_autoBorderAdjust) {}
00227 
00228         IndexPositionMode positionMode;
00229         ushort positionOffset;
00230         bool autoBorderAdjust;
00231     };
00232 
00233 public:
00234 
00235     //TextureAtlasSamplerFactory c_tor
00236     TextureAtlasSamplerFactory();
00237 
00238     //Singleton implementation
00239     static TextureAtlasSamplerFactory* getSingletonPtr(void);
00240     static TextureAtlasSamplerFactory& getSingleton(void);
00241     
00242 
00243 
00247     virtual const String& getType() const;
00248 
00252     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
00253 
00257     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
00258     
00274     bool addTexutreAtlasDefinition( const Ogre::String& filename, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
00290     bool addTexutreAtlasDefinition( DataStreamPtr stream, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
00291 
00300     void setTextureAtlasTable(const String& textureName, const TextureAtlasTablePtr& atlasData, bool autoBorderAdjust = true);
00301     
00306     void removeTextureAtlasTable(const String& textureName);
00307 
00311     void removeAllTextureAtlasTables();
00312 
00317     const TextureAtlasTablePtr& getTextureAtlasTable(const String& textureName) const;
00318 
00329     void setDefaultAtlasingAttributes(IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
00330 
00335     const TextureAtlasAttib& getDefaultAtlasingAttributes() const;
00336 
00348     void setMaterialAtlasingAttributes(Ogre::Material* material, 
00349         IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
00350 
00351 
00357     bool hasMaterialAtlasingAttributes(Ogre::Material* material, TextureAtlasAttib* attrib = NULL) const;
00358     
00359 protected:
00360 
00361     
00362 
00366     virtual SubRenderState* createInstanceImpl();
00367 
00368 private:
00369 
00370     //Holds a mapping of texture names and the atlas table information associated with them
00371     TextureAtlasMap mAtlases;
00372 
00373     TextureAtlasAttib mDefaultAtlasAttrib;
00374 };
00375 
00376 _OgreRTSSExport void operator<<(std::ostream& o, const TextureAtlasSamplerFactory::TextureAtlasAttib& tai);
00377 
00381 }
00382 }
00383 
00384 #endif
00385 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45