~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxGraphics/GLPBuffer.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-02 03:28:11 UTC
  • Revision ID: neil.patel@canonical.com-20100902032811-i2m18tfb6pkasnvt
Remove Win EOL chars

Show diffs side-by-side

added added

removed removed

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