Mondschein Engine  0.3.0
renderer.cpp
1 /* Mondschein Engine is a fast, powerful, and easy-to-use 3D realtime rendering engine.
2  *
3  * Copyright (C) 2009-2013 by Andreas Amereller
4  * E-Mail: andreas.amereller.dev@googlemail.com
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "core/renderer.h"
22 #include <GL/gl.h>
23 
24 using namespace mondschein;
25 using namespace renderer;
26 
27 Renderer::Renderer()
28 {
29  return;
30 }
31 
32 Renderer::~Renderer()
33 {
34  return;
35 }
36 
37 void Renderer::set_context(Context_p _c)
38 {
39  context=_c;
40 }
41 
42 Context_p Renderer::get_context() const
43 {
44  return context;
45 }
46 
47 void Renderer::toggle_feature(const std::string &_feature,bool _state)
48 {
49  if (context.get()==nullptr)
50  {
51  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
52  err+="void mondschein::renderer::Renderer::toggle_feature(const std::string &_feature,bool _state) const";
53  throw boost::enable_current_exception(exception()) << exception_error(err);
54  }
55  if (!Engine::is_current(context))
56  {
57  std::string err("Mondschein Engine ERROR: The context must be current for the renderer to take action.");
58  err+=" Exception raised in function\n\t";
59  err+="void mondschein::renderer::Renderer::toggle_feature(const std::string &_feature,bool _state) const";
60  throw boost::enable_current_exception(exception()) << exception_error(err);
61  }
62  return;
63 }
64 
65 bool Renderer::query_extension(const std::string &_ext)
66 {
67  if (context.get() == nullptr)
68  {
69  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
70  err+="bool mondschein::renderer::Renderer::query_extension(const std::string &_ext)";
71  throw boost::enable_current_exception(exception()) << exception_error(err);
72  }
73  if (!Engine::is_current(context))
74  {
75  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
76  err+="bool mondschein::renderer::Renderer::query_extension(const std::string &_ext)";
77  throw boost::enable_current_exception(exception()) << exception_error(err);
78  }
79  const char *c=reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
80  std::string str(c);
81  if (str.find(_ext)!=std::string::npos) return true;
82  else return false;
83 }
84 
85 void Renderer::set_clear_color(const Eigen::Vector4d& _c)
86 {
87  if (context.get()==nullptr)
88  {
89  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
90  err+="void mondschein::renderer::Renderer::set_clear_color(const Eigen::Vector4d& _c)";
91  throw boost::enable_current_exception(exception()) << exception_error(err);
92  }
93  if (!Engine::is_current(context))
94  {
95  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
96  err+="void mondschein::renderer::Renderer::set_clear_color(const Eigen::Vector4d& _c)";
97  throw boost::enable_current_exception(exception()) << exception_error(err);
98  }
99  return;
100 }
101 
103 {
104  if (context.get()==nullptr)
105  {
106  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
107  err+="void mondschein::renderer::Renderer::clear_color_buffer()";
108  throw boost::enable_current_exception(exception()) << exception_error(err);
109  }
110  if (!Engine::is_current(context))
111  {
112  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
113  err+="void mondschein::renderer::Renderer::clear_color_buffer()";
114  throw boost::enable_current_exception(exception()) << exception_error(err);
115  }
116  return;
117 }
118 
120 {
121  if (context.get()==nullptr)
122  {
123  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
124  err+="void mondschein::renderer::Renderer::clear_depth_buffer()";
125  throw boost::enable_current_exception(exception()) << exception_error(err);
126  }
127  if (!Engine::is_current(context))
128  {
129  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
130  err+="void mondschein::renderer::Renderer::clear_depth_buffer()";
131  throw boost::enable_current_exception(exception()) << exception_error(err);
132  }
133  return;
134 }
135 
136 void Renderer::make_renderable(scene::Scenenode_c _sn)
137 {
138  if (context.get()==nullptr)
139  {
140  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
141  err+="void mondschein::renderer::Renderer::make_renderable(scene::Scenenode_c _sn)";
142  throw boost::enable_current_exception(exception()) << exception_error(err);
143  }
144  if (!Engine::is_current(context))
145  {
146  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
147  err+="void mondschein::renderer::Renderer::make_renderable(scene::Scenenode_c _sn)";
148  throw boost::enable_current_exception(exception()) << exception_error(err);
149  }
150  return;
151 }
152 
153 void Renderer::render(scene::Scenegraph_c _sg,const uint32 _start)
154 {
155  if (context.get()==nullptr)
156  {
157  std::string err("Mondschein Engine ERROR: No context available or context not set. Exception raised in function\n\t");
158  err+="void mondschein::renderer::Renderer::render(scene::Scenegraph_c _sg,const uint32 _start)";
159  throw boost::enable_current_exception(exception()) << exception_error(err);
160  }
161  if (!Engine::is_current(context))
162  {
163  std::string err("Mondschein Engine ERROR: Context is not current. Exception raised in function\n\t");
164  err+="void mondschein::renderer::Renderer::render(scene::Scenegraph_c _sg,const uint32 _start)";
165  throw boost::enable_current_exception(exception()) << exception_error(err);
166  }
167  return;
168 }