Katana Plug-in APIs 0.1

FnGLStateHelper.h

00001 // Copyright (c) 2017 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNGLSTATEHELPER_H_
00004 #define FNGLSTATEHELPER_H_
00005 
00006 #include <GL/glew.h>
00007 
00008 namespace Foundry
00009 {
00010 namespace Katana
00011 {
00012 namespace ViewerUtils
00013 {
00014 
00020 
00021 
00022 
00023 
00024 
00025 
00028     enum Bit
00029     {
00030         // GL_ALPHA_TEST flag
00031         // GL_AUTO_NORMAL flag
00032         // GL_BLEND flag
00033         // Enable bits for the user - definable clipping planes
00034         // GL_COLOR_MATERIAL
00035         // GL_CULL_FACE flag
00036         // GL_DEPTH_TEST flag
00037         // GL_DITHER flag
00038         // GL_FOG flag
00039         // GL_LIGHTi where 0 <= i < GL_MAX_LIGHTS
00040         // GL_LIGHTING flag
00041         // GL_LINE_SMOOTH flag
00042         // GL_LINE_STIPPLE flag
00043         // GL_COLOR_LOGIC_OP flag
00044         // GL_INDEX_LOGIC_OP flag
00045         // GL_MAP1_x where x is a map type
00046         // GL_MAP2_x where x is a map type
00047         // GL_MULTISAMPLE flag
00048         // GL_NORMALIZE flag
00049         // GL_POINT_SMOOTH flag
00050         // GL_POLYGON_OFFSET_LINE flag
00051         // GL_POLYGON_OFFSET_FILL flag
00052         // GL_POLYGON_OFFSET_POINT flag
00053         // GL_POLYGON_SMOOTH flag
00054         // GL_POLYGON_STIPPLE flag
00055         // GL_SAMPLE_ALPHA_TO_COVERAGE flag
00056         // GL_SAMPLE_ALPHA_TO_ONE flag
00057         // GL_SAMPLE_COVERAGE flag
00058         // GL_SCISSOR_TEST flag
00059         // GL_STENCIL_TEST flag
00060         // GL_TEXTURE_1D flag
00061         // GL_TEXTURE_2D flag
00062         // GL_TEXTURE_3D flag
00063         // Flags GL_TEXTURE_GEN_x where x is S, T, R, or Q
00064         Enable = GL_ENABLE_BIT,
00065 
00066         //Accumulation buffer clear value
00067         AccumuBuffer = GL_ACCUM_BUFFER_BIT,
00068 
00069         // GL_ALPHA_TEST enable bit
00070         // Alpha test function and reference value
00071         // GL_BLEND enable bit
00072         // Blending source and destination functions
00073         // Constant blend color
00074         // Blending equation
00075         // GL_DITHER enable bit
00076         // GL_DRAW_BUFFER setting
00077         // GL_COLOR_LOGIC_OP enable bit
00078         // GL_INDEX_LOGIC_OP enable bit
00079         // Logic op function
00080         // Color mode and index mode clear values
00081         // Color mode and index mode writemasks
00082         ColorBuffer = GL_COLOR_BUFFER_BIT,
00083 
00084         // Current RGBA color
00085         // Current color index
00086         // Current normal vector
00087         // Current texture coordinates
00088         // Current raster position
00089         // GL_CURRENT_RASTER_POSITION_VALID flag
00090         // RGBA color associated with current raster position
00091         // Color index associated with current raster position
00092         // Texture coordinates associated with current raster position
00093         // GL_EDGE_FLAG flag
00094         Current = GL_CURRENT_BIT,
00095 
00096         // GL_DEPTH_TEST enable bit
00097         // Depth buffer test function
00098         // Depth buffer clear value
00099         // GL_DEPTH_WRITEMASK enable bit
00100         DepthBuffer = GL_DEPTH_BUFFER_BIT,
00101 
00102         // GL_MAP1_x enable bits, where x is a map type
00103         // GL_MAP2_x enable bits, where x is a map type
00104         // 1D grid endpoints and divisions
00105         // 2D grid endpoints and divisions
00106         // GL_AUTO_NORMAL enable bit
00107         Eval = GL_EVAL_BIT,
00108 
00109         // GL_FOG enable bit
00110         // Fog color
00111         // Fog density
00112         // Linear fog start
00113         // Linear fog end
00114         // Fog index
00115         // GL_FOG_MODE value
00116         Fog = GL_FOG_BIT,
00117 
00118         // GL_PERSPECTIVE_CORRECTION_HINT setting
00119         // GL_POINT_SMOOTH_HINT setting
00120         // GL_LINE_SMOOTH_HINT setting
00121         // GL_POLYGON_SMOOTH_HINT setting
00122         // GL_FOG_HINT setting
00123         // GL_GENERATE_MIPMAP_HINT setting
00124         // GL_TEXTURE_COMPRESSION_HINT setting
00125         Hint = GL_HINT_BIT,
00126 
00127         // GL_COLOR_MATERIAL enable bit
00128         // GL_COLOR_MATERIAL_FACE value
00129         // Color material parameters that are tracking the current color
00130         // Ambient scene color
00131         // GL_LIGHT_MODEL_LOCAL_VIEWER value
00132         // GL_LIGHT_MODEL_TWO_SIDE setting
00133         // GL_LIGHTING enable bit
00134         // Enable bit for each light
00135         // Ambient, diffuse, and specular intensity for each light
00136         // Direction, position, exponent, and cutoff angle for each light
00137         // Constant, linear, and quadratic attenuation factors for each light
00138         // Ambient, diffuse, specular, and emissive color for each material
00139         // Ambient, diffuse, and specular color indices for each material
00140         // Specular exponent for each material
00141         // GL_SHADE_MODEL setting
00142         Lighting = GL_LIGHTING_BIT,
00143 
00144         // GL_LINE_SMOOTH flag
00145         // GL_LINE_STIPPLE enable bit
00146         // Line stipple pattern and repeat counter
00147         // Line width
00148         Line = GL_LINE_BIT,
00149 
00150         // GL_LIST_BASE setting
00151         List = GL_LIST_BIT,
00152 
00153         // GL_MULTISAMPLE flag
00154         // GL_SAMPLE_ALPHA_TO_COVERAGE flag
00155         // GL_SAMPLE_ALPHA_TO_ONE flag
00156         // GL_SAMPLE_COVERAGE flag
00157         // GL_SAMPLE_COVERAGE_VALUE value
00158         // GL_SAMPLE_COVERAGE_INVERT value
00159         Multisample = GL_MULTISAMPLE_BIT,
00160 
00161         // GL_RED_BIAS and GL_RED_SCALE settings
00162         // GL_GREEN_BIAS and GL_GREEN_SCALE values
00163         // GL_BLUE_BIAS and GL_BLUE_SCALE
00164         // GL_ALPHA_BIAS and GL_ALPHA_SCALE
00165         // GL_DEPTH_BIAS and GL_DEPTH_SCALE
00166         // GL_INDEX_OFFSET and GL_INDEX_SHIFT values
00167         // GL_MAP_COLOR and GL_MAP_STENCIL flags
00168         // GL_ZOOM_X and GL_ZOOM_Y factors
00169         // GL_READ_BUFFER setting
00170         PixelMode = GL_PIXEL_MODE_BIT,
00171 
00172         // GL_POINT_SMOOTH flag
00173         // Point size
00174         Point = GL_POINT_BIT,
00175 
00176         // GL_CULL_FACE enable bit
00177         // GL_CULL_FACE_MODE value
00178         // GL_FRONT_FACE indicator
00179         // GL_POLYGON_MODE setting
00180         // GL_POLYGON_SMOOTH flag
00181         // GL_POLYGON_STIPPLE enable bit
00182         // GL_POLYGON_OFFSET_FILL flag
00183         // GL_POLYGON_OFFSET_LINE flag
00184         // GL_POLYGON_OFFSET_POINT flag
00185         // GL_POLYGON_OFFSET_FACTOR
00186         // GL_POLYGON_OFFSET_UNITS
00187         Polygon = GL_POLYGON_BIT,
00188 
00189         // Polygon stipple image
00190         PolygonStipple = GL_POLYGON_STIPPLE_BIT,
00191 
00192         // GL_SCISSOR_TEST flag
00193         // Scissor box
00194         Scissor = GL_SCISSOR_BIT,
00195 
00196         // GL_STENCIL_TEST enable bit
00197         // Stencil function and reference value
00198         // Stencil value mask
00199         // Stencil fail, pass, and depth buffer pass actions
00200         // Stencil buffer clear value
00201         // Stencil buffer writemask
00202         StencilBuffer = GL_STENCIL_BUFFER_BIT,
00203 
00204         // Enable bits for the four texture coordinates
00205         // Border color for each texture image
00206         // Minification function for each texture image
00207         // Magnification function for each texture image
00208         // Texture coordinates and wrap mode for each texture image
00209         // Color and mode for each texture environment
00210         // Enable bits GL_TEXTURE_GEN_x, x is S, T, R, and Q
00211         // GL_TEXTURE_GEN_MODE setting for S, T, R, and Q
00212         // glTexGen plane equations for S, T, R, and Q
00213         // Current texture bindings(for example, GL_TEXTURE_BINDING_2D)
00214         Texture = GL_TEXTURE_BIT,
00215 
00216         // Coefficients of the six clipping planes
00217         // Enable bits for the user - definable clipping planes
00218         // GL_MATRIX_MODE value
00219         // GL_NORMALIZE flag
00220         // GL_RESCALE_NORMAL flag
00221         Transform = GL_TRANSFORM_BIT,
00222 
00223         // Depth range (near and far)
00224         // Viewport origin and extent
00225         Viewport = GL_VIEWPORT_BIT,
00226     };
00227 
00229     enum Binding
00230     {
00231         // glBindBuffer(GL_ARRAY_BUFFER, 0)
00232         UnbindArrayBuffer = 1u << 0u,
00233         // glBindTexture(GL_TEXTURE_2D, 0)
00234         UnbindTexture = 1u << 1u,
00235         // glBindVertexArray(0)
00236         UnbindVertexArray = 1u << 2u,
00237         // glUseProgram(0);
00238         UnbindProgram = 1u << 3u,
00239 
00240         // Unbind all.
00241         UnbindAll = UnbindArrayBuffer | UnbindTexture | UnbindVertexArray |
00242                     UnbindProgram
00243     };
00244 
00246     class GLStateRestore
00247     {
00248         using Bindings = unsigned;
00249 
00250     public:
00253         explicit GLStateRestore(GLbitfield mask, Bindings bindings = 0)
00254             : m_bindings{bindings}
00255         {
00256             glPushAttrib(mask);
00257         }
00258 
00260         ~GLStateRestore()
00261         {
00262             glPopAttrib();
00263             if (m_bindings)
00264             {
00265                 if (m_bindings & UnbindArrayBuffer)
00266                     glBindBuffer(GL_ARRAY_BUFFER, 0);
00267                 if (m_bindings & UnbindTexture)
00268                     glBindTexture(GL_TEXTURE_2D, 0);
00269                 if (m_bindings & UnbindVertexArray)
00270                     glBindVertexArray(0);
00271                 if (m_bindings & UnbindProgram)
00272                     glUseProgram(0);
00273             }
00274         }
00275 
00276     private:
00277         Bindings m_bindings;
00278     };
00281 }  // namespace ViewerUtils
00282 }  // namespace Katana
00283 }  // namespace Foundry
00284 
00285 #endif  // FNGLSTATEHELPER_H_
 All Classes Functions Variables Typedefs Enumerations Enumerator