NCBI C++ ToolKit
gloscontext.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __GL_OS_RENDERER__HPP
2 #define __GL_OS_RENDERER__HPP
3 /* $Id: gloscontext.hpp 34011 2015-10-20 14:48:52Z falkrb $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Mike DiCuccio
29  *
30  * File Description:
31  * CGlOsContext -- wrapper for Mesa3D's off-screen rendering extension
32  */
33 
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <util/image/image.hpp>
37 
38 #include <GL/glew.h>
39 
40 // GLEW undefines GLAPI and GLAPIENTRY which causes issues with mesa, which
41 // normally includes gl.h first, and then expects these macros to continue
42 // to be defined afterward. More up-to-date versions of glew (1.5.2 and above) may
43 // resolve this issue and allow this code to be removed.
44 #ifdef NCBI_OS_UNIX
45 #ifndef APIENTRY
46 #define APIENTRY
47 #endif
48 
49 #ifndef GLAPIENTRY
50 #define GLAPIENTRY
51 #endif
52 
53 #ifndef GLAPI
54 #define GLAPI extern
55 #endif
56 #endif
57 
58 #include <GL/osmesa.h>
59 
61 
62 
63 //
64 // class CGlOsContext defines a simple interface for off-screen rendering.
65 //
66 // The current implementation depends on using the Off-Screen Mesa
67 // implementation that comes standard with the Mesa3D package, available at
68 // http://www.mesa3d.org/. This interface provides for a simple virtualized
69 // frame-buffer. The user establishes the buffer on their own; Mesa3D then
70 // uses this image as its framebuffer.
71 //
72 
73 class CGlOsContext : public CObject
74 {
75 public:
76  // initialize without a framebuffer. Caller will have to pass
77  // an image to MakeCurrent (allows one redering context to
78  // render to multiple framebuffers)
79  CGlOsContext(unsigned stencilBits = 0);
80 
81  // initialize our renderer with a virtual frame buffer of a given size.
82  // This frame buffer will always be initialized as an RGBA image.
83  CGlOsContext(size_t width, size_t height, unsigned stencilBits = 0);
84 
85  // destructor for cleaning up our OSMesa context
86  virtual ~CGlOsContext();
87 
88  // make the current frame buffer the active buffer for rendering
89  bool MakeCurrent(void);
90  bool MakeCurrent(size_t width, size_t height);
91 
92  // make context current with passed-in frame buffer
93  bool MakeCurrent(CImage* img);
94 
95  // return the maximum size buffer that can be created
96  void GetMaximumBufferSize(GLint& max_width, GLint& max_height);
97 
98  // Set pixel store options via OSMesaPixelStore
99  void SetPixelStore(GLint pname, GLint value);
100 
101  // access the image we use for the virtual frame buffer
102  const CImage& GetBuffer(void) const;
103  CImage& SetBuffer(void);
104 
105  /// Resize frame buffer size.
106  void Resize(size_t width, size_t height);
107 
108 private:
109  void x_InitContext(unsigned stencilBits);
110 
111  // our image
113 
114  // the OSMesa context. This is a hook to Mesa3D's internals.
115  OSMesaContext m_Ctx;
116 };
117 
118 
120 
121 #endif // __GL_OS_RENDERER__HPP
OSMesaContext m_Ctx
CImage & SetBuffer(void)
void SetPixelStore(GLint pname, GLint value)
CRef< CImage > m_Image
bool MakeCurrent(void)
Definition: gloscontext.cpp:84
void GetMaximumBufferSize(GLint &max_width, GLint &max_height)
virtual ~CGlOsContext()
Definition: gloscontext.cpp:75
void Resize(size_t width, size_t height)
Resize frame buffer size.
void x_InitContext(unsigned stencilBits)
Definition: gloscontext.cpp:58
const CImage & GetBuffer(void) const
CGlOsContext(unsigned stencilBits=0)
Definition: gloscontext.cpp:41
CImage –.
Definition: Image.hpp:66
CObject –.
Definition: ncbiobj.hpp:180
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Sun May 19 04:46:37 2024 by modify_doxy.py rev. 669887