00001 00032 #ifndef LL_LLRENDERTARGET_H 00033 #define LL_LLRENDERTARGET_H 00034 00035 #include "llgl.h" 00036 00037 /* 00038 SAMPLE USAGE: 00039 00040 LLRenderTarget target; 00041 00042 ... 00043 00044 //allocate a 256x256 RGBA render target with depth buffer 00045 target.allocate(256,256,GL_RGBA,TRUE); 00046 00047 //render to contents of offscreen buffer 00048 target.bindTarget(); 00049 target.clear(); 00050 ... <issue drawing commands> ... 00051 target.flush(); 00052 00053 ... 00054 00055 //use target as a texture 00056 target.bindTexture(); 00057 ... <issue drawing commands> ... 00058 00059 */ 00060 00061 00062 class LLRenderTarget 00063 { 00064 public: 00065 //whether or not to use FBO implementation 00066 static BOOL sUseFBO; 00067 00068 LLRenderTarget(); 00069 ~LLRenderTarget(); 00070 00071 //allocate resources for rendering 00072 //must be called before use 00073 //multiple calls will release previously allocated resources 00074 void allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage = GL_TEXTURE_2D, BOOL use_fbo = FALSE); 00075 00076 //allocate a depth texture 00077 void allocateDepth(); 00078 00079 //free any allocated resources 00080 //safe to call redundantly 00081 void release(); 00082 00083 //bind target for rendering 00084 //applies appropriate viewport 00085 void bindTarget(); 00086 00087 //unbind target for rendering 00088 static void unbindTarget(); 00089 00090 //clear render targer, clears depth buffer if present, 00091 //uses scissor rect if in copy-to-texture mode 00092 void clear(); 00093 00094 //get applied viewport 00095 void getViewport(S32* viewport); 00096 00097 //get X resolution 00098 U32 getWidth() const { return mResX; } 00099 00100 //get Y resolution 00101 U32 getHeight() const { return mResY; } 00102 00103 //bind results of render for sampling 00104 void bindTexture(); 00105 00106 //bind results of render for sampling depth buffer 00107 void bindDepth(); 00108 00109 //flush rendering operations 00110 //must be called when rendering is complete 00111 //should be used 1:1 with bindTarget 00112 // call bindTarget once, do all your rendering, call flush once 00113 // if fetch_depth is TRUE, every effort will be made to copy the depth buffer into 00114 // the current depth texture. A depth texture will be allocated if needed. 00115 void flush(BOOL fetch_depth = FALSE); 00116 00117 //Returns TRUE if target is ready to be rendered into. 00118 //That is, if the target has been allocated with at least 00119 //one renderable attachment (i.e. color buffer, depth buffer). 00120 BOOL isComplete() const; 00121 00122 private: 00123 U32 mResX; 00124 U32 mResY; 00125 U32 mTex; 00126 U32 mFBO; 00127 U32 mDepth; 00128 U32 mStencil; 00129 BOOL mUseDepth; 00130 BOOL mRenderDepth; 00131 U32 mUsage; 00132 00133 }; 00134 00135 #endif 00136