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

Last change on this file since 499 was 499, checked in by epyon, 9 years ago
  • ecs work
  • particle engine rehaul
  • added map/unmap buffer to ::context
File size: 14.4 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
[40]30unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type )
[35]31{
32        unsigned int mask = 0;
33        if ( (type & clear_state::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
34        if ( (type & clear_state::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
35        if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
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;
[121]204        NV_RETURN_COVERED_DEFAULT( 0 );
[43]205        }
206}
207
[331]208unsigned int nv::image_format_to_internal_enum( pixel_format format )
209{
210        switch( format )
211        {
[340]212        case RGB     : return GL_RGB8;
213        case RGBA    : return GL_RGBA8;
214        case RGB32F  : return GL_RGB32F;
215        case RGBA32F : return GL_RGBA32F;
216        case RGB16F  : return GL_RGBA16F;
217        case RGBA16F : return GL_RGBA16F;
[351]218        case BGR     : return GL_RGB8;
219        case BGRA    : return GL_RGBA8;
[472]220        case RED     : return GL_R8;
221        case R16F    : return GL_R16F;
222        case R32F    : return GL_R32F;
[462]223        case DEPTH16 : return GL_DEPTH_COMPONENT16;
224        case DEPTH24 : return GL_DEPTH_COMPONENT24;
225        case DEPTH32:  return GL_DEPTH_COMPONENT32;
[491]226        case R8I     : return GL_R8I;
227        case R8UI    : return GL_R8UI;
228        case R16I    : return GL_R16I;
229        case R16UI   : return GL_R16UI;
230        case R32I    : return GL_R32I;
231        case R32UI   : return GL_R32UI;
[340]232        NV_RETURN_COVERED_DEFAULT( 0 );
[331]233        }
234}
235
236
[49]237unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
[43]238{
239        switch( filter )
240        {
[49]241        case sampler::LINEAR                 : return GL_LINEAR;
242        case sampler::NEAREST                : return GL_NEAREST;
243        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
244        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
245        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
246        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
[121]247        NV_RETURN_COVERED_DEFAULT( 0 );
[43]248        }
249}
250
[49]251unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
[43]252{
253        switch( wrap )
254        {
[49]255        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
256        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
257        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
258        case sampler::REPEAT          : return GL_REPEAT;
[121]259        NV_RETURN_COVERED_DEFAULT( 0 );
[43]260        }
261}
262
[45]263unsigned int nv::primitive_to_enum( primitive p )
264{
265        switch( p )
266        {
267        case POINTS         : return GL_POINTS;
268        case LINES          : return GL_LINES;
269        case LINE_LOOP      : return GL_LINE_LOOP;
270        case LINE_STRIP     : return GL_LINE_STRIP;
271        case TRIANGLES      : return GL_TRIANGLES;
272        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
273        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
[121]274        NV_RETURN_COVERED_DEFAULT( 0 );
[45]275        }
276}
[43]277
[331]278unsigned int nv::framebuffer_slot_to_enum( framebuffer_slot slot )
279{
280        switch( slot )
281        {
282        case READ_FRAMEBUFFER : return GL_READ_FRAMEBUFFER;
283        case DRAW_FRAMEBUFFER : return GL_DRAW_FRAMEBUFFER;
284        case FRAMEBUFFER      : return GL_FRAMEBUFFER;
285        NV_RETURN_COVERED_DEFAULT( 0 );
286        }
287}
288
289unsigned int nv::output_slot_to_enum( output_slot slot )
290{
291        switch( slot )
292        {
293        case OUTPUT_0 : return GL_COLOR_ATTACHMENT0;
294        case OUTPUT_1 : return GL_COLOR_ATTACHMENT1;
295        case OUTPUT_2 : return GL_COLOR_ATTACHMENT2;
296        case OUTPUT_3 : return GL_COLOR_ATTACHMENT3;
297        case OUTPUT_4 : return GL_COLOR_ATTACHMENT4;
298        case OUTPUT_5 : return GL_COLOR_ATTACHMENT5;
299        case OUTPUT_6 : return GL_COLOR_ATTACHMENT6;
300        case OUTPUT_7 : return GL_COLOR_ATTACHMENT7;
301        case OUTPUT_NONE  : return 0;
302        case OUTPUT_FRONT : return GL_FRONT;
303        case OUTPUT_BACK  : return GL_BACK;
304                NV_RETURN_COVERED_DEFAULT( 0 );
305        }
306}
307
308
[499]309unsigned int nv::buffer_access_to_bitfield( buffer_access type )
310{
311        switch ( type )
312        {
313        case WRITE_UNSYNCHRONIZED     : return GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
314        default: return 0; // TODO: throw!
315        }
316}
317
[70]318unsigned int nv::datatype_to_gl_enum( datatype type )
[35]319{
320        switch( type )
321        {
[44]322        case BYTE           : return GL_BYTE;
323        case UBYTE          : return GL_UNSIGNED_BYTE;
324        case SHORT          : return GL_SHORT;
325        case USHORT         : return GL_UNSIGNED_SHORT;
326        case INT            : return GL_INT;
327        case UINT               : return GL_UNSIGNED_INT;
[35]328        case FLOAT          : return GL_FLOAT;
329        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
330        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
331        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
332        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
333        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
334        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
335        case INT_VECTOR_2   : return GL_INT_VEC2;
336        case INT_VECTOR_3   : return GL_INT_VEC3;
337        case INT_VECTOR_4   : return GL_INT_VEC4;
[68]338        // remove, error or ?
339        case BYTE_VECTOR_2  : return GL_INT_VEC2;
340        case BYTE_VECTOR_3  : return GL_INT_VEC3;
341        case BYTE_VECTOR_4  : return GL_INT_VEC4;
[350]342                // remove, error or ?
343        case UBYTE_VECTOR_2: return GL_INT_VEC2;
344        case UBYTE_VECTOR_3: return GL_INT_VEC3;
345        case UBYTE_VECTOR_4: return GL_INT_VEC4;
346        default: return 0; // TODO: throw!
[35]347        }
348}
349
[70]350nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
[35]351{
352        switch( gl_enum )
353        {
[44]354        case GL_BYTE           : return BYTE;
355        case GL_UNSIGNED_BYTE  : return UBYTE;
356        case GL_SHORT          : return SHORT;
357        case GL_UNSIGNED_SHORT : return USHORT;
358        case GL_INT            : return INT;
359        case GL_UNSIGNED_INT   : return UINT;
360        case GL_FLOAT          : return FLOAT;
361        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
362        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
363        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
364        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
365        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
366        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
367        case GL_INT_VEC2       : return INT_VECTOR_2;
368        case GL_INT_VEC3       : return INT_VECTOR_3;
369        case GL_INT_VEC4       : return INT_VECTOR_4;
[237]370// TODO: separate types?
[331]371        case GL_SAMPLER_1D             : return INT;
372        case GL_SAMPLER_2D             : return INT;
373        case GL_SAMPLER_3D             : return INT;
374        case GL_SAMPLER_2D_RECT        : return INT;
375        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
376        case GL_SAMPLER_CUBE           : return INT;
377        case GL_SAMPLER_1D_SHADOW      : return INT;   
378        case GL_SAMPLER_2D_SHADOW      : return INT;
[463]379        case GL_SAMPLER_1D_ARRAY       : return INT;
380        case GL_SAMPLER_2D_ARRAY       : return INT;
381        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
382        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
[491]383        case GL_SAMPLER_BUFFER         : return INT;
384
385        case GL_INT_SAMPLER_1D                : return INT;
386        case GL_INT_SAMPLER_2D                : return INT;
387        case GL_INT_SAMPLER_3D                : return INT;
388        case GL_INT_SAMPLER_2D_RECT           : return INT;
389        case GL_INT_SAMPLER_CUBE              : return INT;
390        case GL_INT_SAMPLER_1D_ARRAY          : return INT;
391        case GL_INT_SAMPLER_2D_ARRAY          : return INT;
392        case GL_INT_SAMPLER_BUFFER            : return INT;
393        case GL_UNSIGNED_INT_SAMPLER_1D       : return INT;
394        case GL_UNSIGNED_INT_SAMPLER_2D       : return INT;
395        case GL_UNSIGNED_INT_SAMPLER_3D       : return INT;
396        case GL_UNSIGNED_INT_SAMPLER_2D_RECT  : return INT;
397        case GL_UNSIGNED_INT_SAMPLER_CUBE     : return INT;
398        case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : return INT;
399        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : return INT;
400        case GL_UNSIGNED_INT_SAMPLER_BUFFER   : return INT;
[463]401                // TODO: implement?
[237]402//      case GL_BOOL   
403//      case GL_BOOL_VEC2
404//      case GL_BOOL_VEC3
405//      case GL_BOOL_VEC4
406//      case GL_FLOAT_MAT2x3   
407//      case GL_FLOAT_MAT2x4   
408//      case GL_FLOAT_MAT3x2   
409//      case GL_FLOAT_MAT3x4   
410//      case GL_FLOAT_MAT4x2   
411//      case GL_FLOAT_MAT4x3   
[70]412        default : return datatype(0); // TODO: throw!
[35]413        }
414}
[316]415
[438]416string_view nv::datatype_to_glsl_type( datatype type )
[316]417{
418        switch( type )
419        {
420        case INT            : return "int";
421        case FLOAT          : return "float";
422        case FLOAT_VECTOR_2 : return "vec2";
423        case FLOAT_VECTOR_3 : return "vec3";
424        case FLOAT_VECTOR_4 : return "vec4";
425        case FLOAT_MATRIX_2 : return "mat2";
426        case FLOAT_MATRIX_3 : return "mat3";
427        case FLOAT_MATRIX_4 : return "mat4";
428        case INT_VECTOR_2   : return "ivec2";
429        case INT_VECTOR_3   : return "ivec3";
430        case INT_VECTOR_4   : return "ivec4";
431        default : return "error";
432        }
433}
Note: See TracBrowser for help on using the repository browser.