OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shader.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef SHADER_H
22 #define SHADER_H
23 #include "matrix.h"
24 #include "common.h"
25 #include <unordered_map>
26 
27 class Shader
28 {
29 public:
30  Shader();
31 
32  bool load_from_src(const string *sources, GLenum *types, int count);
33  bool load_from_src(string vs_src, string fs_src);
34  bool load_from_file(const string *paths, GLenum *types, int count);
35  bool load_from_file(string vs_path, string fs_path);
36  bool load_compute_from_file(string cs_path);
37  bool link();
38  void dispose();
39 
40  void use();
41  void unuse();
42 
43  GLint get_uniform_location(string name);
44  GLint get_attribute_location(string name);
45 
46  void set_attribfv(string name, GLsizei num_components, GLsizei stride, GLsizei offset);
47  void unset_attrib(string name);
48 
49  void set_uniform(string name, const mat4 &v);
50  void set_uniform(string name, const vec4 &v);
51  void set_uniform(string name, const vec3 &v);
52  void set_uniform(string name, const vec2 &v);
53  void set_uniform(string name, double v);
54  void set_uniform(string name, float v);
55  void set_uniform(string name, int v);
56  void set_uniform(string name, unsigned int v);
57 private:
58  std::unordered_map<string, GLint> m_attributes;
59  std::unordered_map<string, GLint> m_uniforms;
61  std::vector<GLuint> m_shaders;
62 };
63 
64 #endif
const GLfloat * v
Definition: gl2ext.h:2231
Shader()
Definition: shader.cpp:24
void set_attribfv(string name, GLsizei num_components, GLsizei stride, GLsizei offset)
Definition: shader.cpp:182
bool load_compute_from_file(string cs_path)
Definition: shader.cpp:117
Definition: matrix.h:51
Definition: matrix.h:28
bool load_from_file(const string *paths, GLenum *types, int count)
Definition: shader.cpp:93
GLsizei GLenum * sources
Definition: gl2ext.h:136
GLenum GLuint GLintptr offset
Definition: gl2ext.h:629
std::vector< GLuint > m_shaders
Definition: shader.h:61
Definition: matrix.h:75
GLsizei const GLuint * paths
Definition: gl2ext.h:2476
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
bool load_from_src(const string *sources, GLenum *types, int count)
Definition: shader.cpp:72
void dispose()
Definition: shader.cpp:129
std::unordered_map< string, GLint > m_attributes
Definition: shader.h:58
bool link()
Definition: shader.cpp:124
void set_uniform(string name, const mat4 &v)
Definition: shader.cpp:202
GLsizei GLenum GLenum * types
Definition: gl2ext.h:136
GLuint m_id
Definition: shader.h:60
void unuse()
Definition: shader.cpp:143
Definition: shader.h:27
GLint get_attribute_location(string name)
Definition: shader.cpp:165
GLuint name
Definition: gl2ext.h:139
GLint get_uniform_location(string name)
Definition: shader.cpp:148
void use()
Definition: shader.cpp:138
Definition: matrix.h:104
const void GLsizei GLsizei stride
Definition: gl2ext.h:1335
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
std::unordered_map< string, GLint > m_uniforms
Definition: shader.h:59
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
void unset_attrib(string name)
Definition: shader.cpp:197