OgreShaderExTextureAtlasSampler.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _ShaderSGXAtlasTexture_
#define _ShaderSGXAtlasTexture_
#include "OgreShaderPrerequisites.h"
#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
#include "OgreShaderSubRenderState.h"
#include "OgreShaderParameter.h"
#define TAS_MAX_TEXTURES 4
namespace Ogre {
namespace RTShader {
struct _OgreRTSSExport TextureAtlasRecord
{
TextureAtlasRecord(const String & texOriginalName, const String & texAtlasName,
const float texPosU, const float texPosV, const float texWidth, const float texHeight,
const size_t texIndexInAtlas) :
posU(texPosU)
, posV(texPosV)
, width(texWidth)
, height(texHeight)
, originalTextureName(texOriginalName)
, atlasTextureName(texAtlasName)
, indexInAtlas(texIndexInAtlas)
{ }
float posU;
float posV;
float width;
float height;
String originalTextureName;
String atlasTextureName;
size_t indexInAtlas;
};
typedef vector<TextureAtlasRecord>::type TextureAtlasTable;
typedef SharedPtr<TextureAtlasTable> TextureAtlasTablePtr;
typedef map<String, TextureAtlasTablePtr>::type TextureAtlasMap;
class _OgreRTSSExport TextureAtlasSampler : public SubRenderState
{
public:
// Interface.
public:
TextureAtlasSampler();
virtual const String& getType() const;
virtual int getExecutionOrder() const;
virtual void copyFrom(const SubRenderState& rhs);
virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
static String Type;
// Protected methods
protected:
virtual bool resolveParameters(ProgramSet* programSet);
virtual bool resolveDependencies(ProgramSet* programSet);
virtual bool addFunctionInvocations(ProgramSet* programSet);
const char* getAdressingFunctionName(TextureUnitState::TextureAddressingMode mode);
// Attributes.
protected:
ParameterPtr mVSInpTextureTableIndex;
TextureUnitState::UVWAddressingMode mTextureAddressings[TAS_MAX_TEXTURES];
ParameterPtr mVSOutTextureDatas[TAS_MAX_TEXTURES];
ParameterPtr mPSInpTextureDatas[TAS_MAX_TEXTURES];
UniformParameterPtr mPSTextureSizes[TAS_MAX_TEXTURES];
UniformParameterPtr mVSTextureTable[TAS_MAX_TEXTURES];
ushort mAtlasTexcoordPos;
TextureAtlasTablePtr mAtlasTableDatas[TAS_MAX_TEXTURES];
bool mIsAtlasTextureUnits[TAS_MAX_TEXTURES];
bool mIsTableDataUpdated;
bool mAutoAdjustPollPosition;
};
class _OgreRTSSExport TextureAtlasSamplerFactory : public SubRenderStateFactory, public Singleton<TextureAtlasSamplerFactory>
{
public:
enum IndexPositionMode
{
ipmRelative,
ipmAbsolute
};
struct TextureAtlasAttib
{
TextureAtlasAttib(IndexPositionMode _posMode = ipmRelative, ushort _posOffset = 1,
bool _autoBorderAdjust = true) : positionMode(_posMode), positionOffset(_posOffset),
autoBorderAdjust(_autoBorderAdjust) {}
IndexPositionMode positionMode;
ushort positionOffset;
bool autoBorderAdjust;
};
public:
//TextureAtlasSamplerFactory c_tor
TextureAtlasSamplerFactory();
//Singleton implementation
static TextureAtlasSamplerFactory* getSingletonPtr(void);
static TextureAtlasSamplerFactory& getSingleton(void);
virtual const String& getType() const;
virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
bool addTexutreAtlasDefinition( const Ogre::String& filename, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
bool addTexutreAtlasDefinition( DataStreamPtr stream, TextureAtlasTablePtr textureAtlasTable = TextureAtlasTablePtr());
void setTextureAtlasTable(const String& textureName, const TextureAtlasTablePtr& atlasData, bool autoBorderAdjust = true);
void removeTextureAtlasTable(const String& textureName);
void removeAllTextureAtlasTables();
const TextureAtlasTablePtr& getTextureAtlasTable(const String& textureName) const;
void setDefaultAtlasingAttributes(IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
const TextureAtlasAttib& getDefaultAtlasingAttributes() const;
void setMaterialAtlasingAttributes(Ogre::Material* material,
IndexPositionMode mode, ushort offset, bool autoAdjustBorders);
bool hasMaterialAtlasingAttributes(Ogre::Material* material, TextureAtlasAttib* attrib = NULL) const;
protected:
virtual SubRenderState* createInstanceImpl();
private:
//Holds a mapping of texture names and the atlas table information associated with them
TextureAtlasMap mAtlases;
TextureAtlasAttib mDefaultAtlasAttrib;
};
_OgreRTSSExport void operator<<(std::ostream& o, const TextureAtlasSamplerFactory::TextureAtlasAttib& tai);
}
}
#endif
#endif
Ogre::RTShader::UniformParameterPtr
SharedPtr< UniformParameter > UniformParameterPtr
Definition: OgreShaderParameter.h:568
Ogre::LightList
HashedVector< Light * > LightList
Definition: OgreCommon.h:541
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
OgreShaderParameter.h
OgreShaderPrerequisites.h
Ogre::RTShader::ParameterPtr
SharedPtr< Parameter > ParameterPtr
Definition: OgreShaderParameter.h:369
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::operator<<
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
Ogre::TextureUnitState::TextureAddressingMode
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
Definition: OgreTextureUnitState.h:126
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::DataStreamPtr
SharedPtr< DataStream > DataStreamPtr
Shared pointer to allow data streams to be passed around without worrying about deallocation.
Definition: OgreDataStream.h:308
OgreShaderSubRenderState.h
_OgreRTSSExport
#define _OgreRTSSExport
Definition: OgreShaderPrerequisites.h:108
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Material
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:88
Ogre::ushort
unsigned short ushort
Definition: OgrePrerequisites.h:113

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