JWS C++ Library
C++ language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00049 #ifndef OFFSCREEN_H 00050 #define OFFSCREEN_H 00051 00052 00053 #include <jwsc++/config.h> 00054 00055 #include <jwsc++/base/exception.h> 00056 00057 #if defined JWSCXX_HAVE_X11 && defined JWSCXX_HAVE_GLX 00058 #include <X11/Xlib.h> 00059 #include <GL/gl.h> 00060 #include <GL/glx.h> 00061 #elif defined JWSCXX_HAVE_OPENGL_FRAMEWORK 00062 #include <OpenGL/OpenGL.h> 00063 #include <OpenGL/gl.h> 00064 #endif 00065 00066 #if defined JWSCXX_HAVE_OSMESA32 00067 #include <GL/osmesa.h> 00068 #endif 00069 00070 00071 namespace jwscxx { 00072 namespace graphics { 00073 00074 00080 class Offscreen_buffer 00081 { 00082 public: 00083 00085 Offscreen_buffer(int width, int height) 00086 { this->width = width; this->height = height; active = false; } 00087 00089 virtual ~Offscreen_buffer() { } 00090 00092 virtual void activate() throw(jwscxx::base::Exception) = 0; 00093 00095 virtual void deactivate() throw(jwscxx::base::Exception) = 0; 00096 00098 virtual void reactivate() throw(jwscxx::base::Exception) = 0; 00099 00100 protected: 00101 00103 bool active; 00104 00106 int width; 00107 00109 int height; 00110 }; 00111 00112 00113 #if defined JWSCXX_HAVE_X11 && defined JWSCXX_HAVE_GLX 00114 00119 class GLX_offscreen_buffer : public Offscreen_buffer 00120 { 00121 public: 00122 00124 GLX_offscreen_buffer(int width, int height) 00125 : Offscreen_buffer(width, height) { display_open = false; } 00126 00128 virtual ~GLX_offscreen_buffer() { } 00129 00131 virtual void activate() throw(jwscxx::base::Exception); 00132 00134 virtual void deactivate() throw(jwscxx::base::Exception); 00135 00137 virtual void reactivate() throw(jwscxx::base::Exception); 00138 00139 protected: 00140 00145 void save_old_context(); 00146 00148 void open_display(const char* disp_name=0) 00149 throw(jwscxx::base::Result_error); 00150 00152 virtual void create_drawable_and_context(int* attrs) 00153 throw(jwscxx::base::Exception) = 0; 00154 00156 virtual void destroy_drawable() = 0; 00157 00158 protected: 00159 00161 bool display_open; 00162 00164 Display* display; 00165 00167 GLXDrawable drawable; 00168 00170 GLXDrawable old_drawable; 00171 00173 GLXContext context; 00174 00176 GLXContext old_context; 00177 }; 00178 00179 00187 class GLX_offscreen_pixmap : public GLX_offscreen_buffer 00188 { 00189 public: 00190 00192 GLX_offscreen_pixmap(int width, int height, int* attrs=0) 00193 throw(jwscxx::base::Exception); 00194 00196 virtual ~GLX_offscreen_pixmap(); 00197 00198 protected: 00199 00201 virtual void create_drawable_and_context(int* attrs) 00202 throw(jwscxx::base::Result_error); 00203 00205 virtual void destroy_drawable(); 00206 00207 protected: 00208 00210 Pixmap pixmap; 00211 }; 00212 00213 00221 class GLX_offscreen_pbuffer : public GLX_offscreen_buffer 00222 { 00223 public: 00224 00226 GLX_offscreen_pbuffer(int width, int height) 00227 throw(jwscxx::base::Exception); 00228 00230 GLX_offscreen_pbuffer(int width, int heigth, int* attrs) 00231 throw (jwscxx::base::Exception); 00232 00234 virtual ~GLX_offscreen_pbuffer(); 00235 00236 protected: 00237 00239 bool has_pbuffer_extension() const; 00240 00242 virtual void create_drawable_and_context(int* attrs) 00243 throw(jwscxx::base::Exception); 00244 00246 virtual void destroy_drawable(); 00247 }; 00248 00249 00250 #elif defined JWSCXX_HAVE_OPENGL_FRAMEWORK 00251 00256 class CGL_offscreen_pbuffer : public Offscreen_buffer 00257 { 00258 public: 00259 00261 CGL_offscreen_pbuffer 00262 ( 00263 GLsizei width, 00264 GLsizei height, 00265 GLenum format=GL_RGBA, 00266 const CGLPixelFormatAttribute* attrs=0 00267 ) 00268 throw (jwscxx::base::Exception); 00269 00271 virtual ~CGL_offscreen_pbuffer(); 00272 00274 virtual void activate() throw(jwscxx::base::Exception); 00275 00277 virtual void deactivate() throw(jwscxx::base::Exception); 00278 00280 virtual void reactivate() throw(jwscxx::base::Exception); 00281 00282 protected: 00283 00287 virtual void save_old_context(); 00288 00290 virtual void create_pbuffer_and_context 00291 ( 00292 GLenum format, 00293 const CGLPixelFormatAttribute* attrs 00294 ) 00295 throw(jwscxx::base::Exception); 00296 00297 protected: 00298 00300 CGLContextObj context; 00301 00303 CGLContextObj old_context; 00304 00306 CGLPBufferObj pbuffer; 00307 }; 00308 #endif 00309 00310 00311 #if defined JWSCXX_HAVE_OSMESA32 00312 00317 class OSMesa32_offscreen_buffer : public Offscreen_buffer 00318 { 00319 public: 00320 00322 OSMesa32_offscreen_buffer 00323 ( 00324 GLsizei width, 00325 GLsizei height, 00326 GLenum format=OSMESA_RGBA, 00327 GLint depth_bits=4, 00328 GLint stencil_bits=4, 00329 GLint accum_bits=4 00330 ) 00331 throw (jwscxx::base::Exception); 00332 00334 virtual ~OSMesa32_offscreen_buffer(); 00335 00337 virtual void activate() throw(jwscxx::base::Exception); 00338 00340 virtual void deactivate() throw(jwscxx::base::Exception); 00341 00343 virtual void reactivate() throw(jwscxx::base::Exception); 00344 00345 protected: 00346 00348 virtual void create_buffer_and_context 00349 ( 00350 GLenum format, 00351 GLint depth_bits, 00352 GLint stencil_bits, 00353 GLint accum_bits 00354 ) 00355 throw(jwscxx::base::Exception); 00356 00357 protected: 00358 00360 OSMesaContext context; 00361 00363 void* buffer; 00364 }; 00365 #endif 00366 00367 00368 }} 00369 00370 00371 #endif