]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_texture_format.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_texture_format.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 // File: vogl_texture_format.h
27 #ifndef VOGL_TEXTURE_FORMAT_H
28 #define VOGL_TEXTURE_FORMAT_H
29
30 // Corresponds to glTexImage1D/2D/3D/2DMultisample/3DMultisample API calls
31 enum vogl_tex_image_types
32 {
33     cTIT1D,
34     cTIT2D,
35     cTIT3D,
36     cTIT2DMultisample,
37     cTIT3DMultisample,
38     cTITTotalTypes
39 };
40
41 enum vogl_tex_components
42 {
43     cTCRed,
44     cTCGreen,
45     cTCBlue,
46     cTCAlpha,
47     cTCDepth,
48     cTCStencil,
49     cTCIntensity,
50     cTCLuminance,
51     cTCTotalComponents
52 };
53
54 struct vogl_internal_tex_format
55 {
56     GLenum m_fmt;
57     GLenum m_actual_internal_fmt;
58     dynamic_string m_name;
59     int m_comp_sizes[cTCTotalComponents];
60     GLenum m_comp_types[cTCTotalComponents];
61     int m_shared_size;
62
63     // Bitmask of vogl_tex_image_types's - indicates which glTexImage API's are valid to use with this internal format.
64     uint m_tex_image_flags;
65
66     GLenum m_optimum_get_image_fmt;
67     GLenum m_optimum_get_image_type;
68     // 0 for compressed formats, otherwise this is the number of bytes per pixel written by the get_fmt/get_type (NOT the internal format)
69     uint8 m_image_bytes_per_pixel_or_block;
70     uint8 m_block_width;
71     uint8 m_block_height;
72     bool m_compressed;
73
74     vogl_internal_tex_format()
75     {
76         VOGL_FUNC_TRACER utils::zero_object(*this);
77     }
78
79     vogl_internal_tex_format(
80         GLenum fmt, const char *pName, GLenum actual_fmt,
81         int s0, int s1, int s2, int s3, int s4, int s5, int s6, int s7,
82         GLenum t0, GLenum t1, GLenum t2, GLenum t3, GLenum t4, GLenum t5, GLenum t6, GLenum t7,
83         int shared_size, int tex_storage_type_flags, bool compressed, GLenum optimum_get_fmt, GLenum optimum_get_type,
84         uint image_bytes_per_pixel_or_block, uint block_width, uint block_height);
85
86     inline uint get_max_comp_size() const
87     {
88         uint n = 0;
89         for (uint i = 0; i < cTCTotalComponents; i++)
90             n = math::maximum<uint>(n, m_comp_sizes[i]);
91         return n;
92     }
93     inline uint get_total_comps() const
94     {
95         uint n = 0;
96         for (uint i = 0; i < cTCTotalComponents; i++)
97             if (m_comp_sizes[i])
98                 n++;
99         return n;
100     }
101     inline GLenum get_first_comp_type() const
102     {
103         for (uint i = 0; i < cTCTotalComponents; i++)
104             if (m_comp_sizes[i])
105                 return m_comp_types[i];
106         return GL_NONE;
107     }
108
109     // Deep equality comparison
110     bool compare(const vogl_internal_tex_format &rhs) const;
111
112     // Shallow sort comparisons
113     inline bool operator==(const vogl_internal_tex_format &rhs) const
114     {
115         return m_name.compare(rhs.m_name, true) == 0;
116     }
117     inline bool operator<(const vogl_internal_tex_format &rhs) const
118     {
119         return m_name.compare(rhs.m_name, true) < 0;
120     }
121 };
122
123 extern vogl_internal_tex_format g_vogl_internal_texture_formats[];
124 extern uint g_vogl_total_internal_texture_formats;
125
126 void vogl_devel_dump_internal_texture_formats(const vogl_context_info &context_info);
127
128 void vogl_texture_format_init();
129 const vogl_internal_tex_format *vogl_find_internal_texture_format(GLenum internal_format);
130
131 #endif // VOGL_TEXTURE_FORMAT_H