00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Joe Drew 00008 * Side Effects Software Inc 00009 * 123 Front Street West, Suite 1401 00010 * Toronto, Ontario 00011 * Canada M5J 2M2 00012 * 416-504-9876 00013 * 00014 * NAME: RE_RasterObject.h (RE Library, C++) 00015 * 00016 * COMMENTS: 00017 * 00018 * If you want to render offscreen, then (potentially) use the result as 00019 * a texture, there are two choices: framebuffer objects and raster 00020 * windows. Framebuffer objects are preferable, since they're faster, but 00021 * they're not supported everywhere. Raster windows are supported more 00022 * generally. 00023 * 00024 * This class abstracts out choosing whether to use RE_FrameBuffer or 00025 * RE_RasterWindow. Provide this class with a render callback, and when 00026 * you're initializing, call build(). Later, when you are sure an OpenGL 00027 * context has been pushed, call getTexture() to get the ID of a texture 00028 * that contains what you have drawn offscreen. 00029 * 00030 */ 00031 00032 #ifndef __RE_RasterObject__ 00033 #define __RE_RasterObject__ 00034 00035 #include "RE_API.h" 00036 00037 #include <boost/function.hpp> 00038 #include <SYS/SYS_Types.h> 00039 00040 class PXL_Raster; 00041 class RE_FrameBuffer; 00042 class RE_Render; 00043 class RE_RasterWindow; 00044 00045 typedef boost::function<void (RE_Render *, int, int, int, int, void *)> 00046 // ( render, x, y, w, h, data) 00047 RE_RenderCallback; 00048 00049 class RE_API RE_RasterObject 00050 { 00051 public: 00052 /// Provide this class with a callback, the width and height you want to 00053 /// render into, the height and width you want the texture to be (this 00054 /// should be a power of two), and some data to be passed to the callback. 00055 RE_RasterObject(RE_RenderCallback callback, int w, int h, int tw, int th, 00056 void *data); 00057 00058 /// Be very careful before calling this - do you have an OpenGL context 00059 /// pushed? 00060 ~RE_RasterObject(); 00061 00062 /// Frees the offscreen buffer associated with this object without 00063 /// clearing the other data (texture, raster). 00064 void resetBuffer(); 00065 00066 // build() does not create the texture because a valid OGL Context may 00067 // not be present yet. It can safely render into a RasterWindow, as that 00068 // pushes a valid context. We can't render to a RasterWindow in the middle 00069 // of a redraw as that messes up stacks & contexts. So, the texture 00070 // creation is split into 2 parts - build() (called during init) and 00071 // getTexture() (called during redraw). 00072 00073 /// Render offscreen, calling the render callback. 00074 bool build(RE_Render *r); 00075 00076 /// Generate and get the OpenGL ID of a texture that contains the contents 00077 /// of what was render when build() was called. 00078 uint getTexture(RE_Render *r); 00079 00080 /// If the color scheme changes, we need to re-render everything. 00081 void rebuild(RE_Render *r); 00082 00083 /// Whether build() has successfully been called. 00084 bool isBuilt() const; 00085 00086 /// The texture's width. Should be a power of two. 00087 int getTexWidth() const; 00088 00089 /// The texture's height. Should be a power of two. 00090 int getTexHeight() const; 00091 00092 /// The width of what you actually want to render. 00093 int getWidth() const; 00094 00095 /// The height of what you actually want to render. 00096 int getHeight() const; 00097 00098 /// Force PXL_Raster creation 00099 void setForceRaster(bool on) { myForceRaster = on; } 00100 00101 PXL_Raster* getRaster() { return myRaster; } 00102 00103 /// Renders this object directly using the callback. 00104 void renderDirect(RE_Render *r, int x, int y, int w, int h); 00105 00106 private: // methods 00107 void render(RE_Render *r); 00108 bool buildOffscreen(RE_Render *r); 00109 bool buildFrameBuffer(RE_Render *r); 00110 00111 private: 00112 00113 RE_RenderCallback myCallback; 00114 void *myVoidData; 00115 int myTexWidth; 00116 int myTexHeight; 00117 int myWidth; 00118 int myHeight; 00119 bool myBuiltFlag; 00120 uint myTextureID; 00121 PXL_Raster *myRaster; 00122 bool myForceRaster; 00123 RE_RasterWindow *myRasterWindow; 00124 RE_FrameBuffer *myFrameBuffer; 00125 00126 static int theRenderToTexture; 00127 static bool theRenderToBuffer; 00128 }; 00129 00130 #endif 00131
1.5.9