TextureControl.hh 5.03 KB
Newer Older
Robert Menzel's avatar
Robert Menzel committed
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

6
7
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
Robert Menzel's avatar
Robert Menzel committed
8

9
10
11
12
13
/**
 * Can create an empty texture, if a texture should get loaded from a file,
 * see TextureControlFile.
 */

Robert Menzel's avatar
Robert Menzel committed
14
15
#include <ACGL/ACGL.hh>

16
#include <ACGL/Resource/BasicCreateController.hh>
Robert Menzel's avatar
Robert Menzel committed
17
18
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/GL.hh>
Robert Menzel's avatar
Robert Menzel committed
19
20

namespace ACGL{
Robert Menzel's avatar
Robert Menzel committed
21
namespace OpenGL{
Robert Menzel's avatar
Robert Menzel committed
22

23
class TextureControl : public Resource::BasicCreateController<Texture>
Robert Menzel's avatar
Robert Menzel committed
24
25
26
27
28
29
{
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
    TextureControl(void)
30
31
    :   Resource::BasicCreateController<Texture>(),
        mWidth(0),
Robert Menzel's avatar
Robert Menzel committed
32
33
34
35
36
37
38
        mHeight(0),
        mDepth(0),
        mInternalFormat(GL_RGBA),
        mTarget(GL_TEXTURE_2D),
        mFormat(GL_RGBA),
        mType(GL_UNSIGNED_BYTE),
        mMinFilter(0),
39
        mMagFilter(0),
Robert Menzel's avatar
Robert Menzel committed
40
        mAnisotropicFilter(0.0f),
Janis Born's avatar
Janis Born committed
41
        mWrapS(0),
42
43
        mWrapT(0),
        mWrapR(0)
Robert Menzel's avatar
Robert Menzel committed
44
45
46
47
48
49
50
    {}
    virtual ~TextureControl(void) {}

    // ==================================================================================================== \/
    // ============================================================================================ METHODS \/
    // ==================================================================================================== \/
public:
51
52
    inline TextureControl& size ( const glm::uvec2 &_size ) { return size(_size.x, _size.y); }
    inline TextureControl& size ( const glm::uvec3 &_size ) { return size(_size.x, _size.y, _size.z); }
53

Robert Menzel's avatar
Robert Menzel committed
54
55
56
57
58
59
60
61
    inline TextureControl& size (GLsizei _width, GLsizei _height = 0, GLsizei _depth = 0)
    {
        mWidth = _width;
        mHeight = _height;
        mDepth = _depth;
        return *this;
    }

62
63
64
65
    inline TextureControl& wrap (GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
    {
        mWrapS = _wrapS;
        mWrapT = _wrapT;
Robert Menzel's avatar
Robert Menzel committed
66
        mWrapR = _wrapR;
67
68
69
        return *this;
    }

70
71
72
73
74
75
    inline TextureControl& internalFormat    (GLenum _internalFormat)   { mInternalFormat = _internalFormat;       return *this; }
    inline TextureControl& target            (GLenum _target)           { mTarget = _target;                       return *this; }
    inline TextureControl& format            (GLenum _format)           { mFormat = _format;                       return *this; }
    inline TextureControl& type              (GLenum type)              { mType = type;                            return *this; }
    inline TextureControl& minFilter         (GLint _minFilter)         { mMinFilter = _minFilter;                 return *this; }
    inline TextureControl& magFilter         (GLint _magFilter)         { mMagFilter = _magFilter;                 return *this; }
Robert Menzel's avatar
Robert Menzel committed
76
    inline TextureControl& anisotropicFilter (GLfloat _anisotropicFilter) { mAnisotropicFilter = _anisotropicFilter; return *this; }
Robert Menzel's avatar
Robert Menzel committed
77
78
79
80
81
82
83

    // ===================================================================================================== \/
    // ============================================================================================ OVERRIDE \/
    // ===================================================================================================== \/
public:
    virtual SharedTexture create(void)
    {
84
85
        SharedTexture texture(new Texture(mTarget));
        texture->bind();
Robert Menzel's avatar
Robert Menzel committed
86
87
88
89
        if(mMinFilter > 0)            texture->setMinFilter(mMinFilter);
        if(mMagFilter > 0)            texture->setMagFilter(mMagFilter);
        if(mWrapS > 0)                texture->setWrap(mWrapS, mWrapT, mWrapR);
        if(mAnisotropicFilter > 0.0f) texture->setAnisotropicFilter(mAnisotropicFilter);
90
91
92
93
94
        texture->setImageData(
            NULL,
            mWidth,
            mHeight,
            mDepth,
Robert Menzel's avatar
Robert Menzel committed
95
96
            mInternalFormat,
            mFormat,
97
            mType);
Robert Menzel's avatar
Robert Menzel committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        return texture;
    }

    // =================================================================================================== \/
    // ============================================================================================ FIELDS \/
    // =================================================================================================== \/
protected:
    GLsizei mWidth;
    GLsizei mHeight;
    GLsizei mDepth;
    GLenum  mInternalFormat;
    GLenum  mTarget;
    GLenum  mFormat;
    GLenum  mType;
    GLint   mMinFilter;
    GLint   mMagFilter;
114
    GLfloat mAnisotropicFilter;
115
116
117
    GLenum  mWrapS;
    GLenum  mWrapT;
    GLenum  mWrapR;
Robert Menzel's avatar
Robert Menzel committed
118
119
};

Robert Menzel's avatar
Robert Menzel committed
120
} // OpenGL
Robert Menzel's avatar
Robert Menzel committed
121
122
} // ACGL

123
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH