Ogre源码分析与学习笔记-2 纹理
来源:互联网 发布:guts and glory mac 编辑:程序博客网 时间:2024/06/02 02:14
Ogre纹理的继承关系:
Resource -> Texture -> GLTexture
1. Resource , 顾名思义就是资源, 包括纹理, 材质, 三角形网格等. Resource由ResourceManager管理, 几个核心函数:
class _OgreExport Resource { public: /** Basic constructor. @warn Subclasses must init mName and mSize! */ Resource() : mIsLoaded( false ), mSize( 0 ) { } /** Virtual destructor. Shouldn't need to be overloaded, as the resource deallocation code should reside in unload() @see Resource::unload() */ virtual ~Resource() { if( mIsLoaded ) unload(); } /** Loads the resource, if it is not already. */ virtual void load() = 0; /** Unloads the resource, but retains data to recreate. */ virtual void unload() {}; /** Gets the last time the resource was 'touched'. */ time_t getLastAccess(void) const { return mLastAccess; } /** A method to make the resource delete itself. @note This exists because Resource objects could be created in other processes, and they need to be destroyed in the process that created them. */ virtual void destroy() { delete this; } };
一个Resource的生命周期: Create -> Load -> Unload -> Destroy.
资源对象被构造出来时, 并不会马上把资源内容Load到内存, 而是根据需要Load, 当一个ResourceManager使用的内存达到上限时, 会主动Unload一些资源, 但不会Destroy它. Unload的根据是最后使用时间
//----------------------------------------------------------------------- void ResourceManager::load(Resource *res, int priority) { res->load(); res->touch(); mResources.insert( ResourceMap::value_type( res->getName(), res ) ); }
Texture类没有实现Resource类的纯虚方法, 而是加入了Texture对象的必要属性:
class _OgreExport Texture : public Resource { public: /** Blits the contents of src on the texture. @deprecated This feature is superseded by the blitImage function. @param src the image with the source data */ virtual void blitToTexture( const Image &src, unsigned uStartX, unsigned uStartY ) = 0; /** Blits a rect from an image to the texture. @param src The image with the source data. @param imgRect The data rect to be copied from the image. @param texRect The rect in which to copy the data in the texture. */ virtual void blitImage( const Image& src, const Image::Rect imgRect, const Image::Rect texRect ) { }/** Copies (and maybe scales to fit) the contents of this texture toanother texture. */virtual void copyToTexture( Texture * target ) {}; /** Loads the data from an image. */ virtual void loadImage( const Image &img ) = 0; protected: unsigned long mHeight; unsigned long mWidth; unsigned short mNumMipMaps; float mGamma; TextureType mTextureType;PixelFormat mFormat; TextureUsage mUsage; unsigned short mSrcBpp; unsigned long mSrcWidth, mSrcHeight; unsigned short mFinalBpp; bool mHasAlpha; };
GLTexture 继承自Texture, 并且不再被继承
class GLTexture : public Texture { public: void load(); void loadImage( const Image &img ); void loadImages( const std::vector<Image> images ); void unload(); void createRenderTexture(); void blitToTexture( const Image& src, unsigned uStartX, unsigned uStartY ); GLuint getGLID() const { return mTextureID; } };
它实现了最终的OpenGL可以使用的texture, 由于平台相关性, GLTexture 需要使用 GLTextureManager来产生:
class GLTextureManager : public TextureManager { public: /** Creates a SDLTexture resource. */ virtual Texture* create( const String& name, TextureType texType); };
- Ogre源码分析与学习笔记-2 纹理
- Ogre源码分析与学习笔记-0
- Ogre源码分析与学习笔记-1
- Ogre源码分析与学习笔记-3 材质
- ogre源码分析 链接
- Ogre纹理的导出与保存
- Ogre纹理阴影与模板阴影
- UnityShader入门精要学习笔记(九):基础纹理之渐变纹理与遮罩纹理
- netty5源码分析(2)--学习笔记
- 【笔记】六、OGRE与CEGUI中Demo分析
- OGRE学习笔记
- OGRE学习笔记
- OGRE学习笔记
- OGRE学习笔记
- Ogre PCZSceneManger学习笔记
- OGRE学习笔记
- D3D学习笔记:纹理
- OpenGL学习笔记:纹理
- eclipse windows python 插件安装
- TextHello - 在 Console Application 下创建第一个C#程序
- 排序--概论
- 一种复杂度为O(n)的排序算法:位操作应用之位排序
- apache-collection的使用
- Ogre源码分析与学习笔记-2 纹理
- Linux中/proc目录下文件详解
- 苹果 ios----把NSDate只精确到天
- HDU3905 DP
- TCP/IP三次握手详解
- Prototypes.js 使用
- 或的解决方案
- 介绍两种常用的Ftp客户端如何显示.htaccess等隐藏文件
- 支持向量机简介