00001 #ifndef GSGL_PLATFORM_SHADER_H 00002 #define GSGL_PLATFORM_SHADER_H 00003 00004 // 00005 // $Id: shader.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "platform/platform.hpp" 00038 #include "data/string.hpp" 00039 #include "data/list.hpp" 00040 00041 namespace gsgl 00042 { 00043 00044 namespace platform 00045 { 00046 00047 class shader_base; 00048 00049 class PLATFORM_API shader_program 00050 { 00051 int opengl_id; 00052 00053 gsgl::data::list<shader_base *> shaders; 00054 public: 00055 shader_program(); 00056 ~shader_program(); 00057 00058 void add_vertex_shader(const gsgl::string & fname); 00059 void add_fragment_shader(const gsgl::string & fname); 00060 00061 /// Loads and compiles the shader program. This should only be called in the main thread with a valid OpenGL context. 00062 void load(); 00063 00064 /// Unloads the shader program. 00065 void unload(); 00066 00067 /// Tells OpenGL to use the shader program. 00068 void bind(); 00069 00070 /// Tells OpenGL to used the default shaders. 00071 void unbind(); 00072 00073 void set_uniform(const char *name, const int & i); 00074 void set_uniform(const char *name, const float & f); 00075 void set_uniform(const char *name, const float ff[4]); 00076 void set_uniform(const char *name, const bool b); 00077 00078 int get_id() { return opengl_id; } 00079 00080 private: 00081 int get_uniform_loc(const char *name); 00082 }; // class shader_program 00083 00084 } // namespace platform 00085 00086 } // namespace gsgl 00087 00088 #endif