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

Last change on this file since 493 was 492, checked in by epyon, 9 years ago
File size: 14.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        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( clear_state::buffers_type type )
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
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 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;
190        case BGR     : return GL_BGR;
191        case BGRA    : return GL_BGRA;
192        case RED     : return GL_RED;
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        NV_RETURN_COVERED_DEFAULT( 0 );
205        }
206}
207
208unsigned int nv::image_format_to_internal_enum( pixel_format format )
209{
210        switch( format )
211        {
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;
218        case BGR     : return GL_RGB8;
219        case BGRA    : return GL_RGBA8;
220        case RED     : return GL_R8;
221        case R16F    : return GL_R16F;
222        case R32F    : return GL_R32F;
223        case DEPTH16 : return GL_DEPTH_COMPONENT16;
224        case DEPTH24 : return GL_DEPTH_COMPONENT24;
225        case DEPTH32:  return GL_DEPTH_COMPONENT32;
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;
232        NV_RETURN_COVERED_DEFAULT( 0 );
233        }
234}
235
236
237unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
238{
239        switch( filter )
240        {
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;
247        NV_RETURN_COVERED_DEFAULT( 0 );
248        }
249}
250
251unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
252{
253        switch( wrap )
254        {
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;
259        NV_RETURN_COVERED_DEFAULT( 0 );
260        }
261}
262
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;
274        NV_RETURN_COVERED_DEFAULT( 0 );
275        }
276}
277
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
289
290unsigned int nv::output_slot_to_enum( output_slot slot )
291{
292        switch( slot )
293        {
294        case OUTPUT_0 : return GL_COLOR_ATTACHMENT0;
295        case OUTPUT_1 : return GL_COLOR_ATTACHMENT1;
296        case OUTPUT_2 : return GL_COLOR_ATTACHMENT2;
297        case OUTPUT_3 : return GL_COLOR_ATTACHMENT3;
298        case OUTPUT_4 : return GL_COLOR_ATTACHMENT4;
299        case OUTPUT_5 : return GL_COLOR_ATTACHMENT5;
300        case OUTPUT_6 : return GL_COLOR_ATTACHMENT6;
301        case OUTPUT_7 : return GL_COLOR_ATTACHMENT7;
302        case OUTPUT_NONE  : return 0;
303        case OUTPUT_FRONT : return GL_FRONT;
304        case OUTPUT_BACK  : return GL_BACK;
305                NV_RETURN_COVERED_DEFAULT( 0 );
306        }
307}
308
309
310unsigned int nv::datatype_to_gl_enum( datatype type )
311{
312        switch( type )
313        {
314        case BYTE           : return GL_BYTE;
315        case UBYTE          : return GL_UNSIGNED_BYTE;
316        case SHORT          : return GL_SHORT;
317        case USHORT         : return GL_UNSIGNED_SHORT;
318        case INT            : return GL_INT;
319        case UINT               : return GL_UNSIGNED_INT;
320        case FLOAT          : return GL_FLOAT;
321        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
322        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
323        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
324        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
325        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
326        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
327        case INT_VECTOR_2   : return GL_INT_VEC2;
328        case INT_VECTOR_3   : return GL_INT_VEC3;
329        case INT_VECTOR_4   : return GL_INT_VEC4;
330        // remove, error or ?
331        case BYTE_VECTOR_2  : return GL_INT_VEC2;
332        case BYTE_VECTOR_3  : return GL_INT_VEC3;
333        case BYTE_VECTOR_4  : return GL_INT_VEC4;
334                // remove, error or ?
335        case UBYTE_VECTOR_2: return GL_INT_VEC2;
336        case UBYTE_VECTOR_3: return GL_INT_VEC3;
337        case UBYTE_VECTOR_4: return GL_INT_VEC4;
338        default: return 0; // TODO: throw!
339        }
340}
341
342nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
343{
344        switch( gl_enum )
345        {
346        case GL_BYTE           : return BYTE;
347        case GL_UNSIGNED_BYTE  : return UBYTE;
348        case GL_SHORT          : return SHORT;
349        case GL_UNSIGNED_SHORT : return USHORT;
350        case GL_INT            : return INT;
351        case GL_UNSIGNED_INT   : return UINT;
352        case GL_FLOAT          : return FLOAT;
353        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
354        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
355        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
356        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
357        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
358        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
359        case GL_INT_VEC2       : return INT_VECTOR_2;
360        case GL_INT_VEC3       : return INT_VECTOR_3;
361        case GL_INT_VEC4       : return INT_VECTOR_4;
362// TODO: separate types?
363        case GL_SAMPLER_1D             : return INT;
364        case GL_SAMPLER_2D             : return INT;
365        case GL_SAMPLER_3D             : return INT;
366        case GL_SAMPLER_2D_RECT        : return INT;
367        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
368        case GL_SAMPLER_CUBE           : return INT;
369        case GL_SAMPLER_1D_SHADOW      : return INT;   
370        case GL_SAMPLER_2D_SHADOW      : return INT;
371        case GL_SAMPLER_1D_ARRAY       : return INT;
372        case GL_SAMPLER_2D_ARRAY       : return INT;
373        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
374        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
375        case GL_SAMPLER_BUFFER         : return INT;
376
377        case GL_INT_SAMPLER_1D                : return INT;
378        case GL_INT_SAMPLER_2D                : return INT;
379        case GL_INT_SAMPLER_3D                : return INT;
380        case GL_INT_SAMPLER_2D_RECT           : return INT;
381        case GL_INT_SAMPLER_CUBE              : return INT;
382        case GL_INT_SAMPLER_1D_ARRAY          : return INT;
383        case GL_INT_SAMPLER_2D_ARRAY          : return INT;
384        case GL_INT_SAMPLER_BUFFER            : return INT;
385        case GL_UNSIGNED_INT_SAMPLER_1D       : return INT;
386        case GL_UNSIGNED_INT_SAMPLER_2D       : return INT;
387        case GL_UNSIGNED_INT_SAMPLER_3D       : return INT;
388        case GL_UNSIGNED_INT_SAMPLER_2D_RECT  : return INT;
389        case GL_UNSIGNED_INT_SAMPLER_CUBE     : return INT;
390        case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : return INT;
391        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : return INT;
392        case GL_UNSIGNED_INT_SAMPLER_BUFFER   : return INT;
393                // TODO: implement?
394//      case GL_BOOL   
395//      case GL_BOOL_VEC2
396//      case GL_BOOL_VEC3
397//      case GL_BOOL_VEC4
398//      case GL_FLOAT_MAT2x3   
399//      case GL_FLOAT_MAT2x4   
400//      case GL_FLOAT_MAT3x2   
401//      case GL_FLOAT_MAT3x4   
402//      case GL_FLOAT_MAT4x2   
403//      case GL_FLOAT_MAT4x3   
404        default : return datatype(0); // TODO: throw!
405        }
406}
407
408string_view nv::datatype_to_glsl_type( datatype type )
409{
410        switch( type )
411        {
412        case INT            : return "int";
413        case FLOAT          : return "float";
414        case FLOAT_VECTOR_2 : return "vec2";
415        case FLOAT_VECTOR_3 : return "vec3";
416        case FLOAT_VECTOR_4 : return "vec4";
417        case FLOAT_MATRIX_2 : return "mat2";
418        case FLOAT_MATRIX_3 : return "mat3";
419        case FLOAT_MATRIX_4 : return "mat4";
420        case INT_VECTOR_2   : return "ivec2";
421        case INT_VECTOR_3   : return "ivec3";
422        case INT_VECTOR_4   : return "ivec4";
423        default : return "error";
424        }
425}
Note: See TracBrowser for help on using the repository browser.