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

Last change on this file since 503 was 503, checked in by epyon, 9 years ago
  • nv::random - support for different rng sources
  • nv::types - fixes and better support
  • nv::mesh_creator - full range transform
  • nv::context - buffer mask as separate type
  • nv::lua - initializations from lua::state instead of lua_State
  • nv::lua - initial support for rtti
File size: 14.8 KB
RevLine 
[395]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.
[35]6
7#include "nv/gl/gl_enum.hh"
8
9#include "nv/lib/gl.hh"
10
11using namespace nv;
12
[331]13unsigned int nv::texture_type_to_enum( texture_type type )
14{
15        switch( type )
16        {
[492]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;
[331]26        NV_RETURN_COVERED_DEFAULT( 0 );
27        }
28}
29
[503]30unsigned int nv::clear_state_buffers_to_mask( buffer_mask type )
[35]31{
32        unsigned int mask = 0;
[503]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;
[35]36        return mask;
37}
38
[40]39unsigned int nv::depth_state_function_to_enum( depth_test::function_type type )
[35]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;
[121]51        NV_RETURN_COVERED_DEFAULT( 0 );
[35]52        }
53}
54
[233]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
[40]68unsigned int nv::blending_factor_to_enum( blending::factor type )
[35]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;
[121]87        NV_RETURN_COVERED_DEFAULT( 0 );
[35]88        }
89}
90
[40]91unsigned int nv::blending_equation_to_enum( blending::equation type )
[35]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;
[121]100        NV_RETURN_COVERED_DEFAULT( 0 );
[35]101        }
102}
103
[40]104unsigned int nv::culling_face_type_to_enum( culling::face_type type )
[35]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;
[121]111        NV_RETURN_COVERED_DEFAULT( 0 );
[35]112        }
113}
114
[40]115unsigned int nv::culling_order_type_to_enum( culling::order_type type )
[35]116{
117        switch( type )
118        {
119        case culling::CW   : return GL_CW;
120        case culling::CCW  : return GL_CCW;
[121]121        NV_RETURN_COVERED_DEFAULT( 0 );
[35]122        }
123}
124
[40]125unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
[35]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;
[121]137        NV_RETURN_COVERED_DEFAULT( 0 );
[35]138        }
139}
140
[40]141unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
[35]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;
[121]153        NV_RETURN_COVERED_DEFAULT( 0 );
[35]154        }
155}
156
[42]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;
[121]164        NV_RETURN_COVERED_DEFAULT( 0 );
[42]165        }
166}
167
[302]168unsigned int nv::buffer_type_to_enum( buffer_type type )
169{
170        switch( type )
171        {
[473]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;
[491]175        case TEXTURE_BUFFER : return GL_TEXTURE_BUFFER;
[302]176                NV_RETURN_COVERED_DEFAULT( 0 );
177        }
178}
179
[292]180unsigned int nv::image_format_to_enum( pixel_format format )
[43]181{
182        switch( format )
183        {
[340]184        case RGB     : return GL_RGB;
185        case RGBA    : return GL_RGBA;
186        case RGB32F  : return GL_RGB;
187        case RGBA32F : return GL_RGBA;
188        case RGB16F  : return GL_RGB;
189        case RGBA16F : return GL_RGBA;
[351]190        case BGR     : return GL_BGR;
191        case BGRA    : return GL_BGRA;
[461]192        case RED     : return GL_RED;
[472]193        case R16F    : return GL_RED;
194        case R32F    : return GL_RED;
[462]195        case DEPTH16 : return GL_DEPTH_COMPONENT;
196        case DEPTH24 : return GL_DEPTH_COMPONENT;
197        case DEPTH32 : return GL_DEPTH_COMPONENT;
[491]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;
[500]204        case RGBA8I  : return GL_RGBA;
205        case RGBA8UI : return GL_RGBA;
206        case RGBA16I : return GL_RGBA;
207        case RGBA16UI: return GL_RGBA;
208        case RGBA32I : return GL_RGBA;
209        case RGBA32UI: return GL_RGBA;
[121]210        NV_RETURN_COVERED_DEFAULT( 0 );
[43]211        }
212}
213
[331]214unsigned int nv::image_format_to_internal_enum( pixel_format format )
215{
216        switch( format )
217        {
[340]218        case RGB     : return GL_RGB8;
219        case RGBA    : return GL_RGBA8;
220        case RGB32F  : return GL_RGB32F;
221        case RGBA32F : return GL_RGBA32F;
222        case RGB16F  : return GL_RGBA16F;
223        case RGBA16F : return GL_RGBA16F;
[351]224        case BGR     : return GL_RGB8;
225        case BGRA    : return GL_RGBA8;
[472]226        case RED     : return GL_R8;
227        case R16F    : return GL_R16F;
228        case R32F    : return GL_R32F;
[462]229        case DEPTH16 : return GL_DEPTH_COMPONENT16;
230        case DEPTH24 : return GL_DEPTH_COMPONENT24;
231        case DEPTH32:  return GL_DEPTH_COMPONENT32;
[491]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;
[500]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
[340]245        NV_RETURN_COVERED_DEFAULT( 0 );
[331]246        }
247}
248
249
[49]250unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
[43]251{
252        switch( filter )
253        {
[49]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;
[121]260        NV_RETURN_COVERED_DEFAULT( 0 );
[43]261        }
262}
263
[49]264unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
[43]265{
266        switch( wrap )
267        {
[49]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;
[121]272        NV_RETURN_COVERED_DEFAULT( 0 );
[43]273        }
274}
275
[45]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;
[121]287        NV_RETURN_COVERED_DEFAULT( 0 );
[45]288        }
289}
[43]290
[331]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
[499]322unsigned int nv::buffer_access_to_bitfield( buffer_access type )
323{
324        switch ( type )
325        {
326        case WRITE_UNSYNCHRONIZED     : return GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
327        default: return 0; // TODO: throw!
328        }
329}
330
[70]331unsigned int nv::datatype_to_gl_enum( datatype type )
[35]332{
333        switch( type )
334        {
[44]335        case BYTE           : return GL_BYTE;
336        case UBYTE          : return GL_UNSIGNED_BYTE;
337        case SHORT          : return GL_SHORT;
338        case USHORT         : return GL_UNSIGNED_SHORT;
339        case INT            : return GL_INT;
340        case UINT               : return GL_UNSIGNED_INT;
[35]341        case FLOAT          : return GL_FLOAT;
342        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
343        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
344        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
345        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
346        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
347        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
348        case INT_VECTOR_2   : return GL_INT_VEC2;
349        case INT_VECTOR_3   : return GL_INT_VEC3;
350        case INT_VECTOR_4   : return GL_INT_VEC4;
[68]351        // remove, error or ?
352        case BYTE_VECTOR_2  : return GL_INT_VEC2;
353        case BYTE_VECTOR_3  : return GL_INT_VEC3;
354        case BYTE_VECTOR_4  : return GL_INT_VEC4;
[350]355                // remove, error or ?
356        case UBYTE_VECTOR_2: return GL_INT_VEC2;
357        case UBYTE_VECTOR_3: return GL_INT_VEC3;
358        case UBYTE_VECTOR_4: return GL_INT_VEC4;
359        default: return 0; // TODO: throw!
[35]360        }
361}
362
[70]363nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
[35]364{
365        switch( gl_enum )
366        {
[44]367        case GL_BYTE           : return BYTE;
368        case GL_UNSIGNED_BYTE  : return UBYTE;
369        case GL_SHORT          : return SHORT;
370        case GL_UNSIGNED_SHORT : return USHORT;
371        case GL_INT            : return INT;
372        case GL_UNSIGNED_INT   : return UINT;
373        case GL_FLOAT          : return FLOAT;
374        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
375        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
376        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
377        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
378        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
379        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
380        case GL_INT_VEC2       : return INT_VECTOR_2;
381        case GL_INT_VEC3       : return INT_VECTOR_3;
382        case GL_INT_VEC4       : return INT_VECTOR_4;
[237]383// TODO: separate types?
[331]384        case GL_SAMPLER_1D             : return INT;
385        case GL_SAMPLER_2D             : return INT;
386        case GL_SAMPLER_3D             : return INT;
387        case GL_SAMPLER_2D_RECT        : return INT;
388        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
389        case GL_SAMPLER_CUBE           : return INT;
390        case GL_SAMPLER_1D_SHADOW      : return INT;   
391        case GL_SAMPLER_2D_SHADOW      : return INT;
[463]392        case GL_SAMPLER_1D_ARRAY       : return INT;
393        case GL_SAMPLER_2D_ARRAY       : return INT;
394        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
395        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
[491]396        case GL_SAMPLER_BUFFER         : return INT;
397
398        case GL_INT_SAMPLER_1D                : return INT;
399        case GL_INT_SAMPLER_2D                : return INT;
400        case GL_INT_SAMPLER_3D                : return INT;
401        case GL_INT_SAMPLER_2D_RECT           : return INT;
402        case GL_INT_SAMPLER_CUBE              : return INT;
403        case GL_INT_SAMPLER_1D_ARRAY          : return INT;
404        case GL_INT_SAMPLER_2D_ARRAY          : return INT;
405        case GL_INT_SAMPLER_BUFFER            : return INT;
406        case GL_UNSIGNED_INT_SAMPLER_1D       : return INT;
407        case GL_UNSIGNED_INT_SAMPLER_2D       : return INT;
408        case GL_UNSIGNED_INT_SAMPLER_3D       : return INT;
409        case GL_UNSIGNED_INT_SAMPLER_2D_RECT  : return INT;
410        case GL_UNSIGNED_INT_SAMPLER_CUBE     : return INT;
411        case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : return INT;
412        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : return INT;
413        case GL_UNSIGNED_INT_SAMPLER_BUFFER   : return INT;
[463]414                // TODO: implement?
[237]415//      case GL_BOOL   
416//      case GL_BOOL_VEC2
417//      case GL_BOOL_VEC3
418//      case GL_BOOL_VEC4
419//      case GL_FLOAT_MAT2x3   
420//      case GL_FLOAT_MAT2x4   
421//      case GL_FLOAT_MAT3x2   
422//      case GL_FLOAT_MAT3x4   
423//      case GL_FLOAT_MAT4x2   
424//      case GL_FLOAT_MAT4x3   
[70]425        default : return datatype(0); // TODO: throw!
[35]426        }
427}
[316]428
[438]429string_view nv::datatype_to_glsl_type( datatype type )
[316]430{
431        switch( type )
432        {
433        case INT            : return "int";
434        case FLOAT          : return "float";
435        case FLOAT_VECTOR_2 : return "vec2";
436        case FLOAT_VECTOR_3 : return "vec3";
437        case FLOAT_VECTOR_4 : return "vec4";
438        case FLOAT_MATRIX_2 : return "mat2";
439        case FLOAT_MATRIX_3 : return "mat3";
440        case FLOAT_MATRIX_4 : return "mat4";
441        case INT_VECTOR_2   : return "ivec2";
442        case INT_VECTOR_3   : return "ivec3";
443        case INT_VECTOR_4   : return "ivec4";
444        default : return "error";
445        }
446}
Note: See TracBrowser for help on using the repository browser.