Shader.hh 2.99 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_OBJECTS_SHADER_HH
#define ACGL_OPENGL_OBJECTS_SHADER_HH
Robert Menzel's avatar
Robert Menzel committed
8

Robert Menzel's avatar
Robert Menzel committed
9
/**
Robert Menzel's avatar
Robert Menzel committed
10 11 12 13 14 15 16 17
 * A Shader ist just one OpenGL shader like a fragment or vertex shader. To use these
 * a ShaderProgram is needed that links together multiple Shaders for the different
 * pipelinestages.
 *
 * So normally you want to work with ShaderPrograms instead of Shaders (switch Programs,
 * set uniforms etc).
 */

Robert Menzel's avatar
Robert Menzel committed
18 19
#include <vector>
#include <string>
Robert Menzel's avatar
Robert Menzel committed
20 21 22

#include <ACGL/ACGL.hh>

23
#include <ACGL/Base/Macros.hh>
Robert Menzel's avatar
Robert Menzel committed
24
#include <ACGL/OpenGL/GL.hh>
Robert Menzel's avatar
Robert Menzel committed
25 26

namespace ACGL{
Robert Menzel's avatar
Robert Menzel committed
27
namespace OpenGL{
Robert Menzel's avatar
Robert Menzel committed
28 29 30

class Shader
{
31 32
    ACGL_NOT_COPYABLE(Shader)

Robert Menzel's avatar
Robert Menzel committed
33 34 35 36 37
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
    Shader(GLenum _type)
38
    :   mObjectName(0),
Robert Menzel's avatar
Robert Menzel committed
39 40
        mType(_type)
    {
41
        mObjectName = glCreateShader(mType);
Robert Menzel's avatar
Robert Menzel committed
42 43 44 45 46
    }

    virtual ~Shader(void)
    {
        // "DeleteShader will silently ignore the value zero." - GL Spec
47
        glDeleteShader(mObjectName);
Robert Menzel's avatar
Robert Menzel committed
48 49 50 51 52 53
    }
    
    // ==================================================================================================== \/
    // ============================================================================================ GETTERS \/
    // ==================================================================================================== \/
public:
54 55
    inline GLuint getObjectName(void) const { return mObjectName; }
    inline GLenum getType      (void) const { return mType;       }
Robert Menzel's avatar
Robert Menzel committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    // ==================================================================================================== \/
    // ============================================================================================ METHODS \/
    // ==================================================================================================== \/
public:
    bool setFromFile (const std::string &_filename);
    bool setSource   (const std::string &_source  );

protected:
    bool compile (const char *_pProgramText) const;

    // =================================================================================================== \/
    // ============================================================================================ FIELDS \/
    // =================================================================================================== \/
protected:
71
    GLuint              mObjectName;
72
    GLenum              mType;
Robert Menzel's avatar
Robert Menzel committed
73 74
};

Robert Menzel's avatar
Robert Menzel committed
75
ACGL_SMARTPOINTER_TYPEDEFS(Shader)
Robert Menzel's avatar
Robert Menzel committed
76 77

} // OpenGL
Robert Menzel's avatar
Robert Menzel committed
78 79
} // ACGL

80
#endif // ACGL_OPENGL_OBJECTS_SHADER_HH