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

Last change on this file since 463 was 463, checked in by epyon, 10 years ago
  • 3D/2D_ARRAY texture support
File size: 12.5 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 DEPTH16 : return GL_DEPTH_COMPONENT;
190        case DEPTH24 : return GL_DEPTH_COMPONENT;
191        case DEPTH32 : return GL_DEPTH_COMPONENT;
192        NV_RETURN_COVERED_DEFAULT( 0 );
193        }
194}
195
196unsigned int nv::image_format_to_internal_enum( pixel_format format )
197{
198        switch( format )
199        {
200        case RGB     : return GL_RGB8;
201        case RGBA    : return GL_RGBA8;
202        case RGB32F  : return GL_RGB32F;
203        case RGBA32F : return GL_RGBA32F;
204        case RGB16F  : return GL_RGBA16F;
205        case RGBA16F : return GL_RGBA16F;
206        case BGR     : return GL_RGB8;
207        case BGRA    : return GL_RGBA8;
208        case RED     : return 0x8040; // GL_LUMINANCE8; // TODO: change to GL_R8!
209        case DEPTH16 : return GL_DEPTH_COMPONENT16;
210        case DEPTH24 : return GL_DEPTH_COMPONENT24;
211        case DEPTH32:  return GL_DEPTH_COMPONENT32;
212        NV_RETURN_COVERED_DEFAULT( 0 );
213        }
214}
215
216
217unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
218{
219        switch( filter )
220        {
221        case sampler::LINEAR                 : return GL_LINEAR;
222        case sampler::NEAREST                : return GL_NEAREST;
223        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
224        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
225        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
226        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
227        NV_RETURN_COVERED_DEFAULT( 0 );
228        }
229}
230
231unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
232{
233        switch( wrap )
234        {
235        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
236        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
237        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
238        case sampler::REPEAT          : return GL_REPEAT;
239        NV_RETURN_COVERED_DEFAULT( 0 );
240        }
241}
242
243unsigned int nv::primitive_to_enum( primitive p )
244{
245        switch( p )
246        {
247        case POINTS         : return GL_POINTS;
248        case LINES          : return GL_LINES;
249        case LINE_LOOP      : return GL_LINE_LOOP;
250        case LINE_STRIP     : return GL_LINE_STRIP;
251        case TRIANGLES      : return GL_TRIANGLES;
252        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
253        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
254        NV_RETURN_COVERED_DEFAULT( 0 );
255        }
256}
257
258unsigned int nv::framebuffer_slot_to_enum( framebuffer_slot slot )
259{
260        switch( slot )
261        {
262        case READ_FRAMEBUFFER : return GL_READ_FRAMEBUFFER;
263        case DRAW_FRAMEBUFFER : return GL_DRAW_FRAMEBUFFER;
264        case FRAMEBUFFER      : return GL_FRAMEBUFFER;
265        NV_RETURN_COVERED_DEFAULT( 0 );
266        }
267}
268
269
270unsigned int nv::output_slot_to_enum( output_slot slot )
271{
272        switch( slot )
273        {
274        case OUTPUT_0 : return GL_COLOR_ATTACHMENT0;
275        case OUTPUT_1 : return GL_COLOR_ATTACHMENT1;
276        case OUTPUT_2 : return GL_COLOR_ATTACHMENT2;
277        case OUTPUT_3 : return GL_COLOR_ATTACHMENT3;
278        case OUTPUT_4 : return GL_COLOR_ATTACHMENT4;
279        case OUTPUT_5 : return GL_COLOR_ATTACHMENT5;
280        case OUTPUT_6 : return GL_COLOR_ATTACHMENT6;
281        case OUTPUT_7 : return GL_COLOR_ATTACHMENT7;
282        case OUTPUT_NONE  : return 0;
283        case OUTPUT_FRONT : return GL_FRONT;
284        case OUTPUT_BACK  : return GL_BACK;
285                NV_RETURN_COVERED_DEFAULT( 0 );
286        }
287}
288
289
290unsigned int nv::datatype_to_gl_enum( datatype type )
291{
292        switch( type )
293        {
294        case BYTE           : return GL_BYTE;
295        case UBYTE          : return GL_UNSIGNED_BYTE;
296        case SHORT          : return GL_SHORT;
297        case USHORT         : return GL_UNSIGNED_SHORT;
298        case INT            : return GL_INT;
299        case UINT               : return GL_UNSIGNED_INT;
300        case FLOAT          : return GL_FLOAT;
301        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
302        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
303        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
304        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
305        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
306        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
307        case INT_VECTOR_2   : return GL_INT_VEC2;
308        case INT_VECTOR_3   : return GL_INT_VEC3;
309        case INT_VECTOR_4   : return GL_INT_VEC4;
310        // remove, error or ?
311        case BYTE_VECTOR_2  : return GL_INT_VEC2;
312        case BYTE_VECTOR_3  : return GL_INT_VEC3;
313        case BYTE_VECTOR_4  : return GL_INT_VEC4;
314                // remove, error or ?
315        case UBYTE_VECTOR_2: return GL_INT_VEC2;
316        case UBYTE_VECTOR_3: return GL_INT_VEC3;
317        case UBYTE_VECTOR_4: return GL_INT_VEC4;
318        default: return 0; // TODO: throw!
319        }
320}
321
322nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
323{
324        switch( gl_enum )
325        {
326        case GL_BYTE           : return BYTE;
327        case GL_UNSIGNED_BYTE  : return UBYTE;
328        case GL_SHORT          : return SHORT;
329        case GL_UNSIGNED_SHORT : return USHORT;
330        case GL_INT            : return INT;
331        case GL_UNSIGNED_INT   : return UINT;
332        case GL_FLOAT          : return FLOAT;
333        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
334        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
335        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
336        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
337        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
338        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
339        case GL_INT_VEC2       : return INT_VECTOR_2;
340        case GL_INT_VEC3       : return INT_VECTOR_3;
341        case GL_INT_VEC4       : return INT_VECTOR_4;
342// TODO: separate types?
343        case GL_SAMPLER_1D             : return INT;
344        case GL_SAMPLER_2D             : return INT;
345        case GL_SAMPLER_3D             : return INT;
346        case GL_SAMPLER_2D_RECT        : return INT;
347        case GL_SAMPLER_2D_RECT_SHADOW : return INT;
348        case GL_SAMPLER_CUBE           : return INT;
349        case GL_SAMPLER_1D_SHADOW      : return INT;   
350        case GL_SAMPLER_2D_SHADOW      : return INT;
351        case GL_SAMPLER_1D_ARRAY       : return INT;
352        case GL_SAMPLER_2D_ARRAY       : return INT;
353        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
354        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
355                // TODO: implement?
356//      case GL_BOOL   
357//      case GL_BOOL_VEC2
358//      case GL_BOOL_VEC3
359//      case GL_BOOL_VEC4
360//      case GL_FLOAT_MAT2x3   
361//      case GL_FLOAT_MAT2x4   
362//      case GL_FLOAT_MAT3x2   
363//      case GL_FLOAT_MAT3x4   
364//      case GL_FLOAT_MAT4x2   
365//      case GL_FLOAT_MAT4x3   
366        default : return datatype(0); // TODO: throw!
367        }
368}
369
370string_view nv::datatype_to_glsl_type( datatype type )
371{
372        switch( type )
373        {
374        case INT            : return "int";
375        case FLOAT          : return "float";
376        case FLOAT_VECTOR_2 : return "vec2";
377        case FLOAT_VECTOR_3 : return "vec3";
378        case FLOAT_VECTOR_4 : return "vec4";
379        case FLOAT_MATRIX_2 : return "mat2";
380        case FLOAT_MATRIX_3 : return "mat3";
381        case FLOAT_MATRIX_4 : return "mat4";
382        case INT_VECTOR_2   : return "ivec2";
383        case INT_VECTOR_3   : return "ivec3";
384        case INT_VECTOR_4   : return "ivec4";
385        default : return "error";
386        }
387}
Note: See TracBrowser for help on using the repository browser.