Shader.hh 2.98 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 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 23
#include <tr1/memory>

#include <ACGL/ACGL.hh>

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

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

class Shader
{
32 33
    ACGL_NOT_COPYABLE(Shader)

Robert Menzel's avatar
Robert Menzel committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
    Shader(GLenum _type)
    :   mContext(0),
        mType(_type)
    {
        mContext = glCreateShader(mType);
    }

    virtual ~Shader(void)
    {
        // "DeleteShader will silently ignore the value zero." - GL Spec
        glDeleteShader(mContext);
    }
    
    // ==================================================================================================== \/
    // ============================================================================================ GETTERS \/
    // ==================================================================================================== \/
public:
    inline GLuint getContext (void) const { return mContext; }
    inline GLenum getType    (void) const { return mType;    }

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

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

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

76
ACGL_SHARED_TYPEDEF(Shader)
Robert Menzel's avatar
Robert Menzel committed
77 78

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

81
#endif // ACGL_OPENGL_OBJECTS_SHADER_HH