00001 #ifndef RENDERING_MODE_H_IS_INCLUDED 00002 #define RENDERING_MODE_H_IS_INCLUDED 00003 00004 /*! 00005 * \file rendering_mode.H 00006 * \brief Contains the definitions of classes that make it easier to create 00007 * gTextures that have multiple rendering modes. That is, they have multiple 00008 * ways to achieve the same effect. The mode that is used usually depends on 00009 * the capabilities of the graphics card that is available. 00010 * 00011 */ 00012 00013 #include "mesh/patch.H" 00014 00015 #include "gtex/basic_texture.H" 00016 00017 /*! 00018 * \brief The abstract interface for a rendering mode. 00019 * 00020 * Rendering modes determine how a gTexture is rendered (for example, using 00021 * just shaders, using shaders and textures, or using no shaders). 00022 * 00023 * Concrete rendering modes should subclass this class and override one or more 00024 * of the setup_for_drawing or after_drawing methods. Subclasses should also 00025 * create their own subclass of RenderingModeStripCB to act as the GLStripCB for 00026 * their gTexture. The get_new_strip_cb() method should be overriden to return 00027 * a newly allocated one of these RenderingModeStripCB subclasses. 00028 * 00029 * \note Each concrete rendering mode is responsible for managing all the OpenGL 00030 * resources it needs for rendering. These resources will most likely be 00031 * allocated in the rendering mode's constructor and deallocated in the 00032 * destructor. 00033 * 00034 */ 00035 class RenderingMode { 00036 00037 public: 00038 00039 class RenderingModeStripCB : public GLStripCB { 00040 00041 }; 00042 00043 virtual ~RenderingMode() { }; 00044 00045 //! \brief Setup the OpenGL state for rendering in this mode. This 00046 //! method will be called each time the style is drawn. 00047 //! 00048 //! \note Code that uses values that vary from redraw to redraw should 00049 //! be put in this method so that the values are not captured once in a 00050 //! display list. 00051 virtual void setup_for_drawing_outside_dl(const Patch *patch) { } 00052 00053 //! \brief Setup the OpenGL state for rendering in this mode. This 00054 //! method will be called once inside a display list. 00055 virtual void setup_for_drawing_inside_dl(const Patch *patch) { } 00056 00057 //! \brief Perform any operations that should happen after drawing is 00058 //! complete. This method will be called each time the style is drawn. 00059 //! 00060 //! \note Code that uses values that vary from redraw to redraw should 00061 //! be put in this method so that the values are not captured once in a 00062 //! display list. 00063 virtual void after_drawing_outside_dl(const Patch *patch) { } 00064 00065 //! \brief Perform any operations that should happen after drawing is 00066 //! complete. This method will be called once inside a display list. 00067 virtual void after_drawing_inside_dl(const Patch *patch) { } 00068 00069 //! \brief Get a newly allocated object of the GLStripCB class used by this 00070 //! mode. 00071 //! \note The returned GLStripCB pointer should be deleted by the caller 00072 //! when it is done being used. 00073 virtual GLStripCB *get_new_strip_cb() const = 0; 00074 00075 }; 00076 00077 /*! 00078 * \brief A singleton class that keeps track of the rendering mode to be used 00079 * by all instances of a particular gTexture. 00080 * 00081 * This class determines which rendering modes are available for use and picks 00082 * the best one based on the RenderingModeSelectionPolicy. This policy should 00083 * be a class with a public static class method called SelectRenderingMode that 00084 * takes no arguments and returns a pointer to a newly allocated rendering mode 00085 * (or 0 if none of the available rendering modes can be used). 00086 * 00087 */ 00088 template <typename RenderingModeSelectionPolicy> 00089 class RenderingModeSingleton { 00090 00091 public: 00092 00093 inline static RenderingModeSingleton<RenderingModeSelectionPolicy> &Instance(); 00094 00095 //! \brief Indicates whether any of the available rendering modes are 00096 //! supported on the current system. 00097 bool supported() 00098 { return mode != 0; } 00099 00100 //! \copydoc RenderingMode::setup_for_drawing_outside_dl(const Patch*) 00101 void setup_for_drawing_outside_dl(const Patch *patch) 00102 { if(mode) mode->setup_for_drawing_outside_dl(patch); } 00103 00104 //! \copydoc RenderingMode::setup_for_drawing_inside_dl(const Patch*) 00105 void setup_for_drawing_inside_dl(const Patch *patch) 00106 { if(mode) mode->setup_for_drawing_inside_dl(patch); } 00107 00108 //! \copydoc RenderingMode::after_drawing_outside_dl(const Patch*) 00109 void after_drawing_outside_dl(const Patch *patch) 00110 { if(mode) mode->after_drawing_outside_dl(patch); } 00111 00112 //! \copydoc RenderingMode::after_drawing_inside_dl(const Patch*) 00113 void after_drawing_inside_dl(const Patch *patch) 00114 { if(mode) mode->after_drawing_inside_dl(patch); } 00115 00116 //! \copydoc RenderingMode::get_new_strip_cb() 00117 GLStripCB *get_new_strip_cb() 00118 { return mode ? mode->get_new_strip_cb() : 0; } 00119 00120 private: 00121 00122 RenderingMode *mode; 00123 00124 inline RenderingModeSingleton(); 00125 RenderingModeSingleton(const RenderingModeSingleton &other); 00126 00127 inline ~RenderingModeSingleton(); 00128 00129 RenderingModeSingleton &operator=(const RenderingModeSingleton &rhs); 00130 00131 }; 00132 00133 template <typename RenderingModeSelectionPolicy> 00134 inline 00135 RenderingModeSingleton<RenderingModeSelectionPolicy>& 00136 RenderingModeSingleton<RenderingModeSelectionPolicy>::Instance() 00137 { 00138 00139 static RenderingModeSingleton<RenderingModeSelectionPolicy> instance; 00140 return instance; 00141 00142 } 00143 00144 template <typename RenderingModeSelectionPolicy> 00145 inline 00146 RenderingModeSingleton<RenderingModeSelectionPolicy>::RenderingModeSingleton() 00147 : mode(RenderingModeSelectionPolicy::SelectRenderingMode()) 00148 { 00149 00150 } 00151 00152 template <typename RenderingModeSelectionPolicy> 00153 inline 00154 RenderingModeSingleton<RenderingModeSelectionPolicy>::~RenderingModeSingleton() 00155 { 00156 00157 delete mode; 00158 00159 } 00160 00161 #endif // RENDERING_MODE_H_IS_INCLUDED