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

Last change on this file since 43 was 43, checked in by epyon, 12 years ago
  • texture2d object interface and implementation
File size: 7.5 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::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
146unsigned 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
157unsigned 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
171unsigned 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
183
184unsigned int nv::type_to_gl_enum( type type )
185{
186        switch( type )
187        {
188        case FLOAT          : return GL_FLOAT;
189        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
190        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
191        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
192        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
193        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
194        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
195        case INT            : return GL_INT;
196        case INT_VECTOR_2   : return GL_INT_VEC2;
197        case INT_VECTOR_3   : return GL_INT_VEC3;
198        case INT_VECTOR_4   : return GL_INT_VEC4;
199        default : return 0; // TODO: throw!
200        }
201}
202
203nv::type nv::gl_enum_to_type( unsigned int gl_enum )
204{
205        switch( gl_enum )
206        {
207        case GL_FLOAT      : return FLOAT;
208        case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
209        case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
210        case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
211        case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
212        case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
213        case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
214        case GL_INT        : return INT;
215        case GL_INT_VEC2   : return INT_VECTOR_2;
216        case GL_INT_VEC3   : return INT_VECTOR_3;
217        case GL_INT_VEC4   : return INT_VECTOR_4;
218        default : return type(0); // TODO: throw!
219        }
220}
Note: See TracBrowser for help on using the repository browser.