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

Last change on this file since 237 was 237, checked in by epyon, 11 years ago
  • debug_draw module added
  • evil vertex descriptor and info added
  • fix for sampler objects
  • various fixes
File size: 8.9 KB
RevLine 
[36]1// Copyright (C) 2012-2013 Kornel Kisielewicz
[35]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
[40]11unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type )
[35]12{
13        unsigned int mask = 0;
14        if ( (type & clear_state::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
15        if ( (type & clear_state::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
16        if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
17        return mask;
18}
19
[40]20unsigned int nv::depth_state_function_to_enum( depth_test::function_type type )
[35]21{
22        switch( type )
23        {
24        case depth_test::NEVER            : return GL_NEVER;
25        case depth_test::LESS             : return GL_LESS;
26        case depth_test::EQUAL            : return GL_EQUAL;
27        case depth_test::LESS_OR_EQUAL    : return GL_LEQUAL;
28        case depth_test::GREATER          : return GL_GREATER;
29        case depth_test::NOT_EQUAL        : return GL_NOTEQUAL;
30        case depth_test::GREATER_OR_EQUAL : return GL_GEQUAL;
31        case depth_test::ALWAYS           : return GL_ALWAYS;
[121]32        NV_RETURN_COVERED_DEFAULT( 0 );
[35]33        }
34}
35
[233]36unsigned int nv::polygon_mode_fill_to_enum( polygon_mode::fill_type type )
37{
38        switch( type )
39        {
40        case polygon_mode::FILL           : return GL_FILL;
41        case polygon_mode::LINE           : return GL_LINE;
42        case polygon_mode::POINT          : return GL_POINT;
43        NV_RETURN_COVERED_DEFAULT( 0 );
44        }
45}
46
47
48
[40]49unsigned int nv::blending_factor_to_enum( blending::factor type )
[35]50{
51        switch( type )
52        {
53        case blending::ZERO                    : return GL_ZERO;
54        case blending::ONE                     : return GL_ONE;
55        case blending::SRC_COLOR               : return GL_SRC_COLOR;
56        case blending::ONE_MINUS_SRC_COLOR     : return GL_ONE_MINUS_SRC_COLOR;
57        case blending::DST_COLOR               : return GL_DST_COLOR;
58        case blending::ONE_MINUS_DST_COLOR     : return GL_ONE_MINUS_DST_COLOR;
59        case blending::SRC_ALPHA               : return GL_SRC_ALPHA;
60        case blending::ONE_MINUS_SRC_ALPHA     : return GL_ONE_MINUS_SRC_ALPHA;
61        case blending::DST_ALPHA               : return GL_DST_ALPHA;
62        case blending::ONE_MINUS_DST_ALPHA     : return GL_ONE_MINUS_DST_ALPHA;
63        case blending::CONSTANT_COLOR          : return GL_CONSTANT_COLOR;
64        case blending::ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR;
65        case blending::CONSTANT_ALPHA          : return GL_CONSTANT_ALPHA;
66        case blending::ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA;
67        case blending::SRC_ALPHA_SATURATE      : return GL_SRC_ALPHA_SATURATE;
[121]68        NV_RETURN_COVERED_DEFAULT( 0 );
[35]69        }
70}
71
[40]72unsigned int nv::blending_equation_to_enum( blending::equation type )
[35]73{
74        switch( type )
75        {
76        case blending::ADD              : return GL_FUNC_ADD;
77        case blending::SUBTRACT         : return GL_FUNC_SUBTRACT;
78        case blending::REVERSE_SUBTRACT : return GL_FUNC_REVERSE_SUBTRACT;
79        case blending::MINIMUM          : return GL_MIN;
80        case blending::MAXIMUM          : return GL_MAX;
[121]81        NV_RETURN_COVERED_DEFAULT( 0 );
[35]82        }
83}
84
[40]85unsigned int nv::culling_face_type_to_enum( culling::face_type type )
[35]86{
87        switch( type )
88        {
89        case culling::FRONT          : return GL_FRONT;
90        case culling::BACK           : return GL_BACK;
91        case culling::FRONT_AND_BACK : return GL_FRONT_AND_BACK;
[121]92        NV_RETURN_COVERED_DEFAULT( 0 );
[35]93        }
94}
95
[40]96unsigned int nv::culling_order_type_to_enum( culling::order_type type )
[35]97{
98        switch( type )
99        {
100        case culling::CW   : return GL_CW;
101        case culling::CCW  : return GL_CCW;
[121]102        NV_RETURN_COVERED_DEFAULT( 0 );
[35]103        }
104}
105
[40]106unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
[35]107{
108        switch( type )
109        {
110        case stencil_test_face::NEVER            : return GL_NEVER;
111        case stencil_test_face::LESS             : return GL_LESS;
112        case stencil_test_face::EQUAL            : return GL_EQUAL;
113        case stencil_test_face::LESS_OR_EQUAL    : return GL_LEQUAL;
114        case stencil_test_face::GREATER          : return GL_GREATER;
115        case stencil_test_face::NOT_EQUAL        : return GL_NOTEQUAL;
116        case stencil_test_face::GREATER_OR_EQUAL : return GL_GEQUAL;
117        case stencil_test_face::ALWAYS           : return GL_ALWAYS;
[121]118        NV_RETURN_COVERED_DEFAULT( 0 );
[35]119        }
120}
121
[40]122unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
[35]123{
124        switch( type )
125        {
126        case stencil_test_face::ZERO             : return GL_ZERO;
127        case stencil_test_face::INVERT           : return GL_INVERT;
128        case stencil_test_face::KEEP             : return GL_KEEP;
129        case stencil_test_face::REPLACE          : return GL_REPLACE;
130        case stencil_test_face::INCREMENT        : return GL_INCR;
131        case stencil_test_face::DECREMENT        : return GL_DECR;
132        case stencil_test_face::INCREMENT_WRAP   : return GL_INCR_WRAP;
133        case stencil_test_face::DECREMENT_WRAP   : return GL_DECR_WRAP;
[121]134        NV_RETURN_COVERED_DEFAULT( 0 );
[35]135        }
136}
137
[42]138unsigned int nv::buffer_hint_to_enum( buffer_hint hint )
139{
140        switch( hint )
141        {
142        case STATIC_DRAW   : return GL_STATIC_DRAW;
143        case STREAM_DRAW   : return GL_STREAM_DRAW;
144        case DYNAMIC_DRAW  : return GL_DYNAMIC_DRAW;
[121]145        NV_RETURN_COVERED_DEFAULT( 0 );
[42]146        }
147}
148
[49]149unsigned int nv::image_format_to_enum( image_format format )
[43]150{
151        switch( format )
152        {
[49]153        case RGB  : return GL_RGB;
154        case RGBA : return GL_RGBA;
[121]155        NV_RETURN_COVERED_DEFAULT( 0 );
[43]156        }
157}
158
[49]159unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
[43]160{
161        switch( filter )
162        {
[49]163        case sampler::LINEAR                 : return GL_LINEAR;
164        case sampler::NEAREST                : return GL_NEAREST;
165        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
166        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
167        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
168        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
[121]169        NV_RETURN_COVERED_DEFAULT( 0 );
[43]170        }
171}
172
[49]173unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
[43]174{
175        switch( wrap )
176        {
[49]177        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
178        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
179        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
180        case sampler::REPEAT          : return GL_REPEAT;
[121]181        NV_RETURN_COVERED_DEFAULT( 0 );
[43]182        }
183}
184
[45]185unsigned int nv::primitive_to_enum( primitive p )
186{
187        switch( p )
188        {
189        case POINTS         : return GL_POINTS;
190        case LINES          : return GL_LINES;
191        case LINE_LOOP      : return GL_LINE_LOOP;
192        case LINE_STRIP     : return GL_LINE_STRIP;
193        case TRIANGLES      : return GL_TRIANGLES;
194        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
195        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
[121]196        NV_RETURN_COVERED_DEFAULT( 0 );
[45]197        }
198}
[43]199
[70]200unsigned int nv::datatype_to_gl_enum( datatype type )
[35]201{
202        switch( type )
203        {
[44]204        case BYTE           : return GL_BYTE;
205        case UBYTE          : return GL_UNSIGNED_BYTE;
206        case SHORT          : return GL_SHORT;
207        case USHORT         : return GL_UNSIGNED_SHORT;
208        case INT            : return GL_INT;
209        case UINT               : return GL_UNSIGNED_INT;
[35]210        case FLOAT          : return GL_FLOAT;
211        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
212        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
213        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
214        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
215        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
216        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
217        case INT_VECTOR_2   : return GL_INT_VEC2;
218        case INT_VECTOR_3   : return GL_INT_VEC3;
219        case INT_VECTOR_4   : return GL_INT_VEC4;
[68]220        // remove, error or ?
221        case BYTE_VECTOR_2  : return GL_INT_VEC2;
222        case BYTE_VECTOR_3  : return GL_INT_VEC3;
223        case BYTE_VECTOR_4  : return GL_INT_VEC4;
[121]224        NV_RETURN_COVERED_DEFAULT( 0 );
[35]225        }
226}
227
[70]228nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
[35]229{
230        switch( gl_enum )
231        {
[44]232        case GL_BYTE           : return BYTE;
233        case GL_UNSIGNED_BYTE  : return UBYTE;
234        case GL_SHORT          : return SHORT;
235        case GL_UNSIGNED_SHORT : return USHORT;
236        case GL_INT            : return INT;
237        case GL_UNSIGNED_INT   : return UINT;
238        case GL_FLOAT          : return FLOAT;
239        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
240        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
241        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
242        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
243        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
244        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
245        case GL_INT_VEC2       : return INT_VECTOR_2;
246        case GL_INT_VEC3       : return INT_VECTOR_3;
247        case GL_INT_VEC4       : return INT_VECTOR_4;
[237]248// TODO: separate types?
249        case GL_SAMPLER_1D         : return INT;
250        case GL_SAMPLER_2D         : return INT;
251        case GL_SAMPLER_3D         : return INT;
252        case GL_SAMPLER_CUBE       : return INT;
253        case GL_SAMPLER_1D_SHADOW  : return INT;       
254        case GL_SAMPLER_2D_SHADOW  : return INT;
255// TODO: implement?
256//      case GL_BOOL   
257//      case GL_BOOL_VEC2
258//      case GL_BOOL_VEC3
259//      case GL_BOOL_VEC4
260//      case GL_FLOAT_MAT2x3   
261//      case GL_FLOAT_MAT2x4   
262//      case GL_FLOAT_MAT3x2   
263//      case GL_FLOAT_MAT3x4   
264//      case GL_FLOAT_MAT4x2   
265//      case GL_FLOAT_MAT4x3   
[70]266        default : return datatype(0); // TODO: throw!
[35]267        }
268}
Note: See TracBrowser for help on using the repository browser.