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

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