TextureData.hh 4.48 KB
Newer Older
1
2
3
4
5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
6
7
8
9

#ifndef ACGL_OPENGL_DATA_TEXTUREDATA_HH
#define ACGL_OPENGL_DATA_TEXTUREDATA_HH

Robert Menzel's avatar
Robert Menzel committed
10
11
12
13
14
/**
 * TextureData holds the data of a 1,2 or 3 dimensional image to be used as a texture.
 * This structure is used for texture loading.
 */

15
16
17
18
#include <ACGL/ACGL.hh>

#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
Robert Menzel's avatar
Robert Menzel committed
19
#include <ACGL/OpenGL/Tools.hh>
20
#include <ACGL/Math/Math.hh>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

namespace ACGL{
namespace OpenGL{

class TextureData
{
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
    TextureData(void)
    :   pData(NULL),
        width(0),
        height(0),
        depth(0),
        format(GL_RGBA),
37
        mType(GL_UNSIGNED_BYTE),
Robert Menzel's avatar
Robert Menzel committed
38
        paddingBytesPerRow(0)
39
40
41
42
43
44
45
46
47
48
49
    {}
    virtual ~TextureData(void)
    {
        delete[] pData;
    }

    // ========================================================================================================= \/
    // ================================================================================================= GETTERS \/
    // ========================================================================================================= \/
public:
    GLubyte* getData    (void) const { return pData;   }
50
51

    //! width in pixel
52
    GLsizei  getWidth   (void) const { return width;   }
53
54

    //! height in pixel
55
    GLsizei  getHeight  (void) const { return height;  }
56
57

    //! depth in pixel
58
    GLsizei  getDepth   (void) const { return depth;   }
59
60

    //! channels etc. e.g. GL_RGB
61
    GLenum   getFormat  (void) const { return format;  }
62
63
64
65
66

    //! data type (e.g. GL_BYTE)
    GLenum   getType    (void) const { return mType;   }

    //! each line can have a few bytes of padding, number of bytes is returned
Robert Menzel's avatar
Robert Menzel committed
67
    GLsizei  getPadding (void) const { return paddingBytesPerRow; }
68
69

    //! in bytes
Robert Menzel's avatar
Robert Menzel committed
70
    glm::uvec3 getSize  (void) const { return glm::uvec3( width, height, depth ); }
Robert Menzel's avatar
Robert Menzel committed
71
72
73
74
75
76

    //! the byte alignment of each pixel row, e.g. 1,2,4,8 (bytes)
    GLsizei  getPackAlignment()const;

    //! 1,2,3 or 4 based on format
    GLsizei  getNumberOfChannels() const;
77
78
79

    //! flips the image horizontally as some image formats have a different coordinate system as OpenGL has.
    void flipHorizontally();
80
81
82
83
84
85
86
87
88
    // ========================================================================================================= \/
    // ================================================================================================= SETTERS \/
    // ========================================================================================================= \/
public:
    void setData  (GLubyte* _pData)  { pData  = _pData;  }
    void setWidth (GLsizei  _width)  { width  = _width;  }
    void setHeight(GLsizei  _height) { height = _height; }
    void setDepth (GLsizei  _depth)  { depth  = _depth;  }
    void setFormat(GLenum   _format) { format = _format; }
89
    void setType  (GLenum   _type)   { mType  = _type;   }
Robert Menzel's avatar
Robert Menzel committed
90
    void setPadding(GLsizei _padding){ paddingBytesPerRow = _padding; }
91
    void setSize  (const glm::uvec3 &_size) { width  = _size.x; height = _size.y; depth = _size.z; }
92
93
94
95
96

    // ========================================================================================================= \/
    // ================================================================================================== FIELDS \/
    // ========================================================================================================= \/
private:
97
    size_t   getBytesPerScanline() const;
98
99
100
101
    GLubyte* pData;
    GLsizei  width;
    GLsizei  height;
    GLsizei  depth;
Robert Menzel's avatar
Robert Menzel committed
102
    GLenum   format; // channel types and count
103
    GLenum   mType;   // data type
Robert Menzel's avatar
Robert Menzel committed
104
105
    GLsizei  paddingBytesPerRow; // number of padding bytes added per row: glReadPixel can read with padding and
                                 // some image writers support/need this as well (e.g. QT)
106
107
};

Robert Menzel's avatar
Robert Menzel committed
108
ACGL_SMARTPOINTER_TYPEDEFS(TextureData)
109
110
111
112
113

} // OpenGL
} // ACGL

#endif // ACGL_OPENGL_DATA_TEXTUREDATA_HH