Debian Codegraph @

avogadro/rendering/shader.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_RENDERING_SHADER_H
7 #define AVOGADRO_RENDERING_SHADER_H
8
9 #include "avogadrorenderingexport.h"
10 #include <avogadro/core/avogadrocore.h>
11
12 #include <string> // For member variables.
13
14 namespace Avogadro {
15 namespace Rendering {
16
17 /**
18 * @class Shader shader.h <avogadro/rendering/shader.h>
19 * @brief Vertex or Fragment shader, combined into a ShaderProgram.
20 * @author Marcus D. Hanwell
21 *
22 * This class creates a Vertex or Fragment shader, that can be attached to a
23 * ShaderProgram in order to render geometry etc.
24 */
25
26 class AVOGADRORENDERING_EXPORT Shader
27 {
28 public:
29 /** Available shader types. */
30 enum Type
31 {
32 Vertex, /**< Vertex shader */
33 Fragment, /**< Fragment shader */
34 Unknown /**< Unknown (default) */
35 };
36
37 explicit Shader(Type type = Unknown, const std::string& source = "");
38 ~Shader();
39
40 /** Set the shader type. */
41 void setType(Type type);
42
43 /** Get the shader type, typically Vertex or Fragment. */
44 Type type() const { return m_type; }
45
46 /** Set the shader source to the supplied string. */
47 void setSource(const std::string& source);
48
49 /** Get the source for the shader. */
50 std::string source() const { return m_source; }
51
52 /** Get the error message (empty if none) for the shader. */
53 std::string error() const { return m_error; }
54
55 /** Get the handle of the shader. */
56 Index handle() const { return m_handle; }
57
58 /** Compile the shader.
59 * @note A valid context must to current in order to compile the shader.
60 */
61 bool compile();
62
63 /** Delete the shader.
64 * @note This should only be done once the ShaderProgram is done with the
65 * Shader.
66 */
67 void cleanup();
68
69 protected:
70 Type m_type;
71 Index m_handle;
72 bool m_dirty;
73
74 std::string m_source;
75 std::string m_error;
76 };
77
78 } // namespace Rendering
79 } // namespace Avogadro
80
81 #endif // AVOGADRO_RENDERING_SHADER_H