All Classes Files Functions Variables Typedefs Pages
TexFormat.hpp
1 #pragma once
2 
3 #include "../util/half.hpp"
4 
5 #include <GL/glew.h>
6 #include <cstdint>
7 
8 namespace lumina {
9 
10 enum class TexFormat {
11  R8,
12  RGB8,
13  RGBA8,
14 
15  R16F,
16  RGB16F,
17  RGBA16F,
18 
19  R32F,
20  RGB32F,
21  RGBA32F,
22 
23  D16,
24  D32,
25  D24S8
26 };
27 
28 
29 template <TexFormat> struct TexFormatTrait;
30 
31 
32 #define X( \
33  format_, size_, components_, type_, glFormat_, glType_, glInternalFormat_) \
34  template <> struct TexFormatTrait<TexFormat::format_> { \
35  static constexpr int size = size_; \
36  static constexpr int components = components_; \
37  using type = type_; \
38  static constexpr GLenum glFormat = glFormat_; \
39  static constexpr GLenum glType = glType_; \
40  static constexpr GLint glInternalFormat = glInternalFormat_; \
41  };
42 
43 
44 X(R8, 1, 1, uint8_t, GL_RED, GL_UNSIGNED_BYTE, GL_R8)
45 X(RGB8, 3, 3, uint8_t, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8)
46 X(RGBA8, 4, 4, uint8_t, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8)
47 X(R16F, 2, 1, half, GL_RED, GL_HALF_FLOAT, GL_R16F)
48 X(RGB16F, 6, 3, half, GL_RGB, GL_HALF_FLOAT, GL_RGB16F)
49 X(RGBA16F, 8, 4, half, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F)
50 X(R32F, 4, 1, float, GL_RED, GL_FLOAT, GL_R32F)
51 X(RGB32F, 12, 3, float, GL_RGB, GL_FLOAT, GL_RGB32F)
52 X(RGBA32F, 16, 4, float, GL_RGBA, GL_FLOAT, GL_RGBA32F)
53 X(D16, 2, 1, void, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT16) // TODO: type
54 X(D32, 4, 1, void, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32)
55 X(D24S8, 4, 2, void, GL_DEPTH_STENCIL, GL_FLOAT, GL_DEPTH24_STENCIL8)
56 
57 #undef X
58 
59 
60 #define X(format_, prop_)\
61  case TexFormat::format_: return TexFormatTrait<TexFormat::format_>::prop_;
62 
63 #define Y(prop_)\
64  X(R8, prop_)\
65  X(RGB8, prop_)\
66  X(RGBA8, prop_)\
67  X(R16F, prop_)\
68  X(RGB16F, prop_)\
69  X(RGBA16F, prop_)\
70  X(R32F, prop_)\
71  X(RGB32F, prop_)\
72  X(RGBA32F, prop_)\
73  X(D16, prop_)\
74  X(D32, prop_)\
75  X(D24S8, prop_)
76 
77 inline GLenum texFormatToGLFormat(TexFormat format) {
78  switch(format) {
79  Y(glFormat);
80  }
81 }
82 
83 inline GLenum texFormatToGLType(TexFormat format) {
84  switch(format) {
85  Y(glType);
86  }
87 }
88 
89 inline GLint texFormatToGLInternalFormat(TexFormat format) {
90  switch(format) {
91  Y(glInternalFormat);
92  }
93 }
94 
95 inline int texFormatSize(TexFormat format) {
96  switch(format) {
97  Y(size);
98  }
99 }
100 
101 #undef Y
102 #undef X
103 
104 
105 } // namespace lumina
Definition: half.hpp:23
Definition: TexFormat.hpp:29