OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderExTextureAtlasSampler.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderSGXAtlasTexture_
28 #define _ShaderSGXAtlasTexture_
29 
31 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
33 #include "OgreTextureUnitState.h"
34 
35 #define TAS_MAX_TEXTURES 4
36 namespace Ogre {
37 namespace RTShader {
38 
45 struct _OgreRTSSExport TextureAtlasRecord
46 {
47  TextureAtlasRecord(const String & texOriginalName, const String & texAtlasName,
48  const float texPosU, const float texPosV, const float texWidth, const float texHeight,
49  const size_t texIndexInAtlas) :
50  posU(texPosU)
51  , posV(texPosV)
52  , width(texWidth)
53  , height(texHeight)
54  , originalTextureName(texOriginalName)
55  , atlasTextureName(texAtlasName)
56  , indexInAtlas(texIndexInAtlas)
57  { }
58 
59  float posU;
60  float posV;
61  float width;
62  float height;
63  String originalTextureName;
64  String atlasTextureName;
65  size_t indexInAtlas;
66 };
67 
68 typedef vector<TextureAtlasRecord>::type TextureAtlasTable;
69 typedef SharedPtr<TextureAtlasTable> TextureAtlasTablePtr;
70 typedef map<String, TextureAtlasTablePtr>::type TextureAtlasMap;
71 
72 
73 
130 class _OgreRTSSExport TextureAtlasSampler : public SubRenderState
131 {
132 public:
133 
134 // Interface.
135 public:
136 
138  TextureAtlasSampler();
139 
143  virtual const String& getType() const;
144 
148  virtual int getExecutionOrder() const;
149 
153  virtual void copyFrom(const SubRenderState& rhs);
154 
158  virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
159 
163  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
164 
165  static String Type;
166 
167 // Protected methods
168 protected:
169  virtual bool resolveParameters(ProgramSet* programSet);
170  virtual bool resolveDependencies(ProgramSet* programSet);
171  virtual bool addFunctionInvocations(ProgramSet* programSet);
172 
176  const char* getAdressingFunctionName(TextureUnitState::TextureAddressingMode mode);
177 
178 
179 // Attributes.
180 protected:
182  ParameterPtr mVSInpTextureTableIndex;
183 
185  TextureUnitState::UVWAddressingMode mTextureAddressings[TAS_MAX_TEXTURES];
187  ParameterPtr mVSOutTextureDatas[TAS_MAX_TEXTURES];
189  ParameterPtr mPSInpTextureDatas[TAS_MAX_TEXTURES];
191  UniformParameterPtr mPSTextureSizes[TAS_MAX_TEXTURES];
193  UniformParameterPtr mVSTextureTable[TAS_MAX_TEXTURES];
194 
196  ushort mAtlasTexcoordPos;
198  TextureAtlasTablePtr mAtlasTableDatas[TAS_MAX_TEXTURES];
200  bool mIsAtlasTextureUnits[TAS_MAX_TEXTURES];
202  bool mIsTableDataUpdated;
204  bool mAutoAdjustPollPosition;
205 };
206 
207 
208 
213 class _OgreRTSSExport TextureAtlasSamplerFactory : public SubRenderStateFactory, public Singleton<TextureAtlasSamplerFactory>
214 {
215 public:
216  enum IndexPositionMode
217  {
218  ipmRelative,
219  ipmAbsolute
220  };
221 
222  struct TextureAtlasAttib
223  {
224  TextureAtlasAttib(IndexPositionMode _posMode = ipmRelative, ushort _posOffset = 1,
225  bool _autoBorderAdjust = true) : positionMode(_posMode), positionOffset(_posOffset),
226  autoBorderAdjust(_autoBorderAdjust) {}
227 
228  IndexPositionMode positionMode;
229  ushort positionOffset;
230  bool autoBorderAdjust;
231  };
232 
233 public:
234 
235  //TextureAtlasSamplerFactory c_tor
236  TextureAtlasSamplerFactory();
237 
238  //Singleton implementation
239  static TextureAtlasSamplerFactory* getSingletonPtr(void);
240  static TextureAtlasSamplerFactory& getSingleton(void);
241 
242 
243 
247  virtual const String& getType() const;
248 
252  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
253 
257  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
258 
274  bool addTexutreAtlasDefinition( const Ogre::String& filename, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
290  bool addTexutreAtlasDefinition( DataStreamPtr stream, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
291 
300  void setTextureAtlasTable(const String& textureName, const TextureAtlasTablePtr& atlasData, bool autoBorderAdjust = true);
301 
306  void removeTextureAtlasTable(const String& textureName);
307 
311  void removeAllTextureAtlasTables();
312 
317  const TextureAtlasTablePtr& getTextureAtlasTable(const String& textureName) const;
318 
329  void setDefaultAtlasingAttributes(IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
330 
335  const TextureAtlasAttib& getDefaultAtlasingAttributes() const;
336 
348  void setMaterialAtlasingAttributes(Ogre::Material* material,
349  IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
350 
351 
357  bool hasMaterialAtlasingAttributes(Ogre::Material* material, TextureAtlasAttib* attrib = NULL) const;
358 
359 protected:
360 
361 
362 
366  virtual SubRenderState* createInstanceImpl();
367 
368 private:
369 
370  //Holds a mapping of texture names and the atlas table information associated with them
371  TextureAtlasMap mAtlases;
372 
373  TextureAtlasAttib mDefaultAtlasAttrib;
374 };
375 
376 _OgreRTSSExport void operator<<(std::ostream& o, const TextureAtlasSamplerFactory::TextureAtlasAttib& tai);
377 
381 }
382 }
383 
384 #endif
385 #endif
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:84
#define _OgreRTSSExport
SharedPtr< Parameter > ParameterPtr
HashedVector< LightClosest > LightList
Definition: OgreCommon.h:569
SharedPtr< DataStream > DataStreamPtr
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
unsigned short ushort
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:666
SharedPtr< UniformParameter > UniformParameterPtr
_StringBase String
Definition: OgreCommon.h:53