// Copyright (C) 2012-2015 ChaosForge Ltd // http://chaosforge.org/ // // This file is part of Nova libraries. // For conditions of distribution and use, see copying.txt file in root folder. #include "nv/gl/gl_enum.hh" #include "nv/lib/gl.hh" using namespace nv; unsigned int nv::texture_type_to_enum( texture_type type ) { switch( type ) { case TEXTURE_1D : return GL_TEXTURE_1D; case TEXTURE_2D : return GL_TEXTURE_2D; case TEXTURE_RECT : return GL_TEXTURE_RECTANGLE; case TEXTURE_3D : return GL_TEXTURE_3D; case TEXTURE_CUBE : return GL_TEXTURE_CUBE_MAP; case TEXTURE_1D_ARRAY: return GL_TEXTURE_1D_ARRAY; case TEXTURE_2D_ARRAY: return GL_TEXTURE_2D_ARRAY; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type ) { unsigned int mask = 0; if ( (type & clear_state::COLOR_BUFFER) != 0 ) mask |= GL_COLOR_BUFFER_BIT; if ( (type & clear_state::DEPTH_BUFFER) != 0 ) mask |= GL_DEPTH_BUFFER_BIT; if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT; return mask; } unsigned int nv::depth_state_function_to_enum( depth_test::function_type type ) { switch( type ) { case depth_test::NEVER : return GL_NEVER; case depth_test::LESS : return GL_LESS; case depth_test::EQUAL : return GL_EQUAL; case depth_test::LESS_OR_EQUAL : return GL_LEQUAL; case depth_test::GREATER : return GL_GREATER; case depth_test::NOT_EQUAL : return GL_NOTEQUAL; case depth_test::GREATER_OR_EQUAL : return GL_GEQUAL; case depth_test::ALWAYS : return GL_ALWAYS; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::polygon_mode_fill_to_enum( polygon_mode::fill_type type ) { switch( type ) { case polygon_mode::FILL : return GL_FILL; case polygon_mode::LINE : return GL_LINE; case polygon_mode::POINT : return GL_POINT; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::blending_factor_to_enum( blending::factor type ) { switch( type ) { case blending::ZERO : return GL_ZERO; case blending::ONE : return GL_ONE; case blending::SRC_COLOR : return GL_SRC_COLOR; case blending::ONE_MINUS_SRC_COLOR : return GL_ONE_MINUS_SRC_COLOR; case blending::DST_COLOR : return GL_DST_COLOR; case blending::ONE_MINUS_DST_COLOR : return GL_ONE_MINUS_DST_COLOR; case blending::SRC_ALPHA : return GL_SRC_ALPHA; case blending::ONE_MINUS_SRC_ALPHA : return GL_ONE_MINUS_SRC_ALPHA; case blending::DST_ALPHA : return GL_DST_ALPHA; case blending::ONE_MINUS_DST_ALPHA : return GL_ONE_MINUS_DST_ALPHA; case blending::CONSTANT_COLOR : return GL_CONSTANT_COLOR; case blending::ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR; case blending::CONSTANT_ALPHA : return GL_CONSTANT_ALPHA; case blending::ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA; case blending::SRC_ALPHA_SATURATE : return GL_SRC_ALPHA_SATURATE; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::blending_equation_to_enum( blending::equation type ) { switch( type ) { case blending::ADD : return GL_FUNC_ADD; case blending::SUBTRACT : return GL_FUNC_SUBTRACT; case blending::REVERSE_SUBTRACT : return GL_FUNC_REVERSE_SUBTRACT; case blending::MINIMUM : return GL_MIN; case blending::MAXIMUM : return GL_MAX; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::culling_face_type_to_enum( culling::face_type type ) { switch( type ) { case culling::FRONT : return GL_FRONT; case culling::BACK : return GL_BACK; case culling::FRONT_AND_BACK : return GL_FRONT_AND_BACK; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::culling_order_type_to_enum( culling::order_type type ) { switch( type ) { case culling::CW : return GL_CW; case culling::CCW : return GL_CCW; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type ) { switch( type ) { case stencil_test_face::NEVER : return GL_NEVER; case stencil_test_face::LESS : return GL_LESS; case stencil_test_face::EQUAL : return GL_EQUAL; case stencil_test_face::LESS_OR_EQUAL : return GL_LEQUAL; case stencil_test_face::GREATER : return GL_GREATER; case stencil_test_face::NOT_EQUAL : return GL_NOTEQUAL; case stencil_test_face::GREATER_OR_EQUAL : return GL_GEQUAL; case stencil_test_face::ALWAYS : return GL_ALWAYS; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type ) { switch( type ) { case stencil_test_face::ZERO : return GL_ZERO; case stencil_test_face::INVERT : return GL_INVERT; case stencil_test_face::KEEP : return GL_KEEP; case stencil_test_face::REPLACE : return GL_REPLACE; case stencil_test_face::INCREMENT : return GL_INCR; case stencil_test_face::DECREMENT : return GL_DECR; case stencil_test_face::INCREMENT_WRAP : return GL_INCR_WRAP; case stencil_test_face::DECREMENT_WRAP : return GL_DECR_WRAP; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::buffer_hint_to_enum( buffer_hint hint ) { switch( hint ) { case STATIC_DRAW : return GL_STATIC_DRAW; case STREAM_DRAW : return GL_STREAM_DRAW; case DYNAMIC_DRAW : return GL_DYNAMIC_DRAW; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::buffer_type_to_enum( buffer_type type ) { switch( type ) { case VERTEX_BUFFER : return GL_ARRAY_BUFFER; case INDEX_BUFFER : return GL_ELEMENT_ARRAY_BUFFER; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::image_format_to_enum( pixel_format format ) { switch( format ) { case RGB : return GL_RGB; case RGBA : return GL_RGBA; case RGB32F : return GL_RGB; case RGBA32F : return GL_RGBA; case RGB16F : return GL_RGB; case RGBA16F : return GL_RGBA; case BGR : return GL_BGR; case BGRA : return GL_BGRA; case RED : return GL_RED; case R16F : return GL_RED; case R32F : return GL_RED; case DEPTH16 : return GL_DEPTH_COMPONENT; case DEPTH24 : return GL_DEPTH_COMPONENT; case DEPTH32 : return GL_DEPTH_COMPONENT; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::image_format_to_internal_enum( pixel_format format ) { switch( format ) { case RGB : return GL_RGB8; case RGBA : return GL_RGBA8; case RGB32F : return GL_RGB32F; case RGBA32F : return GL_RGBA32F; case RGB16F : return GL_RGBA16F; case RGBA16F : return GL_RGBA16F; case BGR : return GL_RGB8; case BGRA : return GL_RGBA8; case RED : return GL_R8; case R16F : return GL_R16F; case R32F : return GL_R32F; case DEPTH16 : return GL_DEPTH_COMPONENT16; case DEPTH24 : return GL_DEPTH_COMPONENT24; case DEPTH32: return GL_DEPTH_COMPONENT32; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::sampler_filter_to_enum( sampler::filter filter ) { switch( filter ) { case sampler::LINEAR : return GL_LINEAR; case sampler::NEAREST : return GL_NEAREST; case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST; case sampler::LINEAR_MIPMAP_NEAREST : return GL_LINEAR_MIPMAP_NEAREST; case sampler::NEAREST_MIPMAP_LINEAR : return GL_NEAREST_MIPMAP_LINEAR; case sampler::LINEAR_MIPMAP_LINEAR : return GL_LINEAR_MIPMAP_LINEAR; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap ) { switch( wrap ) { case sampler::CLAMP_TO_EDGE : return GL_CLAMP_TO_EDGE; case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER; case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT; case sampler::REPEAT : return GL_REPEAT; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::primitive_to_enum( primitive p ) { switch( p ) { case POINTS : return GL_POINTS; case LINES : return GL_LINES; case LINE_LOOP : return GL_LINE_LOOP; case LINE_STRIP : return GL_LINE_STRIP; case TRIANGLES : return GL_TRIANGLES; case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP; case TRIANGLE_FAN : return GL_TRIANGLE_FAN; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::framebuffer_slot_to_enum( framebuffer_slot slot ) { switch( slot ) { case READ_FRAMEBUFFER : return GL_READ_FRAMEBUFFER; case DRAW_FRAMEBUFFER : return GL_DRAW_FRAMEBUFFER; case FRAMEBUFFER : return GL_FRAMEBUFFER; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::output_slot_to_enum( output_slot slot ) { switch( slot ) { case OUTPUT_0 : return GL_COLOR_ATTACHMENT0; case OUTPUT_1 : return GL_COLOR_ATTACHMENT1; case OUTPUT_2 : return GL_COLOR_ATTACHMENT2; case OUTPUT_3 : return GL_COLOR_ATTACHMENT3; case OUTPUT_4 : return GL_COLOR_ATTACHMENT4; case OUTPUT_5 : return GL_COLOR_ATTACHMENT5; case OUTPUT_6 : return GL_COLOR_ATTACHMENT6; case OUTPUT_7 : return GL_COLOR_ATTACHMENT7; case OUTPUT_NONE : return 0; case OUTPUT_FRONT : return GL_FRONT; case OUTPUT_BACK : return GL_BACK; NV_RETURN_COVERED_DEFAULT( 0 ); } } unsigned int nv::datatype_to_gl_enum( datatype type ) { switch( type ) { case BYTE : return GL_BYTE; case UBYTE : return GL_UNSIGNED_BYTE; case SHORT : return GL_SHORT; case USHORT : return GL_UNSIGNED_SHORT; case INT : return GL_INT; case UINT : return GL_UNSIGNED_INT; case FLOAT : return GL_FLOAT; case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2; case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3; case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4; case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2; case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3; case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4; case INT_VECTOR_2 : return GL_INT_VEC2; case INT_VECTOR_3 : return GL_INT_VEC3; case INT_VECTOR_4 : return GL_INT_VEC4; // remove, error or ? case BYTE_VECTOR_2 : return GL_INT_VEC2; case BYTE_VECTOR_3 : return GL_INT_VEC3; case BYTE_VECTOR_4 : return GL_INT_VEC4; // remove, error or ? case UBYTE_VECTOR_2: return GL_INT_VEC2; case UBYTE_VECTOR_3: return GL_INT_VEC3; case UBYTE_VECTOR_4: return GL_INT_VEC4; default: return 0; // TODO: throw! } } nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum ) { switch( gl_enum ) { case GL_BYTE : return BYTE; case GL_UNSIGNED_BYTE : return UBYTE; case GL_SHORT : return SHORT; case GL_UNSIGNED_SHORT : return USHORT; case GL_INT : return INT; case GL_UNSIGNED_INT : return UINT; case GL_FLOAT : return FLOAT; case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2; case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3; case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4; case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2; case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3; case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4; case GL_INT_VEC2 : return INT_VECTOR_2; case GL_INT_VEC3 : return INT_VECTOR_3; case GL_INT_VEC4 : return INT_VECTOR_4; // TODO: separate types? case GL_SAMPLER_1D : return INT; case GL_SAMPLER_2D : return INT; case GL_SAMPLER_3D : return INT; case GL_SAMPLER_2D_RECT : return INT; case GL_SAMPLER_2D_RECT_SHADOW : return INT; case GL_SAMPLER_CUBE : return INT; case GL_SAMPLER_1D_SHADOW : return INT; case GL_SAMPLER_2D_SHADOW : return INT; case GL_SAMPLER_1D_ARRAY : return INT; case GL_SAMPLER_2D_ARRAY : return INT; case GL_SAMPLER_1D_ARRAY_SHADOW: return INT; case GL_SAMPLER_2D_ARRAY_SHADOW: return INT; // TODO: implement? // case GL_BOOL // case GL_BOOL_VEC2 // case GL_BOOL_VEC3 // case GL_BOOL_VEC4 // case GL_FLOAT_MAT2x3 // case GL_FLOAT_MAT2x4 // case GL_FLOAT_MAT3x2 // case GL_FLOAT_MAT3x4 // case GL_FLOAT_MAT4x2 // case GL_FLOAT_MAT4x3 default : return datatype(0); // TODO: throw! } } string_view nv::datatype_to_glsl_type( datatype type ) { switch( type ) { case INT : return "int"; case FLOAT : return "float"; case FLOAT_VECTOR_2 : return "vec2"; case FLOAT_VECTOR_3 : return "vec3"; case FLOAT_VECTOR_4 : return "vec4"; case FLOAT_MATRIX_2 : return "mat2"; case FLOAT_MATRIX_3 : return "mat3"; case FLOAT_MATRIX_4 : return "mat4"; case INT_VECTOR_2 : return "ivec2"; case INT_VECTOR_3 : return "ivec3"; case INT_VECTOR_4 : return "ivec4"; default : return "error"; } }