Ocean
Loading...
Searching...
No Matches
GLESShader.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_GLES_SHADER_H
9#define META_OCEAN_RENDERING_GLES_SHADER_H
10
13
15
16namespace Ocean
17{
18
19namespace Rendering
20{
21
22namespace GLESceneGraph
23{
24
25// Forward declaration.
26class GLESShader;
27
28/**
29 * Definition of an object reference for shader containers.
30 * @ingroup renderinggles
31 */
33
34/**
35 * This class is the base class for all OpenGL ES shader container.
36 * @ingroup renderinggles
37 */
38class OCEAN_RENDERING_GLES_EXPORT GLESShader
39{
40 public:
41
42 /**
43 * Creates a new shader.
44 */
45 GLESShader() = default;
46
47 /**
48 * Destructs a vertex shader object.
49 */
50 virtual ~GLESShader();
51
52 /**
53 * Returns the id of this OpenGL ES shader.
54 * @return OpenGL ES shader id
55 */
56 inline GLuint id() const;
57
58 /**
59 * Compiles the shader using the given shader code.
60 * @param type The type of the shader, e.g., GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc.
61 * @param code Shader code defining the shader
62 * @param message Returning compiler error or warning message.
63 * @return True, if the compilation was successfully
64 */
65 bool compile(const GLenum type, const std::string& code, std::string& message);
66
67 /**
68 * Compiles the shader using the given shader code.
69 * @param type The type of the shader, e.g., GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc.
70 * @param codes Shader code defining the shader, can be composed of several individual code blocks
71 * @param lengths The lengths of the individual code fragments, in bytes
72 * @param message Returning compiler error or warning message.
73 * @return True, if the compilation was successfully
74 */
75 bool compile(const GLenum type, const std::vector<const GLchar*>& codes, const std::vector<GLint>& lengths, std::string& message);
76
77 /**
78 * Returns whether this shader holds no valid code.
79 * @return True, if so
80 */
81 inline bool isNull() const;
82
83 /**
84 * Returns whether this shader has been compiled successfully.
85 * @return True, if so
86 */
87 explicit inline operator bool() const;
88
89 protected:
90
91 /// OpenGL ES shader id.
92 GLuint id_ = 0u;
93
94 /// OpenGL ES shader type.
95 GLenum type_ = 0u;
96};
97
98inline GLuint GLESShader::id() const
99{
100 return id_;
101}
102
103inline bool GLESShader::isNull() const
104{
105 return id_ == 0u;
106}
107
108inline GLESShader::operator bool() const
109{
110 return id_ != 0u;
111}
112
113}
114
115}
116
117}
118
119#endif // META_OCEAN_RENDERING_GLES_SHADER_H
This template class implements a object reference with an internal reference counter.
Definition base/ObjectRef.h:58
This class is the base class for all OpenGL ES shader container.
Definition GLESShader.h:39
bool compile(const GLenum type, const std::string &code, std::string &message)
Compiles the shader using the given shader code.
GLuint id_
OpenGL ES shader id.
Definition GLESShader.h:92
GLESShader()=default
Creates a new shader.
bool isNull() const
Returns whether this shader holds no valid code.
Definition GLESShader.h:103
GLuint id() const
Returns the id of this OpenGL ES shader.
Definition GLESShader.h:98
bool compile(const GLenum type, const std::vector< const GLchar * > &codes, const std::vector< GLint > &lengths, std::string &message)
Compiles the shader using the given shader code.
virtual ~GLESShader()
Destructs a vertex shader object.
Ocean::ObjectRef< GLESShader > GLESShaderRef
Definition of an object reference for shader containers.
Definition GLESShader.h:32
The namespace covering the entire Ocean framework.
Definition Accessor.h:15