source: trunk/src/gl/gl_enum.cc @ 462

Last change on this file since 462 was 462, checked in by epyon, 10 years ago
  • camera/device/uniform - modelview_inv added
  • image_data/context/texture/device/enum - DEPTH format support added
File size: 12.2 KB
Line 
1// Copyright (C) 2012-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7#include "nv/gl/gl_enum.hh"
8
9#include "nv/lib/gl.hh"
10
11using namespace nv;
12
13unsigned int nv::texture_type_to_enum( texture_type type )
14{
15        switch( type )
16        {
17        case TEXTURE_1D   : return GL_TEXTURE_1D;
18        case TEXTURE_2D   : return GL_TEXTURE_2D;
19        case TEXTURE_RECT : return GL_TEXTURE_RECTANGLE;
20        case TEXTURE_3D   : return GL_TEXTURE_3D;
21        case TEXTURE_CUBE : return GL_TEXTURE_CUBE_MAP;
22        NV_RETURN_COVERED_DEFAULT( 0 );
23        }
24}
25
26unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type )
27{
28        unsigned int mask = 0;
29        if ( (type & clear_state::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
30        if ( (type & clear_state::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
31        if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
32        return mask;
33}
34
35unsigned int nv::depth_state_function_to_enum( depth_test::function_type type )
36{
37        switch( type )
38        {
39        case depth_test::NEVER            : return GL_NEVER;
40        case depth_test::LESS             : return GL_LESS;
41        case depth_test::EQUAL            : return GL_EQUAL;
42        case depth_test::LESS_OR_EQUAL    : return GL_LEQUAL;
43        case depth_test::GREATER          : return GL_GREATER;
44        case depth_test::NOT_EQUAL        : return GL_NOTEQUAL;
45        case depth_test::GREATER_OR_EQUAL : return GL_GEQUAL;
46        case depth_test::ALWAYS           : return GL_ALWAYS;
47        NV_RETURN_COVERED_DEFAULT( 0 );
48        }
49}
50
51unsigned int nv::polygon_mode_fill_to_enum( polygon_mode::fill_type type )
52{
53        switch( type )
54        {
55        case polygon_mode::FILL           : return GL_FILL;
56        case polygon_mode::LINE           : return GL_LINE;
57        case polygon_mode::POINT          : return GL_POINT;
58        NV_RETURN_COVERED_DEFAULT( 0 );
59        }
60}
61
62
63
64unsigned int nv::blending_factor_to_enum( blending::factor type )
65{
66        switch( type )
67        {
68        case blending::ZERO                    : return GL_ZERO;
69        case blending::ONE                     : return GL_ONE;
70        case blending::SRC_COLOR               : return GL_SRC_COLOR;
71        case blending::ONE_MINUS_SRC_COLOR     : return GL_ONE_MINUS_SRC_COLOR;
72        case blending::DST_COLOR               : return GL_DST_COLOR;
73        case blending::ONE_MINUS_DST_COLOR     : return GL_ONE_MINUS_DST_COLOR;
74        case blending::SRC_ALPHA               : return GL_SRC_ALPHA;
75        case blending::ONE_MINUS_SRC_ALPHA     : return GL_ONE_MINUS_SRC_ALPHA;
76        case blending::DST_ALPHA               : return GL_DST_ALPHA;
77        case blending::ONE_MINUS_DST_ALPHA     : return GL_ONE_MINUS_DST_ALPHA;
78        case blending::CONSTANT_COLOR          : return GL_CONSTANT_COLOR;
79        case blending::ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR;
80        case blending::CONSTANT_ALPHA          : return GL_CONSTANT_ALPHA;
81        case blending::ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA;
82        case blending::SRC_ALPHA_SATURATE      : return GL_SRC_ALPHA_SATURATE;
83        NV_RETURN_COVERED_DEFAULT( 0 );
84        }
85}
86
87unsigned int nv::blending_equation_to_enum( blending::equation type )
88{
89        switch( type )
90        {
91        case blending::ADD              : return GL_FUNC_ADD;
92        case blending::SUBTRACT         : return GL_FUNC_SUBTRACT;
93        case blending::REVERSE_SUBTRACT : return GL_FUNC_REVERSE_SUBTRACT;
94        case blending::MINIMUM          : return GL_MIN;
95        case blending::MAXIMUM          : return GL_MAX;
96        NV_RETURN_COVERED_DEFAULT( 0 );
97        }
98}
99
100unsigned int nv::culling_face_type_to_enum( culling::face_type type )
101{
102        switch( type )
103        {
104        case culling::FRONT          : return GL_FRONT;
105        case culling::BACK           : return GL_BACK;
106        case culling::FRONT_AND_BACK : return GL_FRONT_AND_BACK;
107        NV_RETURN_COVERED_DEFAULT( 0 );
108        }
109}
110
111unsigned int nv::culling_order_type_to_enum( culling::order_type type )
112{
113        switch( type )
114        {
115        case culling::CW   : return GL_CW;
116        case culling::CCW  : return GL_CCW;
117        NV_RETURN_COVERED_DEFAULT( 0 );
118        }
119}
120
121unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
122{
123        switch( type )
124        {
125        case stencil_test_face::NEVER            : return GL_NEVER;
126        case stencil_test_face::LESS             : return GL_LESS;
127        case stencil_test_face::EQUAL            : return GL_EQUAL;
128        case stencil_test_face::LESS_OR_EQUAL    : return GL_LEQUAL;
129        case stencil_test_face::GREATER          : return GL_GREATER;
130        case stencil_test_face::NOT_EQUAL        : return GL_NOTEQUAL;
131        case stencil_test_face::GREATER_OR_EQUAL : return GL_GEQUAL;
132        case stencil_test_face::ALWAYS           : return GL_ALWAYS;
133        NV_RETURN_COVERED_DEFAULT( 0 );
134        }
135}
136
137unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
138{
139        switch( type )
140        {
141        case stencil_test_face::ZERO             : return GL_ZERO;
142        case stencil_test_face::INVERT           : return GL_INVERT;
143        case stencil_test_face::KEEP             : return GL_KEEP;
144        case stencil_test_face::REPLACE          : return GL_REPLACE;
145        case stencil_test_face::INCREMENT        : return GL_INCR;
146        case stencil_test_face::DECREMENT        : return GL_DECR;
147        case stencil_test_face::INCREMENT_WRAP   : return GL_INCR_WRAP;
148        case stencil_test_face::DECREMENT_WRAP   : return GL_DECR_WRAP;
149        NV_RETURN_COVERED_DEFAULT( 0 );
150        }
151}
152
153unsigned int nv::buffer_hint_to_enum( buffer_hint hint )
154{
155        switch( hint )
156        {
157        case STATIC_DRAW   : return GL_STATIC_DRAW;
158        case STREAM_DRAW   : return GL_STREAM_DRAW;
159        case DYNAMIC_DRAW  : return GL_DYNAMIC_DRAW;
160        NV_RETURN_COVERED_DEFAULT( 0 );
161        }
162}
163
164unsigned int nv::buffer_type_to_enum( buffer_type type )
165{
166        switch( type )
167        {
168        case VERTEX_BUFFER : return GL_ARRAY_BUFFER;
169        case INDEX_BUFFER  : return GL_ELEMENT_ARRAY_BUFFER;
170                NV_RETURN_COVERED_DEFAULT( 0 );
171        }
172}
173
174unsigned int nv::image_format_to_enum( pixel_format format )
175{
176        switch( format )
177        {
178        case RGB     : return GL_RGB;
179        case RGBA    : return GL_RGBA;
180        case RGB32F  : return GL_RGB;
181        case RGBA32F : return GL_RGBA;
182        case RGB16F  : return GL_RGB;
183        case RGBA16F : return GL_RGBA;
184        case BGR     : return GL_BGR;
185        case BGRA    : return GL_BGRA;
186        case RED     : return GL_RED;
187        case DEPTH16 : return GL_DEPTH_COMPONENT;
188        case DEPTH24 : return GL_DEPTH_COMPONENT;
189        case DEPTH32 : return GL_DEPTH_COMPONENT;
190        NV_RETURN_COVERED_DEFAULT( 0 );
191        }
192}
193
194unsigned int nv::image_format_to_internal_enum( pixel_format format )
195{
196        switch( format )
197        {
198        case RGB     : return GL_RGB8;
199        case RGBA    : return GL_RGBA8;
200        case RGB32F  : return GL_RGB32F;
201        case RGBA32F : return GL_RGBA32F;
202        case RGB16F  : return GL_RGBA16F;
203        case RGBA16F : return GL_RGBA16F;
204        case BGR     : return GL_RGB8;
205        case BGRA    : return GL_RGBA8;
206        case RED     : return 0x8040; // GL_LUMINANCE8; // TODO: change to GL_R8!
207        case DEPTH16 : return GL_DEPTH_COMPONENT16;
208        case DEPTH24 : return GL_DEPTH_COMPONENT24;
209        case DEPTH32:  return GL_DEPTH_COMPONENT32;
210        NV_RETURN_COVERED_DEFAULT( 0 );
211        }
212}
213
214
215unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
216{
217        switch( filter )
218        {
219        case sampler::LINEAR                 : return GL_LINEAR;
220        case sampler::NEAREST                : return GL_NEAREST;
221        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
222        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
223        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
224        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
225        NV_RETURN_COVERED_DEFAULT( 0 );
226        }
227}
228
229unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
230{
231        switch( wrap )
232        {
233        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
234        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
235        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
236        case sampler::REPEAT          : return GL_REPEAT;
237        NV_RETURN_COVERED_DEFAULT( 0 );
238        }
239}
240
241unsigned int nv::primitive_to_enum( primitive p )
242{
243        switch( p )
244        {
245        case POINTS         : return GL_POINTS;
246        case LINES          : return GL_LINES;
247        case LINE_LOOP      : return GL_LINE_LOOP;
248        case LINE_STRIP     : return GL_LINE_STRIP;
249        case TRIANGLES      : return GL_TRIANGLES;
250        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
251        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
252        NV_RETURN_COVERED_DEFAULT( 0 );
253        }
254}
255
256unsigned int nv::framebuffer_slot_to_enum( framebuffer_slot slot )
257{
258        switch( slot )
259        {
260        case READ_FRAMEBUFFER : return GL_READ_FRAMEBUFFER;
261        case DRAW_FRAMEBUFFER : return GL_DRAW_FRAMEBUFFER;
262        case FRAMEBUFFER      : return GL_FRAMEBUFFER;
263        NV_RETURN_COVERED_DEFAULT( 0 );
264        }
265}
266
267
268unsigned int nv::output_slot_to_enum( output_slot slot )
269{
270        switch( slot )
271        {
272        case OUTPUT_0 : return GL_COLOR_ATTACHMENT0;
273        case OUTPUT_1 : return GL_COLOR_ATTACHMENT1;
274        case OUTPUT_2 : return GL_COLOR_ATTACHMENT2;
275        case OUTPUT_3 : return GL_COLOR_ATTACHMENT3;
276        case OUTPUT_4 : return GL_COLOR_ATTACHMENT4;
277        case OUTPUT_5 : return GL_COLOR_ATTACHMENT5;
278        case OUTPUT_6 : return GL_COLOR_ATTACHMENT6;
279        case OUTPUT_7 : return GL_COLOR_ATTACHMENT7;
280        case OUTPUT_NONE  : return 0;
281        case OUTPUT_FRONT : return GL_FRONT;
282        case OUTPUT_BACK  : return GL_BACK;
283                NV_RETURN_COVERED_DEFAULT( 0 );
284        }
285}
286
287
288unsigned int nv::datatype_to_gl_enum( datatype type )
289{
290        switch( type )
291        {
292        case BYTE           : return GL_BYTE;
293        case UBYTE          : return GL_UNSIGNED_BYTE;
294        case SHORT          : return GL_SHORT;
295        case USHORT         : return GL_UNSIGNED_SHORT;
296        case INT            : return GL_INT;
297        case UINT               : return GL_UNSIGNED_INT;
298        case FLOAT          : return GL_FLOAT;
299        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
300        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
301        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
302        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
303        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
304        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
305        case INT_VECTOR_2   : return GL_INT_VEC2;
306        case INT_VECTOR_3   : return GL_INT_VEC3;
307        case INT_VECTOR_4   : return GL_INT_VEC4;
308        // remove, error or ?
309        case BYTE_VECTOR_2  : return GL_INT_VEC2;
310        case BYTE_VECTOR_3  : return GL_INT_VEC3;
311        case BYTE_VECTOR_4  : return GL_INT_VEC4;
312                // remove, error or ?
313        case UBYTE_VECTOR_2: return GL_INT_VEC2;
314        case UBYTE_VECTOR_3: return GL_INT_VEC3;
315        case UBYTE_VECTOR_4: return GL_INT_VEC4;
316        default: return 0; // TODO: throw!
317        }
318}
319
320nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
321{
322        switch( gl_enum )
323        {
324        case GL_BYTE           : return BYTE;
325        case GL_UNSIGNED_BYTE  : return UBYTE;
326        case GL_SHORT          : return SHORT;
327        case GL_UNSIGNED_SHORT : return USHORT;
328        case GL_INT            : return INT;
329        case GL_UNSIGNED_INT   : return UINT;
330        case GL_FLOAT          : return FLOAT;
331        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
332        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
333        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
334        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
335        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
336        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
337        case GL_INT_VEC2       : return INT_VECTOR_2;
338        case GL_INT_VEC3       : return INT_VECTOR_3;
339        case GL_INT_VEC4       : return INT_VECTOR_4;
340// TODO: separate types?
341        case GL_SAMPLER_1D             : return INT;
342        case GL_SAMPLER_2D             : return INT;
343        case GL_SAMPLER_3D             : return INT;
344        case GL_SAMPLER_2D_RECT        : return INT;
345        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
346        case GL_SAMPLER_CUBE           : return INT;
347        case GL_SAMPLER_1D_SHADOW      : return INT;   
348        case GL_SAMPLER_2D_SHADOW      : return INT;
349// TODO: implement?
350//      case GL_BOOL   
351//      case GL_BOOL_VEC2
352//      case GL_BOOL_VEC3
353//      case GL_BOOL_VEC4
354//      case GL_FLOAT_MAT2x3   
355//      case GL_FLOAT_MAT2x4   
356//      case GL_FLOAT_MAT3x2   
357//      case GL_FLOAT_MAT3x4   
358//      case GL_FLOAT_MAT4x2   
359//      case GL_FLOAT_MAT4x3   
360        default : return datatype(0); // TODO: throw!
361        }
362}
363
364string_view nv::datatype_to_glsl_type( datatype type )
365{
366        switch( type )
367        {
368        case INT            : return "int";
369        case FLOAT          : return "float";
370        case FLOAT_VECTOR_2 : return "vec2";
371        case FLOAT_VECTOR_3 : return "vec3";
372        case FLOAT_VECTOR_4 : return "vec4";
373        case FLOAT_MATRIX_2 : return "mat2";
374        case FLOAT_MATRIX_3 : return "mat3";
375        case FLOAT_MATRIX_4 : return "mat4";
376        case INT_VECTOR_2   : return "ivec2";
377        case INT_VECTOR_3   : return "ivec3";
378        case INT_VECTOR_4   : return "ivec4";
379        default : return "error";
380        }
381}
Note: See TracBrowser for help on using the repository browser.