[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 |
|
---|
| 9 | using namespace nv;
|
---|
| 10 |
|
---|
[40] | 11 | unsigned 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] | 20 | unsigned 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] | 36 | unsigned 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] | 49 | unsigned 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] | 72 | unsigned 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] | 85 | unsigned 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] | 96 | unsigned 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] | 106 | unsigned 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] | 122 | unsigned 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] | 138 | unsigned 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 |
|
---|
[302] | 149 | unsigned int nv::buffer_type_to_enum( buffer_type type )
|
---|
| 150 | {
|
---|
| 151 | switch( type )
|
---|
| 152 | {
|
---|
| 153 | case VERTEX_BUFFER : return GL_ARRAY_BUFFER;
|
---|
| 154 | case INDEX_BUFFER : return GL_ELEMENT_ARRAY_BUFFER;
|
---|
| 155 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[292] | 159 | unsigned int nv::image_format_to_enum( pixel_format format )
|
---|
[43] | 160 | {
|
---|
| 161 | switch( format )
|
---|
| 162 | {
|
---|
[49] | 163 | case RGB : return GL_RGB;
|
---|
| 164 | case RGBA : return GL_RGBA;
|
---|
[121] | 165 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
[43] | 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[49] | 169 | unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
|
---|
[43] | 170 | {
|
---|
| 171 | switch( filter )
|
---|
| 172 | {
|
---|
[49] | 173 | case sampler::LINEAR : return GL_LINEAR;
|
---|
| 174 | case sampler::NEAREST : return GL_NEAREST;
|
---|
| 175 | case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
|
---|
| 176 | case sampler::LINEAR_MIPMAP_NEAREST : return GL_LINEAR_MIPMAP_NEAREST;
|
---|
| 177 | case sampler::NEAREST_MIPMAP_LINEAR : return GL_NEAREST_MIPMAP_LINEAR;
|
---|
| 178 | case sampler::LINEAR_MIPMAP_LINEAR : return GL_LINEAR_MIPMAP_LINEAR;
|
---|
[121] | 179 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
[43] | 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[49] | 183 | unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
|
---|
[43] | 184 | {
|
---|
| 185 | switch( wrap )
|
---|
| 186 | {
|
---|
[49] | 187 | case sampler::CLAMP_TO_EDGE : return GL_CLAMP_TO_EDGE;
|
---|
| 188 | case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
|
---|
| 189 | case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
|
---|
| 190 | case sampler::REPEAT : return GL_REPEAT;
|
---|
[121] | 191 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
[43] | 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[45] | 195 | unsigned int nv::primitive_to_enum( primitive p )
|
---|
| 196 | {
|
---|
| 197 | switch( p )
|
---|
| 198 | {
|
---|
| 199 | case POINTS : return GL_POINTS;
|
---|
| 200 | case LINES : return GL_LINES;
|
---|
| 201 | case LINE_LOOP : return GL_LINE_LOOP;
|
---|
| 202 | case LINE_STRIP : return GL_LINE_STRIP;
|
---|
| 203 | case TRIANGLES : return GL_TRIANGLES;
|
---|
| 204 | case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
|
---|
| 205 | case TRIANGLE_FAN : return GL_TRIANGLE_FAN;
|
---|
[121] | 206 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
[45] | 207 | }
|
---|
| 208 | }
|
---|
[43] | 209 |
|
---|
[70] | 210 | unsigned int nv::datatype_to_gl_enum( datatype type )
|
---|
[35] | 211 | {
|
---|
| 212 | switch( type )
|
---|
| 213 | {
|
---|
[44] | 214 | case BYTE : return GL_BYTE;
|
---|
| 215 | case UBYTE : return GL_UNSIGNED_BYTE;
|
---|
| 216 | case SHORT : return GL_SHORT;
|
---|
| 217 | case USHORT : return GL_UNSIGNED_SHORT;
|
---|
| 218 | case INT : return GL_INT;
|
---|
| 219 | case UINT : return GL_UNSIGNED_INT;
|
---|
[35] | 220 | case FLOAT : return GL_FLOAT;
|
---|
| 221 | case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
|
---|
| 222 | case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
|
---|
| 223 | case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
|
---|
| 224 | case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
|
---|
| 225 | case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
|
---|
| 226 | case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
|
---|
| 227 | case INT_VECTOR_2 : return GL_INT_VEC2;
|
---|
| 228 | case INT_VECTOR_3 : return GL_INT_VEC3;
|
---|
| 229 | case INT_VECTOR_4 : return GL_INT_VEC4;
|
---|
[68] | 230 | // remove, error or ?
|
---|
| 231 | case BYTE_VECTOR_2 : return GL_INT_VEC2;
|
---|
| 232 | case BYTE_VECTOR_3 : return GL_INT_VEC3;
|
---|
| 233 | case BYTE_VECTOR_4 : return GL_INT_VEC4;
|
---|
[121] | 234 | NV_RETURN_COVERED_DEFAULT( 0 );
|
---|
[35] | 235 | }
|
---|
| 236 | }
|
---|
| 237 |
|
---|
[70] | 238 | nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
|
---|
[35] | 239 | {
|
---|
| 240 | switch( gl_enum )
|
---|
| 241 | {
|
---|
[44] | 242 | case GL_BYTE : return BYTE;
|
---|
| 243 | case GL_UNSIGNED_BYTE : return UBYTE;
|
---|
| 244 | case GL_SHORT : return SHORT;
|
---|
| 245 | case GL_UNSIGNED_SHORT : return USHORT;
|
---|
| 246 | case GL_INT : return INT;
|
---|
| 247 | case GL_UNSIGNED_INT : return UINT;
|
---|
| 248 | case GL_FLOAT : return FLOAT;
|
---|
| 249 | case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
|
---|
| 250 | case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
|
---|
| 251 | case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
|
---|
| 252 | case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
|
---|
| 253 | case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
|
---|
| 254 | case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
|
---|
| 255 | case GL_INT_VEC2 : return INT_VECTOR_2;
|
---|
| 256 | case GL_INT_VEC3 : return INT_VECTOR_3;
|
---|
| 257 | case GL_INT_VEC4 : return INT_VECTOR_4;
|
---|
[237] | 258 | // TODO: separate types?
|
---|
| 259 | case GL_SAMPLER_1D : return INT;
|
---|
| 260 | case GL_SAMPLER_2D : return INT;
|
---|
| 261 | case GL_SAMPLER_3D : return INT;
|
---|
| 262 | case GL_SAMPLER_CUBE : return INT;
|
---|
| 263 | case GL_SAMPLER_1D_SHADOW : return INT;
|
---|
| 264 | case GL_SAMPLER_2D_SHADOW : return INT;
|
---|
| 265 | // TODO: implement?
|
---|
| 266 | // case GL_BOOL
|
---|
| 267 | // case GL_BOOL_VEC2
|
---|
| 268 | // case GL_BOOL_VEC3
|
---|
| 269 | // case GL_BOOL_VEC4
|
---|
| 270 | // case GL_FLOAT_MAT2x3
|
---|
| 271 | // case GL_FLOAT_MAT2x4
|
---|
| 272 | // case GL_FLOAT_MAT3x2
|
---|
| 273 | // case GL_FLOAT_MAT3x4
|
---|
| 274 | // case GL_FLOAT_MAT4x2
|
---|
| 275 | // case GL_FLOAT_MAT4x3
|
---|
[70] | 276 | default : return datatype(0); // TODO: throw!
|
---|
[35] | 277 | }
|
---|
| 278 | }
|
---|