[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin1/hugin/TextureManager.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00023 /* a TextureManager sets up openGL textures for each of the input images in a
00024  * panorama. It scales images down so they should fit in graphics memory.
00025  */
00026 
00027 /* Texture sizes must be powers of two. The texture sizes are the biggest size
00028  * that does not scale up the input image, or the biggest size supported by the
00029  * hardware, whichever is smaller. However, not all of the texture is defined
00030  * at any time, so the memory consumption is limited.
00031  * The textures are mipmapped, i.e. they use progressivly smaller versions.
00032  * The mipmaps are defined in a range from the smallest 1*1 pixel version to
00033  * the largest mipmap that doesn't go over the texture space budget. OpenGL
00034  * uses mip level 0 to be the original image, and log2(max(width, height)) + 1
00035  * to be the smallest 1 by 1 pixel image. We use this convention too.
00036  */
00037 
00038 #ifndef _TextureManager_h
00039 #define _TextureManager_h
00040 
00041 #include <string>
00042 #include <map>
00043 #include "PT/Panorama.h"
00044 
00045 class GLViewer;
00046 class ViewState;
00047 
00048 class TextureManager
00049 {
00050 public:
00051     TextureManager(PT::Panorama *pano, ViewState *view);
00052     virtual ~TextureManager();
00053     // selct the texture for the requested image in opengl
00054     void DrawImage(unsigned int image_number, unsigned int display_list);
00055     // react to the images & fields of view changing. We can update the
00056     // textures here.
00057     void CheckUpdate();
00058     // change the OpenGL state for rendering the textures.
00059     void Begin();
00060     void End();
00061     // set to true if we are doing photmetric correction
00062     void SetPhotometricCorrect(bool state);
00063     // return true if we are doing photometric correction.
00064     bool GetPhotometricCorrect() {return photometric_correct;}
00065     // get the OpneGL texture name for a given image
00066     unsigned int GetTextureName(unsigned int image_number);
00067     // binds the texture for a given image
00068     void BindTexture(unsigned int image_number);
00069     // disables the image textures
00070     void DisableTexture(bool maskOnly=false);
00071 
00072 protected:
00073     PT::Panorama  * m_pano;
00074     ViewState *view_state;
00075     float viewer_exposure;
00076     // remove textures for deleted images.
00077     void CleanTextures();
00078     class TextureInfo
00079     {
00080     public:
00081         TextureInfo(ViewState *new_view_state);
00082         // specify log2(width) and log2(height) for the new texture's size.
00083         // this is the size of mip level 0, which may or may not be defined.
00084         TextureInfo(ViewState *new_view_state, unsigned int width_p, unsigned int height_p);
00085         ~TextureInfo();
00086         // width and height are the size of the texture. This can be different
00087         // to the image size, we have to scale to powers of two. The texture
00088         // size is the biggest we can use for the image without scaling up
00089         // (unless the hardware doesn't support textures that big)
00090         // we generally have only lower mip levels defined though.
00091         unsigned int width, height;
00092         // log base 2 of the above, cached.
00093         unsigned int width_p, height_p;
00094         // min_lod is the most detailed mipmap level defined
00095         int min_lod;
00096         
00097         void DefineLevels(int min, int max,
00098                           bool photometric_correct,
00099                           const HuginBase::PanoramaOptions &dest_img,
00100                           const HuginBase::SrcPanoImage &state);
00101         void DefineMaskTexture(const HuginBase::SrcPanoImage &srcImg);
00102         void UpdateMask(const HuginBase::SrcPanoImage &srcImg);
00103         void SetMaxLevel(int level);
00104         void Bind();
00105         void BindImageTexture();
00106         void BindMaskTexture();
00107         unsigned int GetNumber() {return num;};
00108         // if the image has a mask, we want to use alpha blending to draw it.
00109         bool GetUseAlpha() {return has_mask;};
00110         bool GetHasActiveMasks() {return has_active_masks;};
00111     private:
00112         unsigned int num;     // the openGL texture name
00113         unsigned int numMask; // the openGL texture name for the mask
00114         bool has_mask; // this is the alpha channel
00115         bool has_active_masks; // has active masks
00116         ViewState *m_viewState;
00117         // this binds a new texture in openGL and sets the various parameters
00118         // we need for it.
00119         void CreateTexture();
00120         void SetParameters();
00121     };
00122     
00123     // A TextureKey uniquely identifies a texture. It contains the filename
00124     // of the image and the photometric correction properties used to make it.
00125     class TextureKey
00126     {
00127     public:
00128         TextureKey();
00129         TextureKey(HuginBase::SrcPanoImage * source, bool *photometric_correct_ptr);
00130             
00131         // TODO all of this lot should probably be made read only
00132         std::string filename;
00133         double exposure, white_balance_red, white_balance_blue;
00134         std::vector<float> EMoR_params;
00135         std::vector<double> radial_vig_corr_coeff;
00136         hugin_utils::FDiff2D radial_vig_corr_center_shift;
00137         int vig_corr_mode;
00138         HuginBase::SrcPanoImage::ResponseType response_type;
00139         std::vector<double> radial_distortion_red;
00140         std::vector<double> radial_distortion_blue;
00141         double gamma;
00142         std::string masks;
00143                 
00144         // when stored in the textures map, this should be set to something that
00145         // always indicates if photometric correction comparisons should be made
00146         bool *photometric_correct;
00147         // we need to specify our own comparison function as the photometric
00148         // correction parameters do not need to be compared when we are not
00149         // using photometric correction.
00150         const bool operator==(const TextureKey comp) const;
00151         // we need to be able to order the keys
00152         const bool operator<(const TextureKey comp) const;
00153     private:
00154         void SetOptions(HuginBase::SrcPanoImage *source);
00155     };
00156     // we map filenames to TexturesInfos, so we can keep track of
00157     // images' textures when the numbers change.
00158     std::map<TextureKey, TextureInfo> textures;
00159     // Our pixel budget for all textures.
00160     unsigned int GetMaxTotalTexels();
00161     // this is the maximum size a single texture is supported on the hardware.
00162     unsigned int GetMaxTextureSizePower(); 
00163     float texel_density;          // multiply by angles to get optimal size.
00164     bool photometric_correct;
00165 };
00166 
00167 #endif
00168    

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1