Free Electron
DrawOpenGL.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __opengl_DrawOpenGL_h__
8 #define __opengl_DrawOpenGL_h__
9 
10 #define DGL_CYLINDER_GLU FALSE // replace default with glu version
11 #define DGL_SPHERE_GLU TRUE // replace default with glu version
12 
13 #define DGL_DEFAULT_TEXTURE_SIZE 256
14 
15 namespace fe
16 {
17 namespace ext
18 {
19 
20 /**************************************************************************//**
21  @brief OpenGL-specific implementations for DrawI
22 
23  @ingroup opengl
24 *//***************************************************************************/
25 class FE_DL_EXPORT DrawOpenGL: public DrawCommon,
26  public Initialize<DrawOpenGL>
27 {
28  public:
29 
30  DrawOpenGL();
31 virtual ~DrawOpenGL();
32 
33  void initialize(void);
34 
35 virtual BWORD isDirect(void) const { return m_isDirect; }
36 virtual void flush(void);
37 
38 virtual void pushMatrixState(void);
39 virtual void popMatrixState(void);
40 
41 virtual void pushMatrix(MatrixMode a_mode,Real a_values[16]);
42 virtual void popMatrix(MatrixMode a_mode);
43 
44 virtual void unbindVertexArray(void);
45 
46 virtual void setBrightness(Real a_brightness);
47 virtual void setContrast(Real a_contrast);
48 
49 virtual void setDrawMode(sp<DrawMode> spMode);
50 
51 virtual sp<FontI> font(void)
52  { assureFont();
53  return m_spFont; }
54 
55 virtual Real multiplication(void);
56 
58 
59 virtual void drawPoints(const SpatialVector *vertex,
60  const SpatialVector *normal,U32 vertices,
61  BWORD multicolor,const Color *color,
62  sp<DrawBufferI> spDrawBuffer);
63 
65 
66 virtual void drawLines(const SpatialVector *vertex,
67  const SpatialVector *normal,U32 vertices,
68  StripMode strip,
69  BWORD multicolor,const Color *color,
70  BWORD multiradius,const Real *radius,
71  const Vector3i *element,U32 elementCount,
72  sp<DrawBufferI> spDrawBuffer);
73 
75 
76 virtual void drawTriangles(const SpatialVector *vertex,
77  const SpatialVector *normal,
78  const Vector2 *texture,U32 vertices,
79  StripMode strip,BWORD multicolor,
80  const Color *color,
81  const Array<I32>* vertexMap,
82  const Array<I32>* hullPointMap,
83  const Array<Vector4i>* hullFacePoint,
84  sp<DrawBufferI> spDrawBuffer);
85 
86 virtual void drawRectangles(const SpatialVector *vertex,U32 vertices,
87  BWORD multicolor,const Color *color);
88 
89 virtual void drawAlignedText(const SpatialVector &location,
90  const String text,const Color &color);
91 
92 #if DGL_CYLINDER_GLU
93 virtual void drawCylinder(const SpatialTransform &transform,
94  const SpatialVector *scale,
95  Real baseScale,const Color &color,U32 slices)
96  { drawCylinderGLU(transform,scale,baseScale,
97  color,slices); }
98 #endif
99 
100 #if DGL_SPHERE_GLU
101 virtual void drawSphere(const SpatialTransform &transform,
102  const SpatialVector *scale,const Color &color)
103  { drawSphereGLU(transform,scale,color); }
104 #endif
105 
106  using DrawCommon::drawTransformedPoints;
107 
108 virtual void drawTransformedPoints(
109  const SpatialTransform &transform,
110  const SpatialVector *scale,
111  const SpatialVector *vertex,
112  const SpatialVector *normal,U32 vertices,
113  BWORD multicolor,const Color *color,
114  sp<DrawBufferI> spDrawBuffer);
115 
116  using DrawCommon::drawTransformedLines;
117 
118 virtual void drawTransformedLines(
119  const SpatialTransform &transform,
120  const SpatialVector *scale,
121  const SpatialVector *vertex,
122  const SpatialVector *normal,
123  U32 vertices,StripMode strip,
124  BWORD multicolor,const Color *color,
125  BWORD multiradius,const Real *radius,
126  const Vector3i *element,U32 elementCount,
127  sp<DrawBufferI> spDrawBuffer);
128 
129  using DrawCommon::drawTransformedTriangles;
130 
131 virtual void drawTransformedTriangles(
132  const SpatialTransform &transform,
133  const SpatialVector *scale,
134  const SpatialVector *vertex,
135  const SpatialVector *normal,
136  const Vector2 *texture,
137  U32 vertices,StripMode strip,BWORD multicolor,
138  const Color *color,
139  const Array<I32>* vertexMap,
140  const Array<I32>* hullPointMap,
141  const Array<Vector4i>* hullFacePoint,
142  sp<DrawBufferI> spDrawBuffer);
143 
144 virtual void drawRaster(sp<ImageI> spImageI,
145  const SpatialVector& location);
146 
147 virtual sp<DrawBufferI> createBuffer(void);
148 
149  protected:
150 
151 virtual void createDefaultView(void);
152 
153 virtual void drawPolys(U32 grain,const SpatialVector *vertex,
154  const SpatialVector *normal,
155  const Vector2 *texture,
156  U32 vertices,StripMode strip,
157  BWORD multicolor,const Color *color,
158  const Array<I32>* vertexMap,
159  const Array<I32>* hullPointMap,
160  const Array<Vector4i>* hullFacePoint,
161  sp<DrawBufferI> spDrawBuffer);
162 
163 virtual void drawLinesInternal(const SpatialVector *vertex,
164  const SpatialVector *normal,
165  const Vector2 *texture,U32 vertices,
166  StripMode strip,
167  BWORD multicolor,const Color *color,
168  BWORD multiradius,const Real *radius,
169  const Vector3i *element,U32 elementCount,
170  sp<DrawBufferI> spDrawBuffer);
171 
172  class Texture:
173  virtual public Component,
174  public CastableAs<Texture>
175  {
176  public:
177  Texture(void);
178  virtual ~Texture(void);
179 
180  GLuint m_id;
181  GLsizei m_width;
182  GLsizei m_height;
183  GLenum m_type;
184  const GLvoid* m_pData;
185  I32 m_serial;
186  };
187 
188  class Buffer:
189  public Catalog,
190  public DrawBufferI,
191  public CastableAs<Buffer>
192  {
193  public:
194  Buffer(void);
195  virtual ~Buffer(void);
196  void releaseAll(void);
197 
198  sp<DrawI> m_spDrawI;
199  GLuint m_vboVertex;
200  GLuint m_vboVertexMap;
201  GLuint m_vboNormal;
202  GLuint m_vboTexture;
203  GLuint m_vboColor;
204 
205 #ifdef FE_GL_OPENCL
206  cl_mem m_clMemVertex;
207  cl_mem m_clMemColor;
208 #endif
209  };
210 
211  sp<Texture> createTexture(void);
212  sp<Texture> getTexture(GLsizei a_width,GLsizei a_height,
213  GLenum a_format,GLenum a_type,
214  const GLvoid* a_pData,I32 a_serial);
215 
216  void assureFont(void);
217 
218  void threadLock(void);
219  void threadUnlock(void);
220 
221  void bindTexture(sp<ImageI> spImageI,I32 imageID);
222 
223  void drawCylinderGLU(const SpatialTransform &transform,
224  const SpatialVector *scale,
225  Real baseScale,const Color &color,U32 slices);
226 
227  void drawSphereGLU(const SpatialTransform &transform,
228  const SpatialVector *scale,const Color &color);
229 
230  void beginArrays(const SpatialVector *vertex,
231  const SpatialVector *normal,
232  const Array<I32>* vertexMap,
233  const Vector2 *texture,U32 vertices,
234  BWORD multicolor,const Color *color,
235  sp<DrawBufferI> spDrawBuffer,
236  BWORD normals,BWORD blending);
237  void endArrays(const Array<I32>* vertexMap,
238  const Vector2 *texture,
239  BWORD multicolor,const Color *color,
240  sp<DrawBufferI> spDrawBuffer,
241  BWORD normals);
242 
243  void setupLights(void);
244  void createDefaultTexture(void);
245  void useDefaultTexture(void);
246  void pushAntialiasPoints(void);
247  void pushAntialiasLines(void);
248  void pushBlending(void);
249  void activateBlending(void);
250  void queryFormat(sp<ImageI> spImageI,GLenum& format,
251  GLenum& type,GLint& components);
252 
253  void setup(DrawMode::DrawStyle style,BWORD lit,BWORD dual,
254  BWORD texture,BWORD frontcull,BWORD backcull,
255  BWORD zBuffer);
256 
257 static void checkForError(String a_location);
258 
259  sp<ImageI> m_spCurrentTexture;
260  I32 m_currentTextureId;
261 
262  Real m_multiplication;
263  BWORD m_isDirect;
264  BWORD m_lockThreads;
265  GLUquadric* m_pQuadric;
266 
267  sp<Texture> m_spDefaultTexture;
268  GLubyte m_defaultTextureData[DGL_DEFAULT_TEXTURE_SIZE]
269  [DGL_DEFAULT_TEXTURE_SIZE][3];
270 
271  std::map< const void*, sp<Texture> > m_textureTable;
272 
273  sp<FontI> m_spFont;
274 };
275 
276 } /* namespace ext */
277 } /* namespace fe */
278 
279 #endif /* __opengl_DrawOpenGL_h__ */
virtual void drawPoints(const SpatialVector *vertex, const SpatialVector *normal, U32 vertices, BWORD multicolor, const Color *color)
Draw points vertex[vertices].
Definition: DrawCommon.cc:222
Drawing functions not specific to the graphics language.
Definition: DrawCommon.h:32
kernel
Definition: namespace.dox:3
Dictionary of Arbitrary Instances.
Definition: Catalog.h:24
StripMode
Format of vertices for tri-stripping.
Definition: DrawI.h:26
GPU cache.
Definition: DrawBufferI.h:20
virtual void drawTriangles(const SpatialVector *vertex, const SpatialVector *normal, const Vector2 *texture, U32 vertices, StripMode strip, BWORD multicolor, const Color *color)
Draw triangles.
Definition: DrawCommon.cc:257
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Special vector for color (RGBA)
Definition: Color.h:21
virtual BWORD isDirect(void) const
Returns TRUE is display is local and rendered directly.
Definition: DrawOpenGL.h:35
Automatically reference-counted string container.
Definition: String.h:128
OpenGL-specific implementations for DrawI.
Definition: DrawOpenGL.h:25
virtual void drawLines(const SpatialVector *vertex, const SpatialVector *normal, U32 vertices, StripMode strip, BWORD multicolor, const Color *color)
Draw lines.
Definition: DrawCommon.cc:238
DrawStyle
Rendering schemes that an an implementation may recognize.
Definition: DrawMode.h:42
Base for all interfacable components.
Definition: Component.h:20
virtual sp< FontI > font(void)
Get current font.
Definition: DrawOpenGL.h:51
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192