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

Last change on this file since 90 was 70, checked in by epyon, 12 years ago
  • etype -> datatype
  • types clarifications, and datatype_traits
File size: 8.1 KB
Line 
1// Copyright (C) 2012-2013 Kornel Kisielewicz
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
11unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type )
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
20unsigned int nv::depth_state_function_to_enum( depth_test::function_type type )
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
36unsigned int nv::blending_factor_to_enum( blending::factor type )
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
59unsigned int nv::blending_equation_to_enum( blending::equation type )
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
72unsigned int nv::culling_face_type_to_enum( culling::face_type type )
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
83unsigned int nv::culling_order_type_to_enum( culling::order_type type )
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
93unsigned int nv::stencil_function_to_enum( stencil_test_face::function_type type )
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
109unsigned int nv::stencil_operation_to_enum( stencil_test_face::operation type )
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
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
136unsigned int nv::image_format_to_enum( image_format format )
137{
138        switch( format )
139        {
140        case RGB  : return GL_RGB;
141        case RGBA : return GL_RGBA;
142        default : return 0; // TODO: throw!
143        }
144}
145
146unsigned int nv::sampler_filter_to_enum( sampler::filter filter )
147{
148        switch( filter )
149        {
150        case sampler::LINEAR                 : return GL_LINEAR;
151        case sampler::NEAREST                : return GL_NEAREST;
152        case sampler::NEAREST_MIPMAP_NEAREST : return GL_NEAREST_MIPMAP_NEAREST;
153        case sampler::LINEAR_MIPMAP_NEAREST  : return GL_LINEAR_MIPMAP_NEAREST;
154        case sampler::NEAREST_MIPMAP_LINEAR  : return GL_NEAREST_MIPMAP_LINEAR;
155        case sampler::LINEAR_MIPMAP_LINEAR   : return GL_LINEAR_MIPMAP_LINEAR;
156        default : return 0; // TODO: throw!
157        }
158}
159
160unsigned int nv::sampler_wrap_to_enum( sampler::wrap wrap )
161{
162        switch( wrap )
163        {
164        case sampler::CLAMP_TO_EDGE   : return GL_CLAMP_TO_EDGE;
165        case sampler::CLAMP_TO_BORDER : return GL_CLAMP_TO_BORDER;
166        case sampler::MIRRORED_REPEAT : return GL_MIRRORED_REPEAT;
167        case sampler::REPEAT          : return GL_REPEAT;
168        default : return 0; // TODO: throw!
169        }
170}
171
172unsigned int nv::primitive_to_enum( primitive p )
173{
174        switch( p )
175        {
176        case POINTS         : return GL_POINTS;
177        case LINES          : return GL_LINES;
178        case LINE_LOOP      : return GL_LINE_LOOP;
179        case LINE_STRIP     : return GL_LINE_STRIP;
180        case TRIANGLES      : return GL_TRIANGLES;
181        case TRIANGLE_STRIP : return GL_TRIANGLE_STRIP;
182        case TRIANGLE_FAN   : return GL_TRIANGLE_FAN;
183        default : return 0; // TODO: throw!
184        }
185}
186
187unsigned int nv::datatype_to_gl_enum( datatype type )
188{
189        switch( type )
190        {
191        case BYTE           : return GL_BYTE;
192        case UBYTE          : return GL_UNSIGNED_BYTE;
193        case SHORT          : return GL_SHORT;
194        case USHORT         : return GL_UNSIGNED_SHORT;
195        case INT            : return GL_INT;
196        case UINT               : return GL_UNSIGNED_INT;
197        case FLOAT          : return GL_FLOAT;
198        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
199        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
200        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
201        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
202        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
203        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
204        case INT_VECTOR_2   : return GL_INT_VEC2;
205        case INT_VECTOR_3   : return GL_INT_VEC3;
206        case INT_VECTOR_4   : return GL_INT_VEC4;
207        // remove, error or ?
208        case BYTE_VECTOR_2  : return GL_INT_VEC2;
209        case BYTE_VECTOR_3  : return GL_INT_VEC3;
210        case BYTE_VECTOR_4  : return GL_INT_VEC4;
211        default : return 0; // TODO: throw!
212        }
213}
214
215nv::datatype nv::gl_enum_to_datatype( unsigned int gl_enum )
216{
217        switch( gl_enum )
218        {
219        case GL_BYTE           : return BYTE;
220        case GL_UNSIGNED_BYTE  : return UBYTE;
221        case GL_SHORT          : return SHORT;
222        case GL_UNSIGNED_SHORT : return USHORT;
223        case GL_INT            : return INT;
224        case GL_UNSIGNED_INT   : return UINT;
225        case GL_FLOAT          : return FLOAT;
226        case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
227        case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
228        case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
229        case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
230        case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
231        case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
232        case GL_INT_VEC2       : return INT_VECTOR_2;
233        case GL_INT_VEC3       : return INT_VECTOR_3;
234        case GL_INT_VEC4       : return INT_VECTOR_4;
235        default : return datatype(0); // TODO: throw!
236        }
237}
Note: See TracBrowser for help on using the repository browser.