nux-1.16.0
GraphicsDisplayWin.h
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 GRAPHICSDISPLAYWIN_H
00024 #define GRAPHICSDISPLAYWIN_H
00025 
00026 #include "Gfx_Interface.h"
00027 #include "GLTimer.h"
00028 #include "GLDeviceObjects.h"
00029 #include "GLRenderStates.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class Event;
00035   class MainFBO;
00036   class GpuDevice;
00037   class GraphicsEngine;
00038   class IOpenGLFrameBufferObject;
00039 
00040   enum WindowStyle
00041   {
00042     WINDOWSTYLE_NORMAL,
00043     WINDOWSTYLE_PANEL,
00044     WINDOWSTYLE_DIALOG,
00045     WINDOWSTYLE_TOOL,
00046     WINDOWSTYLE_NOBORDER,
00047   };
00048 
00049 #define NUX_THREADMSG                           (WM_APP+0)
00050 #define NUX_THREADMSG_START_RENDERING           (WM_APP+1)  // Connection established // start at WM_APP
00051 #define NUX_THREADMSG_CHILD_WINDOW_TERMINATED   (WM_APP+2)  // General failure - Wait Connection failed
00052 #define NUX_THREADMSG_THREAD_TERMINATED         (WM_APP+3)  // Set wParam = Thread ID, lParam = 0
00053 
00054 // This will become GLWindow
00055   class GraphicsDisplay : public GraphicSystem
00056   {
00057     friend class GraphicsEngine;
00058 
00059   private:
00060 #ifdef WIN32
00061     // WIN32 system variables
00062     HGLRC       _opengl_rendering_context;  
00063     HDC         _device_context;            
00064     HWND        m_hWnd;                     
00065     HWND        m_ParentWindow;
00066 
00067     TCHAR m_WindowClassName[256];
00068     GLuint      m_PixelFormat;      // Holds The Results After Searching For A Match
00069     DWORD       m_dwExStyle;        // Window Extended Style
00070     DWORD       m_dwStyle;          // Window Style
00071     NString     m_WindowTitle;
00072 #endif
00073 
00074     static HGLRC sMainGLRC;         // Used as the first argument of wglShareLists to make all successive OpenGL  context share their objects
00075     static HDC   sMainDC;           // Used as the first argument of wglShareLists to make all successive OpenGL  context share their objects
00076 
00077     // size, position
00078     Size  m_ViewportSize;
00079     Size m_WindowSize;
00080 
00081     // surface attibute;
00082     bool m_fullscreen;
00083     unsigned int m_ScreenBitDepth;
00084 
00085     // verifiy that the interface is properly created
00086     bool m_GfxInterfaceCreated;
00087 
00088     // Device information
00089     void GetDisplayInfo();
00090     int m_index_of_current_mode;
00091 
00092     bool m_is_window_minimized;
00093 
00094     HCURSOR m_Cursor;
00095 
00096     static int Win32KeySymToINL (int Keysym);
00097     static int Win32VKToNuxKey (int vk);
00098   public:
00099 
00100     // Device
00101     int m_num_device_modes;
00102 
00103     // Event object
00104     Event *event_;
00105 
00106     // Creation
00107     bool IsGfxInterfaceCreated();
00108 
00110 
00118     bool CreateOpenGLWindow (
00119       const TCHAR *WindowTitle,
00120       unsigned int WindowWidth,
00121       unsigned int WindowHeight,
00122       WindowStyle Style,
00123       const GraphicsDisplay *Parent,
00124       bool FullscreenFlag = false,
00125       bool create_rendering_data = true);
00126 
00128 
00133     bool CreateFromOpenGLWindow (HWND WindowHandle, HDC WindowDCHandle, HGLRC OpenGLRenderingContext);
00134 
00135     void DestroyOpenGLWindow();
00136 
00137     void SetWindowTitle (const TCHAR *Title);
00138     void SetWindowSize (int width, int height);
00139     void SetViewPort (int x, int y, int width, int height);
00140     Point GetMouseScreenCoord();
00141     Point GetMouseWindowCoord();
00142     Point GetWindowCoord();
00143     Rect GetWindowGeometry();
00144     Rect GetNCWindowGeometry();
00145     void MakeGLContextCurrent (bool b = true);
00146     void SwapBuffer (bool glswap = true);
00147 
00148     // Event methods
00149     void GetSystemEvent (Event *evt);
00150     Event &GetCurrentEvent();
00151 
00152     bool isWindowMinimized() const
00153     {
00154       return m_is_window_minimized;
00155     }
00156 
00157     void ShowWindow();
00158     void HideWindow();
00159     bool IsWindowVisible ();
00160 
00161     void EnterMaximizeWindow();
00162     void ExitMaximizeWindow();
00163 
00164     HWND GetWindowHandle() const
00165     {
00166       return m_hWnd;
00167     }
00168     HWND GetParentWindowHandle() const
00169     {
00170       return m_ParentWindow;
00171     }
00172     HDC GetWindowHDC() const
00173     {
00174       return _device_context;
00175     }
00176     bool IsChildWindow() const
00177     {
00178       return m_ParentWindow != 0;
00179     }
00180 
00181     // Return true if VSync swap control is available
00182     bool HasVSyncSwapControl() const;
00183     void EnableVSyncSwapControl();
00184     void DisableVSyncSwapControl();
00185 
00186     // m_FrameRate
00187     float GetFrameTime() const;
00188     void ResetFrameTime();
00189 
00190     GraphicsEngine *GetGraphicsEngine() const;
00191     
00192     GpuDevice *GetGpuDevice () const;
00193 
00194     // Dialog
00195     bool StartOpenFileDialog (FileDialogOption &fdo);
00196     bool StartSaveFileDialog (FileDialogOption &fdo);
00197     bool StartColorDialog (ColorDialogOption &cdo);
00198 
00199 
00200     void GetWindowSize (int &w, int &h);
00201     int GetWindowWidth();
00202     int GetWindowHeight();
00203 
00205 
00209     void ResetWindowSize ();
00210 
00211     bool HasFrameBufferSupport();
00212     void SetWindowCursor (HCURSOR cursor);
00213     HCURSOR GetWindowCursor() const;
00214 
00215     void ProcessForeignWin32Event (HWND hWnd, MSG msg, WPARAM wParam, LPARAM lParam, Event *event);
00216     LRESULT ProcessWin32Event (HWND hWnd, t_u32 uMsg, WPARAM wParam, LPARAM lParam);
00217 
00219 
00228     void PauseThreadGraphicsRendering();
00229     bool IsPauseThreadGraphicsRendering() const;
00230 
00231     // Pointer and keyboard grab API
00232     typedef void (*GrabReleaseCallback) (bool replaced, void *user_data);
00233 
00234     bool GrabPointer   (GrabReleaseCallback callback, void *data, bool replace_existing);
00235     bool UngrabPointer (void *data);
00236     bool PointerIsGrabbed ();
00237 
00238     bool GrabKeyboard   (GrabReleaseCallback callback, void *data, bool replace_existing);
00239     bool UngrabKeyboard (void *data);
00240     bool KeyboardIsGrabbed ();
00241 
00242     void * KeyboardGrabData () { return _global_keyboard_grab_data; }
00243     void * PointerGrabData () { return _global_pointer_grab_data; }
00244 
00245   private:
00246     void InitGlobalGrabWindow ();
00247 
00248     bool m_PauseGraphicsRendering;
00249     GLTimer m_Timer;
00250     float m_FrameTime;
00251     GpuDevice *m_DeviceFactory;
00252     GraphicsEngine *m_GraphicsContext;
00253     WindowStyle m_Style;
00254 
00255     HWND                _global_grab_window;
00256 
00257     void               *_global_pointer_grab_data;
00258     bool                _global_pointer_grab_active;
00259     GrabReleaseCallback _global_pointer_grab_callback;
00260 
00261     void               *_global_keyboard_grab_data;
00262     bool                _global_keyboard_grab_active;
00263     GrabReleaseCallback _global_keyboard_grab_callback;
00264 
00265 
00266   public:
00267     ~GraphicsDisplay();
00268     GLEWContext *GetGLEWContext()
00269     {
00270       return &m_GLEWContext;
00271     }
00272     WGLEWContext *GetWGLEWContext()
00273     {
00274       return &m_WGLEWContext;
00275     }
00276 
00277   private:
00278     GraphicsDisplay();
00279     GraphicsDisplay (const GraphicsDisplay &);
00280     // Does not make sense for a singleton. This is a self assignment.
00281     GraphicsDisplay &operator= (const GraphicsDisplay &);
00282 
00283 
00284     GLEWContext m_GLEWContext;
00285     WGLEWContext m_WGLEWContext;
00286     friend class DisplayAccessController;
00287   };
00288 
00289   LRESULT CALLBACK WndProcManager (HWND    hWnd,          // Handle For This Window
00290                                    t_u32   uMsg,           // Message For This Window
00291                                    WPARAM  wParam,         // Additional Message Information
00292                                    LPARAM  lParam);        // Additional Message Information
00293 
00294 }
00295 
00296 #endif //GRAPHICSDISPLAYWIN_H
00297 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends