1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 // File: vogl_shader_utils.h
27 #ifndef VOGL_SHADER_UTILS_H
28 #define VOGL_SHADER_UTILS_H
30 #include "vogl_core.h"
31 #include "vogl_common.h"
32 #include "vogl_matrix.h"
34 GLuint vogl_create_program(const char *pVertex_shader, const char *pFragment_shader);
36 class vogl_scoped_program_binder
38 VOGL_NO_COPY_OR_ASSIGNMENT_OP(vogl_scoped_program_binder);
41 vogl_scoped_program_binder(GLuint new_prog) :
44 GL_ENTRYPOINT(glGetIntegerv)(GL_CURRENT_PROGRAM, reinterpret_cast<GLint *>(&m_prev_program));
47 GL_ENTRYPOINT(glUseProgram)(new_prog);
51 ~vogl_scoped_program_binder()
53 GL_ENTRYPOINT(glUseProgram)(m_prev_program);
58 GLuint m_prev_program;
61 class vogl_simple_gl_program
63 VOGL_NO_COPY_OR_ASSIGNMENT_OP(vogl_simple_gl_program);
66 vogl_simple_gl_program();
67 vogl_simple_gl_program(const char *pVertex_shader, const char *pFragment_shader);
68 ~vogl_simple_gl_program();
70 bool init(const char *pVertex_shader, const char *pFragment_shader);
73 bool is_valid() const { return m_program != 0; }
75 GLuint get_handle() const { return m_program; }
77 GLint get_uniform_location(const char *pName) const;
78 bool has_uniform(const char *pName) const;
80 void set_uniform(const char *pName, int s);
81 void set_uniform(const char *pName, uint s);
82 void set_uniform(const char *pName, float s);
84 void set_uniform(const char *pName, const vec2I &v);
85 void set_uniform(const char *pName, const vec2F &v);
87 void set_uniform(const char *pName, const vec3I &v);
88 void set_uniform(const char *pName, const vec3F &v);
90 void set_uniform(const char *pName, const vec4I &v);
91 void set_uniform(const char *pName, const vec4F &v);
93 void set_uniform(const char *pName, const matrix33F &m, bool transpose);
94 void set_uniform(const char *pName, const matrix44F &m, bool transpose);
100 #endif // VOGL_SHADER_UTILS_H