蔡军生先生第二人生的源码分析(五十六)OpenGL离屏渲染的实现
2008-06-01 14:21
483 查看
我们都知道显示卡有一片内存叫做显存,顾名思义,显存就是显示内容的存储器。意思就是说所有显示到显示器的内容都需要放到这片内存里,然后显示卡再作DAC的动作,最后才能从屏幕里看到输出的内容。现在的显示内存都比较大了,在屏幕里显示一帧图片,已经只占很小一块内存空间了。那也许你会问为什么厂家还在不断推出大显示内存的显示卡呢?难道厂商只是想多挣几块钱吗?呵呵,下面就带你来了解一下大显示内存的优势所在,其实由于显示卡与内存之间,还需要通过数据总线来连接的,其实越多显示内容放在显示卡里面,就会加速显示速度。并且现在的显示卡,还可以一边显示小部份内存,一边让剩余的显示内存就让给CPU在后台操作,生成下一帧的数据,这样显示内存越大,就可以后台生成越多的图片帧数据,这样就可以加速显示。那么在后台生成的显示数据,就叫做离屏渲染。下面就来看看第二人生里是怎么使用这种高级的功能呢?LLRenderTarget类的声明代码如下:
#001 class LLRenderTarget
#002 {
#003 public:
是否使用离屏对象。
#004 //whether or not to use FBO implementation
#005 static BOOL sUseFBO;
#006
#007 LLRenderTarget();
#008 ~LLRenderTarget();
#009
#010 //allocate resources for rendering
#011 //must be called before use
#012 //multiple calls will release previously allocated resources
下面函数分配离屏对象。
#013 void allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage = GL_TEXTURE_2D, BOOL force_fbo = FALSE);
#014
#015 //free any allocated resources
#016 //safe to call redundantly
下面函数删除离屏对象。
#017 void release();
#018
#019 //bind target for rendering
#020 //applies appropriate viewport
下面函数绑定离屏对象。
#021 void bindTarget();
#022
#023 //clear render targer, clears depth buffer if present,
#024 //uses scissor rect if in copy-to-texture mode
下面函数清除离屏对象内容。
#025 void clear();
#026
下面函数获取显示的视口。
#027 //get applied viewport
#028 void getViewport(S32* viewport);
#029
下面函数设置纹理。
#030 //bind results of render for sampling
#031 void bindTexture();
#032
下面函数显示离屏对象到显示内存。
#033 //flush rendering operations
#034 //must be called when rendering is complete
#035 //should be used 1:1 with bindTarget
#036 // call bindTarget once, do all your rendering, call flush once
#037 void flush();
#038
下面函数判断是否离屏对象是否准备好。
#039 //Returns TRUE if target is ready to be rendered into.
#040 //That is, if the target has been allocated with at least
#041 //one renderable attachment (i.e. color buffer, depth buffer).
#042 BOOL isComplete() const;
#043
#044 private:
#045 U32 mResX;
#046 U32 mResY;
#047 U32 mTex;
#048 U32 mFBO;
#049 U32 mDepth;
#050 BOOL mUseDepth;
#051 U32 mUsage;
#052 };
#053
上面类LLRenderTarget就通过这些函数来操作离屏对象的。下一次再仔细分析它是通什么样OpenGL函数来实现的。
#001 class LLRenderTarget
#002 {
#003 public:
是否使用离屏对象。
#004 //whether or not to use FBO implementation
#005 static BOOL sUseFBO;
#006
#007 LLRenderTarget();
#008 ~LLRenderTarget();
#009
#010 //allocate resources for rendering
#011 //must be called before use
#012 //multiple calls will release previously allocated resources
下面函数分配离屏对象。
#013 void allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage = GL_TEXTURE_2D, BOOL force_fbo = FALSE);
#014
#015 //free any allocated resources
#016 //safe to call redundantly
下面函数删除离屏对象。
#017 void release();
#018
#019 //bind target for rendering
#020 //applies appropriate viewport
下面函数绑定离屏对象。
#021 void bindTarget();
#022
#023 //clear render targer, clears depth buffer if present,
#024 //uses scissor rect if in copy-to-texture mode
下面函数清除离屏对象内容。
#025 void clear();
#026
下面函数获取显示的视口。
#027 //get applied viewport
#028 void getViewport(S32* viewport);
#029
下面函数设置纹理。
#030 //bind results of render for sampling
#031 void bindTexture();
#032
下面函数显示离屏对象到显示内存。
#033 //flush rendering operations
#034 //must be called when rendering is complete
#035 //should be used 1:1 with bindTarget
#036 // call bindTarget once, do all your rendering, call flush once
#037 void flush();
#038
下面函数判断是否离屏对象是否准备好。
#039 //Returns TRUE if target is ready to be rendered into.
#040 //That is, if the target has been allocated with at least
#041 //one renderable attachment (i.e. color buffer, depth buffer).
#042 BOOL isComplete() const;
#043
#044 private:
#045 U32 mResX;
#046 U32 mResY;
#047 U32 mTex;
#048 U32 mFBO;
#049 U32 mDepth;
#050 BOOL mUseDepth;
#051 U32 mUsage;
#052 };
#053
上面类LLRenderTarget就通过这些函数来操作离屏对象的。下一次再仔细分析它是通什么样OpenGL函数来实现的。
相关文章推荐
- 第二人生的源码分析(五十六)OpenGL离屏渲染的实现
- 蔡军生先生第二人生的源码分析(五十七)OpenGL离屏渲染的相关函数
- 蔡军生先生第二人生的源码分析(11)地面显示的实现
- 蔡军生先生第二人生的源码分析(七十八)LLOSInfo类实现获取操作系统信息
- 蔡军生先生第二人生的源码分析(五十九)字体类LLFont的实现
- 蔡军生先生第二人生的源码分析(5)类Log的实现
- 蔡军生先生第二人生的源码分析(三十二)消息解包的实现
- 蔡军生先生第二人生的源码分析(九十九)雷达地图的实现
- 蔡军生先生第二人生的源码分析(6)类CallSite的实现
- 蔡军生先生第二人生的源码分析(十七)人物Mesh数据显示的实现
- 蔡军生先生第二人生的源码分析(三十三)消息解包的实现
- 蔡军生先生第二人生的源码分析(六十一)LLCurl类实现libcurl库封装
- 蔡军生先生第二人生的源码分析(12)天空显示的实现
- 蔡军生先生第二人生的源码分析(十八)人物纹理显示的实现
- 蔡军生先生第二人生的源码分析(二十二)调用OpenGL显示人物名称的函数
- 蔡军生先生第二人生的源码分析(六十二)类Easy实现多协议文件传送
- 蔡军生先生第二人生的源码分析(13)树显示的实现
- 蔡军生先生第二人生的源码分析(六十三)类Multi实现多请求
- 蔡军生先生第二人生的源码分析(七十一)实现闪屏窗口
- 蔡军生先生第二人生的源码分析(4)Log调试功能的实现