Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImgObjGL.hh
1 #ifndef __ImgObjGL_h__
2 #define __ImgObjGL_h__
3 
4 #include <bias_config.h>
5 #include <Base/Common/W32Compat.hh>
6 
7 #ifndef BIAS_HAVE_OPENGL
8 # error Please recompile BIAS with USE_OPENGL to use ImgObjGL
9 #endif // BIAS_HAVE_OPENGL
10 
11 //#ifndef BIAS_HAVE_GLEW
12 //# error Please recompile BIAS with USE_GLEW to use ImgObjGL
13 //#endif // BIAS_HAVE_GLEW
14 
15 
16 #include "biasgl.h"
17 
18 // BIAS
19 #include <Base/Image/ImageBase.hh>
20 #include <Base/Image/Image.hh>
21 
22 #define IMGOBJ_DEFAULT_MIPMAPPED false
23 #define IMGOBJ_IMMEDIATE_COPY_DEFAULT true
24 
25 namespace BIAS {
26 
27  /** data holder describing OpenGL texture objects in addition to its unique texID.
28  Please note that querying glTexImage2D(GL_PROXY_TEXTURE_2D,... may be more reliable
29  See http://www.opengl.org/resources/faq/technical/texture.htm
30 
31  \bug TODO copy constructor that duplicates the GL pixel data required for std::vector.resize() (major bug, do not resize with std::vector for now!)
32 
33  @author Jan Woetzel */
34  class BIASGui_EXPORT ImgObjGL {
35  public:
36  ~ImgObjGL();
37 
38  ImgObjGL();
39 
40  //* ctor initializing members JW */
41  ImgObjGL(
42  const GLuint & id,
43  const unsigned int & widthBrutto,
44  const unsigned int & heightBrutto,
45  const GLenum & target=GL_TEXTURE_2D
46  );
47 
48  /// set members to defaults
49  void InitMembers();
50 
51  /// convenience interace for glewInit() c´with checks and ifdefs
52  static void InitGlew();
53 
54  /// frees the pointer members if we allocated them
55  void Release();
56 
57  /// deletes the texture memory and frees texture in GL
58  void DeleteGLTexture();
59 
60 
61  /// @return true on classic GL_TEXTURE_2D target (instead of RECT or cubemap)
62  bool IsTexture2D() const;
63 
64  /// @return true if RECT texture (instead of 2D pow2 or cubemap)
65  bool IsRectangleTexture() const;
66 
67  /// @return true on cubemap texture
68  bool IsCubemap() const;
69 
70 
71  /** creates an OpenGL texture from p_valueImage JW
72  if ImmediateCopyData is false the memory is just allocated and not copied from c_img.
73  JW */
74  void CreateGLTexture(
75  const BIAS::ImageBase & c_img, /*zeropad etc is currently missing*/
76  const bool & forcePow2tex=true,
77  const bool & flipY=true,
78  const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT );
79 
80  void CreateGLCubemap(const std::vector< BIAS::ImageBase * > cm,
81  const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT,
82  const bool mipmapped=IMGOBJ_DEFAULT_MIPMAPPED );
83 
84  /// helper creating cubemap from disk files
85  int CreateGLCubemap(
86  const std::string & cm0PosX,
87  const std::string & cm1NegX,
88  const std::string & cm2PosY,
89  const std::string & cm3NegY,
90  const std::string & cm4PosZ,
91  const std::string & cm5NegZ,
92  const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT,
93  const bool mipmapped=IMGOBJ_DEFAULT_MIPMAPPED );
94 
95  /// helper creating cubemap from disk files
96  int CreateGLCubemap(
97  const std::vector< std::string > cmFilenames,
98  const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT,
99  const bool mipmapped=IMGOBJ_DEFAULT_MIPMAPPED );
100 
101 
102  // create an empty cubemap including allocating all mipmap texture levels
103  // thus the complete mipmap chain for all faces and levels is created on request
104  void CreateGLCubemapEmpty(const unsigned int w, const unsigned int h,
105  GLint gpu_internalFmt=GL_RGBA,
106  const bool & mipmapped=false);
107 
108 
109  /** set the textur retarget to rectangular or pow 2 texture JW */
110  void SetTargetPOW2();
111  void SetTarget2D();
112  void SetTargetRECT();
113  void SetTargetCUBE();
114 
115  /** get the GLenum pixel storage type for the corresponding BIAS enum @author Jan Woetzel */
116  static GLenum GetGLStorageType(const BIAS::ImageBase::EStorageType & biasST,
117  const unsigned int & ByteDepth );
118 
119  /** get the GLenum pixel src format for the corresponding BIAS enum ColroModel @author Jan Woetzel */
120  static GLenum GetGLPixelFormat(const BIAS::ImageBase::EColorModel & biasCM,
121  const unsigned int & channelcount );
122 
123  /// JW determin the GPU internal format the src data should be mapped to @author Jan Woetzel
124  static GLint GetGLInternalFormat(
125  const BIAS::ImageBase::EStorageType & biasST,
126  const BIAS::ImageBase::EColorModel & biasCM,
127  const unsigned int & channelcount,
128  const unsigned int & ByteDepth,
129  const unsigned int & BitDepth );
130 
131  /// interface for the above @author Jan Woetzel
132  static GLint GetGLInternalFormat(const BIAS::ImageBase & img);
133 
134 
135  public:
136  // OpenGL texture
137  GLuint id; // unique OpengL texture id
138  GLenum target; // GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_NV
139 
140  // true if we "created" the above and need to free it in destructor.
142 
145 
146  // original feed in size
147  unsigned int widthOrig; // should match p_valueImage size if exists
148  unsigned int heightOrig;
149 
150  // padded to next pow2 size:
151  unsigned int widthBrutto;
152  unsigned int heightBrutto;
153 
154  // image containing the original values
156 
157  // true if we "newed" the above and have to free it in destructor.
158  // false if we got a pointer which we do not need to clean up.
160 
161  };
162 } // namespace BIAS
163 
164 #endif
165 
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
unsigned int heightOrig
Definition: ImgObjGL.hh:148
BIAS::ImageBase * p_valueImage
Definition: ImgObjGL.hh:155
GLenum minificationMode
Definition: ImgObjGL.hh:143
unsigned int heightBrutto
Definition: ImgObjGL.hh:152
bool p_valueImage_SelfAllocated
Definition: ImgObjGL.hh:159
data holder describing OpenGL texture objects in addition to its unique texID.
Definition: ImgObjGL.hh:34
GLenum magnificationMode
Definition: ImgObjGL.hh:144
unsigned int widthOrig
Definition: ImgObjGL.hh:147
GLenum target
Definition: ImgObjGL.hh:138
bool p_id_SelfAllocated
Definition: ImgObjGL.hh:141
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
unsigned int widthBrutto
Definition: ImgObjGL.hh:151