-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy patherrors.cpp
More file actions
118 lines (101 loc) · 3.18 KB
/
Copy patherrors.cpp
File metadata and controls
118 lines (101 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2004 by Jonathan Brandmeyer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
#include "util/errors.hpp"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <boost/python/import.hpp>
#include "python/gil.hpp"
namespace cvisual {
void write_stderr( const std::string& message ) {
python::gil_lock L; // though usually we already have it
// TODO: Exception handling; in case of failure maybe print error to "real" stderr or a log file
boost::python::import( "sys" ).attr( "stderr" ).attr( "write" )( message );
boost::python::import( "sys" ).attr( "stderr" ).attr( "flush" )();
}
void
write_critical(
std::string file,
int line,
std::string function,
std::string message)
{
std::ostringstream o;
o << "VPython ***CRITICAL ERROR***: " << file << ":" << line << ": "
<< function << ": " << message << "\n";
write_stderr( o.str() );
return;
}
void
write_warning(
std::string file,
int line,
std::string function,
std::string message)
{
std::ostringstream o;
o << "VPython WARNING: " << file << ":" << line << ": "
<< function << ": " << message << "\n";
write_stderr( o.str() );
return;
}
void
write_note( std::string file, int line, std::string message)
{
static bool enable = (bool)getenv( "VPYTHON_DEBUG");
if (!enable) return;
std::ostringstream o;
o << "VPython: " << file << ":" << line << ": " << message
<< "\n";
write_stderr( o.str() );
}
void
dump_glmatrix()
{
// TODO: set this up to write out a matrix with the same format for all of
// the members.
float M[4][4];
glGetFloatv( GL_MODELVIEW_MATRIX, M[0]);
std::cout << "Modelview matrix status:\n";
std::cout << "| " << M[0][0] << " " << M[1][0] << " " << M[2][0] << " " << M[3][0] << "|\n";
std::cout << "| " << M[0][1] << " " << M[1][1] << " " << M[2][1] << " " << M[3][1] << "|\n";
std::cout << "| " << M[0][2] << " " << M[1][2] << " " << M[2][2] << " " << M[3][2] << "|\n";
std::cout << "| " << M[0][3] << " " << M[1][3] << " " << M[2][3] << " " << M[3][3] << "|\n";
glGetFloatv( GL_PROJECTION_MATRIX, M[0]);
std::cout << "Projection matrix status:\n";
std::cout << "| " << M[0][0] << " " << M[1][0] << " " << M[2][0] << " " << M[3][0] << "|\n";
std::cout << "| " << M[0][1] << " " << M[1][1] << " " << M[2][1] << " " << M[3][1] << "|\n";
std::cout << "| " << M[0][2] << " " << M[1][2] << " " << M[2][2] << " " << M[3][2] << "|\n";
std::cout << "| " << M[0][3] << " " << M[1][3] << " " << M[2][3] << " " << M[3][3] << "|\n";
}
void
clear_gl_error_real()
{
#ifndef NDEBUG
glGetError();
#endif
}
void
check_gl_error_real( const char* file, int line)
{
#ifndef NDEBUG
GLenum err_code = glGetError();
// Insert the manual cast from the unsigned char pointer to signed char
// pointer type.
if (err_code != GL_NO_ERROR) {
std::ostringstream err;
err << file << ":" << line << " " << (const char*)gluErrorString(err_code);
throw gl_error( err.str().c_str(), err_code);
}
#endif
}
gl_error::gl_error( const char* msg, const GLenum err)
: std::runtime_error(msg), error( err)
{
}
gl_error::gl_error( const char* msg)
: std::runtime_error(msg), error( GL_NO_ERROR)
{
}
} // !namespace cvisual