forked from funkey/gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenGlTraits.h
108 lines (72 loc) · 1.83 KB
/
OpenGlTraits.h
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
#ifndef OPENGL_TRAITS_H__
#define OPENGL_TRAITS_H__
#include <boost/array.hpp>
#include <config.h>
#ifdef HAVE_VIGRA
#include <vigra/stdimage.hxx>
#endif
#ifdef HAVE_CAIRO
#include <gui/Cairo.h>
#endif
namespace gui {
namespace detail {
/**
* Data type traits. Finds the corresponding OpenGl data type to a pixel value
* type.
*/
// default
template <typename DataType>
struct pixel_type_traits {
};
template <>
struct pixel_type_traits<unsigned char> {
enum { gl_type = GL_UNSIGNED_BYTE };
};
template <>
struct pixel_type_traits<double> {
// OpenGl does not support that -- consider using converter<float> on your
// image
};
template <>
struct pixel_type_traits<float> {
enum { gl_type = GL_FLOAT };
};
/**
* Pixel type traits. Finds the corresponding OpenGl pixel type to a various
* pixel types.
*/
// default: GL_LUMINANCE
template <typename PixelType>
struct pixel_format_traits {
typedef PixelType value_type;
enum { gl_format = GL_LUMINANCE };
enum { gl_type = pixel_type_traits<value_type>::gl_type };
};
#ifdef HAVE_VIGRA
// specialisation: GL_RGB
template <typename ValueType>
struct pixel_format_traits<vigra::RGBValue<ValueType> > {
typedef ValueType value_type;
enum { gl_format = GL_RGB };
enum { gl_type = pixel_type_traits<value_type>::gl_type };
};
#endif
#ifdef HAVE_CAIRO
// specialisation: GL_BGRA
template <>
struct pixel_format_traits<cairo_pixel_t> {
typedef unsigned char value_type;
enum { gl_format = GL_BGRA };
enum { gl_type = GL_UNSIGNED_BYTE };
};
#endif
// specialisation: boost::array<???, 4>
template <typename ValueType>
struct pixel_format_traits<boost::array<ValueType, 4> > {
typedef ValueType value_type;
enum { gl_format = GL_RGBA };
enum { gl_type = pixel_type_traits<value_type>::gl_type };
};
} // namspace detail
} // namespace gui
#endif // OPENGL_TRAITS_H__