VedaMachineLinux/OGLMachineLinux.h

Go to the documentation of this file.
00001 /*! \file
00002     \author victorien ferry & www.m4nkind.com
00003     \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING.
00004 */
00005 #ifndef COM_M4NKIND_OGLMachineLinux_H
00006 #define COM_M4NKIND_OGLMachineLinux_H
00007 #include "OGLMachine.h"
00008 
00009 #include <GL/glx.h>
00010 #include <GL/gl.h>
00011 #include <GL/glu.h>
00012 #include <X11/extensions/xf86vmode.h>
00013 #include <X11/keysym.h>
00014 /*!
00015     \class  OGLMachineLinux 
00016     \ingroup    VirtualMachineDocGroup
00017     \brief  Defines a \mainprojectname Machine for linux systems, using OGLMachine for 3D and OSS for the sound server.
00018 */
00019 
00020 class OGLMachineLinux : public OGLMachine
00021 {
00022 /*=================================================================
00023                                 PUBLIC
00024 ==================================================================*/
00025 public:
00026     /*!
00027         \brief  Constructor. 
00028     */
00029     OGLMachineLinux(void);
00030     /*!
00031         \brief  Destructor.
00032     */
00033     virtual ~OGLMachineLinux(void);
00034 
00035     /*!
00036         \brief  Init
00037     */
00038     virtual eVMResult   InitMachine();  
00039 
00040     /*!
00041         \brief  Swap buffer so that what was drawn is shown.
00042     */
00043     virtual void    SwapMainScreenBuffer();
00044 
00045     /*!
00046         \brief  Check the Process the message of the interface, in the real time:
00047     */
00048     virtual void    ProcessInterface();
00049 
00050     /*!
00051         \brief  Method that update the cicular buffer. It is to be thrown
00052                 by the main task message handling, for event GetSoundBufferEventHandle()
00053      */
00054     static  void    UpdateCircularSoundBuffer();
00055 
00056     /*!
00057         \brief  force a date to the clock passed to the sound objects.
00058         \param  _seconds    in second units.
00059         \param  _fraction   the following after-the-point-units of _seconds, like if the whole were a 64 bits integer.
00060     */
00061     virtual void    SetSoundCurrentTime(int _seconds,unsigned int _fraction );
00062 
00063     /*!
00064         \brief  For Information, an image of the current sound buffer.
00065                 This is always a 2 float(left,right) table: 
00066                 The buffer size may vary. It can be used by preview methods or
00067                 live effects.
00068         \param  _ppSoundBuffer  pointer on pointer on the buffer to return.
00069         \param  _pLength    pointer on a unsigned int that return the length.
00070     */
00071     virtual void    GetCurrentSoundBufferImage(float ** const _ppSoundBuffer,unsigned int *_pLength) const;
00072     /*!
00073         \brief  tool: change main volume [0,1].
00074                 Yes, you can saturate when >1.
00075         \param  _newVolumeValue [0,1]
00076     */
00077     virtual void    SetSoundVolume(float _newVolumeValue);
00078     //{ m_SoundVolume = _newVolumeValue; };
00079     /*!
00080         \brief  tool: get main volume value [0,1].
00081         \return VolumeValue [0,1]
00082     */
00083     virtual float   GetSoundVolume();
00084     //{ return m_SoundVolume;  };
00085     /*!
00086         \brief  Return the machine main play frequency, in herz, (tick per sec).
00087         \return freq (44100.0,22050.0,...)
00088     */
00089     virtual float   GetPlayFrequency(); 
00090 
00091 /*==================================================================
00092             Cultural Stuff
00093 ==================================================================*/
00094 
00095     /*!
00096         \brief  Return the language of the machine, as a simple enum. It can be used
00097             by exemple
00098         \return an enum integer.
00099     */
00100     virtual eMachineLocalization    GetCurrentWorldLocalizationEnum(){ return eMachineLocalization_LocalisationNotImplemented; };
00101 
00102 /*==================================================================
00103             Disk Operating System Stuff.
00104 ==================================================================*/
00105 #ifdef _ENGINE_EDITABLE_
00106     /*!
00107         \brief  In edition mode, ask a file path to a file requester.
00108             the string format should vary, but will be compatible with LoadFile() and SaveFile()
00109         \param  _pDisplayString a string to inform to what's the file for.
00110         \param  _pResultFileName the file path , returned.
00111         \param  _nameMaxLength the maximum buffer size to write.
00112         \return true if _pDisplayString valid.
00113     */
00114     virtual bool    FileRequester(const char *_pDisplayString,char *_pResultFileName, unsigned int _nameMaxLength );
00115 
00116 #endif
00117 #ifdef _ENGINE_EDITABLE_
00118     /*!
00119         \brief  load a file into a memory chunk. You can load all in one row, or stream.
00120                 memory is to be deleted by the CALLER with operator: "delete [] pointer", for each 
00121                 succesfull call. return 0L if failed.
00122         \param  _pFilePath          the path of the file to load
00123         \param  _pFileStart         an offset of where to start reading the file. 0 if all file.
00124         \param  _LoadByteLength     return the exact real length of what was read and returned, if OK.
00125         \param  _maximumSizeLoad    the maximum length to read
00126         \return the memory chunk, or 0L if failed.
00127     */
00128     virtual const char *LoadFile(const char *_pFilePath,unsigned int _pFileStart,unsigned int &_LoadByteLength, unsigned int _maximumSizeLoad=0xffffffff);
00129 #endif
00130 #ifdef _ENGINE_EDITABLE_
00131     /*!
00132         \brief  write a file from a memory chunk. You can save all in one row, or stream.
00133         \param  _pFilePath      the path of the file to write
00134         \param  _chunkToWrite   your memory chunk to save, as char *.
00135         \param  _ChunkLength    the length of _chunkToWrite
00136         \param  _append         if true, file is continued. if false, file is rewritten. default to false.
00137         \return true if OK, false if not.
00138     */
00139     virtual bool SaveFile(const char *_pFilePath,const char *_chunkToWrite,unsigned int _ChunkLength,bool _append=false);
00140 #endif
00141 #ifdef _ENGINE_EDITABLE_
00142     /*!
00143         \brief  in edition mode, redirection of machine task wait.
00144         \param  _milliseconds time to wait.
00145     */
00146     virtual void    Sleep( unsigned int _milliseconds );
00147 #endif
00148 /*==================================================================
00149                                 PROTECTED
00150 ==================================================================*/
00151 protected:
00152     //! to be reached from process functions
00153     static  OGLMachineLinux *m_LastInstance;
00154     //! true if fullscreen.
00155     bool        m_fullscreen;
00156     //!  true when windows or screen is shown, so we got to draw:
00157     bool        m_active;
00158     //! screen dimension: can change when resizing:
00159     volatile unsigned int   m_Width;
00160     //! screen dimension: can change when resizing:
00161     volatile unsigned int   m_Height;
00162 typedef struct {
00163     Display *dpy;
00164     int screen;
00165     Window win;
00166     GLXContext ctx;
00167     XSetWindowAttributes attr;
00168     Bool fs;
00169 /*
00170 typedef struct {
00171     unsigned int    dotclock;
00172     unsigned short  hdisplay;
00173     unsigned short  hsyncstart;
00174     unsigned short  hsyncend;
00175     unsigned short  htotal;
00176     unsigned short  hskew;
00177     unsigned short  vdisplay;
00178     unsigned short  vsyncstart;
00179     unsigned short  vsyncend;
00180     unsigned short  vtotal;
00181     unsigned int    flags;
00182     int         privsize;
00183 #if defined(__cplusplus) || defined(c_plusplus)
00184     INT32       *c_private;
00185 #else
00186     INT32       *private;
00187 #endif
00188 } XF86VidModeModeInfo;
00189 */
00190     XF86VidModeModeInfo **ppdeskMode;
00191     int x, y;
00192     unsigned int width, height;
00193     unsigned int depth;
00194 } GLWindow;
00195     //! GLWin object.
00196     GLWindow m_GLWin;
00197     /*
00198         \brief  Tool, GLX window init.
00199     */
00200     bool CreateGLWindow( int bits, bool fullscreenflag );
00201     /*
00202         \brief  Tool, GLX window end.
00203     */
00204     void KillGLWindow(void);
00205 
00206 
00207     bool    SoundInit_OSS();
00208     /*!
00209         \brief protected sound init
00210         \param  _window 
00211     */
00212     bool    SoundInit();
00213     /*!
00214         \brief protected sound exit
00215     */
00216     void    SoundExit();
00217 
00218 protected:
00219 
00220     //! the current main sound volume of the machine.[0,1]
00221     float           m_SoundVolume;
00222     
00223 
00224     //! Figure out how big the DSound buffer should be 1 * 2 channel * sizeof(short)
00225     //static    DWORD   m_dwDSBufferSize;
00226     //! stereo = 2
00227     //#define   m_dwPrimaryChannels     2
00228     //! sec freq.
00229     //static    DWORD   m_dwPrimaryFreq;
00230     //! bytesize of one sound sample unit: (  2 channel * sizeof(short) = 4)
00231     //#define   m_nBlockAlign   ((16/8) * m_dwPrimaryChannels)
00232     //! circular sound buffer: offset where to write.
00233     //static    DWORD   m_dwNextWriteOffset;
00234 
00235     //! the m_dwDSBufferSize * 2 * sizeof(float) table passed to contextes:
00236     //static    float   *m_pStaticSoundBuffer;
00237     //! the total of amount played by a machine.
00238     unsigned int    m_TotalPlaySize;
00239     //!
00240     int         m_LastStartPlayTime_SecondUnit;
00241     //!
00242     unsigned int    m_LastStartPlayTime_SecondFrac;
00243 
00244     //! link the machine to a static machine list
00245     static  OGLMachineLinux *m_pFirstMachine;
00246     OGLMachineLinux         *m_pNextMachine;
00247 
00248     //!
00249     static  void *FSOUND_Software_OutputThread(void * arg);
00250 
00251     static void FSOUND_Software_Fill();
00252 #ifdef _ENGINE_EDITABLE_
00253     //! true if MachineIsLockedForSoundManagement. so that we don't use a list that is worked on.
00254     volatile static bool    m_MachineIsLockedForSoundManagement;
00255     volatile static bool    m_MachineIsLockedForSoundUpdate;
00256 #endif
00257 
00258 };
00259 
00260 
00261 #endif
00262 
00263 

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/