qxLib
shaders.h
Go to the documentation of this file.
1 /**
2 
3  @file shaders.h
4  @author Khrapov
5  @date 17.06.2019
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
13 
14 #include <glew.h>
15 
16 namespace qx
17 {
18 
19 enum class shader_type
20 {
21  vert, //!< vertex
22  tesc, //!< tessellation control
23  tese, //!< tessellation evaluation
24  geom, //!< geometry
25  frag, //!< fragment
26  comp //!< compute
27 };
28 
29 /**
30 
31  @class shader_base
32  @brief OpenGL base shader
33  @details ~
34  @tparam ShaderType - GL_VERTEX_SHADER, GL_TESS_CONTROL_SHADER,
35  GL_TESS_EVALUATION_SHADER, GL_GEOMETRY_SHADER,
36  GL_FRAGMENT_SHADER, GL_COMPUTE_SHADER
37  @author Khrapov
38  @date 17.06.2019
39 
40 **/
41 template<GLenum ShaderType>
43 {
44 public:
45  QX_NONCOPYABLE(shader_base);
46  QX_MOVABLE(shader_base);
47 
48  shader_base() = default;
49  ~shader_base();
50 
51  /**
52  @brief Init (compile) shader
53  @param pszShaderCode - string with shader code
54  @retval - error or empty string if init was successful
55  **/
56  string Init(const GLchar* pszShaderCode);
57 
58  /**
59  @brief Get shader name
60  @retval - shader name
61  **/
62  GLuint GetID() const;
63 
64  /**
65  @brief Get shader parameter
66  @param eParameter - shader parameter
67  \see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetProgram.xhtml
68  @retval - shader parameter value
69  **/
70  GLint GetParameter(GLenum eParameter) const;
71 
72 private:
73  GLuint m_nShader = std::numeric_limits<GLuint>::max();
74 };
75 
82 
83 } // namespace qx
84 
85 #include <qx/gl/shaders.inl>
OpenGL base shader.
Definition: shaders.h:43
GLuint GetID() const
Get shader name.
Definition: shaders.inl:54
GLint GetParameter(GLenum eParameter) const
Get shader parameter.
Definition: shaders.inl:60
string Init(const GLchar *pszShaderCode)
Init (compile) shader.
Definition: shaders.inl:20
shader_type
Definition: shaders.h:20
@ frag
fragment
@ tese
tessellation evaluation
@ geom
geometry
@ tesc
tessellation control