1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com>
8 Copyright (c) 2000-2014 Torus Knot Software Ltd
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 -----------------------------------------------------------------------------
28 */
29 
30 #ifndef __EGLWindow_H__
31 #define __EGLWindow_H__
32 
33 #include "OgreRenderWindow.h"
34 #include "OgreEGLSupport.h"
35 #include "OgreEGLContext.h"
36 #include "OgreGLRenderTarget.h"
37 
38 namespace Ogre {
39     class _OgrePrivate EGLWindow : public RenderWindow, public GLRenderTarget
40     {
41     private:
42         protected:
43             bool mClosed;
44             bool mVisible;
45             bool mIsTopLevel;
46             bool mIsExternal;
47             bool mIsExternalGLControl;
48             bool mVSync;
49             unsigned int mVSyncInterval;
50 
51             EGLSupport* mGLSupport;
52             EGLContext* mContext;
53             NativeWindowType mWindow;
54             NativeDisplayType mNativeDisplay;
55             ::EGLDisplay mEglDisplay;
56 
57 
58             ::EGLConfig mEglConfig;
59             ::EGLSurface mEglSurface;
60 
61             ::EGLSurface createSurfaceFromWindow(::EGLDisplay display, NativeWindowType win);
62 
63             virtual void switchFullScreen(bool fullscreen) = 0;
createEGLContext()64             EGLContext * createEGLContext() const {
65                 return new EGLContext(mEglDisplay, mGLSupport, mEglConfig, mEglSurface);
66             }
67 
68             virtual void getLeftAndTopFromNativeWindow(int & left, int & top, uint width, uint height) = 0;
69             virtual void initNativeCreatedWindow(const NameValuePairList *miscParams) = 0;
70             virtual void createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ) = 0;
71             virtual void reposition(int left, int top) = 0;
72             virtual void resize(unsigned int width, unsigned int height) = 0;
73             virtual void windowMovedOrResized() = 0;
74 
getContext()75             GLContext* getContext() const { return mContext; }
76     public:
77             EGLWindow(EGLSupport* glsupport);
78             virtual ~EGLWindow();
79 
80 //      Moved create to native source because it has native calls in it.
81 //            void create(const String& name, unsigned int width, unsigned int height,
82 //                        bool fullScreen, const NameValuePairList *miscParams);
83 
84             virtual void setFullscreen (bool fullscreen, uint width, uint height);
85             void destroy(void);
86             bool isClosed(void) const;
87             bool isVisible(void) const;
88             void setVisible(bool visible);
89             void swapBuffers();
90             void copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer);
91 
92             /** @copydoc see RenderWindow::setVSyncEnabled */
93             void setVSyncEnabled(bool vsync);
94 
95             /** @copydoc see RenderWindow::isVSyncEnabled */
isVSyncEnabled()96             bool isVSyncEnabled() const {
97                 return mVSync;
98             }
99 
100             /** @copydoc see RenderWindow::setVSyncInterval */
101             void setVSyncInterval(unsigned int interval);
102 
103             /** @copydoc see RenderWindow::getVSyncInterval */
getVSyncInterval()104             unsigned int getVSyncInterval() const {
105                 return mVSyncInterval;
106             }
107 
108             /**
109                @remarks
110                * Get custom attribute; the following attributes are valid:
111                * WINDOW         The X NativeWindowType target for rendering.
112                * GLCONTEXT      The Ogre GLContext used for rendering.
113                * DISPLAY        EGLDisplay connection behind that context.
114                * DISPLAYNAME    The name for the connected display.
115                */
116             virtual void getCustomAttribute(const String& name, void* pData);
117 
118             bool requiresTextureFlipping() const;
119 
120             PixelFormat suggestPixelFormat() const;
121     };
122 }
123 
124 #endif
125