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

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