[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;
|
---|
| 32 | default : return 0; // TODO: throw!
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[40] | 36 | unsigned int nv::blending_factor_to_enum( blending::factor type )
|
---|
[35] | 37 | {
|
---|
| 38 | switch( type )
|
---|
| 39 | {
|
---|
| 40 | case blending::ZERO : return GL_ZERO;
|
---|
| 41 | case blending::ONE : return GL_ONE;
|
---|
| 42 | case blending::SRC_COLOR : return GL_SRC_COLOR;
|
---|
| 43 | case blending::ONE_MINUS_SRC_COLOR : return GL_ONE_MINUS_SRC_COLOR;
|
---|
| 44 | case blending::DST_COLOR : return GL_DST_COLOR;
|
---|
| 45 | case blending::ONE_MINUS_DST_COLOR : return GL_ONE_MINUS_DST_COLOR;
|
---|
| 46 | case blending::SRC_ALPHA : return GL_SRC_ALPHA;
|
---|
| 47 | case blending::ONE_MINUS_SRC_ALPHA : return GL_ONE_MINUS_SRC_ALPHA;
|
---|
| 48 | case blending::DST_ALPHA : return GL_DST_ALPHA;
|
---|
| 49 | case blending::ONE_MINUS_DST_ALPHA : return GL_ONE_MINUS_DST_ALPHA;
|
---|
| 50 | case blending::CONSTANT_COLOR : return GL_CONSTANT_COLOR;
|
---|
| 51 | case blending::ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR;
|
---|
| 52 | case blending::CONSTANT_ALPHA : return GL_CONSTANT_ALPHA;
|
---|
| 53 | case blending::ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA;
|
---|
| 54 | case blending::SRC_ALPHA_SATURATE : return GL_SRC_ALPHA_SATURATE;
|
---|
| 55 | default : return 0; // TODO: throw!
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[40] | 59 | unsigned int nv::blending_equation_to_enum( blending::equation type )
|
---|
[35] | 60 | {
|
---|
| 61 | switch( type )
|
---|
| 62 | {
|
---|
| 63 | case blending::ADD : return GL_FUNC_ADD;
|
---|
| 64 | case blending::SUBTRACT : return GL_FUNC_SUBTRACT;
|
---|
| 65 | case blending::REVERSE_SUBTRACT : return GL_FUNC_REVERSE_SUBTRACT;
|
---|
| 66 | case blending::MINIMUM : return GL_MIN;
|
---|
| 67 | case blending::MAXIMUM : return GL_MAX;
|
---|
| 68 | default : return 0; // TODO: throw!
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[40] | 72 | unsigned int nv::culling_face_type_to_enum( culling::face_type type )
|
---|
[35] | 73 | {
|
---|
| 74 | switch( type )
|
---|
| 75 | {
|
---|
| 76 | case culling::FRONT : return GL_FRONT;
|
---|
| 77 | case culling::BACK : return GL_BACK;
|
---|
| 78 | case culling::FRONT_AND_BACK : return GL_FRONT_AND_BACK;
|
---|
| 79 | default : return 0; // TODO: throw!
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[40] | 83 | unsigned int nv::culling_order_type_to_enum( culling::order_type type )
|
---|
[35] | 84 | {
|
---|
| 85 | switch( type )
|
---|
| 86 | {
|
---|
| 87 | case culling::CW : return GL_CW;
|
---|
| 88 | case culling::CCW : return GL_CCW;
|
---|
| 89 | default : return 0; // TODO: throw!
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[40] | 93 | unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
|
---|
[35] | 94 | {
|
---|
| 95 | switch( type )
|
---|
| 96 | {
|
---|
| 97 | case stencil_test_face::NEVER : return GL_NEVER;
|
---|
| 98 | case stencil_test_face::LESS : return GL_LESS;
|
---|
| 99 | case stencil_test_face::EQUAL : return GL_EQUAL;
|
---|
| 100 | case stencil_test_face::LESS_OR_EQUAL : return GL_LEQUAL;
|
---|
| 101 | case stencil_test_face::GREATER : return GL_GREATER;
|
---|
| 102 | case stencil_test_face::NOT_EQUAL : return GL_NOTEQUAL;
|
---|
| 103 | case stencil_test_face::GREATER_OR_EQUAL : return GL_GEQUAL;
|
---|
| 104 | case stencil_test_face::ALWAYS : return GL_ALWAYS;
|
---|
| 105 | default : return 0; // TODO: throw!
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[40] | 109 | unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
|
---|
[35] | 110 | {
|
---|
| 111 | switch( type )
|
---|
| 112 | {
|
---|
| 113 | case stencil_test_face::ZERO : return GL_ZERO;
|
---|
| 114 | case stencil_test_face::INVERT : return GL_INVERT;
|
---|
| 115 | case stencil_test_face::KEEP : return GL_KEEP;
|
---|
| 116 | case stencil_test_face::REPLACE : return GL_REPLACE;
|
---|
| 117 | case stencil_test_face::INCREMENT : return GL_INCR;
|
---|
| 118 | case stencil_test_face::DECREMENT : return GL_DECR;
|
---|
| 119 | case stencil_test_face::INCREMENT_WRAP : return GL_INCR_WRAP;
|
---|
| 120 | case stencil_test_face::DECREMENT_WRAP : return GL_DECR_WRAP;
|
---|
| 121 | default : return 0; // TODO: throw!
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[42] | 125 | unsigned int nv::buffer_hint_to_enum( buffer_hint hint )
|
---|
| 126 | {
|
---|
| 127 | switch( hint )
|
---|
| 128 | {
|
---|
| 129 | case STATIC_DRAW : return GL_STATIC_DRAW;
|
---|
| 130 | case STREAM_DRAW : return GL_STREAM_DRAW;
|
---|
| 131 | case DYNAMIC_DRAW : return GL_DYNAMIC_DRAW;
|
---|
| 132 | default : return 0; // TODO: throw!
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[43] | 136 | unsigned int nv::texture_format_to_enum( texture2d::format format )
|
---|
| 137 | {
|
---|
| 138 | switch( format )
|
---|
| 139 | {
|
---|
| 140 | case texture2d::RGB : return GL_RGB;
|
---|
| 141 | case texture2d::RGBA : return GL_RGBA;
|
---|
| 142 | default : return 0; // TODO: throw!
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | unsigned int nv::texture_datatype_to_enum( texture2d::datatype datatype )
|
---|
| 147 | {
|
---|
| 148 | switch( datatype )
|
---|
| 149 | {
|
---|
| 150 | case texture2d::UINT : return GL_UNSIGNED_INT;
|
---|
| 151 | case texture2d::UBYTE : return GL_UNSIGNED_BYTE;
|
---|
| 152 | case texture2d::FLOAT : return GL_FLOAT;
|
---|
| 153 | default : return 0; // TODO: throw!
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | unsigned int nv::texture_filter_to_enum( texture2d_sampler::filter filter )
|
---|
| 158 | {
|
---|
| 159 | switch( filter )
|
---|
| 160 | {
|
---|
| 161 | case texture2d_sampler::LINEAR : return GL_LINEAR;
|
---|
| 162 | case texture2d_sampler::NEAREST : return GL_NEAREST;
|
---|
| 163 | case texture2d_sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
|
---|
| 164 | case texture2d_sampler::LINEAR_MIPMAP_NEAREST : return GL_LINEAR_MIPMAP_NEAREST;
|
---|
| 165 | case texture2d_sampler::NEAREST_MIPMAP_LINEAR : return GL_NEAREST_MIPMAP_LINEAR;
|
---|
| 166 | case texture2d_sampler::LINEAR_MIPMAP_LINEAR : return GL_LINEAR_MIPMAP_LINEAR;
|
---|
| 167 | default : return 0; // TODO: throw!
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | unsigned int nv::texture_wrap_to_enum( texture2d_sampler::wrap wrap )
|
---|
| 172 | {
|
---|
| 173 | switch( wrap )
|
---|
| 174 | {
|
---|
| 175 | case texture2d_sampler::CLAMP_TO_EDGE : return GL_CLAMP_TO_EDGE;
|
---|
| 176 | case texture2d_sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
|
---|
| 177 | case texture2d_sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
|
---|
| 178 | case texture2d_sampler::REPEAT : return GL_REPEAT;
|
---|
| 179 | default : return 0; // TODO: throw!
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[45] | 183 | unsigned int nv::primitive_to_enum( primitive p )
|
---|
| 184 | {
|
---|
| 185 | switch( p )
|
---|
| 186 | {
|
---|
| 187 | case POINTS : return GL_POINTS;
|
---|
| 188 | case LINES : return GL_LINES;
|
---|
| 189 | case LINE_LOOP : return GL_LINE_LOOP;
|
---|
| 190 | case LINE_STRIP : return GL_LINE_STRIP;
|
---|
| 191 | case TRIANGLES : return GL_TRIANGLES;
|
---|
| 192 | case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
|
---|
| 193 | case TRIANGLE_FAN : return GL_TRIANGLE_FAN;
|
---|
| 194 | default : return 0; // TODO: throw!
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
[43] | 197 |
|
---|
[40] | 198 | unsigned int nv::type_to_gl_enum( type type )
|
---|
[35] | 199 | {
|
---|
| 200 | switch( type )
|
---|
| 201 | {
|
---|
[44] | 202 | case BYTE : return GL_BYTE;
|
---|
| 203 | case UBYTE : return GL_UNSIGNED_BYTE;
|
---|
| 204 | case SHORT : return GL_SHORT;
|
---|
| 205 | case USHORT : return GL_UNSIGNED_SHORT;
|
---|
| 206 | case INT : return GL_INT;
|
---|
| 207 | case UINT : return GL_UNSIGNED_INT;
|
---|
[35] | 208 | case FLOAT : return GL_FLOAT;
|
---|
| 209 | case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
|
---|
| 210 | case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
|
---|
| 211 | case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
|
---|
| 212 | case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
|
---|
| 213 | case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
|
---|
| 214 | case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
|
---|
| 215 | case INT_VECTOR_2 : return GL_INT_VEC2;
|
---|
| 216 | case INT_VECTOR_3 : return GL_INT_VEC3;
|
---|
| 217 | case INT_VECTOR_4 : return GL_INT_VEC4;
|
---|
| 218 | default : return 0; // TODO: throw!
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[40] | 222 | nv::type nv::gl_enum_to_type( unsigned int gl_enum )
|
---|
[35] | 223 | {
|
---|
| 224 | switch( gl_enum )
|
---|
| 225 | {
|
---|
[44] | 226 | case GL_BYTE : return BYTE;
|
---|
| 227 | case GL_UNSIGNED_BYTE : return UBYTE;
|
---|
| 228 | case GL_SHORT : return SHORT;
|
---|
| 229 | case GL_UNSIGNED_SHORT : return USHORT;
|
---|
| 230 | case GL_INT : return INT;
|
---|
| 231 | case GL_UNSIGNED_INT : return UINT;
|
---|
| 232 | case GL_FLOAT : return FLOAT;
|
---|
| 233 | case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
|
---|
| 234 | case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
|
---|
| 235 | case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
|
---|
| 236 | case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
|
---|
| 237 | case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
|
---|
| 238 | case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
|
---|
| 239 | case GL_INT_VEC2 : return INT_VECTOR_2;
|
---|
| 240 | case GL_INT_VEC3 : return INT_VECTOR_3;
|
---|
| 241 | case GL_INT_VEC4 : return INT_VECTOR_4;
|
---|
[35] | 242 | default : return type(0); // TODO: throw!
|
---|
| 243 | }
|
---|
| 244 | }
|
---|