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

Last change on this file since 42 was 42, checked in by epyon, 12 years ago
  • vertex_buffer interface and implementation
File size: 6.0 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;
32        default : return 0; // TODO: throw!
33        }
34}
35
[40]36unsigned 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]59unsigned 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]72unsigned 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]83unsigned 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]93unsigned 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]109unsigned 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]125unsigned 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
[40]136unsigned int nv::type_to_gl_enum( type type )
[35]137{
138        switch( type )
139        {
140        case FLOAT          : return GL_FLOAT;
141        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
142        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
143        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
144        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
145        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
146        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
147        case INT            : return GL_INT;
148        case INT_VECTOR_2   : return GL_INT_VEC2;
149        case INT_VECTOR_3   : return GL_INT_VEC3;
150        case INT_VECTOR_4   : return GL_INT_VEC4;
151        default : return 0; // TODO: throw!
152        }
153}
154
[40]155nv::type nv::gl_enum_to_type( unsigned int gl_enum )
[35]156{
157        switch( gl_enum )
158        {
159        case GL_FLOAT      : return FLOAT;
160        case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
161        case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
162        case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
163        case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
164        case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
165        case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
166        case GL_INT        : return INT;
167        case GL_INT_VEC2   : return INT_VECTOR_2;
168        case GL_INT_VEC3   : return INT_VECTOR_3;
169        case GL_INT_VEC4   : return INT_VECTOR_4;
170        default : return type(0); // TODO: throw!
171        }
172}
Note: See TracBrowser for help on using the repository browser.