44 const char*,
const char*);
46 const char*,
const char**);
48 const char*,
unsigned char);
50 const char*,
unsigned int);
52 const char*,
const float*);
54 const char*,
const int*);
56 const char*,
const unsigned char*);
58 const char*,
const unsigned int*);
60 const char*,
const void*);
72 const char*,
long long);
74 const char*,
long long*);
76 const char*,
unsigned char*);
78 const char*,
unsigned int*);
80 const char*,
unsigned long);
82 const char*,
unsigned long*);
84 const char*,
unsigned long long);
86 const char*,
unsigned long long*);
101 template <
typename T>
102 static const std::string AnyToString(
const T& val) {
103 std::ostringstream out;
109 template <>
const std::string AnyToString(
const unsigned int& val) {
110 std::ostringstream out;
111 out <<
"0x" << std::hex << val;
118 static const std::string GetClearBitsString(GLbitfield mask) {
120 if (mask & GL_COLOR_BUFFER_BIT) {
121 s +=
"GL_COLOR_BUFFER_BIT";
122 mask &= ~GL_COLOR_BUFFER_BIT;
124 if (mask & GL_DEPTH_BUFFER_BIT) {
127 s +=
"GL_DEPTH_BUFFER_BIT";
128 mask &= ~GL_DEPTH_BUFFER_BIT;
130 if (mask & GL_STENCIL_BUFFER_BIT) {
133 s +=
"GL_STENCIL_BUFFER_BIT";
134 mask &= ~GL_STENCIL_BUFFER_BIT;
145 static const std::string GetMapBitsString(GLbitfield mode) {
147 if (mode & GL_MAP_READ_BIT) {
148 s +=
"GL_MAP_READ_BIT";
149 mode &= ~GL_MAP_READ_BIT;
151 if (mode & GL_MAP_WRITE_BIT) {
154 s +=
"GL_MAP_WRITE_BIT";
155 mode &= ~GL_MAP_WRITE_BIT;
165 template <
typename T>
166 static std::string ArrayToString(
const std::string&
type,
T arg) {
167 return std::string();
171 template <
typename T>
172 static std::string TypedArrayToString(
const std::string&
type,
T arg) {
173 std::ostringstream out;
179 if (type.find(
"matrix") != std::string::npos)
182 for (
int j = 0; j < rows; ++j) {
183 for (
int i = 0; i < count; ++i) {
184 out << arg[j * count + i];
199 std::string ArrayToString<const int*>(
const std::string&
type,
const int* arg) {
200 return TypedArrayToString(type, arg);
203 std::string ArrayToString<const float*>(
const std::string&
type,
205 return TypedArrayToString(type, arg);
211 #define ION_ADD_CONSTANT(name) (*constants)[name] = #name
212 static void IonAddConstantsAToF(
213 std::unordered_map<int, std::string>* constants) {
351 static void IonAddConstantsGToQ(
352 std::unordered_map<int, std::string>* constants) {
469 static void IonAddConstantsRToS(
470 std::unordered_map<int, std::string>* constants) {
619 static void IonAddConstantsTToZ(
620 std::unordered_map<int, std::string>* constants) {
755 #undef ION_ADD_CONSTANT
760 IonAddConstantsAToF(&constants_);
761 IonAddConstantsGToQ(&constants_);
762 IonAddConstantsRToS(&constants_);
763 IonAddConstantsTToZ(&constants_);
767 template <
typename T>
770 const std::string arg_type_str(arg_type);
771 if (arg_type_str.find(
'*') != std::string::npos ||
772 arg_type_str.find(
"PROC") != std::string::npos) {
773 if (arg != static_cast<T>(0)) {
774 std::ostringstream out;
775 out <<
"0x" << std::hex << *reinterpret_cast<size_t*>(&arg);
778 out << ArrayToString(arg_type, arg);
785 return AnyToString(arg);
792 return std::string(
"\"") + arg +
'"';
798 return std::string(
"\"") + arg +
'"';
803 const char* arg_type,
const char** arg) {
804 return arg ?
"[" +
ToString(arg_type, arg[0]) +
", ...]" :
"NULL";
810 const char* arg_type,
unsigned char arg) {
818 return AnyToString(static_cast<int>(arg));
827 if (!strcmp(arg_type,
"GLtextureenum")) {
830 if (arg >= 0 && !constants_[arg].empty()) {
837 case GL_CLAMP_TO_EDGE:
838 case GL_COMPARE_REF_TO_TEXTURE:
845 case GL_LINEAR_MIPMAP_LINEAR:
846 case GL_LINEAR_MIPMAP_NEAREST:
848 case GL_MIRRORED_REPEAT:
850 case GL_NEAREST_MIPMAP_NEAREST:
851 case GL_NEAREST_MIPMAP_LINEAR:
856 return constants_[arg];
860 const std::string&
name = constants_[arg];
862 return constants_[arg];
864 }
else if (!strcmp(arg_type,
"GLintenum")) {
865 if (arg >= 0 && !constants_[arg].empty()) {
866 return constants_[arg];
870 return AnyToString(arg);
879 if (!strcmp(arg_type,
"GLblendenum")) {
882 else if (arg == GL_ONE)
884 else if (!constants_[arg].empty())
885 return constants_[arg];
886 }
else if (!strcmp(arg_type,
"GLstencilenum")) {
889 else if (!constants_[arg].empty())
890 return constants_[arg];
891 }
else if (!strcmp(arg_type,
"GLenum")) {
892 if (!constants_[arg].empty())
893 return constants_[arg];
894 }
else if (!strcmp(arg_type,
"GLbitfield")) {
896 const std::string s = GetClearBitsString(arg);
899 }
else if (!strcmp(arg_type,
"GLmapaccess")) {
901 const std::string s = GetMapBitsString(arg);
904 }
else if (!strcmp(arg_type,
"GLtextureenum")) {
907 else if (!constants_[arg].empty())
908 return constants_[arg];
910 return AnyToString(arg);
915 const char*,
const float*);
917 const char*,
const int*);
919 const char*,
const unsigned char*);
921 const char*,
const unsigned int*);
923 const char*,
const void*);
927 const char*,
float*);
935 const char*,
long long);
937 const char*,
long long*);
939 const char*,
unsigned char*);
941 const char*,
unsigned int*);
943 const char*,
unsigned long);
945 const char*,
unsigned long*);
947 const char*,
unsigned long long);
949 const char*,
unsigned long long*);
953 const char*,
void**);
959 #endif // ION_PRODUCTION
bool StartsWith(const std::string &target, const std::string &start)
Returns whether target begins with start.
const std::string ToString(const char *arg_type, T arg)
This templated function is used to print each OpenGL function argument in a more readable way...
TracingHelper()
The constructor sets up the data necessary to map OpenGL constant values to mnemonic names...
#define ION_ADD_CONSTANT(name)
int32 ION_API StringToInt32(const std::string &str)
Extracts and returns an integral value from str.