glcxx: A Modern C++ Interface to OpenGL Object Management
Shader.hpp
Go to the documentation of this file.
1 
6 #ifndef GLCXX_SHADER_HPP
7 #define GLCXX_SHADER_HPP
8 
9 #include "glcxx/gl.hpp"
10 #include <memory>
11 
12 namespace glcxx
13 {
17  class Shader
18  {
19  public:
25  Shader(GLenum shader_type);
26 
30  ~Shader();
31 
40  void set_source(const char * source, int length = -1);
41 
47  void set_source_from_file(const char * filename);
48 
54  GLuint id() const { return m_id; }
55 
65  static std::shared_ptr<Shader>
66  create(GLenum shader_type, const char * source, int length = -1)
67  {
68  std::shared_ptr<Shader> shader = std::make_shared<Shader>(shader_type);
69  shader->set_source(source, length);
70  return shader;
71  }
72 
79  static std::shared_ptr<Shader>
80  create_from_file(GLenum shader_type, const char * filename)
81  {
82  std::shared_ptr<Shader> shader = std::make_shared<Shader>(shader_type);
83  shader->set_source_from_file(filename);
84  return shader;
85  }
86 
87  protected:
91  GLuint m_id;
92 
96  GLenum m_shader_type;
97 
101  void allocate();
102  };
103 };
104 
105 #endif
void allocate()
Allocate the OpenGL shader object.
Definition: Shader.cpp:81
C++ wrapper for an OpenGL shader object.
Definition: Shader.hpp:17
GLuint id() const
Get the shader object&#39;s ID.
Definition: Shader.hpp:54
Include module for the main OpenGL header.
Definition: Array.cpp:4
GLenum m_shader_type
The OpenGL shader type.
Definition: Shader.hpp:96
~Shader()
Destroy the shader object.
Definition: Shader.cpp:15
Shader(GLenum shader_type)
Create and allocate an OpenGL shader object.
Definition: Shader.cpp:9
GLuint m_id
The shader object&#39;s ID.
Definition: Shader.hpp:91
void set_source_from_file(const char *filename)
Load shader source from a file.
Definition: Shader.cpp:65
void set_source(const char *source, int length=-1)
Load shader source from memory.
Definition: Shader.cpp:20
static std::shared_ptr< Shader > create(GLenum shader_type, const char *source, int length=-1)
Factory method to construct a Shader object.
Definition: Shader.hpp:66
static std::shared_ptr< Shader > create_from_file(GLenum shader_type, const char *filename)
Factory method to construct a Shader object.
Definition: Shader.hpp:80