nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef __PBUFFERS_H__ 00024 #define __PBUFFERS_H__ 00025 00026 #if defined(WIN32) 00027 #include "GLResource.h" 00028 00029 # pragma warning (disable : 4786) 00030 #elif defined(UNIX) 00031 # include <GL/glx.h> 00032 # include <GL/glxext.h> 00033 #elif defined(__APPLE__) 00034 # include <AGL/agl.h> 00035 #endif 00036 00037 #include <string> 00038 #include <vector> 00039 00040 // The pixel format for the pbuffer is controlled by the mode string passed 00041 // into the PBuffer constructor. This string can have the following attributes: 00042 // 00043 // r - r pixel format (for float buffer). 00044 // rg - rg pixel format (for float buffer). 00045 // rgb - rgb pixel format. 8 bit or 16/32 bit in float buffer mode 00046 // rgba - same as "rgb alpha" string 00047 // alpha - must have alpha channel 00048 // depth - must have a depth buffer 00049 // depth=n - must have n-bit depth buffer 00050 // stencil - must have a stencil buffer 00051 // double - must support double buffered rendering 00052 // samples=n - must support n-sample antialiasing (n can be 2 or 4) 00053 // float=n - must support n-bit per channel floating point 00054 // 00055 // texture2D 00056 // textureRECT 00057 // textureCUBE - must support binding pbuffer as texture to specified target 00058 // - binding the depth buffer is also supporting by specifying 00059 // '=depth' like so: texture2D=depth or textureRECT=depth 00060 // - the internal format of the texture will be rgba by default or 00061 // float if pbuffer is floating point 00062 // 00063 00064 namespace nux 00065 { 00066 00067 class PBuffer 00068 { 00069 public: 00070 // see above for documentation on strMode format 00071 // set managed to true if you want the class to cleanup OpenGL objects in destructor 00072 PBuffer (const char *strMode, bool managed = false); 00073 ~PBuffer(); 00074 00075 bool Initialize (int iWidth, int iHeight, bool bShareContexts, bool bShareObjects); 00076 void Destroy(); 00077 00078 void Activate (PBuffer *current = NULL); // to switch between pbuffers, pass active pbuffer as argument 00079 void Deactivate(); 00080 00081 #if defined(WIN32) 00082 int Bind (int iBuffer); 00083 int Release (int iBuffer); 00084 00085 void HandleModeSwitch(); 00086 #endif 00087 00088 unsigned int GetSizeInBytes(); 00089 unsigned int CopyToBuffer (void *ptr, int w = -1, int h = -1); 00090 00091 inline int GetNumComponents() 00092 { 00093 return m_iNComponents; 00094 } 00095 00096 inline int GetBitsPerComponent() 00097 { 00098 return m_iBitsPerComponent; 00099 } 00100 00101 inline int GetWidth() 00102 { 00103 return m_iWidth; 00104 } 00105 00106 inline int GetHeight() 00107 { 00108 return m_iHeight; 00109 } 00110 00111 inline bool IsSharedContext() 00112 { 00113 return m_bSharedContext; 00114 } 00115 00116 #if defined(WIN32) 00117 inline bool IsTexture() 00118 { 00119 return m_bIsTexture; 00120 } 00121 #endif 00122 00123 protected: 00124 #if defined(NUX_OS_WINDOWS) 00125 HDC m_hDC; 00126 HGLRC m_hGLRC; 00127 HPBUFFERARB m_hPBuffer; 00128 00129 HGLRC m_hOldGLRC; 00130 HDC m_hOldDC; 00131 00132 std::vector<int> m_pfAttribList; 00133 std::vector<int> m_pbAttribList; 00134 00135 bool m_bIsTexture; 00136 #elif defined(NUX_OS_LINUX) 00137 Display *m_pDisplay; 00138 GLXPbuffer m_glxPbuffer; 00139 GLXContext m_glxContext; 00140 00141 Display *m_pOldDisplay; 00142 GLXPbuffer m_glxOldDrawable; 00143 GLXContext m_glxOldContext; 00144 00145 std::vector<int> m_pfAttribList; 00146 std::vector<int> m_pbAttribList; 00147 #elif defined(NUX_OS_MACOSX) 00148 AGLContext m_context; 00149 WindowPtr m_window; 00150 std::vector<int> m_pfAttribList; 00151 #endif 00152 00153 int m_iWidth; 00154 int m_iHeight; 00155 int m_iNComponents; 00156 int m_iBitsPerComponent; 00157 00158 const char *m_strMode; 00159 bool m_bSharedContext; 00160 bool m_bShareObjects; 00161 00162 private: 00163 std::string getStringValue (std::string token); 00164 int getIntegerValue (std::string token); 00165 #if defined(NUX_OS_WINDOWS) || defined(NUX_OS_LINUX) 00166 void parseModeString (const char *modeString, std::vector<int> *pfAttribList, std::vector<int> *pbAttribList); 00167 00168 bool m_bIsBound; 00169 bool m_bIsActive; 00170 bool m_bManaged; 00171 #endif 00172 }; 00173 } 00174 00175 #endif // __PBUFFERS_H__