-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathtypespec.cpp
67 lines (58 loc) · 1.99 KB
/
typespec.cpp
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
// Copyright 2015, Christopher J. Foster and the other displaz contributors.
// Use of this code is governed by the BSD-style license found in LICENSE.txt
#include "typespec.h"
#include "glutil.h"
#include <tinyformat.h>
//------------------------------------------------------------------------------
// TypeSpec functions
int glBaseType(const TypeSpec& spec)
{
switch (spec.type)
{
case TypeSpec::Float:
if (spec.elsize == 2) return GL_HALF_FLOAT;
if (spec.elsize == 4) return GL_FLOAT;
if (spec.elsize == 8) return GL_DOUBLE;
break;
case TypeSpec::Int:
if (spec.elsize == 1) return GL_BYTE;
if (spec.elsize == 2) return GL_SHORT;
if (spec.elsize == 4) return GL_INT;
break;
case TypeSpec::Uint:
if (spec.elsize == 1) return GL_UNSIGNED_BYTE;
if (spec.elsize == 2) return GL_UNSIGNED_SHORT;
if (spec.elsize == 4) return GL_UNSIGNED_INT;
break;
default:
break;
}
assert(0 && "Unable to convert TypeSpec -> GL type");
return GL_BYTE;
}
std::ostream& operator<<(std::ostream& out, const TypeSpec& spec)
{
if (spec.type == TypeSpec::Float)
{
const char* baseTypeStr = "";
switch (spec.elsize)
{
case 2: baseTypeStr = "half"; break;
case 4: baseTypeStr = "float"; break;
case 8: baseTypeStr = "double"; break;
default: baseTypeStr = "?"; assert(0); break;
}
tfm::format(out, "%s[%d]", baseTypeStr, spec.count);
return out;
}
const char* baseTypeStr = "";
switch (spec.type)
{
case TypeSpec::Int: baseTypeStr = "int"; break;
case TypeSpec::Uint: baseTypeStr = "uint"; break;
case TypeSpec::Unknown: baseTypeStr = "unknown"; break;
default: assert(0);
}
tfm::format(out, "%s%d_t[%d]", baseTypeStr, 8*spec.elsize, spec.count);
return out;
}