您的位置:首页 > 运维架构

蔡军生先生第二人生的源码分析(五十六)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函数来实现的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐