TAPs 0.7.7.3
TAPsPBuffer.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsPBuffer.hpp
00003 
00004 Class PBuffer (Pixel Buffer) is a class for managing a pbuffer.
00005 
00006 SUKITTI PUNAK   (05/18/2005)
00007 UPDATE          (09/10/2010)
00008 ******************************************************************************/
00025 // Modified from NVIDIA SDK 9.1 shared/pbuffer.h
00026 // The pixel format for the pbuffer is controlled by the mode string passed
00027 // into the PBuffer constructor. This string can have the following attributes:
00028 //
00029 // r            - r pixel format (for float buffer).
00030 // rg           - rg pixel format (for float buffer).
00031 // rgb          - rgb pixel format. 8 bit or 16/32 bit in float buffer mode
00032 // rgba         - same as "rgb alpha" string
00033 // alpha        - must have alpha channel
00034 // depth        - must have a depth buffer
00035 // depth=n      - must have n-bit depth buffer
00036 // stencil      - must have a stencil buffer
00037 // double       - must support double buffered rendering
00038 // samples=n    - must support n-sample antialiasing (n can be 2 or 4)
00039 // float=n      - must support n-bit per channel floating point
00040 // 
00041 // texture2D
00042 // textureRECT
00043 // textureCUBE  - must support binding pbuffer as texture to specified target
00044 //              - binding the depth buffer is also supporting by specifying
00045 //                '=depth' like so: texture2D=depth or textureRECT=depth
00046 //              - the internal format of the texture will be rgba by default or
00047 //                float if pbuffer is floating point
00048 //      
00049 /******************************************************************************/
00050 #ifndef TAPs_PIXEL_BUFFER_HPP
00051 #define TAPs_PIXEL_BUFFER_HPP
00052 
00053 #include "../Core/TAPsDef.hpp"
00054 
00055 #if defined ( WIN32 )
00056     //#define GLEW_STATIC 1
00057     #include <GL/glew.h>
00058     #include <GL/wglew.h>
00059     #include <GL/glut.h>
00060     #include <GL/wglext.h>
00061     //#include <windows.h>
00062 //#  pragma warning (disable : 4786)
00063 #elif defined ( UNIX )
00064     #error "UNIX is not supported!"
00065     #include <GL/glx.h>
00066     #include <GL/glxext.h>
00067 #elif defined ( MACOS )
00068     #error "MacOSX is not supported!"
00069     #include <AGL/agl.h>
00070 #else
00071     #error "This OS is not supported!"
00072 #endif
00073 
00074 #include <iostream>
00075 #include <cstdio>   // for stdin, stdout, and stderr
00076 #include <string>
00077 #include <vector>
00078 
00079 BEGIN_NAMESPACE_TAPs__OpenGL
00080 //=============================================================================
00081 class PBuffer {
00082 //=============================================================================
00083 // MEMBER FUNCTIONS
00084 //=============================================================================
00085 public:
00086     //-------------------------------------------------------------------------
00087     // Output Operator <<
00088     friend std::ostream & operator<< ( std::ostream &output, 
00089                                        PBuffer const &o )
00090     {
00091         output  << "PBuffer with ..."
00092                 << "\n";
00093         return output;
00094     }
00095     //-------------------------------------------------------------------------
00096     // Constructor(s) and Destructor
00097     // see above for documentation on strMode format
00098     // set managed to true if you want the class to cleanup OpenGL objects in destructor
00099     PBuffer ( const char *strMode, bool managed = false );
00100     ~PBuffer ();
00101     //-------------------------------------------------------------------------
00102     // Operation(s): Create or Destroy the PBuffer
00103     bool Create ( int iWidth, int iHeight, bool bShareContexts, bool bShareObjects );
00104     void Destroy ();
00105     //-------------------------------------------------------------------------
00106     // Operation(s): Activate or Deactivate the PBuffer
00107     // To switch between pbuffers, pass active pbuffer as argument
00108     void Activate   ( PBuffer *current = NULL );
00109     void Deactivate ();
00110     //-------------------------------------------------------------------------
00111 #if defined ( WIN32 )
00112     // Operation(s): Bind as a texture or Release it from a texture
00113     //void Bind  ( unsigned int buffer = GL_FRONT );
00114     //void Release ( unsigned int buffer = GL_FRONT );
00115     int Bind    ( int iBuffer );
00116     int Release ( int iBuffer );
00117     // Check to see if the PBuffer was lost.
00118     //   If it was lost, destroy it and then recreate it.
00119     void HandleModeSwitch ();
00120     //void Swap (); // Swap if applicable (flush if single)
00121 #endif
00122     //-------------------------------------------------------------------------
00123     // Get/Set Fns
00124     // Return the total size in bytes of the PBuffer
00125     unsigned int    GetSizeInBytes  ();
00126     // Make a copy of the entire PBuffer in the memory
00127     //   have to allocate this area (ptr).
00128     //   if want to read a smaller size : 
00129     //     specify it through w and h 
00130     //     otherwise w = h =-1
00131     unsigned int    CopyToBuffer    ( void *ptr, int w = -1, int h = -1 );
00132     inline int  GetNoOfComponents   ()  { return m_iNoOfComponents; }
00133     inline int  GetBitsPerComponent ()  { return m_iBitsPerComponent; }
00134     inline int  GetWidth  ()    { return m_iWidth; }
00135     inline int  GetHeight ()    { return m_iHeight; }
00136     inline bool IsSharedContext ()  { return m_bSharedContextStatus; }
00137 #if defined ( WIN32 )
00138     inline bool IsTexture ()    { return m_bIsTexture; }
00139 #endif
00140     //-------------------------------------------------------------------------
00141     // Operation(s): Swap if applicable (flush if single)
00142     //void Swap ();
00143     //-------------------------------------------------------------------------
00144 //-----------------------------------------------------------------------------
00145 //=============================================================================
00146 // DATA MEMBERS
00147 //=============================================================================
00148 protected:
00149     int m_iWidth, m_iHeight;            // height and width
00150     int m_iNoOfComponents;              // # of components
00151     int m_iBitsPerComponent;            // # of bits / components
00152     const char *m_cpMode;               // string mode for PBuffer
00153     bool m_bSharedContextStatus;        // shared context status
00154     bool m_bShareObjectsStatus;         // shared object status
00155 #if defined ( WIN32 )
00156     HDC         m_hDC;      // Handle to a device context
00157     HGLRC       m_hGLRC;    // Handle to a GL context
00158     HPBUFFERARB m_hPBuffer; // Handle to a pbuffer
00159     HDC         m_hOldDC;
00160     HGLRC       m_hOldGLRC;
00161     std::vector<int>    m_pfAttribList;
00162     std::vector<int>    m_pbAttribList;
00163     bool        m_bIsTexture;
00164 #elif defined ( UNIX )
00165     Display *   m_pDisplay;
00166     GLXPbuffer  m_glxPBuffer;
00167     GLXContext  m_glxContext;
00168     Display *   m_pOldDisplay
00169     GLXPbuffer  m_glxOldDrawable;
00170     GLXContext  m_glxOldContext;
00171     std::vector<int>    m_pfAttribList;
00172     std::vector<int>    m_pbAttribList;
00173 #elif defined ( MACOS )
00174     AGLContext  m_context;
00175     WindowPtr   m_window;
00176     std::vector<int>    m_pfAttribList;
00177 #endif
00178 //=============================================================================
00179 // Helper Member Fn(s) and Data Member(s)
00180 private:
00181     std::string GetStrValue( std::string sToken );
00182     int GetIntValue ( std::string sToken );
00183 #if defined(UNIX) || defined(WIN32)
00184     void ParseModeString(   const char *modeString, 
00185                             std::vector<int> *pfAttribList, 
00186                             std::vector<int> *pbAttribList );
00187     bool m_bIsBound;
00188     bool m_bIsActive;
00189     bool m_bManaged;
00190 #endif
00191 //-----------------------------------------------------------------------------
00192 }; // END CLASS PBuffer
00193 //=============================================================================
00194 END_NAMESPACE_TAPs__OpenGL
00195 //-----------------------------------------------------------------------------
00196 // Include definition if TAPs_USE_EXPORT is not defined
00197 #if !defined( TAPs_USE_EXPORT )
00198     #include "TAPsPBuffer.cpp"
00199 #endif
00200 //-----------------------------------------------------------------------------
00201 #endif
00202 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00203 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines