GL Studio SCECpp Runtime Library
gls_render_object.h
Go to the documentation of this file.
1 #ifndef _GLS_RENDER_OBJECT_H
2 #define _GLS_RENDER_OBJECT_H
3 
4 /*! \file gls_render_object.h
5 \brief This header defines an abstract class for a display object that is
6  directly rendered to OpenGL (not a composite of other objects) and
7  maintains its own draw settings.
8  GL Studio DO-178B Runtime Library
9 
10 \par Copyright Information
11 Copyright (C) 1999-2012 The DiSTI Corporation<br>
12 Orlando, FL USA<br>
13 All rights reserved.<br>
14 
15  This file is copyrighted software and contains proprietary trade secrets of
16 DiSTI, and embodies substantial creative efforts as well as confidential
17 information, ideas, and expressions.
18 
19  Permission to use, and copy this software and its documentation for any
20 purpose is hereby granted per the Distribution Agreement and/or the Licensing
21 Agreement signed with DiSTI. This permission is granted provided that:
22  1. The above copyright notice appears in all copies.
23  2. That both the copyright notice and this permission notice appear in
24  the supporting documentation.
25  3. That the names DiSTI and GL Studio not be used in advertising or
26  publicity pertaining to distribution of the software without specific,
27  written prior permission of DiSTI.
28 
29  Permission to modify the software is granted, but not the right to
30 distribute the source code whether modified, or non-modified. Modifying the
31 software might invalidate the DO-178B certification package.
32 
33  Permission to distribute binaries produced by compiling source code, or
34 modified source code is granted, provided you:
35  1. Provide your name and address as the primary contact for the support
36  of your modified version.
37  2. Retain our contact information in regard to use of the base software.
38 
39  DiSTI does not provide warranty for this software or guarantee that it
40 satisfies any specification or requirement unless otherwise stated in a
41 specific contractual arrangement between the customer and DiSTI.
42 
43 */
44 
45 #include "gls_include.h"
46 #include "gls_display_object.h"
47 #include "gls_render_settings.h"
48 #include "gls_texture_palette.h"
49 
50 /** Defines an abstract class for a display object that is
51  * directly rendered to OpenGL (not a composite of other objects) and
52  * maintains its own draw settings
53  * \invariant base class invariant holds,
54  * _texturePalette.Invariant();
55  * GlsTextureMapModeIsValid( _textureMapMode ),
56  * GlsTextureFilterModeIsValid( _textureMagFilterMode ),
57  * GlsTextureFilterModeIsValid( _textureMinFilterMode ),
58  * GlsDepthBufferModeIsValid( _depthBufferMode ),
59  * GlsPolygonEndModeIsValid( _polygonEndMode ),
60  * GlsAlphaModeIsValid( _alphaMode ),
61  * _lineColor.IsValid(),
62  * ( GlsTexturePalette::NO_TEXTURE == _textureIndex ) ||
63  * ( _textureIndex < _texturePalette.GetSize() ),
64  * GlsPolygonModeIsValid( _polygonMode ),
65  * GlsShadingModeIsValid( _shadingMode ),
66  * _fillColor.IsValid(),
67  * GlsLineWidthIsValid( _lineWidth )
68  */
70 {
71 public:
73 
74  #if defined( GLS_DEBUG )
75  /** minimum allowable line width */
76  static const GlsFloat32 LINE_WIDTH_MIN;
77  /** maximum allowable line width */
78  static const GlsFloat32 LINE_WIDTH_MAX;
79  #endif // GLS_DEBUG
80 
81  /** initialization parameters for a GlsRenderObject */
83  {
84  const GlsDisplayObject::InitParameters displayInitParameters; /**< init parameters for base class */
85 
86  const GlsAlphaMode alphaMode; /**< initial alpha mode */
87  const GlsBool antiAlias; /**< GLS_TRUE if object is antialiased
88  * else GLS_FALSE */
89  const GlsBool cullBackFace; /**< GLS_TRUE if backface culling is enabled
90  * else GLS_FALSE */
91  const GlsDepthBufferMode depthBufferMode; /**< Depth buffer test / write mode */
92  const GlsColor fillColor; /**< initial fill color */
93  const GlsColor lineColor; /**< initial line color */
94  const GlsFloat32 lineWidth; /**< initial line width in pixels,
95  * GlsRenderObject::LINE_WIDTH_MIN <= lineWidth,
96  * lineWidth <= GlsRenderObject::LINE_WIDTH_MAX */
97  const GlsPolygonMode polygonMode; /**< initial polygon mode */
98  const GlsPolygonEndMode polygonEndMode; /**< Polygon end mode */
99  const GlsShadingMode shadingMode; /**< Shading mode */
100  const GlsUInt32 textureIndex; /**< initial texture index into palette
101  * else GlsTexturePalette::NO_TEXTURE */
102  const GlsTextureMapMode textureMapMode; /**< texture mapping mode */
103  const GlsTextureFilterMode textureMagFilterMode; /**< texture magnification filtering mode */
104  const GlsTextureFilterMode textureMinFilterMode; /**< texture minification filtering mode */
105  const GlsTexturePalette* const *texturePalette; /**< palette of textures available */
106  const GlsBool textureRepeat; /**< GLS_TRUE to enable texture repeat
107  * else GLS_FALSE for texture clamp */
108 
109  #if defined( GLS_DEBUG )
110  /** Determine if the initialization parameters are valid ( GLS_DEBUG only )
111  * \return GLS_TRUE if valid else GLS_FALSE
112  * \pre none
113  * \post none
114  */
115  GlsBool IsValid( void ) const;
116  #endif // GLS_DEBUG
117  };
118 
119  /** Set the alpha mode
120  * \param alphaMode desired alpha mode
121  * \pre GlsAlphaModeIsValid( alphaMode )
122  * \post object has new alpha mode
123  */
124  virtual void SetAlphaMode( const GlsAlphaMode alphaMode );
125 
126  /** Set the fill color
127  * \param fillColor desired fill color
128  * \pre fillColor.IsValid()
129  * \post object has new fill color
130  */
131  virtual void SetFillColor( const GlsColor &fillColor );
132 
133  /** Set the line color
134  * \param lineColor desired line color
135  * \pre lineColor.IsValid()
136  * \post object has new line color
137  */
138  virtual void SetLineColor( const GlsColor &lineColor );
139 
140  /** Set the line width
141  * \param lineWidth new line width,
142  * GlsRenderObject::LINE_WIDTH_MIN <= lineWidth <= GlsRenderObject::LINE_WIDTH_MAX
143  * \pre GlsLineWidthIsValid( lineWidth )
144  * \post object has new line width
145  */
146  virtual void SetLineWidth( const GlsFloat32 lineWidth );
147 
148  /** Set the polygon mode
149  * \param polygonMode new polygon mode
150  * \pre GlsPolygonModeIsValid( polygonMode )
151  * \post object has new polygon mode
152  */
153  virtual void SetPolygonMode( const GlsPolygonMode polygonMode );
154 
155  /** Set the desired texture index
156  * \param textureIndex desired texture index into palette else GlsTexturePalette::NO_TEXTURE
157  * \pre textureIndex is less than the size of the texture palette, else GlsTexturePalette::NO_TEXTURE,
158  * object's texture palette must have a valid texture (not an empty palette entry) at textureIndex
159  * if textureIndex != GlsTexturePalette::NO_TEXTURE
160  * \post object has new texture index or is untextured if textureIndex == GlsTexturePalette::NO_TEXTURE
161  */
162  virtual void SetTextureIndex( const GlsUInt32 textureIndex );
163 
164  /** Offset the texture on the object
165  * \param offset x, y offset for texture
166  * \pre offset.IsValid()
167  * \post offset is added to the texture coordinates
168  */
169  virtual void OffsetTexture( const GlsVector2D &offset ) = 0;
170 
171 protected:
172  static const GLclampf ALPHA_MODE_2_LEVEL_REF; /**< alpha function reference value when in 2 level alpha mode */
173 
174  const GlsBool _antiAlias; /**< GLS_TRUE if antialiasing is enabled else GLS_FALSE */
175  const GlsTexturePalette &_texturePalette; /**< palette with textures available to object */
176  const GlsBool _textureRepeat; /**< GLS_TRUE to enable texture repeat
177  * else GLS_FALSE for texture clamp */
178  const GlsTextureMapMode _textureMapMode; /**< texture mapping mode */
179  const GlsTextureFilterMode _textureMagFilterMode; /**< texture magnification filter mode */
180  const GlsTextureFilterMode _textureMinFilterMode; /**< texture minification filter mode */
181  const GlsBool _cullBackFace; /**< GLS_TRUE if backface culling is enabled else GLS_FALSE */
182  const GlsDepthBufferMode _depthBufferMode; /**< depth buffer test / write mode */
183  const GlsPolygonEndMode _polygonEndMode; /**< Polygon close mode */
184  const GlsShadingMode _shadingMode; /**< shading mode */
185 
186  GlsAlphaMode _alphaMode; /**< alpha mode */
187  GlsColor _lineColor; /**< line color */
188  GlsUInt32 _textureIndex; /**< texture index into palette
189  * else GlsTexturePalette::NO_TEXTURE */
190  GlsPolygonMode _polygonMode; /**< polygon mode */
191  GlsColor _fillColor; /**< fill color */
192  GlsFloat32 _lineWidth; /**< line width in pixels,
193  * GlsRenderObject::LINE_WIDTH_MIN <= lineWidth <= GlsRenderObject::LINE_WIDTH_MAX */
194 
195  /** Construct with given initialization parameters
196  * \param initParameters initialization parameters
197  * \param eventDispatcher event dispatcher for this object else GLS_NULL
198  * \pre initParameters.IsValid()
199  * \post object constructed
200  */
201  GlsRenderObject( const InitParameters &initParameters, GlsEventDispatcher* const eventDispatcher );
202 
203  /** Get the GL texture filter enum for the correspoding GlsTextureFilterMode
204  * \param mode GlsTextureFilterMode in question
205  * \return GL texture filer enum for the given GlsTextureFilterMode
206  * \pre GlsTextureFilterModeIsValid( mode )
207  * \post none
208  */
209  GLint GlsTextureFilterModeToGL( const GlsTextureFilterMode mode ) const;
210 
211  /** Setup the GL depth settings based on current object settings
212  * \param gl GL state manager to setup
213  * \pre GlsDepthBufferModeIsValid( _depthBufferMode )
214  * \post GL depth settings are set based on current object settings
215  */
216  void SetupDepthTest( GlsStateManager &gl ) const;
217 
218  /** Setup the GL alpha test and blend settings based on the current object settings
219  * \param gl GL state manager to setup
220  * \pre GlsAlphaModeIsValid( _alphaMode )
221  * \post GL alpha test and blend settings are set based on current object settings
222  */
223  void SetupAlpha( GlsStateManager &gl ) const;
224 
225  /** Setup GL with the proper texture binding and parameters as indicated by the current
226  * object settings and the given texture index
227  * \param gl GL state manager to setup
228  * \param textureIndex index of texture to setup
229  * \return GLS_TRUE if this object has a texture else GLS_FALSE
230  * \pre ( textureIndex == GlsTexturePalette::NO_TEXTURE ) else ( textureIndex < _texturePalette.GetSize()
231  * and _texturePalette does not have an empty slot at textureIndex ),
232  * GlsTextureMapModeIsValid( _textureMapMode ), GlsTextureFilterModeIsValid( _textureMagFilterMode ),
233  * GlsTextureFilterModeIsValid( _textureMinFilterMode ),
234  * \post GL texture binding and parameters are setup as indicated by the current object settings
235  */
236  GlsBool SetupTexture( GlsStateManager &gl, const GlsUInt32 textureIndex ) const;
237 
238  /** Setup GL with the proper texture filter settings based on the current object settings.
239  * \param gl GL state manager to setup
240  * \pre GlsTextureFilterModeIsValid( _textureMagFilterMode ), GlsTextureFilterModeIsValid( _textureMinFilterMode )
241  * \post GL texture filter settings are setup based on the current object settings
242  */
244 
245  /** Setup GL with the proper backface culling mode based on the current object settings
246  * \param gl GL state manager to setup
247  * \pre none
248  * \post GL backface culling mode is setup based on the current object settings
249  */
250  void SetupBackfaceCulling( GlsStateManager &gl ) const;
251 
252  /** Setup GL with the proper shading settings based on the current object settings
253  * \param gl GL state manager to setup
254  * \pre GlsShadingModeIsValid( _shadingMode )
255  * \post GL shading settings are setup based on the current object settings
256  */
257  void SetupShading( GlsStateManager &gl ) const;
258 
259  /** Setup GL with the proper line style settings based on the current object settings
260  * \param gl GL state manager to setup
261  * \pre GlsLineWidthIsValid( _lineWidth )
262  * \post GL line style settings are setup based on the current object settings
263  */
264  void SetupLineStyle( GlsStateManager &gl ) const;
265 
266  /** Setup GL with the proper antialias settings based on the current object settings
267  * \param gl GL state manager to setup
268  * \pre none
269  * \post GL antialias settings are setup based on the current object settings
270  */
271  void SetupAntiAlias( GlsStateManager &gl ) const;
272 
273  /** Destructor - shall never be called
274  * \pre none
275  * \post none
276  */
277  virtual ~GlsRenderObject();
278 
279 private:
280  typedef GlsDisplayObject _BaseClass; /**< base class alias */
281 
282  // Disable implicit generated Members
283  GlsRenderObject& operator=( const GlsRenderObject &rhs );
284  GlsRenderObject( const GlsRenderObject &src );
285 };
286 
287 #if defined( GLS_DEBUG )
288 #pragma BullseyeCoverage save off
289 /** Determine if the given line width is valid ( GLS_DEBUG only )
290  * \param lineWidth line width in question
291  * \return GLS_TRUE if valid else GLS_FALSE
292  * \pre none
293  * \post none
294  */
295 inline GlsBool GlsLineWidthIsValid( const GlsFloat32 lineWidth )
296 {
297  return( ( GlsRenderObject::LINE_WIDTH_MIN <= lineWidth ) && ( lineWidth <= GlsRenderObject::LINE_WIDTH_MAX ) );
298 }
299 #pragma BullseyeCoverage restore
300 #endif // GLS_DEBUG
301 
302 #endif // _GLS_RENDER_OBJECT_H
void SetupShading(GlsStateManager &gl) const
Definition: gls_render_object.h:69
const GlsBool cullBackFace
Definition: gls_render_object.h:89
Definition: gls_color.h:47
const GlsBool _antiAlias
Definition: gls_render_object.h:174
bool GlsBool
Definition: gls_types.h:96
GlsAlphaMode _alphaMode
Definition: gls_render_object.h:186
void SetupAntiAlias(GlsStateManager &gl) const
const GlsPolygonEndMode _polygonEndMode
Definition: gls_render_object.h:183
virtual void SetPolygonMode(const GlsPolygonMode polygonMode)
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
This header defines the basic render setting types used in the GL Studio DO-178B Runtime Library...
virtual void SetLineColor(const GlsColor &lineColor)
void SetupTextureFilterSettings(GlsStateManager &gl) const
Definition: gls_state_manager.h:63
GlsBool SetupTexture(GlsStateManager &gl, const GlsUInt32 textureIndex) const
const GlsTexturePalette *const * texturePalette
Definition: gls_render_object.h:105
const GlsTexturePalette & _texturePalette
Definition: gls_render_object.h:175
const GlsTextureFilterMode textureMagFilterMode
Definition: gls_render_object.h:103
const GlsColor fillColor
Definition: gls_render_object.h:92
Definition: gls_display_object.h:110
GlsPolygonMode _polygonMode
Definition: gls_render_object.h:190
GlsColor _fillColor
Definition: gls_render_object.h:191
virtual void SetAlphaMode(const GlsAlphaMode alphaMode)
const GlsTextureFilterMode _textureMagFilterMode
Definition: gls_render_object.h:179
unsigned int GlsUInt32
Definition: gls_types.h:73
virtual void SetFillColor(const GlsColor &fillColor)
GlsAlphaMode
Definition: gls_render_settings.h:162
const GlsTextureFilterMode _textureMinFilterMode
Definition: gls_render_object.h:180
Definition: gls_event.h:304
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
GlsColor _lineColor
Definition: gls_render_object.h:187
const GlsDisplayObject::InitParameters displayInitParameters
Definition: gls_render_object.h:84
const GlsShadingMode _shadingMode
Definition: gls_render_object.h:184
const GlsAlphaMode alphaMode
Definition: gls_render_object.h:86
Definition: gls_texture_palette.h:54
virtual void SetLineWidth(const GlsFloat32 lineWidth)
GlsUInt32 _textureIndex
Definition: gls_render_object.h:188
const GlsBool _cullBackFace
Definition: gls_render_object.h:181
void SetupLineStyle(GlsStateManager &gl) const
const GlsBool antiAlias
Definition: gls_render_object.h:87
float GlsFloat32
Definition: gls_types.h:78
static const GLclampf ALPHA_MODE_2_LEVEL_REF
Definition: gls_render_object.h:172
GlsTextureMapMode
Definition: gls_render_settings.h:47
const GlsTextureMapMode textureMapMode
Definition: gls_render_object.h:102
const GlsPolygonEndMode polygonEndMode
Definition: gls_render_object.h:98
Definition: gls_display_object.h:64
virtual void OffsetTexture(const GlsVector2D &offset)=0
GlsFloat32 _lineWidth
Definition: gls_render_object.h:192
GlsShadingMode
Definition: gls_render_settings.h:216
GlsDepthBufferMode
Definition: gls_render_settings.h:104
GLint GlsTextureFilterModeToGL(const GlsTextureFilterMode mode) const
void SetupDepthTest(GlsStateManager &gl) const
Definition: gls_render_object.h:82
const GlsDepthBufferMode depthBufferMode
Definition: gls_render_object.h:91
Definition: gls_vertex.h:49
virtual ~GlsRenderObject()
This header defines the base class for all graphical objects in the GL Studio DO-178B Runtime Library...
const GlsTextureMapMode _textureMapMode
Definition: gls_render_object.h:178
const GlsFloat32 lineWidth
Definition: gls_render_object.h:94
const GlsUInt32 textureIndex
Definition: gls_render_object.h:100
GlsPolygonMode
Definition: gls_render_settings.h:131
const GlsPolygonMode polygonMode
Definition: gls_render_object.h:97
virtual void SetTextureIndex(const GlsUInt32 textureIndex)
GlsPolygonEndMode
Definition: gls_render_settings.h:191
const GlsTextureFilterMode textureMinFilterMode
Definition: gls_render_object.h:104
GlsRenderObject(const InitParameters &initParameters, GlsEventDispatcher *const eventDispatcher)
void SetupBackfaceCulling(GlsStateManager &gl) const
This header defines the GlsTexturePalette class used in the GL Studio DO-178B Runtime Library...
const GlsColor lineColor
Definition: gls_render_object.h:93
void SetupAlpha(GlsStateManager &gl) const
const GlsBool textureRepeat
Definition: gls_render_object.h:106
const GlsBool _textureRepeat
Definition: gls_render_object.h:176
const GlsDepthBufferMode _depthBufferMode
Definition: gls_render_object.h:182
const GlsShadingMode shadingMode
Definition: gls_render_object.h:99
GlsTextureFilterMode
Definition: gls_render_settings.h:77