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

Last change on this file since 550 was 535, checked in by epyon, 8 years ago
  • unified pixel_format instead of image_format
File size: 15.1 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        case TEXTURE_1D_ARRAY       : return GL_TEXTURE_1D_ARRAY;
23        case TEXTURE_2D_ARRAY       : return GL_TEXTURE_2D_ARRAY;
24        case TEXTURE_1D_BUFFER      : return GL_TEXTURE_BUFFER;
25        case TEXTURE_2D_MULTISAMPLE : return GL_TEXTURE_2D_MULTISAMPLE;
26        NV_RETURN_COVERED_DEFAULT( 0 );
27        }
28}
29
30unsigned int nv::clear_state_buffers_to_mask( buffer_mask type )
31{
32        unsigned int mask = 0;
33        if ( (type & buffer_mask::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
34        if ( (type & buffer_mask::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
35        if ( (type & buffer_mask::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
36        return mask;
37}
38
39unsigned int nv::depth_state_function_to_enum( depth_test::function_type type )
40{
41        switch( type )
42        {
43        case depth_test::NEVER            : return GL_NEVER;
44        case depth_test::LESS             : return GL_LESS;
45        case depth_test::EQUAL            : return GL_EQUAL;
46        case depth_test::LESS_OR_EQUAL    : return GL_LEQUAL;
47        case depth_test::GREATER          : return GL_GREATER;
48        case depth_test::NOT_EQUAL        : return GL_NOTEQUAL;
49        case depth_test::GREATER_OR_EQUAL : return GL_GEQUAL;
50        case depth_test::ALWAYS           : return GL_ALWAYS;
51        NV_RETURN_COVERED_DEFAULT( 0 );
52        }
53}
54
55unsigned int nv::polygon_mode_fill_to_enum( polygon_mode::fill_type type )
56{
57        switch( type )
58        {
59        case polygon_mode::FILL           : return GL_FILL;
60        case polygon_mode::LINE           : return GL_LINE;
61        case polygon_mode::POINT          : return GL_POINT;
62        NV_RETURN_COVERED_DEFAULT( 0 );
63        }
64}
65
66
67
68unsigned int nv::blending_factor_to_enum( blending::factor type )
69{
70        switch( type )
71        {
72        case blending::ZERO                    : return GL_ZERO;
73        case blending::ONE                     : return GL_ONE;
74        case blending::SRC_COLOR               : return GL_SRC_COLOR;
75        case blending::ONE_MINUS_SRC_COLOR     : return GL_ONE_MINUS_SRC_COLOR;
76        case blending::DST_COLOR               : return GL_DST_COLOR;
77        case blending::ONE_MINUS_DST_COLOR     : return GL_ONE_MINUS_DST_COLOR;
78        case blending::SRC_ALPHA               : return GL_SRC_ALPHA;
79        case blending::ONE_MINUS_SRC_ALPHA     : return GL_ONE_MINUS_SRC_ALPHA;
80        case blending::DST_ALPHA               : return GL_DST_ALPHA;
81        case blending::ONE_MINUS_DST_ALPHA     : return GL_ONE_MINUS_DST_ALPHA;
82        case blending::CONSTANT_COLOR          : return GL_CONSTANT_COLOR;
83        case blending::ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR;
84        case blending::CONSTANT_ALPHA          : return GL_CONSTANT_ALPHA;
85        case blending::ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA;
86        case blending::SRC_ALPHA_SATURATE      : return GL_SRC_ALPHA_SATURATE;
87        NV_RETURN_COVERED_DEFAULT( 0 );
88        }
89}
90
91unsigned int nv::blending_equation_to_enum( blending::equation type )
92{
93        switch( type )
94        {
95        case blending::ADD              : return GL_FUNC_ADD;
96        case blending::SUBTRACT         : return GL_FUNC_SUBTRACT;
97        case blending::REVERSE_SUBTRACT : return GL_FUNC_REVERSE_SUBTRACT;
98        case blending::MINIMUM          : return GL_MIN;
99        case blending::MAXIMUM          : return GL_MAX;
100        NV_RETURN_COVERED_DEFAULT( 0 );
101        }
102}
103
104unsigned int nv::culling_face_type_to_enum( culling::face_type type )
105{
106        switch( type )
107        {
108        case culling::FRONT          : return GL_FRONT;
109        case culling::BACK           : return GL_BACK;
110        case culling::FRONT_AND_BACK : return GL_FRONT_AND_BACK;
111        NV_RETURN_COVERED_DEFAULT( 0 );
112        }
113}
114
115unsigned int nv::culling_order_type_to_enum( culling::order_type type )
116{
117        switch( type )
118        {
119        case culling::CW   : return GL_CW;
120        case culling::CCW  : return GL_CCW;
121        NV_RETURN_COVERED_DEFAULT( 0 );
122        }
123}
124
125unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
126{
127        switch( type )
128        {
129        case stencil_test_face::NEVER            : return GL_NEVER;
130        case stencil_test_face::LESS             : return GL_LESS;
131        case stencil_test_face::EQUAL            : return GL_EQUAL;
132        case stencil_test_face::LESS_OR_EQUAL    : return GL_LEQUAL;
133        case stencil_test_face::GREATER          : return GL_GREATER;
134        case stencil_test_face::NOT_EQUAL        : return GL_NOTEQUAL;
135        case stencil_test_face::GREATER_OR_EQUAL : return GL_GEQUAL;
136        case stencil_test_face::ALWAYS           : return GL_ALWAYS;
137        NV_RETURN_COVERED_DEFAULT( 0 );
138        }
139}
140
141unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
142{
143        switch( type )
144        {
145        case stencil_test_face::ZERO             : return GL_ZERO;
146        case stencil_test_face::INVERT           : return GL_INVERT;
147        case stencil_test_face::KEEP             : return GL_KEEP;
148        case stencil_test_face::REPLACE          : return GL_REPLACE;
149        case stencil_test_face::INCREMENT        : return GL_INCR;
150        case stencil_test_face::DECREMENT        : return GL_DECR;
151        case stencil_test_face::INCREMENT_WRAP   : return GL_INCR_WRAP;
152        case stencil_test_face::DECREMENT_WRAP   : return GL_DECR_WRAP;
153        NV_RETURN_COVERED_DEFAULT( 0 );
154        }
155}
156
157unsigned int nv::buffer_hint_to_enum( buffer_hint hint )
158{
159        switch( hint )
160        {
161        case STATIC_DRAW   : return GL_STATIC_DRAW;
162        case STREAM_DRAW   : return GL_STREAM_DRAW;
163        case DYNAMIC_DRAW  : return GL_DYNAMIC_DRAW;
164        NV_RETURN_COVERED_DEFAULT( 0 );
165        }
166}
167
168unsigned int nv::buffer_type_to_enum( buffer_type type )
169{
170        switch( type )
171        {
172        case VERTEX_BUFFER  : return GL_ARRAY_BUFFER;
173        case INDEX_BUFFER   : return GL_ELEMENT_ARRAY_BUFFER;
174        case UNIFORM_BUFFER : return GL_UNIFORM_BUFFER;
175        case TEXTURE_BUFFER : return GL_TEXTURE_BUFFER;
176                NV_RETURN_COVERED_DEFAULT( 0 );
177        }
178}
179
180unsigned int nv::image_format_to_enum( pixel_format format )
181{
182        switch( format )
183        {
184        case RGB8    : return GL_RGB;
185        case RGBA8   : return GL_RGBA;
186        case R8      : return GL_RED;
187        case RGB32F  : return GL_RGB;
188        case RGBA32F : return GL_RGBA;
189        case RGB16F  : return GL_RGB;
190        case RGBA16F : return GL_RGBA;
191        case BGR8    : return GL_BGR;
192        case BGRA8   : return GL_BGRA;
193        case R16F    : return GL_RED;
194        case R32F    : return GL_RED;
195        case DEPTH16 : return GL_DEPTH_COMPONENT;
196        case DEPTH24 : return GL_DEPTH_COMPONENT;
197        case DEPTH32 : return GL_DEPTH_COMPONENT;
198        case R8I     : return GL_RED_INTEGER;
199        case R8UI    : return GL_RED_INTEGER;
200        case R16I    : return GL_RED_INTEGER;
201        case R16UI   : return GL_RED_INTEGER;
202        case R32I    : return GL_RED_INTEGER;
203        case R32UI   : return GL_RED_INTEGER;
204        case RGBA8I  : return GL_RGBA_INTEGER;
205        case RGBA8UI : return GL_RGBA_INTEGER;
206        case RGBA16I : return GL_RGBA_INTEGER;
207        case RGBA16UI: return GL_RGBA_INTEGER;
208        case RGBA32I : return GL_RGBA_INTEGER;
209        case RGBA32UI: return GL_RGBA_INTEGER;
210        NV_RETURN_COVERED_DEFAULT( 0 );
211        }
212}
213
214unsigned int nv::image_format_to_internal_enum( pixel_format format )
215{
216        switch( format )
217        {
218        case RGB8    : return GL_RGB8;
219        case RGBA8   : return GL_RGBA8;
220        case R8      : return GL_R8;
221        case RGB32F  : return GL_RGB32F;
222        case RGBA32F : return GL_RGBA32F;
223        case RGB16F  : return GL_RGBA16F;
224        case RGBA16F : return GL_RGBA16F;
225        case BGR8    : return GL_RGB8;
226        case BGRA8   : return GL_RGBA8;
227        case R16F    : return GL_R16F;
228        case R32F    : return GL_R32F;
229        case DEPTH16 : return GL_DEPTH_COMPONENT16;
230        case DEPTH24 : return GL_DEPTH_COMPONENT24;
231        case DEPTH32 :  return GL_DEPTH_COMPONENT32;
232        case R8I     : return GL_R8I;
233        case R8UI    : return GL_R8UI;
234        case R16I    : return GL_R16I;
235        case R16UI   : return GL_R16UI;
236        case R32I    : return GL_R32I;
237        case R32UI   : return GL_R32UI;
238        case RGBA8I  : return GL_RGBA8I;
239        case RGBA8UI : return GL_RGBA8UI;
240        case RGBA16I : return GL_RGBA16I;
241        case RGBA16UI: return GL_RGBA16UI;
242        case RGBA32I : return GL_RGBA32I;
243        case RGBA32UI: return GL_RGBA32UI;
244
245        NV_RETURN_COVERED_DEFAULT( 0 );
246        }
247}
248
249
250unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
251{
252        switch( filter )
253        {
254        case sampler::LINEAR                 : return GL_LINEAR;
255        case sampler::NEAREST                : return GL_NEAREST;
256        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
257        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
258        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
259        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
260        NV_RETURN_COVERED_DEFAULT( 0 );
261        }
262}
263
264unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
265{
266        switch( wrap )
267        {
268        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
269        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
270        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
271        case sampler::REPEAT          : return GL_REPEAT;
272        NV_RETURN_COVERED_DEFAULT( 0 );
273        }
274}
275
276unsigned int nv::primitive_to_enum( primitive p )
277{
278        switch( p )
279        {
280        case POINTS         : return GL_POINTS;
281        case LINES          : return GL_LINES;
282        case LINE_LOOP      : return GL_LINE_LOOP;
283        case LINE_STRIP     : return GL_LINE_STRIP;
284        case TRIANGLES      : return GL_TRIANGLES;
285        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
286        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
287        NV_RETURN_COVERED_DEFAULT( 0 );
288        }
289}
290
291unsigned int nv::framebuffer_slot_to_enum( framebuffer_slot slot )
292{
293        switch( slot )
294        {
295        case READ_FRAMEBUFFER : return GL_READ_FRAMEBUFFER;
296        case DRAW_FRAMEBUFFER : return GL_DRAW_FRAMEBUFFER;
297        case FRAMEBUFFER      : return GL_FRAMEBUFFER;
298        NV_RETURN_COVERED_DEFAULT( 0 );
299        }
300}
301
302unsigned int nv::output_slot_to_enum( output_slot slot )
303{
304        switch( slot )
305        {
306        case OUTPUT_0 : return GL_COLOR_ATTACHMENT0;
307        case OUTPUT_1 : return GL_COLOR_ATTACHMENT1;
308        case OUTPUT_2 : return GL_COLOR_ATTACHMENT2;
309        case OUTPUT_3 : return GL_COLOR_ATTACHMENT3;
310        case OUTPUT_4 : return GL_COLOR_ATTACHMENT4;
311        case OUTPUT_5 : return GL_COLOR_ATTACHMENT5;
312        case OUTPUT_6 : return GL_COLOR_ATTACHMENT6;
313        case OUTPUT_7 : return GL_COLOR_ATTACHMENT7;
314        case OUTPUT_NONE  : return 0;
315        case OUTPUT_FRONT : return GL_FRONT;
316        case OUTPUT_BACK  : return GL_BACK;
317                NV_RETURN_COVERED_DEFAULT( 0 );
318        }
319}
320
321
322unsigned int nv::shader_type_to_enum( shader_type type )
323{
324        switch ( type )
325        {
326        case VERTEX_SHADER:   return GL_VERTEX_SHADER;
327        case FRAGMENT_SHADER: return GL_FRAGMENT_SHADER;
328                NV_RETURN_COVERED_DEFAULT( 0 );
329        }
330}
331
332unsigned int nv::buffer_access_to_bitfield( buffer_access type )
333{
334        switch ( type )
335        {
336        case WRITE_UNSYNCHRONIZED     : return GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
337        default: return 0; // TODO: throw!
338        }
339}
340
341unsigned int nv::datatype_to_gl_enum( datatype type )
342{
343        switch( type )
344        {
345        case BYTE           : return GL_BYTE;
346        case UBYTE          : return GL_UNSIGNED_BYTE;
347        case SHORT          : return GL_SHORT;
348        case USHORT         : return GL_UNSIGNED_SHORT;
349        case INT            : return GL_INT;
350        case UINT               : return GL_UNSIGNED_INT;
351        case FLOAT          : return GL_FLOAT;
352        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
353        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
354        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
355        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
356        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
357        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
358        case INT_VECTOR_2   : return GL_INT_VEC2;
359        case INT_VECTOR_3   : return GL_INT_VEC3;
360        case INT_VECTOR_4   : return GL_INT_VEC4;
361        // remove, error or ?
362        case BYTE_VECTOR_2  : return GL_INT_VEC2;
363        case BYTE_VECTOR_3  : return GL_INT_VEC3;
364        case BYTE_VECTOR_4  : return GL_INT_VEC4;
365                // remove, error or ?
366        case UBYTE_VECTOR_2: return GL_INT_VEC2;
367        case UBYTE_VECTOR_3: return GL_INT_VEC3;
368        case UBYTE_VECTOR_4: return GL_INT_VEC4;
369        default: return 0; // TODO: throw!
370        }
371}
372
373nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
374{
375        switch( gl_enum )
376        {
377        case GL_BYTE           : return BYTE;
378        case GL_UNSIGNED_BYTE  : return UBYTE;
379        case GL_SHORT          : return SHORT;
380        case GL_UNSIGNED_SHORT : return USHORT;
381        case GL_INT            : return INT;
382        case GL_UNSIGNED_INT   : return UINT;
383        case GL_FLOAT          : return FLOAT;
384        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
385        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
386        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
387        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
388        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
389        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
390        case GL_INT_VEC2       : return INT_VECTOR_2;
391        case GL_INT_VEC3       : return INT_VECTOR_3;
392        case GL_INT_VEC4       : return INT_VECTOR_4;
393// TODO: separate types?
394        case GL_SAMPLER_1D             : return INT;
395        case GL_SAMPLER_2D             : return INT;
396        case GL_SAMPLER_3D             : return INT;
397        case GL_SAMPLER_2D_RECT        : return INT;
398        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
399        case GL_SAMPLER_CUBE           : return INT;
400        case GL_SAMPLER_1D_SHADOW      : return INT;   
401        case GL_SAMPLER_2D_SHADOW      : return INT;
402        case GL_SAMPLER_1D_ARRAY       : return INT;
403        case GL_SAMPLER_2D_ARRAY       : return INT;
404        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
405        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
406        case GL_SAMPLER_BUFFER         : return INT;
407
408        case GL_INT_SAMPLER_1D                : return INT;
409        case GL_INT_SAMPLER_2D                : return INT;
410        case GL_INT_SAMPLER_3D                : return INT;
411        case GL_INT_SAMPLER_2D_RECT           : return INT;
412        case GL_INT_SAMPLER_CUBE              : return INT;
413        case GL_INT_SAMPLER_1D_ARRAY          : return INT;
414        case GL_INT_SAMPLER_2D_ARRAY          : return INT;
415        case GL_INT_SAMPLER_BUFFER            : return INT;
416        case GL_UNSIGNED_INT_SAMPLER_1D       : return INT;
417        case GL_UNSIGNED_INT_SAMPLER_2D       : return INT;
418        case GL_UNSIGNED_INT_SAMPLER_3D       : return INT;
419        case GL_UNSIGNED_INT_SAMPLER_2D_RECT  : return INT;
420        case GL_UNSIGNED_INT_SAMPLER_CUBE     : return INT;
421        case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : return INT;
422        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : return INT;
423        case GL_UNSIGNED_INT_SAMPLER_BUFFER   : return INT;
424                // TODO: implement?
425//      case GL_BOOL   
426//      case GL_BOOL_VEC2
427//      case GL_BOOL_VEC3
428//      case GL_BOOL_VEC4
429//      case GL_FLOAT_MAT2x3   
430//      case GL_FLOAT_MAT2x4   
431//      case GL_FLOAT_MAT3x2   
432//      case GL_FLOAT_MAT3x4   
433//      case GL_FLOAT_MAT4x2   
434//      case GL_FLOAT_MAT4x3   
435        default : return datatype(0); // TODO: throw!
436        }
437}
438
439string_view nv::datatype_to_glsl_type( datatype type )
440{
441        switch( type )
442        {
443        case INT            : return "int";
444        case FLOAT          : return "float";
445        case FLOAT_VECTOR_2 : return "vec2";
446        case FLOAT_VECTOR_3 : return "vec3";
447        case FLOAT_VECTOR_4 : return "vec4";
448        case FLOAT_MATRIX_2 : return "mat2";
449        case FLOAT_MATRIX_3 : return "mat3";
450        case FLOAT_MATRIX_4 : return "mat4";
451        case INT_VECTOR_2   : return "ivec2";
452        case INT_VECTOR_3   : return "ivec3";
453        case INT_VECTOR_4   : return "ivec4";
454        default : return "error";
455        }
456}
Note: See TracBrowser for help on using the repository browser.