OgreShaderExTextureAtlasSampler.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25-----------------------------------------------------------------------------
26*/
27#ifndef _ShaderSGXAtlasTexture_
28#define _ShaderSGXAtlasTexture_
29
31#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
33#include "OgreShaderParameter.h"
34
35#define TAS_MAX_TEXTURES 4
36namespace Ogre {
37namespace RTShader {
38
45struct _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
68typedef vector<TextureAtlasRecord>::type TextureAtlasTable;
69typedef SharedPtr<TextureAtlasTable> TextureAtlasTablePtr;
70typedef map<String, TextureAtlasTablePtr>::type TextureAtlasMap;
71
72
73
130class _OgreRTSSExport TextureAtlasSampler : public SubRenderState
131{
132public:
133
134// Interface.
135public:
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
168protected:
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.
180protected:
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
213class _OgreRTSSExport TextureAtlasSamplerFactory : public SubRenderStateFactory, public Singleton<TextureAtlasSamplerFactory>
214{
215public:
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
233public:
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
359protected:
360
361
362
366 virtual SubRenderState* createInstanceImpl();
367
368private:
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
#define _OgreRTSSExport
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:89
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
HashedVector< Light * > LightList
Definition: OgreCommon.h:542
SharedPtr< Parameter > ParameterPtr
SharedPtr< UniformParameter > UniformParameterPtr
SharedPtr< DataStream > DataStreamPtr
Shared pointer to allow data streams to be passed around without worrying about deallocation.
_StringBase String
unsigned short ushort
std::map< K, V, P, A > type
std::vector< T, A > type

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.