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

Last change on this file since 35 was 35, checked in by epyon, 12 years ago
  • gl_enum helper functions
  • gl_names GL name handling
File size: 5.7 KB
RevLine 
[35]1// Copyright (C) 2011 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 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 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 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 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 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 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 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 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 type_to_gl_enum( type type )
126{
127        switch( type )
128        {
129        case FLOAT          : return GL_FLOAT;
130        case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
131        case FLOAT_VECTOR_3 : return GL_FLOAT_VEC3;
132        case FLOAT_VECTOR_4 : return GL_FLOAT_VEC4;
133        case FLOAT_MATRIX_2 : return GL_FLOAT_MAT2;
134        case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
135        case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
136        case INT            : return GL_INT;
137        case INT_VECTOR_2   : return GL_INT_VEC2;
138        case INT_VECTOR_3   : return GL_INT_VEC3;
139        case INT_VECTOR_4   : return GL_INT_VEC4;
140        default : return 0; // TODO: throw!
141        }
142}
143
144nv::type gl_enum_to_type( unsigned int gl_enum )
145{
146        switch( gl_enum )
147        {
148        case GL_FLOAT      : return FLOAT;
149        case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
150        case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
151        case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
152        case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
153        case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
154        case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
155        case GL_INT        : return INT;
156        case GL_INT_VEC2   : return INT_VECTOR_2;
157        case GL_INT_VEC3   : return INT_VECTOR_3;
158        case GL_INT_VEC4   : return INT_VECTOR_4;
159        default : return type(0); // TODO: throw!
160        }
161}
Note: See TracBrowser for help on using the repository browser.