GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HdlShader.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : HdlShader.hpp */
11 /* Original Date : August 7th 2010 */
12 /* */
13 /* Description : OpenGL Pixel and Fragment Shader Handle */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __HDLSHADER_INCLUDE__
25 #define __HDLSHADER_INCLUDE__
26 
27  // GL include
28  #include "Core/LibTools.hpp"
29  #include "Core/OglInclude.hpp"
30  #include "Core/ShaderSource.hpp"
31  #include "Core/HdlDynamicData.hpp"
32  #include <string>
33  #include <fstream>
34 
35 namespace Glip
36 {
37  namespace CoreGL
38  {
39  // Shader Handle
44  class GLIP_API HdlShader : public ShaderSource
45  {
46  private :
47  // Data
48  GLuint shader;
49  GLenum type;
50 
51  public :
52  // Functions
53  HdlShader(GLenum _type, const ShaderSource& src);
54  ~HdlShader(void);
55 
56  GLuint getShaderID(void) const;
57  GLenum getType(void) const;
58  };
59 
60  // Program Handle
65  class GLIP_API HdlProgram
66  {
67  public :
68  static const int numShaderTypes = 6;
69 
70  private :
71  // Data
72  bool valid;
73  GLuint program;
74  GLuint attachedShaders[HandleOpenGL::numShaderTypes],
75  attachedFragmentShader;
76  std::vector<std::string> activeUniforms;
77  std::vector<GLenum> activeTypes;
78 
79  public :
80  // Functions
81  HdlProgram(void);
82  ~HdlProgram(void);
83 
84  bool isValid(void) const;
85  void updateShader(const HdlShader& shader, bool linkNow = true);
86  void link(void);
87  void use(void);
88 
89  const std::vector<std::string>& getUniformsNames(void) const;
90  const std::vector<GLenum>& getUniformsTypes(void) const;
91 
92  void setFragmentLocation(const std::string& fragName, int frag);
93  void setVar(const std::string& varName, GLenum type, int v0, int v1=0, int v2=0, int v3=0);
94  void setVar(const std::string& varName, GLenum type, int* v);
95  void setVar(const std::string& varName, GLenum type, unsigned int v0, unsigned int v1=0, unsigned int v2=0, unsigned int v3=0);
96  void setVar(const std::string& varName, GLenum type, unsigned int* v);
97  void setVar(const std::string& varName, GLenum type, float v0, float v1=0, float v2=0, float v3=0);
98  void setVar(const std::string& varName, GLenum type, float* v);
99  void setVar(const std::string& varName, const HdlDynamicData& data);
100 
101  void getVar(const std::string& varName, int* ptr);
102  void getVar(const std::string& varName, unsigned int* ptr);
103  void getVar(const std::string& varName, float* ptr);
104  void getVar(const std::string& varName, HdlDynamicData& data);
105 
106  bool isUniformVariableValid(const std::string& varName);
107 
108  // Static tools :
109  static int maxVaryingVar(void);
110  static void stopProgram(void);
111  };
112  }
113 }
114 
115 #endif
116 
Specific defines for the API structure.
Object handle for OpenGL Shaders Objects (both vertex and fragment shaders).
Definition: HdlShader.hpp:44
OpenGL Dynamic Memory Allocator.
Definition: Component.hpp:32
Shader source and tools.
static const unsigned int numShaderTypes
Number of different shader types.
Definition: OglInclude.hpp:95
Dynamic allocator for GL types (run-time resolution of type).
Definition: HdlDynamicData.hpp:65
Shader source code and infos.
Definition: ShaderSource.hpp:55
Object handle for OpenGL Program (A vertex and a fragment program).
Definition: HdlShader.hpp:65
OpenGL includes and tools.