OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
shader.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GFX_SHADER_HH
20 #define OST_GFX_SHADER_HH
21 
22 /*
23  GLSL wrapper and organization
24 
25  Author: Ansgar Philippsen
26 */
27 
28 #include <string>
29 #include <map>
30 #include <stack>
31 #include <vector>
32 
33 #include <ost/gfx/module_config.hh>
34 #include "glext_include.hh"
35 
36 namespace ost { namespace gfx {
37 
39 public:
40  // singleton implementation
41  static Shader& Instance();
42 
43  void PreGLInit();
44  void Setup();
45  void Activate(const String& name);
46 
47  bool IsValid() const;
48  bool IsActive() const;
49 
50  GLuint GetCurrentProgram() const;
51  String GetCurrentName() const;
52 
53  void PushProgram();
54  void PopProgram();
55 
56  void UpdateState();
57 
58  void Link(const std::string& pr_name, const std::string& vs_code, const std::string& fs_code);
59 
60  static bool Compile(const std::string& shader_name,
61  const std::string& shader_code,
62  GLenum shader_type,
63  GLuint& shader_id);
64 
65 private:
66  Shader();
67 
68  bool valid_;
69  GLuint current_program_;
70  String current_name_;
71 
72  std::stack<String> program_stack_;
73 
74  std::map<String,GLuint> shader_program_map_;
75 };
76 
77 }} // ns
78 
79 #endif
std::string String
Definition: base.hh:54
#define DLLEXPORT_OST_GFX