source: GTP/trunk/App/Demos/Illum/Standalone/Hierarchical Systems Demo [OpenGL]/RESOURCES/include/RttRes/pbuffer.h @ 852

Revision 852, 4.2 KB checked in by szirmay, 19 years ago (diff)
Line 
1#ifndef __PBUFFERS_H__
2#define __PBUFFERS_H__
3
4#if defined(WIN32)
5#  include <windows.h>
6#  include <GL/gl.h>
7#  include <GL/wglext.h>
8#  pragma warning (disable : 4786)
9#elif defined(UNIX)
10#  include <GL/glx.h>
11#  include <GL/glxext.h>
12#elif defined(MACOS)
13#  include <AGL/agl.h>
14#endif
15
16#include <string>
17#include <vector>
18
19// The pixel format for the pbuffer is controlled by the mode string passed
20// into the PBuffer constructor. This string can have the following attributes:
21//
22// r                    - r pixel format (for float buffer).
23// rg                   - rg pixel format (for float buffer).
24// rgb          - rgb pixel format. 8 bit or 16/32 bit in float buffer mode
25// rgba         - same as "rgb alpha" string
26// alpha        - must have alpha channel
27// depth        - must have a depth buffer
28// depth=n      - must have n-bit depth buffer
29// stencil      - must have a stencil buffer
30// double       - must support double buffered rendering
31// samples=n    - must support n-sample antialiasing (n can be 2 or 4)
32// float=n      - must support n-bit per channel floating point
33//
34// texture2D
35// textureRECT
36// textureCUBE  - must support binding pbuffer as texture to specified target
37//              - binding the depth buffer is also supporting by specifying
38//                '=depth' like so: texture2D=depth or textureRECT=depth
39//              - the internal format of the texture will be rgba by default or
40//                float if pbuffer is floating point
41//     
42class PBuffer
43{
44    public:
45                bool m_HasDepthTexture;
46                bool m_HasAuxBuffers;
47        // see above for documentation on strMode format
48        // set managed to true if you want the class to cleanup OpenGL objects in destructor
49        PBuffer(const char *strMode, bool managed = false);
50        ~PBuffer();
51
52        bool Initialize(int iWidth, int iHeight, bool bShareContexts, bool bShareObjects);
53        void Destroy();
54
55        void Activate(PBuffer *current = NULL); // to switch between pbuffers, pass active pbuffer as argument
56        void Deactivate();
57
58#if defined(WIN32)
59        int Bind(int iBuffer);
60        int Release(int iBuffer);
61
62        void HandleModeSwitch();
63#endif
64
65        unsigned int GetSizeInBytes();
66        unsigned int CopyToBuffer(void *ptr, int w=-1, int h=-1);
67
68        inline int GetNumComponents()
69        { return m_iNComponents; }
70
71        inline int GetBitsPerComponent()
72        { return m_iBitsPerComponent; }
73
74        inline int GetWidth()
75        { return m_iWidth; }
76
77        inline int GetHeight()
78        { return m_iHeight; }
79
80        inline bool IsSharedContext()
81        { return m_bSharedContext; }
82
83#if defined(WIN32)
84        inline bool IsTexture()
85        { return m_bIsTexture; }
86#endif
87
88    protected:
89#if defined(WIN32)
90        HDC         m_hDC;     ///< Handle to a device context.
91        HGLRC       m_hGLRC;   ///< Handle to a GL context.
92        HPBUFFERARB m_hPBuffer;///< Handle to a pbuffer.
93
94        HGLRC       m_hOldGLRC;
95        HDC         m_hOldDC;
96       
97        std::vector<int> m_pfAttribList;
98        std::vector<int> m_pbAttribList;
99
100        bool m_bIsTexture;
101#elif defined(UNIX)
102        Display    *m_pDisplay;
103        GLXPbuffer  m_glxPbuffer;
104        GLXContext  m_glxContext;
105
106        Display    *m_pOldDisplay;
107        GLXPbuffer  m_glxOldDrawable;
108        GLXContext  m_glxOldContext;
109       
110        std::vector<int> m_pfAttribList;
111        std::vector<int> m_pbAttribList;
112#elif defined(MACOS)
113        AGLContext  m_context;
114        WindowPtr   m_window;
115        std::vector<int> m_pfAttribList;
116#endif
117
118        int m_iWidth;
119        int m_iHeight;
120        int m_iNComponents;
121        int m_iBitsPerComponent;
122   
123        const char *m_strMode;
124        bool m_bSharedContext;
125        bool m_bShareObjects;
126
127    private:
128        std::string getStringValue(std::string token);
129        int getIntegerValue(std::string token);
130#if defined(UNIX) || defined(WIN32)       
131        void parseModeString(const char *modeString, std::vector<int> *pfAttribList, std::vector<int> *pbAttribList);
132
133        bool m_bIsBound;
134        bool m_bIsActive;
135        bool m_bManaged;
136#endif
137
138};
139
140#endif
Note: See TracBrowser for help on using the repository browser.