glteximage.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: glteximage.hpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 19:50:21  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. #ifndef GUI_OPENGL___GL_TEX_IMAGE___HPP
  10. #define GUI_OPENGL___GL_TEX_IMAGE___HPP
  11. /*  $Id: glteximage.hpp,v 1000.1 2004/06/01 19:50:21 gouriano Exp $
  12.  * ===========================================================================
  13.  *
  14.  *                            PUBLIC DOMAIN NOTICE
  15.  *               National Center for Biotechnology Information
  16.  *
  17.  *  This software/database is a "United States Government Work" under the
  18.  *  terms of the United States Copyright Act.  It was written as part of
  19.  *  the author's official duties as a United States Government employee and
  20.  *  thus cannot be copyrighted.  This software/database is freely available
  21.  *  to the public for use. The National Library of Medicine and the U.S.
  22.  *  Government have not placed any restriction on its use or reproduction.
  23.  *
  24.  *  Although all reasonable efforts have been taken to ensure the accuracy
  25.  *  and reliability of the software and data, the NLM and the U.S.
  26.  *  Government do not and cannot warrant the performance or results that
  27.  *  may be obtained by using this software or data. The NLM and the U.S.
  28.  *  Government disclaim all warranties, express or implied, including
  29.  *  warranties of performance, merchantability or fitness for any particular
  30.  *  purpose.
  31.  *
  32.  *  Please cite the author in any work or product based on this material.
  33.  *
  34.  * ===========================================================================
  35.  *
  36.  * Authors:  Mike DiCuccio
  37.  *
  38.  * File Description:
  39.  *
  40.  */
  41. #include <util/image/image.hpp>
  42. #include <gui/opengl.h>
  43. #include <gui/gui.hpp>
  44. /** @addtogroup GUI_OPENGL
  45.  *
  46.  * @{
  47.  */
  48. BEGIN_NCBI_SCOPE
  49. //
  50. // class CTexImage defines a specialization of CImage that is useful for
  51. // textures.
  52. //
  53. // This class holds a CImage as well as its texture information.
  54. //
  55. class NCBI_GUIOPENGL_EXPORT CTexImage : public CObject
  56. {
  57. public:
  58.     // default ctor
  59.     CTexImage();
  60.     // create a texture from a file
  61.     explicit CTexImage(const string& filename);
  62.     // create a texture around an existing image
  63.     explicit CTexImage(CImage* image);
  64.     // create a texture of a given dimension
  65.     CTexImage(size_t w, size_t h, size_t d);
  66.     // initialize our image.
  67.     // Here, depth is in channels (3 = 24-bit, 4 = 32-bit)
  68.     void Init(size_t w, size_t h, size_t depth);
  69.     // reset our internal structures
  70.     void Clear();
  71.     // "swallow" an image - explicitly assigns the image we wrap
  72.     void Swallow(CImage *image);
  73.     // make this texture the current texture for OpenGL work
  74.     void MakeCurrent();
  75.     // load an image.  this creates a new display list or tex object
  76.     void Load();
  77.     // unload an image.  this destroys the current binding
  78.     void Unload();
  79.     // access the filename
  80.     const string&   GetFileName(void) const;
  81.     // access our image
  82.     const CImage*   GetImage(void) const;
  83.     CImage*         SetImage(void);
  84.     //
  85.     // OpenGL specifics
  86.     //
  87.     // filtering - magnification / minification
  88.     void   SetFilterMin(GLenum f);
  89.     void   SetFilterMag(GLenum f);
  90.     GLenum GetFilterMin(void) const;
  91.     GLenum GetFilterMag(void) const;
  92.     // texture wrapping - in two directions, S and T
  93.     void   SetWrapS(GLenum e);
  94.     void   SetWrapT(GLenum e);
  95.     GLenum GetWrapS(void) const;
  96.     GLenum GetWrapT(void) const;
  97.     // texture environment mode
  98.     void   SetTexEnv(GLenum e);
  99.     GLenum GetTexEnv(void) const;
  100. protected:
  101.     // our filename (may be empty)
  102.     string m_FileName;
  103.     // the CImage we wrap
  104.     CRef<CImage>    m_Image;
  105.     // OpenGL stuff:
  106.     // the texture id - either object or display list
  107.     GLuint m_TexId;
  108.     // texture wrapping (S and T directions)
  109.     GLenum m_WrapS;
  110.     GLenum m_WrapT;
  111.     // texture filtering for magnification / minification
  112.     GLenum m_FilterMin;
  113.     GLenum m_FilterMag;
  114.     // texture environment (modulation vs. decal, for example)
  115.     GLenum m_TexEnv;
  116.     // flag: can we use texture objects?
  117.     // this is an enumerated value indicating the state of texturing support
  118.     enum ETexSupport {
  119.         eNotChecked,
  120.         eTexObj,
  121.         eTexDisplayList
  122.     };
  123.     static ETexSupport sm_TexObjFlag;
  124.     // initialize texture object ability:
  125.     void x_InitTexObj();
  126. private:
  127.     // forbidden
  128.     CTexImage (const CTexImage&);
  129.     CTexImage& operator= (const CTexImage&);
  130. };
  131. //
  132. //
  133. // inline accessors
  134. //
  135. //
  136. inline
  137. CImage* CTexImage::SetImage(void)
  138. {
  139.     return m_Image;
  140. }
  141. inline
  142. const CImage* CTexImage::GetImage(void) const
  143. {
  144.     return m_Image;
  145. }
  146. inline
  147. const string& CTexImage::GetFileName(void) const
  148. {
  149.     return m_FileName;
  150. }
  151. inline
  152. void CTexImage::SetWrapS(GLenum e)
  153. {
  154.     m_WrapS = e;
  155. }
  156. inline
  157. void CTexImage::SetWrapT(GLenum e)
  158. {
  159.     m_WrapT = e;
  160. }
  161. inline
  162. void CTexImage::SetFilterMin(GLenum e)
  163. {
  164.     m_FilterMin = e;
  165. }
  166. inline
  167. void CTexImage::SetFilterMag(GLenum e)
  168. {
  169.     m_FilterMag = e;
  170. }
  171. inline
  172. void CTexImage::SetTexEnv(GLenum e)
  173. {
  174.     m_TexEnv = e;
  175. }
  176. inline
  177. GLenum CTexImage::GetWrapS(void) const
  178. {
  179.     return m_WrapS;
  180. }
  181. inline
  182. GLenum CTexImage::GetWrapT(void) const
  183. {
  184.     return m_WrapT;
  185. }
  186. inline
  187. GLenum CTexImage::GetFilterMin(void) const
  188. {
  189.     return m_FilterMin;
  190. }
  191. inline
  192. GLenum CTexImage::GetFilterMag(void) const
  193. {
  194.     return m_FilterMag;
  195. }
  196. inline
  197. GLenum CTexImage::GetTexEnv(void) const
  198. {
  199.     return m_TexEnv;
  200. }
  201. END_NCBI_SCOPE
  202. /* @} */
  203. /*
  204.  * ===========================================================================
  205.  * $Log: glteximage.hpp,v $
  206.  * Revision 1000.1  2004/06/01 19:50:21  gouriano
  207.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
  208.  *
  209.  * Revision 1.4  2004/05/11 18:54:22  dicuccio
  210.  * Added doxygne modules info
  211.  *
  212.  * Revision 1.3  2004/05/03 12:43:59  dicuccio
  213.  * Added #include for gui/gui.hpp
  214.  *
  215.  * Revision 1.2  2003/06/03 19:36:38  dicuccio
  216.  * Added export specifiers.  Fixed errant #include of <GL/...> files
  217.  *
  218.  * Revision 1.1  2003/06/03 17:42:54  dicuccio
  219.  * Added texture support.  Added classes to handle OpenGL camera setup, viewport
  220.  * specification
  221.  *
  222.  * ===========================================================================
  223.  */
  224. #endif // GUI_OPENGL___GL_TEX_IMAGE___HPP