TextureData.hh 4.06 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),
Robert Menzel's avatar
Robert Menzel committed
37
38
        type(GL_UNSIGNED_BYTE),
        paddingBytesPerRow(0)
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    {}
    virtual ~TextureData(void)
    {
        delete[] pData;
    }

    // ========================================================================================================= \/
    // ================================================================================================= GETTERS \/
    // ========================================================================================================= \/
public:
    GLubyte* getData    (void) const { return pData;   }
    GLsizei  getWidth   (void) const { return width;   }
    GLsizei  getHeight  (void) const { return height;  }
    GLsizei  getDepth   (void) const { return depth;   }
    GLenum   getFormat  (void) const { return format;  }
    GLenum   getType    (void) const { return type;    }
Robert Menzel's avatar
Robert Menzel committed
55
    GLsizei  getPadding (void) const { return paddingBytesPerRow; }
Robert Menzel's avatar
Robert Menzel committed
56
    glm::uvec3 getSize  (void) const { return glm::uvec3( width, height, depth ); }
Robert Menzel's avatar
Robert Menzel committed
57
58
59
60
61
62

    //! 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;
63
64
65
66
67
68
69
70
71
72
    // ========================================================================================================= \/
    // ================================================================================================= 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; }
    void setType  (GLenum   _type)   { type   = _type;   }
Robert Menzel's avatar
Robert Menzel committed
73
    void setPadding(GLsizei _padding){ paddingBytesPerRow = _padding; }
74
    void setSize  (const glm::uvec3 &_size) { width  = _size.x; height = _size.y; depth = _size.z; }
75
76
77
78
79
80
81
82
83

    // ========================================================================================================= \/
    // ================================================================================================== FIELDS \/
    // ========================================================================================================= \/
private:
    GLubyte* pData;
    GLsizei  width;
    GLsizei  height;
    GLsizei  depth;
Robert Menzel's avatar
Robert Menzel committed
84
85
86
87
    GLenum   format; // channel types and count
    GLenum   type;   // data type
    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)
88
89
};

Robert Menzel's avatar
Robert Menzel committed
90
ACGL_SMARTPOINTER_TYPEDEFS(TextureData)
91
92
93
94
95

} // OpenGL
} // ACGL

#endif // ACGL_OPENGL_DATA_TEXTUREDATA_HH