Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfTexture3D.cpp
1 #include "glfTexture3D.hh"
2 #include "glfException.hh"
3 #include <Base/Image/ImageIO.hh>
4 #include "glfFormatDB.hh"
5 
6 using namespace std;
7 using namespace BIAS;
8 
9 glfTexture3D::glfTexture3D() :
10  glfTexture(GL_TEXTURE_3D)
11 {
12 }
13 
15  glfTexture3D::operator=(const glfTexture3D& b)
16  {
17  return (*this);
18 }
19 
21  glfTexture(GL_TEXTURE_3D)
22 {
23 }
24 
25 void
26  glfTexture3D::Set(GLenum minFilter, GLenum magFilter, GLenum wrapS,
27  GLenum wrapT, GLint textureNr)
28 {
29  SetMinFilter(minFilter);
30  SetMagFilter(magFilter);
31  SetWrapS(wrapS);
32  SetWrapT(wrapT);
33  SetTextureNr(textureNr);
34 }
35 
36 void glfTexture3D::Allocate3DImage(int width, int height, int depth,
37  GLenum internalFormat, int mipmap)
38 {
39  GLenum format;
40  int numChannels;
41  glfFormatDB::GetFormatForInternalFormat(internalFormat, format, numChannels);
42 
43  Bind();
44 
45  GLenum type = GL_UNSIGNED_BYTE;
46  if (internalFormat == GL_DEPTH24_STENCIL8_EXT)
47  type = GL_UNSIGNED_INT_24_8_EXT;
48 
49  glTexImage3D(target_, mipmap, internalFormat, width, height, depth, 0,
50  format, type, NULL);
51 
52  GLF_THROW_ON_OPENGL_ERROR;
53 }
54 
55 void glfTexture3D::Allocate3DImage(int width, int height, int depth,
56  ImageBase::EStorageType storageType,
57  ImageBase::EColorModel colorModel,
58  int mipmap) {
59  GLenum internalFormat = glfFormatDB::ProposeInternalFormat(storageType, colorModel);
60  Allocate3DImage(width, height, depth, internalFormat, mipmap);
61 }
62 
63 void
64  glfTexture3D::Upload2DImage(const BIAS::ImageBase& image, unsigned int level)
65 {
66 
67  GLenum format = glfFormatDB::GetFormatForColorModel(image.GetColorModel());
68  GLenum pixelType = glfFormatDB::GetPixelTypeForStorageType(image.GetStorageType());
69 
70 // cout << "pixel type = " << ( pixelType == GL_FLOAT) << endl;
71 
72  // upload data.
73  Bind();
74  // glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
75 
76 
77  glTexSubImage3D(GL_TEXTURE_3D, 0,0,0,level, image.GetWidth(), image.GetHeight(), 1,
78  format, pixelType, image.GetImageData());
79 
80  GLF_THROW_ON_OPENGL_ERROR;
81 }
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
void Bind() const
Binds the texture.
Definition: glfTexture.cpp:242
void SetWrapS(GLenum wrapS)
Sets the wrapping mode for the 1st texture coordinate.
Definition: glfTexture.cpp:105
static void GetFormatForInternalFormat(GLenum internalFormat, GLenum &format, int &numChannels)
Computes a pixel format that can be used with glGetTexImage and glReadPixels for an internal format o...
Definition: glfFormatDB.cpp:32
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void SetMinFilter(GLenum minFilter)
Sets the minifying function.
Definition: glfTexture.cpp:89
const void * GetImageData() const
Definition: ImageBase.hh:280
void SetWrapT(GLenum wrapT)
Sets the wrapping mode for the 2nd texture coordinate.
Definition: glfTexture.cpp:113
unsigned int GetHeight() const
Definition: ImageBase.hh:319
static GLenum ProposeInternalFormat(ImageBase::EStorageType storageType, ImageBase::EColorModel colorModel)
Returns an OpenGL internal pixel format for a BIAS storage type and color model.
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
static GLenum GetFormatForColorModel(ImageBase::EColorModel colorModel)
Returns the OpenGL pixel format (GL_RGB etc.) for a BIAS color model.
void Set(GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, GLint textureNr=GL_TEXTURE0)
Convenience wrapper.
static GLenum GetPixelTypeForStorageType(ImageBase::EStorageType storageType)
Returns the OpenGL pixel type (GL_UNSIGNED_BYTE etc.) for a BIAS storage type.
Base class for textures.
Definition: glfTexture.hh:42
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
void SetTextureNr(GLint textureNr)
Sets the OpenGL texture number (GL_TEXTURE0 - GL_TEXTURE[MaxTextureUnit-1]).
Definition: glfTexture.cpp:207
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void Allocate3DImage(int width, int height, int depth, GLenum internalFormat, int mipmap=0)
void Upload2DImage(const BIAS::ImageBase &image, unsigned int level)
void SetMagFilter(GLenum magFilter)
Sets the magnification function.
Definition: glfTexture.cpp:97